/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

    le.ui.js - core UI objects (widgets, components, etc.)

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/

/*=========================================
    
    Shows an error popup
    
    message - The message in an HTML string
    
=========================================*/
function showErrorPopup(message) {
    var errorPopup = document.getElementById("popError");
    var errorText = document.getElementById("popErrorMessage");
    var errorButton = document.getElementById("popErrorButton").getElementsByTagName("img")[0];
    errorButton.onclick = function () {
        hide(errorPopup);
        hide(document.getElementById(errorPopup.id + "Mask"));
    };
    errorText.innerHTML = message;
    show(document.getElementById(errorPopup.id + "Mask"))
    show(errorPopup);
    movePopupLayer(errorPopup);
}

/*===================================================

    Moves the error popup to the middle of the screen
    and keeps it there.

===================================================*/
function movePopupLayer(divToMove) {
    var myWidth = 0;
    var myHeight = 0;
    var myScrollY = 0;
    // the IFRAME that is used for the mask should be named somethingMask (i.e., popErrorMask)
    var maskObject = document.getElementById(divToMove.id + "Mask");
    
    if (typeof (window.innerWidth) == "number") {
		//Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else {
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
                myWidth = document.body.clientWidth;
                myHeight = document.body.clientHeight;
            }
        }
    }
    
    // Find out how far the user has scrolled in order to position the div at the correct height
    if (window.pageYOffset) {
        myScrollY = window.pageYOffset;
    } else if (document.body.scrollTop && document.body.scrollTop > 0) {
        myScrollY = document.body.scrollTop;
    } else if (document.documentElement.scrollTop && document.documentElement.scrollTop > 0) {
        myScrollY = document.documentElement.scrollTop;
    }
    
    divToMove.style.left = Math.round(myWidth / 2 - divToMove.offsetWidth / 2) + "px";
    divToMove.style.top = Math.round((myHeight / 2 - divToMove.offsetHeight / 2) + myScrollY) + "px";
    applyLayerMask(divToMove, maskObject);
    show(maskObject);
}

/*===========================================================================

    This is a fix for MS IE 5.5+ where form elements punch through all layers
    of divs that cover them.  The applyLayerMask moves an IFRAME between the
    layers and the form elements to prevent the punch-through. Since this
    doesn't break on any other browsers, it's used for all popup layers. I
    don't like branching code based on browser quirks.

    divToMask - the layer having the problem
    maskObject - the IFRAME object used to fix the problem
    
============================================================================*/
function applyLayerMask(divToMask, maskObject) {
    maskObject.style.position = "absolute";
    maskObject.style.top = divToMask.offsetTop;
    maskObject.style.left = divToMask.offsetLeft;
    maskObject.style.height = divToMask.offsetHeight + "px";
    maskObject.style.width = divToMask.offsetWidth + "px";
}

function fixLivePerson(){
    try{
        var tempObject=document.getElementById("myLayer");
        var maskObject=document.getElementById("livePersonMask");
        
        applyLayerMask(tempObject, maskObject);
    }
    catch(exception){
        
    }
    var t=setTimeout("fixLivePerson()",60);
}

// Builds rturn to my school link in Index and Product pages.
function buildReturnToMySchoolLink() {
	var returnToMySchool = document.getElementById("returnToMySchool");
	var linkOutSideSchool = document.getElementById("linkOutSideSchool");
	var customSchoolNum = readCookie("customSchoolNumber");
	if(customSchoolNum != null && customSchoolNum != "") {
		var link = "/ix/school-uniforms/index.html?tab=13&seq=1&page=1&pageSize=12&store=le&schoolStoreNum="+customSchoolNum;
		if(linkOutSideSchool != null) {
			linkOutSideSchool.innerHTML = '<a href=\"'+link+'\" class="btn-spaNEW" style="text-decoration: none;">Back to my School</a>';
		} else if(returnToMySchool != null) {
			returnToMySchool.innerHTML = '<a href=\"'+link+'\">« return to my school</a>';
		}	
	} 
}
/****************************************************************************************
* 							Start Ratings and Reviews									*
*****************************************************************************************/
function showBazaarVoice(newBuyGridKey, currentBuyGridNumber) {
	var bVDiv = document.getElementById("BV_prd_" + currentBuyGridNumber);
	var bVTxt = "";
	if(bVDiv != null) {
		bVTxt = bVDiv.innerHTML;
		bVDiv.innerHTML = "";
	}
	for(i=0;i<stylesSet.length;i++) {
		if("x" + stylesSet[i] == newBuyGridKey) {
			bVDiv = document.getElementById("BV_prd_" + newBuyGridKey);
			if(bVDiv != null) {
				bVDiv.innerHTML = bVTxt;
			}	
		}
	}	
}

function showIndexRatings(avgRating, productNumber, reviewLink) {
	if((ratings.leActive && !location.host.match("canvas")) || (ratings.canvasActive && location.host.match("canvas"))) {
		document.getElementById("indexProductRating_"+productNumber).innerHTML = 
			"<span class=\"ratings_label\">Rating</span> <a id=\"indexRating_" + productNumber + 
			"\" href=" + reviewLink + " class=\"boats_0\" ><span></span></a>";
		var indexRating = document.getElementById("indexRating_"+productNumber);
		avgRating = Math.round(avgRating);
		indexRating.className = "boats_"+avgRating;
	} else {
		document.getElementById("indexProductRating_"+productNumber).className="";
	}
}

function bvCssAction() {
	document.getElementById("BVReviewsContainer").className = "";
	document.getElementById("BVCustomerRatings").className = "";

}
/****************************************************************************************
* 							End Ratings and Reviews	     								*
*****************************************************************************************/
