function menuhover(){
	var menuelements=document.getElementById("menu").getElementsByTagName("LI");

	for (var i=0;i<menuelements.length;i++){
		menuelements[i].onmouseover=function(){
			this.className+=" menuhover";
		}
		menuelements[i].onmouseout=function(){
			this.className=this.className.replace(new RegExp(" menuhover\\b"), "");
		}
	}
}

if(window.attachEvent) window.attachEvent("onload",menuhover);

function MM_jumpMenu(targ,selObj,restore)
{ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function MM_goToURL() 
{ //v3.0
	var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-------------------------------------------------------------------------------------------------------
// Tab Content script
var enabletabpersistence=0 //enable tab persistence via session only cookies, so selected tab is remembered?

////NO NEED TO EDIT BELOW////////////////////////
var tabcontentIDs=new Object()

function expandcontent(linkobj)
{
	var ulid=linkobj.parentNode.parentNode.id //id of UL element
	var ullist=document.getElementById(ulid).getElementsByTagName("li") //get list of LIs corresponding to the tab contents
	for (var i=0; i<ullist.length; i++)
	{
		ullist[i].className=""  //deselect all tabs
		if (typeof tabcontentIDs[ulid][i]!="undefined") //if tab content within this array index exists (exception: More tabs than there are tab contents)
		document.getElementById(tabcontentIDs[ulid][i]).style.display="none" //hide all tab contents
	}
	linkobj.parentNode.className="selected"  //highlight currently clicked on tab
	document.getElementById(linkobj.getAttribute("rel")).style.display="block" //expand corresponding tab content
	saveselectedtabcontentid(ulid, linkobj.getAttribute("rel"))
}

function expandtab(tabcontentid, tabnumber)
{ //interface for selecting a tab (plus expand corresponding content)
	var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber]
	if (thetab.getAttribute("rel"))
		expandcontent(thetab)
}

function savetabcontentids(ulid, relattribute)
{// save ids of tab content divs
	if (typeof tabcontentIDs[ulid]=="undefined") //if this array doesn't exist yet
	tabcontentIDs[ulid]=new Array()
	tabcontentIDs[ulid][tabcontentIDs[ulid].length]=relattribute
}

function saveselectedtabcontentid(ulid, selectedtabid)
{ //set id of clicked on tab as selected tab id & enter into cookie
	if (enabletabpersistence==0) //if persistence feature turned on
	setCookie(ulid, selectedtabid)
}

function getullistlinkbyId(ulid, tabcontentid)
{ //returns a tab link based on the ID of the associated tab content
	var ullist=document.getElementById(ulid).getElementsByTagName("li")
	for (var i=0; i<ullist.length; i++)
	{
		if (ullist[i].getElementsByTagName("a")[0].getAttribute("rel")==tabcontentid)
		{
			return ullist[i].getElementsByTagName("a")[0]
			break
		}
	}
}

function initializetabcontent()
{
	for (var i=0; i<arguments.length; i++)
	{ //loop through passed UL ids
		if (enabletabpersistence==0 && getCookie(arguments[i])!="") //clean up cookie if persist=off
			setCookie(arguments[i], "")
		var clickedontab=getCookie(arguments[i]) //retrieve ID of last clicked on tab from cookie, if any
		var ulobj=document.getElementById(arguments[i])
		var ulist=ulobj.getElementsByTagName("li") //array containing the LI elements within UL
		for (var x=0; x<ulist.length; x++)
		{ //loop through each LI element
			var ulistlink=ulist[x].getElementsByTagName("a")[0]
			if (ulistlink.getAttribute("rel"))
			{
				savetabcontentids(arguments[i], ulistlink.getAttribute("rel")) //save id of each tab content as loop runs
				ulistlink.onclick=function(){
				expandcontent(this)
				return false
			}
			if (ulist[x].className=="selected" && clickedontab=="") //if a tab is set to be selected by default
				expandcontent(ulistlink) //auto load currenly selected tab content
		}
	} //end inner for loop

	if (clickedontab!="")
	{ //if a tab has been previously clicked on per the cookie value
		var culistlink=getullistlinkbyId(arguments[i], clickedontab)
		if (typeof culistlink!="undefined") //if match found between tabcontent id and rel attribute value
			expandcontent(culistlink) //auto load currenly selected tab content
		else //else if no match found between tabcontent id and rel attribute value (cookie mis-association)
			expandcontent(ulist[0].getElementsByTagName("a")[0]) //just auto load first tab instead
	}
	} //end outer for loop
}


function getCookie(Name){ 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return ""
}

function setCookie(name, value){
document.cookie = name+"="+value //cookie value is domain wide (path=/)
}
//-------------------------------------------------------------------------------------------------------
// Pages Validation 
function validate(){
	var pass = true
	if (document.lead_form.first_name.value == "") {
		alert("First Name can not be blank");
		document.lead_form.first_name.focus();
		pass = false;
	}
	if (document.lead_form.last_name && pass==true)
	{
		if(document.lead_form.last_name.value == ""  && pass==true)
		{
			alert("Last Name can not be blank");
			document.lead_form.last_name.focus();
			pass = false;
		}
	}
	if (document.lead_form.company && pass==true)
	{
		if (document.lead_form.company.value == "") {
			alert("Company Name can not be blank");
			document.lead_form.company.focus();
			pass = false;
		}
	}
	if(document.lead_form.email.value == "" && pass==true)
	{
		alert("Email can not be blank");
		document.lead_form.email.focus();
		pass = false;
	}
	else
	{
		if(EmailValidator(document.lead_form.email.value) == false && pass==true)
		{
			alert("Enter a valid Email Address");
			document.lead_form.email.focus();
			pass = false;
		}
	}
	if(document.lead_form.phone.value == "" && pass==true)
	{
		alert("Phone No. can not be blank");
		document.lead_form.phone.focus();
		pass = false;
	}
	else
	{
		if(isInteger(document.lead_form.phone.value) == false && pass==true)
		{
			alert("This is not a valid Phone No.");
			document.lead_form.phone.focus();
			pass = false;
		}
	}
	if(pass==true)
	{
		alert('Thank you for your interest in NGJ Express.');
		return true;
	}
	else
	{
		return false;
	}
	
}
function isInteger(fieldValue)
{
	var num = '0123456789.-';
	
	var i,j,found;
	found = false;
	
	for(i=0;i<fieldValue.length;i++)
	{
		for(j=0;j<num.length;j++)
		{
			if(fieldValue.charAt(i) == num.charAt(j))
			{
				found = true; break;
			}
		}
		if(found == false) {return false;}
		if(found == true) {found=false;}
	}
	
	return true;
}
function storage(frmName)
{
	
	jQuery.ajax({
		type: "POST",
		url: "/mktg/lib/sendform.php",
		data: "&frm="+ frmName + "&email=" + document.lead_form.email.value + "&last_name=" + document.lead_form.last_name.value + "&title=" + document.lead_form.title.value + "&first_name=" + document.lead_form.first_name.value + "&phone=" + document.lead_form.phone.value + "&company=" + document.lead_form.company.value ,
		success: function(){
			return 'complete';
		}
	});
}
function EmailValidator(email)
{
	var validflag=false		
	// primary condition checking
	if((email !="") && (email.indexOf("@")>0) && (email.indexOf(".")>0) )
	{
		var atcount=0
		var spflag=false
		var badflag
		for (var atloop=0 ; atloop<=email.length-1 ; ++atloop)
		{   
			atchr=email.charAt(atloop)
			// checking for special character
					   
			if (atchr=="@"){ atcount=atcount+1 }
			if  ( (atchr>=String.fromCharCode(32)) && (atchr<=String.fromCharCode(44))) { spflag=true }
			if ((atchr==String.fromCharCode(47)) || (atchr==String.fromCharCode(96)) || (atchr==String.fromCharCode(123)) )  spflag=true
			if ((atchr>=String.fromCharCode(58)) && (atchr<=String.fromCharCode(63))) spflag=true
			if ((atchr>=String.fromCharCode(91)) && (atchr<=String.fromCharCode(94))) spflag=true
		}
		if ((atcount==1) && (spflag==false))
		{
			badflag=false;
			sp=email.split('@');	 
			var username=sp[0];
			var domain=sp[1]; 
			if ((username="") || (domain=="")) badflag=true
			if (domain.charAt(0)==".") badflag=true
			if (domain.charAt(domain.len)==".") { badflag=true }
				validflag=true;
		}
	}
	
 	if (badflag==true)	validflag=false 
 	return validflag	   
}

function setLanguage(page,language)
{
	window.location.href = "http://forms.ngjensen.com/mktg/" + language + "/" + page;
}
//-------------------------------------------------------------------------------------------------------

