﻿// JScript File

var Rank = -1;
var MaxRank = -1;
var Custfailed = false;
var CustPrice = 0;
var PlotArray = new Array();
var currencydisplay = false;
var parameters = '';

function RestrictShipPopup(link)
{
    window.open(link,null, 'height=300, width=500, status=yes, toolbar=no, menubar=no, location=no, scrollbars=yes'); void('');
}

function ItemToggle(node)
{
    var divArray = node.getElementsByTagName("img");

    switch (node.id)
    {
        case "proddesc":
        element = document.getElementById('divproddesc').style;
        break;

        case "specification":
        element = document.getElementById('divspecification').style;
        break;

        case "resources":
        element = document.getElementById('divresources').style;
        break;

        case "manufacturerinfo":
        element = document.getElementById('divmanufacturerinfo').style;
        break;

        case "similaritems":
        element = document.getElementById('divsimilaritems').style;
        break;

        case "customerdiscussion":
        element = document.getElementById('divcustomerdiscussion').style;
        break;
        
        case "engravingitems":
        element = document.getElementById('divengravingitems').style;
        break;
    }

    if (element.display == "block")
    {
        element.display = "none";
        divArray[0].src = "Images/expand.jpg";
        divArray[0].alt = "Expand";
    }
    else
    {
        element.display = "block";
        divArray[0].src = "Images/collapse.jpg";
        divArray[0].alt = "Collapse";
    }
}

function ToggleCheck(node)
{
   if(node.value == 0)
   {
      node.checked = true;
      node.value = 1;
   }
   else if(node.value == 1)
   {
      node.checked = false;
      node.value = 0;
   }
      
}

function ToggleCustDiscussionDesc(node)
{
    elementshort = document.getElementById('divdescshort' + node.id).style;
    elementfull = document.getElementById('divdescfull' + node.id).style;
    if (elementfull.display == "block")
    {
        elementfull.display = "none"
        elementshort.display = "block"
        node.alt = "Expand";
        
    }
    else
    {
        elementfull.display = "block"
        elementshort.display = "none"
        node.alt = "Collapse";
    }

}

function ValidateQty(node, position, cartlimit, minqty) 
{
    if (node.value == '') return;
    if (node.value < minqty) 
    {
        if (position == 0) {
            node.value = minqty;
            document.getElementById('divQtyMin').style.display = 'block';
        }
        else {
            node.value = minqty;
            document.getElementById('gcdivminqty' + position).style.display = 'block';
        }
    }
    else if (node.value > cartlimit && cartlimit != -1) 
    {
        if (position == 0)
            document.getElementById('divCartLimit').style.display = 'block';
        else
            document.getElementById('gcdivcartlimit' + position).style.display = 'block';
    }
    else
    {
        if (position == 0) {
            document.getElementById('divQtyMin').style.display = 'none';
            document.getElementById('divCartLimit').style.display = 'none';
        }
        else {
            document.getElementById('gcdivcartlimit' + position).style.display = 'none';
            document.getElementById('gcdivminqty' + position).style.display = 'none';
        }
    }
}

function Popup(node)
{
    if(node.id.substring(0,1) == 'T')
    {
        var id = 'DT' + node.id.substring(1);
        ToolTip_Show(node, document.getElementById(id).innerHTML, '');
    }
    else if(node.id.substring(0,1) == 'R')
    {
        id = 'DR' + node.id.substring(1);
        ToolTip_Show(node, document.getElementById(id).innerHTML, '');
    }
}


function ToolTip_Show(zxcobj,zxcdesc,zxcimg)
{
    intIndexOfMatch = 0;
    var zxctxt;
    
    if(zxcdesc != '' || zxcimg != '')
    {
        while (intIndexOfMatch != -1)
        {
            // Relace out the current instance.
            zxcdesc = zxcdesc.replace("¿", "'");
            // Get the index of any next matching substring.
            intIndexOfMatch = zxcdesc.indexOf( "¿" );
        }
        
       if(zxcimg == '')
         zxctxt = "<table><tr><td>" + zxcdesc + "</td></tr></table>";
       else
        zxctxt = "<table><tr valign='top'><td><img alt='' src='" + zxcimg + "'/>" + "</td><td>" + zxcdesc + "</td></tr></table>";
        
        zxcobj.tt=new zxcOOPToolTip(zxcobj,zxctxt);
        clearTimeout(zxcobj.tt.to);
        zxcobj.tt.setTimeOut('show()',0); 
    }
}

function zxcOOPToolTip(zxcobj,zxctxt)
{
    var tooltip = document.getElementById('divtooltip'); 
    tooltip.innerHTML = "<div style='text-align:right;'><img src='Images/close.gif' alt='' onclick='Tooltip_Hide()' /></div>" +   zxctxt;
    var leftPos = (Tooltip_getLeftPos(zxcobj) + zxcobj.offsetWidth);
    var topPos = Tooltip_getTopPos(zxcobj);
    tooltip.style.left = leftPos + 'px';
    tooltip.style.top = topPos + 'px';
    
    this.tt = tooltip;
    this.ref='zxcooptt';
    window[this.ref]=this;
    this.to=null;
}


zxcOOPToolTip.prototype.show=function()
{
    //zxcStyle(this.tt,{visibility:'visible'});
    this.tt.style.display = 'block';
}

zxcOOPToolTip.prototype.hide=function()
{
    //zxcStyle(this.tt,{visibility:'hidden'});
    this.tt.style.display = 'none';
}

zxcOOPToolTip.prototype.setTimeOut=function(zxcf,zxcd)
{
    this.to=setTimeout('window.'+this.ref+'.'+zxcf,zxcd);
}

function Tooltip_getTopPos(node)
{		
  var returnValue = node.offsetTop;
  while((node = node.offsetParent) != null)
  {
  	if(node.tagName!='HTML')returnValue += node.offsetTop;
  }
  return returnValue;
}

function Tooltip_getLeftPos(node)
{
  var returnValue = node.offsetLeft;
  while((node = node.offsetParent) != null)
  {
  	if(node.tagName!='HTML')returnValue += node.offsetLeft;
  }
  return returnValue;
}

function Tooltip_Hide()
{
    if(document.getElementById('divtooltip') != null)
    {
       document.getElementById('divtooltip').style.display = 'none';
    }
}

function CustDiscussionOnClick(itemno, desc, pgindex)
{
    parameters = "{'itemNo':'" + itemno + "','desc':'" + desc + "','pgIndex':'" + pgindex + "'}";
    $.ajax({
        type: "POST",
        url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetCustDiscussion',
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            OnCustDiscussionSucceeded(result.d);
        },
        error: function (xhr, status, error) {
        }
    });

    return false;  	
}

function OnCustDiscussionFailed()
{
}
function OnCustDiscussionSucceeded(result)
{
   ele = document.getElementById('divcustomerdiscussion');
   ele.innerHTML = result;
}

function DropDownListCompSelected(parentitemno, node, sourcecode)
{
   var pricedisplay = false;
   var pricematchid = 0;
   
   var value = node.options[node.selectedIndex].value;
   var title = node.options[node.selectedIndex].title; 
   var index = title.indexOf('¿', 0);

   if(index >= 0)
   {
       pricedisplay = title.substring(0,index);
       pricematchid = title.substring(index + 1);
   }

   $("input[name='crdcomp']").each(function () {
       if ($(this).val() == value) {
           $(this).attr("checked", true);
       }

   });

  ListCompSelectionChange(parentitemno, value, sourcecode, pricedisplay, pricematchid);
    
}

function RadioListCompSelected(parentitemno, node, sourcecode, pricedisplay, pricematchid) {
    var value = node.value;
    
    var ddvalues = document.getElementById("ddlistcomp").options;
    for(i = 0; i < ddvalues.length; i++)
    {
      if(ddvalues[i].value == value)
      {
         ddvalues[i].selected = true;
      }
    }
    
    ListCompSelectionChange(parentitemno, value, sourcecode, pricedisplay, pricematchid);

}

function ListCompSelectionChange(parentitemno, selectedcompitemno, sourcecode, pricedisplay, pricematchid)
{
    parameters = "{'ParentItemNo':'" + parentitemno + "','SelectedItemNo':'" + selectedcompitemno + "','SourceCode':'" + sourcecode + "','PriceDisplay':'" + pricedisplay + "','PriceMatchID':'" + pricematchid + "'}";
    $.ajax({
        type: "POST",
        url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetSelectedListComp',
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            OnListCompSelectionChangeSucceeded(result.d);            
        },
        error: function (xhr, status, error) {
            alert(xhr.statusText);
        }
        
    });

    return false;  	
}

function OnListCompSelectionChangeFailed()
{
}
function OnListCompSelectionChangeSucceeded(result) {
    if (result != null) {
	if (result[2] != '' && result[2] != null) {
            $("#ctl00_ContentPlaceHolder1_segimage").html(result[2]);
        }  
        for (row = document.getElementById("tblitem").rows[0]; row != null; row = row.nextSibling) {
            if (row.nodeType == 1) {
                for (cell = row.firstChild; cell != null; cell = cell.nextSibling) {
                    if (cell.nodeType == 1) {
                        for (ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling) {
                            if (ctl.id != null && ctl.id != '') {
                                if (ctl.id.indexOf("segshortdesc", 0) != -1)
                                    ctl.innerHTML = result[0];

                                else if (ctl.id.indexOf("segresourcepromo", 0) != -1) {
                                    if (result[1] != null && result[1] != '') {
                                        ctl.innerHTML = result[1];
                                        ctl.style.display = "block";
                                    }
                                    else
                                        ctl.style.display = "none";
                                }

                                else if (ctl.id.indexOf("segimage", 0) != -1)
                                    ctl.innerHTML = result[2];

                                else if (ctl.id.indexOf("segranking", 0) != -1)
                                    ctl.innerHTML = result[3];

                                else if (ctl.id.indexOf("segresources", 0) != -1) {
                                    if (result[4] != null && result[4] != '') {
                                        ctl.innerHTML = result[4];
                                        ctl.style.display = "block";
                                    }
                                    else
                                        ctl.style.display = "none";
                                }

                                else if (ctl.id.indexOf("segmanfinfo", 0) != -1) {
                                    if (result[5] != null && result[5] != '') {
                                        ctl.innerHTML = result[5];
                                        ctl.style.display = "block";
                                    }
                                    else
                                        ctl.style.display = "none";
                                }

                                else if (ctl.id.indexOf("segqty", 0) != -1)
                                    ctl.innerHTML = result[6];

                                else if (ctl.id.indexOf("segcustomization", 0) != -1) {
                                    if (result[7] != null && result[7] != '') {
                                        ctl.innerHTML = result[7];
                                        ctl.style.display = "block";
                                    }
                                    else {
                                        ctl.innerHTML = "";
                                        ctl.style.display = "none";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    } 
}
function VKitSelectionChange(parentitemno, pricedisplay, pricematchid, sourcecode) 
{
    var vkitcompItemNos = '';

    $("select[name='ddvkitcomp'] :selected").each(function () {
        vkitcompItemNos += '¿' + $(this).val();        
    });

    if(vkitcompItemNos != '')
    {
        parameters = "{'ParentItemNo':'" + parentitemno + "','SelectedItemNos':'" + vkitcompItemNos + "','PriceDisplay':'" + pricedisplay + "','PriceMatchID':'" + pricematchid + "','SourceCode':'" + sourcecode + "'}";
        $.ajax({
            type: "POST",
            url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetVKitCompPriceandAvail',
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                OnVKitSelectionChangeSucceeded(result.d);
            },
            error: function (xhr, status, error) {
            }
        });

        return false;  	

    }
}

function OnVKitSelectionChangeFailed()
{
}
function OnVKitSelectionChangeSucceeded(result) {

    //    $("#ctl00_ContentPlaceHolder1_segprice").html(result);
    var img = document.getElementById("ctl00_ContentPlaceHolder1_segprice");
    if (img != null)
        img.innerHTML = result;
    setPostBackPriceRef();
}

function StyleSelectionChange(parentitemno, pricedisplayandpricematchid, sourcecode, errmsg) {

    var selectedpropvals = '';
    var selectedpropText = '';

    $("select[name='ddstyles'] :selected").each(function () {
        selectedpropvals += '¿' + $(this).val();
        selectedpropText += ' ' + $(this).attr("title");
    });

    if(selectedpropvals != '')
    {
        var parameters = "{'ParentItemNo':'" + parentitemno + "','SelectedPropVal':'" + selectedpropvals + "','SelectedPropText':'" + selectedpropText.replace(/\'/g, "\\'") + "','PriceDisplayandPriceMatchID':'" + pricedisplayandpricematchid + "','SourceCode':'" + sourcecode + "','ErrMsg':'" + errmsg + "','topID':'0','leftID':'0'}";
        $.ajax({
            type: "POST",
            url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetSelectedStyleComp',
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                OnStyleSelectionChangeSucceeded(result.d);
            },
            error: function (xhr, status, error) {
                //alert(xhr.statusText); 
            }
        });
        return false;  	
    }
}

function IntStyleSelectionChange(parentitemno, pricedisplayandpricematchid, sourcecode, errmsg, key) {
    var selectedpropvals = '';
    var selectedpropText = '';
    var ctl = null;

    $(".stckybrsbtm").each(function () {
        if ($(this).find("select[name='ddstyles']").length > 0) {
            ctl = $(this).find("select[name='ddstyles']");
            selectedpropvals += '¿' + $(ctl).val();
            selectedpropText += ' ' + $("select[name='ddstyles'] :selected").attr("title");
            
        }
        else if ($(this).find("UL").length > 0) {
            ctl = $(this).find("UL");
            $(ctl).children('li').each(function () {
                if (key > 0) {
                    if (key == $(this).attr("id")) {
                        selectedpropvals += '¿' + $(this).attr("id");
                        $(this).css('borderWidth', '3px');
                    }
                    else {
                        $(this).css('borderWidth', '1px');
                    }
                }
                else {
                    if ($(this).css('borderWidth').indexOf('3px', 0) != -1) {
                        selectedpropvals += '¿' + $(this).attr("id");
                    }
                }
            });

        }
    });

    var topid = 0;
    var leftid = 0;

    list = document.getElementById("topfilter")
    for (i = 0; i < list.childNodes.length; i++) {
        child = list.childNodes.item(i);
        if (child.innerHTML.indexOf("_on", 0) > 0) {
            topid = child.id.substring(1);
            break;
        }
    }
    list = document.getElementById("leftfilter")
    for (i = 0; i < list.childNodes.length; i++) {
        child = list.childNodes.item(i);
        if (child.innerHTML.indexOf("_on", 0) > 0) {
            leftid = child.id.substring(1);
            break;
        }
    }


    if (selectedpropvals != '') {
        parameters = "{'ParentItemNo':'" + parentitemno + "','SelectedPropVal':'" + selectedpropvals + "','SelectedPropText':'" + selectedpropText + "','PriceDisplayandPriceMatchID':'" + pricedisplayandpricematchid + "','SourceCode':'" + sourcecode + "','ErrMsg':'" + errmsg + "','topID':'" + topid + "','leftID':'" + leftid + "'}";
        $.ajax({
            type: "POST",
            url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetSelectedStyleComp',
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                OnStyleSelectionChangeSucceeded(result.d);
            },
            error: function (xhr, status, error) {
            }
        });
        return false;

    }
}

function OnStyleSelectionChangeSucceeded(result) {

    if (result.length == 1) {
        if (document.getElementById("ctl00_ContentPlaceHolder1_segintstyles").innerHTML != '') {
            err = document.getElementById("segstyleerr2");
        }
        else {
            err = document.getElementById("segstyleerr1");
        }
        err.innerHTML = result[0];
        err.style.display = "block";
        err.style.background = 'ivory';
        err.style.color = 'red';

    }
    else {

        if (document.getElementById("ctl00_ContentPlaceHolder1_segintstyles").innerHTML != '') {
            err = document.getElementById("segstyleerr2");
        }
        else {
            err = document.getElementById("segstyleerr1");
        }
        err.innerHTML = ' ';  

        if (result[1] != '' && result[1] != null) {
            $("#ctl00_ContentPlaceHolder1_segimage").html(result[1]);
        }
        for (row = document.getElementById("tblitem").rows[0]; row != null; row = row.nextSibling) {
            if (row.nodeType == 1) 
            {
                for (cell = row.firstChild; cell != null; cell = cell.nextSibling) {
                    if (cell.nodeType == 1)                    
                    {
                        for (ctl = cell.firstChild; ctl != null; ctl = ctl.nextSibling) {
                            if (ctl.id != null && ctl.id != '') {
                                
                                if (ctl.id.indexOf("segshortdesc", 0) != -1)
                                    ctl.innerHTML = result[0];

                                else if (ctl.id.indexOf("segimage", 0) != -1) {
                                    ctl.innerHTML = result[1];
                                }

                                else if (ctl.id.indexOf("segranking", 0) != -1)
                                    ctl.innerHTML = result[2];

                                else if (ctl.id.indexOf("segprice", 0) != -1) {
                                    ctl.innerHTML = result[3];
                                    setPostBackPriceRef();
                                }

                                else if (ctl.id.indexOf("segqty", 0) != -1)
                                    ctl.innerHTML = result[4];

                                else if (ctl.id.indexOf("segcustomization", 0) != -1) {
                                    if (result[5] != null && result[5] != '') {
                                        ctl.innerHTML = result[5];
                                        ctl.style.display = "block";
                                        if (currencydisplay) {
                                            var label = document.getElementById("custpriceperchar");
                                            if (label != null)
                                                label.innerHTML = getInitPriceSavingRef(label.innerHTML);
                                            label = document.getElementById("custprice");
                                            if (label != null)
                                                label.innerHTML = getInitPriceSavingRef(label.innerHTML);
                                        }
                                    }
                                    else {
                                        ctl.innerHTML = "";
                                        ctl.style.display = "none";
                                    }
                                }
                                else if (ctl.id.indexOf("segintstyles", 0) != -1) {
                                    if (result[6] != '' && result[6] != null) {
                                        ctl.innerHTML = result[6];
                                        ctl.style.display = "block";
                                    }
                                    else
                                        ctl.style.display = "none";
                                }
                                else if (ctl.id.indexOf("seggrpitems", 0) != -1) {
                                    if (result[7] != '' && result[7] != null) {
                                        ctl.innerHTML = result[7];
                                        ctl.style.display = "block";
                                        SetDraggables();
                                    }
                                    else
                                        ctl.style.display = "none";
                                }
                            }
                        }
                    }
                }
            }
        }
        //this is done temporarly for version 11.03. let me tune the Item.js script in version 11.04 //
        if (result[6] != '' && result[6] != null) {
            $("#ctl00_ContentPlaceHolder1_segintstyles").html(result[6]);
        }
        //this is done temporarly for version 11.03. //

        if (document.getElementById("ctl00_ContentPlaceHolder1_seggrpitems") != null) {
            if (document.getElementById("ctl00_ContentPlaceHolder1_seggrpitems").innerHTML != '') {
                SetDroppables();
                SetPreloadedIcons();
                //calculate price including attached icons.
                CalIntItemPrice();

            }
        }
    } 
}

function EngSelectionChange(retailprice) 
{
    var engWebPrice = 0.0;

    $("select[name='ddengvkitcomp'] :selected").each(function () {
        engWebPrice += $(this).attr("title");
    });

   parameters = "{'webprice':'" + engWebPrice + "'}";
   $.ajax({
       type: "POST",
       url: getBaseURL() + 'MCWebServices/ItemService.asmx/EngItemPriceFormat',
       data: parameters,
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (result) {
           OnEngPriceFormatSucceeded(result.d);
       },
       error: function (xhr, status, error) {
       }
   });

    return false;  	
    
}

function OnEngPriceFormatSucceeded(result)
{
    $("#divengprice").html("<label class='ourprice4'>" + result + "</label>");
}

function OnGetNoAttachmentErrSucceeded(result) {
    $("#segstyleerr1").html(result);
    $("#segstyleerr1").css("display:block");
}

function AddToButtonClick(itemtype, id, itmno, minqty)
{
    var row;
    var cell;
    var ctl; 
    var itemno = '';
    var qty = '';
    var addtoorderitems = '';
    var webprice = 0;
    var surchrg = 0;
    var stock = false;
    var priceOvrdFlag = 0;
    var priceOvrdAmt = 0;
    var priceMatchId = 0;
    var customization = '';
    var vkitcompItemNos = '';
    var engitemno = '';
    var engqty = 1;
    var engitemtype = 1;
    var engcustomization = '';
    var engvkits = '';
    var checked = false;
    var selected = false;
    var reg = new RegExp("[1-9]");
    var CustText = '';
    var GridItems = '';

    // check if interactive items has atleast one icon attachment
    if ($("#divimg").length > 0) {

        for (i = 0; i < PlotArray.length; i++) {
            if (PlotArray[i][2] != '') {
                selected = true;
                break;
            }
        }
        if (!selected) {
            parameters = "{}";
            $.ajax({
                type: "POST",
                url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetNoAttachmentErr',
                data: parameters,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    OnGetNoAttachmentErrSucceeded(result.d);
                },
                error: function (xhr, status, error) {
                }
            });
            return false;
        }
    }

    selected = false;
   // final check for required customization and calculate cust price.
    if ($("#tblCust").length > 0) {
        CalculateCustPrice();

        if (Custfailed)
            return;
    }

    if (id == "CART" || id == "WISHLIST") {
        itemno = $("#itemno").attr("title");
        if (document.getElementById("txtWidth") && document.getElementById("txtWidth").attributes["id"] !=null) {
            
            qty = ($("#txtWidth").val() * 2) +
                  ($("#txtHeight").val() * 2)

            qty = Math.ceil(qty);
customization = '¿' + "Width " + $("#txtWidth").val() + '¿' +
                            "Height " + $("#txtHeight").val();
        }
        else
        {

        qty = $("#txtQuantity").val();
    }
    } else if (id == "EKITCART") // used in the case of EKITS 'Buy together and save'
    {
        itemno = itmno;
        qty = minqty;
    } else if (id == "ITEMLISTCART" || id == "WISHLISTCART") {
        itemno = itmno;
        qty = minqty;
        id = "CART";
    }
  
  if(id == "CART" || id == "GRIDCART" || id == "EKITCART") {
        //get Recommended ItemNos if checked to add to cart
      $("input[name='ckaddrectoorder']").each(function () {
          if ($(this).is(":checked"))
              addtoorderitems += '¿' + $(this).attr("id");
      });
       
        
       //get TopSelling ItemNos if checked to add to cart
      $("input[name='ckaddtoptoorder']").each(function () {
          if ($(this).is(":checked"))
              addtoorderitems += '¿' + $(this).attr("id");
      });

  }

  if (id == "CART" || id == "WISHLIST") {
      //get price for list items with multiple comps
      if ($("input[name='crdcomp']").length > 0) {
          $("input[name='crdcomp']").each(function () {
              if ($(this).is(':checked')) {
                  position = $(this).attr("id").substring($(this).attr("id").indexOf('-', 0) + 1);
                  if ($("#cwebprice" + position).length > 0)
                      webprice = trim($("#cwebprice" + position).text());
                  if ($("#cexclvatprice" + position).length > 0)
                      webprice = trim($("#cexclvatprice" + position).text());
                  if ($("#csurchrg" + position).length > 0)
                      surchrg = trim($("#csurchrg" + position).text());
                  if ($("#cexclvatsurchrg" + position).length > 0)
                      surchrg = trim($("#cexclvatsurchrg" + position).text());
                  if ($("#cpriceoverride" + position).length > 0) {
                      priceOvrdFlag = 1;
                      priceOvrdAmt = $("#cpriceoverride" + position).val();
                      if (!reg.test(priceOvrdAmt)) {
                          $("#cpriceoverride" + position).css("color:red");
                          $("#cpriceoverride" + position).focus();
                          return;
                      }
                  }
                  if ($("#cpricematch" + position).length > 0) {
                      priceOvrdFlag = 2;
                      priceOvrdAmt = trim($("#cpricematch" + position).text());
                  }
                  if ($("input[name=cpricematchid]").length > 0) {
                      priceMatchId = $('input[name=cpricematchid]').val();
                  }
                  if ($("#cavail" + position).length > 0)
                      stock = $("#cavail" + position).val();
              }
          });
      }
      else // get price for non list items and list item with 1 comp
      {
          if ($("#webprice").length > 0)
              webprice = trim($("#webprice").text());
          if ($("#exclvatprice").length > 0)
              webprice = trim($("#exclvatprice").text());
          if ($("#surchrg").length > 0)
              surchrg = trim($("#surchrg").text());
          if ($("#exclvatsurchrg").length > 0)
              surchrg = trim($("#exclvatsurchrg").text());
          if ($("#priceoverride").length > 0) {
              priceOvrdFlag = 1;
              priceOvrdAmt = $("#priceoverride").val();
              if (!reg.test(priceOvrdAmt)) {
                  $("#priceoverride").css("color:red");
                  $("#priceoverride").focus();
                  return;
              }
          }
          if ($("#pricematch").length > 0) {
              priceOvrdFlag = 2;
              priceOvrdAmt = trim($("#pricematch").text());
          }
          if ($("#pricematchid").length > 0) {
              priceMatchId = $("#pricematchid").val();
          }
          if ($("#avail").length > 0)
              stock = $("#avail").val();
      }
  }

  if (id == "CART") {
      // capture customization
      $("#tblCust input:text").each(function () {
          customization += '¿' + $(this).val();
      });

      if ($("#custdisptxt").length > 0)
          CustText = $("#custdisptxt").val();

      //capture variablekit
      $("select[name='ddvkitcomp'] :selected").each(function () {
          if ($(this).attr("selectedIndex") != 0)
              vkitcompItemNos += '¿' + $(this).val();
      });

      //capture interactive icons if exists
      if ($("#divimg").length > 0) {
          for (i = 0; i < PlotArray.length; i++) {
              if (PlotArray[i][2] != '') {  //img id
                  vkitcompItemNos += '¿' + PlotArray[i][2] + '|' + PlotArray[i][1];
              }
          }
      }

      //capture Engraving

      if ($("#ckengraving").is(":checked")) {
          engitemno = $("#eitemno").val();
          engitemtype = $("#eitemtype").val();

          $("input[name='txtCustParam']").each(function () {
              engcustomization += '¿' + $(this).val();
          });

          $("select[name='ddengvkitcomp'] :selected").each(function () {
              var index = $(this).val().indexOf(' : ', 0);
              if (index != -1)
                  engvkits += '¿' + $(this).val().substr(index + 3);
              else
                  engvkits += '¿' + $(this).val();
          });
      }
  }

if (id == "GRIDCART" || id == "GRIDWISHLIST") {
    $(".gridcomp *").each(function () {
        var ctlid = $(this).attr('id');
        var ctlname = $(this).attr('name');

        if (ctlid != null && ctlid != '') {
            if (ctlid.indexOf("gcitemno", 0) != -1) {
                itemno = $(this).attr('title');
            }
            else if (ctlid.indexOf("gcpricematch", 0) != -1) {
                priceOvrdFlag = 2;
                priceOvrdAmt = trim($(this).val());
            }
            else if (ctlid.indexOf("gcpriceoverride", 0) != -1) {
                priceOvrdFlag = 1;
                priceOvrdAmt = trim($(this).val());
                if (!reg.test(priceOvrdAmt)) {
                    $(this).css("color", "red");
                    $(this).focus();
                    return;
                }

            }
            else if (ctlid.indexOf("gcwebprice", 0) != -1) {
                webprice = trim($(this).text());
            }
            else if (ctlid.indexOf("gcexclvatprice", 0) != -1) {
                webprice = trim($(this).text());
            }
            else if (ctlid.indexOf("gcsurchrg", 0) != -1) {
                surchrg = trim($(this).text());
            }
            else if (ctlid.indexOf("gcexclvatsurchrg", 0) != -1) {
                surchrg = trim($(this).text());
            }
            else if (ctlid.indexOf("gctxtQuantity", 0) != -1) {
                qty = $(this).val();
                if (qty > 0) {
                    GridItems += '<Item>';
                    GridItems += '<ItemNo>' + itemno + '</ItemNo>';
                    GridItems += '<ItemType>' + itemtype + '</ItemType>';
                    GridItems += '<Qty>' + qty + '</Qty>';
                    GridItems += '<PriceOvrdFlag>' + priceOvrdFlag + '</PriceOvrdFlag>';
                    GridItems += '<PriceOvrdAmt>' + priceOvrdAmt + '</PriceOvrdAmt>';
                    GridItems += '<PriceMatchID>' + priceMatchId + '</PriceMatchID>';
                    GridItems += '<WebPrice>' + webprice + '</WebPrice>';
                    GridItems += '<Stock>' + stock + '</Stock>';
                    GridItems += '<SurChrg>' + surchrg + '</SurChrg>';
                    GridItems += '<VKits>' + vkitcompItemNos + '</VKits>';
                    GridItems += '</Item>';
                }
                vkitcompItemNos = '';
            }

        }
        else if (ctlname == 'gcitemtype') {
            itemtype = $(this).val();
        }
        else if (ctlname == 'gcpricematchid') {
            priceMatchId = $(this).val();
        }
        else if (ctlname == 'gcavail') {
            stock = $(this).val();
        }
        else if (ctlname == 'ddvkitcomp') {
            if ($(this).val() != '0')
                vkitcompItemNos += '¿' + $(this).val();
        }
    });
}
  
 if(id == "CART" || id == "EKITCART")
 {
     var custString = CustText.replace("'", "&#39;");
     parameters = "{'ItemNo':'" + itemno + "','ItemType':'" + itemtype + "','Qty':'" + qty + "','AddToOrderItems':'" + addtoorderitems + "','PriceOvrdFlag':'" + priceOvrdFlag + "','PriceMatchId':'" + priceMatchId + "','PriceOvrdAmt':'" + priceOvrdAmt + "','Customization':'" + customization + "','VkitComps':'" + vkitcompItemNos + "','EngItemNo':'" + engitemno + "','EngQty':'" + engqty + "','EngItemType':'" + engitemtype + "', 'EngCustomization':'" + engcustomization + "','EngVKits':'" + engvkits + "','CustPrice':'" + CustPrice + "','CustDispText':'" + custString + "'}";
     $.ajax({
         type: "POST",
         url: getBaseURL() + 'MCWebServices/ItemService.asmx/AddItemToCart',
         data: parameters,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (result) {
             OnAddToCartSucceeded(result.d);
         },
         error: function (xhr, status, error) {
             //alert(xhr.statusText); 
         }
     });

 }
 else if(id == "GRIDCART")
 {
     parameters = "{'GridComps':'<Items>" + GridItems + "</Items>','AddToOrderItems':'" + addtoorderitems + "'}";
     $.ajax({
         type: "POST",
         url: getBaseURL() + 'MCWebServices/ItemService.asmx/AddItemsToCart',
         data: parameters,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (result) {
             OnAddToCartSucceeded(result.d);
         },
         error: function (xhr, status, error) {
         }
     });

 }
 else if(id == "WISHLIST")
 {
     parameters = "{'ItemNo':'" + itemno + "','ItemType':'" + itemtype + "','Qty':'" + qty + "','WebPrice':'" + webprice + "','Surcharge':'" + surchrg + "','Stock':'" + stock + "','PriceOvrdAmt':'" + priceOvrdAmt + "','CustPrice':'" + CustPrice + "'}";
     $.ajax({
         type: "POST",
         url: getBaseURL() + 'MCWebServices/ItemService.asmx/AddItemToWishList',
         data: parameters,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (result) {
             OnAddToWishListSucceeded(result.d);
         },
         error: function (xhr, status, error) {
         }
     });
 }
 else if(id == "GRIDWISHLIST")
 {
     parameters = "{'GridComps':'<Items>" + GridItems + "</Items>'}";
     $.ajax({
         type: "POST",
         url: getBaseURL() + 'MCWebServices/ItemService.asmx/AddItemsToWishList',
         data: parameters,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (result) {
             OnAddToWishListSucceeded(result.d);
         },
         error: function (xhr, status, error) {
         }
     });
 }
 return false;  	

}

function OnAddToCartFailed()
{
}
function OnAddToCartSucceeded(result) {

    var results = result.split("||");
    var returnString = results[0];
    var showFloatingCart = results[1];

    if (showFloatingCart == "true") {
        GetFloatingCart(returnString);
    }
    else {
        var redirectURL = "/CartPage.aspx";
        if (returnString != null || returnString.length > 0) {
            if (returnString.indexOf("--item-") > -1) {
                redirectURL = "/CartPage" + returnString;
            }
        }
        window.location.href = redirectURL;
    }
}

function OnAddToWishListFailed()
{
}
function OnAddToWishListSucceeded(result)
{
   window.location.href = "Members/WishListUpdate.aspx" ;
}


function ToggleRateIt(node)
{
   var val = node.options[node.selectedIndex].value;
   Rank = val;
   MaxRank = node.length - 1;
   var div = document.getElementById('divcustrating');
   var i ;
   
   if(div != null)
   {
       for (i = 0; i < div.childNodes.length; i++) 
       {
           var child = div.childNodes.item(i);
           if (child.nodeName == "IMG")
           {
                if (val == -1) 
                    child.style.visibility = "hidden";
                else  
                    child.style.visibility = "visible";
                    
                break;
           }
       }
    }
       
}

function RateItOnClick(itemno)
{
    parameters = "{'itemno':'" + itemno + "','rank':'" + Rank + "','maxrank':'" + MaxRank + "'}";
    $.ajax({
        type: "POST",
        url: getBaseURL() + 'MCWebServices/ItemService.asmx/InsertItemOverallRanking',
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            OnRateItSucceeded(result.d);
        },
        error: function (xhr, status, error) {
        }
    });
    return false;  	
}
function OnRateItFailed()
{
}
function OnRateItSucceeded(result)
{
   window.location.href = result ;
}

function CalculateCustPrice() {

    PricePerChar = 0;
    PricePerCharThld = 0;
    FlatFee = 0;
    defCurSymbol = '';
    customization = '';
    Custfailed = false;

    PricePerChar = new Number($("#PricePerChar").val());
    PricePerCharThld = new Number($("#PricePerCharThld").val());
    FlatFee = new Number($("#FlatFee").val());
    defCurSymbol = $("#defSymbol").val();

    // capture customization
    $("#tblCust input:text").each(function () {
        if ($(this).attr("name") == 'txtCustReq' && trim($(this).val()).length == 0) {
            $(this).focus();
            Custfailed = true;
            $(this).parent().parent().find(".custreq").css({ 'color': 'Red' })
        }
        else if ($(this).attr("name") == 'txtCustReq' && trim($(this).val()).length > 0) {
            $(this).parent().parent().find(".custreq").css({ 'color': 'Black' })
            customization += trim($(this).val());
        }
        else if ($(this).attr("name") == 'txtCustOpt') {
            customization += trim($(this).val());
        }

    });

    if (Custfailed)
            return -1;


    CustPrice = 0.0;
    if (customization.length > 0 && (PricePerChar > 0 || FlatFee > 0)) {
        CustPrice = FlatFee;
        //calculate price to chars only not to space.
        j = 0;
        temp = new Array();
        for (i = 0; i < customization.length; i++) {
            if (customization[i] != ' ') {
                temp[j] = customization[i];
                j++;
            }
        }

        if (temp.length > PricePerCharThld)
            CustPrice = ((temp.length - PricePerCharThld) * PricePerChar) + FlatFee;

        var div = document.createElement('div');
        div.innerHTML = setCustCalPrice(defCurSymbol + CustPrice.toFixed(2));
        CustPrice = div.innerHTML;

        var label = document.getElementById('custprice');
        if (label != null) {
            label.innerHTML = CustPrice;
        }
    }

}

function GridVKitSelectionChange(GridHdr, parentitemno, pricedisplay, pricematchid, sourcecode, rowIndex) {
    var vkitcompItemNos = '';

    $("select[name='ddvkitcomp'] :selected").each(function () {
        vkitcompItemNos += '¿' + $(this).val();
    });

    if (vkitcompItemNos != '') {
        parameters = "{'GridHdr':'" + GridHdr + "','ParentItemNo':'" + parentitemno + "','SelectedItemNos':'" + vkitcompItemNos + "','PriceDisplay':'" + pricedisplay + "','PriceMatchID':'" + pricematchid + "','SourceCode':'" + sourcecode + "','CompPosition':'" + rowIndex + "'}";
        $.ajax({
            type: "POST",
            url: getBaseURL() + 'MCWebServices/ItemService.asmx/GridVKitSelectionChange',
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                OnGridVKitSelectionChangeSucceeded(result.d);
            },
            error: function (xhr, status, error) {
            }
        });

        return false;

    }
}

function OnGridVKitSelectionChangeFailed() {
}
function OnGridVKitSelectionChangeSucceeded(result) {

    for (row = document.getElementById("tbgridcomp").rows[0]; row != null; row = row.nextSibling) {
        if (row.nodeType == 1 && row.rowIndex == result[0]) {
            for (cell = row.firstChild; cell != null; cell = cell.nextSibling) {
                if (cell.nodeType == 1) {
                    if (cell.innerHTML.indexOf('gcavail', 0) > 0) {
                        cell.innerHTML = result[1];
                    }
                    else if (cell.innerHTML.indexOf('tdprice', 0) > 0) {
                        cell.innerHTML = result[2];
                    }
                    //else if (cell.innerHTML.indexOf('gctxtQuantity', 0) > 0) {
                    //    cell.innerHTML = result[3];
                    //}
              
                }
            }
        }
    }
}

function TopFilterChange(node, itemno) {

    InteractiveImgID = 0;
    if (document.getElementById("intimgid") != null)
        InteractiveImgID = document.getElementById("intimgid").value;
        
    var list = document.getElementById("topfilter")
    var topid = 0;
    var leftid = 0;

    for (i = 0; i < list.childNodes.length; i++) {
        var child = list.childNodes.item(i);
        if (child == node) {
            child.innerHTML = child.innerHTML.replace("_off", "_on") || child.innerHTML.replace("_Off", "_on");
            topid = child.id.substring(1);
        }
        else {
            child.innerHTML = child.innerHTML.replace("_on", "_off") || child.innerHTML.replace("_On", "_off");
        }
    }
    
   list = document.getElementById("leftfilter")
   for (i = 0; i < list.childNodes.length; i++) {
       child = list.childNodes.item(i);
       if (child.innerHTML.indexOf("_on", 0) > 0 || child.innerHTML.indexOf("_On", 0) > 0) {
           leftid = child.id.substring(1);
           break;
       }
   }

   parameters = "{'itemNo':'" + itemno + "','topID':'" + topid + "','leftID':'" + leftid + "','InteractiveImgID':'" + InteractiveImgID + "'}";
   $.ajax({
       type: "POST",
       url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetGroupItems',
       data: parameters,
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (result) {
           OnGetGroupItemsSucceeded(result.d);
       },
       error: function (xhr, status, error) {
       }
   });

   return false;

}

function LeftFilterChange(node, itemno) {

    InteractiveImgID = 0;
    if (document.getElementById("intimgid") != null)
        InteractiveImgID = document.getElementById("intimgid").value;

    var list = document.getElementById("leftfilter")
    var topid = 0;
    var leftid = 0;

    for (i = 0; i < list.childNodes.length; i++) {
        var child = list.childNodes.item(i);
        if (child == node) {
            child.innerHTML = child.innerHTML.replace("_off", "_on") || child.innerHTML.replace("_Off", "_on");
            leftid = child.id.substring(1);
        }
        else {
            child.innerHTML = child.innerHTML.replace("_on", "_off") || child.innerHTML.replace("_On", "_off");
        }
    }
    
   list = document.getElementById("topfilter")
   for (i = 0; i < list.childNodes.length; i++) {
       child = list.childNodes.item(i);
       if (child.innerHTML.indexOf("_on", 0) > 0 || child.innerHTML.indexOf("_On", 0) > 0) {
           topid = child.id.substring(1);
           break;
       }
   }

   parameters = "{'itemNo':'" + itemno + "','topID':'" + topid + "','leftID':'" + leftid + "','InteractiveImgID':'" + InteractiveImgID + "'}";
   $.ajax({
       type: "POST",
       url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetGroupItems',
       data: parameters,
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (result) {
           OnGetGroupItemsSucceeded(result.d);
       },
       error: function (xhr, status, error) {
       }
   });
   return false;

}

function OnGetGroupItemsFailed() {
}
function OnGetGroupItemsSucceeded(result) {
    if (result != null) {
        var div = document.getElementById("ctl00_ContentPlaceHolder1_seggrpitems");
        if (div != null) {
            div.innerHTML = '';
            div.innerHTML = result;
            SetDraggables();
        }
    }
}

function GetAlternativeImgView(parentitemno, parentitemtype, selecteditemno, source, selectedimgid) {
        
    var topid = 0;
    var leftid = 0;

    list = document.getElementById("topfilter")
    for (i = 0; i < list.childNodes.length; i++) {
        child = list.childNodes.item(i);
        if (child.innerHTML.indexOf("_on", 0) > 0) {
            topid = child.id.substring(1);
            break;
        }
    }
    list = document.getElementById("leftfilter")
    for (i = 0; i < list.childNodes.length; i++) {
        child = list.childNodes.item(i);
        if (child.innerHTML.indexOf("_on", 0) > 0) {
            leftid = child.id.substring(1);
            break;
        }
    }

    parameters = "{'ParentItemNo':'" + parentitemno + "','ParentItemType':'" + parentitemtype + "','SelectedItemNo':'" + selecteditemno + "','SourceCode':'" + source + "','selectedImgID':'" + selectedimgid + "','topID':'" + topid + "','leftID':'" + leftid + "'}";
    $.ajax({
        type: "POST",
        url: getBaseURL() + 'MCWebServices/ItemService.asmx/GetAlternativeImgView',
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            OnGetAlternativeImgViewSucceeded(result.d);
        },
        error: function (xhr, status, error) {
        }
    });
    return false;

}

function OnGetAlternativeImgViewFailed() {
}
function OnGetAlternativeImgViewSucceeded(result) {
    if (result != null) {

        if (result[0] != null || result[0] != '') {
            div = document.getElementById("ctl00_ContentPlaceHolder1_segimage");
            if (div != null) {
                div.innerHTML = '';
                div.innerHTML = result[0];
                SetDroppables();
                SetPreloadedIcons();
                //calculate price including attached icons.
                CalIntItemPrice();
            }
        }

        if (result[1] != null || result[1] != '') {
            div = document.getElementById("ctl00_ContentPlaceHolder1_seggrpitems");
            if (div != null) {
                div.innerHTML = '';
                div.innerHTML = result[1];
                SetDraggables();
            }
        }
    }
}

function SetDroppables() {
    $(document).ready(function() {

        $("#divimg > div").droppable({

            accept: '#draggables:td img',
            drop: function(event, ui) {
                var Isexist = false;

                $(this).html('');
                $(this).css('backgroundColor', 'transparent');

                ui.draggable.attr('title', 'Double click to remove the icons');
                ui.draggable.attr('ondblclick', 'javascript:RemoveImage(this);');
                ui.draggable.ondblclick = function() { RemoveImage(this); };

                $(this).append(ui.draggable.clone().css('width', $(this).css('width')).css('height', $(this).css('height'))).fadeIn();

                //delete the noattachmenterr if exists
                var element = document.getElementById("segstyleerr1");
                element.innerHTML = '';
                element.style.display = 'none';

                for (j = 0; j < PlotArray.length; j++) {
                    if (PlotArray[j] != null) {
                        if (PlotArray[j][0] == $(this).attr('id')) {
                            PlotArray[j][1] = $(this).attr('title');
                            PlotArray[j][2] = ui.draggable.attr('id')
                            PlotArray[j][3] = ui.draggable.attr('src')
                            PlotArray[j][4] = ui.draggable.attr('alt')
                            Isexist = true;
                            break;
                        }
                    }
                }

                if (!Isexist) {
                    k = PlotArray.length;
                    PlotArray[k] = new Array(5);
                    PlotArray[k][0] = $(this).attr('id');
                    PlotArray[k][1] = $(this).attr('title');
                    PlotArray[k][2] = ui.draggable.attr('id')
                    PlotArray[k][3] = ui.draggable.attr('src')
                    PlotArray[k][4] = ui.draggable.attr('alt')
                }

                //calculate price including attached icons.
                CalIntItemPrice();
            }
        });
    });
}
function CalIntItemPrice() {

    attachItemIDs = '';
    for (i = 0; i < PlotArray.length; i++) {
        if (PlotArray[i][2] != '') {  //img id
            attachItemIDs += '¿' + PlotArray[i][2];
        }
    }
    if (attachItemIDs != '') {
        parameters = "{'ParentItemNo':'" + document.getElementById("itemno").title + "','AttachedItemIDs':'" + attachItemIDs + "','SourceCode':'" + document.getElementById("source").value + "'}";
        $.ajax({
            type: "POST",
            url: getBaseURL() + 'MCWebServices/ItemService.asmx/CalIntItemPrice',
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                CalIntItemPriceSucceeded(result.d);
            },
            error: function (xhr, status, error) {
            }
        });
        return false;
    }

}
function CalIntItemPriceFailed() {
}
function CalIntItemPriceSucceeded(result) {
    if (result != null) {
        var div = document.getElementById("ctl00_ContentPlaceHolder1_segprice");
        if (div != null) {
            div.innerHTML = '';
            div.innerHTML = result;
        }
    }
}
function SetDraggables() {
    $(document).ready(function() {
        $("#draggables:td img").draggable({
            revert: 'valid',
            cursor: 'move',
            helper: 'clone'
        });
    });
}


function SetPreloadedIcons() {
    var div = document.getElementById("divimg");
    if (div != null) {
        for (i = 0; i < div.childNodes.length; i++) {
            child = div.childNodes.item(i);
            if (child.id.indexOf('plot', 0) != -1) {
                for (j = 0; j < PlotArray.length; j++) {
                    if (PlotArray[j] != null) {
                        if (PlotArray[j][0] == child.id) {
                            if (PlotArray[j][2] != '') {
                                var image = document.createElement('IMG');
                                image.setAttribute('id', PlotArray[j][2]);
                                image.setAttribute('src', PlotArray[j][3]);
                                image.setAttribute('alt', PlotArray[j][4]);
                                image.setAttribute('width', child.style.width);
                                image.setAttribute('height', child.style.height);
                                image.setAttribute('title', 'Double click to remove the icons');
                                image.setAttribute('ondblclick', 'javascript:RemoveImage(this);');
                                image.ondblclick = function() { RemoveImage(this); };
                                child.style.backgroundColor = 'transparent';
                                child.appendChild(image);
                                image.style.width = child.style.width;
                                image.style.height = child.style.height;
                            }
                        }
                    }
                }
            }
        }
    }
}


function RemoveImage(node) {
    id = node.parentNode.id;
    node.parentNode.style.backgroundColor = 'transparent';
    node.parentNode.innerHTML = '';

    for (i = 0; i < PlotArray.length; i++) {
        if (id == PlotArray[i][0]) {
            PlotArray[i][2] = '';
            PlotArray[i][3] = '';
            PlotArray[i][4] = '';
        }
    }

    //calculate price including attached icons.
    attachItemIDs = '';
    for (i = 0; i < PlotArray.length; i++) {
        if (PlotArray[i][2] != '') {  //img id
            attachItemIDs += '¿' + PlotArray[i][2];
        }
    }
    parameters = "{'ParentItemNo':'" + document.getElementById("itemno").title + "','AttachedItemIDs':'" + attachItemIDs + "','SourceCode':'" + document.getElementById("source").value + "'}";
    $.ajax({
        type: "POST",
        url: getBaseURL() + 'MCWebServices/ItemService.asmx/CalIntItemPrice',
        data: parameters,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {
            CalIntItemPriceSucceeded(result.d);
        },
        error: function (xhr, status, error) {
        }
    });
    return false;
}

// Removes leading whitespaces
function LTrim(value) {

    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");

}

// Removes ending whitespaces
function RTrim(value) {

    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");

}

// Removes leading and ending whitespaces
function trim(value) {

    return LTrim(RTrim(value));

}

function setCustCalPrice(price) {
    if (!currencydisplay)
        return price;
    return getInitPrice(price);
}

function setPostBackPriceRef() {
    if (!currencydisplay)
        return;
    setPostBackPrice();
}

function getInitPriceSavingRef(price) {
    if (!currencydisplay)
        return;
    getInitPriceSaving(price);
}


