// Common Script File

// ###### Form Field Validation start #####

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0

	var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;


	for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
	  } else if (test!='R') { num = parseFloat(val);
		if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
	} if (errors) alert('The following error(s) occurred:\n'+errors);
	document.MM_returnValue = (errors == '');
	}

// ###### Form Field Validation end #####

// ###### Pop-up code start #####

var ghWindow;  //-- Global window handle for pop-ups ----
var gsBrowserName = navigator.appName;
var giBrowserVersion = parseInt(navigator.appVersion);

function openWindow(sURL, winName, winWidth, winHeight, sArguments) {
   if ( !sArguments ) {
      sArguments = "scrollbars=1,toolbar=0,resizable=1,location=0,status=1,menubar=1";
   }

   if ( gsBrowserName == "Netscape" && giBrowserVersion > 2) {
      if ( ghWindow ) {
         if ( ghWindow.document ) {
            ghWindow.close();
         }
      }
   } else {
      if ( gsBrowserName == "Microsoft Internet Explorer" && giBrowserVersion > 2) {
         if ( ghWindow ) {
            ghWindow.close();
         }
      }
   }
//   ghWindow = window.open(sURL, winName, "width=" + (winWidth + 30) + ",height=" + (winHeight + 30) + "," + sArguments)
   ghWindow = window.open(sURL, winName, "width=" + winWidth + ",height=" + winHeight + "," + sArguments)

   return true;
}

// ###### Pop-up code end #####

// ###### Form hide/show form elements code start #####

function turnelementon(nr)
{
	if (document.layers)
	{
		document.layers[nr].display = 'block';
	}
	else if (document.all)
	{
		document.all[nr].style.display = 'block';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.display = 'block';
	}
}

function turnelementoff(nr)
{
	if (document.layers)
	{
		document.layers[nr].display = 'none';
	}
	else if (document.all)
	{
		document.all[nr].style.display = 'none';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.display = 'none';
	}
}

// ###### Form hide/show form elements code end #####

// ###### Form hide/show form field code start #####

function turnfieldon(nr)
{
	if (document.layers)
	{
		document.layers[nr].visibility = 'visible';
	}
	else if (document.all)
	{
		document.all[nr].style.visibility = 'visible';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.visibility = 'visible';

	}
}

function turnfieldoff(nr)
{
	if (document.layers)
	{
		document.layers[nr].visibility = 'hidden';
	}
	else if (document.all)
	{
		document.all[nr].style.visibility = 'hidden';
	}
	else if (document.getElementById)
	{
		document.getElementById(nr).style.visibility = 'hidden';

	}
}
// ###### Form hide/show form field code end #####


// ###### CDN SITEPREF HOVER mouseover code start #####

function changeCDNSitePrefImage () {
   document.images.myImage.src="/graphages/cdn_active_over.gif";
   }

function changeCDNSitePrefBack () {
   document.images.myImage.src="/graphages/cdn_active.gif";
   }

// ###### CDN SITEPREF HOVER mouseover code end #####

// ###### US SITEPREF HOVER mouseover code start #####

function changeUSASitePrefImage () {
   document.images.myImage.src="/graphages/usa_active_over.gif";
   }

function changeUSASitePrefBack () {
   document.images.myImage.src="/graphages/usa_active.gif";
   }

// ###### US SITEPREF HOVER mouseover code end #####

// ###### HOME PAGE homepg_login.gif mouseover code start #####

function changeLoginImage () {
   document.images.loginImage.src="/graphages/homepg_login_over.gif";
   }

function changeLoginBack () {
   document.images.loginImage.src="/graphages/homepg_login.gif";
   }

// ###### HOME PAGE homepg_login.gif mouseover code end #####


// ###### SUPPORT newuser.gif mouseover code start #####

function changeImage () {
   document.images.mySupportImage.src="/graphages/boxoutlines/doubleblue/newuser_over.gif";
   }

function changeBack () {
   document.images.mySupportImage.src="/graphages/boxoutlines/doubleblue/newuser.gif";
   }

// ###### SUPPORT newuser.gif mouseover code end #####

// ###### TRAINING trainingcenterlogin.gif mouseover code start #####

function changeThisImage () {
   document.images.myImage.src="/graphages/trainingcenterlogin_over.gif";
   }

function changeThisBack () {
   document.images.myImage.src="/graphages/trainingcenterlogin.gif";
   }

// ###### TRAINING trainingcenterlogin.gif mouseover code end #####

// ###### TRAINING CENTER regfortrainingcenter.gif mouseover code start #####

function changeRegTCThisImage () {
   document.images.myTrainingImage.src="/graphages/regfortrainingcenter_over.gif";
   }

function changeRegTCThisBack () {
   document.images.myTrainingImage.src="/graphages/regfortrainingcenter.gif";
   }

// ###### TRAINING CENTER regfortrainingcenter.gif mouseover code end #####

// ###### SUPPORT User Help product selection dropdown code start #####

function goThere(){
window.location=document.productForm.productSelect.options[document.productForm.productSelect.selectedIndex].value
}

// ###### SUPPORT User Help product selection dropdown code end #####

// ###### SUPPORT Technical Help product selection dropdown code start #####

function goThereTech(){
window.location=document.productTechForm.productTechSelect.options[document.productTechForm.productTechSelect.selectedIndex].value
}

// ###### SUPPORT Technical Help product selection dropdown code end #####




// ###### CDN PRODUCTS Online Forms -- Hide or Show County Field if California Start #####

function cdnmakecountyfieldvisible(frmnm) {

    if (document.forms[frmnm].Province.options[document.forms[frmnm].Province.selectedIndex].value == "California"){
    document.getElementById("CountyDiv").style.display = "block";  // if CA then diaply County field
    } else {
    document.getElementById("CountyDiv").style.display = "none";   // do not diplay field
    document.forms[frmnm].County.selectedIndex = 0;   // set County field back to no value
    }
}

// ###### CDN PRODUCTS Online Forms -- Hide or Show County Field if California End #####



// ###### US PRODUCTS Online Forms -- Hide or Show County Field if California Start #####

function makecountyfieldvisible(frmnm) {

    if (document.forms[frmnm].State.options[document.forms[frmnm].State.selectedIndex].value == "California"){
    document.getElementById("CountyDiv").style.display = "block";   // if CA then diaply County field
    } else {
    document.getElementById("CountyDiv").style.display = "none";   // do not diplay field
    document.forms[frmnm].County.selectedIndex = 0;   // set County field back to no value
    }
}

function makecountyfieldvisible2(frmnm) {

    if (document.forms[frmnm].State.options[document.forms[frmnm].State.selectedIndex].value == "Florida"){
    document.getElementById("CountyDiv2").style.display = "block";   // if FL then display County field
    } else {
    document.getElementById("CountyDiv2").style.display = "none";   // do not diplay field
    document.forms[frmnm].County.selectedIndex = 0;   // set County field back to no value
    }
}

// ###### US PRODUCTS Online Forms -- Hide or Show County Field if California End #####



// ##### Set Region Preference Cookie Functions and Variables #### 
// ##### Created November 29, 2004 by Richard Kooistra #### 
// ##### Edited November 30, 2004 by Richard Kooistra -- Added "French" as an option #### 

var today = new Date();
var expires = new Date(today.getTime() + (56 * 86400000));

function getCookie(NameOfCookie) {
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
} // END getCookie


function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
} // END setCookie


function delCookie (NameOfCookie) {
	if (getCookie(NameOfCookie)) {
	document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
} // END delCookie


// ######################################################
// ##### Called from usa's home.html to set US English
// ##### as region (site) preference 
// ######################################################
function changelangprefcookietoEnglish_USA () {
	var langpref;
	if (getCookie('langpref'))	{
		setCookie('langpref', 'English_USA', 1000);
	}
} // END changelangprefcookietoEnglish_USA


// ######################################################
// ##### Called from cdn's home.html to set Canadian 
// ##### English as region (site) preference 
// ######################################################
function changelangprefcookietoEnglish_Canadian () {
	var langpref;
	if (getCookie('langpref'))	{
		setCookie('langpref', 'English_Canadian', 1000);
	}
} // END changelangprefcookietoEnglish_Canadian


// ######################################################
// ##### Called from french's home.html  to set Canadian
// ##### French as region (site) preference 
// ######################################################
function changelangprefcookietoFrench_Canadian () {
	var langpref;
	if (getCookie('langpref'))	{
		setCookie('langpref', 'French_Canadian', 1000);
	}
} // END changelangprefcookietoFrench_Canadian


// ######################################################
// ##### Called from home.html to determine if cookie
// ##### exists and then redirect browser appropriately.
// ##### OR if 1st visit, then set USA as default, until
// ##### set/changed by user themselves using site nav.
// ######################################################
function checklangprefcookie () {
	var langpref;
	var value;
	if (getCookie('langpref')) {
		value = getCookie('langpref');
		if (value=='English_Canadian') {
			location.href='/cdn/home.html';
		}
		if (value=='French_Canadian') {
			location.href='/fr/home.html';
		}
		if (value=='English_USA') {
			location.href='/us/home.html';
		}
	} else {
	setCookie('langpref', 'English_USA', 1000);
	location.href='http://www.bridges.com/us/home.html';
	}
} // END checklangprefcookie


