 

	//checks to see if the field is empty.first param is the object on which the operation is being performed.
	//second is the string that will be displayed if that object is empty.
	function empty(objectstr,str)
	{
		if (objectstr=="")
			{	
				message(str);			
				return (false);
			}
			
	}
	
	//--------------------------------------------------------------
	//displays the message on VDU at client side.
	function message(stringText)
	{
		alert(stringText);	
	}
	
	//--------------------------------------------------------------
	//This Function checks for the validity for String 
	// i.e. it check for the leading and traling spaces 
	// if it found then it will return false
	function check(str)
	{
		var ft = str;
		var chrloc;
		var stringLength;
		var loopCount;
		var ft1 = ft.charAt(0);
		var ft2= ft.charAt(ft.length - 1);
		if(str=="") {
			return false;
		}
		if (ft1 == " " || ft2 == " ")
		{
			stringLength = ft.length - 1
			for(loopCount=0;loopCount<=stringLength;loopCount++){
				if(ft.charAt(loopCount) != " "){
					return true;
				}
			}
			return false;
		}
		return true;
	}

	
	
	//--------------------------------------------------------------
	//date being compared.if date1 is "" then treats as current date
	//first param is date to compare to and then the date being compared, 
	//and at last if date1 should be greater then date2 i.e. earlier to the current date.
	//then value of type should be '1' else if the reverse is true then pass '2'
	function validate_date(date1,date2,type,str)
	{
		var dateobj,today;
		var dmonth,dday,dyear;
		var month2,day2,year2;
		dateobj=new Date(date2);
		dmonth=dateobj.getMonth();
		dday=dateobj.getDate();
		dyear=dateobj.getFullYear();
		//alert(date1);
		//alert(date2);
		//alert(type);
		if((dmonth=="3")||(dmonth=="5")||(dmonth=="8")||(dmonth=="10"))
		{
			if(dday > 30)
			{
			alert("Please Re-enter.This month doesn't have 31 days");
			return(false);
			}
		}
		
		else if((dmonth=="1")&&(dday > 29))
		{
			alert("Please Re-enter.February doesn't have more than 29 days");
			return(false);
		}

		else if((dmonth=="1")&&(dday==29))
		{
			if((dyear%4==0))
			{
				if((dyear%100)==0)
				{
					if((dyear%400)!=0)
					{
					alert("Please Re-enter.This Year is not a leap year");
					return(false);
					}
				}
			}
			else
			{
			alert("Please Re-enter.This year is not a leap year");
			return (false);
			}
		}
		//check date difference
		
		if (date1=="")
		{		
			today=new Date();
			month2=today.getMonth();
			day2=today.getDate();
			year2=today.getFullYear();
		}
		 
		else
		{
			today=new Date(date1);
			month2=today.getMonth();
			day2=today.getDate();
			year2=today.getFullYear();		
		}
		
		/*alert(day2);
		alert(month2);
		alert(year2); 
		alert(dday);
		alert(dmonth);
		alert(dyear); */
		if (type==1)
		{
			//earlier to current date
			//date1 should be less then date2
			if(year2<dyear) 
			{
				message(str);
				return (false);
			}
			if (year2==dyear)
			{
				if(month2<dmonth)
				{
					message(str);
					return(false);
				}
				if(month2==dmonth && day2<dday)
				{
					message(str);
					return(false);
				}
			}
		}
		else
		{
			//later then current date
			//date1 should be grater then date2
			if(year2>dyear) 
			{
				message(str);	
				return (false);
			}
			if (year2==dyear)
			{
				if(month2>dmonth)
				{
					message(str);
					return(false);
				}
				if(month2==dmonth && day2>dday)
				{
					message(str);
					return(false);
				}
			}
		
		} 
	return true;
	}
	
	
	//--------------------------------------------------------------
	//if any field requires ' quote then users entering this value cannot be updated into the database
	//this function will convert it appropriately and save the changes value in the same variable.
	//so simply insert the value into the database directly.
	function validate_quote(str1)
	{
		//alert(formname);
		//alert(document.formname.object1.value);
		var pos,newstr,nval;
		pos=str1.indexOf("'");
		if (pos>0)
		{
			nval=/'/g;
			newstr=str1.replace(nval,"''");
			return newstr;
		}
		else
		return str1;
		
	}
	
	//--------------------------------------------------------------
	//this function validates email.
	function validate_email(email)
	{
		var len=email.length;
		len=len-1
		var location1=email.indexOf("@");
		var location2=email.lastIndexOf("@");
		var location5=email.lastIndexOf(".");
		var location3=email.indexOf(".");
		var location4=email.indexOf(".",location1);
		if(email!="")
		{
		if((location1==0)||(location1==len))
		{
		alert(" @ cannot be at the beginning or end in the email field");
		return false ;
		}
		else if(location1!=location2)
		{
		alert("There cannot be two \"@\" in the email Id");
		return false ;
		}
		else if((location3==0)||(location3==len))
		{
		alert("\"dot\" cannot be at the beginning or end of email");
		return false;
		}
		else if(location1 < 0 || location3 < 0)
		{
		alert("Email id is invalid");
		return false;
		}
		else if(location4 < 0)
		{
		alert("Email is Invalid");
		return false;
		}
		else if(location5==len)
		{
		alert("Sorry wrong email ID");
		return false;
		}
		else if((location1 == location3+1)||(location1==location3-1))
		{
		alert("Sorry dot and @ cannot be side by side");
		return false;
		}
		}	
		return(true);
	}


//---------------------------------------------------------------------------------------
//This Function will check the validity of date 
//if the date is invalid (like "Febuary 30 2000") it will return false otherwise true
//The Parameters are "Month of Date" "Day of Date" and "Year of date"
//---------------------------------------------------------------------------------------
function vdate(dm,dd,dy)
{
		var dmonth,dday,dyear;
		dmonth = parseInt(dm);
		dday = parseInt(dd);
		dyear = parseInt(dy);
		if((dmonth==4)||(dmonth==6)||(dmonth==9)||(dmonth==11))
		{
			if(dday > 30)
			{
				alert("Please Re-enter.This month doesn't have 31 days");
				return(false);
			}
		}
		else if((dmonth==2)&&(dday > 29))
		{
			alert("Please Re-enter.February doesn't have more than 29 days");
			return(false);
		}
		else if((dmonth==2)&&(dday==29))
		{
			if((dyear%4==0))
			{
				if((dyear%100)==0)
				{
					if((dyear%400)!=0)
					{
						alert("Please Re-enter.This Year is not a leap year");
						return(false);
					}
				}
			}
			else
			{
				alert("Please Re-enter.This year is not a leap year");
				return (false);
			}
		}
return true;
} 
//End of vdate()



//Function to conver single quote to double quote
function makecompatible(str)
{
	var rc=/('+)/g;
	var d = str.replace(rc,"''");
	return(d);
}


function validate_ind_gen(inst)
{
var checkyear=document.registform.stryear.value; 
var currdate=new Date();
var curryear=currdate.getFullYear();
if(document.registform.strfname.value=="")
{
	alert("Please enter first name");
	document.registform.strfname.focus();
	return(false);
}
if(document.registform.strlname.value=="")
{
	alert("Please enter last name");
	document.registform.strlname.focus();
	return(false);
}
/*if(document.registform.strstate.value=="select")
{
	alert("Please select a state");
	document.registform.strstate.focus();
	return(false);
}
if(document.registform.straddress.value=="")
{
	alert("Please enter address");
	document.registform.straddress.focus();
	return(false);
}
if(document.registform.strcity.value=="")
{
	alert("Please enter city");
	document.registform.strcity.focus();
	return(false);
}


if(document.registform.strpin.value=="")
{
	alert("Please enter city pin code");
	document.registform.strpin.focus();
	return(false);
}
if(isNaN(document.registform.strpin.value))
{
	alert("Pin code should be numeric");
	document.registform.strpin.focus();
	return(false);
}*/

//alert(inst);
if (inst!="1")
{
	if(document.registform.stryear.value=="")
	{
		alert("Please enter year");
		document.registform.stryear.focus();
		return(false);
	}
}
if(isNaN(document.registform.stryear.value))
{
	alert("Year should be numeric");
	document.registform.stryear.focus();
	return(false);
}
if (inst=="1")
{
	
		if((document.registform.stryear.value.length!=0) && (document.registform.stragey.value.length!=0 ))
		{
			alert("Please provide either date of birth or age.");
			return(false);
		}
		if((document.registform.stryear.value.length==0) && (document.registform.stragey.value.length==0 ))
		{
			alert("Please specify age.");
			return(false);
		}
	
	
	if(document.registform.stryear.value.length>0)
	{
		
		if(document.registform.stryear.value < 1850)
		{
			alert("Please enter valid year for date of birth");
			document.registform.stryear.focus();
			return(false);
		}

		if(document.registform.stryear.value.length != 4)
		{
			alert("Please enter date in \"YYYY\" format(4 Characters long)");
			document.registform.stryear.focus();
			return(false);
		}
	
	
	}
}
if(document.registform.stryear.value.length>0)
{		
	var dtDob;
	dtDob = document.registform.strmonth.value + "/" + document.registform.strday.value + "/" + document.registform.stryear.value;
	if(!validate_date("",dtDob,1,"Please provide valid date of birth")) {
		return(false);
	}
	
}


/*if(document.registform.strphone.value=="")
{
	alert("Please enter phone no.");
	document.registform.strphone.focus();
	return(false);
}*/
if(inst!="1") 
{
	if(document.registform.stremail.value=="")
	{
		alert("Please enter E-Mail address");
		document.registform.stremail.focus();
		return(false);
	}
}
if(document.registform.strfname.value.length > 25)
{
	alert("The First Name should not be more than 25 characters")
	document.registform.strfname.focus();
	return(false);
}
if(document.registform.strlname.value.length > 25)
{
	alert("The Last Name should not be more than 25 characters")
	document.registform.strlname.focus();
	return(false);
}
if(document.registform.straddress.value.length > 100)
{
	alert("The Address should not be more than 100 characters")
	document.registform.straddress.focus();
	return(false);
}
if(document.registform.strcity.value.length > 50)
{
	alert("The City should not be more than 50 characters")
	document.registform.strcity.focus();
	return(false);
}
if(document.registform.strpin.value.length > 10)
{
	alert("The Pin code should not be more than 10 characters")
	document.registform.strpin.focus();
	return(false);
}
if(document.registform.stryear.value.length > 4)
{
	alert("The Year should not be more than 4 characters")
	document.registform.stryear.focus();
	return(false);
}
if(isNaN(document.registform.stryear.value))
{
	alert("The Year field should not be in characters")
	document.registform.stryear.focus();
	return(false);
} 

if(document.registform.strphone.value.length > 40)
{
	alert("The Phone should not be more than 40 characters")
	document.registform.strphone.focus();
	return(false);
}
if(document.registform.strfax.value.length > 25)
{
	alert("The Fax should not be more than 25 characters")
	document.registform.strfax.focus();
	return(false);
}
if(document.registform.strmobile.value.length > 25)
{
	alert("The Mobile should not be more than 25 characters")
	document.registform.strmobile.focus();
	return(false);
}
if(document.registform.stryear.value >curryear)
{
	alert("Please enter valid year");
	document.registform.stryear.focus();
	return(false);
}
if (inst!="1")
{
	if(document.registform.stryear.value < 1880)
	{
		alert("Please enter valid year for date of birth");
		document.registform.stryear.focus();
		return(false);
	}

	if(document.registform.stryear.value.length != 4)
	{
		alert("Please enter date in \"YYYY\" format(4 Characters long)");
		document.registform.stryear.focus();
		return(false);
	}
}
if(inst!="1" || document.registform.stremail.value.length > 0) {
	if(!validate_email(document.registform.stremail.value)) {
		document.registform.stremail.focus();
		return(false);
	}
}

if (!vdate(document.registform.strmonth.value,document.registform.strday.value,document.registform.stryear.value)) 
{
	document.registform.strday.focus();
	return(false);
}
/*if(!validate_date(document.registform.strmonth.value + "/" + document.registform.strday.value + "/" + document.registform.stryear.value,document.registform.iRmonth.value + "/" + document.registform.iRdate.value + "/" + document.registform.iRyear.value,2,"Your date of birth is greater than your registration date please check."))
{
	document.registform.iRdate.focus();
	return(false);
}*/
return true;
}



function validate_org_gen()
{
var strname			= document.dataform.strname.value.length;
var straddress		= document.dataform.straddress.value.length;
var strcity			= document.dataform.strcity.value.length;
var strstate		= document.dataform.strstate.value;
var strpin			= document.dataform.strpin.value.length;
var strphone		= document.dataform.strphone.value.length;
var strfax			= document.dataform.strfax.value.length;
var strmobile		= document.dataform.strmobile.value.length;
var strorgemail		= document.dataform.strorgemail.value.length;
var strwebsite		= document.dataform.strwebsite.value.length;
var strconname		= document.dataform.strconname.value.length;
var strcondesig		= document.dataform.strcondesig.value.length;
var strconphone		= document.dataform.strconphone.value.length;
var strconmobile	= document.dataform.strconmobile.value.length;
var stremail		= document.dataform.stremail.value.length;

	if(strname == "0")
		{
		alert("Please enter your name");
		document.dataform.strname.focus();
		return false;
	   }
	  if(check(document.dataform.strname.value)==false)
	  {
		alert("Please enter text instead of spaces in the beginning and at the end : Name");
		document.dataform.strname.focus();
		return false;
	  }
	if(strname > "100")
		{
		alert("Orgnisation name should not be more than 100 characters");
		document.dataform.strname.focus();
		return false;
	   }   
    if(straddress == "0")
		{
		alert("Please enter address");
		document.dataform.straddress.focus();
		return false;
	   }
	if(check(document.dataform.straddress.value)==false)
	  {
		alert("Please enter text instead of spaces in the beginning and at the end : Address");
		document.dataform.straddress.focus();
		return false;
	  }
	if(straddress > "100")
		{
		alert("Address should not be more than 100 characters");
		document.dataform.straddress.focus();
		return false;
	   }   
    if(strcity == "0")
		{
		alert("Please enter city name");
		document.dataform.strcity.focus();
		return false;
	   }
	   if(document.dataform.strstate.value=="select")
	   {
			alert("Please select a state");	
			return false;
	   }
	if(check(document.dataform.strcity.value)==false)
	  {
		alert("Please enter text instead of spaces in the beginning and at the end : City");
		document.dataform.strcity.focus();
		return false;
	  }
    if(strcity > "50")
		{
		alert("City name should not be more than 50 characters");
		document.dataform.strcity.focus();
		return false;
	   }

    if(strpin == "0")
		{
		alert("Please enter city pin code");
		document.dataform.strpin.focus();
		return false;
	   }
	if(check(document.dataform.strpin.value)==false)
	  {
		alert("Please enter some text instead of spaces in the beginning and at the end : Pin code");
		document.dataform.strpin.focus();
		return false;
	  }
    if(strpin > "10")
		{
		alert("City Pin code should not be more than 10 characters");
		document.dataform.strpin.focus();
		return false;
	   } 
	   for(i=0;i<document.dataform.strpin.value.length;i++)  
		{
			var ch = document.dataform.strpin.value.substring(i,i+1);
			if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9'))
			{
				alert("Pin code can only be alpha numeric");
				document.dataform.strpin.focus();
				return false;
			}
		}  
	if(strphone == "0")
		{
		alert("Please enter phone no.");
		document.dataform.strphone.focus();
		return false;
	   }
	if(check(document.dataform.strphone.value)==false)
	  {
		alert("Please enter text instead of spaces in the beginning and at the end : phone");
		document.dataform.strphone.focus();
		return false;
	  }
	if(strphone > "40")
		{
		alert("Phone No. should not be more than 40 characters");
		document.dataform.strphone.focus();
		return false;
	   }

	if(strfax > "25")
		{
		alert("Fax number should not be more than 25 characters");
		document.dataform.strfax.focus();
		return false;
	   }   
	 if(strmobile > "25")
		{
		alert("Mobile number should not be more than 25 characters");
		document.dataform.strfax.focus();
		return false;
	   }  
	 if(strorgemail == "0")
		{
		alert("Please enter E-Mail ");
		document.dataform.strorgemail.focus();
		return false;
	   }    
	 if(strorgemail > 0) 
              {
              if(!(validate_email(document.dataform.strorgemail.value) )) {
                document.dataform.strorgemail.focus(); 
		 return false;
               }
               if(check(document.dataform.strorgemail.value)==false)
				{
					alert("Please enter text instead of spaces in the beginning and at the end : Email");
					document.dataform.strorgemail.focus();
					return false;
				}

    	}
     if(strorgemail > "50")
		{
		alert("E-Mail should not be more than 50 characters");
		document.dataform.strorgemail.focus();
		return false;
	   }    
	 
          
     if(strwebsite > "75")
		{
		alert("Website address should not be more than 75 characters");
		document.dataform.strwebsite.focus();
		return false;
	   }   
	 //if(strconname == "0")
	//	{
	//	alert("Please enter contact person's name  ");
	//	document.dataform.strconname.focus();
	//	return false;
	// }    
	// if(strconname > "50")
	//	{
	//	alert("Contact person's name should not be more than 50 characters ");
	//	document.dataform.strconname.focus();
	//	return false;
	//  }    
	 
	// if(strcondesig == "0")
	//	{
	//	alert("Please enter contact person's designation");
	//	document.dataform.strcondesig.focus();
	//	return false;
	//   }     
	//if(strcondesig > "50")
	//	{
	//	alert("Contact person's designation should not be more than 50 characters");
	//	document.dataform.strcondesig.focus();
	//	return false;
	//   }     
	   
	   if(strconphone > "40")
		{
		alert("Phone no. should not be more than 40 characters");
		document.dataform.strcondesig.focus();
		return false;
	   }    
	  if(strconmobile > "25")
		{
		alert("Mobile number should not be more than 25 characters");
		document.dataform.strconphone.focus();
		return false;
	   }   
	   if(stremail > "50")
		{
		alert("E-Mail address should not be more than 50 characters");
		document.dataform.stremail.focus();
		return false;
	   } 
          if(stremail > 0) 
              {
              if(!(validate_email(document.dataform.stremail.value) )) {
                document.dataform.stremail.focus(); 
		 return false;
               }
 	}	   
 	
      return true;
 }




function selectall( strstate,strstateact)
         {
			var strret		= strstate;
			var collection = parseInt(strstateact);
		//	alert(strstate);
		//	alert(collection);
				for (i=1;i < collection ;i++) 
				{
					if (document.dataform.strstate.options[i].value == document.dataform.strstate1.value)
						{
					document.dataform.strstate.options[i].selected = true;
						}      
				}
		}
		
		
 function Email (s)
       {
         var j,flg
		flg=0
            // there must be >= 1 character before @, so we
           // start looking at character position 1
           // (i.e. second character)
           var i = 1;
           var sLength = s.length;

///////////////////////////////////////////////////// 


		for(j=0;j<sLength;j++)
		{

		if(s.charAt(j) == "@")
		{
		flg++;
		}
		}

		if(flg != 1)
		{

		return false;
		}


//////////////////////////////////////////////////////
           // look for @
           while ((i < sLength) && (s.charAt(i) != "@"))
           { i++
           }
           if ((i >= sLength) || (s.charAt(i) != "@")) return false;
           else i += 2;
 
           // look for .
           while ((i < sLength) && (s.charAt(i) != "."))
           { i++
           }
 
           // there must be at least one character after the .
           if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
           else return true;
        }
        