// JavaScript Document
// Scripts for Contact Form
// Authored for UCoat It America, LLC - SPB 05/24/07

//---------------------------------------------------------------------------------------BEGIN FUNCTION
function determineArrival(){
	var departure=location.search.substring(1);
	if(departure!='faq'&&departure!='dlr'&&departure!='req'){document.write('<p class="maintext12">If you are writing in regards to a technical or application question, please check our Frequently Asked Questions page first. Many answers to the most common questions our customers ask are posted there.</p>');}
	if(departure=='dlr'){document.write('<p class="maintext12">UCoat It offers a comprehensive dealer stocking program with great opportunities still available in many major markets. Benefits include:<ul><li>Competitive margin on all products</li><li>Designated customer referral zone</li><li>Co-operative advertising program...and more!</li></ul>Fill out the form below and submit to contact our Dealer Development department for more details. Or call (248) 549-7777 and ask to speak with our Dealer Coordinator about this program.</p>');}
	if(departure=='req'){document.write('<p class="maintext12">Fill out the form below to request a complimentary copy of our full color product brochure. Includes application information, available colors and finishes, technical information and pricing. Please allow 7-10 days for delivery.</p>');}
	
}//--------------------------------------------------------------------------------------END FUNCTION

//---------------------------------------------------------------------------------------BEGIN FUNCTION
function lockVariables(){
	var departure=location.search.substring(1);
	if(departure!='faq'&&departure!='dlr'&&departure!='req'){}
	if(departure=='dlr'){document.contactform.inquiretype.value="5"; document.contactform.inquiretype.disabled=true;}
	if(departure=='req'){}
}//--------------------------------------------------------------------------------------END FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function subRequest(){
	var isinfoOK = false;
	var fname = document.getElementById('required-fname');
	var lname = document.getElementById('required-lname');
	var bestway = document.getElementById('contactmethod');
	var emailaddr = document.getElementById('required-email'); var emailstring = emailaddr.value; var checker=emailstring.indexOf('@');
	var phonenum = document.getElementById('required-phone'); var phonestring = phonenum.value;
	var besttime = document.getElementById('contacttime');
	
	if (fname.value=='' || fname.value==' '){alert('Please enter your first name to continue.'); fname.focus();} else
	if (lname.value=='' || lname.value==' '){alert('Please enter your last name to continue.'); lname.focus();} else
	if (bestway.value=='' || bestway.value==' '){alert('Please choose a contact method.'); bestway.focus();} else
	if (bestway.value=='email' && checker<=0){alert('Please enter a valid email address.'); emailaddr.focus();} else
	if (bestway.value=='phone' && phonestring.length<10){alert('Please enter a valid phone number including area code.'); phonenum.focus();} else
	if (besttime.value==''){alert('Please let us know the best time to contact you.'); besttime.focus();}else{isinfoOK=true;}
	
	if (isinfoOK==true){
	//var request_type=document.contact.emailrecpt.value;
	//parent.leftFrame.storedinfo.reqtype.value = request_type;
	document.contact.submit();}
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------------------------------BEGIN FUNCTION
function setRequirement(a){
	if(a==""){document.contact.rec_phone.value=''; document.contact.rec_email.value='';}
	if(a=="email"){document.contact.rec_phone.value=''; document.contact.rec_email.value='REQUIRED';}
	if(a=="phone"){document.contact.rec_phone.value='REQUIRED'; document.contact.rec_email.value='';}
}//----------------------------------------------------------------------------------------------END FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function buildThanks(){
	var req_type = parent.leftFrame.storedinfo.reqtype.value;
	if (req_type == 'sales'){document.write('<p>We will forward your information to our Sales Department.</p>');}
	if (req_type == 'dealer'){document.write('<p>We will forward your information to our Dealer Development Department.</p>');}
	if (req_type == 'service'){document.write('<p>We will forward your information to our Customer Service Department.</p>');}
	if (req_type == 'tech'){document.write('<p>We will forward your information to our Technical Support Department.</p>');}
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function setArea(a){
	document.contact.comarea.value='Airplane Hangar'; document.contact.resarea.value='Garage';
	showOther('reset');
	if(a=='Residential'){
		document.contact.resarea.style.display='';
		document.contact.comarea.style.display='none';
		
	}else{
		document.contact.resarea.style.display='none';
		document.contact.comarea.style.display='';}
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function showOther(a){
	if(a=='Other'){
		document.contact.otherarea.style.display='';
	}else{
		document.contact.otherarea.style.display='none';
		document.contact.otherarea.value='';
	}
}//----------------------------------------------------------------------END OF FUNCTION
//-----------------------------------------------------------------------BEGIN FUNCTION
function checkOther(a){
	var contact = document.getElementById('contact');
	if(a=='Other'){contact.otherheard.style.display='';
	}else{
		contact.otherheard.style.display='none';
		contact.otherheard.value='';
	}
}//----------------------------------------------------------------------END OF FUNCTION
//-----------------------------------------------------------------------BEGIN FUNCTION
function checkBigger(a){
	var contact = document.getElementById('contact');
	if(a=='Other'){contact.largerarea.style.display='';
	}else{
		contact.largerarea.style.display='none';
		contact.largerarea.value='';
	}
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function showHeard(a){
	var contact = document.getElementById('contact');
	if(a=='0'){
		contact.tvheard.style.display='none'; contact.tvheard.value='0';
		contact.magheard.style.display='none'; contact.magheard.value='0';
		contact.eventheard.style.display='none'; contact.eventheard.value='0';
		contact.webheard.style.display='none'; contact.webheard.value='0';
		contact.otherheard.style.display='none'; contact.otherheard.value='';}
		
	if(a=='TV'){
		contact.tvheard.style.display=''; contact.tvheard.value='0';
		contact.magheard.style.display='none'; contact.magheard.value='0';
		contact.eventheard.style.display='none'; contact.eventheard.value='0';
		contact.webheard.style.display='none'; contact.webheard.value='0';
		contact.otherheard.style.display='none'; contact.otherheard.value='';}
	
	if(a=='Magazine'){
		contact.tvheard.style.display='none'; contact.tvheard.value='0';
		contact.magheard.style.display=''; contact.magheard.value='0';
		contact.eventheard.style.display='none'; contact.eventheard.value='0';
		contact.webheard.style.display='none'; contact.webheard.value='0';
		contact.otherheard.style.display='none'; contact.otherheard.value='';}
	
	if(a=='Special Event'){
		contact.tvheard.style.display='none'; contact.tvheard.value='0';
		contact.magheard.style.display='none'; contact.magheard.value='0';
		contact.eventheard.style.display=''; contact.eventheard.value='0';
		contact.webheard.style.display='none'; contact.webheard.value='0';
		contact.otherheard.style.display='none'; contact.otherheard.value='';}
	
	if(a=='Web'){
		contact.tvheard.style.display='none'; contact.tvheard.value='0';
		contact.magheard.style.display='none'; contact.magheard.value='0';
		contact.eventheard.style.display='none'; contact.eventheard.value='0';
		contact.webheard.style.display=''; contact.webheard.value='0';
		contact.otherheard.style.display='none'; contact.otherheard.value='';}
	
	if(a=='Other'){
		contact.tvheard.style.display='none'; contact.tvheard.value='0';
		contact.magheard.style.display='none'; contact.magheard.value='0';
		contact.eventheard.style.display='none'; contact.eventheard.value='0';
		contact.webheard.style.display='none'; contact.webheard.value='0';
		contact.otherheard.style.display=''; contact.otherheard.value='';}
		
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function compileRequest(){
	var contact=document.getElementById('contact');
	//----------compile area description -----------
	var areatype=contact.areatype.value;
	var areadesc;
	if(areatype=='0'){areadesc='N/A'; contact.areaspecs.value=areadesc;}else{
		if(areatype=='Residential'){areadesc=contact.resarea.value}else{areadesc=contact.comarea.value}
		if(areadesc=='Other'){areadesc=areadesc+': ' + String(contact.otherarea.value);}
		contact.areaspecs.value=areatype + ' Area, ' + areadesc;
	}
	
	if(contact.req_quote.checked){contact.quoterequest.value='YES';}else{contact.quoterequest.value='NO';}
	if(contact.add_list.checked){contact.mailinglist.value='YES';}else{contact.mailinglist.value='NO';}
	if(contact.add_elist.checked){contact.emaillist.value='YES';}else{contact.emaillist.value='NO';}
	if(contact.add_brochure.checked){contact.brochure.value='YES';}else{contact.brochure.value='NO';}
	
	//----------compile how heard info --------------
	var howheard = contact.howheard.value;
	var howhearddesc = contact.howheard.value + ', ';
	if(howheard=='TV'){
		howhearddesc = howhearddesc + contact.tvheard.value;
		if(contact.tvheard.value=='Other'){howhearddesc=howhearddesc + ': ' + contact.otherheard.value;}
		}
	if(howheard=='Magazine'){
		howhearddesc = howhearddesc + contact.magheard.value;
		if(contact.magheard.value=='Other'){howhearddesc=howhearddesc + ': ' + contact.otherheard.value;}
		}
	if(howheard=='Special Event'){
		howhearddesc = howhearddesc + contact.eventheard.value;
		if(contact.eventheard.value=='Other'){howhearddesc=howhearddesc + ': ' + contact.otherheard.value;}
		}
	if(howheard=='Web'){howhearddesc = howhearddesc + contact.webheard.value;
		if(contact.webheard.value=='Other'){howhearddesc=howhearddesc + ': ' + contact.otherheard.value;}
		}
	if(howheard=='Other'){howhearddesc = howhearddesc + contact.otherheard.value;}
	contact.howhearddesc.value=howhearddesc;
	//----------submit form -----------------
	contact.submit();
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
function verifyForm(a){
	if (a.fname.value=='' || a.fname.value==' '){alert('Please enter your first name to continue.'); return;}
	if (a.lname.value=='' || a.lname.value==' '){alert('Please enter your last name to continue.'); return;}
	if (a.address.value=='' || a.address.value==' '){alert('Please enter a valid street address to continue.'); return;}
	if (a.address.value=='' || a.address.value==' '){alert('Please enter a valid street address to continue.'); return;}
	if (a.city.value=='' || a.city.value==' '){alert('Please enter a valid city address to continue.'); return;}
	if (a.state.value=='' || a.state.value==' '){alert('Please enter a valid state or province to continue.'); return;}
	if (a.zip.value=='' || a.zip.value==' '){alert('Please enter a valid zipcode to continue.'); return;}
	var at_check=String(a.email.value); var pos=at_check.indexOf('@');
	if (pos == -1 || pos==0){alert('Please enter a valid email address to continue.'); return;}
	
	if (a.req_quote.checked){ if(a.areatype.value=='0'){alert('Please enter your area type, if requesting a quote, to continue.'); return;} }
	
	a.bname.value=cleanString(a.bname.value);
	a.fname.value=cleanString(a.fname.value);
	a.lname.value=cleanString(a.lname.value);
	compileRequest();
}//----------------------------------------------------------------------END OF FUNCTION

//-----------------------------------------------------------------------BEGIN FUNCTION
//-----------------------------------------------------------------------BEGIN FUNCTION
function cleanString(x){
	var newstring=String(x);
	//---- capitalize first char no matter what -----
	var str1 = newstring.substring(0,1); str1=str1.toUpperCase();
	var str1en = newstring.length;
	var remaining = newstring.substring(1,str1en);
	newstring = str1+remaining;
	
	for (i=0; i<newstring.length; i++){
		var thischar = newstring.substring(i,i+1);
		//---- remove reserved characters -----
		if(thischar=="'" || thischar=="%" || thischar=="<"  || thischar=="?"  || thischar==">" || thischar=="#" || thischar == "$"){
			newstring=newstring.substring(0,i)+newstring.substring(i+1, newstring.length);
		}
		//---- capitalize any other char after space or dash -----
		if(thischar==' ' || thischar=='-'){
			
			var nextchar=newstring.substring(i+1,i+2);
			nextchar=nextchar.toUpperCase();
			newstring=newstring.substring(0,i+1)+ nextchar +newstring.substring(i+2, newstring.length);
		}
	}
	return newstring;
}//----------------------------------------------------------------------END OF FUNCTION
