/* ********************************************************
globals.js

Only place common scripts used in most or all pages in this file.
******************************************************** */

/*
 *  Set all glodal vars before anything else.
 */
 
	var focused = new Array();
	var fm = self.document.forms;
	var CurrentObj = null;
	var CurrentForm = null;


/* *************************
   Rollover Scripts
************************** */
		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 for setting visibility attribute in layers */
	function showHideLayers() {
	  var i,p,v,obj,args=showHideLayers.arguments;if(document.getElementById){
	   for (i=0; i<(args.length-2); i+=3){ obj=ns6_findObj(args[i]);v=args[i+2];
	   v=(v=='show')?'visible':(v='hide')?'hidden':v;
	   if(obj)obj.style.visibility=v;}} else{
	  for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	    obj.visibility=v; }}
	}
	
	
		
	/* Closes popup window - invoked when an Action button as closepopup=true
	 * Delay the close for browsers like Netscape to allow for page submission
	 */
	function closePopupWindow( w )
	{ 
		w.setTimeout("close()",100); 
	}
		
		
	/* Used to create a pop-up window */
	function popUpWindow( filename , title , windowHeight , windowWidth , scroll, options) {
	  var ScrollBar = 0;
	  if (scroll == "yes" || scroll == "Yes")
	    ScrollBar = 1;
	  var features = "top=20,left=20,alwaysRaised=1,resizable=yes,scrollbars=" + ScrollBar;
	  if( windowWidth && windowWidth > 0 ) { features += ",width=" + windowWidth; }
	  else { features += ",width=550"; }
	  if( windowHeight && windowHeight > 0 ) { features += ",height=" + windowHeight; }
	  else { features += ",height=585"; }
	  var strOptions = "";
	  if ( options && options != " " ){
	    var strChopList = options.split( ",");
	    strOptions = "?";
	    for (count = 0 ; count < strChopList.length; count++ ){
	      strOptions = strOptions + "&" + strChopList[ count ];
	    }
	  }
	  if( !title ) { title = "popupWindow"; }
	  if( top.window.popupWindow && ! top.window.popupWindow.closed )
	    top.window.popupWindow.close();
	  top.window.popupWindow=window.open(filename + strOptions, title, features);
	}
	
	/* Sets the checked property of all gadgets of the same type
	 * as the passed gadget to the value of the passed gadget
	 */
	function checkAll(gadget, aForm)
	{
	  for (var i=0;i<aForm.elements.length;i++)
	  {
	    var e = aForm.elements[i];
	    if (e.tagName == gadget.tagName) 
	    {
	      if (e.type == gadget.type) 
	      { 
	      	e.checked = gadget.checked; 
	      }
	    }
	  }
	}
	
	/**
	 * Will uncheck a checked parent gadget if a child control is unchecked.
	 * The parent gadget would be the gadget that when checked, checks all
	 * of the child gadgets.
	 */
	function checkAllChildHandler(child, parent, aForm) 
	{
		if (parent && parent.checked && !child.checked) {
			parent.checked = false;
		}
	}
			

		function confirmation(loc)
		{
			var x = confirm(self.logOffText);
			if (x)			
			{ 
				// Output when OK is clicked
				location=loc;
				//alert ("??? You have logged off. ???"); 
			}	
			else
			{
					void(0);
				//alert ("??? You are still logged in ???"); 
			}
		}

		
		
	/* Global function to show mesages in the browser's status bar */
	function displayStatusMsg(msgStr) 
	{ 
		window.status=msgStr; return true; 
	}


	/*  Set the value of a selection box to the given value.  Return false if value
	 *  not found in set of options.
	 */
	function setSelect(e,value){
	  for( var i=0; i < e.length; ++i ){
	    var sText = e.options[i].text;
	    if( sText==value){
	      e.selectedIndex=i;
	      return true;
	    }
	  }
	  return false;
	}


	function setCookie(label,data,expires){
	  if( expires ) 
	  { 
	  	document.cookie = label+"="+escape(data)+";expires="+expires; 
	  }
	  else 
	  { 
	  	document.cookie = label+"="+escape(data); 
	  }
	}

	function removeCookie(label)
	{ 
		document.cookie = label+"=.;expires=Thu, 01-Jan-70 00:00:01 GMT" 
	}
	
	
	/* Encode attributes by escaping quotes using their hex value srrounded by %% chars.
	 * Note that the better solution would have been to use true XML encoding
	 * &#x27; rather than %%x27%% -.
	 */
	function encodeXMLAttribute( str ){
	  str = str.replace(/\'/g,"%%#x27%%");
	  str = str.replace(/\"/g,"%%#x22%%");
	  str = str.replace(/&/g,"%%#x38%%");
	  return str;
	}

	function decodeXMLAttribute( str ){
	  str = str.replace(/%%#x27%%/g,"'");
	  str = str.replace(/%%#x22%%/g,'"');
	  str = str.replace(/%%#x38%%/g,"&");
	  str = str.replace(/&#x27;/g,"'");
	  str = str.replace(/&#x22;/g,'"');
	  return str;
	}

	/* Establish focus on first field in form */
	function setInitFocus() {
		for(var i = 0; i < fm.length; i++) {
			var f = fm[i];
			if (!f.name ||
			   	(f.name &&
			   	 f.name != "LanguageForm" &&
			   	 f.name != "utilForm" &&
			   	 f.name != "HeaderCatalogSearchForm")
			   ) {
			   
				CurrentForm = f;
				for(var i = 0; i < f.elements.length; i++) {
					var elt = f.elements[i];
					
					if(elt.type != "hidden" &&
					   !elt.disabled &&
					   elt.id != "resultsPerPage") {
					   
						try
						{
							f.elements[i].focus();						
						}
						catch (e)
						{
							/* If focus can't be set, just ignore */
						}

						return;					
					}
				}
			}
		}
	}
	
	/* This function will submit the current form when the <enter> key is pressed. */
	function elementOnKeyPress(e) {
		if (e.keyCode == 13) {
			if (CurrentForm != null) {
				CurrentForm.submit();
			}
		}
	}
	
	function addLoadEvent(func) 
	{
	  var oldonload = window.onload;
	  if (typeof window.onload != 'function') {
	    window.onload = func;
	  } else {
	    window.onload = function() {
	      oldonload();
	      func();
	    }
	  }
	}

	function setFormElementEvents()
	{			
		// iterate over forms
		for(var i = 0; i < fm.length; i++) {
			// iterate over the elements
			var elements = fm[i];
			var elementsLength = elements.length;
			for( var j = 0; j < elementsLength; j++ )
			{
				var elm = elements[j];
				if( elm.type !="hidden" && elm.disabled != true )
				{
					addAnEvent(elm, "blur", clearCurrentForm);
					addAnEvent(elm, "focus", setCurrentForm);
					// keypress events should not be captured by textarea elements
					if (elm.type != "textarea") {
						addAnEvent(elm, "keypress", elementOnKeyPress);
					}
				}
			}
		}
	}
	
	function addAnEvent(el, evname, func) 
	{	
     if (el.attachEvent) 
     {
        el.attachEvent("on" + evname, func);
     } 
     else if (el.addEventListener) 
     {
        el.addEventListener(evname, func, true);         
     } 
     else 
     {
        el["on" + evname] = func;
     }
	}
		
	function clearCurrentForm()
	{
		CurrentForm = null;
	}
	
	function setCurrentForm()
	{
		if (this && this.form) {
			CurrentForm = this.form;
		} else {
			CurrentForm = event.srcElement.form;
		}
	}
	
	/*
	 * Uses the utility form to set the new language ID and refresh the current page
	 * by doing a post.
	 */
	 function switchLanguage(langId) {
	 
	 	if (langId) {
		 	updateUtilFormParam("langId", langId);
		} else {
			// no langId parameter was included when the function was called
		 	var currentLangId = getUtilFormParam("langId");
		 	if (currentLangId && currentLangId != "") {
		 		if (currentLangId == "-1") {
		 			switchLanguage("-11")
		 		} else if (currentLangId == "-11") {
			 		switchLanguage("-1");
		 		} else if (currentLangId == "-12") {
			 		switchLanguage("-13")
		 		} else if (currentLangId == "-13") {
		 			switchLanguage("-12")
		 		}
		 	}
		}
		
	 	// do not set a view, not setting a view will submit to the current view
		submitUtilForm();
	 }
	
	/*
	 *  Takes a list of selected produts, and builds the request parameters from them and some
	 *  hidden fields and sends a request to the OrderItemAdd URL.
	 */
	function addSelectedToCart(form) {
		
		form.action = "AddSelectedToCart";

		/*if (topPane)
		{
			//Defect 1237: Always load with the Mini Shopping Cart on top
			topPane.setSelectedIndex(0);
		}*/
		
		form.submit();
		
	}
	
	/*
	 *  Takes a list of selected produts, and builds the request parameters from them and some
	 *  hidden fields and sends a request to the SavedListChoicePage URL.
	 */
	function addSelectedToList(form) {
	
		form.action = "SavedListChoicePage";
		form.submit();
	}
	

	/*
	 *  This is used from the SubCategory page and Search results. It uses a different checkbox to
	 *  saved_list_selected_# to indicate what parts are to be added. It checks the hidden checkbox "selected".
	 */
	function addSelectedToListFromCatalog(form,action) 
	{
		setSavedListCheckboxesForEnrich(form,action);	
		//addSelectedToList(form);
	}

	/*
	 *  This is used from the SubCategory page and Search results. It uses a different checkbox to
	 *  saved_list_selected_# to indicate what parts are to be added. It checks the hidden checkbox "selected".
	 */
	function addSelectedToListFromCatalogWithEnter(e, form) 
	{
		var ENTER_KEY = 13;
		var keyCode = e.keyCode ? e.keyCode : (e.which ? e.which : e.charCode);
    
	    if (keyCode == ENTER_KEY) 
	    {	    	
	    	setSavedListCheckboxes(form);
		}
	}
	
	function setSavedListCheckboxesForEnrich(form,action)
	{
		var allCheckboxes = document.getElementsByTagName("input");
		var checklistbox=false;
		for (var i = 0; i < allCheckboxes.length; i++)
		{
			//needs to start with "saved_list_selected_" and be checked
			var isSavedListSelectedCheckbox = (allCheckboxes[i].name.indexOf("saved_list_selected_") == 0);
			
			if (isSavedListSelectedCheckbox && allCheckboxes[i].checked)
			{
				
				var selectedCheckboxId = "selected_" + allCheckboxes[i].name.substring(20, allCheckboxes[i].name.length);				
				//find the checkboxes in the form
				var formElements = form.elements;
				for (var j = 0; j < formElements.length; j++)
				{
					if (formElements[j].id == selectedCheckboxId)
					{
						formElements[j].checked = true;
					}
				}
				checklistbox=true;
			}
		}
		if(!checklistbox){
		document.getElementById('errorMessage').value="At least one item must be selected in order to add to your Saved List. To select a part, please click on the box to the far left of the part information.";
		form.action=action;
		}
		form.submit();		
	}

	function setSavedListCheckboxes(form)
	{
		var allCheckboxes = document.getElementsByTagName("input");
		var checklistbox=false;
		for (var i = 0; i < allCheckboxes.length; i++)
		{
			//needs to start with "saved_list_selected_" and be checked
			var isSavedListSelectedCheckbox = (allCheckboxes[i].name.indexOf("saved_list_selected_") == 0);
			
			if (isSavedListSelectedCheckbox && allCheckboxes[i].checked)
			{
				
				var selectedCheckboxId = "selected_" + allCheckboxes[i].name.substring(20, allCheckboxes[i].name.length);				
				//find the checkboxes in the form
				var formElements = form.elements;
				for (var j = 0; j < formElements.length; j++)
				{
					if (formElements[j].id == selectedCheckboxId)
					{
						formElements[j].checked = true;
					}
				}
				checklistbox=true;
			}
		}
		form.submit();		
	}

	/*
	 * Single Part no# added
	 *  Takes a list of selected produts, and builds the request parameters from them and some
	 *  hidden fields and sends a request to the OrderItemAdd URL.
	 */
	function addSelectedToCartFromCatalog(form, partcheck) {
	
		
		form.action = "AddSelectedToCart";
		
		//unselect other parts
		var allCheckboxes = document.getElementsByTagName("input");
		for (var i = 0; i < allCheckboxes.length; i++)
		{
			//needs to start with "selected_"
			if (allCheckboxes[i].name.indexOf("selected_") == 0)
			{
				allCheckboxes[i].checked = false;
			
			}
		}
		partcheck.checked = true;

		/*if (topPane)
		{
			//Defect 1237: Always load with the Mini Shopping Cart on top
			topPane.setSelectedIndex(0);
		}*/
		
		form.submit();
		
	}
	
	/*
	 *  Adds/update the value of the Results per Page dropdown to the
	 *  current page's query string.
	 */
	function updateResultsPerPage(cboResultsPerPage, viewName, pageParam) {
		
		updateUtilFormParam(cboResultsPerPage.id, cboResultsPerPage.value);
		
		
		if (pageParam) {
			updateUtilFormParam(pageParam, "1");
		}
		
		
		submitUtilForm(viewName);
	}
	
	/*
	 * Changes the sort order if the same sub column was clicked again.  Otherwise,
	 * the sort column, subcolumn, and direction parameters are updated.
	 */
	function sortMultiHeaderCol(viewName,
								tableUid,
								currentSortColumn,
								newSortColumn,
								currentSortSubcolumn,
								newSortSubcolumn,
								currentSortDirection) {
		
		var href = location.href;
		var sortDirectionName = "d-" + tableUid + "-o";
		
		// determine if the same sort column is being clicked again
		if (currentSortColumn == newSortColumn && currentSortSubcolumn == newSortSubcolumn) {
			// just update the sort direction
			var newSortDirection = 1;
			if (newSortDirection == currentSortDirection) {
				newSortDirection = 2;
			}
			updateUtilFormParam(sortDirectionName, newSortDirection);
			
		} else {
			
			if (newSortColumn != currentSortColumn) {
				var sortColumnName = "d-" + tableUid + "-s";
				// replace the sort column value
				updateUtilFormParam(sortColumnName, newSortColumn);
			}
			
			if (newSortSubcolumn != currentSortSubcolumn) {
				// replace the sub column value
				updateUtilFormParam("ssub", newSortSubcolumn);
			}
			
			if (currentSortDirection != 2) {
				// first sort ascending
				updateUtilFormParam(sortDirectionName, 2);
			}
		}
		
		submitUtilForm(viewName);
	} // end sortMultiHeaderCol()
	
	/*
	 * Obtains a value given a name from the UtilForm
	 */
	function getUtilFormParam(paramName) {
		var paramValue = "";
		var utilForm = document.utilForm;
		if (utilForm[paramName]) {
			paramValue = utilForm[paramName].value;
		}
		return paramValue;
	}
	
	/*
	 * If the name of the parameter is already a hidden field on the utility form,
	 * then the value is just updated.  Otherwise, a temp hidden field is changed
	 * to reflect both the name and value of the passed arguments.
	 */
	function updateUtilFormParam(paramName, paramValue) {
		var utilForm = document.utilForm;
		if (utilForm[paramName]) {
			// the param value was in the request, so it already is a hidden field
			utilForm[paramName].value = paramValue;
		} else {
			// one of the 
			var index = 1;
			var tempParamName = "temp" + index;
			var tempParam = utilForm[tempParamName];
			var found = false;
			
			while (tempParam && !found) {
				if (tempParam.name == '') {
					// a temp hidden field was found that can be used
					tempParam.name = paramName;
					// don't change the value of the ID attribute
					tempParam.value = paramValue;
					// exit the loop
					found = true;
				} else {
					// update the conditional variables
					index++;
					tempParamName = "temp" + index;
					tempParam = utilForm[tempParamName];
				}
			} // ~while
		}
	} // ~ updateUtilFormParam()
	
	/*
	 * Sets the utility form's action and submits it.
	 */
	function submitUtilForm(viewName) {
		var utilForm = document.utilForm;
		if (viewName) {
			utilForm.action = viewName;
		}
		utilForm.submit();
	}
	
	function clearForm(form) {
		var elements = form.elements;
		for (var i = 0; i < elements.length; i++) {
			var element = elements[i];
			if (element.type == 'text') {
				element.value = '';
			} else if (element.type == 'select-one') {
				element.selectedIndex = 0;
			}
			// additional types can be added later
		}
	}
	
	/*
	 * Function removes leading and trailing whitespaces from a String.
	 */
	function trim(str) {
	
		while (str.substring(0, 1) == ' ') {
			str = str.substring(1, str.length);
		}
		
		while (str.substring(str.length-1, str.length) == ' ') {
			str = str.substring(0, str.length - 1);
		}
		
		return str;
	}
	
	/*
	 * Function replaces placeholders in the message with the given parameters.
	 * Placeholders in the message must follow the pattern {0}, {1}, {2} ... {n}
	 * Placeholders must also start at 0 and be numbered consecutively to
	 * ensure their replacement.
	 * If the message contains more placeholder then parameters that were provided,
	 * the placeholders will be replaced by the empty string.
	 */
	 function replaceMsgParams(msg, params) {
	 
	 	var hasMoreParams = true;
	 	// the replacement of params will be placeholder driven, not parameter (var params) driven
	 	for (var i = 0; hasMoreParams; i++) {
	 		// replace the parameter with the current index
	 		var replaceValue = "";
	 		if (i < params.length) {
	 			replaceValue = params[i];
	 		}
		 	msg = msg.replace("{" + i + "}", replaceValue);
		 	
	 		// see if the message has another parameter
	 		hasMoreParams = ((msg.indexOf("{" + (i + 1) + "}")) >= 0);
	 	}
	 	
	 	return msg;
	 }
	/*
	 * Function used to disable any buttons  on the form so that
	 * it cannot be clicked twice
	 *
	 */
	 function disableIt(obj)
		{
						
			var z = (obj.disabled) ? 'disabled' : 'enabled';
			// alert(obj.type + ' now ' + z);		 
  		// obj.style.background="#FF6600";
		  // obj.style.backgroundimage="";
			obj.disabled = true;			 

		}
	addLoadEvent(setInitFocus);
	addLoadEvent(setFormElementEvents);
	
	/*
	 * Function used to link to other pages with a input button
	 *
	 */
	
	function MM_goToURL() { //v3.0
		  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
		  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
		}
	
	
	/*
	 *  Formats the Canadian Postal Code XXX XXX
	 */
	 function formatPostalCode(form){
	 	if(form.storeId.value == '10052'){
	 		var zip = form.zipCode.value;
	 		if(zip.length == 6){
	 			form.zipCode.value = zip.substring(0,3)+" "+zip.substring(3,6);
	 		}
	 		if(zip.length == 7 && zip.substring(3,4) == '-') {
	 			form.zipCode.value = zip.substring(0,3)+" "+zip.substring(4,7);
	 		}
	 		form.zipCode.value = form.zipCode.value.toUpperCase();
	 	}
	 }
	
	/*
	 *  Formats the Canadian Postal Code XXX XXX
	 */
	 function formatOrgPostalCode(form){
	 	if(form.storeId.value == '10052'){
	 		var zip = form.zipCode.value;
	 		var billZip = form.BillTo_zipCode.value;
	 		if(zip.length == 6){
	 			form.zipCode.value = zip.substring(0,3)+" "+zip.substring(3,6);
	 		}
	 		if(zip.length == 7 && zip.substring(3,4) == '-'){
	 			form.zipCode.value = zip.substring(0,3)+" "+zip.substring(4,7);
	 		}
	 		if(billZip.length == 6) {
		 		form.BillTo_zipCode.value = billZip.substring(0,3)+" "+billZip.substring(3,6);
	 		}
	 		if(billZip.length == 7 && billZip.substring(3,4) == '-'){
	 			form.BillTo_zipCode.value = billZip.substring(0,3)+" "+billZip.substring(4,7);
	 		}
	 		
	 	}
	 }
	 
	 /*
	 * Updates WCParam.poNumber field if changes were made during the Final Review page (function is called from OrderSubmitForm.jsp)
	 */
	 function changePONumber(poNumberVal)
	 {
	 	document.utilForm.poNumber.value = poNumberVal;
	 	document.utilForm.submit();
	 }
	 

	/*
	* This javascript function is to be used to prevent the event caused by the enter key. For example, when a form has 
	* only one input of type text and the enter key is hit, the form is submitted. To prevent this behaviour, use this function in
	* the onKeyPress event for the field in question.
	*/
	function disableEnterKey(newEvent)
	{
		var key = (window.event) ? newEvent.keyCode : (event.which) ? newEvent.which : newEvent.charCode;

		if (key == 13)
		{
			if (window.event)
			{
				window.event.keyCode = 0;
			}
			
	 		return false;			
		}
		else
		{
			return true;
		}

	}
	
	
	/*
	* Formats the list of Promo Codes
	*/
	function formatPromoCode(form)
	{
		if (form.promoCode != null)
		{
			form.promoCode.value = form.promoCode.value.toUpperCase();  		
		}
	}
	
	/*
	*
	*/
	function lengthCheck(field, maxlength)
	{
		if (field.value.length > maxlength)
			field.value = field.value.substring(0, maxlength);
	}
	




/*
	* FLASH EMBEDDING SCRIPT TO DISABLE IE "CLICK TO ACTIVATE CONTENT" FUNCTION
	* DO NOT REMOVE
*/

if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs[variablePairs.length] = key +"="+ variables[key];
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'" style="'+ this.getAttribute('style') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
		var axo = 1;
		var counter = 3;
		while(axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//				document.write("player v: "+ counter);
				PlayerVersion = new deconcept.PlayerVersion([counter,0,0]);
			} catch (e) {
				axo = null;
			}
		}
	} else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if (param == null) { return q; }
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i = objects.length - 1; i >= 0; i--) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in some fp9 versions see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	if (!deconcept.unloadSet) {
		deconcept.SWFObjectUtil.prepUnload = function() {
			__flash_unloadHandler = function(){};
			__flash_savedUnloadHandler = function(){};
			window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
		}
		window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
		deconcept.unloadSet = true;
	}
}
/* add document.getElementById if needed (mobile IE < 5) */
if (!document.getElementById && document.all) { document.getElementById = function(id) { return document.all[id]; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;




















function hasSupport() {

	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;
	
	var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
	
	hasSupport.support = ( typeof document.implementation != "undefined" &&
			document.implementation.hasFeature( "html", "1.0" ) || ie55 )
			
	// IE55 has a serious DOM1 bug... Patch it!
	if ( ie55 ) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function ( sTagName ) {
			if ( sTagName == "*" )
				return document.all;
			else
				return document._getElementsByTagName( sTagName );
		};
	}

	return hasSupport.support;
}


function WebFXTabPane( el, bUseCookie ) {
	if ( !hasSupport() || el == null ) return;
	
	this.element = el;
	this.element.tabPane = this;
	this.pages = [];
	this.selectedIndex = null;
	this.useCookie = bUseCookie != null ? bUseCookie : true;
	
	// add class name tag to class name
	this.element.className = this.classNameTag + " " + this.element.className;
	
	// add tab row
	this.tabRow = document.createElement( "div" );
	this.tabRow.className = "tab-row";
	el.insertBefore( this.tabRow, el.firstChild );

	var tabIndex = 0;
	if ( this.useCookie ) {
		tabIndex = Number( WebFXTabPane.getCookie( "webfxtab_" + this.element.id ) );
		if ( isNaN( tabIndex ) )
			tabIndex = 0;
	}
	this.selectedIndex = tabIndex;
	
	// loop through child nodes and add them
	var cs = el.childNodes;
	var n;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab-page") {
			this.addTabPage( cs[i] );
		}
	}
}

WebFXTabPane.prototype.classNameTag = "dynamic-tab-pane-control";

WebFXTabPane.prototype.setSelectedIndex = function ( n ) {
	if (this.selectedIndex != n) {
		if (this.selectedIndex != null && this.pages[ this.selectedIndex ] != null )
			this.pages[ this.selectedIndex ].hide();
		this.selectedIndex = n;
		this.pages[ this.selectedIndex ].show();
		
		if ( this.useCookie )
			WebFXTabPane.setCookie( "webfxtab_" + this.element.id, n );	// session cookie
	}
};
	
WebFXTabPane.prototype.getSelectedIndex = function () {
	return this.selectedIndex;
};
	
WebFXTabPane.prototype.addTabPage = function ( oElement ) {
	if ( !hasSupport() ) return;
	
	if ( oElement.tabPage == this )	// already added
		return oElement.tabPage;

	var n = this.pages.length;
	var tp = this.pages[n] = new WebFXTabPage( oElement, this, n );
	tp.tabPane = this;
	
	// move the tab out of the box
	this.tabRow.appendChild( tp.tab );
			
	if ( n == this.selectedIndex )
		tp.show();
	else
		tp.hide();
		
	return tp;
};
	
WebFXTabPane.prototype.dispose = function () {
	this.element.tabPane = null;
	this.element = null;		
	this.tabRow = null;
	
	for (var i = 0; i < this.pages.length; i++) {
		this.pages[i].dispose();
		this.pages[i] = null;
	}
	this.pages = null;
};



// Cookie handling
WebFXTabPane.setCookie = function ( sName, sValue, nDays ) {
	var expires = "";
	if ( nDays ) {
		var d = new Date();
		d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};

WebFXTabPane.getCookie = function (sName) {
	var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
};

WebFXTabPane.removeCookie = function ( name ) {
	setCookie( name, "", -1 );
};




function WebFXTabPage( el, tabPane, nIndex ) {
	if ( !hasSupport() || el == null ) return;
	
	this.element = el;
	this.element.tabPage = this;
	this.index = nIndex;
	
	var cs = el.childNodes;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab") {
			this.tab = cs[i];
			break;
		}
	}
	
	// insert a tag around content to support keyboard navigation
	
	
	var a = document.createElement( "A" );
	this.aElement = a;
	a.href = "#";
	a.onclick = function () { return false; };
	while ( this.tab.hasChildNodes() )
		a.appendChild( this.tab.firstChild );
	this.tab.appendChild( a );

	
	// hook up events, using DOM0
	var oThis = this;
	this.tab.onclick = function () { oThis.select(); };
	this.tab.onmouseover = function () { WebFXTabPage.tabOver( oThis ); };
	this.tab.onmouseout = function () { WebFXTabPage.tabOut( oThis ); };
}

WebFXTabPage.prototype.show = function () {
	var el = this.tab;
	var s = el.className + " selected";
	s = s.replace(/ +/g, " ");
	el.className = s;
	
	this.element.style.display = "block";
};

WebFXTabPage.prototype.hide = function () {
	var el = this.tab;
	var s = el.className;
	s = s.replace(/ selected/g, "");
	el.className = s;

	this.element.style.display = "none";
};
	
WebFXTabPage.prototype.select = function () {
	this.tabPane.setSelectedIndex( this.index );
};
	
WebFXTabPage.prototype.dispose = function () {
	this.aElement.onclick = null;
	this.aElement = null;
	this.element.tabPage = null;
	this.tab.onclick = null;
	this.tab.onmouseover = null;
	this.tab.onmouseout = null;
	this.tab = null;
	this.tabPane = null;
	this.element = null;
};

WebFXTabPage.tabOver = function ( tabpage ) {
	var el = tabpage.tab;
	var s = el.className + " hover";
	s = s.replace(/ +/g, " ");
	el.className = s;
};

WebFXTabPage.tabOut = function ( tabpage ) {
	var el = tabpage.tab;
	var s = el.className;
	s = s.replace(/ hover/g, "");
	el.className = s;
};


// This function initializes all uninitialized tab panes and tab pages
function setupAllTabs() {
	if ( !hasSupport() ) return;

	var all = document.getElementsByTagName( "*" );
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var tabPageRe = /tab\-page/;
	var cn, el;
	var parentTabPane;
	
	for ( var i = 0; i < l; i++ ) {
		el = all[i]
		cn = el.className;

		// no className
		if ( cn == "" ) continue;
		
		// uninitiated tab pane
		if ( tabPaneRe.test( cn ) && !el.tabPane )
			new WebFXTabPane( el );
	
		// unitiated tab page wit a valid tab pane parent
		else if ( tabPageRe.test( cn ) && !el.tabPage &&
					tabPaneRe.test( el.parentNode.className ) ) {
			el.parentNode.tabPane.addTabPage( el );			
		}
	}
}

function disposeAllTabs() {
	if ( !hasSupport() ) return;
	
	var all = document.getElementsByTagName( "*" );
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var cn, el;
	var tabPanes = [];
	
	for ( var i = 0; i < l; i++ ) {
		el = all[i]
		cn = el.className;

		// no className
		if ( cn == "" ) continue;
		
		// tab pane
		if ( tabPaneRe.test( cn ) && el.tabPane )
			tabPanes[tabPanes.length] = el.tabPane;
	}
	
	for (var i = tabPanes.length - 1; i >= 0; i--) {
		tabPanes[i].dispose();
		tabPanes[i] = null;
	}
}


// initialization hook up

// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", setupAllTabs, false );

// IE 
else if ( typeof window.attachEvent != "undefined" ) {
	window.attachEvent( "onload", setupAllTabs );
	window.attachEvent( "onunload", disposeAllTabs );
}

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			setupAllTabs();
		};
	}
	else 
		window.onload = setupAllTabs;
}








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_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkAll(gadget, aForm)
	{
	  for (var i=0;i<aForm.elements.length;i++)
	  {
	    var e = aForm.elements[i];
	    if (e.tagName == gadget.tagName) 
	    {
	      if (e.type == gadget.type) 
	      { 
	      	e.checked = gadget.checked; 
	      }
	    }
	  }
	}

function submitSearch(form)
{
	if (form.name == "SearchWithinForm")
	{
		form.srchWithin.value = trim(form.srchWithin.value);
	}
	else
	{
		form.srchTerm.value = trim(form.srchTerm.value);	
	}

	disableIt(form.searchButton);
	form.submit();
}
function submiLogon(form)
{	
	disableIt(form.logonButton);	
	form.submit();
}

function submiLogonEnter(e,form)
{
var ENTER_KEY = 13;
	var code = "";
      
    if (window.event) // IE
    {
        code = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        code = e.which;
    }
            
    if (code == ENTER_KEY) 
    {				    	
      // disableIt(form.logonButton); 		       
	   form.submit();
    }  
}
function submitSearchOnEnter(e, form)
{
	var ENTER_KEY = 13;
	var code = "";
      
    if (window.event) // IE
    {
        code = e.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        code = e.which;
    }
            
    if (code == ENTER_KEY) 
    {
		if (form.name == "SearchWithinForm")
		{
			form.srchWithin.value = trim(form.srchWithin.value);
		}
		else
		{
			form.srchTerm.value = trim(form.srchTerm.value);	
		}
		
		disableIt(form.searchButton);
        return true;
    }
	

}
function addToCartFromCatalogWithEnter(e, form, partcheck)
{
	var ENTER_KEY = 13;
	var keyCode = e.keyCode ? e.keyCode : (e.which ? e.which : e.charCode);
    
    if (keyCode == ENTER_KEY) 
    {
		/** Repeating the logic for the add to cart button here, the difference is we do not do form.submit()
		and let the browser event propagation take care of that. This is ugly, but it was the only option that
		worked consistently with IE and Firefox.*/
		
		form.action = "AddSelectedToCart";
		
		//unselect other parts
		var allCheckboxes = document.getElementsByTagName("input");
		for (var i = 0; i < allCheckboxes.length; i++)
		{
			if (allCheckboxes[i].name.indexOf("selected_") == 0)
			{
				allCheckboxes[i].checked = false;
			}
		}
		partcheck.checked = true;

		if (topPane)
		{
			//Defect 1237: Always load with the Mini Shopping Cart on top
			topPane.setSelectedIndex(0);
		}
	}
		
    	return true;

}

function chooseActionOnEnter(e, savedlistCheckBox, form, partcheck)
{
	
	if (savedlistCheckBox.checked)
	{		
		addSelectedToListFromCatalogWithEnter(e, form);
	}
	else
	{
		addToCartFromCatalogWithEnter(e, form, partcheck);
	}

}


function focusSelectBox()
{
document.HeaderCatalogSearchForm.srchTerm.focus();
}

function addPartToCart(count, userType, part, quantity, partchecked) {
		var mainURL = "";
		var endecaURL = "";
		var re_URL = "";
		
		
		
		if(userType ==  'R') {
			//var selectedObj = "document.productsForm.selected_"+count;
			//alert(selectedObj);
			//alert("inside the registered "+document.productsForm);
					//	alert("part selected"+partchecked);
			addSelectedToCartFromCatalog(document.productsForm, partchecked);
			
		}else {
			mainURL = "langId="+document.productsForm.langId.value+"&storeId="+document.productsForm.storeId.value+"&catalogId="+document.productsForm.catalogId.value;
			
			/*if(document.productsForm.srchType.value == 'NAV') {*/
				endecaURL = "nstate="+document.productsForm.nstate.value+"&numItems="+document.productsForm.numItems.value;
				/*if(document.productsForm.offset != null) {
					endecaURL = endecaURL + "&offset="+ document.productsForm.offset.value;
				}
				if(document.productsForm.sort != null) {
					endecaURL = endecaURL + "&sort="+ document.productsForm.sort.value;
				}*/
				re_URL = escape("NavigationSearch?"+mainURL+"&"+endecaURL);
			/*} else {
				endecaURL = "nstate=0&numItems="+document.productsForm.numItems.value+"&srchType="+document.productsForm.srchType.value+"&srchTerm="+document.productsForm.srchTerm.value;
				if(document.productsForm.offset != null) {
					endecaURL = endecaURL + "&offset="+ document.productsForm.offset.value;
				}
				if(document.productsForm.sort != null) {
					endecaURL = endecaURL + "&sort="+ document.productsForm.sort.value;
				}
				if(document.productsForm.srchWithin != null) {
					endecaURL = endecaURL + "&srchWithin="+ document.productsForm.srchWithin.value;
				}
				//if(document.productsForm.srchMode != null) {
				//	endecaURL = endecaURL + "&srchMode="+ escape(document.productsForm.srchMode.value);
				//}
				if(document.productsForm.srchScope != null) {
					endecaURL = endecaURL + "&srchScope="+ document.productsForm.srchScope.value;
				}
				re_URL = escape("NavigationSearch?"+mainURL+"&"+endecaURL+"&errorViewName=NoResultsDisplayView");
			}*/
			
			var url = escape("/webapp/wcs/stores/servlet/AddSelectedToCart?quantity_"+count+"="+quantity+"&selected_"+count+"=Y&partNumber_"+count+"="+part+"&WcUseHttps=true&"+mainURL+"&"+endecaURL+"&errorViewName="+document.productsForm.errorViewName.value+"&re_URL="+re_URL);
			document.location="/webapp/wcs/stores/servlet/LogonForm?"+mainURL+"&URL="+url;
		}
}


/* Accordion Script */
/* Accordion Script */


var ContentHeight = 140;
var TimeToSlide = 250.0;

var openAccordion = '';

function runAccordion(index)
{
  var nID = "Accordion" + index + "Content";
  if(openAccordion == nID)
    nID = '';
    
  setTimeout("animate(" + new Date().getTime() + "," + TimeToSlide + ",'" + openAccordion + "','" + nID + "')", 33);
  
  openAccordion = nID;
}

function animate(lastTick, timeLeft, closingId, openingId)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var opening = (openingId == '') ? null : document.getElementById(openingId);
  var closing = (closingId == '') ? null : document.getElementById(closingId);
 
  if(timeLeft <= elapsedTicks)
  {
    if(opening != null)
      opening.style.height = ContentHeight + 'px';
    
    if(closing != null)
    {
      closing.style.display = 'none';
      closing.style.height = '0px';
    }
    return;
  }
 
  timeLeft -= elapsedTicks;
  var newClosedHeight = Math.round((timeLeft/TimeToSlide) * ContentHeight);

  if(opening != null)
  {
    if(opening.style.display != 'block')
      opening.style.display = 'block';
    opening.style.height = (ContentHeight - newClosedHeight) + 'px';
  }
  
  if(closing != null)
    closing.style.height = newClosedHeight + 'px';

  setTimeout("animate(" + curTick + "," + timeLeft +",'" + closingId + "','" + openingId + "')", 33);
}


/* Accordion Script */
/* Accordion Script */

