// myjsfile.js
// JavaScript Document

function setfocus() {
	if (document.location.href=="http://www.silvercote.com/iqaccountinfo.php")
		document.account.job.focus();
	if (document.location.href=="http://www.silvercote.com/iqbuildingstyle.php")
		document.bstyle.conti.focus();
	if (document.location.href=="http://www.silvercote.com/iqinsulationoptions.php")
		document.myform.BuildingDesc.focus();
	if (document.location.href=="http://www.silvercote.com/IQDimensionsDS.php")
		document.forms[0].Width.focus();
	if (document.location.href=="http://www.silvercote.com/IQDimensionsSS.php")
		document.forms[0].Width.focus();
	if (document.location.href=="http://www.silvercote.com/IQDimensionsDSOffset.php")
		document.forms[0].LeftWidth.focus();
	if (document.location.href=="http://www.silvercote.com/IQSidewallDeduction.php")
		document.sidewall.OptionalName.focus();
	if (document.location.href=="http://www.silvercote.com/IQEndWallDeduction.php")
		document.endwall.EndWall1Name.focus();
	if (document.location.href=="http://www.silvercote.com/IQNewBuilding.php")
		document.form2.conti.focus();
	if (document.location.href=="http://www.silvercote.com/IQTax.php")
		document.taxes.PatchTape.focus();

}

function linkEffect(wh, el, cl, td) {

	window.status = wh;
	el.style.color = cl;
	el.style.textDecoration = td;

}

function setPageTitle(toWhat) {
	document.title = toWhat;
}

function setWindowStatus(toWhat) {
	window.status = toWhat;
}
/*
function confirmation(q){
	if(confirm(q))
		return true; // window.location = "xxxx.php";
	else
		 return false;
}
*/

function confirmation(q){
	if(document.forms[0].submitbtn != null)
		btnChange(document.forms[0].submitbtn, 'Sending...', true);
	
	if(confirm(q))
		return true; // window.location = "xxxx.php";
	else{
		 if(document.forms[0].submitbtn != null)
		  	 btnChange(document.forms[0].submitbtn, 'Submit', false)
		 return false;
		}
}

function setFocus(it){
	it.focus();
}


/////////////////////// auto tab /////////////////////////////////

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(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;
}

///////////////////////////////////////////////////////////////////



/////////////////////// capitalize first letter ///////////////////

function initUpper (InString)  {
	if(InString.length==0) return(InString)
	InString=InString.toLowerCase();
	Space=false;
	OutString="";
	OutString+=InString.substring(0, 1).toUpperCase();
	for(Count=1; Count<InString.length; Count++)  {
		if(InString.substring(Count, Count+1)==" ")  {
			Space=true;
			OutString+=InString.substring(Count, Count+1)
			continue;
		}
		if (Space)  {
			OutString+=InString.substring(Count, Count+1).toUpperCase();
			Space=false;
			continue;
		}
		OutString+=InString.substring(Count, Count+1);
	}
	return (OutString);
}


////////////////////////////////////////////////////////////////////


function btnChange( btnname, val, enab )  { 
	btnname.value = val;
	btnname.disabled = enab;
	return true;
} 

function CheckTax() {
	if (document.checktax.valid_tax.value == 'update zipcode') {
		alert("Please update your shipping zipcode");
    	return false;
	}
	else if (document.checktax.shipping_cost.value == '0.00') {
		alert("The zipcode you typed in is invalid. Please try it again. Or call 1-800-231-6200 for help");
    	return false;
	}	
	else {
		location.href='scart_checkout.php';
		return true;
	}
}

function checkwebid() {
	if (document.forms[0].uwebid.value=='') {
		alert("Your authorization to use IQWeb Quotation System is in process. Usually it takes 24 hours. For immediate access please call 1 800 231 6200 for express set up");
		return false;
	}
	return true;
}

function ClearQuote() {
	document.location.href = "IQnewquoteaction.php";
}		

function RedoQuote() {
	document.location.href = "IQBuildingStyle.php";
}

function shipformtest(quote)	{
	if (document.order.shipping_name.value==""){
		alert("Ship-To Name can't be empty");
		return false;
	}
	if (document.order.shipping_address.value==""){
		alert("Ship-To Address can't be empty");
		return false;
	}
	if (document.order.shipping_city.value==""){
		alert("Ship-To City can't be empty");
		return false;
	}
	if (document.order.shipping_state.value==""){
		alert("Ship-To State can't be empty");
		return false;
	}
	if (document.order.shipping_zip.value==""){
		alert("Ship-To Zip can't be empty");
		return false;
	}
	if (document.order.shipping_phone.value==""){
		alert("Ship-To Phone can't be empty");
		return false;
	}
	if (quote==1) {
		if (document.order.shipping_date.value==""){
			alert("Delivery Date can't be empty");
			return false;
		}
	}
	return true;
}


	