/*----
 * This javascript file contains validation routines for different scenarios
 *--*/
 
 
 //Function: ValidateLastName
 //Input parameter: Text element where user has entered last name
 //Description:This function is used to validate last name entered by user. If last name
 //entered is not valid, an error message pops up and focus is set to that text control 


function ValidateCredentials(field,fieldName){

    
    //var validList = "'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_@";		
    
    var inputVal;
    inputVal = field.value;
    
    if (!inputVal)
    {
        alert("Please Enter your "+fieldName+".");
        field.focus();
        return false;
    }
    return true
}

function ValidateQuestion(field,fieldName){

    var inputVal;
    inputVal = field.value;
    if (!inputVal)
    {
        alert("Please Enter your "+fieldName+".");
        field.focus();
        return false;
    }
    
    if( inputVal.length >= 500 ){
        alert("Character length of Question should be less  than 500.");
        field.focus();
        return false;
    
    }
    return true
}

function ValidateDetAnswer(field,fieldName){
	
	var inputVal;
    inputVal = field.value;
    
	if (inputVal)
    {
    	if( inputVal.length > 150 ){
        	alert("Character length of Detailed Answer should be less  than 150.");
        	field.focus();
        	return false;    
    	}   	

	}
	return true;
}




function ValidateAnswer(field,fieldName){
    var inputVal;    
    inputVal = field.value;
    if (!inputVal)
    {
        alert("Please Enter your "+fieldName+".");
        field.focus();
        return false;
    }
    return true
}

function ValidateInput(field,fieldName){
    var inputVal;
    inputVal = field.value;
    if (!inputVal)
    {
        alert("Please Enter your "+fieldName+".");
        field.focus();
        return false;
    }
    return true
}



function ValidateCorrectAns(field){

    var chklength = field.length;
    var bool = false
    for (counter = 0; counter < chklength ; counter++){
        if(field[counter].checked){
            bool = true
            return true;
        }
    }
    if(bool == false){
        alert("Please check the correct answer.");
        return false;
    }
}


function trim(str) {
	  
    if(str.length < 1) {
        return "";
    }
    var trimFlag = 1

    for(var k=0;k<str.length;k++){

        if(str.charAt(k) != " ") 
        {
            trimFlag = 0
            break	
        }
    }

    if(trimFlag == 1){
        return "";
    } 	

    for(var i=0; i < str.length; i++) {

        if(str.charAt(i) != " "){
                break; 
        }
    }

    for(var j=str.length-1; j >=0; j--) 
        if(str.charAt(j) != " ") break;

    return(str.substring(i,j+1));
}




  
 function ValidateLastName(txtLastname)
 {
        var strLastname;


            //Valid list of characters which the lastname can contain
            var validList = "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";

            strLastname = trim(txtLastname.value);

            if(strLastname.length == 0)
            {
                    alert ("Enter Last Name.");
                    txtLastname.value = "";
                    txtLastname.focus();
                    return false;
            }

            //Check if invalid characters are contained in the Lastname
            for(var i = 0; i < strLastname.length; i++)
            {
                    if(validList.indexOf(strLastname.charAt(i))== -1)
                    {
                            alert("Last Name contains invalid characters.");
                            txtLastname.focus();
                            return false;
                    }
            }

            return true;
 }
 
 //Function: ValidateMidName
 //Input parameter: Text element where user has entered middle name
 //Description:This function is used to validate middle name entered by user. If middle name
 //entered is not valid, an error message pops up and focus is set to that text control 
  
 function ValidateMidName(txtMidname)
 {
	var strMidname;
							
								
		//Valid list of characters which the middle name can contain
		var validList = "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";
		
		strMidname = trim(txtMidname.value);
		
		if(strMidname.length == 0)
			return true;
		
		//Check if invalid characters are contained in the Lastname
		for(var i = 0; i < strMidname.length; i++)
		{
			if(validList.indexOf(strMidname.charAt(i))== -1)
			{
				alert("Middle Name contains invalid characters.");
				txtMidname.focus();
				return false;
			}
		}
		
		return true;
 }

 //Function: ValidateFirstName
 //Input parameter: Text element where user has entered first name
 //Description:This function is used to validate first name entered by user. If first name
 //entered is not valid, an error message pops up and focus is set to that text control 
 
 function ValidateFirstName(txtFirstname)
 {
	var strFirstname;
				
		//Valid list of characters which the lastname can contain
		var validList = "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ- ";
		
		strFirstname = trim(txtFirstname.value);
		
		if(strFirstname.length == 0)
		{
			alert ("Enter First Name.");
			txtFirstname.value = "";
			txtFirstname.focus();
			return false;
		}
		
		//Check if invalid characters are contained in the First name
		for(var i = 0; i < strFirstname.length; i++)
		{
			if(validList.indexOf(strFirstname.charAt(i))== -1)
			{
				alert("First Name contains invalid characters.")
				txtFirstname.focus();
				return false;
			}
		} 
		return true;
 }
 
 
 //Function: ValidateCarrierName
 //Input parameter: Text element where user has entered carrier name
 //Description:This function is used to validate carrier name entered by user.
 // If carrier name entered is not valid, an error message pops up 
 // and focus is set to that text control 
 function ValidateCarrierName(txtName)
 {
	var strName;
			
	//Valid list of characters which the productId can contain
	var invalidChar = "%#";
		
	strName = trim(txtName.value);
				
	// If no name specifed, popup error message and return focus to it.
	if(strName.length == 0)
	{
		alert ("Enter a carrier name.");
		txtName.value = "";
		txtName.focus();
		return false;
	}
	
	//Check if invalid characters are contained in the Carrier name
	for(var i = 0; i < strName.length; i++)
	{
		if( (strName.charAt(i) == invalidChar.charAt(0)) ||
			(strName.charAt(i) == invalidChar.charAt(1)) )
		{
			alert("Carrier name contains an invalid character.");
			txtName.focus();
			return false;
		}
	}
 }
 
 //Function: ValidateCarrierGroupName
 //Input parameter: Text element where user has entered carrier name
 //Description:This function is used to validate carrier name entered by user.
 // If carrier name entered is not valid, an error message pops up 
 // and focus is set to that text control 
 function ValidateCarrierGroupName(txtName)
 {
	var strName;
			
	//Valid list of characters which the productId can contain
	var invalidChar = "%";
	strName = trim(txtName.value);
				
	// If no name specifed, popup error message and return focus to it.
	if(strName.length == 0)
	{
		alert ("Enter a carrier group name.");
		txtName.value = "";
		txtName.focus();
		return false;
	}
		
	//Check if invalid characters are contained in the Carrier name
	for(var i = 0; i < strName.length; i++)
	{
		if(strName.charAt(i) == invalidChar)
		{
			alert("Carrier name contains an invalid character.");
			txtName.focus();
			return false;
		}
	}
 }
 
 //Function: ValidateCode
 //Input parameter: Text element where user has entered Motorola code
 //Description:This function is used to validate Motorola code entered by user. If code
 //entered is not valid, an error message pops up and focus is set to that text control 
 
 function ValidateCode(txtCode)
 {
	var strCode;
		
		//Valid list of characters which the lastname can contain
		var validList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		strCode = txtCode.value
		
		if(strCode.length == 0)
		{
			alert ("Specify the Global Motorola Code of the Stakeholder.");
			txtCode.focus();
			return false;
		}
		
		//Check if invalid characters are contained in the code
		for(var i = 0; i < strCode.length; i++)
		{
			if(validList.indexOf(strCode.charAt(i))== -1)
			{
				alert("The global Motorola code is not valid. Only alphanumeric characters are allowed.")
				txtCode.focus();
				return false;
			}
		}
		
		//Motorola code should atleast be 6 chars 
		if(strCode.length < 5)
		{
			alert ("The Global Motorola Code should contain at least five characters.");
			txtCode.focus();
			return false;
		}
			
 }
 
 //Function: ValidateEmail
 //Input parameter: Text element where user has entered email
 //Description:This function is used to validate email entered by user. If email
 //entered is not valid, an error message pops up and focus is set to that text control 
 
 function ValidateEmail(txtEmail)
 {
	var strEmail;
				
		//Valid list of characters which email can contain
		var validList = "'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-_@";
		
		strEmail = trim(txtEmail.value);
		
		if(strEmail.length == 0)
		{
			alert("Enter the e-mail address.");	
			txtEmail.focus();
			return false;
		}		
		
		//The email should always contain one occurence of '@'
		if(strEmail.indexOf("@") > 0)
		{
			if(strEmail.indexOf("@") != strEmail.lastIndexOf("@") )
			{
				alert("Invalid e-mail address format.");
				txtEmail.focus();
				return false;
			}
		}
		else
		{
			alert("Invalid e-mail address format.");
			txtEmail.focus();
			return false;
		
		}
		
		
		
		//The email should also contain the '.' character
		if(strEmail.indexOf(".") <= 0)
		{
			alert("Invalid e-mail address format.");
			txtEmail.focus();
			return false;
		}
		
		//Check if invalid characters are contained 
		for(var i = 0; i < strEmail.length; i++)
		{
			if(validList.indexOf(strEmail.charAt(i))== -1)
			{
				alert("Invalid e-mail address format.");
				txtEmail.focus();
				return false;
			}
		}
		
		
		return true;

 }
 
 //Function: ValidatePhone
 //Input parameter: Text element where user enters phone number
 //Description: This function is used to validate phone number entered by user
 
 function ValidatePhone(txtPhone)
 {
	var strPhone;
		//Valid list of characters which the lastname can contain
		var validList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ()-+. ";
		strPhone = trim(txtPhone.value);
		
		//Check if invalid characters are contained in the First name
		for(var i = 0; i < strPhone.length; i++)
		{
			if(validList.indexOf(strPhone.charAt(i))== -1)
			{
				alert("The phone number contains invalid characters.");
				txtPhone.focus();
				return false;
			}
		} 
		return true;
}

//Function: ValidateFax
 //Input parameter: Text element where user enters phone number
 //Description: This function is used to validate phone number entered by user
 
 function ValidateFax(txtPhone)
 {
	var strPhone;
		//Valid list of characters which the lastname can contain
		var validList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ()-+. ";
		strPhone = trim(txtPhone.value);
		
		//Check if invalid characters are contained in the First name
		for(var i = 0; i < strPhone.length; i++)
		{
			if(validList.indexOf(strPhone.charAt(i))== -1)
			{
				alert("The fax number contains invalid characters.");
				txtPhone.focus();
				return false;
			}
		} 
		return true;
}

//Function: ValidateMobile
 //Input parameter: Text element where user enters phone number
 //Description: This function is used to validate phone number entered by user
 
 function ValidateMobile(txtPhone)
 {
	var strPhone;
		//Valid list of characters which the lastname can contain
		var validList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ()-+. ";
		strPhone = trim(txtPhone.value);
		
		//Check if invalid characters are contained in the First name
		for(var i = 0; i < strPhone.length; i++)
		{
			if(validList.indexOf(strPhone.charAt(i))== -1)
			{
				alert("The mobile number contains invalid characters.");
				txtPhone.focus();
				return false;
			}
		} 
		return true;
}

//Function: ValidateLastName
 //Input parameter: Text element where user has entered last name
 //Description:This function is used to validate last name entered by user. If last name
 //entered is not valid, an error message pops up and focus is set to that text control 
  
 function ValidateRegion(txtRegion)
 {
	var strRegion;
							
								
		//Valid list of characters which the lastname can contain
		var validList = "'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
		
		strRegion = trim(txtRegion.value);
		
		//Check if invalid characters are contained in the Lastname
		for(var i = 0; i < strRegion.length; i++)
		{
			if(validList.indexOf(strRegion.charAt(i))== -1)
			{
				alert("Region field contains invalid characters. Only alphanumeric characters are allowed.");
				txtRegion.focus();
				return false;
			}
		}
 }
 
 
 //Function: ValidateProductID
 //Input parameter: Text element where user has entered productID
 //Description:This function is used to validate productID of the radio entered by user. If productID
 //entered is not valid, an error message pops up and focus is set to that text control 
 function ValidateProductID(txtProductID)
 {
	var strProductID;
							
	//Valid list of characters which the productId can contain
	var invalidChar = "%#";
		
	strProductID = trim(txtProductID.value);
	
	if(strProductID == "(none)")
	{
		alert (" '(none)' is not a valid radio name.Enter a new radio name.");
		txtProductID.value = "";
		txtProductID.focus();
		return false;
	}
		
	if(strProductID.length == 0)
	{
		alert ("Enter a radio name.");
		txtProductID.value = "";
		txtProductID.focus();
		return false;
	}
		
	//Check if invalid characters are contained in the Product ID
	for(var i = 0; i < strProductID.length; i++)
	{
		if( (strProductID.charAt(i) == invalidChar.charAt(0)) ||
			(strProductID.charAt(i) == invalidChar.charAt(1)) )
		{
			alert("Product ID contains an invalid character.");
			txtProductID.focus();
			return false;
		}
	}
 }

//Function: ValidateMarketModel
 //Input parameter: Text element where user has entered market model
 //Description:This function is used to validate market model of the radio entered by user. 
 // If productID
 //entered is not valid, an error message pops up and focus is set to that text control 
function ValidateMarketModel( txtWWMarketModel,txtBrazilMarketModel )
{
	var strWWMarketModel;
	var strBrazilMarketModel;
							
	//Valid list of characters which the Market model can contain
	var validList = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_ ";
		
	strWWMarketModel = trim(txtWWMarketModel.value);
	strBrazilMarketModel = trim(txtBrazilMarketModel.value);
	
	if(strWWMarketModel.length == 0 && strBrazilMarketModel.length == 0)
	{
		alert ("Atleast one of the market models should have a value.");
		txtWWMarketModel.value = "";
		txtWWMarketModel.focus();
		return false;
	}
		
	//Check if invalid characters are contained in the Market Model
	for(var i = 0; i < strWWMarketModel.length; i++)
	{
		if(validList.indexOf(strWWMarketModel.charAt(i))== -1)
		{
			alert("WW Market Model contains invalid characters.");
			txtWWMarketModel.focus();
			return false;
		}
	}
	
	//Check if invalid characters are contained in the Brazil Market Model
	for(var i = 0; i < strBrazilMarketModel.length; i++)
	{
		if(validList.indexOf(strBrazilMarketModel.charAt(i))== -1)
		{
			alert("Brazil Market Model contains invalid characters.");
			txtBrazilMarketModel.focus();
			return false;
		}
	}
}


//Function: ValidateGo
 //Input parameters: Text elements where user has entered From and To values
 //Description:This function is used to validate From and To indexes entered by user.
 //If indexes entered is not valid, an error message pops up and focus is 
 //set to that text control 
 function ValidateGo(txtFrom,txtTo)
 {
	
	var strFrom;
	var strTo;
							
	//Valid list of characters which the lastname can contain
	var validList = "0123456789";
	strFrom = trim(txtFrom.value);
	strTo = trim(txtTo.value);
	
	// If no From index specified,alert
	if(strFrom.length == 0)
	{
		alert ("Specify the From index.");
		txtFrom.value = "";
		txtFrom.focus();
		return false;
	}
	
	// If no To index specified,alert
	if(strTo.length == 0)
	{
		alert ("Specify the To index.");
		txtTo.value = "";
		txtTo.focus();
		return false;
	}
	
	//Check if invalid characters are contained in the From index
	for(var i = 0; i < strFrom.length; i++)
	{
		if(validList.indexOf(strFrom.charAt(i))== -1)
		{
			alert("From index contains invalid characters. Only numeric values greater than zero are allowed.");
			txtFrom.value = "";
			txtFrom.focus();
			return false;
		}
	}
	
	//Check if invalid characters are contained in the To index
	for(var i = 0; i < strTo.length; i++)
	{
		if(validList.indexOf(strTo.charAt(i))== -1)
		{
			alert("To index contains invalid characters. Only numeric values greater than zero are allowed.");
			txtTo.value = "";
			txtTo.focus();
			return false;
		}
	}
	
	var nFrom = parseInt(strFrom);
	var nTo = parseInt(strTo);
	
	if( nFrom > nTo )
	{
		alert ("From Index cannot be greater than To index.");
		txtFrom.value = "";
		txtFrom.focus();
		return false;
	}
	
	// From index should have value >0
	if( nFrom == 0 )
	{
		alert ("Only numeric values greater than zero is allowed in From index field.");
		txtFrom.value = "";
		txtFrom.focus();
		return false;
	}
	
	// To index should have value >0
	if( nTo == 0 )
	{
		alert ("Only numeric values greater than zero is allowed in To index field.");
		txtTo.value = "";
		txtTo.focus();
		return false;
	}
	
	
	return true;
	
 }
 
 
 
 //Function : ValidateAddress
 //Input Parameter: Text element where user enters the address data
 //If no of characters in address fields is more than 500 pops up an error message.
 function ValidateAddress(txtAddress)
 {
   var strAddress;
   
   strAddress = trim(txtAddress.value);
   
   // If address field has more than 500 characters
	if(strAddress.length > 500 )
	{
		alert ("Address field cannot contain more than 500 characters.");
		txtAddress.focus();
		return false;
	}
	return true; 
 }
 
 
 //Function : ValidateDescription
 //Input Parameter: Text element where user enters the description data
 //If no of characters in description fields is more than 1024, pops up an error message.
 function ValidateDescription(txtDescription)
 {
   var strDescription;
   
   strDescription = trim(txtDescription.value);
   
   // If address field has more than 1024 characters
	if(strDescription.length > 1024 )
	{
		alert ("Description field cannot contain more than 1024 characters.");
		txtDescription.focus();
		return false;
	}
	return true;
 }

function ValidateDate(txtDate)
{ 
	var dateStr;
	
	dateStr = trim(txtDate.value);
	
	if(dateStr.length == 0)
		return true;
	
	// Checks for the following valid date formats: 
	// MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY 
	// Also separates date into month, day, and year variables 

	//var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/; 

	// To require a 4 digit year entry, use this line instead: 
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; 

	var matchArray = dateStr.match(datePat); // is the format ok? 
	if (matchArray == null) { 
	alert("Date is not in a valid format.") 
	txtDate.focus();
	return false; 
	} 
	month = matchArray[1]; // parse date into variables 
	day = matchArray[3]; 
	year = matchArray[4]; 
	if (month < 1 || month > 12) { // check month range 
	alert("Month must be between 1 and 12."); 
	txtDate.focus();
	return false; 
	} 
	if (day < 1 || day > 31) {
	alert("Day must be between 1 and 31."); 
	txtDate.focus();
	return false; 
	} 
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("Month "+month+" doesn't have 31 days!") 
	txtDate.focus();
	return false 
	} 
	if (month == 2) { // check for february 29th 
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 
	if (day>29 || (day==29 && !isleap)) { 
	alert("February " + year + " doesn't have " + day + " days!"); 
	txtDate.focus();
	return false; 
	} 
	} 
	return true; // date is valid 
} 

//Function:CheckMotorolaEmail
//This function is used to check if the email entered is a Motorola email, in which case thsi function returns false
function CheckMotorolaEmail(txtEmail)
{
var emailpos;

		Email = trim(txtEmail.value);

		if(Email.length >13)
		{
			
			var startpos = Email.indexOf("@");
			var substr = Email.substring(startpos+1, Email.length);
			substr = substr.toLowerCase();
			if(substr == "email.mot.com")
			{
				alert("The customer email you entered belongs to a Motorola employee. You cannot select Motorola employees as customers.")
				txtEmail.focus();	
				return true;	
			}
		}	
		
		return false;
}


/*function ValidateGoDate(selFromMonthOpenCRs,txtFromDayOpenCRs,selFromYearOpenCRs,
						selToMonthOpenCRs,txtToDayOpenCRs,selToYearOpenCRs)
{
	//get the month,day and year values
	FromMonth = selFromMonthOpenCRs.selectedIndex + 1;
	FromDay = txtFromDayOpenCRs.value; 
	FromYear = selFromYearOpenCRs.value; 
	
	//if month is Apr,Jun,Sep,Novand day is 31 ,then set month as the next month and
	//day as 1st of the new month.
	if ((FromMonth == 4 || FromMonth == 6 || FromMonth == 9 || FromMonth == 11) && FromDay == 31)
	{
		selFromMonthOpenCRs.selectedIndex = FromMonth + 1;
		selFromDayOpenCRs.selectedIndex = 0;
		return false ;
	} 
	
	//if month is Feb,check if its leap year.If date is > 29 ,set date to March 1st.If date
	//is 29th and its not a leap year,set the date to Mar 1st.
	if (FromMonth == 2)
	{ 
		var isleap = (FromYear % 4 == 0 && (FromYear % 100 != 0 || FromYear % 400 == 0)); 
		
		if (FromDay > 29 || (FromDay == 29 && !isleap))
		{
			selFromMonthOpenCRs.selectedIndex = FromMonth;
			selFromDayOpenCRs.selectedIndex = 0;
			return false; 
		} 
	} 
	
	
	//get the month,day and year values
	ToMonth = selToMonthOpenCRs.selectedIndex + 1;
	ToDay = txtToDayOpenCRs.value; 
	ToYear = selToYearOpenCRs.value;
	
	
	//if month is Apr,Jun,Sep,Novand day is 31 ,then set month as the next month and
	//day as 1st of the new month.
	if ((ToMonth == 4 || ToMonth == 6 || ToMonth == 9 || ToMonth == 11) && ToDay == 31)
	{
		selToMonthOpenCRs.selectedIndex = ToMonth + 1;
		selToDayOpenCRs.selectedIndex = 0;
		return false ;
	} 
	
	//if month is Feb,check if its leap year.If date is > 29 ,set date to March 1st.If date
	//is 29th and its not a leap year,set the date to Mar 1st.
	if (ToMonth == 2)
	{ 
		var isleap = (ToYear % 4 == 0 && (ToYear % 100 != 0 || ToYear % 400 == 0)); 
		
		if (ToDay > 29 || (ToDay == 29 && !isleap))
		{
			selToMonthOpenCRs.selectedIndex = ToMonth;
			selToDayOpenCRs.selectedIndex = 0;
			return false; 
		} 
	} 
	
	//if from year is > to year, display error message
	if(FromYear > ToYear)
	{
		alert ("From date cannot be greater than To date.");
		return false;
	}
	else if(FromYear == ToYear)
	{
		//if from month is > to month, display error message
		if(FromMonth > ToMonth)
		{
			alert ("From date cannot be greater than To date.");
			return false;
		}
		else if(FromMonth == ToMonth)
		{
			//if from day is > to day, display error message
			if(FromDay > ToDay)
			{
				alert ("From date cannot be greater than To date.");
				return false;
			}
		}
	}
	return true;
}*/

function ValidateGoDate(selFromMonth,txtFromDay,selFromYear,
						selToMonth,txtToDay,selToYear)
{
	//get the month,day and year values
	FromMonth = selFromMonth.selectedIndex + 1;
	FromDay = txtFromDay.value; 
	FromYear = selFromYear.value;
	
	//Valid list of characters which the day field can contain
	var validList = "0123456789";
	
	//Check if invalid characters are contained in the From index
	for(var i = 0; i < FromDay.length; i++)
	{
		if(validList.indexOf(FromDay.charAt(i))== -1)
		{
			alert("From Day contains invalid characters. Only numeric values are allowed.");
			txtFromDay.value = "";
			txtFromDay.focus();
			return false;
		}
	}
	
	var nFromMonth = parseInt(FromMonth);
	var nFromDay = parseInt(FromDay);
	var nFromYear = parseInt(FromYear);
		
	if( nFromMonth == 0 || nFromDay == 0 || nFromYear == 0 )
	{
		alert ("Invalid From Date.");
		return false;
	}
		
	if( isNaN(nFromMonth) || isNaN(nFromDay) || isNaN(nFromYear) )
	{
		alert ("Invalid From Date.");
		return false;
	}
	
	//if month is Apr,Jun,Sep,Nov and day is > 30 ,then set date to 30
	if ((nFromMonth == 4 || nFromMonth == 6 || nFromMonth == 9 || nFromMonth == 11) && nFromDay > 30)
	{
		txtFromDay.value = 30;
		return false ;
	} 
	
	//if month is Jan,Mar,May,Jul,Aug,Oct,Dec and date is > 31 ,then set date to 31
	if ((nFromMonth == 1 || nFromMonth == 3 || nFromMonth == 5 || nFromMonth == 7 || nFromMonth == 8 ||
	    nFromMonth == 10 || nFromMonth == 12) && nFromDay > 31)
	{
		txtFromDay.value = 31;
		return false ;
	} 
	
	//if month is Feb,check if its leap year.If date is > 29 ,set date to 29.If date
	//is 29th and its not a leap year,set the date to 28.
	if (nFromMonth == 2)
	{ 
		var isleap = (nFromYear % 4 == 0 && (nFromYear % 100 != 0 || nFromYear % 400 == 0)); 
		
		if (nFromDay > 29 || (nFromDay == 29 && !isleap))
		{
			if(isleap)
				 txtFromDay.value = 29;
			else txtFromDay.value = 28;
			return false; 
		} 
	}
	
	//get the month,day and year values
	ToMonth = selToMonth.selectedIndex + 1;
	ToDay = txtToDay.value; 
	ToYear = selToYear.value;
	
	//Check if invalid characters are contained in the From index
	for(var i = 0; i < ToDay.length; i++)
	{
		if(validList.indexOf(ToDay.charAt(i))== -1)
		{
			alert("To Day contains invalid characters. Only numeric values are allowed.");
			txtToDay.value = "";
			txtToDay.focus();
			return false;
		}
	}
	
	var nToMonth = parseInt(ToMonth);
	var nToDay = parseInt(ToDay);
	var nToYear = parseInt(ToYear);
			
	if( nToMonth == 0 || nToDay == 0 || nToYear == 0 )
	{
		alert ("Invalid To Date.");
		return false;
	}
	
	if( isNaN(nToMonth) || isNaN(nToDay) || isNaN(nToYear) )
	{
		alert ("Invalid To Date.");
		return false;
	}
		
	//if month is Apr,Jun,Sep,Nov and day > 30 ,then set month as the next month and
	//day as 1st of the new month.
	if ((nToMonth == 4 || nToMonth == 6 || nToMonth == 9 || nToMonth == 11) && nToDay > 30)
	{
		txtToDay.value = 30;
		return false ;
	} 
	
	//if month is Jan,Mar,May,Jul,Aug,Oct,Dec and day > 31 ,then set month as the next month and
	//day as 1st of the new month.
	if ((nToMonth == 1 || nToMonth == 3 || nToMonth == 5 || nToMonth == 7 || nToMonth == 8 ||
		 nToMonth == 10 || nToMonth == 12 ) && nToDay > 31)
	{
		txtToDay.value = 31;
		return false ;
	} 
	
	//if month is Feb,check if its leap year.If date is > 29 ,set date to 29.If date
	//is 29th and its not a leap year,set the date to 28.
	if (nToMonth == 2)
	{ 
		var isleap = (nToYear % 4 == 0 && (nToYear % 100 != 0 || nToYear % 400 == 0)); 
		
		if (nToDay > 29 || (nToDay == 29 && !isleap))
		{
			if(isleap)
				 txtToDay.value = 29;
			else txtToDay.value = 28;
			return false; 
		} 
	}
	
	//if from year is > to year, display error message
	if(nFromYear > nToYear)
	{
		alert ("From date cannot be greater than To date.");
		return false;
	}
	else if(nFromYear == nToYear)
	{
		//if from month is > to month, display error message
		if(nFromMonth > nToMonth)
		{
			alert ("From date cannot be greater than To date.");
			return false;
		}
		else if(nFromMonth == nToMonth)
		{
			//if from day is > to day, display error message
			if(nFromDay > nToDay)
			{
				alert ("From date cannot be greater than To date.");
				return false;
			}
		}
	}
	return true;
}
function validatePassword(field1,field2) {

    var inputVal1;
    inputVal1 = field1.value;
    var inputVal2;
    inputVal2 = field2.value;


    if (inputVal1 != inputVal2)
    {
        alert("Your password entries do not match.");
        field2.focus();
        field1.focus();
        return false;
    }
    return true
}
