var hideTimer;
function showInlineViewer(viewerID, displayMillis)
{
        var cartHead = document.getElementById("cartHeader");
	var viewer = document.getElementById(viewerID);
        cartHead.style.backgroundImage="url(/media/images/cart_bg_2.gif)";
        viewer.style.display="block";
	waitInlineViewer(viewerID, displayMillis);
}
// Keeps the inline viewer specified by [viewerID] from hiding by removing it's display timeout.
function stayInlineViewer()
{
	clearTimeout(hideTimer);
}
// Hides the inline viewer specified by [viewerID] after a duration of [hideInMillis].
function waitInlineViewer(viewerID, hideInMillis)
{
	stayInlineViewer();
	hideTimer = setTimeout("hideInlineViewer('" + viewerID + "');", hideInMillis);
}
// Uses the Aculo "SlideUp" effect to hide the inline viewer specified by [viewerID].  
function hideInlineViewer(viewerID)
{
    var cartHead = document.getElementById("cartHeader");
    var viewer = document.getElementById(viewerID);
    stayInlineViewer();
    viewer.innerHTML = "";
    viewer.style.display = "none";
    cartHead.style.backgroundImage="url(/media/images/cart_bg.gif)";

}

function removeErrorHTML(errorID) {
    if (document.getElementById(errorID)!=null) {
       var errorMessage = document.getElementById(errorID);
       errorMessage.innerHTML = "";
    }
}

function removeDotFlash(elementID, newClass) {
    var element = document.getElementById(elementID);
    if (element != null) {
        element.setAttribute("class", newClass); //For Most Browsers
        element.setAttribute("className", newClass); //For IE; harmless to other browsers.
    }
}

function  initQtyFeatureItem() {
    if (document.getElementsByName("ADD_CART_ITEM_ARRAY<>quantity").length == 1) {
        var elem = document.getElementsByName("ADD_CART_ITEM_ARRAY<>quantity");
        if (elem != null) {
             setFeatureItemCartQty(elem[0].id); 
        }
     }
}

function blankPersonalization() {
    if (document.getElementsByName("ADD_CART_ITEM_ARRAY<>ATR_crt_txt_personalization").length == 1) {
        var elem = document.getElementsByName("ADD_CART_ITEM_ARRAY<>ATR_crt_txt_personalization");
        if (elem != null) {
            elem[0].value="";
        }
    }
}

function addToCartInline(formID, submitID, viewerID)
{
	if (checkCartQty(formID) && validateCartQty(formID) && checkPersonalization(formID)=="")
	{        
		//document.getElementById(formID).<%= AppConstants.PARAM_INLINE_VIEWER_SUBMIT_ID %>.value = submitID;
		var script = "if(xmlhttp.responseText.match('<!-- START CART UPDATE -->') == null) { window.location = '/home/home.jsp'; } else {";
		script += "document.getElementById('" + viewerID + "').innerHTML = xmlhttp.responseText;";
		script += " showInlineViewer('" + viewerID + "', 5000);";
		//script += "clearFormFields('" + formID + "', 'quantity');";
		script += "document.getElementById('" + formID + "').reset();";
		script += "document.getElementById('cart_summary_header').innerHTML = document.getElementById('cart_summary_viewer').innerHTML;";
                script += "initQtyFeatureItem();blankPersonalization();";
		script += "window.clearTimeout(iTimerID1); window.clearTimeout(iTimerID2); StartSessionTimerToDisplay(); }";
                submitForm(formID, submitID, '/order/service/svc_cart_update.jsp', script);
                removeErrorHTML("error_div");
                removeDotFlash("dotFlash", "dotFlashHide");
		itemsInCart = true;
	}
	else
	{
                okToSubmit=true;
	}
}
function addToCartInlineWishList(formID, submitID, viewerID, wlDivID)
{
	if (  checkCartQty(formID) && validateCartQtyWishlist(formID, wlDivID) )
        {
		var script = "if(xmlhttp.responseText.match('<!-- START CART UPDATE -->') == null) { window.location = '/home/home.jsp'; } else {";
		script += "document.getElementById('" + viewerID + "').innerHTML = xmlhttp.responseText;";
		script += " showInlineViewer('" + viewerID + "', 5000);";
		script += "document.getElementById('" + formID + "').reset();";
		script += "document.getElementById('cart_summary_header').innerHTML = document.getElementById('cart_summary_viewer').innerHTML;";
		script += "window.clearTimeout(iTimerID1); window.clearTimeout(iTimerID2); StartSessionTimerToDisplay(); }";
                submitFormWishList(formID, submitID, wlDivID, '/order/service/svc_cart_update.jsp', script);
                removeErrorHTML("error_div");
		itemsInCart = true;
	}
	else
	{
                okToSubmit=true;
	}
}
