/************************************************
* Function: onEnter
*
* Date: 2007
*
* Description: 
* ------------
*
* This function is used for the top
* search bar and will post the current value of
* the text box to a search-results page.
*
************************************************/

function onEnter( evt, frm ) {
    var keyCode = null;

    if( evt.which ) 
    {
        keyCode = evt.which;
    }
    else if( evt.keyCode ) 
     {
        keyCode = evt.keyCode;
    }
    if( 13 == keyCode )
    {
        //Submitted Search
        location.href='/search-results.aspx?query=' + document.aspnetForm.s.value;
        return false;
    }
    
}

/************************************************
* Function: MM_CheckFlashVersion
*
* Date: 2007
*
* Description: 
* ------------
*
* Built in macromedia dreamweaver flash checker.
* This function is used for the banner.
************************************************/

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

/************************************************
* Function: MM_preloadImages, MM_swapImgRestore,
*           MM_findObj, MM_swapImage
*
* Date: 2007
*
* Description: 
* ------------
*
* Built in macromedia dreamweaver function to handle
* mouse rollovers, preloading of images, etc.
************************************************/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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];}
}


/************************************************
* Function: createCookie
*
* Date: 2007
*
* Description: 
* 
* Function creates a none expiring cookie for 
* keeping the users font size. (eg. M, L, XL)
************************************************/

function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/******************************************************************************************
    F O N T   R E - S I Z I N G  F U N C T I O N S
******************************************************************************************/

/************************************************
* Function: readCookie
*
* Date: 2007
*
* Description: 
* ------------
*
* Reads a javascript cookies value.  This functionality
* is used for the users font size. (eg. M, L, XL)
************************************************/

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/************************************************
* Function: eraseCookie
*
* Date: 2007
*
* Description: 
* ------------
*
* Erases the users cookie based on the cookies name
*
************************************************/

function eraseCookie(name){
	createCookie(name,"",-1);
}

/************************************************
* Function: changetext
*
* Date: 2007
*
* Description: 
* ------------
*
* This function reads a cookie value, then makes the 
* appropriate changes in order to allow for font size 
* to be increased or decreased. If no cookie is found 
* the function will create a newcookie for the user.
************************************************/

function changetext(id)
{
    //Read the Javascript Textsize Cookie
	var checkcookie = readCookie('selkirktextsize');

    //If the Cookie Exists	
	if (checkcookie)
	{
		if (id !== checkcookie)
		{
			createCookie('selkirktextsize', id, 10);
			id = readCookie('selkirktextsize');
			//alert("cookie created - updated");
		}
		else
		{
			//alert("cookie already existed - no need to update");
		}
	}
	//If the cookie does NOT exist
	else	
	{
	    //Create the cookie
		createCookie('selkirktextsize', id, 10);
		//alert("cookie created - didnt exist");
	}

    //Parse through the entire DOM (document object model) searching for a specific
    //class name    
	elements = document.getElementsByTagName("*"); 

    //Start While Loop to search through elements for class of 'content'	
	for (var i=0; i < elements.length; i++)
	{ 
		if (elements[i].className == 'content-medium' || elements[i].className == 'content-large' || elements[i].className == 'content-extra-large')
		{
		    //Set content to new font size;
            elements[i].className = id;         
		}		
	} 
}


/************************************************
* Function: changetext
*
* Date: 2007
*
* Description: 
* ------------
*
* This function reads a cookie value, then makes the 
* appropriate changes in order to allow for font size 
* to be increased or decreased. If no cookie is found 
* the function will create a newcookie for the user.
************************************************/

currentfontsize = readCookie('selkirktextsize');

if (!currentfontsize)
{   
        currentfontsize = "content-medium"; 
}
else
{
    //Clears old cookie Values with default new value
    if (currentfontsize == 'text-black-content-11px' || 'text-black-content-12px' || 'text-black-content-14px')
    {
        createCookie('selkirktextsize', 'content-medium', 10);
        id = readCookie('selkirktextsize');
    }
}


/******************************************************************************************
    C O L U M N   H I E G T   M A T C H I N G  F U N C T I O N S
******************************************************************************************/

/************************************************
* Date: 2007
*
* Description: 
* ------------
*
* This javascript is executed on .JS file load 
* and will set the users current to the default
* size of 'content-medium'.
************************************************/


matchHeight=function(){ 
  
     var divs, contDivs, maxHeight, divHeight, d; 

     divs=document.getElementsByTagName('div');     // get all <div> elements in the document 

     contDivs=[]; 

     maxHeight=0;   // initialize maximum height value 
    
    // iterate over all <div> elements in the document 
     for (var i=0; i < divs.length; i++)
     { 
          // make collection with <div> elements with class attribute 'matchcolumn' 
          if(/\bmatchcolumn\b/.test(divs[i].className)){ 

                d = divs[i];

                contDivs[contDivs.length]=d; 

                if (d.offsetHeight) // determine height for <div> element 
                { 
                     divHeight=d.offsetHeight; 
                } 

                else if(d.style.pixelHeight)
                { 
                     divHeight=d.style.pixelHeight; 
                } 

                // calculate maximum height 
                maxHeight=Math.max(maxHeight,divHeight); 
          } 
     } 
     
     /* ====================================
        New Addition
        ------------
        
        Added: August 7th, 2007
        Description:
            Basically this just checks that if the columns
            are not more then 590 set the page height to that
            size to take up the entire page.
            
              
        ==================================== */
     
     if (maxHeight < 350)
     {
        
        
        /* ====================================
        New revision
        ------------
        
        Added: June, 10th 2008
        By: Matt
        Description:
            changed from 588 to 350 maxheight so new landing pages would have proper layout.
        
        ==================================== */
     
     
     maxHeight = 350;
        
        
     }
     
     /* ======= END OF ADDITION ======= */
     
     
     for(var i=0;i<contDivs.length;i++)
     { 
          contDivs[i].style.height = maxHeight + 'px'; // assign maximum height value                                               // to all of container <div> elements 
     } 

} 


// execute function when page loads 
function checkColumns()
{ 
     if(document.getElementsByTagName)
     { 
        
          matchHeight(); 
     } 
}







/***

USED FOR INTERNAL SUB NAV

***/






function showSubMenu(){
    var objThis = this;	
    
    for(var i = 0; i  < objThis.childNodes.length; i++)
    {
        if(objThis.childNodes.item(i).nodeName == "UL")			
        {							
            objThis.childNodes.item(i).style.display = "block";
            break;            
        }		
    }	
}


function hideSubMenu()
{								
    var objThis = this;	
    
    for(var i = 0; i  < objThis.childNodes.length; i++)			
    {
        if(objThis.childNodes.item(i).nodeName == "UL")
        {				
            objThis.childNodes.item(i).style.display = "none";			
            break;
        }			
    }	
}

function initialiseMenu()
{
    var objLICollection = document.body.getElementsByTagName("LI");        
    for(var i = 0; i < objLICollection.length; i++)
    {        
        var objLI = objLICollection[i];        
        for(var j = 0; j  < objLI.childNodes.length; j++)
        {

            /*
                Date: August 13, 2007
                By: Walter @ IP
                
                Added in classname check so that the file subnavigation in the content area,
                does not interfer with the top UL / LI navigation.               
            */
            
            if(objLI.childNodes.item(j).nodeName == "UL" && objLI.childNodes.item(j).className == "productFilesSubNav")
            {
                objLI.onmouseover=showSubMenu;
                objLI.onmouseout=hideSubMenu;
                
                for(var j = 0; j  < objLI.childNodes.length; j++)
                {
                    if(objLI.childNodes.item(j).nodeName == "A")
                    {                    
                        objLI.childNodes.item(j).className = "hassubmenu";                                
                    }
                }
            }
        }
    }
}
