// JavaScript Document

function showHide(obj){
	if(obj.value=='Hardwood'){
		document.getElementById('purchasedQ').style.display='block';
	}else{
		document.getElementById('purchasedQ').style.display='none';
	}//end of if-else	
}//end of function showHide() 


function searchvalidate() {
	if (document.banner.query.value == "") {
		alert('Please enter a valid keyword');
		return false;
	} 
}

function validateStep1() {
	if (document.step1.Service.value == "") {
		alert('Please select a service');
		return false;
	} 
	else if (document.step1.budget.value == ""){
		alert('Please select a budget');
	return false;
	}
	else if (document.step1.ProjToBegin.value == ""){
		alert('Please select a timeline');
	return false;
	}
}

function validateStep2() {
	if (document.step2.FN.value == "") {
		document.step2.FN.focus();
		alert('Please provide your First Name');
		return false;
	} else if (document.step2.LN.value == "") {
		document.step2.LN.focus();
		alert('Please provide your Last Name.');
		return false;
	} else if (document.step2.S1.value == "" || document.step2.S1.value == "") {
		document.step2.S1.focus();
		alert('Please provide your Address.');
		return false;
	} else if (document.step2.CT.value == "") {
		document.step2.CT.focus();
		alert('Please provide your City.');
		return false;
	} else if (document.step2.SP.value == "") {
		document.step2.SP.focus();
		alert('Please provide your State.');
		return false;
	} else if (!validateZIP(document.step2.PC.value)) {
		document.step2.PC.focus();
		alert('Please provide your Zip Code.');
		return false;
	} else if (document.step2.EM.value == "") {
		document.step2.EM.focus();
		alert('Please provide your Email Address.');
		return false;
	} else if (!validateEmail(document.step2.EM.value)) {
		document.step2.EM.focus();
		alert('Please provide a valid Email Address.');
		return false;
	} else if (document.step2.HP1.value == "" || document.step2.HP1.value.length < 3) {
		document.step2.HP1.focus();
		alert('Please provide your Phone Number.');
		return false;
	} else if(document.step2.HP2.value == "" || document.step2.HP2.value.length < 3) {
		document.step2.HP2.focus();
		alert('Please provide your Phone Number.');
		return false;
	} else if(document.step2.HP3.value == "" || document.step2.HP3.value.length < 4) {
		document.step2.HP3.focus();
		alert('Please provide your Phone Number.');
		return false;
	}
}
function validateStep3() {
//print document.step3.service[0].value;
	
if (document.step3.service.value == "") {
	alert('Please select a home improvement project');
	return false;
 }
}
function validateZIP(field) {
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if (field.length!=5 && field.length!=10) 
		return false;

	for (var i=0; i < field.length; i++) {
		temp = "" + field.substring(i, i+1);
		if (temp == "-") 
			hyphencount++;
		if (valid.indexOf(temp) == "-1")
			return false;
		if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-"))
			return false;
	}
	return true;
}

function validateEmail(address) {
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   if(reg.test(address) == false) {
		  return false;
	   }
	   return true;
	}

function popup(param) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(param, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=1,resizable=1,width=600,height=600');");
}

function HP_AREAonFocus()
{	
	var nKeyCode = ''; // Holds the Ascii values for the key pressed
	_dom = 0;		
 	_dom=document.all?3:(document.getElementById?1:(document.layers?2:0));
	document.step2.HP1.onkeypress = KeyPress;
	function KeyPress(e)
	{
		var oEvent = (window.event) ? window.event : e;
			nKeyCode =  oEvent.keyCode ? oEvent.keyCode :
						oEvent.which ? oEvent.which : 
						void 0;
			if(_dom==3){   // for IE
					if ((event.keyCode < 48 || event.keyCode > 57) ) return false;
					if ((event.keyCode == 45) && document.step2.HP1.value.length > 0) return false;
			}else //NN4 and Mozilla
			{
					if ((nKeyCode < 48 || nKeyCode > 57)  //Ascii for Numbers 0 to 9 is 48 to 57 
						&&  (nKeyCode < 16 || nKeyCode > 18) //Ascii for SHIFT = 16, CTRL = 17, ALT = 18
						&&  nKeyCode!=92  //Ascii for MS = 92
						&&  nKeyCode!=93  //Ascii for View  = 93
						&&  nKeyCode!=8   //Ascii for Back = 8
						&&  nKeyCode!=9   //Ascii for Tab = 9
						) return false;
					if ((nKeyCode == 45) && document.step2.HP1.value.length > 0) return false;
			}
	}
}

