// JavaScript Document
<!--

function updateCountry()
{
   if (document.myform.state_required) {
	if (document.myform.country.value != 'United States') {
		document.myform.state_required.setStyle({'display':'none'});
		document.myform.zip_required.setStyle({'display':'none'});
		document.myform.phone_required.setStyle({'display':'none'});
		document.myform.fax_required.setStyle({'display':'none'});
		document.myform.int_phone_required.setStyle({'display':'inline'});
		document.myform.int_fax_required.setStyle({'display':'inline'});
	}
	else {
		document.myform.state_required.setStyle({'display':'inline'});
		document.myform.zip_required.setStyle({'display':'inline'});
		document.myform.phone_required.setStyle({'display':'inline'});
		document.myform.fax_required.setStyle({'display':'inline'});
		document.myform.int_phone_required.setStyle({'display':'none'});
		document.myform.int_fax_required.setStyle({'display':'none'});
	}
   }
}

function doAddAnother(){
	with (document.myform) {
		if (submit_quote()){
			addAnother.value=1;
			submit();
		}
		else{
			return false;
		}
	}
}

function metal_family ( )
{
	var d = document;
	var metal_families = "Alloy Steels,Carbon Steels,Stainless Steel,Tool Steels,Aluminum,Magnesium Alloys,Titanium,";
		metal_families += "Super Alloy,Refractory Alloys,Copper Alloys,Brazing/ Soldering Alloys,Cast Irons,Ductile Irons,";
		metal_families += "Electrical Steel,Gray Irons,Metal Matrix Composites,Pure Elements,Unknown,Zinc Alloys";
	metal_families = metal_families.split(",");

	var option;
	for(var i=0;i<metal_families.length;i++)
	{
		option = d.getElementById('metal_family').appendChild(d.createElement("option"));
		option.text = metal_families[i];
		option.value = metal_families[i];
	}
}

function clear_options ( optionlist )
{
	//alert('clear_options');
	var d = document;
	var myoptions = d.getElementById(optionlist);
	//alert(myoptions.length);
	for(var i=1;i<myoptions.length;i++)
	{
		myoptions[i] = null;
	}
}

function get_metal_family_total ( )
{
	var d = document;
	var metal_families = d.getElementById('metal_family').length - 1;
	return metal_families;
}

function update_alloys()
{

	var metal_family = $('metal_family').value;
	
	var url = PATH+'incl/js_update_alloys.req.php';
	
	var pars = 'metal_family='+metal_family;

	new Ajax.Updater('alloy_div',
			url,
			{
	 			method: 'get',
	 			parameters: pars
			});
}

//**************************Quote************************************
function submit_quote()
{
	var name = document.myform.name.value;
	var lname = document.myform.lname.value;
	var company = document.myform.company.value;
	var title = document.myform.title.value;
	var address = document.myform.address.value;
	var address2 = document.myform.address2.value;
	var city = document.myform.city.value;
	var state = document.myform.state.value;
	var zip = document.myform.zip.value;
	var country = document.myform.country.value;
	var phone1 = document.myform.phone1.value;
	var phone2 = document.myform.phone2.value;
	var phone3 = document.myform.phone3.value;
	var extension = document.myform.extension.value;
	var fax1 = document.myform.fax1.value;
	var fax2 = document.myform.fax2.value;
	var fax3 = document.myform.fax3.value;
	var intl_phone = document.myform.intl_phone.value;
	var intl_fax = document.myform.intl_fax.value;
	var email = document.myform.email.value;
	var email_confirm = document.myform.email_confirm.value;
	var website = document.myform.website.value;
	var send_literature = document.myform.send_literature.value;
	var contact_method = document.myform.contact_method.value;
	var metal_family = document.myform.metal_family.value;
	var alloy = document.myform.alloy.value;
	var metal_form = document.myform.metal_form.value;
	var size = document.myform.size.value;
	var size_unit = document.myform.size_unit.value;
	var size_type = document.myform.size_type.value;
	var quantity = document.myform.quantity.value;
	var metal_unit = document.myform.metal_unit.value;
	var additional_quantity1 = document.myform.additional_quantity1.value;
	var additional_quantity2 = document.myform.additional_quantity2.value;
	var additional_quantity3 = document.myform.additional_quantity3.value;
	var additional_quantity4 = document.myform.additional_quantity4.value;
	var additional_quantity5 = document.myform.additional_quantity5.value;
	var specs = document.myform.specs.value;
	var det_type = document.myform.det_type.value;
	var det_type = document.myform.det_type.value;
	var delivery_info = document.myform.delivery_info.value;
	var others = document.myform.others.value;
	var part_number = document.myform.part_number.value;
	var att1 = document.myform.att1.value;
	var att2 = document.myform.att2.value;
	var att3 = document.myform.att3.value;
	var comments = document.myform.comments.value;

	if (name=="") {
		alert("Please fill in your first name properly");
		document.myform.name.focus();
		return false;
	}
	else if (lname=="") {
		alert("Please fill in your last name properly");
		document.myform.lname.focus();
		return false;
	}
	else if (company=="") {
		alert("Please fill in your company name properly");
		document.myform.company.focus();
		return false;
	}
	else if (address=="") {
		alert("Please fill in the address properly");
		document.myform.address.focus();
		return false;
	}
	else if (city=="") {
		alert("Please fill in your city properly");
		document.myform.city.focus();
		return false;
	}
	else if (country=="") {
		alert("Please select your country properly");
		document.myform.country.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && state=="") {
		alert("Please select your state properly");
		document.myform.state.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && (zip=="" || validate_zipcode(zip))) {		
		alert("Please fill in your zip code properly");
		document.myform.zip.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && phone1=="") {
		alert("Please fill your phone area code properly");
		document.myform.phone1.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && isNaN(phone1)) {
		alert("Please fill your phone area code properly (numbers only)");
		document.myform.phone1.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && phone1.length != 3) {
		alert("Please fill your phone area code properly (3 digits)");
		document.myform.phone1.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && phone2=="") {
		alert("Please fill your phone number prefix properly");
		document.myform.phone2.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && isNaN(phone2)) {
		alert("Please fill your phone number prefix properly (numbers only)");
		document.myform.phone2.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && phone2.length != 3) {
		alert("Please fill your phone number prefix properly (3 digits)");
		document.myform.phone2.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && phone3=="") {
		alert("Please fill your phone number properly");
		document.myform.phone3.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && isNaN(phone3)) {
		alert("Please fill your phone number properly (numbers only)");
		document.myform.phone3.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && phone3.length != 4) {
		alert("Please fill your phone number properly (4 digits)");
		document.myform.phone3.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && fax1=="") {
		alert("Please fill your fax area code properly");
		document.myform.fax1.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && isNaN(fax1)) {
		alert("Please fill your fax area code properly (numbers only)");
		document.myform.fax1.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && fax1.length != 3) {
		alert("Please fill your fax area code properly (3 digits)");
		document.myform.fax1.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && fax2=="") {
		alert("Please fill your fax number prefix properly");
		document.myform.fax2.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && isNaN(fax2)) {
		alert("Please fill your fax number prefix properly (numbers only)");
		document.myform.fax2.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && fax2.length != 3) {
		alert("Please fill your fax number prefix properly (3 digits)");
		document.myform.fax2.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && fax3=="") {
		alert("Please fill your fax number properly");
		document.myform.fax3.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && isNaN(fax3)) {
		alert("Please fill your fax number properly (numbers only)");
		document.myform.fax3.focus();
		return false;
	}
	else if (document.myform.country.value == 'United States' && fax3.length != 4) {
		alert("Please fill your fax number properly (4 digits)");
		document.myform.fax3.focus();
		return false;
	}
	else if (document.myform.country.value != 'United States' && intl_phone=="") {
		alert("Please fill your phone properly");
		document.myform.intl_phone.focus();
		return false;
	}
	else if (document.myform.country.value != 'United States' && intl_fax=="") {
		alert("Please fill your fax properly");
		document.myform.intl_fax.focus();
		return false;
	}
	else if (email=="") {
		alert("Please enter your email address.");
		document.myform.email.focus();
		return false;
	}
	else if (email != email_confirm) {
		alert("Please reconfirm your email address");
		document.myform.email_confirm.focus();
		return false;
	}
	else if (contact_method=="") {
		alert("Please select a contact method");
		document.myform.contact_method.focus();
		return false;
	}
	else if (metal_family=="") {
		alert("Please select a metal family");
		document.myform.metal_family.focus();
		return false;
	}
	else if (alloy=="") {
		alert("Please select alloy type");
		document.myform.alloy.focus();
		return false;
	}
	else if (metal_form == "") {
		alert("Please select a metal form");
		document.myform.metal_form.focus();
		return false;
	}

	else if (size == "") {
		alert("Please fill in the size properly.\n\n Incomplete or inaccurate size information will slow down the inquiry process and may result in us being unable to send you a quote.");
		document.myform.size.focus();
		return false;
	}
	
	else if (quantity == "") {
		alert("Please enter a quantity");
		document.myform.quantity.focus();
		return false;
	}

        if (!(document.myform.inq_id)) {
        	//alert('sending insite post!');
		//************************************Insite Post******************************
		url = "http://www.topfloortech.com/insitemetrics/uRMJ/uniformv2.php";
		url += "?actk=t0dvlq-2tqu62jx8s"; //unique action key
		url += "&imReferrerField=" + escape(document.referrer);
		url += "&Name=" + escape(document.myform.name.value+" "+document.myform.lname.value);
		url += "&Company=" + escape(document.myform.company.value);
		url += "&Title=" + escape(document.myform.title.value);	
		url += "&Address=" + escape(document.myform.address.value);
		url += "&Address2=" + escape(document.myform.address2.value);
		url += "&City=" + escape(document.myform.city.value);
		url += "&State=" + escape(document.myform.state.value);
		url += "&Zip=" + escape(document.myform.zip.value);
		url += "&Country=" + escape(document.myform.country.value);
		url += "&Phone=" + escape(document.myform.phone1.value) +"-"+ escape(document.myform.phone2.value) +"-"+ escape(document.myform.phone3.value);
		url += "&Extension=" + escape(document.myform.extension.value);
		url += "&Fax=" + escape(document.myform.fax1.value) +"-"+ escape(document.myform.fax2.value) +"-"+ escape(document.myform.fax3.value);
		url += "&intl_phone=" + escape(document.myform.intl_phone.value);
		url += "&intl_fax=" + escape(document.myform.intl_fax.value);
		url += "&imEmailField=" + escape(document.myform.email.value);
		url += "&Website=" + escape(document.myform.website.value);
		url += "&Send_Literature=" + escape(document.myform.send_literature.value);
		url += "&Contact_Method=" + escape(document.myform.contact_method.value);
		url += "&Metal_Family=" + escape(document.myform.metal_family.value);	
		url += "&Alloy=" + escape(document.myform.alloy.value);
		url += "&Metal_Form=" + escape(document.myform.metal_form.value);
		url += "&Size=" + escape(document.myform.size.value);
		url += "&Size_Unit=" + escape(document.myform.size_unit.value);
		url += "&Size_Type=" + escape(document.myform.size_type.value);
		url += "&Quantity=" + escape(document.myform.quantity.value);
		url += "&Metal_Unit=" + escape(document.myform.metal_unit.value);
		url += "&additional_quantity1=" + escape(document.myform.additional_quantity1.value);
		url += "&additional_quantity2=" + escape(document.myform.additional_quantity2.value);
		url += "&additional_quantity3=" + escape(document.myform.additional_quantity3.value);
		url += "&additional_quantity4=" + escape(document.myform.additional_quantity4.value);
		url += "&additional_quantity5=" + escape(document.myform.additional_quantity5.value);
		url += "&Specs=" + escape(document.myform.specs.value);
		url += "&Det_Type=" + escape(document.myform.det_type.value);
		url += "&Delivery_Info=" + escape(document.myform.delivery_info.value);
		url += "&Others=" + escape(document.myform.others.value);
		url += "&Part_Number=" + escape(document.myform.part_number.value);
		url += "&Comments=" + escape(document.myform.comments.value);
		img = new Image(0,0);
		setTimeout(function(){img.src = url;},500)
		//************************************End Insite Post******************************
        }
	
	return true;
}
//****************************End Quote*****************************************

// Validate zip
function validate_zipcode(zip)
{
	var stripped = zip.replace(/[\(\)\.\-\ ]/g, '');
	
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
		return 1;
	}
	
	if (!(stripped.length == 5)) {
		return 1;
	}
	return 0;
}

