var ns6=document.getElementById&&!document.all;
var opera=navigator.userAgent.indexOf("Opera")>=0;
var eventObj = (document.all) ? "window.event.srcElement" : "event.target";

if (ns6) document.captureEvents(Event.KEYDOWN);


function getKey(evt) {
    /*
	if (evt && ns6)
		typedKey=evt.which;
	else
		typedKey=event.keyCode;    
    */
    
    var typedKey = null;
	if(evt && evt.which)
	{ //if which property of event object is supported (NN4)
		//e = e ?? 
		typedKey = evt.which //character code is contained in NN4's which property
	}
	else
	{		
		typedKey = event.keyCode; //character code is contained in IE's keyCode property
	}
	if (typedKey == 13) {	    
		if(document.all) {
			window.event.cancelBubble='true';
		    window.event.returnValue = false;
		} else {
			evt.stopPropagation();
		    evt.preventDefault();
		    
		}
		document.getElementById("searchBtn").click();		
	 }
}

function setSearch() 
{
	document.getElementById('mainform').action ='search.aspx?search=' + encodeURI(document.getElementById("searchbox").value);
	document.getElementById('mainform').submit();
}


function visStortWindow(SitecoreID, width, height)
{
	var visStortWin = window.open("/Global/ShowImage.aspx?id="+ SitecoreID, '', "resizable=no,scrollbars=no,status=no,statusbar=no,titlebar=no,left=25,top=0,height="+ height +",width="+ width);
	visStortWin.focus();
}

function ccvWindow()
{
	var ccvWin = window.open('/Nozzle/CCV.html', '', 'resizable=no,scrollbars=no,status=no,statusbar=no,titlebar=no,left=25,top=0,height=180,width=500');
	ccvWin.focus();
}



/*********** LEFT MENU FUNCTIONS  ************/
function showCollapseDiv(divID, divCount) {

    var divMenu = document.getElementById(divID);
   
    //collapse all the div except the current one
    for (i=1; i<=divCount; i++) {
        var curr_div = document.getElementById("div" + i);
        if (divMenu != curr_div) {
            curr_div.style.display =  "none";
        }
    }
    
    
    if (divMenu.style.display == "inline") {
        divMenu.style.display =  "none";
    }
    else {
        divMenu.style.display = "inline";
    }
}




 /****ZEBRA STRIPES CODE BEGIN*****/

 // this function is needed to work around 
  // a bug in IE related to element attributes
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripeTables(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
	// Set the alternate color in the method call arguments
	var evenColor; 
	
	
	
	
	
	// hard coded here and applies to all tables.
	/*
	*********
	*********
	*/
	
    var oddColor = "#e4e4e4";
	
    /*
	*********
	*********
	*/ 
	// hard coded here and applies to all tables.
	
	
	
	
	 
	 // Populate 2 arrays with the arguments,
	 // separating the colors from the ID's.
	 var colorArray = new Array();
	 var cArrayCount = 0;
	 
	 var IdArray = new Array();
	 var IdArrayCount = 0;
	 
	 // This script assumes that the arguements always
	 // come in pairs: ID / evenColor. So the first
	 // argument will always be the ID.
	 for (i_id = 0; i_id < arguments.length; i_id++) {
	 	
		// Since the function arguments are formatted in ID/color pairs,
		// and the first argument is an ID, when %2 == 0 
		// it will be a element ID and not a color.
		if (i_id%2 == 0) {
			IdArray[IdArrayCount] = arguments[i_id];
			IdArrayCount++;
		}
		else {
			colorArray[cArrayCount] = arguments[i_id];
			cArrayCount++;			
		}
	 }
	 // Populate 2 arrays with arguments
	 
	 
	 
	 
	 /*
	 // Testing code for the arrays
	 alert("Color Array has: "+ colorArray.length);
	 alert("ID Array has: "+IdArray.length);
	 
	 for (a = 0; a < colorArray.length; a++) {
	 	alert(colorArray[a]);	 	
	 }
	 
	  for (a = 0; a < IdArray.length; a++) {
	 	alert(IdArray[a]);	 	
	 }
	 // Testing code for the arrays
	 */
	 
	
	
	 // color the rows for each table as defined in the function arguments
	 for (a = 0; a < IdArray.length; a++) {	 	 
		  		 
		 	     evenColor = colorArray[a]; 		
		 			 
		 		// obtain a reference to the desired table
				// if no such table exists, abort
				var table = document.getElementById(IdArray[a]);
				if (! table) { return; }		 
				
				
				// by definition, tables can have more than one tbody
				// element, so we'll have to get the list of child
				// &lt;tbody&gt;s 
				var tbodies = table.getElementsByTagName("tbody");
			
				// and iterate through them...
				for (var h = 0; h < tbodies.length; h++) {
				
				 // find all the &lt;tr&gt; elements... 
				  var trs = tbodies[h].getElementsByTagName("tr");
				  
				  // ... and iterate through them
				  for (var i = 0; i < trs.length; i++) {
			
					// avoid rows that have a class attribute
					// or backgroundColor style
					if (! hasClass(trs[i]) &&
						! trs[i].style.backgroundColor) {
					  
					  // get all the cells in this row...
					  var tds = trs[i].getElementsByTagName("td");
					
					  // and iterate through them...
					  for (var j = 0; j < tds.length; j++) {
					
						var mytd = tds[j];
			
						// avoid cells that have a class attribute
						// or backgroundColor style
						if (! hasClass(mytd) &&
							! mytd.style.backgroundColor) {
					
						  mytd.style.backgroundColor =
							even ? evenColor : oddColor;
						
						}
					  }
					}
					// flip from odd to even, or vice-versa
					even =  ! even;
				  }
				}
		} // for loop		
  }

 /*******ZEBRA STRIPES CODE END******/




