﻿//Add common javascript code here, please comment all functions


//**************************************************************//
//Makes input control (form control) a highlighted color.  Works
//specifically for textboxes and textareas.
//
//--------------------------------------------------------------//
function toggleActiveControl(control) {
    
    var activeClassName = "input_active";
            
    if(control.className != activeClassName) {
        control.className = activeClassName;    
    }
    else {
        control.className = "input"; 
    }
            
}

//**************************************************************//


//**************************************************************//
//Preloads images for a page to correct wait time when displaying 
//hidden/new images
//
//imgPathArray = string array of img paths to preload 
//--------------------------------------------------------------//
function preloadImages(imgPathArray) {
    for(i=0;i<imgPathArray.length;i++) {
        var img = new Image();
        img.src = imgPathArray[i];
    }
}
//**************************************************************//


//**************************************************************//
//Helper function for adding textbox activate/inactivate event listeners
//
//obj = the object (textbox/input box) to perform action on
//--------------------------------------------------------------//
function doHelperAddTextboxEventListeners(obj) {
    if (obj.addEventListener) {
       obj.addEventListener("focus", function () {doActivateInput(this);}, false);
       obj.addEventListener("blur", function () {doDeactivateInput(this);}, false); 
    } 
    else if (obj.attachEvent) {
       obj.onfocus = function () {doActivateInput(obj);};
       obj.onblur = function () {doDeactivateInput(obj);};
    }
}
//**************************************************************//


//**************************************************************//
//Helper function for adding buttons hover state event listeners
//
//obj = the object (button) to perform action on
//--------------------------------------------------------------//
function doHelperAddButtonEventListeners(obj, activeImgPath, inactiveImgPath) {
    if (obj.addEventListener) {
       obj.addEventListener("mouseover", function () {this.src=activeImgPath;}, false);
       obj.addEventListener("focus", function () {this.src=activeImgPath;}, false);
       obj.addEventListener("mouseout", function () {this.src=inactiveImgPath;}, false);
       obj.addEventListener("blur", function () {this.src=inactiveImgPath;}, false);   
    } 
    else if (obj.attachEvent) {
       obj.onmouseover = function () {this.src=activeImgPath;};
       obj.onfocus = function () {this.src=activeImgPath;};
       obj.onmouseout = function () {this.src=inactiveImgPath;};
       obj.onblur = function () {this.src=inactiveImgPath;};  
    }
}
//**************************************************************//



//**************************************************************//


//**************************************************************//
//functions to display / close overlay message throughout the site
//
//displayHTML = HTML of the overlay message
//--------------------------------------------------------------//
var styleToSelect;
        
// Add click handlers for buttons to show and hide modal popup on pageLoad
function showModalPopupViaClient(ev) {
    ev.preventDefault();
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}

function hideModalPopupViaClient(ev) {
    ev.preventDefault();        
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}

function setBodyHeightToContentHeight() {
    document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) + "px";
}


/*************************************************************************/
/*                                     Open popup without address bar    */
/*************************************************************************/
function open_popup(page, width, height) 
{
    window.open(page,'PopupWindow','width='+width+',height='+height+',resizable=no,scrollbars=no');
}

/*************************************************************************/
/*             Show UPS Tracking Number on Checkout_Confirmation page               */
/*************************************************************************/
function doLinkTracking(strTrackingNumber, strShipperNameCode) {
    if (strShipperNameCode == "FDX") {
		window.open('http://fedex.com/cgi-bin/tracking?action=track&tracknumbers=' + strTrackingNumber); 
	}
	else if (strShipperNameCode == "USPS" || strShipperNameCode == "USP") {
	    window.open('http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=' + strTrackingNumber); 
	} 
	else if (strShipperNameCode == "UPS") {
		window.open('http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion=5.0&sort_by=status&term_warn=yes&Requester=UPSHome&tracknums_displayed=5&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1=' + strTrackingNumber + '&InquiryNumber2=&InquiryNumber3=&InquiryNumber4=&InquiryNumber5=&AgreeToTermsAndConditions=yes&track.x=14&track.y=5'); 
	}
	else {
	    alert('Additional tracking details unavailable.');
	}
} 

/*************************************************************************/
/*                                                     Initial Case                                                      */
/*************************************************************************/
function changeCase(frmObj) {
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;
	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else {
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	frmObj.value = tmpStr;
}

/*************************************************************************/
/*                                  Revert and clear text on textboxes                                    */
/*************************************************************************/
function revertTextField($content,$default){
    if($content==''){
	    return $default;
    }else{
	    return $content;
    }
}

function clearTextField($content,$default){
    if($content==$default){
	    return '';
    }else{
	    return $content;
    }
}

/*************************************************************************/
/*                          Load ACS URL for Verified by Visa / MasterCard                      */
/*************************************************************************/
function loadACSURL(strMD, strACSURL, strPAREQ){
    var iframeSecure = document.getElementById("iframeSecure");
    iframeSecure.style.display = "block";
    
    //iframeSecure.src = "checkout_buyerauth_push.aspx"; 
    var frmBuyerAuth = document.getElementById("frmBuyerAuth");
    frmBuyerAuth.hdnMD.value = strMD;
    frmBuyerAuth.hdnACSURL.value = strACSURL; 
    frmBuyerAuth.hdnPaReq.value = strPAREQ;
    frmBuyerAuth.action = "checkout_buyerauth_push.aspx";
    frmBuyerAuth.target = "iframeSecure";
    frmBuyerAuth.submit();
}


/*************************************************************************/
/*                                          Functions from MM.js file                                            */
/*************************************************************************/
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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

/*************************************************************************/
/* Functions to add items to cart using javascript                       */
/*************************************************************************/
//for adding item to cart - for items with modifiers
function verifyAddToCart(strFormName, strNum, strNum1, strReturn) 
{
	var strThisFormName = 'aspnetForm';
	strNum = "selMod" + strNum;
	strNum1 = "selMod" + strNum1;
	
	try {
 		if(window.document.forms[strThisFormName][strNum].selectedIndex == 0) {
			//alert('Please select Size');
			MM_changeProp('divWarning','','innerHTML','<font color=#FF0000 face=Arial size=2><strong>You must select a Size to add this item to your cart!</strong></font>','DIV');
			window.document.forms[strThisFormName][strNum].focus();
			return;
		}
	var iSelIndex1 = window.document.forms[strThisFormName][strNum].options[window.document.forms[strThisFormName][strNum].selectedIndex].value;
	var iSelIndex2 = '';
	}
	catch(er) {
		//alert(er);
	}
	
	try {
 		if(window.document.forms[strThisFormName][strNum1].selectedIndex == 0) {
			//alert('Please select Size');
			MM_changeProp('divWarning','','innerHTML','<font color=#FF0000 face=Arial size=2><strong>You must select a Color to add this item to your cart!</strong></font>','DIV');
			window.document.forms[strThisFormName][strNum1].focus();
			return;
		}
	var iSelIndex2 = window.document.forms[strThisFormName][strNum1].options[window.document.forms[strThisFormName][strNum1].selectedIndex].value;
	}
	catch(er) {
		//alert(er);
    }

	var strArrayName;
	if (iSelIndex2 == '') {
		strArrayName = iSelIndex1 ;
	}
	else {
		strArrayName = iSelIndex1 + ":" + iSelIndex2;
	}
	

	var iItemID = vItemID[strArrayName];
	var iSubItemID = vSubItemID[strArrayName];
	var iBinLocID = vBinLocID[strArrayName];
			
	if (iSubItemID=='') {
		iSubItemID = '-1';
	}
	AddToCart(strFormName, iItemID, iSubItemID, iBinLocID, strReturn);
}

//add item to cart
function AddToCart(strFormName, strItemID, strSubItemID, strBinLocID, strReturn) 
{
	window.document.forms[strFormName]["ItemID"].value = strItemID;
	window.document.forms[strFormName]["SubItemID"].value = strSubItemID;
	window.document.forms[strFormName]["BinLocID"].value = strBinLocID;
	window.document.forms[strFormName]["ReturnURL"].value = strReturn;
	window.document.forms[strFormName].submit();
}


/*************************************************************************/
/* Show proper year at the footer					*/
/*************************************************************************/

function doClock(){ // By Paul Davis - www.kaosweaver.com
  var t=new Date(),a=doClock.arguments,str="",i,a1,lang="1";
  var month=new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
  var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
  for(i=0;i<a.length;i++) {a1=a[i].charAt(1);switch (a[i].charAt(0)) {
  case "M":if  ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
  str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
  case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
  case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
  case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[i]);}}return str;
}
