﻿var iCurrentPage = 0;

var IsNetscape = (navigator.appName.indexOf("Netscape") != -1);
var px = document.layers ? "" : "px";

var _NothingSelectedExpanded;
var _NothingSelectedCollapsed;
var _currPageSeq;
var _QS;
var _Action;
var _ValidateConfigURL;
var _IsSc;
var _Lang;
var _currScView;

var _ShowSelectionsText;
var _HideSelectionsText;
var _InPictaMode = false;

function makeWin(url) {makeWin2(url);}

function makeWin2(url, p_Width, p_Height) {
	params  = GetWindowOpenParams(92, 0, p_Width, p_Height);
	ProcessOpenWindow(url, "Sitelet", params, false);
}

function OpenDetailsPop(sName, sOrderCode, bNoCaching){
	params  = GetWindowOpenParams(0, 0, 560, 350);
	ProcessOpenWindow('details_popup.aspx?name=' + sName + '&oc=' + sOrderCode, "Sitelet", params, bNoCaching);
}

//use for posting to the lead time shipping date details page
function OpenPostedDetailsPop(url, p_Width, p_Height, bNoCaching){
	windowName = "ShipDateDetails";
	params  = GetWindowOpenParams(92, 0, p_Width, p_Height);
	document.CONFIG_FORM.target = windowName;		  
	ProcessOpenWindow(url, windowName, params, bNoCaching);
	document.CONFIG_FORM.action = url;
	document.CONFIG_FORM.submit();
}	  

function ProcessOpenWindow(url, windowName, params, noCaching)
{
	agent = navigator.userAgent;
	try{
	// close the window to vary the window size
	if (typeof(win) == "object" && !win.closed){win.close();}
	}catch(e){}
	win = OpenWindow(url, windowName, params, noCaching);
	if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) 
	win = OpenWindow(url, windowName, params, noCaching);
	try{
		if (!win.opener) {
			win.opener = window;
		}
	}catch(e){}
  	// bring the window to the front
	try{
		win.focus();	
	}catch(e){}
}

function OpenWindow(url, windowName, params, noCaching)
{
	if (noCaching == true)
		return window.open(url + '&nc=true', windowName , params);
	else
		return window.open(url, windowName , params);
}

function GetWindowOpenParams(top, left, width, height)
{
	params = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,";
	params += "top=" + top + ",";
	params += "left=" + left + ",";
	if (width) {
	 	params += "width=" + width+ ",";
		params += "height=" + height;
	}
	else {
		params += "width=590,height=350";
	}
	return params;
}

function upsell_sc(mod, opt)
{
    if (_doDynamicPricing)
    {
        var postData = '&method=upsell&newclick=' + mod + ';' + opt + ';true&upsold_list=';
	    var upsoldList = getAnElement("upsold_list");
	    if (upsoldList && upsoldList.value.length > 0)
		    postData += upsoldList.value + "," + mod.substr(2);
	    else
		    postData += mod.substr(2);
		
		postData += '&current_action=update_price&expand_list_hidden=' + getAnElement('expand_list_hidden').value;
		postData += '&collapsed_bundles_hidden=' + getAnElement('collapsed_bundles_hidden').value;
    	
 	    hideWithOpacity(getAnElement('saleonlycontainer'));
       	var resp = makeSyncAjaxCall(postData);
    	
    	ResponseFound(resp);
	    ChangeOpacityGeneric('saleonlycontainer', 5, 25); 
    }
    else
        if (getAnElement(mod))
            upgrade_selection_update_price(_currPageSeq, _Action, mod, opt);
        else
            add_selection_update_price(_currPageSeq, _Action, mod, opt);
}
function upgrade_selection_update_price(iCurrPage, sAction, mod, opt)
{
	getAnElement(mod).value = opt;
	upsell_update_price(iCurrPage, sAction, mod, opt);
}
function add_selection_update_price(iCurrPage, sAction, mod, opt)
{
    AddHiddenFormElement(mod,  opt);
	upsell_update_price(iCurrPage, sAction, mod, opt);
}
function upsell_update_price(iCurrPage, sAction, mod, opt)    
{
	AddHiddenFormElement('upsell_item',  mod + ':' + opt);

	var upsoldList = getAnElement("upsold_list");
	if (upsoldList.value.length > 0)
		upsoldList.value += "," + mod.substr(2);
	else
		upsoldList.value = mod.substr(2);
	update_price(iCurrPage, sAction);
}

function update_composite_config(iCurrPage, sAction, parent, parentName, childName)
{
	var obj = getElementsForCC(childName);

	if (parent.checked)
	{
		//close out other single select options first
		if (parent.type=="radio")
			close_composite_config(parentName);
			
		showSelectedCC(obj);
	}
	//close up the already rendered data
	else
	{
		hideUnSelectedCC(obj);
	}
}
	  
function close_composite_config(sModName)
{
	var option;
	var obj;
	var listel = document.getElementsByName("list_" + sModName);
	if (listel.length == 0)
	    return;
	    
	var list = listel[0].value.split(",");

	var i = 0;	
	while (sOptName = list[i++])
	{
		sName = sModName +  ":" + sOptName;
		option = document.getElementsByName(sName)[0];
		if (option != null && !option.checked)
		{
			obj = getElementsForCC(sName);

			if (obj.child1 != null && obj.child2 != null)
			{
				hideUnSelectedCC(obj);
			}
		}
	}
}
function hideUnSelectedCC(obj)
{    if (obj.img != null  && obj.img != undefined)
    {
	    obj.img_out.src = obj.img_out.src.replace("selected_open.gif","unselected.gif");
	    obj.img_out.src = obj.img_out.src.replace("selected_closed.gif","unselected.gif");

	    obj.href_obj.onmouseover = function(){window.status='';return true;};
	    //obj.href_obj.style.cursor = "default";				
	    obj.href_obj.style.cursor = "hand";				

	    obj.child1.style.display = 'none';
	}
	if (obj.child2 != null)
	    obj.child2.style.display = 'none';
}

function show_hide(parentName, childValue, childName, isDisabled, isBottom) 
{
	var obj = getElementsForCC(childName);

	if (isDisabled == "True")
	{
		determineShowHide(obj, isBottom);
	}
	else
	{
		var elements = document.getElementsByName(parentName);
		var i = 0;	
		while (theElement = elements[i++])
		{
			//don't do anything unless the option is selected
			if (theElement.value == childValue && theElement.checked)
				determineShowHide(obj, isBottom);
			else if (theElement.value == childValue && !theElement.checked)
				theElement.click();
		}
	}
}
function determineShowHide(obj, isBottom)
{
	if (obj.child2 != null)
	{
		if (getElementStyle(obj.child2, 'display') == 'none')
			showSelectedCC(obj);
		else
			hideSelectedCC(obj, isBottom);
	}
}
function showSelectedCC(obj)
{
    if (obj.img != null  && obj.img != undefined)
    {
	    document.getElementsByName("expanded_"+obj.name)[0].value = "yes";
	    obj.img.src = obj.img.src.replace("selected_closed.gif","selected_open.gif");
	    obj.img_out.src = obj.img_out.src.replace("selected_closed.gif","selected_open.gif");
	    obj.img_out.src = obj.img.src.replace("unselected.gif","selected_open.gif");
	    obj.sel.innerHTML = obj.sel.innerHTML.replace(_ShowSelectionsText, _HideSelectionsText);
    	
	    obj.href_obj.onmouseover = function(){return false;};
	    obj.href_obj.style.cursor = "hand";

	    obj.child1.style.display = "block";
	}
	if (obj.child2)
	    obj.child2.style.display = "block";

}
function hideSelectedCC(obj, isBottom)
{
    if (obj.img != null  && obj.img != undefined)
    {
	    document.getElementsByName("expanded_"+obj.name)[0].value = "no";
	    obj.img.src = obj.img.src.replace("selected_open.gif","selected_closed.gif");
	    obj.img_out.src = obj.img_out.src.replace("selected_open.gif","selected_closed.gif");
	    obj.sel.innerHTML = obj.sel.innerHTML.replace(_HideSelectionsText, _ShowSelectionsText);
	}
	if (obj.child2)
	    obj.child2.style.display = "none";

	if (isBottom == "true")
	{
		//only do this if it's IE4+ or NS6+
		if (document.all || document.getElementById)
			go_to(GetAbsPosition(obj.child2).y-200);
		else
			window.location.hash = obj.name;
	}
}
function getElementsForCC(name)
{
	var obj = new Object;
	obj.name = name;
	//content under the opt (first Show Selections)
	obj.child1 = document.getElementById("display1_"+name);
	//content after the first Show Selections
	obj.child2 = document.getElementById("display2_"+name);
	//image next to the Hide Selections text
	obj.img = document.getElementsByName("img_"+name)[0];
	//image next to the radio button/checkboxes
	obj.img_out = document.getElementsByName("img_out_"+name)[0];
	//Show Selections/Hide Selections text
	obj.sel = document.getElementById("sel_"+name);
	obj.href_obj = document.getElementById("href_"+name);
							
	return obj;
}
	
function scroll_to(location)
{
	document.CONFIG_FORM.target = window.name;
	window.location.hash = location;
}

function go_to(y_pos)
{
	document.CONFIG_FORM.target = window.name;
	window.scrollTo(0, y_pos)		
}

function submitPage(sAction, current_action, iCurrPage, current_action_param)
{
    if (sAction)
    	document.CONFIG_FORM.action = sAction;
	document.CONFIG_FORM.target = window.name;
	if (current_action_param)
		document.CONFIG_FORM.current_action_params.value = current_action_param;
	if (current_action)
		document.CONFIG_FORM.current_action.value = current_action;
	if (iCurrPage)
	{
		document.CONFIG_FORM.pageseq.value = iCurrPage;
	}
	document.CONFIG_FORM.expand_list.value = getExpandedModules();
	if (_doDynamicPricing)
		document.CONFIG_FORM.dpperf.value =  _totalDPReqs + ':' + _totalDPReqTime;
	document.CONFIG_FORM.submit();					
}
function update_price(iCurrPage, sAction)
{
	document.CONFIG_FORM.y_offset.value = document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	submitPage(sAction, 'update_price_top', iCurrPage);				
}

function cart_add(sAction)
{
  var charStartIndex ;
  var sActionLower=sAction.toLowerCase(); // Converting to Lowercase
  
  charStartIndex= sActionLower.indexOf("oc=");
  
    if(charStartIndex != -1)
     {
       charStartIndex = charStartIndex + 3;
       var subStr = sAction.substring(charStartIndex);
       var charEndIndex = subStr.indexOf("&");
       if(charEndIndex != -1)
       {
          var oc = sAction.substring(charStartIndex,(charStartIndex + charEndIndex));
        if(oc.length!=0)
        {
          oc = ";" + oc.toLowerCase();
       
          s_dell.linkTrackVars="products,events"; 
          s_dell.linkTrackEvents="scAdd"; 
          s_dell.products = oc;
          s_dell.events = 'scAdd'; 
          s_dell.tl(true,'o','AddToCart'); 
         } 
       }
     }
	submitPage(sAction, 'cart_add');
}
function cart_add_override(sAction)
{
	submitPage(sAction, 'cart_add', document.CONFIG_FORM.pageseq.value, 'overrideCart');
}
function wishlist_add(sAction)
{
	submitPage(sAction, 'wishlist_add');
}	  
function wishlist_add_override(sAction)
{
	submitPage(sAction, 'wishlist_add', document.CONFIG_FORM.pageseq.value, 'overrideWishList');
}
function equote_add(sAction)
{
	submitPage(sAction, 'equote_add');
}
function equote_add_override(sAction)
{
	submitPage(sAction, 'equote_add', document.CONFIG_FORM.pageseq.value, 'overrideCart');
}
function changeDPStatus(newStatus, errormsg, donotpost)
{
	AddHiddenFormElement("dpstatus",  newStatus);
	if (errormsg)
		AddHiddenFormElement("dperrormsg",  errormsg);
	if (!donotpost || donotpost == "false")
		submitPage(_Action, 'update_price_change_dp_status');
}
function next_page(sAction)
{
	submitPage(sAction, 'next'); //  + "&pg=" + ("" + (+_currPageSeq + 1))
}
	
//going from pages that don't have compatibility issues to the first page with compatibility issues 
function compat_page(iMinConfigLogicPage, sAction)
{
	submitPage(sAction + "#logicerror", 'compat_page', iMinConfigLogicPage);
}

//going from any page to the any page
function to_page(iToPage, sAction)
{
	submitPage(sAction, 'next', iToPage);
}	

//going from review page to any page, and scroll to a particular mod
function to_page_mod(iToPage, iToMod, sAction, noHistory)
{

	this.Final = function() {
	

        if (_currScView == 'icon' && _moduleBar && typeof(_moduleBar.goToModule) == 'function')
        {
            _moduleBar.goToModule(iToMod, noHistory);
        }
        else
        {
            var listdiv = getAnElement('sc_list_div');
            if (listdiv)
            {
                var div = getAnElement('m_' + iToMod);
                if (!div)
					div = getAnElement('bundleGroup_' + iToMod);
                scrollDivIntoView(listdiv, div);
            }
        }		
	}

    if (_IsSc)
    {
        if (iToPage != _currPageSeq)
        {
            tabChange(iToPage,false, this); //tabchange calls final when done
        }
        else
           this.Final();
    }
    else
    {
	    document.CONFIG_FORM.scroll_to_mod.value = iToMod;
	    var currmod = getAnElement('current_module');
	    if (currmod)
	        currmod.value = iToMod;
	    if (!sAction)
	        sAction = _Action;
	    submitPage(sAction, 'review', iToPage);
	}

}	

//Content functions
function goPopUp(sUrl){	  
	params  = GetWindowOpenParams(600, 500, p_Width, p_Height);
	ProcessOpenWindow(url, "LearnAbt", params, false);
}
function switchSCView(toView)
{
    _currScView = toView;
    _Action = swapQSValues(_Action, 'vw', toView);
    if (_doDynamicPricing)
    {
        _ValidateConfigURL = swapQSValues(_ValidateConfigURL, 'vw', toView);
        _QS = swapQSValues(_QS, 'vw', toView);
        tabChange(_currPageSeq);
    }
    else
    {
	    submitPage(_Action, 'update_price');
	}
	
}

function swapQSValues(QS, key, newValue)
{
        var newQS;
        var x = QS.indexOf(key + '=');
        if (x > -1)
        {
            newQS = QS.substr(0, x) + key + '=' + newValue;
            var y = QS.indexOf('&', x+3);
            if (y > -1)
            {
                newQS += QS.substr(y);
            }
        }
        else
        {
            newQS = QS + '&' + key + '=' + newValue;
        }
        return newQS;
}
function winopen(url,stuff,morestuff) {
	window.open(url,stuff,morestuff).focus();
} 

function checkSelect(module, table, select)
{
	var aDiv = getAnElement("module_options_" + module);
	if (select)
	{
		getAnElement("mod_selector_left_" + module).src = "http://i.dell.com/images/global/configurator/general/bevel_selected.gif";
		getAnElement("mod_selector_middle_" + module).className = "Mod_Selector_cell_middle_selected";
		if (aDiv.className == "option_display_visible") //currently expanded
		{
			getAnElement("mod_selector_right_" + module).src = "http://i.dell.com/images/global/configurator/general/collapse_selected.gif";
		}
		else
		{
			getAnElement("mod_selector_right_" + module).src = "http://i.dell.com/images/global/configurator/general/expand_selected.gif";
		}
	}
	else
	{
		getAnElement("mod_selector_left_" + module).src = "http://i.dell.com/images/global/configurator/general/bevel_notselected.gif";
		getAnElement("mod_selector_middle_" + module).className = "Mod_Selector_cell_middle_notselected";
		if (aDiv.className == "option_display_visible") //currently expanded
		{
			getAnElement("mod_selector_right_" + module).src = "http://i.dell.com/images/global/configurator/general/collapse_notselected.gif";
		}
		else
		{
			getAnElement("mod_selector_right_" + module).src = "http://i.dell.com/images/global/configurator/general/expand_notselected.gif";
		}
	}
	
}

function toggleOptionDisplay(module, table){
	var aDiv = getAnElement("module_options_" + module);
	var expandImage = getAnElement("expand_module_image_" + module);
	var moduleName = getAnElement("mh_" + module).innerHTML;
	var collapsedDesc = _NothingSelectedCollapsed.replace("{0}", moduleName);
	var currDesc = getAnElement("mhd_m_" + module);

	if(aDiv.className == "option_display_visible"){
		aDiv.className="option_display_none";
		getAnElement("modoptshow_" + module).value="0";
		setOptionDisplay(table, module, false);
		if (currDesc.innerHTML == _NothingSelectedExpanded)
			currDesc.innerHTML = collapsedDesc;
	}
	else
	{
		aDiv.className="option_display_visible";
		getAnElement("modoptshow_" + module).value="1";
		setOptionDisplay(table, module, true);
		if (currDesc.innerHTML == collapsedDesc)
			currDesc.innerHTML = _NothingSelectedExpanded;
	}
}
function setOptionDisplay(table, module, isopen)
{
	//table.className="Mod_Selector_table_selected";
	getAnElement("mod_selector_left_" + module).src = "http://i.dell.com/images/global/configurator/general/bevel_selected.gif";
	getAnElement("mod_selector_middle_" + module).className = "Mod_Selector_cell_middle_selected";
	if (isopen)
		getAnElement("mod_selector_right_" + module).src = "http://i.dell.com/images/global/configurator/general/collapse_selected.gif";
	else
		getAnElement("mod_selector_right_" + module).src = "http://i.dell.com/images/global/configurator/general/expand_selected.gif";
}

function checkBundleGroupSelect(bundleGroupId, select)
{
	var urlBase = "http://i.dell.com/images/global/configurator/general/";
	jQuery("#mod_selector_left_" + bundleGroupId).attr("src", urlBase + (select ? "bevel_selected.gif" : "bevel_notselected.gif"));
	jQuery("#mod_selector_middle_" + bundleGroupId).toggleClass("Mod_Selector_cell_middle_notselected");
	jQuery("#mod_selector_middle_" + bundleGroupId).toggleClass("Mod_Selector_cell_middle_selected");

	var aDiv = jQuery("#bundleGroupBundlesDiv_" + bundleGroupId);
	if (select)
		jQuery("#bundleGroupSH_" + bundleGroupId).attr("src", urlBase + (aDiv.is(".bundleGroupDisplayVisible") ? "collapse_selected.gif" : "expand_selected.gif"));
	else
		jQuery("#bundleGroupSH_" + bundleGroupId).attr("src", urlBase + (aDiv.is(".bundleGroupDisplayVisible") ? "collapse_notselected.gif" : "expand_notselected.gif"));
}

function checkBundleSelect(bundleId, select)
{
	var cell = jQuery("#bundleHdrCell_" + bundleId);
	cell.toggleClass("bundleHdrCellNotSel");
	cell.toggleClass("bundleHdrCellSel");
}

function toggleBundleGroupDisplay(bundleGroupId, clickedElement) {
	var hideElement1 = jQuery("#bundleGroupListDiv_" + bundleGroupId);
	var hideElement2 = jQuery("#bundleGroupBundlesDiv_" + bundleGroupId);
	hideElement1.toggleClass("bundleGroupDisplayVisible");
	hideElement1.toggleClass("bundleGroupDisplayNone");
	hideElement2.toggleClass("bundleGroupDisplayVisible");
	hideElement2.toggleClass("bundleGroupDisplayNone");
	jQuery("#bundleGroupShown_" + bundleGroupId).val(hideElement1.is(".bundleDisplayVisible") ? "1" : "0");
	jQuery("#bundleGroupSH_" + bundleGroupId).attr("src", "http://i.dell.com/images/global/configurator/general/" + (hideElement1.is(".bundleDisplayVisible") ? "collapse_selected.gif" : "expand_selected.gif"));
}
	
function toggleBundleDisplay(bundleId, bundleGroupId){
	var hideElement = jQuery("#bundleDtlTableDiv_" + bundleId);
	hideElement.toggleClass("bundleDisplayVisible");
	hideElement.toggleClass("bundleDisplayNone");
	// note: when searching for IDs with jQuery, have to escape periods and colons
	jQuery("#bundleShown_" + bundleGroupId + "\\:" + bundleId).val(hideElement.is(".bundleDisplayVisible") ? "1" : "0");
	var shImg = jQuery("#tdBundleSH_" + bundleId);
	shImg.toggleClass("bundleShowHideCellCollapsed");
	shImg.toggleClass("bundleShowHideCellExpanded");
}

function ensureBundleExpanded(bundleId, bundleGroupId) {
	// note: when searching for IDs with jQuery, have to escape periods and colons
	var isShown = jQuery("#bundleShown_" + bundleGroupId + "\\:" + bundleId).val();
	if (isShown == "0") {
		var elem = jQuery("#bundleDtlTableDiv_" + bundleId);
		elem.removeClass("bundleDisplayNone");
		elem.addClass("bundleDisplayVisible");
		jQuery("#bundleShown_" + bundleGroupId + "\\:" + bundleId).val("1");
		elem = jQuery("#tdBundleSH_" + bundleId);
		elem.removeClass("bundleShowHideCellCollapsed");
		elem.addClass("bundleShowHideCellExpanded");
	}
}

function valmodlink(modId, pageSeq)
{
    if (_IsSc)
        to_page_mod(pageSeq,modId);
    else
	    valmodlink_go('mh_' + modId, pageSeq);
}

function valmodlink_comp(displaytag, pageSeq)
{
	valmodlink_go('c_' + displaytag, pageSeq);
}

function valmodlink_go(sLink, pageSeq, fromTabChange)
{
	var ModRow = getAnElement(sLink);			
	if (ModRow)
	{
        var sclistdiv = getAnElement('sc_list_div');
        if (sclistdiv)
        {
            scrollDivIntoView(sclistdiv, ModRow);
        }
        else
        {
		    var location = GetAbsPosition(ModRow);
		    if (location && VMessages)
		    {
			    window.scrollTo(0,location.y - VMessages.startHeight - 40 );
		    }
		}
	}
	else if(pageSeq != 0 && pageSeq != document.CONFIG_FORM.pageseq.value)
	{
	    if (_IsSc && !(fromTabChange))
	    {
	        this.Final = function() {valmodlink_go(sLink, pageSeq, true)};
	        tabChange(pageSeq,false,this);
	    }
	    else
	    {
		    document.CONFIG_FORM.val_module.value = sLink;
		    document.CONFIG_FORM.scroll_to_mod.value = sLink;
	   	    submitPage(_Action, 'update_price', pageSeq);
	   	}

	}

}

function getAnElement(id)
{
	return document.getElementById?document.getElementById(id):document.all?document.all[id]:document.layers[id];
}

function getExpandedModules()
{
	var div;
	var id;
	var list ;
	var els = document.CONFIG_FORM.elements;
	var x = 0;
	while (el = els[x++])
	{
		if (el.id.substr(0,11) == "modoptshow_")
		{
			id = el.id.substr(11);
			if (el.value=="1")
			{
				div = getAnElement("module_options_" + id)
				if (div && (div.style.display=="inline" || div.className == "option_display_visible"))
					if (list)
						list += "," + id;
					else
						list = id;
			}
		}
	}
	if (list)
		return list;
	else
		return "";
}

function getCollapsedBundles()
{
	var result = "";

	var bundleGroupPrefix = "bundleGroupShown_", bundleGroupPrefixLength = bundleGroupPrefix.length;
	var bundlePrefix = "bundleShown_", bundlePrefixLength = bundlePrefix.length;
	// find inputs whose id starts with 'bundleShown_' and whose value = '0'
	jQuery("input[id^='" + bundleGroupPrefix + "'][value='0']").each(function(b) { if(result.length>0)result+=",";result+=this.id.substr(bundleGroupPrefixLength); });
	// find inputs whose id starts with 'bundleShown_' and whose value = '0'
	jQuery("input[id^='" + bundlePrefix + "'][value='0']").each(function(b) { if(result.length>0)result+=",";result+=this.id.substr(bundlePrefixLength); });

	return result;
}

function GetAbsPosition(object) {
	var position = new Object;
	position.x = 0;
	position.y = 0;

	if( object ) 
	{
		position.x = object.offsetLeft;
		position.y = object.offsetTop;

		if( object.offsetParent ) 
		{
			var parentpos = GetAbsPosition(object.offsetParent);
			position.x += parentpos.x;
			position.y += parentpos.y;
		}
	}

	return position;
}

function AddHiddenFormElement(name, value)
{
	var el = document.createElement('input');
	el.name = name;
	el.id = name;
	el.value = value;
	el.type = "hidden";
	document.CONFIG_FORM.appendChild(el);
	return el;
}	  


function hideDiv(divName)
{
    var theDiv = getAnElement(divName)
    if (theDiv)
    {
        theDiv.style.visibility='hidden';
        theDiv.style.display = 'none';
    }
}

function showDiv(divName)
{
    var theDiv = getAnElement(divName)
    if (theDiv)
    {
        theDiv.style.visibility='visible';
        theDiv.style.display = 'block';
    }
}

function logDebug(info, end)
{
    var theDiv = getAnElement('sc_debug_div');
    if (theDiv)
    {
        var d = new Date();
        if (end && _lastDebug)
            theDiv.innerHTML =  d.getMinutes() + ':' + d.getSeconds() + ':' + d.getMilliseconds()  + ' ' + info + ' ' +  _lastDebug  + '<br>' + theDiv.innerHTML;
        else 
            theDiv.innerHTML =  d.getMinutes() + ':' + d.getSeconds() + ':' + d.getMilliseconds()  + ' ' + info + '<br>' + theDiv.innerHTML;
    }
}


function getElementStyle(el, hyphenName)
    {
        // must use this function to read applied style (.style only returns the style set inline via style tags or script)
        // ie also needs hyphens removed and uppcase on first char after hyphen
        if (el.currentStyle) // ie uses current style
        {                
            var ieName;
            if (hyphenName.indexOf('-')!= -1)
            {
                var sArray; 
                sArray = hyphenName.split('-');
                ieName = sArray[0];
                for(var i=1;i < sArray.length;i++)
                {
                    ieName=ieName + sArray[i].charAt(0).toUpperCase() + sArray[i].substring(1);
                }                
            }
            else
            {
                ieName = hyphenName;
            }
            return el.currentStyle[ieName];
        }
        else if (window.getComputedStyle) // mozilla use getComputedStyle
        {
            var elstyle=window.getComputedStyle(el, '');
            return elstyle.getPropertyValue(hyphenName);
        }
        else // this should probably never happen
        {
            return el.style[hyphenName]        
        }
    }


function addHidden(sName, sValue)
{
	var input
	// ie likes first ff likes catch
	try { input = document.createElement('<input name="' + sName + '">'); }
	catch (e) { input = document.createElement('input'); }
	input.setAttribute('type', 'hidden');
	input.setAttribute('name', sName); // ignored in ie
	input.setAttribute('value', sValue);
	if (_currScView != "builder") {
		var d = getAnElement('sc_main_div');
		if (d == null) {
			document.CONFIG_FORM.appendChild(input);
		} else {
			// var divelem = document.getElementById('sc_app_hidden_div');
			var divelem = getAnElement('sc_app_hidden_div');
			if (divelem != null) {
				divelem.appendChild(input);
			}
		}
	} else {
		$("#sc_app_hidden_div").append(input);
	}
}

function removeHidden(sName, useIdStartsWith)
{
	if (!useIdStartsWith) {
		// remove all hidden form fields with the name 
		var inputs = document.getElementsByName(sName);
		if (inputs) {
			var input;
			var z = 0;
			var ar = new Array();
			while (input = inputs[z++]) {
				if (input.type == 'hidden');
				ar[z] = input;
			}
			for (var i = 1; i < ar.length; i++) {
				if (ar[i].parentNode)
					ar[i].parentNode.removeChild(ar[i]);
			}
		}
	} else {
		jQuery("input[type=hidden][name^=" + sName + "]").remove();
	}
}

function clearChecks(sName)
{
     var inputs = document.getElementsByName(sName);
     if (inputs)
     {
	     var input;
	     var z = 0;
         while (input = inputs[z++])
         {
            if (input.type=='radio' || input.type=='checkbox')
                input.checked = false;
         }
      }
}

function addCheck(sName, sValue)
{
     var inputs = document.getElementsByName(sName);
     if (inputs)
     {
	     var input;
	     var z = 0;
         while (input = inputs[z++])
         {
            if ((input.type=='radio' || input.type=='checkbox') && input.value == sValue)
                input.checked = true;
         }
      }
}
function setCheck(sName,sValue, dState)
{
     var inputs = document.getElementsByName(sName);
     if (inputs)
     {
	     var input;
	     var z = 0;
         while (input = inputs[z++])
         {
             if ((input.type=='radio' || input.type=='checkbox') && input.value == sValue)
                input.disabled = dState;
         }
      }
}

function setOptionFilter(moduleKey, optValue, optionKey, filterState)
{
    var el = getAnElement('tr_' + optionKey);
    if (el)
    {
	    switch(filterState)
	    {
		    case 1:
			    el.className="flavored_option_display_hide";
			    break;			
		    case 2:
			    el.className="flavored_option_display_disabled";
			    setCheck(moduleKey, optValue, true)			
			    break;		
		    default:			
			    el.className="flavored_option_display_enabled";
			    setCheck(moduleKey, optValue, false)			
			    break;
	    }
	}
}

function updateLC(parent, parentName, parentValue, modId)
{
    var childName = parentName+"_"+parentValue;	
	var obj = getElementsForLC(childName,modId);
	if (parent.checked)
	{
		if (parent.type=="radio")
			closeLC(parentName,childName, modId);			
		showSelectedLC(obj,parentValue);
	}
	else
	{
		hideUnSelectedLC(parentName,obj);
	}
	
	var d = getAnElement('icon-options-div');
	if(d!=null)
	{
	        var elems = document.getElementsByName(obj.modId);		
		    for(i=0;i<elems.length;i++)
		    {			
			    if(elems[i].attributes.getNamedItem('legCatAtRoot')!=null)
				    elems[i].checked=false;
		    }		
	}
	else	
	{
	    //unselect the categoryatroot option when a category is selected.
         if(parent.type=="radio")
	     {
	 	    var elems = document.getElementsByName(obj.modId);		
		    for(i=0;i<elems.length;i++)
		    {			
			    if(elems[i].attributes.getNamedItem('legCatAtRoot')!=null)
				    elems[i].checked=false;
		    }		    		

	     }
	}	  
		  
}

function getElementsForLC(name,modId)
{
	 

	var obj = new Object;
	obj.name = name;
	obj.child1 = document.getElementById("tr_mlc_options:"+name);		
	obj.img_out = document.getElementsByName("img_out_"+name)[0];
	obj.href_obj = document.getElementById("href_"+name);	
	obj.modId = modId;
	return obj;
}

function showSelectedLC(obj,val)
{  
	    obj.child1.style.display = '';
	    
	    if (obj.img_out != null  && obj.img_out != undefined)
	    {  	
		    obj.img_out.src = obj.img_out.src.replace("selected_closed.gif","selected_open.gif");
		    obj.img_out.src = obj.img_out.src.replace("unselected.gif","selected_open.gif");
		    obj.href_obj.onmouseover = function(){return false;};
		    obj.href_obj.style.cursor = "hand";			   
		}
		var elems = document.getElementsByName(obj.modId);
		var k = 0;
		for(i=0;i<elems.length;i++)
		{
		  		
			if(elems[i].value=="")
				elems[i].checked=false;		
			if(k==0 && elems[i].attributes.getNamedItem('leg_cat_id')!=null && elems[i].attributes.getNamedItem('leg_cat_id').value==val && elems[i].type=="radio")
			{
			    elems[i].click();
			    k=1;
			}
			if(k==1)
		      break;	
		}		
			

}

function closeLC(sModName,sSelName, modId)
{
	var option;
	var obj;
	var listel = document.getElementsByName("list_" + sModName);	
	if (listel.length == 0)
	    return;
	    
	var list = listel[0].value.split(",");
	var i = 0;	
	while (sOptName = list[i++])
	{
		sName = sModName +  "_" + sOptName;
		if(sSelName!=sName)
		{			
			obj = getElementsForLC(sName, modId);
			if (obj.child1 != null )
			{
				hideUnSelectedLC(sModName,obj,sSelName);
			}
		}
	}
	
}

function hideUnSelectedLC(parentName,obj,lcOptId,elem)
{  	
	    var elm = document.getElementById(parentName);	
	    if(elem!=null)
	    {
	        if(elem.attributes != undefined && elem.attributes.getNamedItem('AlwaysExpanded')!=null)
		    {					
		    }
		    else
		    {
	           obj.child1.style.display = 'none';	
	        }	    	
	    }
	    else
	    {
	        if(elm.attributes != undefined && elm.attributes.getNamedItem('AlwaysExpanded')!=null)
		    {					
		    }
		    else
		    {
	           obj.child1.style.display = 'none';	
	        }	    	
	    }
    	 	
	    if (obj.img_out != null  && obj.img_out != undefined)
	    {
		  /*  obj.img_out.src = obj.img_out.src.replace("selected_open.gif","unselected.gif");
		    obj.img_out.src = obj.img_out.src.replace("selected_closed.gif","unselected.gif");*/
		    obj.img_out.src = obj.img_out.src.replace("selected_open.gif","selected_closed.gif");
		}
		
		if(document.getElementById(parentName)!=null && document.getElementById(parentName) != undefined && document.getElementById(parentName).type=="checkbox")
		{
		    
			var elems = obj.child1.getElementsByTagName('input');			
			var bFound;			
			for(i=0;i<elems.length;i++)
			{
			    
				if(elems[i].name==obj.modId && elems[i].checked)
				{
				    removeFromLastPost(elems[i].name,elems[i].value);
					elems[i].checked = false; 
				    bFound = elems[i];
				}
			}
			if (bFound)
			{
			 runValidation(bFound.name + ';' + bFound.value + ';' + bFound.checked); //dynamic33
			}		    
       }
}

function removeFromLastPost(name,value)
{
    _lastPost = _lastPost.replace('&' + name + '=' + value,'');
}

function hideSelectedLC(obj)
{  	    
	    obj.child1.style.display = 'none';	
	    if (obj.img_out != null  && obj.img_out != undefined)
	    {
		    obj.img_out.src = obj.img_out.src.replace("selected_open.gif","selected_closed.gif");
		    obj.img_out.src = obj.img_out.src.replace("selected_open.gif","selected_closed.gif");
		}	 
}



function show_hide_LC(parentName,childValue,childName, isDisabled) 
{
	
	var obj = getElementsForLC(childName);
	if (isDisabled == "True")
	{
		determineShowHideLC(obj);
	}
	else
	{
		/*var element = document.getElementById(parentName);
		alert(parentName);
		if (element.value==childValue && element.checked)
		{			
			determineShowHide(obj);
		}*/
		 
		var elements = document.getElementsByName(parentName);
		var i = 0;	
		while (theElement = elements[i++])
		{
			//don't do anything unless the option is selected

			if (theElement.value == childValue && theElement.checked)
				determineShowHideLC(obj);
			else if(theElement.value == childValue && !theElement.checked)
			    theElement.click();
			 
		}

	}
	var d = getAnElement('icon-options-div');
        if(d)
		PositionNextButton();
}


function determineShowHideLC(obj)
{
	if (obj.child1 != null)
	{
		if (getElementStyle(obj.child1, 'display') == 'none')
			showSelectedLC(obj);
		else
			hideSelectedLC(obj);
	}
}

function getElementStyle(el, hyphenName)
    {
        // must use this function to read applied style (.style only returns the style set inline via style tags or script)
        // ie also needs hyphens removed and uppcase on first char after hyphen
        if (el.currentStyle) // ie uses current style
        {                
            var ieName;
            if (hyphenName.indexOf('-')!= -1)
            {
                var sArray; 
                sArray = hyphenName.split('-');
                ieName = sArray[0];
                for(var i=1;i < sArray.length;i++)
                {
                    ieName=ieName + sArray[i].charAt(0).toUpperCase() + sArray[i].substring(1);
                }                
            }
            else
            {
                ieName = hyphenName;
            }
            return el.currentStyle[ieName];
        }
        else if (window.getComputedStyle) // mozilla use getComputedStyle
        {
            var elstyle=window.getComputedStyle(el, '');
            return elstyle.getPropertyValue(hyphenName);
        }
        else // this should probably never happen
        {
            return el.style[hyphenName]        
        }
    }
    

function collapseCategories(evt)
{
	    var targetEl = evt.currentTarget ? evt.currentTarget : evt.srcElement ? evt.srcElement : evt.target;
	    if(targetEl!=null && targetEl.type=="checkbox")
	        return;	 
    	var elemList = document.getElementsByName(targetEl.name);
    	if(elemList!=null && elemList != undefined)
    	{
    	   var nm = targetEl.name.replace("m","mlc");		
	        var elements = document.getElementsByName(nm);
        	
	        for(i=0;i<elements.length;i++)
	        {
		       if(elements[i].checked)
		        {
			        elements[i].checked=false;
			        obj = getElementsForLC(elements[i].name+"_"+elements[i].value);
			        if (obj.child1 != null )
			        {
				        hideUnSelectedLC(elements[i].name,obj,elements[i].value,elements[i]);
			        }
		        }

	        }
 
    	}
}

//changes for option qty
function enableQtyText (mod,opt,btnClicked)
{
       var elements = document.getElementsByName(mod);
        var i=0;
        while(elem = elements[i++])
        {
            if(opt==elem.value && (elem.type=="checkbox" || elem.type=="radio"))
            {
                var elmTB = document.getElementById("sq_"+mod+"_"+opt);
                var elmBT = document.getElementById("sqb_"+mod+"_"+opt);
                var tbboxes = document.getElementsByName("q_"+mod+":"+opt);
                for(j=0;j<tbboxes.length;j++)
                {
                    if(elmTB!='undefined' && tbboxes[j]!='undefined' && tbboxes[j].type=="text")
                    {
                        //if the radio/checkbox is checked just now
                        if(elem.checked && btnClicked=='true')
                        {                                       
                           tbboxes[j].className='qty_text_box_edit'; 
                           break;                       
                        }
                        // radio/checkbox is checked and is already selected
                        else if(elem.checked && btnClicked=='false')
                        {
                            tbboxes[j].className='qty_text_box_edit'; 
                            break;
                        }
                        //if the radio/checkbox is not checked, the textbox is selected
                        else if(!elem.checked && btnClicked=='false')
                        {
                            elem.click();
                            tbboxes[j].className='qty_text_box_edit';  
                            break;
                        }                   
                    }
                }
            }
       }
}


function showQtyUpdateButton(d)
{
 	document.getElementById(d).style.display='inline';
}

function updateOptionQty(optQty,mod,opt)
{
    var tbelems = document.getElementsByName(optQty);
    for(j=0;j<tbelems.length;j++)
    {
        if(tbelems[j].type=="text")
        {
            var qty = 1;
            try
            {
                qty = parseInt(tbelems[j].value);
            }
            catch(exp)
            {
                qty = 1;
            }
                        
            optQty = optQty.replace('m_','');       
            replaceLastPostValue(optQty,qty);
            _lastPost = _lastPost+"&qty_changed=true";    
            
             var elements = document.getElementsByName(mod);
             var i=0;
             while(elem = elements[i++])
             {
                if(opt==elem.value && (elem.type=="checkbox" || elem.type=="radio") || elem.type=="hidden")        
                {
                    runValidation(mod + ';' + opt + ';' + elem.checked);            
                    break;    
                }
            }
            
            var qtyBtn = document.getElementById("sqb_"+mod+"_"+opt);   
            if(qtyBtn!=null)    
                qtyBtn.style.display='none';       
            tbelems[j].className="qty_text_box_set";    
       }
    }    
}

function replaceLastPostValue(key,value)
{
    var lastPostTemp = _lastPost;
    if(_lastPost.indexOf(key+'=')>0)
    {
        lastPostTemp = lastPostTemp.substring(lastPostTemp.indexOf(key));
        lastPostTemp = lastPostTemp.substring(0,lastPostTemp.indexOf('&'));
        var vals = lastPostTemp.split('=');
        var newval = vals[0]+'='+value;
        _lastPost = _lastPost.replace(lastPostTemp,newval);
    }
    else
        _lastPost = _lastPost+'&'+key+'='+value;
}



//stuff for pictaflex
	
	function ResizePictaDiv()
	{
	    var windowHeight;
	    var windowWidth;
	    var docHeight;
	    var docWidth;
	    var configBlocker = document.getElementById("config_blocker") ;	
	    if(configBlocker==null || configBlocker=='')
	        return;
	    configBlocker.className = "content_faded";	    
	    configBlocker.style.display = 'block';
	    if (document.body.innerHeight)
            docHeight = document.body.innerHeight;
        else if (document.body.offsetHeight)
            docHeight = document.body.offsetHeight;
        if (window.innerWidth)
            docWidth = window.innerWidth;
        else if (document.documentElement.offsetWidth)
            docWidth = document.documentElement.offsetWidth;        
            
	    configBlocker.style.height = docHeight;
	    configBlocker.style.width = docWidth;
	    var pictaDiv = document.getElementById("picta_div") ;
		pictaDiv.style.display = 'block';
		if (window.innerHeight)
            windowHeight = window.innerHeight;
        else if (document.documentElement.offsetHeight)
            windowHeight = document.documentElement.offsetHeight;   
        var topLoc = (windowHeight - 600)/2;
        if (window.innerWidth)
            windowWidth = window.innerWidth;
        else if (document.documentElement.offsetWidth)
            windowWidth = document.documentElement.offsetWidth;   
        var leftLoc = (windowWidth - 880)/2;
        pictaDiv.style.left = leftLoc;
        pictaDiv.style.top = topLoc;
        pictaDiv.style.width='880';
        pictaDiv.style.height='600';    
	}
	function ShowPictaModPopUp(country,language,segment,customerSetId,orderCode,mod,opt,customId,url,nocache)
	{
	    if(customId==0)
	    {	  
	        var imgId = getPictaOptionImageElement("i_"+mod+":"+opt);
	        if(imgId!=null)
	            customId = imgId;
	    }
	    _InPictaMode = true;
	    ResizePictaDiv();	    	    
	    var pictaDiv = document.getElementById("picta_div") ;		    	
        var containerURL = encodeURIComponent( location.href );        
        var param ="oc="+orderCode+"&c="+country+"&l="+language+"&s="+segment+"&cs="+customerSetId+"&modid="+mod+"&optid="+opt+"&imgid="+customId+"&showclose=true&inconfiglayer=true&nc="+nocache+"&containerURL=" + containerURL;       
		LoadFlashSWF(pictaDiv, url,param);
	} 
	 
    function HidePictaModPopup() 
	{
	    var pictaDiv = document.getElementById("picta_div") ;	   
		pictaDiv.style.display = "none";
		pictaDiv.style.innerHTML='';
		var configBlocker = document.getElementById("config_blocker") ;	
		configBlocker.style.display = "none";
		_InPictaMode = false;	
	}
	
	function onCustomOptionClick(evt,ordercode,customerSetId,segment,country,language,customizationId,url,nocache)
    {
        var targetEl = evt.currentTarget ? evt.currentTarget : evt.srcElement ? evt.srcElement : evt.target;
        var elem = document.getElementById("i_"+targetEl.name+":"+targetEl.value);	    
        if(customizationId==0 && elem==null)
        {
            getPrevSelect(targetEl);
            cancelEvent(evt);                
            if (_prevSelect)
				    _prevSelect.checked = _prevChecked;
            ShowPictaModPopUp(country,language,segment,customerSetId,ordercode,targetEl.name,targetEl.value,customizationId,url,nocache);        
        }
        /*else
        {
            var d = getAnElement('icon-options-div');
            if(d)
                onIconOptionClick(evt);
            else
                checkOnClick(evt);
            
        } */      
    }
    
    function UpdateOptionImageData (optionElem,optionCellId)
    {
        var imgId = 0;
        var imgUrl = null;
        imgUrl = getPictaImageBaseUrl();
        imgId = getPictaOptionImageElement(optionCellId);
        //alert(imgId);
	    if(imgUrl!=null && imgId != 0)
	    {
            optionElem.attributes.getNamedItem('option_image').value = imgUrl + imgId+".jpg";
            onPictaOptionHover(optionCellId,'true');
        }
    }
    
    function getPictaImageBaseUrl()
    {
        var imgUrl = null;
        var elem = document.getElementById("pictaflex_314_url");
         if(elem!=null)
	        imgUrl = elem.value;
	    return imgUrl;
    }
    
    function getPictaOptionImageElement(optionCellId)
    {
        var imgHidden = optionCellId.replace('td2','i');
        var elem = document.getElementsByName(imgHidden);
        var imgId = 0;
        if(elem!=null && elem.length>0)  
	        imgId = elem[0].value;
	    return imgId;    
    }
    
function onPictaOptionHover (optionCellId,isDS)
{            
        var imgId = 0;
        var imgUrl = null;
        imgUrl = getPictaImageBaseUrl();
        imgId = getPictaOptionImageElement(optionCellId);
	    if(imgUrl!=null && imgId != 0)
	    {
	        imgUrl = imgUrl + imgId+".jpg";
	        var hoverelem = document.getElementById("opt_img_hover");
	        if(hoverelem!=null)
	        {
	          onOptionHover(imgUrl, optionCellId);	         
	          if(isDS=='true')        
	            turnOptionBordersOff(optionCellId);	
	        }
	         var optImg = getAnElement('opt_img_selected');
		    if(optImg!=null && isDS=='true')
		    {
	        	optImg.src = imgUrl;
	        }
	        
	        
	    }
	    else
	    {
	        onOptionHover('',optionCellId);
	    }
}

function dsCallBack(selection)
{     
    var mod = "m_"+selection.mod;  
    var key = "i_"+mod+":"+selection.opt; 
     _InPictaMode = false;
    replaceLastPostValue(key,selection.customizationId);
    var options = document.getElementsByName(mod);
	    var z = 0;
	    var option;
	    var elem = null;
	    if(options!=null)
	    {
	        while(option = options[z++])
	        {
	            if(option.value == selection.opt)
	            {
	                var elems = document.getElementsByName("i_"+mod+":"+selection.opt);
                    var imgId = 0;
                    if(elems!=null && elems.length>0)  	                
                        elem = elems[0];	               
	                if(elem!=null)
	                    elem.value = selection.customizationId;
	                else	                
	                    addHidden(key,selection.customizationId);
	                _cancelClick = false;		                 	               	           
	                option.click();	                 
	                if(option.attributes.getNamedItem('iscustom')!=null)
	                {
	                    elem = document.getElementById("td2_"+mod+":"+selection.opt);
	                    if(elem!=null)
	                    {	                        
	                        UpdateOptionImageData(option,elem.id);    	                   
	                    }
	                }
	                break;
	            }
	        }
	    }	    
	    HidePictaModPopup();
}

function addToFavorite( sURL, sTitle )
{
	sTitle = top.document.title;
	
	if (window.sidebar != undefined ) 
	{ 
		// Mozilla Firefox Bookmark		
		window.sidebar.addPanel(sTitle, sURL,"");	
	} 
	else if( window.external != undefined ) 
	{ 
		// IE Favorite		
		window.external.AddFavorite( sURL, sTitle); 
	}	
	else if( window.opera && window.print ) 
	{ 
		// Opera Hotlist		
		return true; 
	}
}

function addToOmniture(modDesc, pageId, view) {

    s_dell.prop8 = pageId.toString();
	
    if (view == 1)
    {
        s_dell.linkTrackVars = 'prop8,prop9,prop10,prop23,prop13';
        s_dell.prop9 = modDesc.toString();
        s_dell.prop10 = 'icon';
        s_dell.prop23 = s_dell.prop10 + ': ' + s_dell.prop8 + ': ' + s_dell.prop9;
    }
    // Call from Builder view
    else if(view == 3)
    {
		if( modDesc == null || modDesc == undefined || modDesc == "")
		{
		  s_dell.linkTrackVars = 'prop8,prop10,prop23,prop13';
		  s_dell.prop10 = 'builder';
          s_dell.prop23 = s_dell.prop10 + ': ' + s_dell.prop8;
		}
		else
		{
		  s_dell.linkTrackVars = 'prop8,prop9,prop10,prop23,prop13';
		  s_dell.prop9 = modDesc.toString();
		  s_dell.prop10 = 'builder';
          s_dell.prop23 = s_dell.prop10 + ': ' + s_dell.prop8 + ': ' + s_dell.prop9;
		}
    }
    else
    {
        s_dell.linkTrackVars = 'prop8,prop10,prop23,prop13';
        s_dell.prop10 = 'list';
        s_dell.prop23 = s_dell.prop10 + ': ' + s_dell.prop8;
    }  
        
    s_dell.tl(true, 'o', 'Config Change');
}


//engraving functions for AW
function ViewEngraveText(optDisplayTag,modId,optId)
{
    var elem = document.getElementById(optDisplayTag);
    UpdateServer(optDisplayTag,modId,optId,elem.value,'true');     
}

function ClearEngraveText(optDisplayTag,modId,optId)
{
    var elem = document.getElementById(optDisplayTag);
    if(elem!=null)
        elem.value='';
    UpdateServer(optDisplayTag,modId,optId,'','false');
}

function UpdateServer(optDisplayTag,modId,optId,text,boolval)
{
	var txt='';
	if(text=='')
		txt = text;
	else
		txt = encodeURIComponent(text);
    replaceLastPostValue(optDisplayTag,txt);
    var modId = 'm_'+modId;
    try{document.body.style.cursor = 'progress';}catch(e){}
    runValidation(modId + ';' + optId + ';' + boolval);
}

function SetEngraveImageSrc(src,mode,val)
{    
    if(mode=="pop")
    {
        if(val!="none")
        {
            var link = 'imagegenerator.aspx?text='+val;        
            makeWin2(link, 370,230);
        }
    }
    else
    {
        var imgElem = document.getElementById('icon_engrave_mod_img');    
        imgElem.src = src;    
    }
}

function enablePictaflexOption(moduleKey, optValue, optionKey, isVisible) {
    var el = getAnElement('tr_' + optionKey);
    if (el) {
        switch (isVisible) {
            case 1:
                el.className = "flavored_option_display_enabled";
                break;
            default:
                el.className = "flavored_option_display_hide";
                break;
        }
    }
    else {
        el = getAnElement(optionKey + '_div');
        if (el != null || el != undefined) {
            switch (isVisible) {
                case 1:
                    el.className = "flavored_option_display_enabled";
                    break;
                default:
                    el.className = "flavored_option_display_hide";
                    break;
            } 
        }
    }
}

function ShowShippingDetails() {
	alert("Show Shipping Details here!");
}

function changeView(action, view) {
	_Action = swapQueryStringValues(action, 'vw', view);	
	if (view == 'list')
		addToOmniture(null, _currPageSeq, 2);
	/*else if (view == 'builder')
		addToOmniture(null, _currPageSeq, 3);		*/
	
	if (_Action) {
		document.CONFIG_FORM.action = _Action;
		document.CONFIG_FORM.submit();
	}	
}

function swapQueryStringValues(QS, key, newValue) {
	var newQS;
	var x = QS.indexOf(key + '=');
	if (x > -1) {
		newQS = QS.substr(0, x) + key + '=' + newValue;
		var y = QS.indexOf('&', x + 3);
		if (y > -1) {
			newQS += QS.substr(y);
		}
	}
	else {
		newQS = QS + '&' + key + '=' + newValue;
	}
	if (newValue == 'list' || newValue == 'classic')
		return newQS + '&frb=1';
	else
		return newQS;
}

