﻿// JScript File

    // This function is used to add the enter key event to hit the default button (for LinkButton) 
    function GetEnterKey(controlID) 
    {
        var e = document.getElementById(controlID);
        if (e && typeof(e.click) == 'undefined') e.click = function()
         {
            var result = true; if (e.onclick) result = e.onclick();
            if (typeof(result) == 'undefined' || result) 
            {
                eval(e.href); 
            }                
         }
     }
     
    function RemoveDefaultValue(objControl, objDefaultValue)
    {
        if(objControl != null)
        {
            if(objControl.value == objDefaultValue)
            {
                objControl.value = "";
            }
        }
    }

    function SetDefaultValue(objControl, objDefaultValue)
    {
        if(objControl != null)
        {
            if(Trim(objControl.value) == "")
            {
                objControl.value = objDefaultValue;
            }
        }
    }

    function Trim(inputstring)
    {
        if(inputstring != "")
        {
            while (inputstring.substring(0,1) == ' ')
            {
	            inputstring = inputstring.substring(1,inputstring.length);
            }
                while (inputstring.substring(inputstring.length-1,inputstring.length) == ' ') 
            {
	            inputstring = inputstring.substring(0,inputstring.length-1);
            }
            return inputstring;
        }
        else
        {
            return inputstring;
        }
    }   

    function SetQtyHiddenValue(str,ID)
       {
          alert(str+"#"+ID);
          if(document.getElementById(ID).value!="")
          {
              str=str+"_"+document.getElementById(ID).value;
              var temp = new Array();
              temp = str.split('~');
              str=getDomainName()+temp[1];
           }
          else
          {
              var temp = new Array();
              temp = str.split('~');
              str=getDomainName()+temp[1];
          }
          //alert(str);
          document.location.href=str;
    }
    
    function SetQtyHiddenValueMyWishList(str,ID,ItemCode)
       {
          alert(str+"#"+ID);
          if(document.getElementById(ID).value!="")
          {
              str=str+"_"+document.getElementById(ID).value;
              var temp = new Array();
              temp = str.split('~');
              str=getDomainName()+temp[1];
           }
          else
          {
              var temp = new Array();
              temp = str.split('~');
              str=getDomainName()+temp[1];
          }
          removecartitem(ItemCode);
          //alert(str);
          document.location.href=str;
    }
    
    function getDomainName()
    {
        var currenturl;
        currenturl = window.location.href;
        
        if(currenturl.indexOf("PublicStore") >= 0)
            {
              if(currenturl.indexOf("https")>=0)
                { 
                currenturl = "https://" + document.domain + "/publicstore";
                }
              else
              {
               currenturl = "http://" + document.domain + "/publicstore";
              }  
            }
        else
        {
         if(currenturl.indexOf("https")>=0)
              { 
            currenturl = "https://" + document.domain;
            }
            else
            {
             currenturl = "http://" + document.domain;  
            }
            
       }
            
        return currenturl;
  }
 
 function checkdate(input)
 {
    //alert(1);
    var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
    var returnval=false
    if (!validformat.test(input.value))
    alert("Invalid Date Format. Please correct and submit again.")
    else{ //Detailed check for valid date ranges
    var monthfield=input.value.split("/")[0]
    var dayfield=input.value.split("/")[1]
    var yearfield=input.value.split("/")[2]
    var dayobj = new Date(yearfield, monthfield-1, dayfield)
    if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
    alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")
    else
    returnval=true
    }
    if (returnval==false) input.select()
    return returnval
}

// JScript File

    function Print()
    {
        alert("Operation Completed");
    }
    
   function Check()						 
	{
	    for(var i=0; i < document.forms[0].elements.length; i++)
        {
            strElement = document.forms[0].elements[i].id;
            if(strElement.substring(strElement.length-12, strElement.length) == "chkSelectAll")
            {
                   CheckAll(document.forms[0].elements[i],"chkItemId");
            }
        }
    }
    function ChkItemSelected()
    { 
        var IsItemSelected = false;
        for(var i=0; i < document.forms[0].elements.length; i++)
        {
            strElement = document.forms[0].elements[i].id;
            if(strElement.substring(strElement.length-9, strElement.length) == "chkItemId")
            {
                if(document.forms[0].elements[i].checked)
                {
                   IsItemSelected = true;
                }
            }
        }
        if(IsItemSelected == false)
        {
            alert("Please select any item to clear.");
            return false;
        } 
        return true;    
    }
/***********************************Addition By Uzma For ToolTip*******************************************/
/***********************dw_event.js**************************/
var dw_event = {
  
  add: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
    else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);
  }, 

  remove: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
    else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);
  }, 

  DOMit: function(e) { 
    e = e? e: window.event;
    e.tgt = e.srcElement? e.srcElement: e.target;
    
    if (!e.preventDefault) e.preventDefault = function () { return false; }
    if (!e.stopPropagation) e.stopPropagation = function () { if (window.event) window.event.cancelBubble = true; }
        
    return e;
  }
  
}
/**************************************************************/
/************************dw_viewport.js************************/
var viewport = {
  getWinWidth: function () {
    this.width = 0;
    if (window.innerWidth) this.width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
  		this.width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		this.width = document.body.clientWidth;
  },
  
  getWinHeight: function () {
    this.height = 0;
    if (window.innerHeight) this.height = window.innerHeight - 18;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		this.height = document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		this.height = document.body.clientHeight;
  },
  
  getScrollX: function () {
    this.scrollX = 0;
  	if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		this.scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		this.scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) this.scrollX = window.scrollX;
  },
  
  getScrollY: function () {
    this.scrollY = 0;    
    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
  		this.scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		this.scrollY = document.body.scrollTop; 
  	else if (window.scrollY) this.scrollY = window.scrollY;
  },
  
  getAll: function () {
    this.getWinWidth(); this.getWinHeight();
    this.getScrollX();  this.getScrollY();
  }
  
}
/**************************************************************/
/**************************dw_tooltip.js***********************/


var Tooltip = {
    followMouse: true,
    offX: 8,
    offY: 12,
    tipID: "tipDiv",
    showDelay: 100,
    hideDelay: 200,
    
    ready:false, timer:null, tip:null, 
  
    init: function() {  
        if ( document.createElement && document.body && typeof document.body.appendChild != "undefined" ) {
            if ( !document.getElementById(this.tipID) ) {
                var el = document.createElement("DIV");
                el.id = this.tipID; document.body.appendChild(el);
            }
            this.ready = true;
        }
    },
    
    show: function(e, msg) {
        if (this.timer) { clearTimeout(this.timer);	this.timer = 0; }
        this.tip = document.getElementById( this.tipID );
        if (this.followMouse) // set up mousemove 
            dw_event.add( document, "mousemove", this.trackMouse, true );
        this.writeTip("");  // for mac ie
        this.writeTip(msg);
        viewport.getAll();
        this.positionTip(e);
        this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'visible')", this.showDelay);
    },
    
    writeTip: function(msg) {
        if ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = msg;
    },
    
    positionTip: function(e) {
        if ( this.tip && this.tip.style ) {
            // put e.pageX/Y first! (for Safari)
            var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
            var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;
    
            if ( x + this.tip.offsetWidth + this.offX > viewport.width + viewport.scrollX ) {
                x = x - this.tip.offsetWidth - this.offX;
                if ( x < 0 ) x = 0;
            } else x = x + this.offX;
        
            if ( y + this.tip.offsetHeight + this.offY > viewport.height + viewport.scrollY ) {
                y = y - this.tip.offsetHeight - this.offY;
                if ( y < viewport.scrollY ) y = viewport.height + viewport.scrollY - this.tip.offsetHeight;
            } else y = y + this.offY;
            
            this.tip.style.left = x + "px"; this.tip.style.top = y + "px";
        }
    },
    
    hide: function() {
        if (this.timer) { clearTimeout(this.timer);	this.timer = 0; }
        this.timer = setTimeout("Tooltip.toggleVis('" + this.tipID + "', 'hidden')", this.hideDelay);
        if (this.followMouse) // release mousemove
            dw_event.remove( document, "mousemove", this.trackMouse, true );
        this.tip = null; 
    },

    toggleVis: function(id, vis) { // to check for el, prevent (rare) errors
        var el = document.getElementById(id);
        if (el) el.style.visibility = vis;
    },
    
    trackMouse: function(e) {
    	e = dw_event.DOMit(e);
     	Tooltip.positionTip(e);
    }
    
}

/**************************************************************/

Tooltip.offX = 4;  
Tooltip.offY = 4;
Tooltip.followMouse = false;

Tooltip.timerId = 0;
function doTooltip(e, msg) 
{
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.clearTimer();
  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
  if ( tip && tip.onmouseout == null ) 
  {
      tip.onmouseout = Tooltip.tipOutCheck;
      tip.onmouseover = Tooltip.clearTimer;
  }
  Tooltip.show(e, msg);
}

function hideTip() 
{
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.timerId = setTimeout("Tooltip.hide()", 300);
}

Tooltip.tipOutCheck = function(e) 
{
  e = dw_event.DOMit(e);
  // is element moused into contained by tooltip?
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if ( this != toEl && !contained(toEl, this) ) Tooltip.hide();
}

function hideTipImmediate() 
{
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.timerId = setTimeout("Tooltip.hide()", 0);
}

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) 
{
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}
Tooltip.clearTimer = function() 
{
  if (Tooltip.timerId) { clearTimeout(Tooltip.timerId); Tooltip.timerId = 0; }
}

Tooltip.unHookHover = function () 
{
    var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
    if (tip) 
    {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;
    }
}
dw_event.add(window, "unload", Tooltip.unHookHover, true);
/***********************************Adds By Uzma For ToolTip*******************************************/

/**********Added by sudhir for the Setfocus functionality**********/
function setFocusOnFirstElement()
{	
	var i,j;
	if( document.forms[0].elements.length != null)  // Counts all elements on form[0]
	{
       for(i=0; i < document.forms[0].elements.length; i++) // Each element is taken in for loop 
	    {
            // The focus should be set on control, present NEXT to the HiddenForSetFocus hidden
            // -input control, OR the control present next to the disabled or hidden.
            if(document.forms[0].elements[i].id == "HiddenForSetFocus" || j == i) 
		    { 
                //alert(document.forms[0].elements[i + 1].type);
                if( document.forms[0].elements[i + 1] != null && 
                    document.forms[0].elements[i + 1] != "undefined" ) 
			    {
			         if(document.forms[0].elements[i + 1].disabled || document.forms[0].elements[i + 1].type == "hidden")    
                    {
                        // If control is disabled or control type is hidden, then the focus should be
                        // set on the next control
                        j = i + 1;
                    } 
                    else if( ( (document.forms[0].elements[i + 1].type == "text") 
                       || (document.forms[0].elements[i + 1].type == "checkbox") 
                       || (document.forms[0].elements[i + 1].type == "radio") 
                       || (document.forms[0].elements[i + 1].type == "textarea" )
                       || (document.forms[0].elements[i + 1].type.substring(0, 6)  == "select") ) 
                       && (!document.forms[0].elements[i + 1].disabled) ) 
                    {
                         document.forms[0].elements[i + 1].focus();
                         break;			                     
                    }
                    else
                    {
                      // do nothing
                      // Continue looping
                    }
                   
                }
		    }
	    }
	}
}
 
function CheckAll(checkAllBox,CheckBoxID )							
{															
	var frm = document.aspnetForm;								
	var ChkState=checkAllBox.checked;						
	for(i=0;i< frm.length;i++)								
	{														
		e=frm.elements[i];									
        if(e.type=='checkbox' && e.name.indexOf(CheckBoxID) != -1)
            e.checked= ChkState ;							
	}														
}


/*Added for stock watch popup*/

    var arrcounter = 0;
    var PopupCont = 0;
    var arrCodeQty = new Array(50);
    var strAddToCartQuery='';
    var IsBackOrderEnabled  ;
    var isStockWatchListEnabled ;
    var IsOutofStockchkEnabled ;
    var BaseURL ; 
    var RedirecttoShopCart;
    var DisplayInventory;
    var UserSessionValue;
    
    //set the stock watch config values
    function SetConfigValues (tempIsBackOrderEnabled,tempisStockWatchListEnabled,tempIsOutofStockchkEnabled, tempBaseURL,tempRedirecttoShopcart)
    {
        IsBackOrderEnabled =  tempIsBackOrderEnabled  ;
        isStockWatchListEnabled =tempisStockWatchListEnabled ;
        IsOutofStockchkEnabled = tempIsOutofStockchkEnabled ;
        BaseURL = tempBaseURL;
        RedirecttoShopcart = tempRedirecttoShopcart;
    }
    
    //set the stock watch config values
    function SetConfigurationValues (tempIsBackOrderEnabled,tempisStockWatchListEnabled,tempIsOutofStockchkEnabled, tempBaseURL,tempRedirecttoShopcart, tempDisplayInventory)
    {
        IsBackOrderEnabled =  tempIsBackOrderEnabled  ;
        isStockWatchListEnabled =tempisStockWatchListEnabled ;
        IsOutofStockchkEnabled = tempIsOutofStockchkEnabled ;
        BaseURL = tempBaseURL;
        RedirecttoShopcart = tempRedirecttoShopcart;
        DisplayInventory = tempDisplayInventory;
    }
    
    //Set the User Session here
    function SetUserSession(_UserSessionValue)
    {
        UserSessionValue = _UserSessionValue;        
        //alert(UserSessionValue);
    }
    
    //Depending upon the stock quantity & entered quantity call the specifc method
    function Additem()
    {
        if ( PopupCont < arrcounter )
        {
            var temparrCartItem = arrCodeQty[PopupCont].split("`");
            if(DisplayInventory == "True")
            {
                if(IsBackOrderEnabled == "0")
                {
                    if ( parseInt(temparrCartItem[1]) < parseInt(temparrCartItem[2]))
                    {
                        straddtocart = temparrCartItem[0] + '_' + temparrCartItem[1];
                        AddItemToCart(straddtocart);
                    }
                    else
                    {
                        straddtocart = temparrCartItem[0] + '_' + temparrCartItem[2];
                        AddItemToCart(straddtocart);
                    }
                }
                else
                {
                    straddtocart = temparrCartItem[0] + '_' + temparrCartItem[2];
                    AddItemToCart(straddtocart);
                }
            }
            else
            {
                straddtocart = temparrCartItem[0] + '_' + temparrCartItem[2];
                AddItemToCart(straddtocart);
            }
        }
        else
        {
            if (strAddToCartQuery != '' || strAddToCartQuery.length != 0)
                AddItemToCart('Redirect');
        }
    }
  
    //show the stock watch pop up message in DIV
    function ShowPopUp(strvalue)
    {
        var strPopUpHTML = '<div class="pop_sku_outer"> <div class="pop_sku_inner" id="PopupContentDiv">'+ GetContenHTML(strvalue)  +  '</div></div>'
        var divH=document.getElementById('popupHead');
        if(!divH)
        {
       
            var dialogTop =  document.documentElement.clientHeight;
            var dialogLeft = document.documentElement.clientWidth;
            
            var Left = parseInt((150)/2) + document.documentElement.scrollLeft;
            var Top = parseInt((300)/2) + document.documentElement.scrollTop;
              
            var divH=document.createElement('div');
            divH.setAttribute('id','popupHead');
            divH.className='popupdivContainer';
            var el = document.createElement('span');
            el.innerHTML = strPopUpHTML;
            divH.appendChild(el);
            divH.style.top= Top+'px';
            //divH.style.left=Left+'px';
            //divH.style.height= ( dialogTop-50)+'px';
            //divH.style.width=(dialogLeft-18)+'px';
            document.getElementsByTagName('body')[0].appendChild(divH);  
        }
        return false;
    }
    
    function GetContenHTML(strvalue)
    {
    var arrCartItem = strvalue.split("`");
    var Code = arrCartItem[0];
    var SKUCode = arrCartItem[1];
    var StockQty =arrCartItem[2]; 
    var Qty = arrCartItem[3];
    var cntHTML = '<div><div class="popup_cancel" ><input id="btnCancel" class="float_right"  type="button" value="X"  onclick="javascript:closePopUp();"/></div><div class="pop_innertext">';
   
        if(eval(Qty) > eval(StockQty))
        {   
            if(IsBackOrderEnabled =="1")
            {
                if(isStockWatchListEnabled=="1" && IsOutofStockchkEnabled =="1")
                { 
                    if(eval(StockQty)<1)
                    {
                        cntHTML = cntHTML + "<strong>Available quantity for the item " + SKUCode + " is '0'.</strong><br/><p><strong>You can either continue to add this item to your cart or <br/> you can track the item on your stock watch list and be notified when it is in stock. </strong></p><p><br/></p>";
                        cntHTML = cntHTML + '<table cellpadding="2" cellspacing="2" align="center" ><tr><td><input id="btnAddtoCart" type="button" class="add2cart_m" onclick="javascript:AddItemToCart(\''+ Code + "_" + Qty + '\');"/></td></tr><tr>'
                        cntHTML = cntHTML + '<td><input id="btnAddtoSW" type="button"  class="add2stockwatchlist_intab" onclick="javascript:AddItemtoStockWatchList(\'' + SKUCode + '\',\'' + Qty + '\');"/></td></tr></table>'
                      
                    }
                    else if(parseInt(Qty) > parseInt(StockQty))
                    {
                        var RemainQty = parseInt(Qty)- parseInt(StockQty);
                        cntHTML = cntHTML + "<p><strong>Available quantity for the item " + SKUCode  + " is " + StockQty + ", remaining quantity '" + RemainQty + "' will be added to your stock watch list.</br></strong></p><p><br/></p>";
                        cntHTML = cntHTML + '<table cellpadding="2" cellspacing="2"  align="center"><tr><td><input id="btnAddtoCart" type="button" class="add2entireqtycart_intab"  onclick="javascript:AddItemToCart(\''+ Code + "_" + Qty + '\');"/></td></tr><tr>'
                        cntHTML = cntHTML + '<td><input id="btnAddtoSW" type="button" class="add2onlyavailableqtycart_intab"  onclick="javascript:AddToCartwithStockWatch(\'' + Code + '\',\'' + StockQty + '\',\'' + RemainQty + '\',\'' + SKUCode + '\');"/></td></tr></table>'
                    }
                    else
                    {
                        cntHTML = cntHTML +Code+"_"+Qty;
                    }
                } 
                else
                {
                    cntHTML = cntHTML +Code+"_"+Qty;
                }   
            }
            else if(IsBackOrderEnabled =="0")
            {
                if(isStockWatchListEnabled=="1" && IsOutofStockchkEnabled =="1")
                { 
                    if(eval(StockQty)<1)
                    {
                        cntHTML = cntHTML + "<p><strong>Item " + SKUCode  + " added is currently not available, however you can track the item on your stock watch list and be notified when it is in stock. </br></strong></p>";
                        cntHTML = cntHTML + '<table cellpadding="2" cellspacing="2"  align="center"><tr><td><input id="btnAddtoCart" type="button" class="cancel"   onclick="javascript:Cancel()"/></td></tr><tr>'
                        cntHTML = cntHTML + '<td><input id="btnAddtoSW" type="button" class="add2stockwatchlist_intab"   onclick="javascript:AddItemtoStockWatchList(\'' + SKUCode + '\',\'' + Qty + '\');"/></td></tr></table>'
                    }
                    else if(eval(Qty) > eval(StockQty))
                    {
                        var RemainQty = parseInt(Qty)- parseInt(StockQty);
                        cntHTML = cntHTML + "<p><strong>Available quantity for the item " + SKUCode + " is '" + StockQty + "', remaining quantity '" + RemainQty + "' will be added to your stock watch list. </br></p>";
                        cntHTML = cntHTML +  '<table cellpadding="2" cellspacing="2"  align="center"><tr><td><input id="btnAddtoCart" class="cancel" type="button"  onclick="javascript:Cancel()" width="87" height="20"/></td></tr><tr>'
                        cntHTML = cntHTML + '<td><input id="btnAddtoSW"  class="add2onlyavailableqtycart_intab" type="button"  onclick="javascript:AddToCartwithStockWatch(\'' + Code + '\',\'' + StockQty + '\',\'' + RemainQty + '\',\'' + SKUCode + '\');"/></td></tr></table>'
                    }                 
                }
                else
                {
                    alert("Item Added is back ordered, Available quantity for item "+SKUCode+" is "+ StockQty+"");
                    return false;
                } 
            } 
         }      
        else
        {
            cntHTML = cntHTML +Code+"_"+Qty;
        }
        cntHTML = cntHTML + '</div></div>'
        return cntHTML;
    }
    
    function AddItemToCart(strvalue)
    { 
        if (strvalue == 'Redirect')
        {
            if (RedirecttoShopcart == 0)
            {                
                setTimeout("ShowProcessing('Adding to your cart, please wait...')",1000);
                var url = BaseURL+"Basket/Purchase.aspx?skus="+strAddToCartQuery+"&closewin=0";
                postRequest(url);
                setTimeout("window.scrollTo(0,0)",1000);                                          
                if(UserSessionValue == "True")
                {
                   if(panel != null)
                    {
                        setTimeout("getCartItems()",1000);
                        setTimeout("panel.show()",1000);
                    }
                    setTimeout("StopProcessing()",1000);
                }
                else
                {
                    var returnurl = document.getElementById("hdnGetRedirectURL").value;
                    returnurl = returnurl.replace("~","../");
                    window.location.href = returnurl;
                }
                
                strAddToCartQuery="";
            }
            else
            {           
                
                setTimeout("window.opener.ShowProcessing('Adding to your cart, please wait...')",1000);
                var url = BaseURL+"Basket/Purchase.aspx?skus="+strAddToCartQuery+"&closewin=0";
                window.opener.postRequest(url);
                setTimeout("window.opener.scrollTo(0,0)",1000);
               
                if(UserSessionValue =="True")
                {
                        if(window.opener.panel != null)
                        {
                            setTimeout("window.opener.getCartItems()",1000);
                            setTimeout("window.opener.panel.show()",1000);
                            if(document.getElementById("lblShowMessage")!=null)                               
                                setTimeout("document.getElementById('lblShowMessage').innerHTML ='Item added successfully.';",1000);
                            
                        }
                        setTimeout("window.opener.StopProcessing()",1000);
                }                                
                else
                {                        
                        var returnurl = document.getElementById("hdnGetRedirectURL").value;
                        returnurl = returnurl.replace("~","../");
                        window.opener.location.href = returnurl;
                }
                strAddToCartQuery="";
            }
            return true;
        }
        else
        {
            if (strAddToCartQuery == '')
                strAddToCartQuery =  strvalue ; 
            else
                strAddToCartQuery = strAddToCartQuery + ';'+ strvalue ; 
            
            PopupCont = PopupCont + 1;
            closePopUp();
            var t=setTimeout("Additem()",300)
        }
        return false;
    }

    //Add the specified quantity to stock watch
    function AddItemtoStockWatchList (strcode, strQty)
    {  
        returnVal = Ignify.eCommerce.Web.Store.MasterTemplates.Ignify.Modules.SharedModules.ProductSkusMultiModule.AddItemtoStockWatchList(strcode, strQty);
        PopupCont = PopupCont + 1;
        closePopUp();
        var t=setTimeout("Additem()",300)
        return false;
    }
    
    //Add the stock quantity to cart & remaining to stock watch
    function AddToCartwithStockWatch(str,qty,StockwatchQty,SkuCode)
    { 
        str=str+"_"+qty;
        returnVal = Ignify.eCommerce.Web.Store.MasterTemplates.Ignify.Modules.SharedModules.ProductSkusMultiModule.AddItemtoStockWatchList(SkuCode, StockwatchQty);
        if (strAddToCartQuery == '')
            strAddToCartQuery =  str ; 
        else
            strAddToCartQuery = strAddToCartQuery + ';'+ str ; 
    
       PopupCont = PopupCont + 1;
       closePopUp();
       var t=setTimeout("Additem()",300)
    }
    
    //close the pop up window
    function closePopUp()
    {
        var divH=document.getElementById('popupHead');
        if(!divH){return};
        divH.parentNode.removeChild(divH);
    }
    
    ///Dont do anything
    function Cancel()
    {
        PopupCont = PopupCont + 1;
        closePopUp();
        var t=setTimeout("Additem()",300)
    }
    
    ///Validate the SKU stock & show POP up message if required
    function ValidateSKUforStockWatchlist(Code,Qty,StockQty,IsBackOrderEnabled,isStockWatchListEnabled,IsOutofStockchkEnabled,baseurl,SKUCode) 
    {
        if(eval(Qty) > eval(StockQty))
        {    
            if(IsBackOrderEnabled =="1")
            {
                if(isStockWatchListEnabled=="1" && IsOutofStockchkEnabled =="1")
                { 
                    if(eval(StockQty)<1)
                    {
                        var win = window.open("../catalog/PopupMessage.aspx?Code= " + Code + "&Qty="+ Qty +"&StockQty="+ StockQty +"&SKUCode="+SKUCode+"&Backorder=FB&BO=True" , "StockWatch", "height=250,width=800,scrollbars=no,screenX=250,screenY=250,left=250,top=250");
                        win.focus();
                    }
                    else if(eval(Qty) > eval(StockQty))
                    {
                        var win = window.open("../catalog/PopupMessage.aspx?Code= " + Code + "&Qty="+ Qty +"&StockQty="+ StockQty +"&SKUCode="+SKUCode+"&&Backorder=PB&BO=True" , "StockWatch", "height=250,width=800,scrollbars=no,screenX=250,screenY=250,left=250,top=250");
                        win.focus();                      
                    }
                    else
                    {    //alert(3);                
                        str=Code+"_"+Qty;
                        //document.location.href=baseurl+"Basket/Purchase.aspx?skus="+str;
                        //window.opener.location.href=baseurl+"Checkout/Shoppingcart.aspx";
                        setTimeout("ShowProcessing('Adding to your cart, please wait...')",1000);
                        var url = baseurl+"Basket/Purchase.aspx?skus="+str;
                        postRequest(url);
                        setTimeout("window.scrollTo(0,0)",1000);
                        if(panel != null)
                        {
                           setTimeout("getCartItems()",1000);
                           setTimeout("panel.show()",1000);
                        }
                        setTimeout("StopProcessing()",1000);
                        
                    }
                } 
                else
                {  
                //alert(4);             
                    str=Code+"_"+Qty;
                    setTimeout("ShowProcessing('Adding to your cart, please wait...')",1000);
                    //document.location.href=baseurl+"Basket/Purchase.aspx?skus="+str;
                    //window.opener.location.href=baseurl+"Checkout/Shoppingcart.aspx";
                    var url = baseurl+"Basket/Purchase.aspx?skus="+str;
                    postRequest(url);
                    setTimeout("window.scrollTo(0,0)",1000);
                    if(panel != null)
                    {
                       setTimeout("getCartItems()",1000);
                       setTimeout("panel.show()",1000); 
                    }
                    setTimeout("StopProcessing()",1000); 
                                 
                }   
            }
            else if(IsBackOrderEnabled =="0")
            {
                if(isStockWatchListEnabled=="1" && IsOutofStockchkEnabled =="1")
                { 
                    if(eval(StockQty)<1)
                    {
                        var win = window.open("../catalog/PopupMessage.aspx?Code= " + Code + "&Qty="+ Qty +"&StockQty="+ StockQty +"&SKUCode="+SKUCode+"&&Backorder=FB&BO=False" , "StockWatch", "height=250,width=800,scrollbars=no,screenX=250,screenY=250,left=250,top=10");
                        win.focus();
                    }
                    else if(eval(Qty) > eval(StockQty))
                    {
                        var win = window.open("../catalog/PopupMessage.aspx?Code= " + Code + "&Qty="+ Qty +"&StockQty="+ StockQty +"&SKUCode="+SKUCode+"&&Backorder=PB&BO=False" , "StockWatch", "height=250,width=800,scrollbars=no,screenX=250,screenY=250,left=250,top=10");
                        win.focus();                      
                    }                   
                }
                else
                {
                    alert("Item Added is back ordered, Available quantity for item "+SKUCode+" is "+ StockQty+"");
                    return false;
                } 
            }
        }      
        else
        {  
        //alert(5);      
            str=Code+"_"+Qty;
            //document.location.href=baseurl+"Basket/Purchase.aspx?skus="+str;
            setTimeout("ShowProcessing('Adding to your cart, please wait...')",1000);
            var url = baseurl+"Basket/Purchase.aspx?skus="+str;
            postRequest(url);
            setTimeout("window.scrollTo(0,0)",1000);            
            if(panel != null)
            {
               setTimeout("getCartItems()",1000);
               setTimeout("panel.show()",1000);
            }
            setTimeout("StopProcessing()",1000);
                        
        }
        return false;
    }
