//*********************************************************
//AUTO TAB
//*********************************************************
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	function auto_Tab(input,len, e) {
		var keyCode = (isNN) ? e.which : e.keyCode; 
		var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
		if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
		found = true;
		else
		index++;
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)index = i;
		else i++;
		return index;
		}
		return true;
	}
//*********************************************************
//*********************************************************
function trim(txt) {
	if (txt=="") return txt;
	var first=0;
	var last=txt.length;
	while (txt.charAt(first) == " ") first++;
	while (txt.charAt(last-1) == " ") last--;
	//if txt have all spaces then last is < first
	if (last<first)last=first=0;
	return txt.substring(first,last);
}

function spacesBetwenChars(txt,formInput){
	for(var i=0;i<txt.length;i++){
		if (txt.charAt(i)==" "){
			alert ("Spaces betwen characters are not allowed");
			formInput.focus();
			return true;
		}
	}
	return false;
}

function spacesBetwenCharsNoMessage(txt,formInput){
	for(var i=0;i<txt.length;i++){
		if (txt.charAt(i)==" "){
			formInput.focus();
			return true;
		}
	}
	return false;
}

function isAlphanumericChar(ch){
	var charCode=ch.charCodeAt(0);
	if( (charCode>=48 && charCode<=57) || (charCode>=65 && charCode<=90) || (charCode>=97 && charCode<=122) )
		return true;
	else
		return false;
}

function isNumericChar(ch){
	var charCode=ch.charCodeAt(0);
	if( (charCode>=48 && charCode<=57))
		return true;
	else
		return false;
}

function SpecialChars( txt, special, numbers, spaces, formInput) {
	for(var i=0;i<txt.length;i++){
		var ch = txt.charAt(i);
		if ( !isAlphanumericChar(ch) && !(ch==' ' && spaces) && ( special.indexOf(ch) == -1 ) ){
			formInput.focus();
			return true;
		}
		if(!numbers){
			if (isNumericChar(ch)){
				formInput.focus();
				return true;
			}
		}
	}
	return false;
}

function isSelected(inputctrl, alerttxt) {
	if (!inputctrl)
	{
		return true;
	}
	
	if (inputctrl.disabled == true) {
		return true;
	}
	if ( (typeof inputctrl.type) == "undefined" ) { 
		alert("Wrong field type, cannot check the size.")
		return false
	}
	else {
			switch(inputctrl.type) {
				case "select-one":
					if(inputctrl.selectedIndex==0){
						alert(alerttxt);
						inputctrl.focus();
						return false;
					}
					return true;
					break;
				case "select-multiple":
					if(inputctrl.selectedIndex==-1){
						alert(alerttxt);
						inputctrl.focus();
						return false;
					}
					return true;
					break;
				case "text","password":
					alert("Wrong field type, cannot check the size.")
					return false;
					break;
				case "checkbox":
					alert("Wrong field type, cannot check the size.")
					return false
					break;
				case "textarea":
					alert("Wrong field type, cannot check the size.")
					return false
					break;
			}
	
	}
	return false;
}

function FieldSize (inputctrl , mandatory , requiredlength , characterLimit , alerttxtEmpty , alerttxt ,  alerttxt2 ) {
		
		if (inputctrl.disabled == true) {
		//alert(inputctrl.disabled + "tets")	
		return true;
		}
		//MANDATORY LOGIC
		//if (mandatory) {
			//CONTINUE		
		//}
		//LET'S CHECK TO SEE IF THERE IS ANYTHING IN THE FIELD AND THEN CONTINUE ONLY IF IT'S NOT BLANK
		//else {
			//NO NEED TO FURTHER CHECK THE SIZE.
		//	if(trim(inputctrl.value) == "") {
		//		return true
		//	}	
		//} 


		if (mandatory) { 
			if(trim(inputctrl.value) == "") {
				alert(alerttxtEmpty);
				inputctrl.focus();
				return false;
			}	
		}

		
		
		if ( (typeof inputctrl.type) == "undefined" ) { 
			alert("Wrong field type, cannot check the size.")
			return false
		}
		else {
				switch(inputctrl.type) {
					case "text","password":
						//alert(inputctrl.value.length + 'sss' + characterLimit)
					
						if (inputctrl.value.length < characterLimit) {
								alert(alerttxt2);
								inputctrl.focus();
								inputctrl.select(); 
								return false;
							}
						//else if (requiredlength == true)
						//		if (inputctrl.value.length < characterLimit)
						//		{
						//		alert(alerttxt2);
						//			inputctrl.focus();
						//			inputctrl.select(); 
						//			return false;
						//		}
						return true;
						break;
					// This is just in case the select only has one checkbox	
					case "checkbox":
						alert("Wrong field type, cannot check the size.")
						return false
						break;
					case "textarea":
					
							if (inputctrl.value.length >= characterLimit) {
								alert(alerttxt);
								inputctrl.focus();
								return false;
							}
							return true;
						break;
				}
	
		}
		return true;
}

function ifSelected(inputctrl , inputctrlValue , mandatory , inputctrlCheck , specChars ,  numbers , spaces, alerttxtEmpty, alerttxt ) {

	if (!inputctrl)
	{
		return true;
	}
	var checkedvalue = "";

	if (!mandatory) {
		if(inputctrl.value == "") {
			//inputctrlCheck.focus();
			return true;
		}
	}
	if (inputctrlValue.indexOf("!")!=-1) {
			notcondition = true;
		}
	else {
			notcondition = false;
		}
	
	//alert(inputctrlCheck.type)
	//return false;
	
	// This is a special case when it's a check box with multiple values.
	if ( (typeof inputctrl.type) == "undefined" ) { 
			
			
				for ( var i = 0; i < inputctrl.length; i++ ) {
				
					if (inputctrl[i].checked == true) {
						//alert(inputctrl[i].value)
						checkedvalue = inputctrl[i].value
						checkedone = true
						break;
					}
					else {
						checkedone = false;
					}
				}
				
				for ( var i = 0; i < inputctrlCheck.length; i++ ) {
					if (inputctrlCheck[i].checked == true) {
						checkedtwo = true
						break;
					}
					else {
						checkedtwo = false;
					}
				}
				
			//focus on the check field
			
						
			if (checkedvalue == inputctrlValue) {
			
				if ( (typeof inputctrlCheck.type) == "undefined" ) { 
				//the check field must be of radio or checkbox type
				
				}
				else {
				
					
					switch(inputctrlCheck.type) {
						case "select-one":
						
							if(isSelected(inputctrlCheck , alerttxtEmpty)){
											//alert(Selected_Option + "-----" + inputctrlValue + ' message ' + alerttxtEmpty)
											return true;		  
										} 
										return false;		  
										break;
						
						
							break;
						case "text":
							if (validName(inputctrlCheck, true, specChars, numbers, spaces, alerttxtEmpty, alerttxt)) {
											return true;
										}
										return false;		  
										break;
							break;
						case "textarea":
							if (validName(inputctrlCheck, true, specChars, numbers, spaces, alerttxtEmpty, alerttxt)) {
											return true;
										}
										return false;		  
										break;
							break;	
						default:
							//alert("Please try again.");
							return false;
							break;	
						// end switch .
						}
				}
			
				
			}
			
			//alert(notcondition + "sss" + checkedone)
	
			
		return true;
			
			
			
	}
	else {
		
					if ( (typeof inputctrlCheck.type) == "undefined" ) { 
											
							for ( var i = 0; i < inputctrlCheck.length; i++ ) {
								if (inputctrlCheck[i].checked == true) {
									checkedtwo = true
									break;
								}
								else {
									checkedtwo = false;
								}
							}
							
						
					}
					
		
						switch(inputctrl.type) {
						case "select-one":
								Selected_Option = inputctrl.options[inputctrl.selectedIndex].value
								
								if(Selected_Option == inputctrlValue){
									
									switch(inputctrlCheck.type) {
										
										case "select-one":
											if(isSelected(inputctrlCheck , alerttxtEmpty)){
												//alert(Selected_Option + "-----" + inputctrlValue + ' message ' + alerttxtEmpty)
												return true;		  
											} 
											return false;		  
											break;
										case "text":
											if (validName(inputctrlCheck, true, specChars, numbers, spaces, alerttxtEmpty, alerttxt)) {
												return true;
											}
											return false;		  
											break;
										case "textarea":
											if (validName(inputctrlCheck, true, specChars, numbers, spaces, alerttxtEmpty, alerttxt)) {
												return true;
											}
											return false;		  
											break;		
										default:
											//alert("Please try again.");
											return true;
											break;			
										}
									return true;		
									}	
							break;
						case "text":
						
							
							//alert(inputctrlCheck.type)
						
								Selected_text = inputctrl.value.toUpperCase();
								
									if (inputctrlValue.indexOf("!")!=-1) {
											inputctrlValue_temp = inputctrlValue.replace('!','').toUpperCase();
											condition = false;
										}
									else {
											inputctrlValue_temp = inputctrlValue.toUpperCase();
											condition = true;
										}	
								
								
								switch(inputctrlCheck.type) {
									case "text":
											if (condition) {
													if (Selected_text == inputctrlValue_temp) {
														if (validName(inputctrlCheck, true, specChars, numbers, spaces, alerttxtEmpty, alerttxt)) {
															return true;
														}
													}
													return true;
											}
											else {
												
												
												
												if (Selected_text != inputctrlValue_temp) {
														if (validName(inputctrlCheck, true, specChars, numbers, spaces, alerttxtEmpty, alerttxt)) {
															return true;
														}
													}
												else {
													//alert(Selected_text+inputctrlValue_temp)
													return true;	
													}	
												
											}
											
											return false;	
										break;
									case "select-one":
									
											if (condition) {
												
											}
											else {
												if(isSelected(inputctrlCheck , alerttxtEmpty)){
													//alert(Selected_Option + "-----" + inputctrlValue + ' message ' + alerttxtEmpty)
													return true;		  
												} 
												return false;
											}
											
										return true;
										break;
									case "radio":
										
									
											if (condition) {
												
											}
											else {
												if(isSelected(inputctrlCheck , alerttxtEmpty)){
													//alert(Selected_Option + "-----" + inputctrlValue + ' message ' + alerttxtEmpty)
													return true;		  
												} 
												return false;
											}
											
										return true;
										break;	
									default:
										//alert("Please try again.");
										if (checkedtwo) {
												return true;
											}
											
										alert(alerttxtEmpty);
										inputctrlCheck[0].focus();	
										return false;
										break;		
									}
									return false;	
							break;	
						case "checkbox":
									
									if (notcondition) {
											if (!inputctrl.checked) {
													
														// This is a special case when it's a check box with multiple values.
														if ( (typeof inputctrlCheck.type) == "undefined" ) { 
																for ( var i = 0; i < inputctrlCheck.length; i++ ) {
																	if (inputctrlCheck[i].checked == true) {
																		return true;
																		break;
																		}
																}
																alert(alerttxtEmpty);
																inputctrlCheck[0].focus();	
																///nothing was checked from the second checkbox	
																return false
																
														}
														else {
																
																switch(inputctrlCheck.type) {
																	case "text":
																		break;
																	// This is just in case the select only has one checkbox	
																	case "checkbox":
																	
																		alert(alerttxtEmpty+'0');
																		
																		break;
																}
														
														}
												
												}
										}
									else {
										
											
										}
									
									
									
									
						
							break;
						default:
							//alert("Please try again.");
							return false;
							break;	
							
						// end for main input type switch .
						}

			// end for else block undefined
			}



return true;
//end for function.
}



	
function RemoveLeadingZeros(strTextIn)
{	
	var strText;

	if (strSource == null) return "";
	strText = strSource;

	if (strText.length == 0) return "";

	for (var intCounter = 0; i < strText.length && strText.charAt(intCounter) == "0"; intCounter++);
	if (intCounter == strText.length) return "";
	
	return strText.substring(intCounter, strText.length);
}

function autoTab(field1, len, field2) {
	
		if (document.getElementById(field1).value.length == len) {
			//if (!document.getElementById(field1).focus())	{
				document.getElementById(field2).focus();
				document.getElementById(field2).select(); 
			//}
		}
}

function autoFill(inputctrl, inputctrl2) {
	
	//alert(document.getElementById(inputctrl).type)
	
		switch(document.getElementById(inputctrl).type) {
				case "text":
					document.getElementById(inputctrl2).value = document.getElementById(inputctrl).value;
					//inputctrl2.value = inputctrl.value;
							
					break;
				// This is just in case the select only has one checkbox	
				case "checkbox":
				
					//alert(alerttxtEmpty+'0');
					
					break;
				case "select-one":

					document.getElementById(inputctrl2).selectedIndex = document.getElementById(inputctrl).selectedIndex;
					
					//alert(alerttxtEmpty+'0');
					
					break;	
			}
}



function togglefield(inputctrl, inputctrl2 , inputctrl3 , startswith) {  
			
		for (var i = 0; i < inputctrl.elements.length; i++) { 
				
				formname = inputctrl.elements[i].id.toUpperCase()
				
				if (inputctrl2) {
					if (inputctrl3 != ""){
						if (formname == inputctrl3.toUpperCase()) {
							//alert(formname + '===' + inputctrl3.toUpperCase())
							inputctrl.elements[i].focus();
						}
					}
				}
				
				if (formname.indexOf(startswith) == 0) {
					disableIt(inputctrl.elements[i])
				}
				
			
			}
				

}

function CompareFields(inputctrl , mandatory , inputctrl2 , alerttxtEmpty) { 
		if (inputctrl.disabled == true) {
		//alert(inputctrl.disabled + "tets")	
		return true;
		}
	
		if (!ismandatory (inputctrl , mandatory ,alerttxtEmpty)) {
			return false
		}
		if (inputctrl.value == inputctrl2.value) {
				return true
			}
		else {
				alert(alerttxtEmpty)
				inputctrl2.focus();
				inputctrl2.select(); 
				return false
			}
} 


function checkValidDateFormat(inputctrl, specCircumstance , dateformat , dateformatdelimitor , intFirstYear , intEndYear , mandatory ,  alerttxtEmpty, alerttxt)
{
	var strMonth;
	var intMonth;
	var strDay;
	var intDay;
	var strYear;
	var intYear;
	var strSlash = new String("/");
	var intPosition;
	var strDate;
	
	if (inputctrl.disabled == true) {
		//alert(inputctrl.disabled + "tets")	
		return true;
	}
	
	
	strDate = inputctrl.value
	
	
	if (mandatory) {
		if(strDate == "") {
			if(alerttxtEmpty!=null)
			{
				alert(alerttxtEmpty);
				inputctrl.focus();
			}	
			return false;
		}
	}
	
	
	if(strDate != "") {
		
		if (specCircumstance == strDate.toUpperCase() && specCircumstance != "") {
			return true;
			}
		else {	
			format = dateformat
			dtStr = strDate
			minYear = intFirstYear
			maxYear = intEndYear
			dtCh 	= dateformatdelimitor
			
			if (isDate(inputctrl , format,dtStr , minYear , maxYear ,  dtCh ))	{
				return true;	
			}
			else {
				return false;	
			}
			
								
		}
				
	}
				
				
	return true;
		
}

function isDate(inputctrl , format , dtStr , minYear , maxYear , dtCh ){
	
	var hasday = false
	var hasmonth = false
	var hasyear = false

	//var format = "mm/yyyy";
	var daysInMonth = DaysArray(12)			
	
	switch(format) {
			case "mm/yyyy":
				var hasday = false
				var hasmonth = true
				var hasyear = true
				var pos1=dtStr.indexOf(dtCh)
				var pos2=dtStr.indexOf(dtCh,pos1)
				var strMonth=dtStr.substring(0,pos1)
				var strYear=dtStr.substring(pos1+1)
				strYr=strYear
				if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
				for (var i = 1; i <= 3; i++) {
					if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
				}
				month=parseInt(parseFloat(strMonth))
				year=parseInt(strYr)
				
				break;
			case "dd/mm/yyyy":
				var hasday = true
				var hasmonth = true
				var hasyear = true
				
				var pos1=dtStr.indexOf(dtCh)
				var pos2=dtStr.indexOf(dtCh,pos1+1)
				var strDay=dtStr.substring(0,pos1)
				var strMonth=dtStr.substring(pos1+1,pos2)
				var strYear=dtStr.substring(pos2+1)
					strYr=strYear
					if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
					if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
					for (var i = 1; i <= 3; i++) {
						if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
					}
					day=parseInt(parseFloat(strDay)) 
					month=parseInt(parseFloat(strMonth))
					year=parseInt(strYr)

				break;
			case "mm/dd/yyyy":
				var hasday = true
				var hasmonth = true
				var hasyear = true
				
				var pos1=dtStr.indexOf(dtCh)
				var pos2=dtStr.indexOf(dtCh,pos1+1)
				var strMonth =dtStr.substring(0,pos1)
				var strDay=dtStr.substring(pos1+1,pos2)
				var strYear=dtStr.substring(pos2+1)
					strYr=strYear
					if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
					if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
					for (var i = 1; i <= 3; i++) {
						if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
					}
					day=parseInt(parseFloat(strDay)) 
					month=parseInt(parseFloat(strMonth))
					year=parseInt(strYr)
				break;	
			case "mm":
				var hasmonth = true
				var strMonth = dtStr
				if (!isInteger(strMonth)) {
					alert("The month should be in number format")
					inputctrl.focus();
					return false
				}
				//parseInt(<my text value>, 10) THIS ANOTHER FIX TO GET RID 08-09
				month=parseInt(parseFloat(strMonth))	
				break;
			case "dd":	
				var strDay=dtStr
				if (!isInteger(strDay)) {
					alert("The day should be in number format")
					inputctrl.focus();
					return false
				}
				day=parseInt(parseFloat(strDay))
				if ( day<1 || day>31 ) {
					alert("Please enter a valid day")
					inputctrl.focus();
					return false	
				}
				return true
				break;
			case "yyyy"	:
			
				var hasyear = true
				var strYear= dtStr
				
				year=strYear
				
				break;
			default:
				alert("Error try again.");
				inputctrl.focus();
				return false
				break;			
			}
			if (pos1==-1 || pos2==-1){
				alert("The date format should be : "+format)
				inputctrl.focus();
				return false
			}
			if (hasmonth) {
				if (strMonth.length<1 || month<1 || month>12){
					alert("Please enter a valid month")
					inputctrl.focus();
					return false
				}
			}
			if(hasday) {
				if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
					alert("Please enter a valid day")
					inputctrl.focus();
					return false
				}
			}
			if(hasyear) {	
				if (strYear.length != 4 || year==0 ){
					alert("Please enter a valid 4 digit year.")
					inputctrl.focus();
					return false
				}
			}
			
			// By the time it gets here the format has been validated.
			alerttxt = "The date entered is outside the date range."
			if(checkDateRange (inputctrl , minYear , maxYear , format , alerttxt)) {
				return true;
			}	
			else {
				return false;
			}
			
			
			//if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			//	alert("Please enter a valid date")
			//	inputctrl.focus();
			//	return false
			//}
			
			//alert (strDay+"/"+strMonth+"/"+strYr+ "::::"+pos1+":::"+pos2)
			return true
}

function doDateCheck(inputctrl, inputctr2 , specCircumstance , mandatory , alerttxtEmpty , alerttxt) {
/*
BY THE TIME THE DATE GETS TO THIS FUNCTION THE FORMAT HAS BEEN VALIDATED.
*/
	
	if (inputctrl.disabled == true) {
		return true;
	}
	
	if (mandatory) {
		if(inputctrl.value == "" || inputctr2.value == "") {
			if(alerttxtEmpty!=null)
			{
				alert(alerttxtEmpty);
				inputctrl.focus();
			}	
			return false;
		}
	}	
	else{
		if(inputctrl.value != "" || inputctr2.value != "") {
			blncheck = true;
			//alert("continue")
			//continue
		}
		else {
			return true;
		}	
	}
		
	
	strFromDate = inputctrl.value	
	if (specCircumstance == strFromDate.toUpperCase()) {
		var curdate = new Date()
		var year = curdate.getYear()
		var month = curdate.getMonth()
		strFromDate = '01/'+month+'/'+year;	
	}
	else {
		strFromDate = '01/'+inputctrl.value	
	}
	strToDate = inputctr2.value	
	if (specCircumstance == strToDate.toUpperCase()) {
		var curdate = new Date()
		var year = curdate.getYear()
		var month = curdate.getMonth()
		strToDate = '01/'+month+'/'+year;	
	}
	else {
		strToDate = '01/'+inputctr2.value	
	}
	

	if (Date.parse(strFromDate) < Date.parse(strToDate)) {
		//alert("The dates are valid.");
		return true;
	}
	else {
		inputctr2.focus();
		alert(alerttxt);
		return false;			
   }
  // return true;
}

function checkDateRange (inputctrl ,  minDate , maxDate , Dateformat , alerttxt) {

	
	switch(Dateformat) {
			case "mm/yyyy":
				inputDate = '01/'+ inputctrl.value
				tempminDate	  = '01/'+ minDate
				tempmaxDate	  = '01/'+ maxDate  
				if (Date.parse(inputDate)<Date.parse(tempminDate) || Date.parse(inputDate)>Date.parse(tempmaxDate) ) {
					inputctrl.focus();
					alert(alerttxt + ' ' + minDate + ' to ' + maxDate );
					return false;		
				}
				else {
					return true;	
				}
			break;
			case "mm/dd/yyyy":	
				inputDate = inputctrl.value
				minDate	  = minDate
				maxDate	  = maxDate
				if (Date.parse(inputDate)<Date.parse(minDate) || Date.parse(inputDate)>Date.parse(maxDate) ) {
					inputctrl.focus();
					alert(alerttxt + ' ' + minDate + ' to ' + maxDate );
					return false;	
				}
				else {
					return true;		
				}
			break;
			case "yyyy":	
				inputDate = '01/01/'+ inputctrl.value
				tempminDate	  = '01/01/'+ minDate
				tempmaxDate	  = '01/01/'+ maxDate  
				if (Date.parse(inputDate)<Date.parse(tempminDate) || Date.parse(inputDate)>Date.parse(tempmaxDate) ) {
					inputctrl.focus();
					alert(alerttxt + ' ' + minDate + ' to ' + maxDate );
					return false;	
					
				}
				else {
					return true;		
				}
			
			break;
			default:
				//alert("Error try again.");
				//inputctrl.focus();
				return false
				break;			
			}
	
	return true;
}

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++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function validateFields(form,formString, formCustomMsg) {
			
			
            var bValid = true;
            var firstfieldtoFocus = "";
            var firstfieldtype = "";
            var checkboxstate = false;
            var checkboxlen   = 0;
            var checkboxIncr  = 0;
            var hasdata = false;
            var breakoutofloop = false;
            var focusField = null;
            var i = 0;
            var elem = form.elements; 
			var flength = elem.length; 
            //THE NAMES ARE PASSED BY DELIMITED TO LOOP THRU THE FIELDS.
            var form_names = formString.split(",");
            // THE DELIMITER IS ','  THIS ALLOWS US TO USE COMMAS IN THE MESSEGES, MAKE SURE YOU USE THAT IN BETWEEN YOUR CUSTOM MESSEGES.
            if (formCustomMsg == "") {
				var custom_msg = false;	
            } else {
				var custom_msg = true;
				var form_custom_msg = formCustomMsg.split("','");
				//WE ARE GOING TO CHECK THE LENGTHS TO ENSURE THAT WE DON'T GET AN ERROR - THIS IS FOR DEVELOPER DEBUGGING.
				if (form_names.length != form_custom_msg.length	) {
					alert("you made a mistake, please ensure that the messeges match the fields you are trying to test.")				
					return true;
				}							
			}
			
			// START GOING THRU THE FORM ELEMENTS.
            for (i=0; i < form_names.length; i++) 
			{
				fnamecheck = form_names[i]
				fnamecheck = fnamecheck+""
					for (x=0; x < flength; x++) 
					{
						var t = elem[x].type;
						var fname = elem[x].name;
						fname = fname+""
						if (t != "hidden"){
							if (fname == fnamecheck) {
								//alert("Type[" + t + "]" + " -- " + fname); 	
								switch(t) 
									{
									case "text":
										if (elem[x].value != "" && hasdata == false) {
											hasdata = true;
										}
										else if (elem[x].value == "" && hasdata == true) {
											//focus this
											if (custom_msg){
												alert(form_custom_msg[i]);
											} else {
												alert("Please make sure you answer all the questions before continuing.");
											}
											elem[x].focus();
											breakoutofloop = true;
											break;
											
										}
										else {if(firstfieldtype==""){firstfieldtype=fname;}}
									break;
									case "radio":
										//FIRST TIME AROUND
										if (checkboxlen == 0) {checkboxlen=form[fname].length;checkboxIncr=0;}
										
											//alert(form[fname].length + "--" + elem[x].checked  + "--" + elem[x].length + fname);
											if (!checkboxstate) {
												if (elem[x].checked && hasdata == false) {
													hasdata = true;
													checkboxstate = true;
												}
												else if (!elem[x].checked && hasdata == false) { 
													checkboxstate = false;
												}
												else if (elem[x].checked && hasdata == true) { 
													checkboxstate = true;
												}
												else {if(firstfieldtype==""){firstfieldtype=fname;}}
												
											}	
											checkboxIncr++
											//alert(fname + " ====== "  + checkboxIncr +"==" +  checkboxlen + "&&" + checkboxstate + " && " + hasdata)
											if (checkboxIncr == checkboxlen && !checkboxstate && hasdata == true) {
												//LET'S FOCUS THIS CHECKBOX
												if (custom_msg){
													alert(form_custom_msg[i]);
												} else {
													alert("Please make sure you answer all the questions before continuing.");
												}
												elem[x].focus();
												breakoutofloop = true;
												break;	
											}
											//CLEAN UP THE COUNTER
											if (checkboxIncr == checkboxlen) {
												checkboxIncr	= 0;
												checkboxstate 	= false;
											}
											
									break;
									case "select-one":
										if (elem[x].selectedIndex != 0 && hasdata == false) {
											hasdata = true;
										}
										else if (elem[x].selectedIndex == 0 && hasdata == true) { 
											//focus this
											if (custom_msg){
												alert(form_custom_msg[i]);
											} else {
												alert("Please make sure you answer all the questions before continuing.");
											}
											elem[x].focus();
											breakoutofloop = true;
											break;
											
										}
										else {if(firstfieldtype==""){firstfieldtype=fname;}}
									break;
									case "textarea":
										if (elem[x].value != "" && hasdata == false) {
											hasdata = true;
										}
										else if (elem[x].value == "" && hasdata == true) {
											//focus this
											if (custom_msg){
												alert(form_custom_msg[i]);
											} else {
												alert("Please make sure you answer all the questions before continuing.");
											}
											elem[x].focus();
											breakoutofloop = true;
											break;
											
										}
										else {if(firstfieldtype==""){firstfieldtype=fname;}}	
										
										
									break;
									default:
										//alert("Error catch.");
										return true;
									break;			
									}
							}
						}	
						if(breakoutofloop){break;}
					}
					if(breakoutofloop){break;}
				}
			//FOCUS THE FIRST FIELD IN THE SECTION.	
				if (!breakoutofloop && hasdata && firstfieldtype == form_names[0]) {
					//focus the first element of the array.
					if (custom_msg){
						alert(form_custom_msg[0]);
					} else {
						alert("Please make sure you answer all the questions before continuing.");
					}
					form[firstfieldtype].focus();
					return false;
				}
				else if (breakoutofloop) {
					return false;
				}
				else {
					return true;
				}
			return true;
}   


function disableIt(obj)
{
	obj.disabled = !(obj.disabled);
	obj.className = "Disabled";
	//var z = (obj.disabled) ? 'disabled' : 'enabled';
	//alert(obj.type + ' now ' + z);
}
function extracheck(obj)
{
	return !obj.disabled;
}   
function CheckForSpaces(strTextIn)
	{	
		var strWorkText;
		var intPointer;
			
		strWorkText = strTextIn;
		intPointer = strWorkText.indexOf(" ");
			
		for (var loopIndex = 0; loopIndex < strTextIn.length; loopIndex++)
		{
			strWorkText = strWorkText.substring(0, intPointer) + strWorkText.substring(intPointer + 1, strWorkText.length);
			intPointer = strWorkText.indexOf(" ", intPointer);
				
			if(intPointer == -1)
			{break;}
		}
		return strWorkText;
} 