
function showConfigurator(val) {
    var myWidth = 0, myHeight = 0;
    if (document.height) {
        myHeight = document.height + "px";
        myWidth = document.width + "px";
    } else {
        if (document.all) {
            if (document.compatMode && document.compatMode != "BackCompat") {
				myHeight = document.documentElement.scrollHeight + "px";
                myWidth = document.documentElement.scrollWidth + "px";
            } else {
				myHeight = document.body.scrollHeight + "px";
                myWidth = document.body.scrollWidth + "px";
            }
        }
    }
    mask = document.getElementById("detailMask");
    if (mask.style.visibility == "visible" || val != "position") {
        mask.style.width = myWidth;
        mask.style.height = myHeight;
    }
    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;
            }
        }
    }
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == "number") {
        //Netscape compliant
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else {
        if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
        //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else {
            if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
        //IE6 standards compliant mode
                scrOfY = document.documentElement.scrollTop;
                scrOfX = document.documentElement.scrollLeft;
            }
        }
    }
    config = document.getElementById("productConfigurator");
    if (config.style.visibility == "visible" || val != "position") {
        config.style.left = ((myWidth - config.clientWidth) / 2) + 'px';
		//config.style.left = ((myWidth * 0.25) / 2) + scrOfX;
        //config.style.top = ((myHeight * 0.1) / 2) + scrOfY;
    }
    //config.style.width = myWidth * 0.75;
    //config.style.height = myHeight * 0.9;
    prodOpt = document.getElementById("productOptions");
    configHeader = document.getElementById("configuratorHeader");
    configHeader.style.height = myHeight * 0.9 * 0.1;
    configBody = document.getElementById("configuratorBody");
    //configBody.style.height = myHeight * 0.9 * 0.85;
    configFooter = document.getElementById("configuratorFooter");
    configFooter.style.height = myHeight * 0.9 * 0.05;
    if (val != "position") {
        mask.style.visibility = (mask.style.visibility == "visible") ? "hidden" : "visible";
        prodOpt.style.visibility = (mask.style.visibility == "visible") ? "hidden" : "visible";
        config.style.visibility = (config.style.visibility == "visible") ? "hidden" : "visible";
        showPersonalizationSection("NONE");
    }
    if (val == "open") {
        var engravingCode = document.getElementById("engravingCode");
        if (engravingCode != null) {
	        document.getElementById('engravingOption').value = engravingCode.value;
	        showEngravingDiv(engravingCode.value);
        }
        var logoCode = document.getElementById("logoCode");
        if (logoCode != null) {
	        document.getElementById("logoOption").value = logoCode.value;
	        showLogoDiv(logoCode.value);
        }
        var messageCode = document.getElementById("messageCode");
        if (messageCode != null) {
	        document.getElementById("messageOption").value = messageCode.value;
	        showMessageDiv(messageCode.value);
        }
        if (engravingCode != null || logoCode != null || messageCode != null) {
        	loadSkuDetails();
    	}
        var engrButton = document.getElementById("ENGRTabButton");
        var logoButton = document.getElementById("LOGOTabButton");
        var mesgButton = document.getElementById("MESGTabButton");
        if (mesgButton != null && mesgButton.style.display != "none") {
            showPersonalizationSection("MESG");
        }
        if (logoButton != null && logoButton.style.display != "none") {
            showPersonalizationSection("LOGO");
        }
        if (engrButton != null && engrButton.style.display != "none") {
            showPersonalizationSection("ENGR");
        }
        if(null!=document.getElementById('personalizationOptionTypeId')){
            var personalizationOptionTypeId = document.getElementById('personalizationOptionTypeId').value;
            var personalizationDefaultIndex = document.getElementById(personalizationOptionTypeId).selectedIndex;
            document.getElementById('defaultPersonalizationIndex').value = personalizationDefaultIndex;
        }
    }
}
function reloadSkuDetails(productPk,imageUrl) {
	var skuOptions = document.getElementById("optionTypeValues_" + productPk).value;
	var engraving;
	var message; 
	if(document.getElementById('engraving')){
		engraving = document.getElementById('engraving').value;
	}
	if(document.getElementById('message')){
		message = document.getElementById('message').value;
	}
    var actionUrl = "/p2p/configurator/personalizationSkuDetails.do?qty=" + document.getElementById("qty").value + "&productPk=" + productPk + "&skuOptions=" + skuOptions;
    if(document.getElementById('engravingCode') && document.getElementById('engravingCode').value == 'FORM') actionUrl = actionUrl + '&engrForm=true';
	if(document.getElementById('engraving') && document.getElementById('engraving').value == 'true'&& document.getElementById('engravingCode').value == 'FORM'){
		actionUrl = actionUrl + '&engraving='+engraving;
	}else{
		actionUrl = actionUrl + '&engraving=false';
	}
	if(document.getElementById('messageCode') && document.getElementById('messageCode').value == 'FORM'){
		actionUrl = actionUrl + '&message='+message;
	}else{
		actionUrl = actionUrl + '&message=false';
	}
    actionUrl = actionUrl + imageUrl;
    sendAjaxRequest(actionUrl, "skuInfo");
}

function showPersonalizationSection(code) {
    var logoTab = document.getElementById("logoTab");
    var messageTab = document.getElementById("messageTab");
    var engravingTab = document.getElementById("engravingTab");
    if (code == "ENGR") {
        if (engravingTab != null) {
            engravingTab.style.display = "block";
            if (document.getElementById('yosTab').value==1)
                YOSTabButtonOn();
            else
                ENGRTabButtonOn();
        }
        if (logoTab != null) {
            logoTab.style.display = "none";
            LOGOTabButtonOff();
        }
        if (messageTab != null) {
            messageTab.style.display = "none";
            MESGTabButtonOff();
        }
    } else {
        if (code == "LOGO") {
            if (logoTab != null) {
                logoTab.style.display = "block";
                LOGOTabButtonOn();
            }
            if (engravingTab != null) {
                engravingTab.style.display = "none";
                if (document.getElementById('yosTab').value==1)
                    YOSTabButtonOff();
                else
                    ENGRTabButtonOff();
            }
            if (messageTab != null) {
                messageTab.style.display = "none";
                MESGTabButtonOff();
            }
        } else {
            if (code == "MESG") {
                if (messageTab != null) {
                    messageTab.style.display = "block";
                    MESGTabButtonOn();
                }
                if (engravingTab != null) {
                    engravingTab.style.display = "none";
                    if (document.getElementById('yosTab').value==1)
                        YOSTabButtonOff();
                    else
                        ENGRTabButtonOff();
                }
                if (logoTab != null) {
                    logoTab.style.display = "none";
                    LOGOTabButtonOff();
                }
            } else {
                if (code == "NONE") {
                    if (engravingTab != null) {
                        engravingTab.style.display = "none";
                    }
                    if (logoTab != null) {
                        logoTab.style.display = "none";
                    }
                    if (messageTab != null) {
                        messageTab.style.display = "none";
                    }
                }
            }
        }
    }
}
function showEngravingDiv(code) {
    var engravingFORM = document.getElementById("engravingFORM");
    var engravingFILE = document.getElementById("engravingFILE");
    var engravingLATE = document.getElementById("engravingLATE");
    var engravingNONE = document.getElementById("engravingNONE");
    if (code == "FORM") {
        if (engravingFORM != null) {
            engravingFORM.style.display = "block";
        }
        if (engravingFILE != null) {
            engravingFILE.style.display = "none";
        }
        if (engravingLATE != null) {
            engravingLATE.style.display = "none";
        }
        if (engravingNONE != null) {
            engravingNONE.style.display = "none";
        }
    } else {
        if (code == "FILE") {
            if (engravingFORM != null) {
                engravingFORM.style.display = "none";
            }
            if (engravingFILE != null) {
                engravingFILE.style.display = "block";
            }
            if (engravingLATE != null) {
                engravingLATE.style.display = "none";
            }
            if (engravingNONE != null) {
                engravingNONE.style.display = "none";
            }
        } else {
            if (code == "LATE") {
                if (engravingFORM != null) {
                    engravingFORM.style.display = "none";
                }
                if (engravingFILE != null) {
                    engravingFILE.style.display = "none";
                }
                if (engravingLATE != null) {
                    engravingLATE.style.display = "block";
                }
                if (engravingNONE != null) {
                    engravingNONE.style.display = "none";
                }
            } else {
                if (engravingFORM != null) {
                    engravingFORM.style.display = "none";
                }
                if (engravingFILE != null) {
                    engravingFILE.style.display = "none";
                }
                if (engravingLATE != null) {
                    engravingLATE.style.display = "none";
                }
                if (engravingNONE != null) {
                    engravingNONE.style.display = "block";
                }
            }
        }
    }
}
function showLogoDiv(code) {
    var logoFILE = document.getElementById("logoFILE");
    var logoLATE = document.getElementById("logoLATE");
    if (code == "FILE") {
        if (logoFILE != null) {
            logoFILE.style.display = "block";
        }
        if (logoLATE != null) {
            logoLATE.style.display = "none";
        }
    } else {
        if (code == "LATE") {
            if (logoFILE != null) {
                logoFILE.style.display = "none";
            }
            if (logoLATE != null) {
                logoLATE.style.display = "block";
            }
        } else {
            if (logoFILE != null) {
                logoFILE.style.display = "none";
            }
            if (logoLATE != null) {
                logoLATE.style.display = "none";
            }
        }
    }
}
function showMessageDiv(code) {
    var messageFORM = document.getElementById("messageFORM");
    var messageFILE = document.getElementById("messageFILE");
    var messageLATE = document.getElementById("messageLATE");
    var messageVERSE = document.getElementById("messageVERSE");
    if (code == "FORM") {
        if (messageFORM != null) {
            messageFORM.style.display = "block";
        }
        if (messageFILE != null) {
            messageFILE.style.display = "none";
        }
        if (messageLATE != null) {
            messageLATE.style.display = "none";
        }
        if (messageVERSE != null) {
            messageVERSE.style.display = "none";
        }
    } else {
        if (code == "FILE") {
            if (messageFORM != null) {
                messageFORM.style.display = "none";
            }
            if (messageFILE != null) {
                messageFILE.style.display = "block";
            }
            if (messageLATE != null) {
                messageLATE.style.display = "none";
            }
            if (messageVERSE != null) {
                messageVERSE.style.display = "none";
            }
        } else {
            if (code == "LATE") {
                if (messageFORM != null) {
                    messageFORM.style.display = "none";
                }
                if (messageFILE != null) {
                    messageFILE.style.display = "none";
                }
                if (messageLATE != null) {
                    messageLATE.style.display = "block";
                }
                if (messageVERSE != null) {
                    messageVERSE.style.display = "none";
                }
            } else {
                if (code == "VERSE") {
                    if (messageFORM != null) {
                        messageFORM.style.display = "none";
                    }
                    if (messageFILE != null) {
                        messageFILE.style.display = "none";
                    }
                    if (messageLATE != null) {
                        messageLATE.style.display = "none";
                    }
                    if (messageVERSE != null) {
                        messageVERSE.style.display = "block";
                    }
                } else {
                    if (messageFORM != null) {
                        messageFORM.style.display = "none";
                    }
                    if (messageFILE != null) {
                        messageFILE.style.display = "none";
                    }
                    if (messageLATE != null) {
                        messageLATE.style.display = "none";
                    }
                    if (messageVERSE != null) {
                        messageVERSE.style.display = "none";
                    }
                }
            }
        }
    }
}
function setPersonalizationOptionValue(elementId) {
    var oSelect = document.getElementById(elementId);
    if (oSelect == null) {
        return "optionTypeNotFound";
    }
    var selectedValue = getCurrentOptionSelections();
    var splitArr = selectedValue.split("_");
    var resultArr = new Array("", "", "");
    var insertIndex;
    for (var i = 0; i < splitArr.length; i++) {
        insertIndex = getInsertIndex(splitArr[i]);
        if (insertIndex != -1) {
            resultArr[insertIndex] = splitArr[i];
        }
    }
    var resultString = "";
    for (var i = 0; i < resultArr.length; i++) {
        if (resultString.length == 0) {
            resultString = resultArr[i];
        } else {
            if (resultArr[i].length != 0) {
                resultString = resultString + "_" + resultArr[i];
            }
        }
    }
    if (resultString == "") {
        resultString = "NONE";
    }
    return searchForSku(oSelect, resultString);
}
function getCurrentOptionSelections(){
    var engravingOption = document.getElementById('engravingOption');
    var logoOption = document.getElementById('logoOption');
    var messageOption = document.getElementById('messageOption');
    var selectedOptions = '';
    if(engravingOption && engravingOption.value != 'NONE' && engravingOption.value != '') selectedOptions = 'ENGR';
    if(logoOption && logoOption.value != 'NONE' && logoOption.value != '') selectedOptions = selectedOptions + '_LOGO';
    if(messageOption && messageOption.value != 'NONE' && messageOption.value != '') selectedOptions = selectedOptions + '_MESG';
    return selectedOptions;
}
function getSkuCount(oSelect, resultString) {
    var count = 0;
    var splitResult = resultString.split("_");
    for (var i = 0; i < oSelect.options.length; i++) {
        var matchingSku = true;
        for (var j = 0; j < splitResult.length; j++) {
            if (oSelect.options[i].text.indexOf(splitResult[j]) == -1 || oSelect.options[i].text.indexOf("Unavailable") != -1) {
                matchingSku = false;
            }
        }
        if (matchingSku) {
            count++;
        }
    }
    return count;
}
function getSkuIndex(oSelect, resultString) {
    for (var i = 0; i < oSelect.options.length; i++) {
        if (oSelect.options[i].text == resultString) {
            return i;
        }
    }
    return -1;
}
function getAnyMatchingSkuIndex(oSelect, resultString) {
	var splitResult = resultString.split("_");
    for (var i = 0; i < oSelect.options.length; i++) {
		var matchingSku = true;
        for (var j = 0; j < splitResult.length; j++) {
			if (oSelect.options[i].text.indexOf(splitResult[j]) == -1 || oSelect.options[i].text.indexOf("Unavailable") != -1) {
				matchingSku = false;
			}
		}
		if(matchingSku){
			return i;
		}
    }
    return -1;
}
function showAllPersonalizationTabs() {
    var engrButton = document.getElementById("ENGRTabButton");
    var logoButton = document.getElementById("LOGOTabButton");
    var mesgButton = document.getElementById("MESGTabButton");
    var currentProductHasYOS = document.getElementById("currentProductHasYOS");
    if (engrButton != null) {
        engrButton.style.display = "inline";
    }
    if (logoButton != null) {
        logoButton.style.display = "inline";
    }
    if (mesgButton != null) {
        mesgButton.style.display = "inline";
    }
    if(currentProductHasYOS && currentProductHasYOS.value == "true"){
        disableEngravingOptions(false);
    }
}
function showPersonalizationTabs(filterString) {
    var engrButton = document.getElementById("ENGRTabButton");
    var logoButton = document.getElementById("LOGOTabButton");
    var mesgButton = document.getElementById("MESGTabButton");
    var currentProductHasYOS = document.getElementById("currentProductHasYOS");
    if (engrButton != null) {
        engrButton.style.display = "none";
    }
    if (logoButton != null) {
        logoButton.style.display = "none";
    }
    if (mesgButton != null) {
        mesgButton.style.display = "none";
    }
    var custArr = filterString.split("_");
    for (var i = 0; i < custArr.length; i++) {
        var code = custArr[i];
        if (code != "NONE" && code != "" && code != null) {
            document.getElementById(code + "TabButton").style.display = "inline";
        }
    }
    if(currentProductHasYOS && currentProductHasYOS.value == "true"){
        if(engrButton.style.display == "none"){
            disableEngravingOptions(true);
            engrButton.style.display = "inline";
        } else {
            disableEngravingOptions(false);
        }
    }
}
function searchForSku(oSelect, resultString) {
    var currentSkuIndex = getSkuIndex(oSelect, resultString);
    var count = getSkuCount(oSelect, resultString);
    var error = document.getElementById("skuNotFoundError");
    var filterString = "";
    var newIndex = 9999;
    if (count == 0) {
        if (error != null) {
            error.style.display = "block";
        }
        document.getElementById('tempCustomization').value = '';
        oSelect.selectedIndex = document.getElementById('defaultPersonalizationIndex').value;
        showAllPersonalizationTabs();
        return "skuNotFound";
    } else if (currentSkuIndex != -1) {
            var splitResult = resultString.split("_");
            for (var i = 0; i < oSelect.options.length; i++) {
                var matchingSku = true;
                for (var j = 0; j < splitResult.length; j++) {
                    if (oSelect.options[i].text.indexOf(splitResult[j]) == -1 || oSelect.options[i].text.indexOf("Unavailable") != -1) {
                        matchingSku = false;
                    }
                }
                if (matchingSku) {
                    filterString = filterString + "_" + oSelect.options[i].text;
                }
            }
            oSelect.selectedIndex = currentSkuIndex;
            document.getElementById('tempCustomization').value = '';
    } else {
        currentSkuIndex = getAnyMatchingSkuIndex(oSelect, resultString);
        if(currentSkuIndex != -1){
            oSelect.selectedIndex = currentSkuIndex;
        }
        var splitResult = resultString.split("_");
        for (var i = 0; i < oSelect.options.length; i++) {
            var matchingSku = true;
            for (var j = 0; j < splitResult.length; j++) {
                if (oSelect.options[i].text.indexOf(splitResult[j]) == -1 || oSelect.options[i].text.indexOf("Unavailable") != -1) {
                    matchingSku = false;
                }
            }
            if (matchingSku) {
                filterString = filterString + "_" + oSelect.options[i].text;
            }
        }
        document.getElementById('tempCustomization').value = resultString; 
    }
    if (resultString != "NONE") {
        showPersonalizationTabs(filterString);
    } else {
        showAllPersonalizationTabs();
    }
    if (currentSkuIndex!=-1) {
        return "skuFound";
    } else {
        oSelect.selectedIndex = document.getElementById('defaultPersonalizationIndex').value;
        return "skuNotFound";
    }
}
function getInsertIndex(code) {
    if (code == "ENGR") {
        return 0;
    } else {
        if (code == "LOGO") {
            return 1;
        } else {
            if (code == "MESG") {
                return 2;
            } else {
                return -1;
            }
        }
    }
}
function copyLineItems(qty, itemCount) {
    if (document.getElementById("line_" + 1 + "_" + 1) != null) {
        for (var qtyIdx = 2; qtyIdx <= qty; qtyIdx++) {
            for (var itemIdx = 1; itemIdx <= itemCount; itemIdx++) {
                document.getElementById("line_" + qtyIdx + "_" + itemIdx).value = document.getElementById("line_" + 1 + "_" + itemIdx).value;
            }
        }
    }
    if (document.getElementById("yos_" + 1) != null) {
        for (var qtyIdx = 2; qtyIdx <= qty; qtyIdx++) {
            document.getElementById("yos_" + qtyIdx).value = document.getElementById("yos_" + 1).value;
            document.getElementById("yos_" + qtyIdx + "_dummy").value = document.getElementById("yos_" + 1).value;
        }
    }
}
function sendAjaxRequest(url, divId) {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4) {
            document.getElementById(divId).innerHTML = xmlHttp.responseText;
        }
    };
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}
function closeConfigurator() {
    confirmed = window.confirm("Are you sure you want to close the Personalization options window? Any changes you have made to the product will be lost if you Continue");
    if (confirmed) {
        document.getElementById("detailMask").style.visibility = "hidden";
        document.getElementById("productConfigurator").style.visibility = "hidden";
        if(document.getElementById('ENGRTabButton'))
            document.getElementById('ENGRTabButton').parentNode.parentNode.style.visibility="hidden";
        if(document.getElementById('LOGOTabButton'))
            document.getElementById('LOGOTabButton').parentNode.parentNode.style.visibility="hidden";
        if(document.getElementById('MESGTabButton')) 
            document.getElementById('MESGTabButton').parentNode.parentNode.style.visibility="hidden";
        prodOpt = document.getElementById("productOptions");
        prodOpt.style.visibility = (mask.style.visibility == "visible") ? "hidden" : "visible";
    } else {
        prodOpt = document.getElementById("productOptions");
        prodOpt.style.visibility = (mask.style.visibility == "visible") ? "hidden" : "visible";
        document.getElementById("productConfigurator").style.visibility = "visible";
    }
}

function rollDownCart(rollDownTime){
    var fireOnThis = null;
    for(var i=0; i<100; i++){
        fireOnThis = document.getElementById('el'+i);
        if(fireOnThis != null){
            break;
        }
    }
    if(fireOnThis != null){
        if( document.createEvent ) {
            var evObj = document.createEvent('MouseEvents');
            evObj.initEvent( 'mouseover', true, false );
            fireOnThis.dispatchEvent(evObj);
        } else if( document.createEventObject ) {
            fireOnThis.fireEvent('onmouseover');
        }
        var t=setTimeout("rollUpCart()",rollDownTime);
    }
}

function rollUpCart(){
    var fireOnThis = null;
    for(var i=0; i<100; i++){
        fireOnThis = document.getElementById('el'+i);
        if(fireOnThis != null){
            break;
        }
    }
    if(fireOnThis != null){
        if( document.createEvent ) {
            var evObj = document.createEvent('MouseEvents');
            evObj.initEvent( 'mouseout', true, false );
            fireOnThis.dispatchEvent(evObj);
        } else if( document.createEventObject ) {
            fireOnThis.fireEvent('onmouseout');
        }
    }
}

function buildImageUrl(msgLineItemCount, engrLineItemCount){
	var imageUrl = '';
	var verseElem = document.getElementById('verse');
    var messageOptionElem = document.getElementById('messageOption');
    var logoOptionElem = document.getElementById('logoOption');
    var engravingOptionElem = document.getElementById('engravingOption');
    var imprintColorElem = document.getElementById('imprintColorId');
	var qtyIndexElem = document.getElementById('previewedEngravingIndex');
	
    var engElem = '';
	var engValue = '';
    var msgValue = '';
    var messageOption = '';
    var engravingOption = '';
    var engrQtyIndex = 1;
    if(verseElem) imageUrl = imageUrl + '&verse=' + verseElem.value;
    if(logoOptionElem) imageUrl = imageUrl + '&logoOption=' + logoOptionElem.value;
    if(imprintColorElem) imageUrl = imageUrl + '&imprintColor=' + imprintColorElem.value;
    if(qtyIndexElem) engrQtyIndex = qtyIndexElem.value;
	if(engravingOptionElem) {
    	engravingOption = engravingOptionElem.value;
    	imageUrl = imageUrl + '&engravingOption=' + engravingOption;
    }
    
    if(messageOptionElem) {
    	messageOption = messageOptionElem.value;
    	imageUrl = imageUrl + '&messageOption=' + messageOption;
    }
    
    if (msgLineItemCount && messageOption == 'FORM') {
    	msgLineItemCount = parseInt(msgLineItemCount);
        for (var j = 1; j <= msgLineItemCount; j++) {
        	msgValue = eval('document.getElementById("line_' + j + '").value');
			imageUrl += '&msg_'+j+'='+encodeURIComponent(msgValue);
        }
    }
      if (engrQtyIndex){
	     if (engrLineItemCount && engravingOption == 'FORM'){
	     	engrLineItemCount = parseInt(engrLineItemCount);
	    	for (var j = 1; j <= engrLineItemCount; j++) {
	            engElem = eval('document.getElementById("line_' + engrQtyIndex + '_' + j + '")');
				if (engElem){
					engValue = engElem.value;
					imageUrl += '&eng_'+j+'='+encodeURIComponent(engValue);
				}
			}
        }
        var yosElem = document.getElementById('yos_'+engrQtyIndex);
        if (yosElem) imageUrl+='&yos='+yosElem.value;
        
    }
	return imageUrl;
}

function previewMessage(msgLineItemCount,engrLineItemCount,productPk) {
	reloadSkuDetails(productPk,buildImageUrl(msgLineItemCount,engrLineItemCount));
}


function previewEngraving(msgLineItemCount,qtyIndex, engrLineItemCount,productPk) {
	document.getElementById('previewedEngravingIndex').value = qtyIndex;
	var currentProductHasYOS = document.getElementById("currentProductHasYOS").value;
	if(currentProductHasYOS!="true"){
	document.getElementById('engraving').value="true";
	}
	reloadSkuDetails(productPk,buildImageUrl(msgLineItemCount,engrLineItemCount));
}

function getX(){
    var myWidth = 0;
    if (typeof (window.innerWidth) == "number") {
    //Non-IE
        myWidth = window.innerWidth;
    } else {
        if (document.documentElement && document.documentElement.clientWidth) {
        
    //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
        } else {
            if (document.body && document.body.clientWidth) {
            
    //IE 4 compatible
                myWidth = document.body.clientWidth;
            }
        }
    }
    var scrOfX = 0;
    if (typeof (window.pageXOffset) == "number") {
        scrOfX = window.pageXOffset;
    } else {
        if (document.body && document.body.scrollLeft) {
        //DOM compliant
            scrOfX = document.body.scrollLeft;
        } else {
            if (document.documentElement && document.documentElement.scrollLeft) {
        //IE6 standards compliant mode
                scrOfX = document.documentElement.scrollLeft;
            }
        }
    }
    return myWidth/2 + scrOfX;
}

function getY(){
    var myHeight = 0;
    if (typeof (window.innerHeight) == "number") {
    //Non-IE
        myHeight = window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
        
    //IE 6+ in 'standards compliant mode'
            myHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
            
    //IE 4 compatible
                myHeight = document.body.clientHeight;
            }
        }
    }
    var scrOfX = 0, scrOfY = 0;
    if (typeof (window.pageYOffset) == "number") {
        //Netscape compliant
        scrOfY = window.pageYOffset;
    } else {
        if (document.body && document.body.scrollTop) {
        //DOM compliant
            scrOfY = document.body.scrollTop;
        } else {
            if (document.documentElement && document.documentElement.scrollTop) {
        //IE6 standards compliant mode
                scrOfY = document.documentElement.scrollTop;
            }
        }
    }
    return myHeight/2 + scrOfY;
}

function showOrHideMask(showMask){
    mask = document.getElementById("detailMask");
    if(showMask){
        mask.style.visibility = "visible";
        var myWidth = 0, myHeight = 0;
        if (document.height) {
            myHeight = document.height + "px";
            myWidth = document.width + "px";
        } else {
            if (document.all) {
                if (document.compatMode && document.compatMode != "BackCompat") {
                    myHeight = document.documentElement.scrollHeight + "px";
                    myWidth = document.documentElement.scrollWidth + "px";
                } else {
                    myHeight = document.body.scrollHeight + "px";
                    myWidth = document.body.scrollWidth + "px";
                }
            }
        }
        mask.style.width = myWidth;
        mask.style.height = myHeight;
    }else{
        mask.style.visibility = "hidden";
    }
}
