//main login

function clearFields(){
document.getElementById('mile_years').value='';
document.getElementById('avg_value').value='';
 }

function removeComboItems(selectbox){	

 	 var i;

	 for(i=selectbox.options.length-1;i>0;i--){

		 if(selectbox.id!='year')

			 selectbox.remove(i);

	 }

	return true;

 }

function removeAllOptions(theForm)

{

var selectboxYear=theForm.year;

removeComboItems(selectboxYear);

var selectboxcarmake=theForm.carmake;

removeComboItems(selectboxcarmake);

var selectboxcarlinename=theForm.car_line_name;

removeComboItems( selectboxcarlinename);

}

function validateFlyingPage(theForm){
	arr = new Array();

	arr["theControl"]="miles";
	arr["theMessage"]="Miles";

	arr["theempty"]="Y";
	arr["theNumeric"]="Y";

	arr["thebadstuff"]="8";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,1);
}

function validateCarPage(theForm){
	arr = new Array();

	arr["theControl"]="mpg,miles_year";
	arr["theMessage"]="Make/Model/Year,Mileage/yr";

	arr["theempty"]="Y,Y";
	arr["theNumeric"]=",Y";

	arr["thebadstuff"]="8,8";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,2);
}

function validateCarPage_deprecate(theForm){
//	alert(theForm);
	//return;
//alert(frm.tons_co2.value);
//return;
//var theForm=document.frm_Calculator;
//alert(theFRM.tons_co2.value);
//var theFRM=document.forms["frm_Calculator"];
//var theFRM=document.getElementById("frm_Calculator").name;
//alert(theForm.tons_co2.value);
	arr = new Array();

//	arr["theControl"]="year,carmake,car_line_name,miles_year,tons_co2";
	
	if(theForm.year.selectedIndex==0)

	{

		alert("Please select the Year");

		return false;

	}

	if(theForm.carmake.selectedIndex==0)

	{

		alert("Please select the carmake");

		return false;

	}

	if(theForm.car_line_name.selectedIndex==0)

	{

		alert("Please select the Car Line Name");

		return false;

	}

	arr["theMessage"]="Year,CarManufacturer,CarLineName,Mile/Year,Tons CO2";

	arr["theempty"]="Y,Y,Y,Y,Y";

	arr["thebadstuff"]="6,6,6,8,8";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,5);



}

function validateAdminPage(theForm){



	arr = new Array();

	arr["theControl"]="year,carmake,car_line_name,mpg";

	arr["theMessage"]="Year,CarManufacturer,CarLineName,MPG";

	arr["theempty"]="Y,Y,Y,Y,,,";

	arr["thebadstuff"]="6,8,8,8";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,4);



}

function validateDrivingCalculator(theForm){



	arr = new Array();

	arr["theControl"]="year,carmake,carmodel,fueltype,miles_year,offset_years,tons_carbon";

	arr["theMessage"]="VehicleModelYear,CarMake,CarModel,FuelType,MilesYear,OffsetYear,TonsCarbon";

	arr["theempty"]="Y,Y,Y,Y,Y,Y,Y";

	arr["thebadstuff"]="6,6,6,6,6,6,8";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,7);



}

function validateHome(theForm){



	arr = new Array();

	arr["theControl"]="avg_electric_bill_amount,recycle_newspaper,recycle_glass,recycle_plastic,recycle_alumunium";

	arr["theMessage"]="Average Electric Amount/KWH,Recycle NewsPaper,Recycle Glass,Recycle Plastic,Recycle Alumunium";

	arr["theempty"]="Y,Y,Y,Y,Y,Y,Y";

	arr["thebadstuff"]="6,6,6,6,6,6,6";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,7);



}

function validateHomeCheckBoxGas(theForm){

	

	if(theForm.chkgas.checked==1)

	{

	arr = new Array();

	arr["theControl"]="avg_gas_bill_amount";

	arr["theMessage"]="Please enter a number, no other characters";

	arr["theempty"]="Y,,,,,,";

	arr["thebadstuff"]="6";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,1);

	}

	else

	return false;

}

function validateHomeCheckBoxHeatingOil(theForm){

	

	if(theForm.chkheatingoil.checked==1)

	{

	arr = new Array();

	arr["theControl"]="avg_heatingoil_bill_amount";

	arr["theMessage"]="Please enter a number, no other characters";

	arr["theempty"]="Y,,,,,,";

	arr["thebadstuff"]="6";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,1);

	}

	else

	return false;

}



function ValidateTextBoxValue(theForm){

	arr = new Array();

	arr["theControl"]="avg_electricity_value,avg_gas_value,avg_heatingoil_value,no_of_people,";

	arr["theMessage"]="Average Value of Electricity,Average Value of Gas,Average Value of FuelOil,Number of People";

	arr["theempty"]="Y,Y,Y,Y,,,";

	arr["thebadstuff"]="8,8,8,8";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,4);

}



function ShowHideAddButton(){

document.getElementById('tdaddbuttonid').style.display='';

} 

function ShowHideGas(chk){



if(chk.checked==true){

document.getElementById('trgas1').style.display='';

document.getElementById('trgas2').style.display='';

}else{

document.getElementById('trgas1').style.display='none';

document.getElementById('trgas2').style.display='none';

}

} 

function ShowHideFuel(chk){



if(chk.checked==true){

document.getElementById('trfuel1').style.display='';

document.getElementById('trfuel2').style.display='';

}else{

document.getElementById('trfuel1').style.display='none';

document.getElementById('trfuel2').style.display='none';

}

} 



function checkLogin(theForm)

{

	arr = new Array();

	arr["theControl"]="txtLoginUser,txtLoginPass";

	arr["theMessage"]="Username,Password";

	arr["theempty"]="Y,Y";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,2);

}





// register nurse

function checkRegister(theForm)

{

	arr = new Array();

	arr["theControl"]="txtRegUserName,txtRegPass,txtRegRePass,txtRegFirstName,txtRegSecondName,txtRegEmail";

	arr["theMessage"]="Username,Password,Retype Password,First Name,Second Name, Email";

	arr["theempty"]="Y,Y,Y,Y,Y,Y";

	arr["theEmail"]=",,,,,Y";

	arr["theConfirmPassword"]=",,Y,,,";

	arr["thebadstuff"]="6,10,6,6,6,";

	

	return validateForm(theForm,arr,6);

}



//Change Password

function checkPassword(theForm)

{

	arr = new Array();

	arr["theControl"]="txtRegOldPass,txtRegPass,txtRegRePass";

	arr["theMessage"]="Old Password,New Password,Retype Password";

	arr["theempty"]="Y,Y,Y";

	//arr["theEmail"]="Y,"; CAN BE USED IN CASE USERNAME  IS EMAIL ID

	return validateForm(theForm,arr,2);

}



/**

 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

 */

// Declaring valid date character, minimum year and maximum year

var dtCh= "/";

var minYear=1900;

var maxYear=2100;



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 isDate(dtStr){

	var daysInMonth = DaysArray(12)

	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)

	}

	month=parseInt(strMonth)

	day=parseInt(strDay)

	year=parseInt(strYr)

	if (pos1==-1 || pos2==-1){

		alert("The date format should be : mm/dd/yyyy")

		return false

	}

	if (strMonth.length<1 || month<1 || month>12){

		alert("Please enter a valid month")

		return false

	}

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){

		alert("Invalid day!")

		return false

	}

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){

		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)

		return false

	}

	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){

		alert("Please enter a valid date")

		return false

	}

return true

}

/*

function ValidateForm(){

	var dt=document.frmSample.txtDate

	if (isDate(dt.value)==false){

		dt.focus()

		return false

	}

    return true

 }

*/

function check_auction_form(){

	if(document.getElementById("textpercantage").value==''){

		alert("Please Enter Pecantage!");

		document.getElementById("textpercantage").focus();

		return false;

	}

	if(document.getElementById("checkauctionterms").checked==false){

		alert("You Must Accept Terms and Conditions to Proceed!");

		document.getElementById("checkauctionterms").focus();

		return false;

	}

}