//Only Numeric Value allowed
function Numeric(el)
{   
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        if ( event.keyCode < 48 || event.keyCode > 57 )
        {
            event.keyCode = 0;
        }
	}
	var KeyID = el.keyCode ? el.keyCode : el.which;
	if((KeyID >= 65 && KeyID <= 90) || (KeyID >= 97 && KeyID <= 122) || (KeyID >= 33 && KeyID <= 47) ||
       (KeyID >= 58 && KeyID <= 64) || (KeyID >= 91 && KeyID <= 96) || (KeyID >= 123 && KeyID <= 126))
    {
        return false;
    }
var KeyID = el.keyCode ? el.keyCode : el.which;
//alert(KeyID); && KeyID != 32
	if (KeyID != 8 && KeyID != 9 && KeyID != 45 && KeyID != 95 && KeyID != 46 && KeyID != 64)
    {
        if ( KeyID >= 0 && KeyID <= 47 )
        {
            return false;
        }
//        else if ( KeyID >= 58 && KeyID <= 96 )
//        {
//            return false;
//        }
        else if ( event.keyCode >= 58 && event.keyCode <= 64 )
	        {
	            return false;
	        }
	         else if ( event.keyCode > 90 && event.keyCode <= 96 )
	        {
	            return false;
	        }
        else if ( KeyID >= 123 && KeyID <= 254 )
        {
            return false;
        }
    }
    return true;
}


//Validate Textbox in grid
function CheckDecimal(dgrid)
			{
				var CheckDeci;
				var frm=document.forms[0];
				for (i = 0 ; i < frm.length ; i++)
				{
				    //alert(frm.elements[i].type);
				    //alert(frm.elements[i].name.indexOf(dgrid));
					if (frm.elements[i].type == "text" && frm.elements[i].name.indexOf(dgrid) == 0)
					{
						if(frm.elements[i].value != null && frm.elements[i].value != '')
						{
						    CheckDeci = frm.elements[i].value;
						    //alert(CheckDeci);
						    if(IsDecimalAndDate(CheckDeci)==false)
						    {
						        alert("Please enter decimal no.")
						        frm.elements[i].focus();
						        return false;
						    }
						    else if(frm.elements[i].value > 24)
						    {
						        //alert(frm.elements[i].value);
						        alert("Please enter valid hours, below 24 Hours")
						        frm.elements[i].focus();
						        return false;
						    }
						}
						else
						{
						    alert("Please enter valid no.")
						    frm.elements[i].focus();
						    return false;
						}
						
					}
					
				}	
			}

//Enter Click
function clickButton(e, buttonid)
			{ 
			var bt = document.getElementById(buttonid); 
			if (typeof bt == 'object')
			{ 
			        if(navigator.appName.indexOf("Netscape")>(-1))
					{ 
						if (e.keyCode == 13)
						{ 
								bt.click();
								return false; 
						} 
					} 
					if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1))
					{ 
						if (event.keyCode == 13)
						{ 
								bt.click(); 
								return false; 
						} 
					} 
			} 
		}
/************************************************************
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 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("-")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("E")!=-1)
	{
		return false;
	}
	if(isNaN(strNum))
	{
		return false;
	}
	return true;
} 


function IsDecimalAndDate(strNum)
{
	if(strNum.length==8)
	{
	    return true;
	}
	if(strNum.indexOf("e")!=-1)
	{
		return false;
	}
	if(strNum.indexOf("-")!=-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)
	
	alert(dtStr);
	
	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 CheckSpecialChar(str)
{
  var chk1 = "!@#$%^*()-+=|\~`{}[]:'<>?/0123456789";
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1=chk1.indexOf(ch);
	if (rtn1 != -1)
		{			
			return false;
		}

   }
   return true;
}

function CheckAlphabets(str)
{
  var chk1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    
  for(var i=0;i<str.length;i++)
   {
	var ch=str.charAt(i);
	var rtn1 = chk1.indexOf(ch);
	
	if (rtn1 == -1)
		{			
			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 alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 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 Activating records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function Activate(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("Activate 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("Activate selected records???")==true)
						return true;
					else
						return false;
				}
				else
				{
					alert("Please select atleast one record!");
					return false;
				}
			}	

/**************************************************************
	this function is called when Deactivating records in datagrid.
	chk   : SelectAll checkbox name.
	dgrid : datagrid name
**************************************************************/
			
			function Deactivate(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("Deactivate 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("Deactivate selected records???")==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 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
            } 