// JavaScript Document

function showSubmenu(ID){
	$("#submenu"+ID).stop(true, true).fadeIn(50);
	$("#submenu"+ID).unbind('mouseover');
	$("#submenu"+ID).unbind('mouseout');
	$("#submenu"+ID).mouseover(function(){ showSubmenu(ID); }); //Submenu On
	$("#submenu"+ID).mouseout( function(){ hideSubmenu(ID); }); //Submenu Out
	if(ID == 1){
		$('#m2').css('backgroundPosition','-3px -57px'); //flip
		$('#m3').css('backgroundPosition','-133px -18px');
		$('#m4').css('backgroundPosition','-265px -18px');
		$('#m6').css('backgroundPosition','-551px -18px');
		$('#m7').css('backgroundPosition','-688px -18px');
	} else if(ID == 2){
		$('#m2').css('backgroundPosition','-3px -18px');
		$('#m3').css('backgroundPosition','-133px -57px'); //flip
		$('#m4').css('backgroundPosition','-265px -18px');
		$('#m6').css('backgroundPosition','-551px -18px');
		$('#m7').css('backgroundPosition','-688px -18px');	
	} else if(ID == 3){
		$('#m2').css('backgroundPosition','-3px -18px');
		$('#m3').css('backgroundPosition','-133px -18px');
		$('#m4').css('backgroundPosition','-265px -57px'); //flip
		$('#m6').css('backgroundPosition','-551px -18px');
		$('#m7').css('backgroundPosition','-688px -18px');	
	} else if(ID == 4){
		$('#m2').css('backgroundPosition','-3px -18px');
		$('#m3').css('backgroundPosition','-133px -18px');
		$('#m4').css('backgroundPosition','-265px -18px');
		$('#m6').css('backgroundPosition','-551px -57px'); //flip
		$('#m7').css('backgroundPosition','-688px -18px');
	} else if(ID == 5){
		$('#m2').css('backgroundPosition','-3px -18px');
		$('#m3').css('backgroundPosition','-133px -18px');
		$('#m4').css('backgroundPosition','-265px -18px');
		$('#m6').css('backgroundPosition','-551px -18px');
		$('#m7').css('backgroundPosition','-688px -57px'); //flip
	}
}
function hideSubmenu(ID){
	$("#submenu"+ID).stop(true, true).delay(200).fadeOut();
	if(ID == 1){
		$('#m2').css('backgroundPosition','-3px -18px'); //flip
	} else if(ID == 2){
		$('#m3').css('backgroundPosition','-133px -18px'); //flip
	} else if(ID == 3){
		$('#m4').css('backgroundPosition','-265px -18px'); //flip
	} else if(ID == 4){
		$('#m6').css('backgroundPosition','-551px -18px'); //flip
	} else if(ID == 5){
		$('#m7').css('backgroundPosition','-688px -18px'); //flip
	}
}

function swapSubContent(ID, PRODUCTID){
	$(".subtext"+ID).html($("#prodtext_"+PRODUCTID).html());
	$(".subimage"+ID).html($("#prodimg_"+PRODUCTID).html());
}
function swapIndustryContent(ID, PRODUCTID){
	$("#subtext"+ID) .html($("#ind_text_"+PRODUCTID).html());
	$("#subimage"+ID).html($("#ind_img_"+PRODUCTID).html());
}
/*
function loadSubmenu(DIR){
	$('#submenu').stop(true, true).load('/ajax_submenus.php?directory='+DIR).fadeIn(200);
    $('#submenu').unbind('mouseover');
    $('#submenu').mouseover(function(){ $(this).stop(true, true).show(); })
}
*/
function spritesStandard(){
	$('#m1').css('backgroundPosition','0px -18px');
	$('#m2').css('backgroundPosition','-3px -18px');
	$('#m3').css('backgroundPosition','-133px -18px');
	$('#m4').css('backgroundPosition','-265px -18px');
	$('#m5').css('backgroundPosition','-411px 0px');
	$('#m6').css('backgroundPosition','-551px -18px');
	$('#m7').css('backgroundPosition','-688px -18px');
	$('#m8').css('backgroundPosition','-818px -18px');
	$('#m9').css('backgroundPosition','-881px -18px');
	$('#m10').css('backgroundPosition','-922px -18px');	
}

//Add to form: onSubmit="validateRequestInfo();return(false);"
function validateRequestInfo(){
	var starter = document.ri;
	if (starter.name.value == ''){
		alert("Please enter your contact name.");
		starter.name.focus();
		return 0;
	}
	if (starter.email.value == ''){
		alert("Please enter your email address.");
		starter.email.focus();
		return 0;
	} else {
		var str = starter.email.value;
	    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	    if (!str.match(re)) {
	        alert("Your email address is invalid. Please verify that you have entered it correctly.");
			starter.email.focus();
			return 0;
	    }
	}
	if (starter.address1.value == ''){
		alert("Please enter your address.");
		starter.address1.focus();
		return 0;
	}
	if (starter.city.value == ''){
		alert("Please enter your city.");
		starter.city.focus();
		return 0;
	}
	if (starter.state.value == ''){
		alert("Please enter your state.");
		starter.state.focus();
		return 0;
	}
	if (starter.zip.value == ''){
		alert("Please enter your zip code.");
		starter.zip.focus();
		return 0;
	}
	if (starter.country.value == ''){
		alert("Please enter your country.");
		starter.country.focus();
		return 0;
	}
	if (starter.phone.value == ''){
		alert("Please enter your phone number.");
		starter.phone.focus();
		return 0;
	}
starter.submit();
}

//Add to form: onSubmit="validateInquiry();return(false);"
function validateWarranty(){
	var starter = document.warranty;
	if (starter.name.value == ''){
		alert("Please enter your contact name.");
		starter.name.focus();
		return 0;
	}
	if (starter.company.value == ''){
		alert("Please enter your company's name.");
		starter.company.focus();
		return 0;
	}
	if (starter.address.value == ''){
		alert("Please enter your street address.");
		starter.address.focus();
		return 0;
	}
	if (starter.city.value == ''){
		alert("Please enter your city.");
		starter.city.focus();
		return 0;
	}
	if (starter.state.value == ''){
		alert("Please enter your state.");
		starter.state.focus();
		return 0;
	}
	if (starter.zip.value == ''){
		alert("Please enter your zip code.");
		starter.zip.focus();
		return 0;
	}
	if (starter.email.value == ''){
		alert("Please enter your email address.");
		starter.email.focus();
		return 0;
	} else {
		var str = starter.email.value;
	    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	    if (!str.match(re)) {
	        alert(str);
			alert("Your email address is invalid. Please verify that you have entered it correctly.");
			starter.email.focus();
			return 0;
	    }
	}
	if (starter.phone.value == ''){
		alert("Please enter your preferred phone number.");
		starter.phone.focus();
		return 0;
	}
	starter.submit();
}

//Add to form: onSubmit="validateInquiry();return(false);"
function validateInquiry(){
	var starter = document.inquiry;
	if (starter.name.value == ''){
		alert("Please enter your name.");
		starter.name.focus();
		return 0;
	}
	if (starter.email.value == ''){
		alert("Please enter your email address.");
		starter.email.focus();
		return 0;
	} else {
		var str = starter.email.value;
	    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	    if (!str.match(re)) {
	        alert("Your email address is invalid. Please verify that you have entered it correctly.");
			starter.email.focus();
			return 0;
	    }
	}
	if (starter.address.value == ''){
		alert("Please enter your street address.");
		starter.address.focus();
		return 0;
	}
	if (starter.city.value == ''){
		alert("Please enter your city.");
		starter.city.focus();
		return 0;
	}
	if (starter.state.value == ''){
		alert("Please enter your state.");
		starter.state.focus();
		return 0;
	}
	if (starter.zip.value == ''){
		alert("Please enter your zip code.");
		starter.zip.focus();
		return 0;
	}
	if (starter.phone.value == ''){
		alert("Please enter your phone number.");
		starter.phone.focus();
		return 0;
	}
	if (starter.comments.value == ''){
		alert("Please enter a detailed inquiry before submitting.");
		starter.comments.focus();
		return 0;
	}
	starter.submit();
}

//Add to form: onSubmit="validateNewsletter();return(false);"
function validateNewsletter(){
	var starter = document.newsletter;
	if (starter.name.value == ''){
		alert("Please enter your name.");
		starter.name.focus();
		return 0;
	}
	if (starter.company.value == ''){
		alert("Please enter your company name.");
		starter.company.focus();
		return 0;
	}
	if (starter.email.value == ''){
		alert("Please enter your email address.");
		starter.email.focus();
		return 0;
	} else {
		var str = starter.email.value;
	    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	    if (!str.match(re)) {
	        alert("Your email address is invalid. Please verify that you have entered it correctly.");
			starter.email.focus();
			return 0;
	    }
	}
	if (starter.address.value == ''){
		alert("Please enter your street address.");
		starter.address.focus();
		return 0;
	}
	if (starter.city.value == ''){
		alert("Please enter your city.");
		starter.city.focus();
		return 0;
	}
	if (starter.state.value == ''){
		alert("Please enter your state.");
		starter.state.focus();
		return 0;
	}
	if (starter.zip.value == ''){
		alert("Please enter your zip code.");
		starter.zip.focus();
		return 0;
	}
	if (starter.country.value == ''){
		alert("Please enter a country name before submitting.");
		starter.country.focus();
		return 0;
	}
	if (starter.phone.value == ''){
		alert("Please enter your phone number.");
		starter.phone.focus();
		return 0;
	}
	
	starter.submit();
}



$(document).ready(function() { // onload
	
	//Set up Sprites
	//spritesStandard();
	
	//Make some rollovers
	$('#m2').mouseover(function(){ $(this).css('backgroundPosition','-3px -57px');   showSubmenu(1); }); //Dump Bodies
	$('#m2').mouseout(function(){  $(this).css('backgroundPosition','-3px -18px');   hideSubmenu(1); });
	$('#m3').mouseover(function(){ $(this).css('backgroundPosition','-133px -57px');  showSubmenu(2); }); //Dump Trailers
	$('#m3').mouseout(function(){  $(this).css('backgroundPosition','-133px -18px');  hideSubmenu(2); });
	$('#m4').mouseover(function(){ $(this).css('backgroundPosition','-265px -57px');  showSubmenu(3); }); //Transfer Trailers
	$('#m4').mouseout(function(){  $(this).css('backgroundPosition','-265px -18px');  hideSubmenu(3); });
	$('#m5').mouseover(function(){ $(this).css('backgroundPosition','-411px -124px'); });                 //In-Stock Inventory
	$('#m5').mouseout(function(){  $(this).css('backgroundPosition','-411px 0px');    });
	$('#m6').mouseover(function(){ $(this).css('backgroundPosition','-551px -57px');  showSubmenu(4);});  //Oil and Gas Equipment
	$('#m6').mouseout(function(){  $(this).css('backgroundPosition','-551px -18px');  hideSubmenu(4);});
	$('#m7').mouseover(function(){ $(this).css('backgroundPosition','-688px -57px');  showSubmenu(5);});  //Tankers
	$('#m7').mouseout(function(){  $(this).css('backgroundPosition','-688px -18px');  hideSubmenu(5);});
	$('#m8').mouseover(function(){ $(this).css('backgroundPosition','-818px -57px'); });                  //News
	$('#m8').mouseout(function(){  $(this).css('backgroundPosition','-818px -18px'); });
	$('#m9').mouseover(function(){ $(this).css('backgroundPosition','-881px -57px'); });                  //Facebook
	$('#m9').mouseout(function(){  $(this).css('backgroundPosition','-881px -18px'); });
	$('#m10').mouseover(function(){$(this).css('backgroundPosition','-922px -57px'); });                  //Twitter
	$('#m10').mouseout(function(){ $(this).css('backgroundPosition','-922px -18px'); });
	
	//$("#submenu1").hide();
	//$("#submenu2").hide();
	//$("#submenu3").hide();
	//$("#submenu4").hide();
	//$("#submenu5").hide();

});
