﻿// JScript File

//suckerfish dropdown support for IE
initSuckerfish = function() {
    if (document.all&&document.getElementById) {
        navRoot = document.getElementById("nav");
        for (i=0; i<navRoot.childNodes.length; i++) {
            node = navRoot.childNodes[i];
            if (node.nodeName=="LI") {
                node.onmouseover=function() {
                    this.className+=" over";
                }
                node.onmouseout=function() {
                    this.className=this.className.replace(" over", "");
                }
            }
         }
     }
}

//end suckerfish dropdown support for IE


if (window.attachEvent) {
    window.attachEvent("onload", lmcm_init);
}else if (window.addEventListener) {
    window.addEventListener("load", lmcm_init, false);
}

function lmcm_init() {
    initSuckerfish();
    buildSecNav();
}

function buildSecNav() {
    var cont = document.getElementById("listContainer");
    var sel = document.getElementById("selectedTab");
    if (sel && cont) {
        var ul = sel.getElementsByTagName("ul");
        if (ul) {
            var items = ul[0].innerHTML;
        }
        cont.innerHTML = items;
    }
    
}

//adding JavaScript to clear the search form in the header
function clearField(Default, field) {
    if (field.value == Default) {
        field.value = "";
    }
}

function resetField(Default, field) {
    if (field.value.replace(new RegExp(" ", "g"),'') == "") {
        field.value = Default;
    }
}

function showNav(nav) {
    var cont = document.getElementById("listContainer");
    var thisItem = nav.parentElement ? nav.parentElement.parentElement : nav.parentNode.parentNode;
    var list = thisItem.getElementsByTagName("ul");
    var selected = document.getElementById("selectedTab");
    if (list.length > 0) {
        if (list[0].childNodes.length > 0) {
            cont.innerHTML = "";
            cont.innerHTML = list[0].innerHTML;
            if (selected) {selected.id = "";}
            thisItem.id = "selectedTab";
        }
        else {
            window.location = nav.href;
        }
    }
}


var oForm;
function contactInit() {
    oForm = document.getElementById("info");
}

function isValid(){
	if (!oForm.FirstName.value.length) {alert("Please enter a valid First Name \n(at least 2 alphanumeric characters).");  oForm.FirstName.focus(); return}
	if (!oForm.LastName.value.length) {alert("Please enter a valid Last Name \n(at least 2 alphanumeric characters)."); oForm.LastName.focus(); return}

	if (!oForm.Email.value.length) {alert("Please enter a valid email address. \n(at least 2 alphanumeric characters)."); oForm.Email.focus(); return}
	else if (oForm.Email.value.indexOf("@") < 1 || oForm.Email.value.indexOf(".") < 1 || oForm.Email.value.indexOf(".") > oForm.Email.value.length - 2) {alert("Please enter a correctly formatted email address."); return}

	if (!oForm.Country[0].checked && !oForm.Country[1].checked) {alert("Please select your location."); return}

	if (oForm.Country[0].checked == true) {

	intclear();

		if (!oForm.Address1.value.length) {alert("Please enter a valid Address."); oForm.Address1.focus(); return}
		if (!oForm.City.value.length) {alert("Please enter a valid City name."); oForm.City.focus(); return}
		if (!oForm.State.value.length) {alert("Please enter a State."); oForm.State.focus(); return}
		if (!oForm.Zip.value.length) {alert("Please enter a Zip Code."); oForm.Zip.focus(); return}
    }

	if (oForm.Country[1].checked == true) {

	usclear();

		if (!oForm.Address1_int.value.length) {alert("Please enter a valid Address."); oForm.Address1_int.focus(); return}
		if (!oForm.City_int.value.length) {alert("Please enter a valid City name."); oForm.City_int.focus(); return}
		// if (!oForm.State_int.value.length) {alert("Please enter a State."); oForm.State_int.focus(); return}
		//if (!oForm.Zip_int.value.length) {alert("Please enter a Zip Code."); oForm.Zip_int.focus(); return}
		if (!oForm.Country_Name.value.length) {alert("Please select your Country."); oForm.Country_Name.focus(); return}
    }

	return true;
}


function doSubmit(){
 	if (isValid()) oForm.submit();
}

function usclear(){
    oForm.Address1.value = "";
    oForm.Address2.value = "";
    oForm.City.value = "";
    oForm.State.value = "";
    oForm.Zip.value = "";
}

function intclear(){
    oForm.Address1_int.value = "";
    oForm.Address2_int.value = "";
    oForm.City_int.value = "";
    oForm.State_int.value = "";
    oForm.Zip_int.value = "";
    oForm.Country_Name.value = "";
}

function toggleForm(type) {
	if (type == "us") {
		document.getElementById("usForm").style.display = "block";
		document.getElementById("intForm").style.display = "none";
	}
	else if (type == "int") {
		document.getElementById("intForm").style.display = "block";
		document.getElementById("usForm").style.display = "none";
	}
}