// mouseover preloads
var mouseovers = new Array();
if (document.images) {
//	var mouseoversList = new Array('products_and_systems', 'service', 'manufacturers', 'about_ga_fleet', 'contact_us', 'products_and_systems_plumbing_and_fire_protection', 'products_and_systems_hvac_and_energy', 'products_and_systems_municipal', 'products_and_systems_equipment_protection', 'products_and_systems_leak_detection', 'about_ga_fleet_company_history', 'about_ga_fleet_news', 'case_studies', 'case_studies_fleet_pump', 'case_studies_equipment', 'case_studies_hvac', 'case_studies_plumbing', 'about_ga_fleet_employment_opportunities', 'contact_us_administrative', 'contact_us_sales', 'contact_us_service', 'contact_us_municipal', 'contact_us_start-up');
	var mouseoversList = new Array('products_and_systems', 'service', 'manufacturers', 'about_ga_fleet', 'contact_us', 'case_studies');
	for (var i=0; i<mouseoversList.length; i++) {
		mouseovers[mouseoversList[i]+'Off'] = new Image();
		mouseovers[mouseoversList[i]+'Off'].src = "/images/nav/"+mouseoversList[i]+'_off.gif';
		mouseovers[mouseoversList[i]+'On'] = new Image();
		mouseovers[mouseoversList[i]+'On'].src = "/images/nav/"+mouseoversList[i]+'_on.gif';
	}
}

// mouseover image functions
function imgOn(parent) {
	// don't turn on current page's nav link
	//alert(parent.id);
	imgName = parent.firstChild.name;
	if (document.images && (imgName != curPage)) { document[imgName].src = mouseovers[imgName+'On'].src; }
}

function imgOff(parent) {
    // don't turn off current page's nav link
	imgName = parent.firstChild.name;
    if (document.images && (imgName != curPage)) { document[imgName].src = mouseovers[imgName+'Off'].src; }
}

// menu init
var inMenu = 0;
var curLayer = "";
var menuTimeout = null;

// mouseover image functions for menu item images
function menuItemOn(el) {
    clearTimeout(menuTimeout);
    inMenu = 1;
	imgOn(el);
	parentImage = el.offsetParent.id;
	parentImage = parentImage.replace("Menu","");
    if (document.images && (parentImage != curPage)) { document[parentImage].src = mouseovers[parentImage+'On'].src; }
}

function menuItemOff(el) {
    inMenu = 0;
	menuTimeout = setTimeout("hideMenu(curLayer)", 50);
	imgOff(el);
	parentImage = el.offsetParent.id;
	parentImage = parentImage.replace("Menu","");
    if (document.images && (parentImage != curPage)) { document[parentImage].src = mouseovers[parentImage+'Off'].src; }
}

// show menu
function showMenu(layerName,parent) {
	if (menuTimeout != null) {
		clearTimeout(menuTimeout);
		hideMenu(curLayer);
	}

	if (navigator.appName == "Netscape" && !document.getElementById) { eval('document.layers.'+layerName+'.visibility = "show"');
	} else if (document.getElementById) { eval('document.getElementById("'+layerName+'").style.visibility = "visible"');
	} else { eval('document.all["'+layerName+'"].style.visibility = "visible"'); }
	curLayer = layerName;
	imgOn(parent);
}

// hide menu
function hideMenu(layerName) {
	if (inMenu == 0) {
		if (navigator.appName == "Netscape" && !document.getElementById) { eval('document.layers.'+layerName+'.visibility = "hide"');
		} else if (document.getElementById) { eval('document.getElementById("'+layerName+'").style.visibility = "hidden"');
		} else { eval('document.all["'+layerName+'"].style.visibility = "hidden"'); }
    }
}

// mouse out timer
function setTimer(parent) {
    // time after mouse moves away from menu heading before menu is hidden
    menuTimeout = setTimeout("timeUp()",150);
	imgOff(parent);
}

// check menu status and see if we should hide the last menu
function timeUp() {
    if (inMenu == 0) {
        hideMenu(curLayer);
    }
}

function popup(src,w,h) {
	wid = w+20;
	hei = h+20;
	params = "width="+wid+",height="+hei+",status=no,toolbar=no,menubar=no,scrollbars=no,top=100,left=100,screenx=100,screey=100";
	window.open(src,"popup",params);
}

function toggleFleetClick() {
	if ($('#open1').css('display') == 'block') {
		$("img#closed").attr({src:"/images/fleetclick/closed.gif"});
		$('#open1').slideUp();
		$('#open2').slideUp();
	} else {
		$("img#closed").attr({src:"/images/fleetclick/open.gif"});
		$('#open1').slideDown();
	}
}

function menuOn(){ 
	allMenuOff();
	imgName = $(this).parent().find("img").attr("name");
	if (mouseovers[imgName+'On']) document[imgName].src = mouseovers[imgName+'On'].src;
	$(this).parent().find("div").css("display","block");
}

function menuOff(){ 
	imgName = $(this).parent().find("img").attr("name");
	if (mouseovers[imgName+'Off']) document[imgName].src = mouseovers[imgName+'Off'].src;
	$(this).parent().find("div").css("display","none");
}

function allMenuOff() {
	for (var i=0; i<mouseoversList.length; i++) {
		document[mouseoversList[i]].src = mouseovers[mouseoversList[i]+'Off'].src;
	}
}

function closeFleetForm() {
	$("#closing").slideUp();
	$("img#closed").attr({src:"/images/fleetclick/closed.gif"});
}

function submitFleetClick() {
	departmentVal = $("input:radio[name='dept']:checked").attr("id");
	productVal = $("input:radio[name='product']:checked").attr("id")
	contact_nameVal = $('#contact_name').attr("value");
	contact_phoneVal = $('#contact_phone').attr("value");
	contact_emailVal = $('#contact_email').attr("value");
	project_nameVal = $('#project_name').attr("value");
	project_addressVal = $('#project_address').attr("value");
	consulting_engineerVal = $('#consulting_engineer').attr("value");
	notesVal = $('#notes').attr("value");
	$.post("/processFleetClick.php", { 
		department: departmentVal,
		product: productVal,
		contact_name: contact_nameVal,
		contact_phone: contact_phoneVal,
		contact_email: contact_emailVal,
		project_name: project_nameVal,
		project_address: project_addressVal,
		consulting_engineer: consulting_engineerVal,
		notes: notesVal
		},function(data){}
	);
}

//function fleetClickResult(result)

function validateFleetForm() {
    var emailPat = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,5}|[0-9]{1,3})(\]?)$/;
    var phonePat = /^\+{0,1}(\d|-|\/| )*(\((\d|-|\/| )+\)){0,1}(\d|-|\/| )+/;
	var errcnt = 0;

	$('#contact_name-error').html("");
	$('#contact_email-error').html("");
	$('#contact_phone-error').html("");

	formObj = document.forms[0];

    if (formObj.contact_name.value.length < 1) {
		errcnt++;
		$('#contact_name-error').html("Please enter your name in the appropriate field.\n");
    }
    if (formObj.contact_email.value.length) {
        if (!emailPat.test(formObj.contact_email.value)) {
			errcnt++;
			$('#contact_email-error').html("Please check your email address entry to make sure it's correct.\n");
        }
    }
    var phoneDigits = formObj.contact_phone.value.replace(/[^\d]/g, '');
    if (formObj.contact_phone.value.length) {
        if (!phonePat.test(formObj.contact_phone.value) || (phoneDigits.length < 7)) {
			errcnt++;
			$('#contact_phone-error').html("Your phone number entry doesn't look like a valid phone number.\n");
        }
    }

/* the following can be blank
department
product
project_name
project_address
consulting_engineer
notes
*/

	if (errcnt > 0) {
        return false;
    }
    return true;
}
