	
	//this function validates the start & end  dates and months
	function Validate(objStartDate,objEndDate,objStartMonth,objEndMonth,objStartYear,objEndYear)
	{
		startdate = eval(objStartDate + ".value");
		enddate = eval(objEndDate + ".value");		
		startmonth = eval(objStartMonth + ".value");
		endmonth = eval(objEndMonth + ".value");
		
		startYear = eval(objStartYear + ".value");
		endYear = eval(objEndYear + ".value");
		
		if(Number(startYear) > Number(endYear))
		{
			alert("Starting Year should be less than the Ending Year !");
			//eval(objStartYear).focus();
			return false;
		}
		
		if(Number(endmonth) < Number(startmonth) && (Number(startYear) >= Number(endYear)) )
		{
			alert("Ending Month should be greater than Starting Month !");
			eval(objEndMonth).focus();
			return false;
		}		
		
		if(Number(endmonth) == Number(startmonth) && (Number(startYear) >= Number(endYear)))
		{
			if(Number(enddate) < Number(startdate))
			{
				alert("To Date should be greater than From Date !");
				eval(objEndDate).focus();
				return false;
			}
		}	
		
		if ((startmonth==4 || startmonth==6 || startmonth==9 || startmonth==11) && startdate==31) 
		{
			alert("From Month doesn't have 31 days!")
			eval(objStartDate).focus();
			return false
		}
		
		if ((endmonth==4 || endmonth==6 || endmonth==9 || endmonth==11) && enddate==31) 
		{
			alert("To Month doesn't have 31 days!")
			eval(objEndDate).focus();
			return false
		}

		if (startmonth == 2) 
		{ // check for february 29th for starting month
			//var today = new Date()
    		//var year = today.getYear()
			var year = startYear;

			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (startdate>29 || (startdate==29 && !isleap)) 
			{
				alert("February " + year + " doesn't have " + startdate + " days!");
				eval(objStartDate).focus();
				return false;
			}
		}
		if(endmonth == 2)
		{	 // check for february 29th for the end month
			//var today = new Date()
    		//var year = today.getYear()
			var year = endYear;

			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (enddate>29 || (enddate==29 && !isleap)) 
			{
				alert("February " + year + " doesn't have " + enddate + " days!");
				eval(objEndDate).focus();
				return false;
			}			
		}
		return true;
	}	
	
	
function populate(objyear,objmonth,objday)
{
	var t = objday.options[objday.selectedIndex].value
	var yearval = objyear; //pass as 2004
	timeA = new Date(yearval, objmonth.options[objmonth.selectedIndex].value,1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	if(objday.options.length>0)
	{
		for (var i = 0; i < objday.length; i++)
		{
			objday.options[0] = null;
		}
	}
	for (var i = 0; i < daysInMonth; i++)
	{
		if(i<9)
		{	
			v = i+1;
			objday.options[i] = new Option("0"+v,v);
		}
		else
			objday.options[i] = new Option(i+1,i+1);
			
	}
	if ((t != "") && (t!= 0))
	{	
		objday.options[t-1].selected = true;
	}
}


	function ValidateAgencyUser()
	{    
		if(document.form1.txtUsername)
		{
			if(document.form1.txtUsername.value == "")
			{
				alert("Please specify User Id!");
				document.form1.txtUsername.focus();
				return false;
			}        
		}
        if(document.form1.txtPassword.value == "")
        {
            alert("Please specify Password!");
            document.form1.txtPassword.focus();
            return false;
        }
        if(document.form1.txtConfirmPassword.value == "")
        {
            alert("Please Confirm Password!");
            document.form1.txtConfirmPassword.focus();
            return false;
        }
        if((document.form1.txtPassword.value != "" && document.form1.txtConfirmPassword.value != "") && (document.form1.txtPassword.value != document.form1.txtConfirmPassword.value))
        {
            alert("Password and Confirm Password are not same!");
            document.form1.txtConfirmPassword.focus();
            return false;
        }
        return true;
	}

	function changeAgencyUser()
	{    

		if(document.form1.txtOldPassword.value == "")
		{
			alert("Please specify Old password!");
			document.form1.txtOldPassword.focus();
			return false;
		}        
        if(document.form1.txtPassword.value == "")
        {
            alert("Please specify Password!");
            document.form1.txtPassword.focus();
            return false;
        }
        if(document.form1.txtConfirmPassword.value == "")
        {
            alert("Please Confirm Password!");
            document.form1.txtConfirmPassword.focus();
            return false;
        }
        if((document.form1.txtPassword.value != "" && document.form1.txtConfirmPassword.value != "") && (document.form1.txtPassword.value != document.form1.txtConfirmPassword.value))
        {
            alert("Password and Confirm Password are not same!");
            document.form1.txtConfirmPassword.focus();
            return false;
        }
        return true;
	}


	function ValidateNewUser()
    {    
        if(document.form1.txtUser.value == "")
        {
            alert("Please specify User Id!");
            document.form1.txtUser.focus();
            return false;
        }        
        if (isNaN(document.form1.txtUser.value) == true)
        {
            alert("Please specify numberic User Id!");
            document.form1.txtUser.focus();
            return false;
        }
        if (Number(document.form1.txtUser.value) <=0)
        {
            alert("Please specify valid User Id!");
            document.form1.txtUser.focus();
            return false;
        }
        
        if(document.form1.txtUserName.value == "")
        {
            alert("Please specify the Name !");
            document.form1.txtUserName.focus();
            return false;
        }
		/*
        var str=document.form1.txtUserName.value;
        var len = str.length;
        if (len <5 || len >10)
        {
            alert("Please check length of User Name \n It should be greater then 5 characters and less then 10 characters!");
            document.form1.txtUserName.focus();
            return false;
        }
		*/
        if(document.form1.txtPassword.value == "")
        {
            alert("Please specify Password!");
            document.form1.txtPassword.focus();
            return false;
        }
        if(document.form1.txtConfirmPassword.value == "")
        {
            alert("Please specify Password!");
            document.form1.txtConfirmPassword.focus();
            return false;
        }
        if((document.form1.txtPassword.value != "" && document.form1.txtConfirmPassword.value != "") && (document.form1.txtPassword.value != document.form1.txtConfirmPassword.value))
        {
            alert("Password and Confirm Password are not same!");
            document.form1.txtConfirmPassword.focus();
            return false;
        }
		/*
        var str1=document.form1.txtPassword.value;
        var len1 = str1.length;
        if (len1 <5 || len1 >10)
        {
            alert("Please check length of Password \n It should be greater then 5 characters and less then 10 characters!");
            document.form1.txtPassword.focus();
            return false;
        }
        */
        if(document.form1.txtName.value == "")
        {
            alert("Please specify the Name !");
            document.form1.txtName.focus();
            return false;
        }
        
        if(document.form1.txtPrimaryEmail.value == "")
        {
            alert("Please specify Primary Email Address !");
            document.form1.txtPrimaryEmail.focus();
            return false;
        }
        
        //if((document.form1.txtPrimaryEmail.value != "") && (fnValidEmail(document.form1.txtPrimaryEmail.value) == false))
        if((document.form1.txtPrimaryEmail.value != "") && (checkemail(document.form1.txtPrimaryEmail) == false))
        {            
            //alert("Please specify valid email address !");
            document.form1.txtPrimaryEmail.focus();
            return false;
        }
        //if((document.form1.txtSecondaryEmail.value != "") && (fnValidEmail(document.form1.txtSecondaryEmail.value) == false))
        if((document.form1.txtSecondaryEmail.value != "") && (checkemail(document.form1.txtSecondaryEmail) == false))
        {            
            //alert("Please specify valid email address !");
            document.form1.txtSecondaryEmail.focus();
            return false;
        }                
        return true;
    }//function
	
	
	//validate existing user (on edit)
	function ValidateUser()
	{		
		if(document.form1.txtName.value == "")
		{
			alert("Please specify the Name !");
			document.form1.txtName.focus();
			return false;
		}
	/*	if(document.form1.txtAddress1.value == "")
		{
			alert("Please specify Address !");
			document.form1.txtAddress1.focus();
			return false;
		}
		if(document.form1.txtCity.value == "")
		{
			alert("Please specify the City!");
			document.form1.txtCity.focus();
			return false;
		}
		if(document.form1.txtState.value == "")
		{
			alert("Please specify the State !");
			document.form1.txtState.focus();
			return false;
		}
		if(document.form1.txtCountry.value == "")
		{
			alert("Please specify the Country!");
			document.form1.txtCountry.focus();
			return false;
		}
		if(document.form1.txtPhone.value != "")
		{
			if(fnValidUSPhoneNumber(document.form1.txtPhone.value) == false)
			{
				alert("Please specify Valid Phone No.!");
				document.form1.txtPhone.focus();
				return false;
			}
		}	*/		
		if(document.form1.txtPrimaryEmail.value == "")
		{
			alert("Please specify Primary Email Address !");
			document.form1.txtPrimaryEmail.focus();
			return false;
		}
		if((document.form1.txtOldPassword.value != "") || (document.form1.txtNewPassword.value != "") || (document.form1.txtConfirmPassword.value != ""))
		{
			 if(document.form1.txtOldPassword.value == "")
			{
				alert("Please specify Old Password !");
				document.form1.txtConfirmPassword.focus();
				return false;
			}
			if(document.form1.txtConfirmPassword.value == "")
			{
				alert("Please specify Confirm Password !");
				document.form1.txtConfirmPassword.focus();
				return false;
			}
			if(document.form1.txtNewPassword.value == "")
			{
				alert("Please specify New Password !");
				document.form1.txtNewPassword.focus();
				return false;
			}
			if(document.form1.txtNewPassword.value != document.form1.txtConfirmPassword.value)
			{
				alert("New Password and Confirm Password are not same!");
				document.form1.txtNewPassword.focus();
				return false;
			}
			if(document.form1.txtOldPassword.value == document.form1.txtNewPassword.value)
			{
				alert("Old Password and New Password can not be same!");
				document.form1.txtOldPassword.focus();
				return false;
			}
			/*
			var str2=document.form1.txtNewPassword.value;
			var len2 = str2.length;
			if (len2 <5 || len2 >10)
			{
				alert("Please check length of New Password \n It should be greater then 5 characters and less then 10 characters!");
				document.form1.txtNewPassword.focus();
				return false;
			}
			*/
		}
		
		//if((document.form1.txtPrimaryEmail.value != "") && (fnValidEmail(document.form1.txtPrimaryEmail.value) == false))
		if((document.form1.txtPrimaryEmail.value != "") && (checkemail(document.form1.txtPrimaryEmail) == false))
		{			
			//alert("Please specify valid email address !");
			document.form1.txtPrimaryEmail.focus();
			return false;
		}
		//if((document.form1.txtSecondaryEmail.value != "") && (fnValidEmail(document.form1.txtSecondaryEmail.value) == false))
		if((document.form1.txtSecondaryEmail.value != "") && (checkemail(document.form1.txtSecondaryEmail) == false))
		{			
			//alert("Please specify valid email address !");
			document.form1.txtSecondaryEmail.focus();
			return false;
		}		
		return true;
	}//function
	
	function fnValidEmail(sEmail) 
	{ 
	   var rgemail =/^\w+([\_\.])?\w+\@\w+\.\w+(\.\w+)?/i; 
	   var result = rgemail.test(sEmail); 
	   return result; 
	}
	
	function fnValidUSPhoneNumber(phone) 
	{ 
	   var rgphone = /^\d{3}\-\d{3}\-\d{4}/; 
	   var result = rgphone.test(phone); 
	   return result; 
	}

	function PhoneNumberOnly(e)
	{
		// This function will allow to type only numbers and hyphen(-).
		if(window.event) 
		{ // if browser is Internet explorer
			key = e.keyCode; 
			if (key==45) 
				return true;
			else
			{
				if(key <48||key>57)
				return false;
			}
		}
		else if(e.which)
		{	// if browser is Netscape or mozilla
			key = e.which; 
			if (key==45) 
				return true;
			else
			{
				if(key <48||key>57)
				return false;
			}
		}
		else
		 {
			// no event, so pass through
			return true;
		}
	}

	function NumbersOnly(e)
	{
		// This function will allow to type only numbers.

		if(window.event) 
		{ // if browser is Internet explorer
			key = e.keyCode; 
			if(key == 8 || key ==9 || key == 46 || key == 13 || key == 127 || key == 10)
				return true;
			if(key <48||key>57)
			return false;		
		}
		else if(e.which)
		{	// if browser is Netscape or mozilla
			key = e.which; 			
			if(key == 8 || key ==9 || key == 46 || key == 13 || key == 127 || key == 10)
				return true;
				
			if(key <48||key>57)
			return false;		
		}
		else
		 {
			// no event, so pass through
			return true;
		}
	}
	
	function FloatsOnly(e)
	{
		// This function will allow to type only numbers.				
		
		if(window.event) 
		{ // if browser is Internet explorer
			key = e.keyCode; 
			if (window.event.shiftKey) 
			{
				key=key+16;
			}

		}
		else if(e.which)
		{	// if browser is Netscape or mozilla
			key = e.which; 
			if (e.modifiers & Event.SHIFT_MASK) 
			{
				key=key+16;
			}

		}
		else
		 {
			// no event, so pass through
			return true;
		}
//		alert("key="+key);
					
		if((key >=48 && key<=57) || (key >= 96 && key <= 105) || key == 110 || key==8 || key ==9 || key==46 || key==16 || key==35 || key==36 || (key >= 37 && key <= 40) || key==190 || key == 13)
			return true;
		else
		{
			return false;		
		}	
	}
	
	function ValidateFaxNumber(e)
	{
		// This function will allow to type only numbers.
		 
		if(window.event) 
		{ // if browser is Internet explorer
			key = e.keyCode; 						
			if((key<45) || (key > 46 && key <48)||key>57)
			return false;		
		}
		else if(e.which)
		{	// if browser is Netscape or mozilla
			key = e.which; 
			if(key <48||key>57)
			return false;		
		}
		else
		 {
			// no event, so pass through
			return true;
		}
	} 
	
	function noSpace(e)
	{
		// This function will allow to type only numbers.
		 
		if(window.event) 
		{ // if browser is Internet explorer
			key = e.keyCode; 	 
			if(key == 32)
				return false;
		}
		else if(e.which)
		{	// if browser is Netscape or mozilla
			key = e.which; 
			if(key =32)
				return false;		
		} 
	} 
	
	function putFocus(control,user)
	{
		con=eval(control+"."+user);

		if(con)
		{
			if((con !="undefined") || (con !=""))
			{
				con.focus();
			}
		}
	}
	
	
	function checkemail(field)
	{
	var emailStr = new String();
	emailStr=field.value;
	if(emailStr!='')
		{
		var emailPat=/^(.+)@(.+)/;
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]";
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]/;
		var atom=validChars + '+';
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		var matchArray=emailStr.match(emailPat);
		if (matchArray==null) {
			alert("Email address seems incorrect (check @ and .'s)");
			field.focus();
			field.select();
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];
	
		if (user.match(userPat)==null) {
			alert("Please enter valid email address !");
			field.focus();
			field.select();
	
			return false;
		}
		var IPArray=domain.match(ipDomainPat);
		if (IPArray!=null)
			{
			for (var i=1;i<=4;i++)
				{
				if (IPArray[i]>255)
					{
					alert("Destination IP in the Email Address address is invalid !");
					field.focus();
					field.select();
					return false;
					}
				}
			return true;
			}
	
		var domainArray=domain.match(domainPat);
		if (domainArray==null)
			{
			alert("The domain name in the Email Address doesn't seem to be valid.");
			field.focus();
			field.select();
			return false;
			}
		var atomPat=new RegExp(atom,"g");
		var domArr=domain.match(atomPat);
		var len=domArr.length;
		if (domArr[domArr.length-1].length<2 ||
			domArr[domArr.length-1].length>3)
			{
		   // the address must end in a two letter or three letter word.
			alert("The Email address must end in a three-letter domain, or two letter country.");
			field.focus();
			field.select();
			return false;
			}
	
		if (len<2)
			{
			var errStr="The Email address is missing a hostname!";
			alert(errStr);
			field.focus();
			field.select();
			return false
			}
		}
	return true;
	}
	
	//function to validate the search text boxes values 
	 function ValidateSearch(totalQues,srno)
	 {		 
		for(i=srno;i<totalQues;i++)
		{	//check if any response is greater than 5
			
			txtval = eval("document.form1.SQUES"+i).value;				 
			if(isNaN(txtval))
			{
				alert("Please enter numeric value !");
				eval("document.form1.SQUES"+i).focus();
				return false;					
			}
			/*if(txtval > 5)
			{
				alert("Please enter value less than 5");
				eval("document.form1.SQUES"+i).focus();
				return false;					
			}//if								
			*/
		}//for	  					
		return true;
	 }
	 
	  //function to clear the search textboxes
	function ClearValues(totQues,srno,formname)
	{
		for(i=srno;i<=totQues;i++)
		{
			eval("document.form1.SQUES"+i).value = ""
			eval("document.form1.SCOMPARE"+i).options.selectedIndex = "0";
		}
		
		//clear all the demo graphic check boxes if selected
		for(i=0;i<document.form1.elements.length;i++)
		{
			if(eval("document." + formname +".elements[i]").type == "checkbox")
				eval("document."+ formname +".elements[i]").checked = false;
		}

			
		//clear search and comparison values of avg column
		document.form1.SAVG.value = ""
		document.form1.SAVGCOMPARE.options.selectedIndex = "0";
		if(document.form1.SURVEY)
		{
			document.form1.SURVEY.value = ""
			document.form1.SURCOMPARE.options.selectedIndex = "0";
		}
		//set the focus on  the first question text
		eval("document.form1.SQUES"+srno).focus();
	
	}//function
	
 function checkparameter(noOfques)
  {
  	totalQues=noOfques+5;
  	srno=6;
  	for(i=srno;i<=totalQues;i++)
		{	//check if any response is greater than 5
			txtval = eval("document.form1.SQUES"+i).value;				 
			if(isNaN(txtval))
			{
				alert("Please enter numeric value !");
				eval("document.form1.SQUES"+i).focus();
				return false;					
			}
			if(txtval > 5)
			{
				alert("Please enter value less than 5");
				eval("document.form1.SQUES"+i).focus();
				return false;					
			}//if								
		}//for	  		
  	
  	if(document.form1.SAVG)
  	{
	  	Avgval=document.form1.SAVG.value
	  
	  	if(isNaN(Avgval))
			{
				alert("Please enter numeric value !");
				document.form1.SAVG.focus();
				return false;					
			}
		if(Avgval > 5)
			{
				alert("Please enter AVG value less than 5");
				document.form1.SAVG.focus();
				return false;					
			}//if	
  	}
  	return true;
  }	
  
	function checkLoyaltyQuestions()
	{
		for(i=0;i<document.form1.elements.length;i++)
		{
			if(document.form1.elements[i].name == 'questions1[]')
			{
				if(document.form1.elements[i].checked == true)
					return true;
			}
		}
		alert("Please select atleast One question ");
		return false;
	}

function validateDnis()
{

	if(document.form1.txtDnis.value == "")
	{
		alert("Please specify DNIS !");
		document.form1.txtDnis.focus();
		return false;
	}
	/*if(document.form1.txtOfficeName.value == "")
	{
		alert("Please specify Office Name!");
		document.form1.txtOfficeName.focus();
		return false;
	}
	if(document.form1.txtShortDesc.value == "")
	{
		alert("Please specify Short Name of Office!");
		document.form1.txtShortDesc.focus();
		return false;
	}*/
	if(document.form1.txtPhoneNum.value == "")
	{
		alert("Please specify Phone Number!");
		document.form1.txtPhoneNum.focus();
		return false;
	}
	
	if(document.form1.txtPhoneNum.value != "")
		{
			if(fnValidUSPhoneNumber(document.form1.txtPhoneNum.value) == false)
			{
				
				alert("Please specify Valid Phone No.!");
				document.form1.txtPhoneNum.focus();
				return false;
			}
		}
}