/*
# List all of the common js function to be shared in this file
*/

// function to generate the navigation
	sfHover = function(){ 
		var sfEls = document.getElementById("navMenu").getElementsByTagName("LI");
		var IfrRef = getObj("DivIframe");
		var isIE = (navigator.appName.indexOf("Microsoft")!= -1)?true:false;
			for (var i=0; i<sfEls.length; i++) {
				sfEls[i].onmouseover=function() {
					var navName = this.className;
					this.className+=" sfhover";
					// if it is IE, add iframe layer
					if (isIE){
						var nLeft = "16px";
						var nWidth = "176px";
						var nHeight = "100px";
						switch (navName)
						{
							case "nav1":
							case "nav1Selected":
                               if (nav1Height != null)
                                    nHeight = nav1Height;
                                break;
							case "nav2":
							case "nav2Selected":
								nLeft = "92px";
                               if (nav2Height != null)
                                    nHeight = nav2Height;
								break;
							case "nav3":
							case "nav3Selected":
								nLeft = "235px";
                                if (nav3Height != null)
                                    nHeight = nav3Height;
								break;
							case "nav4":
							case "nav4Selected":
								nLeft = "300px";
                                if (nav4Height != null)
                                    nHeight = nav4Height;
								break;
						}
						// only for the first 4 drop down menu
						if ( (navName.indexOf("1") != -1 && navName.indexOf("0") == -1) ||  navName.indexOf("2") != -1 || navName.indexOf("3") != -1 || navName.indexOf("4") != -1)
						{
							IfrRef.style.top = "102px";
    					IfrRef.style.left = nLeft;
							IfrRef.style.width = nWidth;
    					IfrRef.style.height = nHeight;
    					IfrRef.style.zIndex = 499;
    					IfrRef.style.display = "block";
						}
					}
				}
				sfEls[i].onmouseout=function() {
					var navName = this.className;
					this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
					if (isIE){
						if ( (navName.indexOf("1") != -1 && navName.indexOf("0") == -1) ||  navName.indexOf("2") != -1 || navName.indexOf("3") != -1 || navName.indexOf("4") != -1) { IfrRef.style.display = "none";}
					}
				} 
			} 
	} 
	
// function to swap table tabs	
	function swapTabs( tabId){
		 var contentTab = "content_" + tabId;
		 var tabName = "tab_" + tabId; 
     if (openedTab){
          openedTabContent.style.display="none";
          openedTab.className=""; 
     }
     
     // get the select tab elements     
     openedTab = getObj( tabName );
     openedTabContent = getObj( contentTab );
     
     // display the proper tab name and the content
     if(openedTab){
     	openedTab.className="current";
     	openedTabContent.style.display = "block";
     }
	}	
	
// function to get and set color set image
	function setColors (colorId, imgOn, displayType){
		var colorContentName = colorId + "_content";
    // hide the previouse selected color set content
    var colorContent = getObj(colorContentName);
    if (colorContent != null)
    	colorContent.style.display=displayType;
    // change the on-image to off
    var colorImgName = new Image();
    colorImgName.src="/img/" + colorId + imgOn + ".gif";
    var colorImg = getObj(colorId);    
    if (colorImg != null)
    	colorImg.src=colorImgName.src;
   	return;
	}
	
// function to swap color sets and change selected image	
	function swapColorSets(setId){
		 
    if (selectedColorSet){
    	setColors(selectedColorSet, "", "none");
    }
    selectedColorSet = setId;
    setColors(setId, "_on", "block");
	}	
	
// set the color chip name
	function setColorChipName(colorName){
		var colorChipName = getObj("colorChipName");
		if (colorChipName != null)
			colorChipName.innerHTML = colorName;
	}	
		
// function to open popup window
// pType define is the popup is a large image or just a color switch
// pType l (L)=large, c = color, n=normal
	function openProductPopup (nWidth, nHeight, picLoc, pType) 
	{
		var popLoc = "/popup.jsp?pic=" + picLoc;
		if (pType != null && pType != ""){
			popLoc += "&t=" + pType;
		}
		var popProperties = "left=100, top=100, scrollbars=no, resizable=no, width="+nWidth + ", height=" + nHeight;
		window.open(popLoc, "prod", popProperties);
	}

// function to change the selected box options
 	 	var isVisible=0;

// Used to create dropdown list options
// Creates array of names based upon
// Item group , item value, item text
//
		function listItem(itemGroup, itemValue, itemText, itemShip){
          this.itemGroup=itemGroup;
          this.itemValue=itemValue;
          this.itemText=itemText;
          this.itemShip = itemShip;
    }

    function populateSubList(arrItems, groupID, objSub, objDsp){
			//this block clears the current listings in the second dropdown, if the dropdown has any
			if(objSub){
				objSub.selectedIndex=0;
      	isVisible=0;
      	if(objSub.options.length>1){
      		for (x=objSub.options.length; x>0; x--){
        		objSub.options[x]=null;
        	}
        	// change the status
        	var shipStatus = getObj(objDsp);
    			if (shipStatus != null){
                    shipStatus.innerHTML="&nbsp;";
    			}
      	}

				//this block populates the second drop down, by matching the selected value of dropdown 1
				//to the lookup value of the list items
				var cnt = 0;
    		for(x=0; x < arrItems.length; x++){
    			if(arrItems[x].itemGroup==groupID){
    				cnt += 1;
    				objSub.options[cnt] = new Option(arrItems[x].itemText, arrItems[x].itemValue);
       		}
     		}
			} else {
				// if objSub is null and we are calling this function diplay the shipping info instead
				displayShipInfo(arrItems, groupID, '', objDsp)
			}
		}

    function displayShipInfo (arrItems, groupID, subID, objDsp){

			if (arrItems != null){
                var x=0;
                for(x; x < arrItems.length; x++){
    			if(arrItems[x].itemGroup==groupID){
    				if(arrItems[x].itemValue==subID){
                        var shipStatus = getObj(objDsp);
    					if (shipStatus != null){
                            if(arrItems[x].itemShip != ""){
                             shipStatus.innerHTML=arrItems[x].itemShip;
                            } else {
                                shipStatus.innerHTML= "&nbsp;";
                            }
    					}
                         break;
                    }
       		    }
             }
                if (x == arrItems.length){
                    var shipStatus = getObj(objDsp);
                    if (shipStatus != null){
                        shipStatus.innerHTML= "&nbsp;";
                    }
                }
            }
		}

/*
* Display the shipping status if there is no color or size dropdown
*/
function displaySingleShipStatus (arrItems, objDsp){

			if (arrItems != null && arrItems.length > 0){
			    var shipStatus = getObj(objDsp);
    			if (shipStatus != null){
    			    shipStatus.innerHTML=arrItems[0].itemShip;
    			}
			}

}

// JS function to display selected address and credit card info
	function listItemField (fldName, fldType){
		this.fldName = fldName;
		this.fldType = fldType;
	}

	function listItemInfo (infoKey, arrDataInfo){
		this.infoKey = infoKey;
		this.arrDataInfo = arrDataInfo;
	}

	function displaySelectedInfo (arrListItemInfo, infoKey, arrListItemField){

		if (arrListItemField != null && arrListItemField.length > 0 ){
			// if infoKey is "" set the default value to ""
			if (infoKey == null || infoKey == "" ){
				for (i=0; i < arrListItemField.length; i++){
    			var fldObj = getObj(arrListItemField[i].fldName);
    			if (fldObj != null){
    				if (arrListItemField[i].fldType == "select"){
    						fldObj.selectedIndex = 0;
        		} else {
    					fldObj.value="";
    				}
    			}
    		}
    	// otherwise set the value according to the info key
			} else if (arrListItemInfo != null){
				for(x=0; x < arrListItemInfo.length; x++){
					// find a match
    			if(arrListItemInfo[x].infoKey==infoKey){
    				for (i=0; i < arrListItemField.length; i++){
    					var fldObj = getObj(arrListItemField[i].fldName);
    					if (fldObj != null){
    						if (arrListItemField[i].fldType=="select"){
    							setSelectedOption (fldObj, arrListItemInfo[x].arrDataInfo[i]);
    						} else {
    							fldObj.value=arrListItemInfo[x].arrDataInfo[i];
    						}
    					}
    				}
    				break;
       		}
     		}
			}

		}
	}

	function setSelectedOption (selObj, selValue){
		if (selObj != null){
			if(selObj.options != null && selObj.options.length > 0){
      	for (k=0; k < selObj.options.length; k++){
        	if(selObj.options[k].value == selValue){
        		selObj.selectedIndex = k;
        		break;
        	}
        }
      }
		}
	}


// load correct src to iframe for image viewer
function imageView(frameName,url){
	frames[frameName].location.href = url;
}


// change img with passed in src and img name
function changeImg(name,img){
	//alert("name = " + name + "and img = " + img );
	document.images[name].src = img;
}

//content popup widow
function openPopup(file) {
	var popProperties = "left=100, top=100, scrollbars=yes, resizable=no, width=455, height=500";
	window.open(file, "sah", popProperties);
}


//popup widow, with size parameters
function openPopupWH(file,wid,hei) {
	window.open(file, "sah", "left=100, top=100, scrollbars=yes, resizable=no, width=" + wid + ", height=" + hei + "");
}



//check to see if quickshop should be visible on page load
function checkQs(){
	theUrl = location.search.substring(1);
	if (theUrl.match("qs=open")){
		showElement('quickShop');
		clearQS();
	}
}

/* 
* This function will display catalog quick shop with focus on the input field
*/
function showQuickShop(){
        showElement('quickShop');
		clearQS();
        
}

function clearQS(){
	var prodCode = getObj("productCode");
	    if (prodCode != null){
			prodCode.value ="";
			prodCode.focus();
		}
}

/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length>mlength)
    obj.value=obj.value.substring(0,mlength)
}

/****************************************************
* This function will disable the enter key from submitting the form
****************************************************/

function disableEnterKey(e)
{
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}



/* this function will set the href url base on an input value */
function setHrefURL (fieldObj, hrefObj, defURL){
    var fObj = getObj(fieldObj);
    var hObj = getObj(hrefObj);
    if (hObj != null){
     if(fObj != null && fObj.value != ""){
         hObj.href=fObj.value;
     } else {
         hObj.href=defURL;
     }
    }
}

/* this function will set the current month and year for credit card expiration */
function setCardExpirationMonth(monObj){
    var mMonth = getObj(monObj);
    if (mMonth != null ){
        if (mMonth.selectedIndex == 0){
            var curDate = new Date();
            var curMon = curDate.getMonth() + 1;
            setSelectedOption (mMonth, curMon);
        }
    }
}


/* change homepage content */
var past = '1';
function changeHp(over,which){
	if (over == 'on'){
		imgName = 'content_' + which  ;
		imgSrc = imgPath + 'txt_content_' + which + '_on_20061020.gif'
		changeImg(imgName,imgSrc);
		
		
		
		if (past != which){
			imgName = 'content_' + past  ;
			imgSrc = imgPath + 'txt_content_' + past + '_off_20061020.gif'
			changeImg(imgName,imgSrc);
			
			document.getElementById('main_' + past).style.display="none";
		}
		document.getElementById('main_' + which).style.display="block";
	} 
	if (over == 'off'){
		past = which;
	}
}

/* change homepage content - simple rollover, no main image change */
/* added by Matt Pritchard on 7/21/06 */
var past = '1';
function changeHpSimple(over,which){
	if (over == 'on'){
		imgName = 'content_' + which  ;
		imgSrc = imgPath + 'txt_content_' + which + '_on_20060721.gif'
		changeImg(imgName,imgSrc);
				
		if (past != which){
			imgName = 'content_' + past  ;
			imgSrc = imgPath + 'txt_content_' + past + '_off_20060721.gif'
			changeImg(imgName,imgSrc);
		}
	} 
	if (over == 'off'){
		past = which;
	}
}