
/************************************************************
function : LTrim(strText)
usage    : for removing blank spaces from left of a string
inputs   : string.
output   : string without spaces on its left
e.g      : LTrim("  abc  ") = "abc  "
************************************************************/
function Test(str)
 {
   alert(str);
 }

function LTrim(strText)
{
	while (strText.substring(0,1) == ' ')
			strText = strText.substring(1, strText.length);
	return strText;
} 


/************************************************************
function : RTrim(strText)
usage    : for removing blank spaces from right of a string
inputs   : string.
output   : string without spaces on its right
e.g      : RTrim("  abc  ") = "  abc"
************************************************************/
function RTrim(strText)
{
	while (strText.substring(strText.length-1,strText.length) == ' ')
			strText = strText.substring(0, strText.length-1);
	return strText;
}
	

/************************************************************
function : Trim(strText)
usage    : for removing blank spaces from right and left of a string
inputs   : string.
output   : string without spaces on its right and left
e.g      : Trim("  abc  ") = "abc"
**************************************************************/
function Trim(strText)
{
	return RTrim(LTrim(strText));
}



/************************************************************
function : IsNumeric(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns false, "-12" returns true
************************************************************/
function IsNumeric(strNum)
{
	
	if(strNum.indexOf(".")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 

/************************************************************
function : IsDigit(strNum)
usage    : to determine whether given string is integer
inputs   : string.
output   : true if it is integer, false otherwise.
e.g      : "123" returns true, "abc44" returns false, "12.34" returns false, "-12" returns false
************************************************************/
function IsDigit(strNum)
{
	
	if(strNum.indexOf(".")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 


/************************************************************
function : IsDecimal(strNum)
usage    : to determine whether given string is decimal
inputs   : string.
output   : true if it is decimal, false otherwise.
e.g      : "123" returns true, "abc" returns false, "12.34" returns true,"-12.34" returns true
************************************************************/
function IsDecimal(strNum)
{
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 





/**************************************************************
function : CheckPhone(p1,p2,p3)
usage    : To check phone number of the form ###-###-####
inputs   : three textbox fields used as input to phone number, str is message to be displayed
output   : returns true if phone number is valid; otherwise returns false
e.g      : 123-345-6789 is valid phone number
**************************************************************/
function CheckPhone(p1,p2,p3,str)
{
	if (p1.value=="" & p2.value=="" & p3.value=="")
	{
		return true;
	}
	if(p1.value.length!=3)
	{
		alert(str);
		p1.select();
		p1.focus();		
		return false;
	}	
	if(!IsDigit(p1.value))
	{
		alert(str);
		p1.select();
		p1.focus();
		return false;
	}
	if(p2.value.length!=3)
	{
		alert(str);
		p2.select();
		p2.focus();		
		return false;
	}	
	if(!IsDigit(p2.value))
	{
		alert(str);
		p2.select();
		p2.focus();
		return false;
	}
	if(p3.value.length!=4)
	{
		alert(str);
		p3.select();
		p3.focus();		
		return false;
	}
	if(!IsDigit(p3.value))
	{
		alert(str);
		p3.select();
		p3.focus();
		return false;
	}
	
	return true;
}

function IsMoney(strNum)
{
	
	//if(strNum.indexOf(".")!=-1)
	//{
	//	return false;
	//}
	alert(strNum);
	var blnFlag=0
	var intLen=strNum.length
	if ( strNum.charAt(0)==".")
	{		
		return false
	}
	if (strNum.charAt(intLen-1)==".")
	{		
		return false
	}
	for (var i=0;i<intLen;i++)
	{
		if (strNum.charAt(i)==".")
		{
			blnFlag=blnFlag+1
		}
	}
	if (blnFlag>1)
	{		
		return false
	}
	if(strNum.indexOf("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 

/************************************************************
function : CheckZip(p1,p2,str)
usage    : To check Zip number of the form #####-####
inputs   : two textbox fields used as input to zip number, str is message to be displayed
output   : returns true if zip number is valid; otherwise returns false
e.g      : 12334-6789 is valid Zip Number
************************************************************/

function CheckZip(p1,p2,str)
{
	if (p1.value=="" & p2.value=="")
	{
		return true;
	}
	if(p1.value.length!=5)
	{
		alert(str);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value))
	{
		alert(str);
		p1.select();
		p1.focus();
		return false;
	}
	if(p2.value.length!=4)
	{
		alert(str);
		p2.select();
		p2.focus();		
		return false;
	}	
	if(!IsDigit(p2.value))
	{
		alert(str);
		p2.select();
		p2.focus();
		return false;
	}
	
	return true;
}


/************************************************************
function : CheckEmail(strMail)
usage    : To check Validity Of Email
inputs   : string containing mail address
output   : returns true if email is valid; otherwise returns false
e.g      : abc@xyz.com is valid Email Address.

************************************************************/
function CheckEmail(strMail)
{ 
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strMail.value))
 {
 return (true)
 }
alert("Invalid E-mail Address! Please re-enter.")
strMail.focus();
strMail.select();
return (false)
}

function CheckEmailPaypal(strMail)
{ 
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strMail.value))
{
return (true)
}
alert("Invalid Paypal ID! Please re-enter.")
strMail.focus();
strMail.select();
return (false)
}
/**************************************************************
function : CheckTaxID(p1,strMessage)
usage    : To check TaxID of the form ##-#######
inputs   : string containing taxid
output   : returns true if taxid is valid; otherwise returns false
e.g      : 12-3456789 is valid tax id
**************************************************************/
function CheckTaxID(p1,strMessage)
{
	var strMessage;
	if (p1.value=="")
	{
		return true;
	}
	if(p1.value.length!=10)
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(0,2)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(2,3)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(3)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
return true;
}

/**************************************************************
function : CheckSSN(p1,strMessage)
usage    : To check SSN number of the form ###-##-####
inputs   : string containing ssn number
output   : returns true if ssn number is valid; otherwise returns false
e.g      : 123-34-6789 is valid phone number
**************************************************************/
function CheckSSN(p1,strMessage)
{
	var strMessage;
	if (p1.value=="")
	{
		return true;
	}
	if(p1.value.length!=11)
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(0,3)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(3,4)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(4,6)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(p1.value.substring(6,7)!="-")
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
	if(!IsDigit(p1.value.substring(7)))
	{
		alert(strMessage);
		p1.select();
		p1.focus();		
		return false;
	}
return true;
}

///this function is used to check if value in textbox is empty
function CheckBlank(p,strMessage)
{
	if(Trim(p.value)=="")
	{
		alert(strMessage);
		p.select();
		p.focus();
		return false;
	}
	return true;
}
///Date Validation function
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function validateInt()
			{
				var k;
			k=window.event.keyCode;
			//alert(k);
			if(k==8 || k==9 || k==13)
				return true;
			else if(k>=48 && k<=57)
				return true;
			else
				return false;
}

function checkNumeric(fieldname,data,leng)
{	
	var num,i	
	num=data.value;
	result = true

	if(num.length > leng)
	{
		alert("Block should not exceed "+leng+" digits")
		return false
	}
	else
	{
		for(i=0; i<num.length ; i++)
		{
			if( (num.charCodeAt(i)<48 || num.charCodeAt(i)>57) )
			{
				alert(fieldname+" should be numeric only")
				data.focus()
				result = false
				break;
			}
			else
			{
				result = true
			}			
		}
		return result
	}
}

function validateIntQty()
			{
				var k;
				k=window.event.keyCode;
				alert(k);
				if(k==8 || k==9 || k==13 || k==46 || (k>=35 && k<=40))
					return true;
				else if((k>48 && k<=57) || (k>=96 && k<=105))
					return true;
				else
					return false;
			}
	function validateFloat()
	{
		
		var k,x,pos;
		
		try{
		k=window.event.keyCode;
		//alert(k);
		if(k==8 || k==9 || k==13 || k==46 || (k>=35 && k<=40) || k==110 ||k==190)
			return true;
		else if((k>=48 && k<=57) || k==110)
				return true;
		else
			return false;
		}
		catch(obj)
		{
		}
	}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

////////////////////////////////////////////////////////
//////////////////    Checking for the special character in the string   //////////////////////////////////     
///////////////////////////////////////////////////////
function SpecialCharEmail(str)
{
  var chk1 = "!#$%^*()+=|\~`{} []:'<>?/";
  
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid email");
			return false;
		}

   }
   return true;
}

///////////Functions For Check All Facility Start


	
	////////////////////
	//URL VALIDATION
	///////////////////	
	
function IsValidURL(urlString)
 {
	var urlReg = "^(file|http|https|ftp):\\/\\/([a-zA-Z0-9]*\\.)?[a-zA-Z0-9-]*\\.[a-zA-Z0-9]*(\\.[a-zA-Z0-9]*)?\\/?$";
	var regex = new RegExp(urlReg);
	var okURL = regex.test(urlString);
	return okURL;
 }
 ///////////////////////////////////
/////URL Validation
////////////////////////////////////
function ValidUrl(str)
{
	re = /^(file|http|https|ftp):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc)$/i
	if (!re.test(str)) 
     {
           alert ("Please Enter Proper Site URL");          
           return false;
       }
      return true; 
      }
 
 //////////////
///Validation of file  either image(*.gif of *.jpg) file or not
//////////////// 

function ValidImage(x)
{		
				var y=x.value;					
				var imglen=y.length;
				var imgdotpos=y.lastIndexOf(".");
				var imgext=y.substring(imgdotpos+1,imglen);
								
				if((imgext!="jpg")&& (imgext!="gif") && (imgext!="JPG")&& (imgext!="GIF"))
				{
					alert("Company Logo Image Must Be Of Type .jpg Or .gif")
					x.select();
					x.focus();
					return false;
				}
	}	
	//Checking for the special character in the string
function SpecialChar(str)
{
  var chk1 = "!@#$%^*()-+=|\~`{}[]:'<>?/";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid entry");
			return false;
		}

   }
   return true;
}
function SpecialCharProductName(str)
{
  var chk1 = "!@#$%^*()+=|\~`{}[]:'<>?/\"";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid entry");
			return false;
		}

   }
   return true;
}
function isNumInStr(s)

{   var i;

    if (isEmpty(s)) 
       if (isNumDigit.arguments.length == 1) return defaultEmptyOK;
       else return (isNumDigit.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (IsDigit(c)) 
        return false;
    }

    // All characters are numbers. 
    return true;
}
/*
function SpecialCharEmail(str)
{
  var chk1 = "!#$%^*()+=|\~`{} []:'<>?/";
  
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please Enter Valid Email");
			return false;
		}

   }
   return true;
}*/
function SpecialChar1(str)
{
  var chk1 = "!@$%^+=|\~`{}[]:<>?";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid entry");
			return false;
		}

   }
   return true;
}
function SpecialCharDes(str)
{
  var chk1 = "<>";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{
			alert("Please enter valid entry");
			return false;
		}

   }
   return true;
}
function isAlphanumeric (s)

{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || IsDigit(c) ) )
        return false;
    }

    // All characters are numbers.
    return true;
}

/**************************************************************
function : Check(obj)
usage    : To check desimal number of the form ###.##
inputs   : string containing object
output   : returns true if number is valid; otherwise returns false
e.g      : 123.34 is valid decimal number
obj      : id of textbox
**************************************************************/

function check(obj)
{           
	
	var bln=false;
	bln=validateFloat();
	//alert(bln);
	if (bln==true)
	{
	//document.title=obj.value.length;              

            if(obj.value.length >=10)

            {
                        window.event.keyCode=0;

                        return;

            }

            if(window.event.keyCode==46)
            {

                        var ind=obj.value.indexOf(".");

                        if(ind>=0)

                        {
                                    window.event.keyCode=0;                                   

                        }

            }
            
            
            var ind=obj.value.indexOf(".");

            if(ind>0)

            {

                        var sstr=obj.value.substring(ind);
                        //if(sstr.length>2)
                        //window.event.keyCode=0;

            }

		}
		else
		{
			return false;
		}		                        

}
/**************************************************************
	this function is used to toggle selectall checkbox for datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/

			function SelectAll1(chk,dgrid)
			{
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );
				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(frm.elements[i].checked==false)
						{
							chkAll.checked=false;
							break;
						}
					}
					if(chkAll.checked==false)
						chkAll.checked=true;
				}									
			}	
			
/**************************************************************
	this function is used to check/uncheck all checkboxes in a datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function SelectAll(chk,dgrid)
			{	
				var i=0;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );
				
				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						frm.elements[i].checked=chkAll.checked;
					}
				}					
			}	

		
			
/**************************************************************
	this function is called when deleting records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function Delete(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Delete all the records???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Delete selected records???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one record!");
					return false;
				}
			}	

/**************************************************************
	this function is called when deleting users permenently in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function DeleteUser(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Delete all the Users???\n\nThis users accounts will be removed permanently.\n\nAll of user's profile information from Social Networking, including user's photographs, comments, journals, and user's personal network of friends will be removed permanently.\n\nThis information cannot be restored.")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Delete selected Users???\n\nThis users accounts will be removed permanently.\n\nAll of user's profile information from Social Networking, including user's photographs, comments, journals, and user's personal network of friends will be removed permanently.\n\nThis information cannot be restored.")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one record!");
					return false;
				}
			}	
/**************************************************************
	this function is called when EnableAll records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function EnableAll(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Enable all the records???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Enable selected records???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one record!");
					return false;
				}
			}
			
/**************************************************************
	this function is called when DisableAll records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function DisableAll(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Disable all the records???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Disable selected records???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one record!");
					return false;
				}
			}
			
/**************************************************************
	this function is called when closing thread in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function Locking(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Close all the topics???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Close selected topic???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one record!");
					return false;
				}
			}
/**************************************************************
	this function is called when trashing records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function Trash(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Trash all the messages???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Trash selected messages???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one message!");
					return false;
				}
			}	


/**************************************************************
	this function is called when Approving All records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function ApproveAll(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Approve all the requests???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Approve selected requests???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one request!");
					return false;
				}
			}	

/**************************************************************
	this function is called when disapproving All records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function DisapproveAll(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Disapprove all the requests???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Disapprove selected requests???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one request!");
					return false;
				}
			}	
/**************************************************************
	this function is called when Denying All records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function DenyAll(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Deny all the requests???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Deny selected requests???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one request!");
					return false;
				}
			}	

/**************************************************************
	this function is called when deleting records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function DeleteMessages(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Delete all the messages???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Delete selected messages???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one message!");
					return false;
				}
			}	
/**************************************************************
	this function is called when need to check whether alleast one checkbox is checked or not in grid view.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function GridViewCheckAtLeastOneCheckBox(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				
				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}				
				if(blnCheck==false)
				{
					alert("Please select atleast one record!");
					return false;
				}				
			}	
			
/**************************************************************
	call this function to check for int.
	
**************************************************************/
function CheckValueForInt()
		{
			var k;
			k=window.event.keyCode;
			//alert(k);
			if(k==8 || k==9 || k==13)
				return true;
			else if(k>=48 && k<=57)
				return true;
			else
				return false;
		}
	function validemail(frmName, field , msg)  
    {
	    var regEx = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	    var str1 = eval("document."+frmName+"."+field);

        var isValidE = regEx.test(str1.value);
    	
	    if (isValidE)
		    return true;
	    else
        {
		    alert(msg);
		    str1.focus();
		    return false;
	    }
    }	
	function ValidateBlank(p,strMessage)
    {
        if(Trim(document.getElementById(p).value)=="")
	    {
		    alert(strMessage);
		    document.getElementById(p).value="";
		    document.getElementById(p).focus();
		    return false;
	    }
	    return true;
    }
    function ValidateDDL(d,strMessage)
    {
    //////alert("ddl value : "+document.getElementById(d).value);
        if(document.getElementById(d).value==0)
	    {
		    alert(strMessage);
		    document.getElementById(d).focus();
		    return false;
	    }
	    return true;
    }
    
    /// check whether radio button or checkbox is selected or not.Pass control name as r.
    function ValidateRBL(r,strMessage)
    {
        var frm=document.forms[0];
        var flag=false;
		for (i = 0 ; i < frm.length ; i++)
		{
		    if (frm.elements[i].name == r)
			{
			    if (frm.elements[i].checked==true)
				    flag=true;
			}	
	    }
	    if (flag==true)
	        return true;
	    else
	    {
		    alert(strMessage);
		    return false;
	    }
    }


/**************************************************************
	this function is called when deleting friends in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function DeleteFriends(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Delete all the friends???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}
					
				}	
				
				if(blnCheck==true)
				{
					if(window.confirm("Delete selected friends???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one friend!");
					return false;
				}
			}	

/**************************************************************
	this function is called when one want to replace some string with another string.
**************************************************************/
			
			function replaceSubstring(inputString, fromString, toString)
			{
               // Goes through the inputString and replaces every occurrence of fromString with toString
               var temp = inputString;
               if (fromString == "") {
                  return inputString;
               }
               if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
                  while (temp.indexOf(fromString) != -1) {
                     var toTheLeft = temp.substring(0, temp.indexOf(fromString));
                     var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
                     temp = toTheLeft + toString + toTheRight;
                  }
               } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
                  var midStrings = new Array("~", "`", "_", "^", "#");
                  var midStringLen = 1;
                  var midString = "";
                  // Find a string that doesn't exist in the inputString to be used
                  // as an "inbetween" string
                  while (midString == "") {
                     for (var i=0; i < midStrings.length; i++) {
                        var tempMidString = "";
                        for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
                        if (fromString.indexOf(tempMidString) == -1) {
                           midString = tempMidString;
                           i = midStrings.length + 1;
                        }
                     }
                  } // Keep on going until we build an "inbetween" string that doesn't exist
                  // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
                  while (temp.indexOf(fromString) != -1) {
                     var toTheLeft = temp.substring(0, temp.indexOf(fromString));
                     var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
                     temp = toTheLeft + midString + toTheRight;
                  }
                  // Next, replace the "inbetween" string with the "toString"
                  while (temp.indexOf(midString) != -1) {
                     var toTheLeft = temp.substring(0, temp.indexOf(midString));
                     var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
                     temp = toTheLeft + toString + toTheRight;
                  }
               } // Ends the check to see if the string being replaced is part of the replacement string or not
               return temp; // Send the updated string back to the user
            } 

/**************************************************************
	this function is called when seting articles records in 
	datagrid to be displayed on Home page.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function SetArticle(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Set all the Articles???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}					
				}
				
				if(blnCheck==true)
				{
					if(window.confirm("Set selected Articles???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one Article to set!");
					return false;
				}
			}	
			
			
/**************************************************************
	this function is called when removing articles records in 
	datagrid to be displayed on Home page.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function SetArticleRemove(chk,dgrid)
			{
				var blnCheck;
				var frm=document.forms[0];
				var chkAll =eval("frm." + chk );

				blnCheck=false;
				if(typeof(chkAll)=="undefined")
					return false;
				if(chkAll.checked==true)
				{
					if(window.confirm("Remove all the Articles???")==true)
						return true;
					else
						return false;
				}

				for (i = 0 ; i < frm.length ; i++)
				{
					if (frm.elements[i].type == "checkbox" && frm.elements[i].name.indexOf(dgrid) > -1)
					{
						if(blnCheck=frm.elements[i].checked==true)
							break;						
					}					
				}
				
				if(blnCheck==true)
				{
					if(window.confirm("Remove selected Articles???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one Article to remove!");
					return false;
				}
			}	
			
			
			
			/////////////////////////
			function clickButton(e, buttonid)
			{ 
			    var bt = document.getElementById(buttonid); 			
			    if (typeof bt == 'object')
			    { 
			            if(navigator.appName.indexOf("Netscape")>(-1))
					    { 
						    if (e.keyCode == 13)
						    { 
								    //bt.onclick;
								    //alert("test");
							        bt.focus();
							        bt.click();
								    return false; 
						    } 
					    } 
					    if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
					    { 
						    if (event.keyCode == 13)
						    { 
								    bt.click(); 
								    bt.focus();
								    return false; 
						    } 
					    } 
			    } 
		    }




/**************************************************************
	Description:Function to restrict alphabets to be entered in 
	textbox allows only numeric value
**************************************************************/
function checkNum(obj)
 {
  var carCode = event.keyCode;
  
      if (((carCode < 48) || (carCode > 57))&&(carCode!=46))
      {
        //alert('Please enter only numbers.');
       event.cancelBubble = true
       event.returnValue = false;
      }
 } 
 
 /**************************************************************
	Description:Function to set all the textboxes checked if 
	header checkbox is selected  
**************************************************************/
  function SelectAllCheckboxes(chkSelectAll)
  {

   var oItem = chkSelectAll.children;
   var theBox= (chkSelectAll.type=="checkbox") ?chkSelectAll :chkSelectAll.children.item[0];
   xState=theBox.checked;
   elm=theBox.form.elements;
   for(i=0;i<elm.length;i++)
   if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
   {
      if(elm[i].checked!=xState)
         elm[i].click();
    }
 }
