// JavaScript Document
<!--

function updateCountry()
{
   if ($('state_required')) {
	if ($('country').value != 'United States') {
		$('state_required').style.display = 'none';
		$('zip_required').style.display = 'none';
		$('phone_required').style.display = 'none';
		$('fax_required').style.display = 'none';
		$('int_phone_required').style.display = '';
		$('int_fax_required').style.display = '';
	}
	else {
		$('state_required').style.display = '';
		$('zip_required').style.display = '';
		$('phone_required').style.display = '';
		$('fax_required').style.display = '';
		$('int_phone_required').style.display = 'none';
		$('int_fax_required').style.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 = $('name').value;
	var lname = $('lname').value;
	var company = $('company').value;
	var title = $('title').value;
	var address = $('address').value;
	var address2 = $('address2').value;
	var city = $('city').value;
	var state = $('state').value;
	var zip = $('zip').value;
	var country = $('country').value;
	var phone1 = $('phone1').value;
	var phone2 = $('phone2').value;
	var phone3 = $('phone3').value;
	var extension = $('extension').value;
	var fax1 = $('fax1').value;
	var fax2 = $('fax2').value;
	var fax3 = $('fax3').value;
	var intl_phone = $('intl_phone').value;
	var intl_fax = $('intl_fax').value;
	var email = $('email').value;
	var email_confirm = $('email_confirm').value;
	var website = $('website').value;
	var send_literature = $('send_literature').value;
	var contact_method = $('contact_method').value;
	var metal_family = $('metal_family').value;
	var alloy = $('alloy').value;
	var metal_form = $('metal_form').value;
//	var Thickness = $('Thickness').value;
//	var Length = $('Length').value;
//	var Width = $('Width').value;
//	var OD = $('OD').value;
//	var ID = $('ID').value;
	var size = $('size').value;
	var size_unit = $('size_unit').value;
	var size_type = $('size_type').value;
	var quantity = $('quantity').value;
	var metal_unit = $('metal_unit').value;
	var additional_quantity1 = $('additional_quantity1').value;
	var additional_quantity2 = $('additional_quantity2').value;
	var additional_quantity3 = $('additional_quantity3').value;
	var additional_quantity4 = $('additional_quantity4').value;
	var additional_quantity5 = $('additional_quantity5').value;
	var specs = $('specs').value;
	var det_type = $('det_type').value;
	var det_type = $('det_type').value;
	var delivery_info = $('delivery_info').value;
	var others = $('others').value;
	var part_number = $('part_number').value;
	var att1 = $('att1').value;
	var att2 = $('att2').value;
	var att3 = $('att3').value;
	var comments = $('comments').value;
		
	if (name=="") {
		alert("Please fill in your first name properly");
		$('name').focus();
		return false;
	}
	else if (lname=="") {
		alert("Please fill in your last name properly");
		$('lname').focus();
		return false;
	}
	else if (company=="") {
		alert("Please fill in your company name properly");
		$('company').focus();
		return false;
	}
	else if (address=="") {
		alert("Please fill in the address properly");
		$('address').focus();
		return false;
	}
	else if (city=="") {
		alert("Please fill in your city properly");
		$('city').focus();
		return false;
	}
	else if (country=="") {
		alert("Please select your country properly");
		$('country').focus();
		return false;
	}
	else if ($('country').value == 'United States' && state=="") {
		alert("Please select your state properly");
		$('state').focus();
		return false;
	}
	else if ($('country').value == 'United States' && (zip=="" || validate_zipcode(zip))) {		
		alert("Please fill in your zip code properly");
		$('zip').focus();
		return false;
	}
	else if ($('country').value == 'United States' && phone1=="") {
		alert("Please fill your phone area code properly");
		$('phone1').focus();
		return false;
	}
	else if ($('country').value == 'United States' && isNaN(phone1)) {
		alert("Please fill your phone area code properly (numbers only)");
		$('phone1').focus();
		return false;
	}
	else if ($('country').value == 'United States' && phone1.length != 3) {
		alert("Please fill your phone area code properly (3 digits)");
		$('phone1').focus();
		return false;
	}
	else if ($('country').value == 'United States' && phone2=="") {
		alert("Please fill your phone number prefix properly");
		$('phone2').focus();
		return false;
	}
	else if ($('country').value == 'United States' && isNaN(phone2)) {
		alert("Please fill your phone number prefix properly (numbers only)");
		$('phone2').focus();
		return false;
	}
	else if ($('country').value == 'United States' && phone2.length != 3) {
		alert("Please fill your phone number prefix properly (3 digits)");
		$('phone2').focus();
		return false;
	}
	else if ($('country').value == 'United States' && phone3=="") {
		alert("Please fill your phone number properly");
		$('phone3').focus();
		return false;
	}
	else if ($('country').value == 'United States' && isNaN(phone3)) {
		alert("Please fill your phone number properly (numbers only)");
		$('phone3').focus();
		return false;
	}
	else if ($('country').value == 'United States' && phone3.length != 4) {
		alert("Please fill your phone number properly (4 digits)");
		$('phone3').focus();
		return false;
	}
	else if ($('country').value == 'United States' && fax1=="") {
		alert("Please fill your fax area code properly");
		$('fax1').focus();
		return false;
	}
	else if ($('country').value == 'United States' && isNaN(fax1)) {
		alert("Please fill your fax area code properly (numbers only)");
		$('fax1').focus();
		return false;
	}
	else if ($('country').value == 'United States' && fax1.length != 3) {
		alert("Please fill your fax area code properly (3 digits)");
		$('fax1').focus();
		return false;
	}
	else if ($('country').value == 'United States' && fax2=="") {
		alert("Please fill your fax number prefix properly");
		$('fax2').focus();
		return false;
	}
	else if ($('country').value == 'United States' && isNaN(fax2)) {
		alert("Please fill your fax number prefix properly (numbers only)");
		$('fax2').focus();
		return false;
	}
	else if ($('country').value == 'United States' && fax2.length != 3) {
		alert("Please fill your fax number prefix properly (3 digits)");
		$('fax2').focus();
		return false;
	}
	else if ($('country').value == 'United States' && fax3=="") {
		alert("Please fill your fax number properly");
		$('fax3').focus();
		return false;
	}
	else if ($('country').value == 'United States' && isNaN(fax3)) {
		alert("Please fill your fax number properly (numbers only)");
		$('fax3').focus();
		return false;
	}
	else if ($('country').value == 'United States' && fax3.length != 4) {
		alert("Please fill your fax number properly (4 digits)");
		$('fax3').focus();
		return false;
	}
	else if ($('country').value != 'United States' && intl_phone=="") {
		alert("Please fill your phone properly");
		$('intl_phone').focus();
		return false;
	}
	else if ($('country').value != 'United States' && intl_fax=="") {
		alert("Please fill your fax properly");
		$('intl_fax').focus();
		return false;
	}
	else if (!(validate_email(email)) || (email == "")) {
		$('email').focus();
		return false;
	}
	else if (email != email_confirm) {
		
		alert("Please reconfirm your email address");
		$('email_confirm').focus();
		return false;
	}
	else if (contact_method=="") {
		alert("Please select a contact method");
		$('contact_method').focus();
		return false;
	}
	else if (metal_family=="") {
		alert("Please select a metal family");
		$('metal_family').focus();
		return false;
	}
	else if (alloy=="") {
		alert("Please select alloy type");
		$('alloy').focus();
		return false;
	}
	else if (metal_form == "") {
		alert("Please select a metal form");
		$('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.");
		$('size').focus();
		return false;
	}
	
	else if (quantity == "") {
		alert("Please enter a quantity");
		$('quantity').focus();
		return false;
	}

        if (!($('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($("name").value+" "+$("lname").value);
		url += "&Company=" + escape($("company").value);
		url += "&Title=" + escape($("title").value);	
		url += "&Address=" + escape($("address").value);
		url += "&Address2=" + escape($("address2").value);
		url += "&City=" + escape($("city").value);
		url += "&State=" + escape($("state").value);
		url += "&Zip=" + escape($("zip").value);
		url += "&Country=" + escape($("country").value);
		url += "&Phone=" + escape($("phone1").value) +"-"+ escape($("phone2").value) +"-"+ escape($("phone3").value);
		url += "&Extension=" + escape($("extension").value);
		url += "&Fax=" + escape($("fax1").value) +"-"+ escape($("fax2").value) +"-"+ escape($("fax3").value);
		url += "&intl_phone=" + escape($("intl_phone").value);
		url += "&intl_fax=" + escape($("intl_fax").value);
		url += "&imEmailField=" + escape($("email").value);
		url += "&Website=" + escape($("website").value);
		url += "&Send_Literature=" + escape($("send_literature").value);
		url += "&Contact_Method=" + escape($("contact_method").value);
		url += "&Metal_Family=" + escape($("metal_family").value);	
		url += "&Alloy=" + escape($("alloy").value);
		url += "&Metal_Form=" + escape($("metal_form").value);
		url += "&Size=" + escape($("size").value);
		url += "&Size_Unit=" + escape($("size_unit").value);
		url += "&Size_Type=" + escape($("size_type").value);
		url += "&Quantity=" + escape($("quantity").value);
		url += "&Metal_Unit=" + escape($("metal_unit").value);
		url += "&additional_quantity1=" + escape($("additional_quantity1").value);
		url += "&additional_quantity2=" + escape($("additional_quantity2").value);
		url += "&additional_quantity3=" + escape($("additional_quantity3").value);
		url += "&additional_quantity4=" + escape($("additional_quantity4").value);
		url += "&additional_quantity5=" + escape($("additional_quantity5").value);
		url += "&Specs=" + escape($("specs").value);
		url += "&Det_Type=" + escape($("det_type").value);
		url += "&Delivery_Info=" + escape($("delivery_info").value);
		url += "&Others=" + escape($("others").value);
		url += "&Part_Number=" + escape($("part_number").value);
		url += "&Comments=" + escape($("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;
}
