/* 
*	This js file contains all general client-side validation functions.
*	It can be included in the html files that need to use these functions 
*	by putting a <script language="JavaScript1.2" src="eHeatCommon.js"> tag in the HEAD section.
*	This file contains the following functions.  
**/


/**
*	Checks whether the single character or string ,
*	is a white space or contains only white spaces
*	Parameter
*	str - the string to be checked
*	Returns
*	true - if the string is a white space
*	false - if it contains any printable character.
*/

function isWhitespace(str)
{   
	var i=0;
	var ch;

	//whitespaces - \t : horizoantal tab , \n : line feed,\r : carriage return and blank space

	var whitespace="\t\n \r";
	for(i=0;i<str.length;i++)
	{
		ch=str.charAt(i);
		if(ch==' ') 
			return true;
		if(whitespace.indexOf(ch)==-1) 
		{		
			return false;
		}
	}//----for
	return true;
}

	

/**
*	Checks the given string is empty or not
*	Parameter
*	str - the string to be checked.
*	Returns
*	true - if the string empty 
*	false - otherwise.
*/

	

function isEmpty(str)
{	
	str=trim(str);
	return ((str == null) || (str.length == 0));
}

				

	

/**
*   Removes the whitespace from the front of the string.
*	Parameter
*	str - the string to be left trimed.
*	Returns	the string, with white space removed from the front.
*/

	

function lTrim(str)
{
	if(str==null||str.length==0) return str;
	if(isWhitespace(str)) return '';
	var i=0;

	//loop from the beginning until a white space is found.

	while((isWhitespace(str.charAt(i++))));

	//return the rest of the string;

	return str.substr(--i,str.length-i+2);
}



/**
*   Removes the whitespace from the end of the string.
*	Parameter
*	str - the string to be right trimed.
*	Returns	the string, with white space removed from the end.
*/

function rTrim(str)
{
	if(str==null||str.length==0) return str;

	if(isWhitespace(str)) return '';

	var i=str.length-1;

	//loop from the end until a white space is found.

	while(isWhitespace((str.charAt(i--))));

	//return the string upto the last non-whitespace character

	return str.substr(0,i+2);

}


/**
*	Removes the whitespace from both ends of the string
*	Parameter
*	str - the string to be trimed.
*	Returns	the string, with white space removed from the front and end.
*/

function trim(str)
{
	//trim both sides
	return(lTrim(rTrim(str)));
}



/**
*	This function checks whether the given string is made up of the characters represented 
*	by the regular expression.The regular expression can accept individual 
*	characters or ranges of characters seperated by a blank space.If the blank space 
*	it self  is to be included in the search expression include 'space' (without quotes) 
*	as one of the characters.	

*	eg: containsOnly(txtFname.value,'a-z A-Z . space') will return true if the txtFname.value contains only alphabets(capital and small), dots and spaces.

*		Parameters
*		str - the string to be matched
*		regexp - the regular expression string indicating the pattern to 
*		be matched


*		Retruns
*		true - if the string contains only the charcaters 
*		indicated by the expression
*		false - otherwise
*/

function containsOnly(str,searchstr)
{

		var i;

		var s;

		//split the regular expression.

		s=searchstr.split(" ");

		var condition="";

		for(i=0;i<s.length;i++){//for1

			var part=s[i];

			// can it contain spaces..?

			if(part=="space"){//if1

				if(i==0)

					condition="(code!=32)";

				else

					condition+="&(code!=32)";	

			}//if1

			//is it a range..?

			else if(part.charAt(1)=='-'){//else if1

				var lb=part.charCodeAt(0);

				var ub=part.charCodeAt(2);

				if(lb>ub){//if2

					var t=lb;

					lb=ub;

					ub=t;

				}//if2

				if(i==0)

					condition = "((code<" + lb + ")||(code>" + ub + "))";		

				else

					condition += "&((code<" + lb + ")||(code>" + ub + "))";		

			}//else if1

			//is a single character?

			else if(part.length==1){//else if1

				var pcode=part.charCodeAt(0);

				if(i==0)

					condition="(code!=" + pcode + ")";

				else

					condition+="&(code!=" + pcode + ")";

			}//else if1

			else{

				alert("Invalid Search Expression !");

				return null;

			}

		}//for1

		for(i=0;i<str.length;i++){//for1

			var code=str.charCodeAt(i);

			if(eval(condition))

				return false;

		}//for1

		return true;		

}

			

/**
*	compares two Java Script date objects.
*	Parameters
*	date1,date2 - two date objects to be compared.
*	Returns
*	The no of days between the two dates.Returns the value 0 
*	if the date1 is equal to date2; a value less than 0 
*	if this date1 is before the date2 ; and a value greater than 0
*	if date1 is after date2.
*/

function compare(date1,date2)
{
	var milsec=date1-date2;
	var no_of_days = milsec/86400000;

	return no_of_days;
}


/**
*	Checks wheteher the the given parameters form a valid date or not.
*	Parameters
*	day,month,year - String or int variables or constants, day and month starts from 1.
*	Returns
*	true - if the combination is a valid date
*	false - otherwise
*/

function isValidDate(day,month,year)
{

		max_days=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

		// a leap year should be divisible by 4 and not divisible by 100 .. or should be divisible by 400.in other words in the case of years divisible by 100 it should also be divisible by 400. The four distinct cases are

		//1996 - leap , 1997 - not leap, 2000- leap , 1900 - not leap

	

		if((((year % 4)==0)&&((year % 100)!=0)||((year) % 400)==0)){//if1

				max_days[1]=29;

		}//if1

		

		if((month>=1 && month<=12) && (day>=1 && day<=max_days[month-1]) && (year>0)){//if1

			if(year.substring(0,1) != "0"){
				return true;
			}
			else{
				return false;	
			}
		}//if1
		else
		{
			return false;
		}
}

			

/**
*	Checks whether the field contains a value or not.
*/

function isNotEmpty(field,desc)
{
	var str = field.value;

	if(isEmpty(str)){//if1
		alert(desc + " cannot be empty.");
		field.focus();
		field.select();
		
		return false;
	}//if1
	else
		return true;
}

	

/**
*Checks whether the field contains a valid number(with out decimal point) or not.	
*/
function isNumber(field,desc)
{
		var str=trim(field.value);
		var i;

		if(isNotEmpty(field,desc)){//if1

			if(str.indexOf("-")!=-1){
				str=str.substring(1,str.length);
			}

			//alert(str);
			for (i = 0; i < str.length; i++){//for1
				if (str.charAt(i) < '0' || str.charAt(i) > '9'){//if2
					alert(desc + " must be a valid numeric entry.  \nPlease do not use commas or dollar signs or any non-numeric symbols.");
					field.focus();
					return false;
				}//if2
			}//for1
		}//if1
		else{
			return false;
		}
		return true;
}
	

	/**
	*	Checks whether the field contains a valid decimal number(with or without decimal point
	*	or not
	*/

	function isDecimal(field,desc){

		var str=trim(field.value);

		var i;

		var ch;

		

		if(isNotEmpty(field,desc)){

			if(str=="."){

			alert(desc + " must be a valid numeric entry.  \nPlease do not use commas or dollar signs or any non-numeric symbols.");
			
			return false;

			}

			var pos1=str.indexOf(".");

			if(pos1==-1) // no decimal point

			{

				return(isNumber(field,desc));
				

			}		

			var pos2=str.lastIndexOf(".");

			//alert(pos2);

			if(pos1!=pos2) //ie there r more than 1 dec. points

			{

				alert(desc+" contains more than one decimal point !");

				return false;

			}

			if(str.indexOf("-")!=-1){

				str=str.substring(1,str.length);

			}

			for (i = 0; i < str.length; i++){

				ch=str.charAt(i);

				if (( ch< '0' || ch > '9')&&(ch!='.')){

					alert(desc + " must be a valid decimal entry. \nPlease do not use any non-numeric symbols other than decimal point.");

					field.focus();

					return false;

				}

			}

	

		}

		else{

			return false;

		}

		return true;

	}

	/**

	*	Checks whether the field contains a valid decimal number(with or without decimal point

	*	or not

	*/

	function isDecimalWith1Digit(field,desc){

		var str=trim(field.value);

		var i;

		var ch;



			if(str=="."){

			alert(desc + " must be a valid numeric entry.  \nPlease do not use commas or dollar signs or any non-numeric symbols.");

			return false;

			}

			var pos1=str.indexOf(".");

			if(pos1==-1) // no decimal point

			{

				return(isNumber(field,desc));
				

			}		

			var pos2=str.lastIndexOf(".");

			//alert(pos2);

			if(pos1!=pos2) //ie there r more than 1 dec. points

			{

				alert(desc+" contains more than one decimal point !");

				return false;

			}

			if(str.indexOf("-")!=-1){

				str=str.substring(1,str.length);

			}

			for (i = 0; i < str.length; i++){

				ch=str.charAt(i);

				if (( ch< '0' || ch > '9')&&(ch!='.')){

					alert(desc + " must be a valid decimal entry. \nPlease do not use any non-numeric symbols other than decimal point.");

					field.focus();

					return false;

				}

			}

	

		

		return true;

	}
	

	/**

	*	Checks whether the field contains a valid decimal number(with or without decimal point

	*	or not

	*/

	function isDecimalWith2Digit(field,desc){

	

		var str=trim(field.value);
		var i;
		var ch;

		if(isNotEmpty(field,desc)){

			if(str=="."){
				alert(desc + " must be a valid numeric entry.  \nPlease do not use commas or dollar signs or any non-numeric symbols.");
				return false;
			}

			var pos1=str.indexOf(".");
			if(pos1==-1) // no decimal point
			{

				//return(isNumber(field,desc));
				alert(desc+" decimal point must be specified"); 
				return false;

			}

			

			var pos2=str.lastIndexOf(".");

			//alert(pos2);

			if(pos1!=pos2) //ie there r more than 1 dec. points

			{

				alert(desc+" contains more than one decimal point!");

				return false;

			}

			if(str.indexOf("-")!=-1){

				str=str.substring(1,str.length);

			}

			for (i = 0; i < str.length; i++){

				ch=str.charAt(i);

				if (( ch< '0' || ch > '9')&&(ch!='.')){

					alert(desc + " must be a valid decimal entry. \nPlease do not use any non-numeric symbols other than decimal point.");

					field.focus();

					return false;

				}

			}

			//alert(str);

			//alert(pos1);

			if(str.length-pos1>3 && pos1>0){

			alert(desc+" should not contain more than two digits after decimal place !");

			return false;

			}
		}
		else{
			return false;
		}
		return true;
	}

	/**

	*	Checks whether the field contains only alphabets or not.

	*/

	function isAlphabetic_7FEB(field,desc){

		var str=trim(field.value);
		var i;
		var ch;

		if(isNotEmpty(field,desc)){//if1

			for (i = 0; i < str.length; i++){//for1

				ch=str.charAt(i)

				if ( (ch< 'a' || ch > 'z') && (ch< 'A' || ch > 'Z')){//if2

					alert(desc + " can contain only capital or small letters.");
					field.select();
					field.focus();
					return false;

				}//if2
			}//for1
		}//if1
		else{
			return false;
		}
		return true;
	}

function isAlphabetic(field,desc)
{
	var str=trim(field.value);
	var i;
	var ch;
	var flag = 'tr'

	if(isNotEmpty(field,desc))
	{
		for (i = 0; i < str.length; i++)
		{
			ch=str.charAt(i)
			if(ch!=" ")
			{
				if ( (ch< 'a' || ch > 'z') && (ch< 'A' || ch > 'Z'))
				{
						flag = 'fal';
				}
			}
		}
	}
	else{
		flag = 'fal';
	}
	//	alert(">>>>>>>>>>>>>>>>>>>"+flag);
	return flag;
}
	
function isAlphaHyphen(field,desc)
{
	var str=trim(field.value);
	var i;
	var ch;
	var flag = 'tr'
	var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz- ';

	if(isNotEmpty(field,desc))
	{ 
		for (i=0; i<str.length; i++) 
		{
			if (upr.indexOf(str.charAt(i),0) == -1) 
				flag = 'fal';
		}
	}
	else{
		flag = 'fal';
	}
	//	alert(">>>>>>>>>>>>>>>>>>>"+flag);
	return flag;
}
	

	/**

	*	Checks	whether the field contains only alphabets and numbers. 

	*/

	function isAlphaNumeric(field,desc){

		var str=trim(field.value);

		if(isNotEmpty(field,desc)){//if1

			if(containsOnly(str,'0-9 a-z A-Z')) // is it contains only alphabets and numbers..?
			{
				return true;
			}
			else
			{
				alert(desc + " can contain only alphabets and numbers.");
				field.focus();
			}
		}//if1
		return false;
	}
	
		

/**	
*	Checks whether the field contains a valid EmailID or not.
*/

function validateEmail( obj )
{
	var emailStr = obj.value;
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	
	if( !reg1.test( emailStr ) && reg2.test( emailStr ) ) {
		return true;
	}else{
		return false;
	}
}

function isEmailID(field)
{
	var str=trim(field.value); 
	regExp=/(\w+)@(.+)\.(\w+)$/;
	str = str.match(regExp);

	if (str !=null){//if1
		if ((str[3].length==2) || (str[3].length==3)){//if2
			return true;
		}//if2
	}//if1

	alert("Please enter a valid Email-ID,");
	field.focus();
	return false;
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    }
	else 
	if(email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    }
	else
	if(email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    }
	else
	if (email.indexOf("..") >=0) { // two periods in a row is not valid
		return false;
    }
	else
	if (email.indexOf(".") == email.length) {  // . must not be the last character
		return false;
    }
	else
	if((email.indexOf(".")!= email.length-4) && (email.indexOf(".")!= email.length-3)) 
	{  // . must not be the last character
		return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


/**
*	Checks whether the field contains a valid date or not.
*/

	function isDate(field){

		str=trim(field.value);

		regExp=new RegExp("-","g");

		str=str.replace(regExp,"/");

		date=str.split('/');

		//day <- date[0]; month <- date[1]; year<-date[2]

		

		//check whether the 3 parts are there and year is a 4 digit number

		if(date.length!=3 || date[2].length!=4){//if1

			alert("Invalid Date Format.\nAcceptable formats are DD-MM-YYYY and DD/MM/YYYY.");

			field.focus();

			return false;

		}//if1

		if(!(isValidDate(date[0],date[1],date[2]))){//if1

			alert("NonExistent Date !! \nAcceptable formats are DD-MM-YYYY and DD/MM/YYYY.");

			field.focus();

			return false;

		}//if1

			

		return true;

	}



/**

*	checks whether the combination of the 3 fields forms a valid date or not.
*	The fields can be text boxes or select lists.The month field can be of
*	values from 1-12 or Jan - Dec.

*/

	function doFormDate(fieldDay,fieldMonth,fieldYear){

		var day=fieldDay[fieldDay.selectedIndex].value;

		var month=fieldMonth[fieldMonth.selectedIndex].value; //month in MM or Mon format

		if(trim(month).length > 2) //ie Mon format

		{

			var months = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");

			for (var i = 0; i < 12; i++){//for1

				if(month.toLowerCase() == months[i]){

					month=i+1;

					break;

				}

			}//for1

		}

		var year=fieldYear[fieldYear.selectedIndex].value;

		if(!isValidDate(day,month,year)){//if1

			alert("Invalid Date !!");

			fieldDay.focus();

			return false;

		}//if1

		return true;

	}

		



      /** checkes whether the value contained in the field has got the minimum required 

	* number of characters.

	*/

	function hasMinLength(field,minlen,desc)

	{

		str=trim(field.value);

		if(str.length<minlen){

			alert(desc+" should contain minimum of "+minlen + "characters.");

			field.focus();

			return false;

		}

		return true;

	}

	

      /**

	*checks whether the value in the field contains not more than max length

	*/

	function notExceedsLength(field,maxlen,desc){

		str = trim(field.value);

		if(str.length > maxlen){

			alert(desc+" should not contain more than " + maxlen + " characters.");

			field.focus();

			return false;

		}

		return true;

	}

	



      /**

	*this function replaces all single quotes(') contained in the field with two single quotes('') 

	*so that the value can be used in an SQL statment with out causing an error.it also replaces 

	*a null value with a blank space

	*/

	function makeSQLSafe(field){

		str=field.value;

		if(str=="") // if the str is null make it a blank.

		{

			field.value=" ";

			return;

		}

		regExp=new RegExp("'","g"); //search for a quot globaly

		str=str.replace(regExp,"''"); //raplce all ' with ''

		field.value=str;

		return;

	}



	



	

	/** This method is used  for Checking all the check boxes under a paticular group

	*The parameters

	*formName - The form object

	*/

	function checkAll(formName)
	{ 	

	for(i=0; i< formName.elements.length; i++){

			if(formName.elements[i].type=="checkbox"){//if1

				formName.elements[i].checked=true;

					

				}//if1

	

		}

	}





	/**

	*This method is used  for UnChecking all the check boxes under a paticular group

	*The parameters

	*formName - The form object

	*/

	function unCheckAll(formName)

	{

	 for(i=0; i< formName.elements.length; i++){

	 			if(formName.elements[i].type=="checkbox"){//if1

	 				formName.elements[i].checked=false;

	 					

	 				}//if1

	 	

		}

	}

	



	/**

	*This method is checking whether one of the Radio button is checked

	*and Submitting to be appropriate Action 

	*The parameters 

	*text - Providing appropriate text string depending on the application

	*actionType - Provide Action like Edit,Add etc.

	*radioControl - The form object

	*/

	function ValidateRadioAction (message,actionType,radioControl)
	{ 

	}

	

	

     /**

	*This method is used for moving the entire list to either side way left or right

	*/

      function moveOptionsForAll(theSelFrom, theSelTo){

	 var valid = true;

	 var count = 0;

	 var sel = theSelFrom.options;

	 for (var i=0; i<sel.length; i++) {

		var status = sel[i];

		if (status.length)

			count=count+1;

	 }

	 

	 //count = count+isSelectable();

	 if (valid) {

		var selLength = theSelFrom.length;

		var selectedText = new Array();

		var selectedValues = new Array();

		var selectedCount = 0;

		var i;

		// Find the Options in reverse order

		// and delete them from the 'from' Select.

		for(i=selLength-1; i>=1; i--){

			if(theSelFrom.options[i]){

				selectedText[selectedCount] = theSelFrom.options[i].text;

				selectedValues[selectedCount] = theSelFrom.options[i].value;

				deleteOption(theSelFrom, i);

				selectedCount++;

			}

		}

	

		// Add the selected text/values in reverse order.

		// This will add the Options to the 'to' Select

		// in the same order as they were in the 'from' Select.

		for(i=selectedCount-1; i>=0; i--)

		{

			addOption(theSelTo, selectedText[i], selectedValues[i]);

		}



	  }



	 return valid;

        }







	

	

	

	

	

      /**

	*This method is used for moving the selected list to either side way left or right

	*/

     function moveOptionsForAdd(theSelFrom, theSelTo){

	 var valid = true;

	 var count = 0;

	 var sel = theSelFrom.options;

	 for (var i=0; i<sel.length; i++) {

		var status = sel[i];

		if (status.selected)

			count=count+1;

	 }

	 //count = count+isSelectable();

	 if (valid) {

		var selLength = theSelFrom.length;

		var selectedText = new Array();

		var selectedValues = new Array();

		var selectedCount = 0;

		var i;

		// Find the selected Options in reverse order

		// and delete them from the 'from' Select.

		for(i=selLength-1; i>=1; i--){

			if(theSelFrom.options[i].selected){

				selectedText[selectedCount] = theSelFrom.options[i].text;

				selectedValues[selectedCount] = theSelFrom.options[i].value;

				deleteOption(theSelFrom, i);

				selectedCount++;

			}

		}



		// Add the selected text/values in reverse order.

		// This will add the Options to the 'to' Select

		// in the same order as they were in the 'from' Select.

		for(i=selectedCount-1; i>=0; i--)

		{

			addOption(theSelTo, selectedText[i], selectedValues[i]);

		}



	  }



	 return valid;

        }

      /**

	*This method is used for adding 

	*/

         function addOption(theSel, theText, theValue){

		var newOpt = new Option(theText, theValue);

		var selLength = theSel.length;

		theSel.options[selLength] = newOpt;

        }



         function deleteOption(theSel, theIndex)

         {	

		var selLength = theSel.length;

		if(selLength>0){

			theSel.options[theIndex] = null;

		}

        }

	
/** Delete selected options from  the list. 
	T2760RC
	Dt:06/16/2005 
*/
	function deleteOptions(theSelFrom){
		var selLength = theSelFrom.length;
	
			var selectedText = new Array();
	
			var selectedValues = new Array();
	
			var selectedCount = 0;
	
			var i;
	
			// Find the selected Options in reverse order
	
			// and delete them from the 'from' Select.
	
			for(i=selLength-1; i>=1; i--){
	
				if(theSelFrom.options[i].selected){
	
					selectedText[selectedCount] = theSelFrom.options[i].text;
	
					selectedValues[selectedCount] = theSelFrom.options[i].value;
	
					deleteOption(theSelFrom, i);
	
					selectedCount++;
	
				}
	
			}
	}		

      /**

	*This method returns a count of number of items selected from the list

	*/

	function isSelectable()

	{

	

	}

	

      /**

	*This method is used  for Concatting the SSN 

	*The parameter

	*formName - The form name of the particular jsp page

	*/

	function concatSSN(ssnHidden,ssn1,ssn2,ssn3){

		var ssnHiddenValue;

		var ssn1Value=ssn1.value;

		var ssn2Value=ssn2.value;

		var ssn3Value=ssn3.value;

		ssnHidden.value=ssn1Value;

		ssnHiddenValue=ssn1Value+ssn2Value+ssn3Value;

		ssnHidden.value=ssnHiddenValue;

		

	}	



		

       /**

	*This method is used  for Concatting the Time Fields

	*The parameter

	*formName - The form name of the particular jsp page

	*/

	function ConcatTime(formName)

	{

	

	}



       /**

	*This method is used  for Concatting the Date Fields

	*The parameter

	*formName - The form name of the particular jsp page

	*/

	function concatDate(dateHidden,mon,date,year){

		var dateHiddenValue;

		var monValue=mon.value;

		var dateValue=date.value;

		var yearValue=year.value;



		if(monValue == "08" || monValue == "8"){

			monValue = "08";

		}

		if(monValue == "09" || monValue == "9"){

			monValue = "09";

		}



		if(dateValue == "08" || dateValue == "8"){

			dateValue = "08";

		}

		if(dateValue == "09" || dateValue == "9"){

			dateValue = "09";

		}



		if(parseInt(monValue) >= 1 && parseInt(monValue) <=7){

				monValue = "0"+parseInt(monValue);

		}



		if(parseInt(dateValue) >= 1 && parseInt(dateValue) <=7){

				dateValue = "0"+parseInt(dateValue);

		}

		dateHiddenValue=yearValue+"-"+monValue+"-"+dateValue;

		dateHidden.value=dateHiddenValue;

	}

	

      /**

	*This method is checking whether one of the checkbox is checked

	*The parameters 

	*message - Providing appropriate text string depending on the application

	*actionType - Provide Action like Remove etc.

	*checkboxControl - The form object

	*/

	function ValidateCheckAction (formName,operationId,message,targetAction)

	{ 

		status=false;

		for(i=0; i< formName.elements.length; i++){//for1

			if(formName.elements[i].type=="checkbox"){//if1

				if(formName.elements[i].checked){//if2

					status=true;

						break;

					}//if2

				}//if1

		}//for1

		if(status=="false"){//if1

			alert(message);

			return false; 

		}//if1

		else{

			return submitForm(formName,operationId,targetAction);

		}

	

	}



	/**

	 * Sorts data based on the field number.

	 *

	 */

	function sortData(formName,operationId,fieldNumber,targetAction){

	

	            var sortOrder

	            if(formName.sortOrderBy.value==fieldNumber){//if1

	                  sortOrder=formName.ascending.value;

	                  if(sortOrder=="true"){//if1

	                        formName.ascending.value="false";

	                  }//if1

	                  if(sortOrder=="false"){//if2

	                        formName.ascending.value="true";

	                  }//if2

	            }

	            else { //else1

		            formName.sortOrderBy.value=fieldNumber;

   		            if(formName.ascending.value = "true"){

			            formName.ascending.value="false";

		            }

		            else{

		                formName.ascending.value="true";

		            }



	            }// else1

	            return submitForm(formName,operationId,targetAction);

	      }

	



	

	

	/**

	 * Submits the form.

	 *

	 */

function submitForm(formName,operationId,targetAction){

		//formName.operation.value=operationId;		

		if(targetAction != null)
		{
			formName.action=targetAction;
		//	alert(formName.action);
		}
		formName.submit();
		return false;
	}

	

	/**
	 * MODIFIED TO CORRECT ALERT TO SELECT ONE ITEM WHEN THERE IS NO ITEM IN THE LIST
	 * Checks if the radio button has been checked or not.
	 *  
	 */
	function validateRadioSelected(formName,operationId,message,targetAction){

		var status=false;

		var radioFound = false;

		for(i=0; i< formName.elements.length; i++){//for1

			if(formName.elements[i].type=="radio"){//if1

				radioFound = true;

				if(formName.elements[i].checked){//if2

					status=true;

					break;

				}//if2

			}//if1

		}//for1

		//alert("br radioFound---->"+radioFound);

		if(radioFound == true){

			//alert("ar radioFound--->"+radioFound);

			if(status==false ){//if1

				alert(message);

				return false; 

			}//if1

			else{

				return submitForm(formName,operationId,targetAction);

			}

		}

	}



	/**

	 * To disable the form fields for view pages.

	 *

	 */

	function ViewFrm (currentFrm)

	{

	    var i;

	    for(i=0;i<currentFrm.elements.length;i++)

	    {

		if(currentFrm.elements[i].type == "text" || currentFrm.elements[i].type == "textarea" || currentFrm.elements[i].type == "password"  )
		{
		     currentFrm.elements[i].readOnly=true;
		}

		if(currentFrm.elements[i].type == "select-one" || currentFrm.elements[i].type == "radio" || currentFrm.elements[i].type == "img" || currentFrm.elements[i].type == "checkbox" )
		{
		    currentFrm.elements[i].disabled=true;
		}

		if(currentFrm.elements[i].type == "button" || currentFrm.elements[i].type == "submit" || currentFrm.elements[i].type == "reset")
		{
			if(currentFrm.elements[i].value != "Quit")
			{
				currentFrm.elements[i].disabled=true;
			}
		}
	    }

	}

	/**

	 * Splits the zipHidden value into zip1 and zip2.

	 * zipHidden should be in the format 999999999

	 *

	 */

	function formatZipCode(zipHidden,zip1,zip2)

	{

		var zipHiddenValue=zipHidden.value;

		var zip1Value=zipHiddenValue.substr(0,5);

		var zip2Value=zipHiddenValue.substr(5,zipHiddenValue.length);

		zip1.value=zip1Value;

		zip2.value=zip2Value;

	}
//----------------
/**
* DHTML phone number validation script.
*/


// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
//----------------
/**
 * Splits the phoneHidden value into phone1, phone2 and ext.
 * phoneHidden should be in the format 999-9999999#999
 *
 */

	function formatPhoneNumber(phoneHidden,phone1,phone2,ext)
	{
		var phoneHiddenValue=phoneHidden.value;
		var phone1Value=phoneHiddenValue.substr(0,3);
		var phone2Value="";
		var extValue="";

		if(ext!=null)
		{
			phone2Value=phoneHiddenValue.substr(3,7);
			if(phoneHiddenValue.length>10)
			{
				extValue=phoneHiddenValue.substr(11,phoneHiddenValue.length);
				ext.value=extValue;
			}
	    }
   	    else
		{
			phone2Value=phoneHiddenValue.substr(3,phoneHiddenValue.length);
		}
        	phone1.value=phone1Value;
			phone2.value=phone2Value;
	}
	

	/**
	 * Resets the necessary form field values for search operation & submits the form.
	 *
	 */

	function submitSearch(formName,operationId,targetAction)
	{
		formName.pageCount.value="0";
		return submitForm(formName,operationId,targetAction);
	}


/**
 * Validating Date in Text field 
 *
 */

	 function ValidateTextDate(date,month,year){
	 	  date.value = trim(date.value);
	 	  month.value = trim(month.value);
	 	  year.value = trim(year.value);  

		 if(!(isEmpty(date.value))||!(isEmpty(month.value))||!(isEmpty(year.value))){
			status=false;
			status=isNaN(month.value);
			if(status=="true" || !(isDot(month.value))){//if1
				alert("Please enter a valid date.");
				month.focus();
				return false;
				}//if1
			status=isNaN(date.value);
			if(status=="true" || !(isDot(date.value))){//if1
				alert("Please enter a valid date.");
				date.focus();
				return false; 
				}//if1
			status=isNaN(year.value);
			if(status=="true" || !(isDot(year.value))){//if1
				alert("Please enter a valid date.");
				year.focus();
				return false;
				}//if1

			if(year.value.length<4){//if1
			alert("Please enter a valid date.");
			year.focus();
			return false;
			}//if1

			status=isValidDate(date.value,month.value,year.value);
			if(status=="false"){//if1
				alert("Please enter a valid date.");
				month.focus();
				return false;

			}//if1
			return true;
		}
		return true;
	}
	

/**
 * Validating SSN
 *
 */

	function validateSSN(ssn1,ssn2,ssn3){
		if(!(isEmpty(ssn1.value) &&isEmpty(ssn2.value) &&isEmpty(ssn3.value))){

			if(trim(ssn1.value).length !=3) {

				alert('Not a valid SSN Number.');

				ssn1.focus();

				return false;

			}

			else if(!isAlphaNumeric(ssn1,'Social Security Number')){

				ssn1.focus();

				return false;

			}

			if(trim(ssn2.value).length !=2) {

				alert('Not a valid SSN Number.');

				ssn2.focus();

				return false;

			}

			else if(!isAlphaNumeric(ssn2,'Social Security Number')){

				ssn2.focus();

				return false;

			}

			if(trim(ssn3.value).length !=4) {

				alert('Not a valid SSN Number.');

				ssn3.focus();

				return false;

			}

			else if(!isAlphaNumeric(ssn3,'Social Security Number')){

				ssn3.focus();

				return false;

			}

			ssn1.value = ssn1.value.toUpperCase();

			ssn2.value = ssn2.value.toUpperCase();

			ssn3.value = ssn3.value.toUpperCase();

			return true;

		}

		else {

			return true;

		}

			

	}

	

	

       /**

	 * This methods for validating the drop down

	 *

	 */

	function ValidateDropdownList(formName,fieldName,msg){

		var obj = eval("formName."+fieldName);

		if(obj.selectedIndex == 0 && obj.options.length>1){//if1

			alert(msg);

			eval("formName."+fieldName).focus();

			return false;

		}

		else{

			return true;

		}

	}

	

	/**

	 * This methods for validating the drop down

	 *

	 */

	function isDot(strvalue)

	{

		var str=trim(strvalue);

		var pos1=str.indexOf(".");

		if(pos1==-1) // no decimal point

		{

			return true;

		}

		else{

			return false;

		}	

	}

	

	/**

	 * This methods for validating the Status History

	 *

	 */

	function   ValidateStatusHistory(formName,opID,msg,tableId,action){

		var radioFound = false;

		status=false;

		for(i=0; i< formName.elements.length; i++){//for1

		if(formName.elements[i].type=="radio"){//if1

				radioFound = true;

				if(formName.elements[i].checked){//if2

					if (formName.elements[i].value<0){

					alert("History can be viewed only for save data.");

					return false;

					}

					formName.tranID.value = formName.elements[i].value;

					status=true;

					break;

				}//if2

			}//if1

		}//for1

		if(radioFound == true){

			if(status=="false"){//if1

				alert(msg);

				return false; 

			}//if1

			formName.tableID.value = tableId;

			submitForm(formName,opID,action);

		}

				

	}

	

	

	 /**

	 * This methods for validating the frozen drop down

	 *

	 */

	function ValidateFrozenDropdownList(formName,fieldName,msg){



	var obj = eval("formName."+fieldName);

	//alert(obj.length);

		for(i=0; i< obj.length; i++){

			if(obj[i].type=="select-one"){

				if(obj[i].selectedIndex == 0 && obj[i].options.length>1){//if1

						alert(msg);

						obj[i].focus();

						return false;

						break;

					}

					else{

				}

			}

		}

		return true;

	}

	

	/**

	 * This methods for validating the Status History without radio

	 *

	 */

	function  submitStatusHistory(formName,opID,tableId,action){

	

		formName.tranID.value = formName.eventID.value;

		formName.tableID.value = tableId;

		submitForm(formName,opID,action);

	

	}

	

	/**

	 * This methods for validating the Payment Status History 

	 *

	 */

	function  ValidatePaymentStatusHistory(formName,opID,msg,tableId,action){

		var radioFound = false;

		var selectedID;

		var paymentIDObj;

		status=false;

		for(i=0; i< formName.elements.length; i++){//for1

			if(formName.elements[i].type=="radio"){//if2

				radioFound = true;

				if(formName.elements[i].checked){//if3

					if (formName.elements[i].value<0){

					alert("History can be viewed only for save data");

					return false;

					}

					status=true;

					selectedID = formName.elements[i].value;

					paymentIDObj = document.getElementById(selectedID);

					if(null != paymentIDObj){

						formName.tranID.value =  paymentIDObj.value;

						break;		

					}

				}//if3



			}//if2



		}//for1

		if(radioFound == true){

			if(status=="false"){//if1

				alert(msg);

				return false; 

			}//if1

			else{

				formName.tableID.value = tableId;

				return submitForm(formName,opID,action);

			}

		}	



	}

	

	

	

	var downStrokeField;

	

	function autojump(fieldName,nextFieldName,fakeMaxLength,formName)
	{
	

	if(formName != null){

		var myForm=formName;

	}

	else{

		var myForm=document.forms[document.forms.length - 1];

	}

	

	var myField=myForm.elements[fieldName];

	myField.nextField=myForm.elements[nextFieldName];

	

	if (myField.maxLength == null)
	   myField.maxLength=fakeMaxLength;
	   myField.onkeydown=autojump_keyDown;
       myField.onkeyup=autojump_keyUp;

	}
	

	function autojump_keyDown()

	{

	

	this.beforeLength=this.value.length;

	downStrokeField=this;

	}

	

	

	function autojump_keyUp()

	{

	if ((this == downStrokeField) && (this.value.length > this.beforeLength) &&  (this.value.length >= this.maxLength)  )

	   this.nextField.focus();

	   downStrokeField=null;

	

	}

	

	/**

	 * 

	 * Checks if the radio button has been checked or not.

	 * Confirmation checked 

	 *

	 */

	function validateConfirmRadioSelected(formName,operationId,message,targetAction,confirmMessage){

		var status=false;

		var radioFound = false;

		for(i=0; i< formName.elements.length; i++){//for1

			if(formName.elements[i].type=="radio"){//if1

				radioFound = true;

				if(formName.elements[i].checked){//if2

					status=true;

					break;

				}//if2

			}//if1

		}//for1

		//alert("br radioFound---->"+radioFound);

		if(radioFound == true){

			//alert("ar radioFound--->"+radioFound);

			if(status==false ){//if1

				alert(message);

				return false; 

			}//if1

			else{

				status=confirm(confirmMessage);	

				if(status){

					

						return submitForm(formName,operationId);

					}

					else{

						return false;

					}

				

			}

		}

	}

	/**

	 * 

	 * This opens the help window. 

	 *

	 */	

	function showHelp(urlString)

	{

		

		if(urlString==null || urlString.length==0)

		{

			alert("Help for this screen is under construction.");

			return false;

		}

		else

		{

			window.open(urlString,'eHEAT','eHEAT-Help');

			return true;

		}

	}

	

	function showToolTip()

	{

		/* get the mouse left position */	

		x = event.clientX + document.body.scrollLeft + 105;



		/* get the mouse top position */

		y = event.clientY + document.body.scrollTop + 15;



		/* display the popup */

		Popup.style.display="block";

		

		/* set the popups left */

		Popup.style.left = x;

		

		/* set the popups top */

		Popup.style.top = y;

	}





	function hideToolTip()

	{

		Popup.style.display = "none";

	}

	

	

	

	

/************************************************************************************

* Note:*******************************************************************************

* The use of methods with oToolTip._ prefix is for internal use only (I wish there was a private/public)*

* In order to use this code you just need to use the oToolTip.showToolTip() and the oToolTip.hideToolTip()*

* methods.****************************************************************************

*************************************************************************************/



var oToolTip = new Object();

oToolTip._topDivZIndex = 10000;

oToolTip._oBody = null;

oToolTip._oHelperIframe = null;

oToolTip._oToolTipDiv = null;

oToolTip._mousePos = new Object();

// Add dynamic div to the page

oToolTip._init = function(){

// Creating and adding dynamic iframe to the page source.

oToolTip._oBody = document.getElementsByTagName("BODY").item(0);

oToolTip._oHelperIframe = document.createElement("IFRAME");

oToolTip._oHelperIframe.style.border = 0;

oToolTip._oHelperIframe.width = 0;

oToolTip._oHelperIframe.height = 0;

oToolTip._oHelperIframe.style.position = "absolute";

oToolTip._oBody.appendChild(oToolTip._oHelperIframe);



// Creating and adding dynamic DIV to the page source (for the tool-tip).

oToolTip._oToolTipDiv = document.createElement("DIV");

oToolTip._oToolTipDiv.style.border = 0;

oToolTip._oToolTipDiv.width = 0;

oToolTip._oToolTipDiv.height = 0;

oToolTip._oToolTipDiv.style.position = "absolute";

oToolTip._oBody.appendChild(oToolTip._oToolTipDiv);



oToolTip._attachToEvent(document, 'onmousemove', oToolTip._mousemove);

}



// Should return the div actual width.

oToolTip._getToolTipDivWidth = function(){

// We are checking the inner table because of a bug in NS/Mozilla with the DIV-->offsetWidth

var tableWidth = "" + oToolTip._oToolTipDiv.getElementsByTagName("table").item(0).offsetWidth;

if(tableWidth.indexOf('px') > -1){

return parseInt(tableWidth.substring(0, tableWidth.infexOf('px')));

} else {

return tableWidth;

}

}



// Should return the div actual Height.

oToolTip._getToolTipDivHeight = function(){

// We are checking the inner table because of a bug in NS/Mozilla with the DIV-->offsetHeight

var tableHeight = "" + oToolTip._oToolTipDiv.getElementsByTagName("table").item(0).offsetHeight;

if(tableHeight.indexOf('px') > -1){

return parseInt(tableHeight.substring(0, tableHeight.infexOf('px')));

} else {

return tableHeight;

}

}



oToolTip._mousemove = function(e){

if(typeof(e) == 'undefined')e = event;

oToolTip._mousePos.Y = e.clientY;

oToolTip._mousePos.X = e.clientX;

if(oToolTip._oToolTipDiv.style.visibility == 'visible'){

oToolTip._fixTipPosition();

}

}



// Will move the div and the helper iframe to the given X and Y position

oToolTip._fixTipPosition = function(){

// Set the Y position

if(oToolTip._mousePos.Y > Math.round(oToolTip._oBody.clientHeight / 1 )){

// Open to top

oToolTip._oHelperIframe.style.top = oToolTip._mousePos.Y - oToolTip._getToolTipDivHeight() + oToolTip._oBody.scrollTop; 

}

else {

// Open to bottom

oToolTip._oHelperIframe.style.top = oToolTip._mousePos.Y + oToolTip._oBody.scrollTop; 

}



// Set the X position

if(oToolTip._mousePos.X > Math.round(oToolTip._oBody.clientWidth / 2)){

// Open to left

oToolTip._oHelperIframe.style.left = oToolTip._mousePos.X - oToolTip._getToolTipDivWidth() + oToolTip._oBody.scrollLeft; 

}

else {

// Open to right

oToolTip._oHelperIframe.style.left = oToolTip._mousePos.X + 5 + oToolTip._oBody.scrollLeft; 

}



oToolTip._oToolTipDiv.style.top = oToolTip._oHelperIframe.style.top;

oToolTip._oToolTipDiv.style.left = oToolTip._oHelperIframe.style.left;

}



oToolTip._attachToEvent = function(obj, name, func) {

name = name.toLowerCase();

// Add the hookup for the event.

if(typeof(obj.addEventListener) != "undefined") {

if(name.length > 2 && name.indexOf("on") == 0) name = name.substring(2, name.length);

obj.addEventListener(name, func, false);

} else if(typeof(obj.attachEvent) != "undefined"){

obj.attachEvent(name, func);

} else {

if(eval("obj." + name) != null){

// Save whatever defined in the event

var oldOnEvents = eval("obj." + name);

eval("obj." + name) = function(e) {

try{

func(e);

eval(oldOnEvents);

} catch(e){}

};

} else {

eval("obj." + name) = func;

}

}

}



// Will show the div and the helper iframe.

oToolTip.showToolTip = function(theSelName){

oToolTip._oHelperIframe.style.zIndex = oToolTip._topDivZIndex++;

var theSel = theSelName.options;

var lengthOfSelectedRoleScreens=theSel.length;

var toolTipMessage = '';

var divContent = "<table style='border:1px solid black;background-color:LightGoldenrodYellow' cellspacing='0' cellpading='0'><tr><td>" +toolTipMessage+"</td></tr></table>";

for(i=1;i<lengthOfSelectedRoleScreens;i++){

	if(theSelName.options[i].selected == true)

	{

		toolTipMessage= theSelName.options[i].text;

		var divContent = "<table style='border:1px solid black;background-color:LightGoldenrodYellow' cellspacing='0' cellpading='0'><tr><td>" +toolTipMessage+"</td></tr></table>";

	}

}

//var divContent = "<table style='border:1px solid black;background-color:LightGoldenrodYellow' cellspacing='0' cellpading='0'><tr><td>" +toolTipMessage+ "." +rtext + "</td></tr></table>";

oToolTip._oToolTipDiv.innerHTML = divContent; 

oToolTip._mousePos

oToolTip._oToolTipDiv.style.zIndex = oToolTip._topDivZIndex++;

oToolTip._oHelperIframe.style.top = oToolTip._oToolTipDiv.style.top;

oToolTip._oHelperIframe.style.left = oToolTip._oToolTipDiv.style.left;

oToolTip._oHelperIframe.width = oToolTip._getToolTipDivWidth();

oToolTip._oHelperIframe.height = oToolTip._getToolTipDivHeight();

oToolTip._oHelperIframe.style.visibility = 'visible';

oToolTip._oToolTipDiv.style.visibility = 'visible';



oToolTip._fixTipPosition();

}



// Will hide the div and the helper iframe.

oToolTip.hideToolTip = function(){

oToolTip._oHelperIframe.style.visibility = 'hidden';

oToolTip._oToolTipDiv.style.visibility = 'hidden';

}



// Attach to the onload event

oToolTip._attachToEvent(window, 'onload', oToolTip._init);



///////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////RATE TABLE ////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////



function openNewWindow(theurl)

{

	// set width and height

	var the_width=1000;

	var the_height=650;

	// set window position

	var from_top=0;

	var from_left=0;

	// set other attributes

	var has_toolbar='no';

	var has_location='no';

	var has_directories='no';

	var has_status='no';

	var has_menubar='yes';

	var has_scrollbars='yes';

	var is_resizable='yes';

	// atrributes put together

	var the_atts='width='+the_width+',height='+the_height+',top='+from_top+',screenY='+from_top+',left='+from_left+',screenX='+from_left;

	the_atts+=',toolbar='+has_toolbar+',location='+has_location+',directories='+has_directories+',status='+has_status;

	the_atts+=',menubar='+has_menubar+',scrollbars='+has_scrollbars+',resizable='+is_resizable;

	// open the window

	window.open(theurl,'',the_atts);

}



function openNewCopyWindow(theurl)

{

	// set width and height

	var the_width=450;

	var the_height=130;

	// set window position

	var from_top=150;

	var from_left=250;

	// set other attributes

	var has_toolbar='no';

	var has_location='no';

	var has_directories='no';

	var has_status='no';

	var has_menubar='no';

	var has_scrollbars='no';

	var is_resizable='no';

	// atrributes put together

	var the_atts='width='+the_width+',height='+the_height+',top='+from_top+',screenY='+from_top+',left='+from_left+',screenX='+from_left;

	the_atts+=',toolbar='+has_toolbar+',location='+has_location+',directories='+has_directories+',status='+has_status;

	the_atts+=',menubar='+has_menubar+',scrollbars='+has_scrollbars+',resizable='+is_resizable;

	// open the window

	window.open(theurl,'',the_atts);

}





function enableSubmit(formName){				

   if (formName.checkPending.checked) {	

		 formName.btnSubmit.disabled=true;

		 formName.btnApprove.disabled=true;

		 formName.checkPending.value="check";

	}//if

	else{

		 formName.btnSubmit.disabled=false;

//		 formName.btnApprove.disabled=false;

		 formName.checkPending.value="unCheck";

		 formName.btnSubmit.focus();

	}//else

	return true;

}





function onLoad(menuId){



 if(rateTableDetailForm.checkPending != null){	

	if(rateTableDetailForm.checkPending.value="check"){

		rateTableDetailForm.checkPending.checked = true;	

	}else if(rateTableDetailForm.checkPending.value="unCheck"){

		rateTableDetailForm.checkPending.checked = false;	

	}

	

	if(rateTableDetailForm.checkPending.checked){

		//rateTableDetailForm.btnSubmit.disabled = true;

		//rateTableDetailForm.btnApprove.disabled = true;

	}else{

		//rateTableDetailForm.btnSubmit.disabled = false;

//		rateTableDetailForm.btnApprove.disabled = false;



	}	

 }

	showContent(menuId);

	return true;

}



function onLoadGeography(){



 if(rateTableDetailForm.checkPending != null){	

	if(rateTableDetailForm.checkPending.value="check"){

		rateTableDetailForm.checkPending.checked = true;	

	}else if(rateTableDetailForm.checkPending.value="unCheck"){

		rateTableDetailForm.checkPending.checked = false;	

	}

	

	if(rateTableDetailForm.checkPending.checked){

		//rateTableDetailForm.btnSubmit.disabled = true;

		//rateTableDetailForm.btnApprove.disabled = true;

	}else{

		//rateTableDetailForm.btnSubmit.disabled = false;

       //rateTableDetailForm.btnApprove.disabled = false;



	}	

 }


    showContent(4);	
	return true;

}











function onLoadCheck(tabNumber){

	if(rateTableDetailForm.checkPending.checked){
		rateTableDetailForm.checkPending.checked = true;
		rateTableDetailForm.btnSubmit.disabled = true;
		rateTableDetailForm.btnApprove.disabled = true;
		rateTableDetailForm.btnApprove.disabled = true;
		rateTableDetailForm.btnCopy.disabled = true;
		
	}
	
	showContent(tabNumber);
	return true;

}



function rateTableModeSubmit(formName,targetAction, modeValue,pageValue){
	
	if (modeValue=="Submit" && (formName.checkPending.checked)){
		alert("Please uncheck pending status");
		return false;
	}

	
	

	if(modeValue == "Save"){

		if(validate(pageValue)){

			formName.rateTableMode.value = modeValue;

			formName.action = targetAction;

			formName.submit();

			return true;

		}

	}
	
	 if(modeValue != "Save"){

		// if(formName.approvedBy.value.length > 0 && formName.approvedBy.value != null){
		// alert("Rate Table already approved By-"+formName.approvedBy.value+"@"+formName.approvedOn.value);        
		// return false;
	    // }
		formName.rateTableMode.value = modeValue;
		formName.action = targetAction;
		formName.submit();
		return true;



	}

}




function validate(tab){
   if( tab == "rateTableDetailTab" ){
      return saveRateTableCheck();
   }else if( tab == "baseRatesTab"){
    return true;
   }else if( tab == "adjustmentsTab" ){
    return true;
   }else if( tab == "geoTab" ){
     return true;
   }
   alert("Invalid Tab option-" + tab + "-selected");
   return false;
}

function saveRateTableCheck(){

   

   	var status=true;    

    var missing = "";

	
	if( document.rateTableDetailForm.selectedLOB.value == "0"){

		status = false;

        missing += "\nLine Of Business";

        

    } 



	if( document.rateTableDetailForm.selectedRTType.value == "0"){

		status = false;

        //alert("Please select Rate Table Type");

        missing += "\nRate Table Type";

        

    } 

    // checked for country type if usa

	if (document.rateTableDetailForm.chkCountryType.value != "" && document.rateTableDetailForm.chkCountryType.value == "1") {

	

		if(trim(document.rateTableDetailForm.mssProgramCode.value) == "" ||  trim(document.rateTableDetailForm.mssProgramCode.value) == null){

			//status = false;

	        //alert("Please enter MSS Program Code");

	        //missing += "\nMSS Program Code(numbers only)";

	        

	    }else{

			var str=trim(document.rateTableDetailForm.mssProgramCode.value);

			if(containsOnly(str,'0-9 a-z A-Z')) // is it contains only alphabets and numbers..?

			{

			}

			else

			{

				alert("MSS Program Code allows only AlphaNumerics.");

				//missing += "\nMSS Program Code(numeric)";

				status = false;

				//document.rateTableDetailForm.mssProgramCode.focus();

				return false;

			}

		}

		

	} //checked for country type if usa

	

	// checked for country type if canada

	if (document.rateTableDetailForm.chkCountryType.value != "" && document.rateTableDetailForm.chkCountryType.value == "2") {

	

		if(trim(document.rateTableDetailForm.discountingExpiryDate.value) == "" ||  trim(document.rateTableDetailForm.discountingExpiryDate.value) == null){

			status = false;

	        //alert("Please enter MSS Program Code");

	        missing += "\nDiscounting Expiry Date";

	        

	    }

	    

	} //checked for country type if canada

	

	if (trim(document.rateTableDetailForm.rateName.value)=="" || trim(document.rateTableDetailForm.rateName.value==null)){

		status=false;

		//alert("Please enter RateTable Name");

		missing += "\nRateTable Name";

		status = false;

      // document.rateTableDetailForm.rateName.focus();

		

	}



	if (trim(document.rateTableDetailForm.detailEffectiveDate.value)=="" || trim(document.rateTableDetailForm.detailEffectiveDate.value==null)){

		status=false;

		//alert("Please enter Effective Date");

		missing += "\nEffective Date";

		status = false;

//		document.rateTableDetailForm.detailEffectiveDate.focus();

		

	}



	if (trim(document.rateTableDetailForm.expirationDate.value)=="" || trim(document.rateTableDetailForm.expirationDate.value==null)){

		status=false;

		//alert("Please enter Expiration Date");

		missing += "\nExpiration Date";

		status = false;

//		document.rateTableDetailForm.expirationDate.focus();

		

	}



	

	if (status) {

		return true;

	}else{

	   alert( "Please provide the following information:" + missing);

	   return false;

	}



}



function showContent(menuId){

	// Set Selected

	if (null != document.getElementById(menuId)){

		document.getElementById(menuId).className = "activeMenu";

		document.getElementById(menuId + 100).className = "activeMenu";

	}

	// Flip to Normal Menu

	for(i=1;i<=6;i++){ 

		if( i != menuId && null != document.getElementById(i)){

			document.getElementById(i).className = "defaultMenu";

			document.getElementById(i+100).className = "defaultMenu";

		} 

	} 

}



////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////RATE TABLE/////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////



/////////////////////CHARGE & FEES ///////////////////////////////////////

function checkDecimals(fieldName, fieldValue) {

	decallowed = 2;  // how many decimals are allowed?

	if (isNaN(fieldValue) || fieldValue == "") {
		alert("Please enter valid Amount.");
		fieldName.select();
		fieldName.focus();
	}
	else {
		if (fieldValue.indexOf('.') == -1) fieldValue += ".";
			dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

		if (dectext.length > decallowed)
		{
//			alert ("Amount allows" + decallowed + " decimal places.  Please try again.");
			alert("Only two decimal places allowed,99.99");
			fieldName.select();
			fieldName.focus();
	    }
	else {
		return true;
	    }
   }
}


function getSelectedGeoIds(formName){
	var status=true; 
	var lengthOfSelectedGeos=formName.selectedGeos.options.length;
	var selectedGeoArrays = new Array();
	var	geoName="";
	var	geoNameValue="";
	var j = 0;
	for(i=1;i<lengthOfSelectedGeos;i++){
		if(formName.selectedGeos.options[i].selected)
		{
			geoName=formName.selectedGeos.options[i].text;
			geoNameValue= geoNameValue+formName.selectedGeos.options[i].value +"+"+geoName+"*";
			j++;
		}
	}
	formName.selectedGeosArray.value = geoNameValue;
	
	
	if (trim(formName.feeDescription.value)=="" || trim(formName.feeDescription.value==null)){
		status=false;
		alert("Please enter Fee Description.");
		formName.feeDescription.focus();
		return false;
	}
		
	if (formName.selectedFeeType.selectedIndex==0){
		status=false;
		alert("Please select Fee Type.");					
		formName.selectedFeeType.focus();
		return false;
	}		

	if (trim(formName.amount.value)=="" || trim(formName.amount.value==null)){
		status=false;
		alert("Please enter Amount.");
		formName.amount.focus();
		return false;
	}else{
		if(checkDecimals(document.addFeeActionForm.amount,document.addFeeActionForm.amount.value)){
		}else{
			return false;
		}
	}
		
	if (trim(formName.effectiveDate.value)=="" || trim(formName.effectiveDate.value==null)){
		status=false;
		alert("Please enter Effective Date.");
		formName.effectiveDate.focus();
		return false;
	}

	if (trim(formName.expirationDate.value)=="" || trim(formName.expirationDate.value==null)){
		status=false;
		alert("Please enter Expiration Date.");
		formName.expirationDate.focus();
		return false;
	}else{
			var effDate  = new Date(formName.effectiveDate.value);
			var expDate = new Date(formName.expirationDate.value);
			var compare = ((effDate) - (expDate))/86400000 ;

			if(compare >= 1){
				alert("Please enter valid Expiration Date." );
				formName.expirationDate.value == "";
			return false;
			}
	}
	
	if ((formName.selectedLocation.options.length < 1)){
		status=false;
		alert("Please select Geography Type.");					
		formName.selectedLocation.focus();
		return false;
	}		

	if(formName.selectedLocation.value == 0){
		
	}else{
		if((formName.selectedGeos.options.length < 1) || (formName.selectedGeos.value) == ""){
			alert("Please select Geography.");
			status = false;
			formName.selectedGeos.focus();
			return false;
		}
	}

	if((formName.selectedLOB.options.length < 2) || (formName.selectedLOB.value) == ""){
		alert("Please select Line Of Business.");
		status = false;
		formName.selectedLOB.focus();
		return false;
	}
	else if(formName.selectedLOB.selectedIndex==0){
		var selLength = formName.selectedLOB.options.length;
		var selectedCount = 1;
		var i;
		for(i=selLength-1; i>=1; i--){
			if(formName.selectedLOB.options[i].selected){
				selectedCount++;
			}
		}
		if(selectedCount> 1){
			alert("Please select valid Line Of Business.");
			status = false;
			formName.selectedLOB.focus();
			return false;
		}
	}



	if((formName.selectedUsageType.options.length < 2) || (formName.selectedUsageType.value) == ""){
		alert("Please select Usage Type.");
		status = false;
		formName.selectedUsageType.focus();
		return false;
	}
	else if(formName.selectedUsageType.selectedIndex==0){
		var selLength = formName.selectedUsageType.options.length;
		var selectedCount = 1;
		var i;
		for(i=selLength-1; i>=1; i--){
			if(formName.selectedUsageType.options[i].selected){
				selectedCount++;
			}
		}
		if(selectedCount> 1){
			alert("Please select valid Usage Type.");
			status = false;
			formName.selectedUsageType.focus();
			return false;
		}
	}


/*	if (formName.selectedMake.selectedIndex==0){
		status=false;
		alert("Please select Make.");					
		formName.selectedMake.focus();
		return false;
	}		
*/
	for (counter = 0; counter < formName.radioSelect.length; counter++){
		if (formName.radioSelect[counter].checked){
			if(formName.radioSelect[counter].value == "make"){
					if((formName.selectedMake.options.length < 2) || (formName.selectedMake.value) == ""){
						alert("Please select Make.");
						status = false;
						formName.selectedMake.focus();
						return false;
					}
					else if(formName.selectedMake.selectedIndex==0){
						var selLength = formName.selectedMake.options.length;
						var selectedCount = 1;
						var i;
						for(i=selLength-1; i>=1; i--){
							if(formName.selectedMake.options[i].selected){
								selectedCount++;
							}
						}
						if(selectedCount> 1){
							alert("Please select valid Make.");
							status = false;
							formName.selectedMake.focus();
							return false;
						}
					}
					
			}
			else if(formName.radioSelect[counter].value == "modelYear"){
					if (formName.selectedMake.selectedIndex==0){
						status=false;
						alert("Please select Make.");					
						formName.selectedMake.focus();
						return false;
					}		
					if((formName.selectedYear.options.length < 2) || (formName.selectedYear.value) == ""){
						alert("Please select Year.");
						status = false;
						formName.selectedYear.focus();
						return false;
					}
					else if(formName.selectedYear.selectedIndex==0){
						var selLength = formName.selectedYear.options.length;
						var selectedCount = 1;
						var i;
						for(i=selLength-1; i>=1; i--){
							if(formName.selectedYear.options[i].selected){
								selectedCount++;
							}
						}
						if(selectedCount> 1){
							alert("Please select valid Year.");
							status = false;
							formName.selectedYear.focus();
							return false;
						}
					}
			}
			else if(formName.radioSelect[counter].value == "class"){
					if (formName.selectedMake.selectedIndex==0){
						status=false;
						alert("Please select Make.");					
						formName.selectedMake.focus();
						return false;
					}		

					if (formName.selectedYear.selectedIndex==0){
						status=false;
						alert("Please select Year.");					
						formName.selectedYear.focus();
						return false;
					}		
					if((formName.selectedClass.options.length < 2) || (formName.selectedClass.value) == ""){
						alert("Please select Class.");
						status = false;
						formName.selectedClass.focus();
						return false;
					}
					else if(formName.selectedClass.selectedIndex==0){
						var selLength = formName.selectedClass.options.length;
						var selectedCount = 1;
						var i;
						for(i=selLength-1; i>=1; i--){
							if(formName.selectedClass.options[i].selected){
								selectedCount++;
							}
						}
						if(selectedCount> 1){
							alert("Please select valid Class.");
							status = false;
							formName.selectedClass.focus();
							return false;
						}
					}
			}

			else if(formName.radioSelect[counter].value == "model"){

					if (formName.selectedMake.selectedIndex==0){
						status=false;
						alert("Please select Make.");					
						formName.selectedMake.focus();
						return false;
					}		
					if (formName.selectedYear.selectedIndex==0){
						status=false;
						alert("Please select Year.");					
						formName.selectedYear.focus();
						return false;
					}		
					if (formName.selectedClass.selectedIndex==0){
						status=false;
						alert("Please select Class.");					
						formName.selectedClass.focus();
						return false;
					}		
					if((formName.selectedModel.options.length < 2) || (formName.selectedModel.value) == ""){
						alert("Please select Model.");
						status = false;
						formName.selectedModel.focus();
						return false;
					}
					else if(formName.selectedModel.selectedIndex==0){
						var selLength = formName.selectedModel.options.length;
						var selectedCount = 1;
						var i;
						for(i=selLength-1; i>=1; i--){
							if(formName.selectedModel.options[i].selected){
								selectedCount++;
							}
						}
						if(selectedCount> 1){
							alert("Please select valid Model.");
							status = false;
							formName.selectedModel.focus();
							return false;
						}
					}
					

			}
		}
	}

	if (status) {
		formName.mode.value = "Save";
		formName.submit();
		return true;
	}
	else {
		 return false;
   	}
}

function submitCF(formName,modeValue){
	formName.mode.value = modeValue;
	formName.submit();
}

function submitGeoType(formName)
{
	formName.mode.value="geoType";
	formName.submit();
}


function submitLOB(formName)
{
	var selLength = formName.selectedLOB.options.length;
	var selectedText = new Array();
	var selectedValues = new Array();
	var selectedCount = 0;
	var i;
		for(i=selLength-1; i>=1; i--){
			if(formName.selectedLOB.options[i].selected){
				selectedText[selectedCount] = formName.selectedLOB.options[i].text;
				selectedValues[selectedCount] = formName.selectedLOB.options[i].value;
				selectedCount++;
			}
		}
	if((selectedCount = 1)){
		//if(formName.selectedLOB.selectedIndex > 0){
			formName.mode.value="geoType";
			formName.submit();
		//}
	}
}


function submitMake(formName)
{
	formName.mode.value="makeSubmit";
	formName.vehicleMode.value="makeSubmit";
	formName.submit();
}

function submitYear(formName)
{
	formName.mode.value="yearSubmit";
	formName.vehicleMode.value="yearSubmit";
	formName.submit();
}

function submitClass(formName)
{
	formName.mode.value="classSubmit";
	formName.vehicleMode.value = "classSubmit";
	formName.submit();
}

function radioCheck(formName){
	for (counter = 0; counter < formName.radioSelect.length; counter++)
	{
		if (formName.radioSelect[counter].checked){
			if(formName.radioSelect[counter].value == "make"){
					formName.displayMake.value = "multiple";
					formName.displayModel.value = null;
					formName.displayClass.value = null;
					formName.displayModelYear.value = null;
					formName.mode.value = "Display";
					formName.vehicleMode.value = "makeRadio";
					formName.submit();				
			}
			else if(formName.radioSelect[counter].value == "modelYear"){
					formName.displayModelYear.value = "multiple";
					formName.displayMake.value = "single";
					formName.displayClass.value = null;
					formName.displayModel.value = null;				
					formName.selectedMake.value = null;
					formName.mode.value = "Display";				
					formName.vehicleMode.value = "makeSubmit";
					formName.submit();
			}
			else if(formName.radioSelect[counter].value == "class"){
					formName.displayClass.value = "multiple";
					formName.displayMake.value = "single";
					formName.displayModelYear.value = "single";				
					formName.displayModel.value = null;
					formName.selectedMake.value = null;
					formName.selectedYear.value = null;
					formName.mode.value = "Display";				
					formName.vehicleMode.value = "yearSubmit";				
					formName.submit();								
			}
			else if(formName.radioSelect[counter].value == "model"){
					formName.displayModel.value = "multiple";
					formName.displayMake.value = "single";
					formName.displayClass.value = "single";
					formName.displayModelYear.value = "single";				
					formName.selectedMake.value = null;
					formName.selectedYear.value = null;
					formName.selectedClass.value = null;
					formName.mode.value = "Display";				
					formName.vehicleMode.value = "classSubmit";
					formName.submit();								
			}
		}
			
	}
}


function isDecimalWith5Digits(field,desc){
		var str=trim(field.value);
		var i;
		var ch;
		if(isNotEmpty(field,desc)){
			if(str=="."){
				alert(desc + " must be a valid numeric entry.  \nPlease do not use commas or dollar signs or any non-numeric symbols.");
				return false;

			}
			var pos1=str.indexOf(".");
			if(pos1==-1) // no decimal point
			{
				//return(isNumber(field,desc));
				alert(desc+" decimal point must be specified"); 
				return false;
			}
			var pos2=str.lastIndexOf(".");
			//alert(pos2);
			if(pos1!=pos2) //ie there r more than 1 dec. points
			{
				alert(desc+" contains more than one decimal point!");
				return false;
			}
			if(str.indexOf("-")!=-1){
				str=str.substring(1,str.length);
			}
			for (i = 0; i < str.length; i++){
				ch=str.charAt(i);
				if (( ch< '0' || ch > '9')&&(ch!='.')){
					alert(desc + " must be a valid decimal entry. \nPlease do not use any non-numeric symbols other than decimal point.");
					field.focus();
					return false;
				}
			}
			//alert(str);
			//alert(pos1);
			if(str.length-pos1<6 && pos1>0){
				alert(desc+" should contain five digits after decimal place !");
				return false;
			}
		}
		else{
			return false;
		}
			return true;
}


function checkForOverlapTerms(fromTerm,toTerm){
    var tempFromTerm=fromTerm;
    var tempToTerm=toTerm;
	for (i=0;i<fromTerm.length;i++){		
		fromStr=fromTerm[i];
		toStr=toTerm[i];
		for(j=0;j<tempFromTerm.length;j++){
			if (i==j) continue;
			//alert(fromStr +"/"+tempFromTerm[j]+"/"+tempToTerm[j]);
				if (fromStr >= tempFromTerm[j] && fromStr <= tempToTerm[j] ){
					message="In Term : "+(j+1)+"\n";
					message=message+"Overlapping of Term Ranges found.";
					alert(message);
					return false;
				}
			//alert(toStr +"/"+tempFromTerm[j]+"/"+tempToTerm[j]);
				if (toStr >= tempFromTerm[j] && toStr <= tempToTerm[j] ){
					message="In Term : "+(j+1)+"\n";
					message=message+"Overlapping of Term Ranges found.";
					alert(message);
					return false;
				}
			}
	}
	return true;
}
 
function testAlerts(id,alertMessage)
{
	alert(""+alertMessage);
	if(id=="description" || id=="content")
	{
		/*
		if(id=="description")
		{ 
			document.form1.description.select();
			document.form1.description.focus();
		}else
		{ alert("content : ");
			document.form1.content.select();
			document.form1.content.focus();
		}
		*/
		return false;
	}
	else{
		document.getElementById(id).select();
		document.getElementById(id).focus();	
	}
		return false;
}
