/* Browser check */

IS_DOM = (document.getElementById) ? true : false;

IS_IE = (document.all) ? true : false;

IS_IE50 = (navigator.userAgent.indexOf("IE 5.0") != -1);

IS_Mac = (navigator.appVersion.indexOf("Mac") != -1);



// preload rollovers

var aNavigation = new Array();

//aNavigation = ["", "industries", "products", "services", "partners", "news", "company"];
aNavigation = ["", "company", "partners", "contact", "news", "support", "industries", "solution"];

for (i = 0; i <= 7; i++) { 

	eval("menu"+i+"on = new Image();"); eval("menu"+i+"off = new Image();");

	if (sSelectedButton == aNavigation[i]) {

		eval("menu"+(i)+"on.src = \"" + "" + "/img/buttons/l1-" + aNavigation[i] + "-r.gif\";");

		eval("menu"+(i)+"off.src = \"" + "" + "/img/buttons/l1-" + aNavigation[i] + "-r.gif\";");

	} else {

		eval("menu"+(i)+"on.src = \"" + "" + "/img/buttons/l1-" + aNavigation[i] + "-r.gif\";");

		eval("menu"+(i)+"off.src = \"" + "" + "/img/buttons/l1-" + aNavigation[i] + "-0.gif\";");

	}

}



// preload rollovers

var aNavigation = new Array();

aNavigation = ["", "home", "careers", "ir", "contact", "site-map", "reseller-login"];

for (i = 0; i <= 6; i++) { 

	eval("C"+i+"on = new Image();"); eval("C"+i+"off = new Image();");

	if (sSelectedButton == aNavigation[i]) {

		eval("C"+(i)+"on.src = \"" + "" + "/img/buttons/cnst-" + aNavigation[i] + "-r.gif\";");

		eval("C"+(i)+"off.src = \"" + "" + "/img/buttons/cnst-" + aNavigation[i] + "-r.gif\";");

	} else {

		eval("C"+(i)+"on.src = \"" + "" + "/img/buttons/cnst-" + aNavigation[i] + "-r.gif\";");

		eval("C"+(i)+"off.src = \"" + "" + "/img/buttons/cnst-" + aNavigation[i] + "-0.gif\";");

	}

}



// General Site Functions

function imgOn(imgName) {

  if (IS_DOM) {

    document.getElementById(imgName).src = eval(imgName + "on.src");

  }

}

 

function imgOff(imgName) {

  if (IS_DOM) {

    document.getElementById(imgName).src = eval(imgName + "off.src");

  }

}



// image swapper

function changeImages() 

{

  if (document.getElementById) {

    for (var i = 0; i < changeImages.arguments.length; i += 2) { 

  		document.getElementById(changeImages.arguments[i]).src = eval(changeImages.arguments[i + 1] + ".src"); 

	}

  }

}



// FUNCTIONS TO CONTROL FAUX FORM ELEMENTS



// show or hide dropdown element based on current display state

function controlDropdown(oDropdown)

{

	if (IS_DOM) {

		if (oDropdown.style.overflow == "visible") {

			oDropdown.style.overflow = "hidden";

		} else {

			oDropdown.style.overflow = "visible";

		}

	}

}



// assign new value to form's element

function updateForm(sFormName, sInputName, sNewValue, oListElement)

{

	oList = oListElement.parentNode;

	oDiv = oList.parentNode;

	// show dropdown list

	controlDropdown(oDiv);

	

	// get form in question, find input requested and update its value

	oForm = document.forms[sFormName];

	oElement = oForm.elements[sInputName];

	oElement.value = sNewValue;

	

	// move selected element to top of list

	oList.insertBefore(oListElement, oList.firstChild); 

	// apply class to position new top item correctly

	oListElement.className = "firstItem";

	

	

	// display second drop down menu

	if (sInputName == "choice1") {

		var aMenus = document.getElementById("dropEnvelope").getElementsByTagName("div");

		for (var i = 0; i < aMenus.length; i++) {

			aMenus[i].style.visibility = "hidden";

		}

		if (sNewValue != '') {

			document.getElementById(sNewValue).style.visibility = "visible";

		}

	}

	

	//define target url

	if (oForm.choice1.value == "A") {

		oForm.action = "";

	} else if (oForm.choice1.value == "B") {

		oForm.action = "";

	} else if (oForm.choice1.value == "C") {

		oForm.action = "";

	} else if (oForm.choice1.value == "D") {

		oForm.action = "";

	} else if (oForm.choice1.value == "E") {

		oForm.action = "";

	} else {

		oForm.action = "";

	}

	

	if (sInputName == "lookingFor") {		

		// oForm.action += "#" + sNewValue;
		oForm.action += "" + sNewValue;

	}

}



function submitResource(formObject,businessInterest,urlSuffix)

{

//	http://localhost:9080/efundscomnew/products-services/index.htm



//	var urlPrefix = document.URL.substring(0,(document.URL.indexOf("us/en")));



	var urlPrefix = document.URL;

	var endIndex;

	

	for(i = 0;i < 3;i++){

		endIndex = urlPrefix.indexOf('/',endIndex + 1);

	}



	//urlPrefix = urlPrefix.substring(0,endIndex+1);

	urlPrefix = urlPrefix.substring(0,endIndex+1) + "efundscomnew/";

	

	formObject.businessInterest.value=businessInterest;

	formObject.action =urlPrefix+urlSuffix;

	formObject.submit();

}



//Information Request Form Required Field Check

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function validRequired(formField,fieldLabel)
{
	var result = true;
	
	if (formField.value == "")
	{
		alert('Please enter a value for the "' + fieldLabel +'" field.');
		formField.focus();
		result = false;
	}
	
	return result;
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	
	return result;
}

function validEmail(formField,fieldLabel,required)
{
	var result = true;
	
	if (required && !validRequired(formField,fieldLabel))
		result = false;

	if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
	{
		alert("Please enter a complete email address in the form: yourname@yourdomain.com");
		formField.focus();
		result = false;
	}
   
  return result;

}

function validNum(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		if (!allDigits(formField.value))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validInt(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var num = parseInt(formField.value,10);
 		if (isNaN(num))
 		{
 			alert('Please enter a number for the "' + fieldLabel +'" field.');
			formField.focus();		
			result = false;
		}
	} 
	
	return result;
}


function validDate(formField,fieldLabel,required)
{
	var result = true;

	if (required && !validRequired(formField,fieldLabel))
		result = false;
  
 	if (result)
 	{
 		var elems = formField.value.split("/");
 		
 		result = (elems.length == 3); // should be three components
 		
 		if (result)
 		{
 			var month = parseInt(elems[0],10);
  			var day = parseInt(elems[1],10);
 			var year = parseInt(elems[2],10);
			result = allDigits(elems[0]) && (month > 0) && (month < 13) &&
					 allDigits(elems[1]) && (day > 0) && (day < 32) &&
					 allDigits(elems[2]) && ((elems[2].length == 2) || (elems[2].length == 4));
 		}
 		
  		if (!result)
 		{
 			alert('Please enter a date in the format MM/DD/YYYY for the "' + fieldLabel +'" field.');
			formField.focus();		
		}
	} 
	
	return result;
}


//POP-UP WIndows
function popup(URL,h,w) {
	info = "width=" + w + ",height=" + h + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=no,top=0,left=0";
	win = window.open(URL, 'New', info);
	win.focus();
}

//POP-UP WIndows 2
function popup2(URL,h,w) {
	info = "width=" + w + ",height=" + h + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,top=0,left=0";
	win = window.open(URL, 'New', info);
	win.focus();
}

//Images Pop-up Window
<!-- ;
var newwindow = ''
function popitup(url) {
if (newwindow.location && !newwindow.closed) {
    newwindow.location.href = url; 
    newwindow.focus(); } 
else { 
    newwindow=window.open(url,'htmlname','width=800,height=600,resizable=0');} 
}


function tidy() {
if (newwindow.location && !newwindow.closed) { 
   newwindow.close(); } 
}
