function ShowMenuItem(oName){
	try {
		var oDiv = MM_findObj('TopHomeMenu');
		if(oDiv){
			oPos = getpos('TopHomeLink');
			oDiv.className = "TopMenuItemOpen";
			oDiv.style.top = oPos.y + 20;
			oDiv.style.left = oPos.x + 20;
		}
	} catch(e){alert(e.description);} // getting oDiv failed
}
function show(id) {
	var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {
			document.getElementById('smenu'+i).style.display='none';
		}
	}
	if (d) {d.style.display='block';}
}


function submitFeedBack(f){
	f.submitButton.value = "validating ...";
	f.submitButton.disabled = true;
	var r = "";
	//r+= validateContactWho(f.contactWho);
	r+= validateName(f.contactName);
	r+=validateContactBy(f.contactBy);
	r+=validateComments(f.comments);
	if(r==""){
		f.submitButton.value = "sending ...";
		var sBody = "";
		sBody += "\nName: " + f.contactName.value;
		sBody += "\nReply By: " + f.contactBy.value;
		sBody += "\nComments: " + f.comments.value;
		var e1 = "webmaster"
		var e2 = "lowen.com"
		var e3 = "comments"
		var e4 = "lowensignvehiclewraps.com"
		SendAjaxMail(e1 + "@" + e2,((isEmail(f.contactBy.value))?f.contactBy.value:e3+"@"+e4,"Comments from Lowen Sign Vehicle Wraps Site",sBody,CommentSent));
	} else {
		alert("The form could not be submitted, please correct the following items and resend.\n\n" + r);
		f.submitButton.value = "send";
		f.submitButton.disabled = false;
	}
	return(false);
}

var submitButtonPreHTML;
function ValidateOrderForm(){
	var o = document.orderform;
	var r = "";
		r+=validateName(o.fullName);
		r+=validatePhone(o.dayPhone);
		r+=validateEmail(o.email);
		r+=validateZip(o.zip);
		r+=validateYear(o.vehicleYear);
		r+=validateType(o.vehicleType);
		r+=validateMake(o.vehicleMake);

		r+=validateModel(o.vehicleModel);
		r+=validateCoverage(o.coverage,o.priceRange);
		r+=validateHelpNeeded(o.helpNeeded);

		var submitButton = document.getElementById("FormSubmitButton");
		if(submitButton){
			submitButtonPreHTML = submitButton.innerHTML
			submitButton.innerHTML = "Validating Form...";
		}

		if(r!=""){
			alert("The form could not be submitted, please correct the following issues, and then resubmit"+r);
			submitButton.innerHTML = submitButtonPreHTML;
			return(false);
		} else {
			submitButton.innerHTML = "Sending Request...";
			var sBody = "";
			sBody += "\nName: " + o.fullName.value;
			sBody += "\nPhone: " + o.dayPhone.value;
			sBody += "\nEmail: " + o.email.value;
			sBody += "\nzip: " + o.zip.value;
			var vYear = o.vehicleYear[o.vehicleYear.selectedIndex].text;
			sBody += "\nVehicle Year: " + vYear
			var vMake = o.vehicleMake[o.vehicleMake.selectedIndex].text
			sBody += "\nVehicle Make: " + vMake;
			var vModel = o.vehicleModel[o.vehicleModel.selectedIndex].text
			sBody += "\nVehicle Model: " + vModel;
			sBody += "\nCoverage/Price Range: " + o.coverage.value + " / " + o.priceRange.value;
			sBody += "\nDesign Help Needed: " + (o.helpNeeded[0].checked==true);
			sBody += "\nComments:\n" + o.comments.value;

			var ajax = new Ajax()
			ajax.method = "POST"
			ajax.url = "./assets/ajax/_method.sendQuoteRequest.asp";
			ajax.add("body", sBody);
			ajax.add("returnto",o.email.value);
			ajax.onSuccess = function(x,t){
				EstReqestSent();
			}
			// ajax.debug = true;
			ajax.send()
			return(false);
		}
}

function SendNewMakeModel(){
	var o = document.orderform;
	try {
		var vYear = o.vehicleYear[o.vehicleYear.selectedIndex];
		var vMake = o.vehicleMake[o.vehicleMake.selectedIndex];
		var vModel = o.vehicleModel[o.vehicleModel.selectedIndex];
		var cYearMakeModel = vYear.text + "|" + vMake.text +"|"+ vModel.text;

		if(__ECHO__SUBMITTED_MAKEMODEL__FOR!=cYearMakeModel){
			__ECHO__SUBMITTED_MAKEMODEL__FOR = cYearMakeModel;
			var e1 = "webmaster"; //"patk"
			var e2 = "lowen.com"
			var e3 = "lowensignvehiclewraps"
			if((o.vehicleMake.value=="0" || o.vehicleModel.value=="0") && ((vYear.value!=".none" && vYear.value!=".suggest") && (vMake.value!=".none" && vMake.value!=".suggest") && (vModel.value!=".none" && vModel.value!=".suggest"))){
				SendAjaxMail(e1+"@"+e2,e3+"@"+e2,"Requested new Make/Model","\nYear: " + vYear.text + "\nMake: " + vMake.text + "\nModel: " + vModel.text,false)
			}
		}
	} catch(e){}
}

function EstReqestSent(x,t){
	var pageContent = document.getElementById("ContentSection");
	pageContent.innerHTML = "<br /><br /><br /><div align=\"center\"><img src=\"/assets/images/thankyou.jpg\" border=\"0\" /><br /><br /><br />Your request has been sent. Thank you for your interest.</div>";
	document.location += "#top";
}

function CommentSent(x,t){
	var pageContent = document.getElementById("ContentSection");
	pageContent.innerHTML = "<p align=\"center\">Your comments has been sent. Thank you for your interest.</p>";
}

function validateName(o){
	try {markIt(o.name,(o.value==""))} catch(e){trace("valudateName");showProperties(e);}
	return((o.value=="")?"\n\t• Please enter your name":"");
};
function validatePhone(o){
	var args = new Object();
		args.allowAreaCode = "force";
	var v = validPhone(o.value,args);
	o.value = v.value;
	try {markIt(o.name,!v.valid)} catch(e){trace("validatePhone");showProperties(e);}
	if(o.value==""){return("\n\t• Please enter your daytime phone number");}
	if(v.valid==false){return("\n\t• The entered phone number is invalid" + ((v.error!="")?": " + v.error:""));};
	return("");
}
function validateEmail(o){
	var v = isEmail(o.value);
	try {markIt(o.name,!v)} catch(e){trace("validateEmail");showProperties(e);}
	if(o.value==""){return("\n\t• Please enter your email address");}
	if(v==false){return("\n\t• The entered email address is invalid");};
	return("");
}
function validateZip(o){
	var v = isZip(o.value);
	try {
		markIt(o.name,!v||o.value=="")
	} catch(e){trace("validateZip");showProperties(e);}
	if(o.value==""){return("\n\t• Please enter your zip code");}
	if(v==false){return("\n\t• The entered zip code is invalid");};
	return("");
}
function validateYear(o){
	try {markIt(o.name,(o.value==""))} catch(e){trace("validateYEar");showProperties(e);}
	return((o.value=="")?"\n\t• Please enter your vehicle year":"");
}
function validateType(o){
	try {markIt(o.name,(o.value==""))} catch(e){trace("validateType");showProperties(e);}
	return((o.value=="")?"\n\t• Please enter your vehicle type":"");
}

var __ECHO__SUBMITTED_MAKEMODEL__FOR = "";
function validateMake(o){
	SendNewMakeModel();
	try {markIt(o.name,(o.value==""))} catch(e){trace("validateMake");showProperties(e);}
	return((o.value=="")?"\n\t• Please enter your vehicle make":"");
}
function validateModel(o){
	SendNewMakeModel();
	try {markIt(o.name,(o.value==""))} catch(e){trace("validateModel");showProperties(e);}
	return((o.value=="")?"\n\t• Please enter your vehicle model":"");
}
function validateCoverage(o,p){
	p.disabled = o.value!="budget";
	p.style.borderColor = (o.value!="budget")?"#cccccc":"#000000";

	var v = (o.value!="" && o.value!="budget");
	if(o.value=="budget" && p.value!=""){v = true;}
	try {
		markIt(o.name,!v);
		markIt(p.name,(o.value=="budget" && p.value==""));
		} catch(e){trace("validateCoverage");showProperties(e);}
	if(o.value!=""&&o.value!="budget"){p.value = "";}
	if(o.value=="" && p.value==""){
		return("\n\t• Please enter your desired coverage or price range");
	} else if(o.value=="budget" && p.value==""){
		return("\n\t• Please enter your desired price range");
	} else {
		return("");
	}
}
function validateHelpNeeded(o){
	if(!o[0].checked&&!o[1].checked){
		return("\n\t• Please indicate if you will need design help");
	}
	return("");
}

/* validates either phone or email based on what the user has entered
 */ function validateContactBy(o){
 			/* first check to see if it's empty, if so, return an error
 			 */ if(o.value==""){
 			 			markIt(o.name,true);
 			 			return("\n\t• Please enter an Email address, or Phone number");
 			 		}
 			/* check to see if it appears to be an email address
 			 * this will be done by looking for 2 basic elements which is must have
 			 * @ and .
 			 */ if(o.value.toLowerCase().indexOf("@")!=-1){
 			 			/* we're looking at an email address... validate it as such */
 			 			return(validateEmail(o))
 			 		}
 			 /* if it doesn't resolve as an email address, check to see if it fits as a phone number
 			 */

 			 if(numOnly(o.value,"-. ()")==o.value){
 			 	return(validatePhone(o));
 			 }

 			return("\n\t• The entered Phone number or Email address is unrecognizable");

		/* first check to see if it qualifies as a phone number */
		var args = new Object();
			args.allowAreaCode = "force";
		var v = validPhone(o.value,args);
		if(v.valid){
			o.value = v.value;
			return("");
		}
}

function validateContactWho(o){
	if(o[0].checked==false && o[1].checked == false){
		return("\n\t• Indicate to whom the email should be sent");
	}
	return("");
}

function validateComments(o){
	markIt(o.name, o.value=="");
	return((o.value=="")?"\n\t• No comment has been entered":"");
}

function ShowImage(imgName){
	imgWindow('/assets/images/gallery/' + imgName,'Lowen Sign Car Wrap Gallery:: ' + imgName,'500','500');
}

	function LoadTicker(){
		var TICKER = document.getElementById("TICKER");
		if(TICKER){
			TICKER.innerHTML = loadFlash("/assets/realtorTicker.swf","8","60","500",true);
		}
	}

function InjectNavBar(){
	var oOutput = document.getElementById("navCell");
	if(oOutput){
		var oDiv = document.getElementById("NavHolder");
		if(oDiv){
			//alert(oDiv.innerHTML);
			oOutput.appendChild(oDiv);
			oDiv.className = undefined;
		} else {
			oOutput.innerHTML = "navigation could not be loaded, please refresh your screen";
		}
	} else {
		trace("navigation could not be loaded, please refresh your screen");
	}
}

function SetVehicalMakeList(oIn,oOut,oModel){
	while(oModel.length>0) {oModel.options[oModel.length-1] = null;}
	while(oOut.length>0) {oOut.options[oOut.length-1] = null;}

	if(oOut.length==0){
		oOut.length++;
		oOut.options[0].text = "Retrieving list ...";
		oOut.options[0].value = ".none";
	}

	var ajax = new Ajax();
	ajax.output = oOut;
	ajax.input = oIn;
	ajax.onSuccess = SetVehicalMakeList_Success;
	// ajax.debug = true;
	ajax.send("/assets/ajax/_method.getMakeList.asp?year=" + oIn.value);
}

function SetVehicalMakeList_Success(x,t){
	while(this.output.length>0) {
		this.output.options[this.output.length-1] = null;
	}


	try {
	this.output.length=1;
	this.output.options[0].text = "Select a make...";
	this.output.options[0].value = ".none";
	} catch(e){Catch("Error Setting Select a Make",e);}

	this.output.length++;
	this.output.options[1].text = "Not found, I would like to suggest...";
	this.output.options[1].value = ".suggest";

	this.output.length++;

	if(x.childNodes[0].hasChildNodes()){
		var VehicleList = x.childNodes[0].childNodes;
		var i = 0
		for(i;i<VehicleList.length;i++){
			var nId = VehicleList[i].firstChild.firstChild.nodeValue
			var cMake = VehicleList[i].childNodes[1].firstChild.nodeValue

			this.output.length ++;
			var sl = this.output.length - 1;
			this.output.options[sl].text = cMake;
			this.output.options[sl].value = nId;
		}
	}
}

function SetVehicalModelList(oIn,oOut,nYear){
	// clear the makes select list
	while(oOut.length>0) {oOut.options[oOut.length-1] = null;}
	if(oIn.value==".suggest"){
		var newMake = prompt("Please enter new make");
		if(newMake!=null){
			oIn.options.length ++;
			oIn.selectedIndex = oIn.options.length-1;
			oIn[oIn.selectedIndex].value = 0;
			oIn[oIn.selectedIndex].text = newMake;
			SendNewMakeModel();
			oOut.focus();
		} else {
			oIn.focus();
			return;
		}
	}
	if(oOut.length==0){
		oOut.length++;
		oOut.options[0].text = "Retrieving list ...";
		oOut.options[0].value = ".none";
	}

	var ajax = new Ajax();
	ajax.output = oOut;
	ajax.input = oIn;
	ajax.onSuccess = SetVehicalModelList_Success;
	var url = "/assets/ajax/_method.getModelList.asp?year=" + nYear + "&make=" + oIn.value;
	// ajax.debug = true;
	ajax.send(url);
}

function SetVehicalModelList_Success(x,t){
	while(this.output.length>0) {
		this.output.options[this.output.length-1] = null;
	}

		this.output.length=1;
		this.output.options[0].text = "Select a model...";
		this.output.options[0].value = ".none";

		this.output.length++;
		this.output.options[1].text = "Not found, I would like to suggest...";
		this.output.options[1].value = ".suggest";

	if(x.childNodes[0].hasChildNodes()){
		var VehicleList = x.childNodes[0].childNodes
		var i = 0


		this.output.length++;

		for(i;i<VehicleList.length;i++){
			var nId = VehicleList[i].firstChild.firstChild.nodeValue
			var cModel = VehicleList[i].childNodes[1].firstChild.nodeValue

			this.output.length ++;
			var sl = this.output.length - 1;
			this.output.options[sl].text = cModel;
			this.output.options[sl].value = nId;
		}
	}
}

function SuggestModel(o){
		var newModel = prompt("Please enter new model");
		if(newModel!=null){
			o.options.length ++;
			o.selectedIndex = o.options.length-1;
			o[o.selectedIndex].value = 0;
			o[o.selectedIndex].text = newModel;
			SendNewMakeModel();
		} else {
			o.focus();
		}
	}

function ResetYearMakeModelToHaveNothingSelectedInOrderToUndoFoxProMischief(){
	var f  = document.orderform;
	f.vehicleType.selectedIndex = -1;
	f.vehicleYear.selectedIndex = -1;
	f.vehicleMake.selectedIndex = -1;
	f.vehicleModel.selectedIndex = -1;
}

