// common.js : Javascript functions common to all of www.pdcorp.com
// Created on 20070420 by chriss.

// ************************************************************************************************************************************

// Country Selection Menu (visitors select their country from a dropdown selection menu and are fowarded to the appropriate index)

/** Usage: Insert full pathnames from root level (i.e, '/be/index.html') as selection options.

  <div id="country_menu">
    <select class="dropbox" name="select"  onchange="myCountry(this)">
      <option selected ="selected">Select Your Country [USA]</option>
      <option value="/international.html">Afghanistan</option>
	   ....
	</select>
  </div>

**/

  function myCountry(country){
   var site = country.options[country.selectedIndex].value;
    countryJumpMenu('parent',site,0);								
  }

// ************************************************************************************************************************************

// Forward URL (used by Country Selection Menu to change index)
  function countryJumpMenu(targ,site,restore){ //v3.0
    var prefix = '';
    if (site != ''){
      eval(targ+".location='"+prefix+site+"'");
    }
  }

// ************************************************************************************************************************************

// Contact PDC (cloaks email addresses to help prevent spamming)

/** Usage: <script>javascript:contact("info","pdcorp")</script> **/

  function contact(alias,host){
    var username = alias;
    var hostname = host + ".com";
    var visible = username + "@" + hostname;
    document.write("<a href=" + "mail" + "to:" + username + "@" + hostname + ">" + visible + "</a>")
  }

// ************************************************************************************************************************************

// Toggle Layer Display On/Off (allows a link to show/hide a layer)

/** Usage: <a href="javascript:showDiv('layerName');">Sample Link</a> **/

  function showDiv(layerName){
    if (document.getElementById) {
    // this is the way the standards work
      if (document.getElementById(layerName).style.display == "none"){
	    document.getElementById(layerName).style.display = "";
	    //alert("changing to visible");
      }
      else {
	    document.getElementById(layerName).style.display = "none";
	    //alert("changing to hidden");
      }
    }
    else if (document.all) {
    // this is the way old msie versions work
      if (document.all[layerName].style.display == "none"){
        document.all[layerName].style.display = ""
      }
      else {
	    document.all[layerName].style.display = "none"  
      }
    }
    else if (document.layers) {
    // this is the way nn4 works
      if (document.layers[layerName].display == "none"){
	    document.layers[layerName].display = "visible";
      }
      else {
	    document.layers[layerName].display = "none";
	  } 
    }
  }
  
// ************************************************************************************************************************************

// Update Cart function to simplify/shorten call in page.

/* Usage: 

<form action="INSERT CURRENT URL HERE" method="post" name="cartupdate" id="cartupdate">
...
...
...
<p align="center"><a href="javascript:order();" class="cart" title="UPDATE CART">UPDATE CART</a></p>
<div style="display:none">[- crtin0pag(); -]</div>
<input type="hidden" name="CMD_updchkout" value="1"></form>

**/

function order() {
	document.cartupdate.submit();
}

// ************************************************************************************************************************************

// Rollover Functions for Color Swatches (rolling your cursor over color swatches changes the product photo on the page accordingly)

/** Usage: 

<img name="product-photo" id="product-photo" src="2008.gif" />

<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('product_photo','','4017-palm-trees-red.gif',1)">
  <img src="file://///newie/websites/Internet_v4/crowd-control/graphics/swatches/green22.gif" name="swatch1" width="26" height="26" border="0" id="swatch1" /></a>

<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('product-photo','','4017-palm-trees-green.gif',1)"> 
  <img src="file://///newie/websites/Internet_v4/crowd-control/graphics/swatches/blue13.gif" name="swatch2" width="26" height="26" border="0" id="swatch2" /></a>

**/

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// ************************************************************************************************************************************

// Clear Text Input Fields When User Clicks in Textbox
// Usage: clearText(this);

function clearText(field) {
  field.value = "";	
}

// ************************************************************************************************************************************
// Reset Initial Value of Search Field to display "Search by Keyword" to resolve empty textboxes on page reloads
// Usage: resetSearch();

function resetSearch(language) {
  if ((language == 'es-419') || (language == 'es-es')){
    document.searchform.words.value = "B\372squeda por palabra clave";
  }
  if ((language == 'fr-be') || (language == 'fr-fr')){
	document.searchform.words.value = "Recherche par mot-cl\351";
  }
  if (language == 'it-it'){
    document.searchform.words.value = "Ricerca per parola chiave";
  }
  if (language == 'nl-nl'){
    document.searchform.words.value = "Zoek op woord";
  } 
  if ((language == 'en-001') || (language == 'en-gb') || (language == 'en-us')){
    document.searchform.words.value = "Search by keyword";
  }
  if (language == 'de-de'){
    document.searchform.words.value = "Schlagwort-Suche";
  }
}

// ************************************************************************************************************************************
// 50th Anniversary Slideshow
// Usage: <a href="javascript:slideshow('1');">Photo Link Goes Here</a>

function slideshow(position){
  myPos = "../../en-us/company/50th-anniversary-photos.html?myPos=" + position;
  slideWindow = window.open(myPos, 'slideWin', 'width= 640,height=500,scrollbars=yes');
  slideWindow.focus();
}

// ************************************************************************************************************************************
// Online Press Kit Flyers (open PDF flyers in a new window)
// Usage: <a href="javascript:flyer('../../downloads/SB_IraqFlyer.pdf');">Link Goes Here</a>

function flyer(myFile){
  flyerWindow = window.open(myFile,'flyerWin', 'width=600,height=600,scrollbars=yes,location=yes,toolbars=yes,resizable=yes');
  flyerWindow.focus();
}

// ************************************************************************************************************************************
// Keep Track of Layers for Videos.html
// Usage: <a href="javascript:setLast(one);setCategory(sbvideo)">Link Goes Here</a>

var lastField = '';
var lastCategory = '';

function setLast(lastDiv){
// Hides the previously clicked layer, saves and displays the new layer.

  if (lastField != ""){
  // Hide the previously clicked layer, unlesss a layer hasn't been clicked.
    showDiv(lastField);
  }
  
  else {
  // Hide the initial layer on the first clicked layer.
    showDiv(one);
  }
  window.lastField = lastDiv;  // set the variable
  showDiv(lastField);  // show the new layer
}
			
function setCategory(lastCat){
// Same logic as setLast() function above.
  if (lastCategory != ""){
    showDiv(lastCategory);
  }
  window.lastCategory = lastCat;
  showDiv(lastCategory);
}

// ************************************************************************************************************************************
// Jump Menu for partners.html
// Usage: see partners.html for details.
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// ************************************************************************************************************************************
// setReply for Contact PDC, Surveys, etc.  Sets the 'replyto' field to the customer's email address.
// Usage: add 'onchange="setReply(this)"' to Email fields.
function setReply(what){
    document.myForm.replyto.value = what.value;
    //alert(what.value);
  }
  
// ************************************************************************************************************************************
// serialValidation to validate Serial Number input fields
// Usage: add 'onChange="serialValidation(this,this.value)" onClick="resetSerial(this)"' to Serial Number fields.  
function serialValidation(what,string) {
  //alert("in function");
  what.style.backgroundColor='#FFFFFF';
  var Chars = "0123456789";
  var error = 0;
  for (var i = 0; i < string.length; i++) {
    if (Chars.indexOf(string.charAt(i)) == -1){
  	  error++;
    }
	
  }
  if (error != '0'){
	serialAlert(what);
	alert("ERROR! Only numeric characters (no commas) can be used for Serial Numbering.");
	what.focus();
  }
}

function serialAlert(what) {
  what.value = 'ERROR!';
  what.style.backgroundColor='#FFFF00';
}

function resetSerial(what) {
  if(what.value == 'ERROR!'){
    what.value = '';
  }
  what.style.backgroundColor='#FFFFFF';
}