//this function is used to check all or uncheck all the check box when a CHECK ALL check box is checked

//this function is used to check whether only one check box is checked


//this function is used to check whether only one check box is checked

		
// this function is to check whether the from date is less than to date		
function isAlpha(parm) {
var lwr = 'abcdefghijklmnopqrstuvwxyz';
var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
val=lwr+upr;
if (parm == "") return false;
for (i=0; i<parm.length; i++) {
if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
return true;
}
function startTime()
{
var today=new Date()
var h=today.getHours()
var m=today.getMinutes()
var s=today.getSeconds()
// add a zero in front of numbers<10
m=checkTime(m)
s=checkTime(s)
document.getElementById('lbltime').innerHTML=h+":"+m+":"+s
t=setTimeout('startTime()',500)
}

function checkTime(i)
{
if (i<10) 
  {i="0" + i}
  return i
}

function msg(val)
{
	if (val=="1")
	{
		alert('Please enter an e-mail id');
		return false;
	}
	else if (val=="2")
	{
		//alert('Enter Correct email id');
		alert('one or more email addresses entered is invalid');
		return false;
	}
	else if (val=="3")
	{
		alert('Your friend has been referred already');
		return false;
	}
	
	else if (val=="4")
	{
		alert('Thank You For Refering the Site');	
		return true;
	}
}  

function ref(val)
{
	if (val=="1")
	{
		document.getElementById("td1").style.display="none";
	document.getElementById("td3").style.display="none";
	document.getElementById("td4").style.display="none";
	document.getElementById("td5").style.display="none";
		return false;
	}
	else if (val=="2")
	{
		document.getElementById("td1").style.display="none";
	document.getElementById("td2").style.display="none";
	document.getElementById("td4").style.display="none";
	document.getElementById("td5").style.display="none";
		return false;
	}
	else if (val=="3")
	{
		document.getElementById("td1").style.display="none";
	document.getElementById("td2").style.display="none";
	document.getElementById("td3").style.display="none";
	document.getElementById("td5").style.display="none";
		return false;
	}
	
	else if (val=="4")
	{
		document.getElementById("td2").style.display="none";
	document.getElementById("td3").style.display="none";
	document.getElementById("td4").style.display="none";
	document.getElementById("td5").style.display="none";
		return true;
	}
	
	else if (val=="5")
	{
	document.getElementById("td1").style.display="none";
	document.getElementById("td2").style.display="none";
	document.getElementById("td3").style.display="none";
	document.getElementById("td4").style.display="none";
	}
}

function dateCompare(dt1, dt2){ 
var dt1_dt = Date.parse(dt1.value); 
var dt2_dt = Date.parse(dt2.value); 
if (!dt1_dt){ 
alert('The entry in the from field is not a valid date'); 
dt1.focus(); 
return false; 
} 
else if (!dt2_dt){ 
alert('The entry in the to field is not a valid date'); 
dt2.focus(); 
return false; 
} 
else if (dt1_dt >= dt2_dt) { 
alert("To date should be greater than From date."); 
dt2.focus(); 
return false; 
} 
else{ 
alert('The difference between the two dates you entered is: '+(dt2_dt-dt1_dt)/86400000+' day(s).'); 
return true; 
} 
} 



function FromLessTo(from,to)
{
	var day = from.substring(0,2);
	var mon = from.substring(3,5)-1;
	var yar = from.substring(6,10);
	var datfrom =  new Date(yar,mon,day);

	var day = to.substring(0,2);
	var mon = to.substring(3,5)-1;
	var yar = to.substring(6,10);
	var datto =  new Date(yar,mon,day);

	if (datfrom < datto)
		return true;
	else 
		return false;
}		
//This function is called when the delete button is pressed
		
//This function will check for alphanumerci characters

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<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  
		  }
		else	
		  {
		    
		     
			 return false;
		  }
		}
 return true;
}


// date validation  for dd/mm/yyyy. <---START HERE---> 

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=3000;

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 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 strDay=dtStr.substring(0,pos1)
	var strMonth=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){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}
// date validation  for dd/mm/yyyy. <---END HERE---> 
//this function check the given value is decimal
function isDecimal(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (oRegExp.test(strString))
    {

         return true;
    }
    else
    {
   
   return false;
    }
}




//this function check the given value as correct no.of.days
/*function isNoDays(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}
*/

//this function check the given value is decimal
function isAmount(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (strString > 999999999999.99)
{
 return false;
}


if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}


		function isAmountValid(strString)
			{
			var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
			if (strString > 999999999999999.99)
			{
			return false;
			}


			if (oRegExp.test(strString))
				{
				if (strString.indexOf(".") == -1 )	
					{
						return true;
					}
				else
					{  
					if (strString.indexOf(".") == strString.length - 3 || strString.indexOf(".") == strString.length - 2)
		 					{return true;}
					else
							{return false;}
					} 
				}
				else
				{
					return false;
				}
			}

//this function check the given value is decimal
function isNoDays(strString)
{
var oRegExp = /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
if (strString > 999.9)
{
 return false;
}


if (oRegExp.test(strString))
    {
	  if (strString.indexOf(".") == -1 )	
	     {
	        return true;
	     }
	  else
	    {  
		  if (strString.indexOf(".") == strString.length - 3  || strString.indexOf(".") == strString.length - 2 || strString.indexOf(".") == strString.length)
		 		{return true;}
		  else
				{return false;}
        } 
    }
    else
    {
		return false;
    }
}


//this function check the given value is Email
function isEmail(strEmail)
{
	var oRegExp = /^[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]$/g;
	if (oRegExp.test(strEmail))
    {
         return true;
    }
    else
    {
		return false;
    }
}




function echeck(str) 
{


	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	if (str.indexOf(at)==-1)
	{

				return false;
	}

if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
{
				 return false;		
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
{
		
		 return false;

}		
 if (str.indexOf(at,(lat+1))!=-1)
{		   
 
 return false;		
 }
 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
{	    

return false;
}
if (str.indexOf(dot,(lat+2))==-1)
{

return false;
 }	
//if (str.indexOf()!=-1)
//{
	//alert(Invalid E-mail ID)
 //return false		 
//}		 
return true	

}

function checkEmail(strEmail)


    {
    	ok=true
    	if(strEmail=="")
        	{
        	//	alert("Please enter e-mail address.")
        		
        		ok=false
        	}
        	else


            	{
            		mail=strEmail
            		at_pos=mail.indexOf("@")
            		dot_pos=mail.indexOf(".")
            		if((at_pos<0)||(dot_pos<0)||(dot_pos<at_pos))


                		{
                	//		alert("Please check position of '@' and '.' in email address.")
                		//	strEmail.focus()
                			ok=false
                		}
                		else


                    		{
                    			mail=strEmail
                    			condition="yes"
                    			var at_count=0
                    			var dot_count=0
                    			for(var i=0;i<mail.length;i++)


                        			{
                        				if((mail.charCodeAt(i)>0 && mail.charCodeAt(i)<48)||(mail.charCodeAt(i)>57 && mail.charCodeAt(i)<65)||(mail.charCodeAt(i)>91 && mail.charCodeAt(i)<97)||(mail.charCodeAt(i)>122))


                            				{
                            					if((mail.charAt(i)=="@") || (mail.charAt(i)=="."))


                                					{
                                						if(mail.charAt(i)=="@"){at_count++}else{dot_count++}// counts the no. of times @ and . appears in email
                                					
                                					}
                                					else
                                 					{
                                    						condition="no"
                                    						i=mail.length
                                    					}
                                    				}
                                    			}
                                    			if(condition=="no")


                                        			{
                                        			
                                        				ok=false
                                        			}
                                        			else


                                            			{
                                            				if(at_count>1 || dot_count>1)


                                                				{
                                                					
                                                					ok=false
                                                				}
                                                				else


                                                    				{
                                                    					pos=dot_pos-at_pos
                                                    					if(pos<2)


                                                        					{
                                                        						
                                                        						ok=false
                                                        					}
                                                        					else


                                                            					{
                                                            						count=dot_pos+1
                                                            						domain=""
                                                            						for(count;count<mail.length;count++)


                                                                						{
                                                                							domain=domain+mail.charAt(count)
                                                                						}
                                                                						dom=new Array("com","net","org","edu","in","mil","gov","arpa","biz","aero","name","coop","info","pro","museum")
                                                                						error="yes"
                                                                						for(var k=0;k<dom.length;k++)


                                                                    						{
                                                                    							if(domain==dom[k])


                                                                        							{
                                                                        								k=dom.length
                                                                        								error="no"
                                                                        							}
                                                                        						}
                                                                        						if((error=="yes" && (domain.length>2)) || (domain.length<2))


                                                                            						{
                                                                            							
                                                                            							ok=false
                                                                            						}
                                                                            					}
                                                                            				}
                                                                            			}
                                                                            		}
                                                                            	}
                                                                            	return ok
                                                                        }



//this function check given value for valid WEBSITE address
function isWeb(theUrl)
{
  if(theUrl.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ||
	 theUrl.match(/^(www)\.\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ||
     theUrl.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i)  
     )
      {
		return true;
	  }
   else 
	  {
		return false;
	  }

}




//this function used to check the value to be empty
function isEmpty(strString)
{
if (((strString == null) || (strString.length == 0)))
{
	return true;
}
else
{

var strLen= strString.length;
var intLen=0;
	for(intLenIndex=0; intLenIndex < strLen ; intLenIndex++)
	{
		
		/*	if(strString.charAt(intLenIndex)==String.fromCharCode(13))//This will check ENTER KEY VALUE 
			{
			   intLen=intLen+2;
			}
			else
			{
		*/
				//if(strString.charAt(intLenIndex)==" ")
				if(strString.charAt(intLenIndex)==" ") 
						{
							intLen=intLen+1;
						}
		//	}	    
	}
	
	if (intLen==strString.length)
	{
			return true;
	}		
	else
	{	
		return false;
	}
}
}


//this function check the given value is number
function isNumber(strString)
{

var oRegExp = /(^-?\d\d*$)/;

if (oRegExp.test(strString))

    {

         return true;
    }
    else
    {
   
   return false;
    }
}


// phone number Validation <--START HERE -->

// Declaring required variables
var digits = "0121456789";

// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ,";

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 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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isPhone(strPhone)
{
	var cnt=0;
	s=stripCharsInBag(strPhone,phoneNumberDelimiters);
	if (isInteger(s))
	{
		if ((isSpecial(strPhone.charAt(0),"(")==false) && (isNumber(strPhone.charAt(strPhone.length-1))==true) )
			{
				for (i = 0; i < strPhone.length; i++)
				{
						if (strPhone.charAt(i)=="(") {cnt++;}
						if (strPhone.charAt(i)==")") {cnt--;}
				}				
				if (cnt==0)
					{return true;}
				else 
					{return false;}
			}
		else
			{
				return false;
			}
	}
	else
	{
		return false;
	}		
	
}


// phone number Validation <--END HERE -->


//this function used to check the positive decimal value
function isPositiveDecimal(strString)
{
	var blnReturn;
  	if (parseFloat(strString)>=0)
	{
		blnReturn =true;
	}
	else
	{
		blnReturn=false;
	}

return blnReturn;
}


//This function will check for blank spaces 
function isSpace(strString)
{	
	var strLen= strString.length; 	
	var blnReturn;
	//blnReturn = true;
	for(intLenIndex=0; intLenIndex < strLen ; intLenIndex++)
	{
		if(strString.charAt(intLenIndex)==" ")
		{
			//strString.IsValid = false;			 
			//blnReturn =false; 
			return false;
		}
	}	    
	//return blnReturn;  
	return true;
}

//This function will check whether it contains any special characters with given chars
function isSpecial(strString,strSplChar)
{
  var blnReturn;
  var strFound;
  blnReturn=false;
  var strvalue;
   
  strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1214567890" + strSplChar;
  
  for (intLoop=0;intLoop<strString.length;intLoop++)
  	{
		
	   if ((strvalue.indexOf(strString.charAt(intLoop)))<0)
	   		{ 
				blnReturn=true;
			}
	}
	return blnReturn;
}

//This function will check whether it contains any special characters with given chars
function isChar(strString,strSplChar)
{
  var blnReturn;
  var strFound;
  blnReturn=false;
  var strvalue;
     
  strvalue = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + strSplChar;
    
  for (intLoop=0;intLoop<strString.length;intLoop++)
	{
		
	   if ((strvalue.indexOf(strString.charAt(intLoop)))<0)
			{ 
				blnReturn=true;
 			}
	}
	return blnReturn;
}



//function to get the current date
function currentdate()
	    {
		  	 datX=new Date();
			 datY=new String(new Date());
					
			if (navigator.appName=="Netscape")
				{
							if (parseFloat(navigator.appVersion.substring(0,3))>4.01)
							{
								thisYear=parseInt(datY.substring(51,55))
							}
							else
							{
								thisYear=datX.getYear();
							}
				}
				else
				{
						thisYear=datX.getYear();
				}
			thisMonth=datX.getMonth()+1;
			thisDate=datX.getDate();
		  return ((thisDate+'/'+thisMonth+'/'+thisYear));
	    }		


//Date Comparison
function datecompare(arguments1, arguments2,arguments3)
		{
		 // to check date1 as valid Date
		    dategiven=arguments1;
	        datX=new Date();
			datY=new String(new Date());
			
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
		
			d1=Date.UTC(year,month,day,0,0,0,0)
			// check for second date
			dategiven=arguments2;
					datX=new Date();
					datY=new String(new Date());
						
			var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;
			var matchArray = dategiven.match(datePat); // is the format ok?

			month = matchArray[3]; // parse date into variables
			day = matchArray[1];
			year = matchArray[4];
			
			d2=Date.UTC(year,month,day,0,0,0,0)
							
						
			// check for date 
			if (arguments3 == "<" )
				{
					if(d1<d2)
						{ return  true;	}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '<=' )
				{
					if(d1<=d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '>' )
				{
					if(d1>d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
				
			if (arguments3 == '>=' )
				{
					if(d1>=d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
							
			if (arguments3 == "=" )
				{
					if(d1==d2)
						{ return  true;}
					else
					 	{ return  false; }
				}
							
		  return false;  
		 
			}

  			
// This function will return the Selected Date to the CtrlName Control.
 function GetDate(CtrlName)
 {
	ChildWindow = window.open('../calendar/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar", "width=212,height=198,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no,minimize=no,maximise=no");    
 }
 
 
//This is used to check the currency format 
 function currencyCheck(mystr)
{
	var blnreturn;
	   	
	var c=Number(0);
	
	for(i=0;i<mystr.length;i++)
	{
		if(mystr.charAt(i)==".")
		{
			c=c+1;
				
		}
	}
	if(c>1)
	{
		return true
	}
	else
	{
		  	if ((mystr.charAt(0)==".") || (mystr.charAt(mystr.length-1)==".") )
   			{
     		//return bln=true;
				return true
			}
		  	else
   			{
				subs=mystr.substr(mystr.indexOf("."));
				if(subs.length>3)
					return true
				else
					return false
			}
	}
	
}

function LTrim(str) {
 for (var i=0; str.charAt(i)<=" "; i++);
 return str.substring(i,str.length);
}

function rev(str) {
    var s = "";
    var i = str.length;
    while (i>0) {
        s += str.substring(i-1,i);
        i--;
    }
    return s;
}

function RTrim(str) {
 for (var i=str.length-1; str.charAt(i)<=" "; i--);
 return str.substring(0,i+1);
}

function isSpacebar(str)
{
	var strLen=str.length;
	if (str.charAt(0)==" ")
	{
		return true;
	}
	
	if (str.charAt(strLen-1)==" ")
	{
		return true;
	}
	return false;
}

// This function will return the Selected Date to the CtrlName Control.
 function GetDate(CtrlName)
 {
	ChildWindow = window.open('../Calender/Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' + CtrlName, "PopUpCalendar", "width=212,height=198,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no,minimize=no,maximise=no");    
 }
	
// This function will limit the maxlength for a TextArea.it will be used like this, in Textbox tag
// onKeyDown="maxlength(document.forms[0].field,250)" onKeyUp="maxlength(document.forms[0].field,250)"
function maxlength(field,maxlimit)
			{
				if (field.value.length > maxlimit)
				field.value = field.value.substr(0, maxlimit);
			}

//Open a new URL
 function vOpen(strUrl)
			{
				window.open(strUrl); 
			}
	
	//date compare function

function DateValidate(Dat1,Dat2)
		{
			var d1;
			var d2;
			
					d1=Dat1.split('/');
					d2=Dat2.split('/');
					var Date1=new Date(d1[2],d1[1],d1[0]);
					var Date2=new Date(d2[2],d2[1],d2[0]);
					if (Date1 > Date2)
					 { 
						return false ; 
					} 	
					return true;
      	}		
     
  // function YearValidate(Dat1,Dat2)
//		{
//			var d1;
//			var d2;
			
//					d1=Dat1.split('/');
//					d2=Dat2.split('/');
//					var Date1=new Date(d1[2],d1[1],d1[0]);
//					var Date2=new Date(d2[2],d2[1],d2[0]);
//					if (Date1 > Date2)
//					 { 
//						return false ; 
//					} 	
//					return true;
  //    	}		
   	


//this function is used to check all or uncheck all the check box when a CHECK ALL check box is checked
//this function is to check whether add,edit,delete and view check box are checked r not

