
//function to detect browser

function getbrowser()
{
	if (navigator.appName =="Netscape")
	strBrowser = "Netscape"
	else
	strBrowser = "IE"
	return strBrowser;
}

//function to populate Listboxes for day month year

function showlistmdy(month,day,year)
{	//idx=document.frm.month.selectedIndex
	//alert(document.frm.month(idx).value)
	idx=month.selectedIndex
	switch(idx)
	{	case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			fillDay(31,month,day,year)
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			fillDay(30,month,day,year)
			break;
		case 2:
			fillLeap(month,day,year)
			break;
		default:
	}
}

function fillDay(len,month,day,year)
{	
	limit=day.length
	optArray=new Array()
	
	day.options.length=0	
	
	optArray[0]=new Option("Select Day",0,true,true)
	eval("day.options[0]=optArray[0]")
	
	for(i=1;i<=len;i++)
	{	optArray[i]=new Option(i,i,false,true)
		eval("day.options[i]=optArray[i]")
	}
	day.selectedIndex=0
}

function fillLeap(month,day,year)
{
	if(month.selectedIndex!=0 && year.selectedIndex!=0)
	{	calcleap(month,day,year)
	}	
	else
	{	alert("Please select month and year")
		return	
	}
	 



}
function calcleap(month,day,year)
{	idx=year.selectedIndex
	yr=year(idx).value
	if(month.selectedIndex==2)
	{	leap=false
		if(yr%4==0)
		{	if(yr%100==0)
			{	if(yr%400==0)
					leap=true
				else
					leap=false
			}
			else
			{	leap=true
			}
		}
		else
			leap=false
			
		if(leap==true)
			fillDay(29,month,day,year)
		else
			fillDay(28,month,day,year)
	}
	

}

//End funtion to populate LB's forDay month year

function getnumbervalue(split_what,name,split_by)
{
	cookie_value=removespace(split_what)
	cookie_array=cookie_value.split(split_by)
	x=cookie_array.length
	for (i=0; i<10; i++)
	{
		x=cookie_array[i]
		y=x.split ("=")
		for (j=0; j < y.length; ++j)
		{
		//alert (y[j])
			if (y[j]==name)
			{
				++j
				return (y[j])
			}
			else
			{
				return 0
			}
		}
	
	}
}

function removespace(value)
{
	new_value=""
	for (i=0; i < value.length; ++i)
	{
		if (value.charAt(i)!=" ")
		{
			new_value= new_value + value.charAt(i)
		}
	}
	value=new_value
	return value
}


function GetCityList()
{
//ideally lbState should be passed - should and can be generalized
  var sIndex,statename,ctl,win
  ctl = document.thisForm;
  sIndex = ctl.lbState.selectedIndex;
  statename = ctl.lbState[sIndex].value;
  win = window.open("../includes/getcitylist.asp?state=" + statename,"newwin","toolbar=no,location=no,directories=no,status=yes,menubar=no,top=15,left=25,width=500, scrollbars=yes,resizable=no") 
  
}

function Attachment()
{// to get attachemnts
  var sIndex,statename,ctl,win
  ctl = document.thisForm;
  win = window.open("attachments.asp" ,"newwin","toolbar=no,location=no,directories=no,status=yes,menubar=no,top=15,left=25,width=500, scrollbars=yes,resizable=no") 
  
}


// date validation 

function validateDate(str,ident)
{ var i,errormsg ;
      errormsg = "" ;
 
if (str == "")
	{
		errormsg = errormsg + "Please Enter "  + ident + "\n"
	}
  else
   { 
  
	 strslash = str.indexOf("/")
  
			if (strslash == -1) 
				errormsg = errormsg + "Invalid Format For "  + ident + ", Use mm/dd/yy or mm/dd/yyyy \n "
			else
			{
				var  today = new Date()

				a1=today.getMonth() 
				b1 =today.getDate() 
				c1 =today.getYear() 

				var now1 = new Date(c1,a1,b1)

				
				one = str.indexOf("/")
				a = str.substr(0,one)
				two = str.indexOf("/",one+1)
				b = str.substr(one+1,two)
				b = b.substr(0,b.indexOf("/"))
				c = str.substr(two+1,str.length)
               
                strtext = "0123456789/"
                errmsg = ''
				for (i = 0;i < str.length ; i++)
		        {    
			      ch = str.charAt(i);
			      if (strtext.indexOf(ch) == -1)
                  errmsg = " Invalid  " + ident +" format \n"
		       }
			   
			   if (errmsg!='')
			   errormsg = errormsg + errmsg +"\n"
			   else
			   {
				month = parseInt(a,10)
				day =   parseInt(b,10)
				year =  parseInt(c,10)
				
				if ((year%4) == 0)
				{
					leap = true
				}
				else
				{
					leap = false
				}

				var now = new Date(year,month,day)

				
				if (month < 1  || month > 12 || a == '')
				{
				errormsg = errormsg + "Invalid Month \n"
				}
                
                if (month==2 && leap ) 
				{
					if (day < 1 || day > 29 || b == '')
					errormsg = errormsg + "Invalid day \n"
				}
                
                if (month==2 && !leap ) 
				{
					if (day < 1 || day > 28 || b == '')
					errormsg = errormsg + "Invalid day \n"
				}
				
				if ((month==4) ||( month==6) || (month==9) || (month==11 ) )
				{
					if ((day < 1) ||( day > 30) || (b==''))
					errormsg = errormsg + "Invalid day \n"
				}
                
                if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12 ) 
				{
					if (day < 1 || day > 31 || b=='')
					errormsg = errormsg + "Invalid day \n"
				}
				
                              
               if (( c.indexOf("/") != -1) || ((c.length !=2) && (c.length !=4)))
               {
               	errormsg = errormsg + "Invalid Year \n"
               } 
                
				if (year>9999 && year <0)
				{
					errormsg = errormsg + "Invalid Year \n"
				}

                } // msg if end
    		}
			
			if (Date.parse(str) < Date.parse("1/1/1753"))
			{
			errormsg = errormsg + " Date Must Be Greater Than 1/1/1753\n"
			}
			
     
  }
  
return errormsg ;      	

}

// time validation
function validateTime(str,ident)
{ var i,errormsg ;
      errormsg = "" ;
  
if (str == "")
	{
		errormsg = errormsg + "Please Enter "  + ident
	}
  else
    { 
    
		  strtwo = str.substring(0,2)
		  
	if (( strtwo == "am" ) || ( strtwo == "AM" ) || ( strtwo == "pm" ) || ( strtwo == "PM") || (strtwo=="Am") ||(strtwo=="Pm"))
		   {
		   errormsg = errormsg + "Please Enter "+ ident +"\n"
		   }
    else
		  {
	  	strtext ="0123456789ampAMP: "
        for (i = 0;i < str.length ; i++)
		   {    
			 ch = str.charAt(i);
			 if(strtext.indexOf(ch) == -1)
             errormsg = " Invalid " + ident 
		   }
		
			if (errormsg=='')
			
				{
				 strAM = str.substring(str.length-2,str.length)
				
				if (( strAM != "am" ) && ( strAM != "AM" )&& ( strAM != "pm" ) && ( strAM != "PM")&&(strAM!="Am") &&(strAM!="Pm"))
				{
				errormsg = errormsg + "Please Enter AM or PM in "+ ident +"Slot\n"
				}
			}
		}	
  }
return errormsg ;      	
}

// validate function for Numeric values like Zipcode, postrange, password etc.

function validate(str,strtext,ident)
{ 
 var i,errormsg ;
      errormsg = "" ;
    
	if (str == "")
	{
		errormsg = "Please Enter "  + ident
	}
	else
	{   
	
			for (i = 0;i < str.length ; i++)
		   {
			 ch = str.charAt(i);
			 ch = ch.toLowerCase();
			 if(strtext.indexOf(ch) == -1)
             errormsg = " Invalid  " + ident 
             if (ch==" " && strtext.indexOf(ch) == -1)
             errormsg =  " Spaces are not allowed - Invalid  " + ident  
		   }
		 
	}
	
     return errormsg ;      
}

// eg :validating atleast 5 char in a zipcode

function minnumber(str,minnum,ident)
{
var errormsg ;
      errormsg = "" ;
val = str.length

if (parseInt(val) < parseInt(minnum))
errormsg = " Enter minimum "+ minnum + " " + ident 

return errormsg ;      
}
//eg: Enter not more than 9 nosfor Zip
function maxnumber(str,maxnum,ident)
{
var errormsg ;
      errormsg = "" ;
val = str.length

if (parseInt(val) > parseInt(maxnum))
errormsg = " Enter maximum "+ maxnum + " " + ident 

return errormsg ;      
}


// to eliminate the repeating char if not reqd, eg ht: 5.1.235 should be error 5.1 is correct
function elimrepeat(str,ch,ident)
{      errormsg = "" ;
atcount = 0;
		for (i = 0;i < str.length ; i++)
         {    
         vch = str.charAt(i);
         
         if (vch == ch )
         atcount ++ 
         
         }
         
         if (atcount > 1) 		    
         {
	     errormsg = " Too Many '"+ ch + "' - Invalid  " + ident 
	    
		 }
	  return errormsg ;      

}


//Compare dates
function comparedates(start_date,end_date)
{

//x = parseInt(start_date.indexOf("/",3),10) + 
//alert(x)
//y = start_date.substring(x+1,12)
//alert(y)
/*if (start_date.length> 9 )
{
	x = start_date.substring(6,9)
	alert(x)
	if ( x == "20" )
	{
		start_date = start_date.substring(0,6) + start_date.substring(8,9)
		alert(start_date)
	}
} 
else 
{
	alert("no")
}*/

//var stdate = new Date()
stdate = Date.parse(start_date)
//var eddate = new Date()
eddate = Date.parse(end_date)

if (stdate > eddate)
	{
	ErrorMsg = "Error : StartDate is After EndDate\n"
	}
else 
	{
	ErrorMsg = ""
	}
return ErrorMsg
}

// Validate Email
function validateEmail(str,ident)
{
  var i,errormsg;
        errormsg = "" ;
         if( str == "")
         errormsg = "Please Enter " + ident 
         else
         {
			if(str.indexOf("/") != -1)
			errormsg = " / not allowed -Invalid  " + ident 
			if(str.indexOf("@") == -1)
			errormsg = " @ not Present -Invalid  " + ident 
			if(str.indexOf(".") == -1)
			errormsg = " Dot Not Present - Invalid  " + ident 
			if(str.indexOf(" ") != -1)
			errormsg = " Spaces not Allowed - Invalid  " + ident 
			if(str.indexOf('@')!=-1 && str.indexOf('.',str.indexOf('@'))!=-1)  
			{	//
			}
			else
			{	
				
				errormsg = "Invalid " + ident 	
			}
			
        //if(str.indexOf(".") != str.length-4)
        //errormsg = " Invalid " + ident 
          
         atcount = 0;
         for (i = 0;i < str.length ; i++)
         {    
			ch = str.charAt(i);
			if (ch == "@" )
			atcount ++       
         }
         if (atcount > 1) 		    
			errormsg = " Invalid " + ident
	      
	 }
	  return errormsg ;      

}
// Another function for EmailVildations by Sumeet

function validate_email(stremail)
{
	msg=""
	str_length=stremail.length
	flag1=0
	flag2=0
	flag3=0
	flag4=0
	flag5=0
			for (counter=0;counter < str_length;++counter)
			{
				schar = stremail.charAt(counter)
				if (!(((schar >= "0") && (schar <= "9")) || ((schar >= "a") && (schar <= "z")) || ((schar >= "A") && (schar <= "Z")) || (schar == "_") || (schar == "-") || (schar == ".") || (schar == "@")))
				{
				    msg= msg+"\n Email address has invalid character '"+schar+"'."
				    flag1=1
				}
			}
			count=0
//******************************************************************
			
			do //check that e-mail is : xyz@something & not xy@something
			{
				a=stremail.charAt(count)
				if (a=="@")
				{
					if ((count+1)<=3)
					{
						msg= msg+"\n The email address should have 3 characters before @"
						flag4=1
					}
					if ((stremail.charAt(count-1)=="."))
					{
						msg =msg+ "\n The e-mail address must not have a ' @ ' immediately after a ' . '"
						flag4=1
					}
					if ((stremail.charAt(count+1)==""))
					{
						msg=msg+ "\n The e-mail address must have something ahead of ' @ '"
						flag4=1
					}
					store=count+1
					count=str_length
					flag2=1
				}
				else
				{
					store=0
				}
				count+=1
			}
			while ((count<  str_length) && (flag1==0))
//****************************************************************			
			if (flag1==0 && flag2==0)//if there is no @
			{
				msg=msg+ "\n Confirm the e-mail address. It should have 1 '@' & 1 '.'"
				flag4=1
			}
//*****************************************************************	
			count=store
			do 
			{
			a=stremail.charAt(count)
				if (a=="@" || a==".")
				{	
					if (a=="@")// More than 1 @ not allowed
					{
					msg=msg+ "\n More than 1 '@' not allowed"
					count=str_length
					flag3=1
					}
					else
					{
						flag5=1
						if ((count+1)==str_length)
						{
							msg= msg+ "\n There should be something ahead of '.'... like .com, .org"
							count=str_length
							flag3=1
						}
						if ((count+1)<=(store+3))//   ###@xyz.## & not ###@xy.##
						{
							msg=msg+ "\n The email address should have 3 characters between '@' & '.'"
							count=str_length
							flag3=1
						}
						else
						no_of_dots=0
						for (c=(count+1);c < str_length;++c)
							{
								if (stremail.charAt(c)==".") // cant be ###@####.####.###
								{
									no_of_dots=no_of_dots+1
									if (no_of_dots>2)
									{
										msg=msg+ "\n There cant be more than 2 '.' after the ' @ ' "
										c=str_length
										flag3=1	
									}
								}
							}
					}
				} //ending if loop for @ & .
				else
				if ((count+1)==(str_length) && flag5==0 && flag4==0)
				{
					msg=msg+ "\n There is no dot after the @ sign"
					flag3=1
				}
				count+=1
			} //ending do loop
			while (count< str_length)
//*****************************************************************
			
			count=1 //no use
			if (!((flag1==0) && (flag3==0) && (flag4==0)))
			{
				error1=1
				constraint3=0	//now u can move to the next person as e-mail address is OK.
			//	alert("Now its moving to next persons record")
			}
			
			
return(msg);			
}

//function for wordwrapping
function wordwrap(str,Alen)

{
 // str is the string to be wrapped
// Alen is the length which it is wrapped to
// slen is the length of the string

slen = str.length

if (slen>Alen)
c=str.charAt(Alen+1)

if( c.indexOf(" ")==-1)
{
	for(i=Alen+2;i < slen;i++)
	{
		c=str.charAt(i)
		if(c.indexOf(" ")==-1)
		{
			continue;
		}
		else
		{
			break;
		}
	}	

}
s=str.substr(0,i)		
return(s)	
	
}
// function to enable disable HTML form elements using JavaScript

function chkdisable()
{
// requires  arguments, we dont specify name or no of arg
// uses an arg array
// here function call will have formname, objectname1 which is checked,
// objectname(S) which is (are) to be enabled/diasbled when objectname1 is 
//enabled/diasbled
n = chkdisable.arguments.length
vtext = 0
formname=0
vstr1 = chkdisable.arguments[0]
formname=chkdisable.arguments[1]
if(eval("document."+formname+"."+vstr1+".checked ==true"))
{
	for(i=2;i < n;i++)
	{	
		vtext = chkdisable.arguments[i]			
		eval("document."+formname+"."+vtext+".disabled=false")
	}
}
else
{
	for(i=2;i< n;i++)
	{	
		vtext = chkdisable.arguments[i]			
		eval("document."+formname+"."+vtext+".disabled=true")

	}
}

}

//Function for storing values of checkboxes in a grid 
function addtotextbox(tbName,cbName)
{
 if (navigator.appName == "Netscape")
  
 { 
   //if (cbName.length != NaN)
   if (typeof(cbName.length) != 'undefined')
   
  {
    document.forms[0].elements[tbName].value = ""
    for (i=0;i <= cbName.length - 1;i++)
     {   
      if (cbName[i].checked)  
       
       {
	     if (document.forms[0].elements[tbName].value != "" )
	     { 
		 document.forms[0].elements[tbName].value = document.forms[0].elements[tbName].value + "," + cbName[i].value
	     }
	     else 
	     {
		 document.forms[0].elements[tbName].value = cbName[i].value
	     }
	   }
      else 
       {
	    strOriginal = document.forms[0].elements[tbName].value
	    strRemove = "," + cbName[i].value
	    strFinal = strOriginal.replace(strRemove,"")
	    strRemove = cbName[i].value+","
	    strFinal = strFinal.replace(strRemove,"")
	    strRemove = cbName[i].value
	    document.forms[0].elements[tbName].value = strFinal.replace(strRemove,"")
	    strFinal = document.forms[0].elements[tbName].value
	    strRemove = ",,"
	    document.forms[0].elements[tbName].value = strFinal.replace(strRemove,",")
       }
      }//end of for loop
    }//end of if NaN
   else
   {
     
    if (cbName.checked)  
       {
          
	     if (document.forms[0].elements[tbName].value != "" )
	     { 
		 document.forms[0].elements[tbName].value = document.forms[0].elements[tbName].value + "," + cbName.value
	     }
	     else 
	     {
		 document.forms[0].elements[tbName].value = cbName.value
	     }
	   }
      else 
       {
	    strOriginal = document.forms[0].elements[tbName].value
	    strRemove = "," + cbName.value
	    strFinal = strOriginal.replace(strRemove,"")
	    strRemove = cbName.value+","
	    strFinal = strFinal.replace(strRemove,"")
	    strRemove = cbName.value
	    document.forms[0].elements[tbName].value = strFinal.replace(strRemove,"")
	    strFinal = document.forms[0].elements[tbName].value
	    strRemove = ",,"
	    document.forms[0].elements[tbName].value = strFinal.replace(strRemove,",")
       }
   }// end of else
    
   }//end of if netscape 
   else
   {
   if (window.document.activeElement.checked)  
     {
	  if (document.forms[0].item(tbName).value != "" )
	   { 
		document.forms[0].item(tbName).value = document.forms[0].item(tbName).value + "," + window.event.srcElement.value
	   }
	  else 
	   {
		document.forms[0].item(tbName).value = window.event.srcElement.value
	   }
	 }
    else 
     {
	   strOriginal = document.forms[0].item(tbName).value
	   strRemove = "," + window.event.srcElement.value
	   strFinal = strOriginal.replace(strRemove,"")
	   strRemove = window.event.srcElement.value+","
	   strFinal = strFinal.replace(strRemove,"")
	   strRemove = window.event.srcElement.value
	   document.forms[0].item(tbName).value = strFinal.replace(strRemove,"")
	   strFinal = document.forms[0].item(tbName).value
	   strRemove = ",,"
	   document.forms[0].item(tbName).value = strFinal.replace(strRemove,",")
     }

   }
  
}

function _navImgpage(mode,count,rscount,pagesize,length,gridname)
{
 y = "document.forms[0]."+ gridname
 eval("gotopage = " + y + "gotopage.value")
 var ctl; 
 eval("ctl = " + y + "page")
 switch (mode)
  {
    case "F":
      //alert (ctl.value)
      if (ctl.value == 1)
      {
       alert("You are already on first record.") 
       if (navigator.appName != "Netscape")
	     {
	      eval(y + "previouspage.disabled = true")
	      eval(y + "firstpage.disabled = true")
	     }  
	   return false
	  }
	  else
	  {
	   ctl.value = 1;
	  }
    break;
	
	case "L":
      if (ctl.value == count)
      {
       alert("You are already on last record.") 
       if (navigator.appName != "Netscape")
	     {
	      
	      eval(y + "lastpage.disabled = true")
	      eval(y + "nextpage.disabled = true")
	     } 
	   return false
	  }
	   else
	  {
	   ctl.value = count;
	  } 
	    
	    
    break;
    
    case "N":
      if(ctl.value == "")
       {
        ctl.value = 1;
       }
      ctl.value = parseInt(ctl.value) + parseInt("1");
      if(ctl.value > count)
       {
  	    ctl.value = count;
	    if (navigator.appName != "Netscape")
	    {
	     eval(y + "lastpage.disabled = true")
	     eval(y + "nextpage.disabled = true")
	    } 
	    alert("There are no more records to view.") 
	    return false
	   }
     break; 
    
     case "P":
      
      if(ctl.value == "" || ctl.value == 0)
       {
        ctl.value = 2;
       } 
        ctl.value = parseInt(ctl.value) - 1;  
        if(ctl.value <= 0)
         {
	      ctl.value = 1;
		  if (navigator.appName != "Netscape")
		    {
		     eval(y + "previouspage.disabled = true")
	         eval(y + "firstpage.disabled = true")
	        } 
		  alert("You are already on the first record.") 
		  return false
		 }
         
     break;
     case "G":
        if (gotopage == "" )
       {
        return false
        //window.event.returnValue = false 
       }
       else   
       {        //----- 1st
         if (isNaN(gotopage))
           {
             alert("Please enter a numeric value.") 
             return false
           }
           else  //----- 2nd
           {
            if (gotopage > count)  
             {
              alert("You exeeding the number of record.") 
              return false
              //window.event.returnValue = false 
             }
            else  //----- 3rd
             {
              if ( gotopage < 1)
               {
                alert("Records cannot be negative record.") 
                return false
                //window.event.returnValue = false 
               }
              else
               {
                ctl.value = gotopage;
               }
             }  //----- 3rd
           }   //----- 2nd
     }        //----- 1st
      break; 
    }
    if  (navigator.appName != "Netscape")
	  {
	   if (ctl.value != count)
	     {
	      eval(y + "previouspage.disabled = false")
	      eval(y + "firstpage.disabled = false")
	     }
	   if (ctl.value != 1)
	     {
	      eval(y + "nextpage.disabled = false")
	      eval(y + "lastpage.disabled = false")
	     }    
	   } 
}  
function form_Submit(mode,pagecount ,rscount,pagesize ,length ,gridname)
{
 
 if (window.event.keyCode == 13 )
 {
  _navpage(mode,pagecount ,rscount,pagesize ,length ,gridname)
 }
   
}
function form_Submit_Client(mode,maxcount,count,rscount,pagesize ,length ,gridname)
{
 
 if (window.event.keyCode == 13 )
 {
  navclientpage(mode,maxcount,count,rscount,pagesize,length,gridname)
 }
   
}

function _navpage(mode,count,rscount,pagesize,length,gridname)
{
 y = "document.forms[0]."+ gridname
 eval("gotopage = " + y + "gotopage.value")
 var ctl; 
 eval("ctl = " + y + "page")
 switch (mode)
  {
    case "F":
      //alert (ctl.value)
      if (ctl.value == 1)
      {
       alert("You are already on first record.") 
       if (navigator.appName != "Netscape")
	     {
	      eval(y + "previouspage.disabled = true")
	      eval(y + "firstpage.disabled = true")
	     }  
	   return false
	  }
	  else
	  {
	   ctl.value = 1;
	  }
    break;
	
	case "L":
      if (ctl.value == count)
      {
       alert("You are already on last record.") 
       if (navigator.appName != "Netscape")
	     {
	      
	      eval(y + "lastpage.disabled = true")
	      eval(y + "nextpage.disabled = true")
	     } 
	   return false
	  }
	   else
	  {
	   ctl.value = count;
	  } 
	    
	    
    break;
    
    case "N":
      if(ctl.value == "")
       {
        ctl.value = 1;
       }
      ctl.value = parseInt(ctl.value) + parseInt("1");
      if(ctl.value > count)
       {
  	    ctl.value = count;
	    if (navigator.appName != "Netscape")
	    {
	     eval(y + "lastpage.disabled = true")
	     eval(y + "nextpage.disabled = true")
	    } 
	    alert("There are no more records to view.") 
	    return false
	   }
     break; 
    
     case "P":
      
      if(ctl.value == "" || ctl.value == 0)
       {
        ctl.value = 2;
       } 
        ctl.value = parseInt(ctl.value) - 1;  
        if(ctl.value <= 0)
         {
	      ctl.value = 1;
		  if (navigator.appName != "Netscape")
		    {
		     eval(y + "previouspage.disabled = true")
	         eval(y + "firstpage.disabled = true")
	        } 
		  alert("You are already on the first record.") 
		  return false
		 }
         
     break;
     case "G":
        if (TrimStr(gotopage) == "" )
       {
        return false
        //window.event.returnValue = false 
       }
       else
       {     //------1st
        if (isNaN(gotopage))
           {
             alert("Please enter a numeric value.") 
             document.forms[0].gotopage.value = ""
             return false
           }
           else  //----- 2nd
           {

         if (gotopage > count)  
          {
           alert("You exeeding the number of record.") 
           return false
           //window.event.returnValue = false 
          }
        else
         {
          if ( gotopage < 1)
          {
           alert("Records cannot be negative record.") 
           return false
           //window.event.returnValue = false 
          }
          else
          {
          ctl.value = gotopage;
          }
         }
        }
      }
      break; 
    }
    if  (navigator.appName != "Netscape")
	  {
	   if (ctl.value != count)
	     {
	      eval(y + "previouspage.disabled = false")
	      eval(y + "firstpage.disabled = false")
	     }
	   if (ctl.value != 1)
	     {
	      eval(y + "nextpage.disabled = false")
	      eval(y + "lastpage.disabled = false")
	     }    
	   } 
}


function sortlink(sortexpression,gridname)
    
{
    
	objt = "document.forms[0]."+gridname.name
	txtLocation = document.location.href
	txtsearch=""
	txtsearch = document.location.search
    count = txtLocation.split("?")
    if (count.length > 1)
    {
		 txtLocation = count[0]
		 txtsearch= count[1]
		 if (txtsearch != "")
		 {
			
			  count = txtsearch.split("&")
			  count_length = count.length
			  txtsearch = ""
			  for (i = 0;i < count_length;++i)
			  {
				arr = count[i].split("=")
				if (arr[0] != gridname.name + "sortorder") 
				{
					   txtsearch = txtsearch + count[i] + "&"
				}
	          }
	      }
	}
	else
	{
	  //txtsearch = "?"
	}
	
	txtsearch= txtsearch + gridname.name + "sortorder=" +  sortexpression
	txtLocation = txtLocation + "?" + txtsearch //txtQueryString
	eval(objt + "tbSort.value = 'sorted'")
	document.forms[0].action = txtLocation 
	document.forms[0].submit()
	//document.thisForm.tbSort.value = "sorted"
	//document.thisForm.action = txtLocation 
	//document.thisForm.submit() 
}

function DeleteSelected(htmObject,htmAction,Alertmessage,Actionvalue)
{	
	if (document.forms[0].elements[htmObject].value == "")
	{
		alert(Alertmessage)
	}
	else
	{
		document.forms[0].elements[htmAction].value = Actionvalue
		document.forms[0].submit()
	}
}

//function to check the checkbox on clientside
function getchecked(chkbox,hidtxtval,strval)
 {
   
   chkbox.checked = false
   chkbox.value  = strval
   if (hidtxtval != "")
      {              
        if (hidtxtval.indexOf(strval)>=0)
	       {
	         chkbox.checked = true
		   }
	  }
 }
function navclientpage(mode,maxcount,count,rscount,pagesize,length,gridname)
{
	y = "document.forms[0]."+ gridname.name
	tab = "document.all." + gridname.name
	eval("gotopage = " + y + "gotopage.value")
	var ctl; 
    eval("ctl = " + y + "page")
    
  switch (mode)
  {
    case "F":
       ctl.value = 1;
        eval(y + "lastpage.disabled = false")
	    eval(y + "nextpage.disabled = false")
	   if  ( eval(y + "tbStart.value") != 1) 
	    {
	     eval(y + "tbStart.value = ctl.value")
	     endValue = parseInt(ctl.value) + parseInt(maxcount) - 1
         eval(y + "tbEnd.value = endValue")
         varSubmit = true 
        }
       else
        {
        
        eval(y + "firstpage.disabled = true")
	    eval(y + "previouspage.disabled = true")
         varSubmit = false
        }
    break;
	case "L":
       
       if (ctl.value == count)
        {
        alert("You are already on last record.") 
        eval(y + "lastpage.disabled = true")
	    eval(y + "nextpage.disabled = true")
	    varSubmit = true 
	    window.event.returnValue = false
	    }
	   else
	   { 
         ctl.value = count;
         eval(y + "firstpage.disabled = false")
	     eval(y + "previouspage.disabled = false")
	     val = count % maxcount
	     if (val == 0 )
	      {
	       val = maxcount
	      }
	     startValue = ctl.value 
	     eval(y + "tbStart.value = startValue")
         eval(y + "tbEnd.value = ctl.value") 
         varSubmit = true 
       } 
        
    break;
    case "N":
       
       if(ctl.value == "")
        {
         ctl.value = 1;
        }
       ctl.value = parseInt(ctl.value) + parseInt("1");
       endPage = parseInt(eval(y + "tbStart.value")) + parseInt(maxcount) - 1
       
       if (endPage > count - 1 )
        {
         endPage = count - 1
        }
        
         if(ctl.value > endPage)
       {
        eval(y + "tbStart.value = ctl.value")
        eval(y + "tbEnd.value = endPage")
        varSubmit = true 
       }
       else 
       {
		varSubmit = false
       }
           if(ctl.value > count)
        {
  	     ctl.value = count;
  	     eval(y + "tbStart.value = ctl.value")
	     //document.all.item("nextpage").disabled = true
	     //document.all.item("lastpage").disabled = true
	     eval(y + "nextpage.disabled = true")
	     eval(y + "lastpage.disabled = true")
	     alert("There are no more records to view.") 
	     window.event.returnValue = false 
	    }
	    
	    if (navigator.appName != "Netscape")
	    {
	    eval(y + "firstpage.disabled = false")
	    eval(y + "previouspage.disabled = false")
	   
		}
		
    break; 
    case "P":
       if(ctl.value == "" || ctl.value == 0)
       {
        ctl.value = 2;
       } 
      ctl.value = parseInt(ctl.value) - 1;  
      if(ctl.value <= 0)
       {
	    ctl.value = 1;
		eval(y + "previouspage.disabled = true")
		eval(y + "firstpage.disabled = true")
		//document.all.item("previouspage").disabled = true
		//document.all.item("firstpage").disabled = true
		alert("You are already on the first record.") 
		varSubmit = false
	    }
      startValue = parseInt(eval(y + "tbStart.value")) 
      if(ctl.value < startValue || ctl.value == count - 1)
       {
         if (startValue == count)
           {
             val = (ctl.value - maxcount) + 1
             while (!((val % maxcount) - 1 == 0))
              {
               val = val + 1
              }
             startValue = val 
           }
         else
           {
            startValue = (ctl.value - maxcount) + 1
           }
          endValue = startValue + parseInt(maxcount) - 1
          eval(y + "tbStart.value = startValue")
          eval(y + "tbEnd.value = endValue")
          varSubmit = true 
        }
       else 
       {
		varSubmit = false
	   }
      eval(y + "lastpage.disabled = false")
	  eval(y + "nextpage.disabled = false")
	  //document.all.item("nextpage").disabled = false
	  //document.all.item("lastpage").disabled = false
     break;
     case "G":
     //case for goto nav bar
     if (TrimStr(gotopage) == "" )              //------ 1st
        {
          varSubmit = false
        }
     else                              //------ 1st
        {
           if (isNaN(gotopage))       //----- 2nd
           {
             alert("Please enter a numeric value.") 
             //document.forms[0].gotopage.value = "" 
             varSubmit = false
             return false
           }
           else                      //----- 2nd
            {
             if (gotopage > count)  //----- 3rd
              {
               alert("You are exeeding the number of record.") 
               varSubmit = false
		      }
             else                 //----- 3rd
              {
               if ( gotopage < 1) //----- 4th
                 {
                  alert("Records cannot be negative in Number.") 
                  varSubmit = false
                 }
               else               //----- 4th
                 {
                  ctl.value = gotopage;    
                                  //----- 5th if starting down
                   if (gotopage >= parseInt(eval(y + "tbStart.value")) && gotopage <= parseInt(eval(y + "tbEnd.value")) ) 
                    {
                     varSubmit = false  //Need not submit
                    }
                    else         //----- 5th
                    {
                      if (gotopage == count) //----- 6th
                        {
                         startValue = count
                         endValue = count
                        }
                      else                       //----- 6th 
                        {
                          val = parseInt(gotopage) - (parseInt(gotopage/maxcount) * maxcount)
						  if (val== 0)           //----- 7th
						    {
						      startValue = (parseInt(gotopage) - parseInt(maxcount)) + parseInt("1")
						    }
					      else                   //----- 7th
                            {
                              startValue = (maxcount * parseInt(gotopage/maxcount)) + 1
                            }                    //----- 7th end else
						  endValue = startValue + parseInt(maxcount) - 1
						  if (endValue >= count) // ----- 8th start if
							{
							  endValue = count - 1
							}                    // ----- 8th end of if
                        }                        //----- 6th  end of else
					   eval(y + "tbStart.value = startValue")
                       eval(y + "tbEnd.value = endValue")
                       varSubmit = true 
                   }   //----- 5th end of else                          
                  }   //----- 4th end of else
                 }   //----- 3rd end of else
                }   //----- 2nd end of else
               }   //----- 1st end of else   
     break; 
    }
if  (navigator.appName != "Netscape")
	  {
	   if (ctl.value != count)
	     {
	      eval(y + "previouspage.disabled = false")
	      eval(y + "firstpage.disabled = false")
	     }
	   if (ctl.value != 1)
	     {
	      eval(y + "nextpage.disabled = false")
	      eval(y + "lastpage.disabled = false")
	     }    
	   }
//end of switch case     
if (varSubmit) 
    {
		window.event.returnValue=true
    }
else 
	{ 
	    
		i = 0;
		valtemp=Math.floor(ctl.value / maxcount)
		val = ctl.value - (maxcount * valtemp)
        if (val == 0)
		{
		  val = maxcount
		}
		startValue = (pagesize * (val - 1))
		endValue = (pagesize * val - 1)
        length = length - 1
        for (pagestart = startValue;pagestart<=endValue ; pagestart++) 
		  {   
		   
		    if (pagestart < rscount)
		     {
		        for (j = 0;j<=length;j++) //i.e for"#cb#" text columns
		        {
		          checkvalue = eval( y + "tbcol" + j + "[" + pagestart + "].value")
		          
		          if (checkvalue.indexOf("#cb#") >=0)
		          { 
		           //alert(checkvalue)
		           chkbox =  checkvalue.split("#cb#")
		           
		           eval("getchecked(document.forms[0]." + chkbox[1] + "[" + i + "],document.forms[0]." + chkbox[2] + ".value," + chkbox[0] + ")")
		          }
		           else
		           {
		           //x = "txtcol" + j 
		           if (navigator.appName == "Netscape")
		           {
		            // document.anchors[x,i].text = eval("document.thisForm.tbcol" + j + "[" + pagestart + "].value")
		           }
		           else
		           {
		            Myval = eval(y + "tbcol" + j + "[" + pagestart + "].value")
		            
		            //eval(tab + ".rows(i).cells(j).innerHTML" = eval(y + "tbcol" + j + "[" + pagestart + "].value")
		            eval(tab + ".rows(i + 1).cells(j).innerHTML = Myval")
		            //document.all.mytable.rows(i + 1 ).cells(j).innerHTML = eval("document.thisForm.tbcol" + j + "[" + pagestart + "].value")
		            //document.all.item(x,i).innerHTML = eval("document.thisForm.tbcol" + j + "[" + pagestart + "].value")
		           }
		           
		          }
		        }
		        
		     }
		       i = i + 1 ;
		    } 
		if (ctl.value == "")
		eval(tab + "text_1.innerText = '1'")  //The current page label
		else
		eval(tab + "text_1.innerText = ctl.value")   
		//return false
		window.event.returnValue=false
    }
    
}
function LTrimStr(Str)
{
  mval = ""
  val = Str
  stat = true
  for (i=0;i < val.length ;i++)
  {
    ch = val.charAt(i)
    if (stat )
      {
       if (ch == " ")
        {
         mval = mval 
        }
       else
        {
         mval = mval + ch
         stat = false
        }  
      }
   else
     {
     mval = mval + ch 
     }
   }
   return mval
}
function RTrimStr(Str)
{
  sval = ""
  stat = true
  ipos = Str.length - 1
  for (i=ipos ;i > -1 ;--i)
  {
    ch = Str.charAt(i)
    if (stat)
      {
        if (ch == " ")
        {
         sval = sval 
        }
        else
        {
        sval = ch + sval
        stat = false
        }  
      }
     else
     {
     sval = ch + sval
     }
   }
return sval
}
function TrimStr(Str)
{
  Lstr = LTrimStr(Str)   
  BStr = RTrimStr(Lstr)
  return BStr
}
function ValidateNumeric(tbObject,message)
  {
  fmsg = ""
  tbval = TrimStr(tbObject.value)
  if (tbval=="")
	{
		fmsg = fmsg +  "Please Enter " + message + "\n"
		tbObject.value  = "" 
	}
	else
	{
	   if (isNaN(tbval))
	   {
	    fmsg = fmsg +  "Please Enter a numeric value for " + message + "\n"
	   }
	   else
	   {
	    if (tbval < 1)
	    {
	     fmsg = fmsg +  "Please Enter a value greater than 1 " + message + " \n"
	    }
	   }
	}
}


function isBlank(val)
{	var flg=true
	var str;
	str=""
	//val=valen.value
	len=val.length
	if(len > 0)
	{
		for(i=0;i< len;i++)
		{	if(val.substring(i,i+1)!=" ")
			{	flg=false
				break
			}
		}
	}
	return flg;
} 

function selectAllCheckbox(objCheckbox){
	if(objCheckbox.length){
		for(i=0;i<objCheckbox.length;i++)
			objCheckbox[i].checked=true
	}
	else {
		objCheckbox.checked=true;
	}
}


	//Function to check max length for textarea 
	function checkLength(objText, iMaxLength, objLabel){
		var iDiff
		var sText
		sText = objText.value
		if (sText.length > iMaxLength){
			iDiff=sText.length - iMaxLength;
			alert(objLabel + " limited to " + iMaxLength + " characters\n" + "Please reduce the text by " + iDiff+ " character(s) " );
			objText.focus();
			return false; 
		}
		return true;
	}


