﻿// 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_MSG)
    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_DATE_MONTH_YEAR_FORMAT_MSG)
    else
    returnval=true
    }
    if (returnval==false) input.select()
    return returnval
}

// JScript File

    function Print()
    {
        alert(OPERATION_COMPLETED_MSG);
    }
    
   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");
               if (document.forms[0].elements[i].checked == true)
               {
              
                   CheckAll();
               }
               else
               {
              
                   UnCheckAll();
               }

            }
        }
    }
  function CheckAll()
    {
       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") 
            {
                document.forms[0].elements[i].checked = true ;   
            }
        }
    }
    function UnCheckAll()
    {
        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") 
            {
                document.forms[0].elements[i].checked = false;    
            }
        }
    }

    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(SELECT_ITEM_MSG);
            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) ) 
                    {
                        if ((document.forms[0].elements[i + 1].className ==" gsc-input") && (document.forms[0].elements[i + 1].name =="search"))//For SiteSearch Page    
                            {
                                //do nothing
                            }
                           else
                           {                            
                                if(document.forms[0].elements[i + 1].id != "fullname22")
                                {
                                    try
                                    {
                                        document.forms[0].elements[i + 1].focus();
                                        break;
                                    }
                                    catch(er)
                                    {
                                        //do nothing
                                    }
                                }
                           }			                     
                    }
                    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("`");
            //keep the original call as it is if we are not passing any value
            if(temparrCartItem.length == "6")
            {
                if(DisplayInventory == "True")
                {
                    if(IsBackOrderEnabled == "0")
                    {
                        if ( parseInt(temparrCartItem[1]) < parseInt(temparrCartItem[2]))
                        {
                            straddtocart = temparrCartItem[0] + '_' + temparrCartItem[1] + '_' + temparrCartItem[3] + '_' + temparrCartItem[4] + '_' + temparrCartItem[5];
                            AddItemToCart(straddtocart);
                        }
                        else
                        {
                            straddtocart = temparrCartItem[0] + '_' + temparrCartItem[2]+ '_' + temparrCartItem[3] + '_' + temparrCartItem[4] + '_' + temparrCartItem[5];
                            AddItemToCart(straddtocart);
                        }
                    }
                    else
                    {
                        straddtocart = temparrCartItem[0] + '_' + temparrCartItem[2] + '_' + temparrCartItem[3] + '_' + temparrCartItem[4] + '_' + temparrCartItem[5];
                        AddItemToCart(straddtocart);
                    }
                }
                else
                {
                    straddtocart = temparrCartItem[0] + '_' + temparrCartItem[2] + '_' + temparrCartItem[3] + '_' + temparrCartItem[4] + '_' + temparrCartItem[5];
                    AddItemToCart(straddtocart);
                }
            }
            else
            {
                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
                {
                    //"Item Added is back ordered, Available quantity for item "+SKUCode+" is "+ StockQty
                    var str1=BACK_ORDER_MSG;
                    str1=str1.replace('{0}',SKUCode);
                    str1=str1.replace('{1}',StockQty);
                    alert(str1);
                    return false;
                } 
            } 
         }      
        else
        {
            cntHTML = cntHTML +Code+"_"+Qty;
        }
        cntHTML = cntHTML + '</div></div>'
        return cntHTML;
    }
    
    function AddItemToCart(strvalue)
    { 
        
        if (strvalue == 'Redirect')
        {
            
            if (RedirecttoShopcart == 0)
            {
                //var url = BaseURL+"Basket/Purchase.aspx?skus="+strAddToCartQuery+"&closewin=0";
                Ignify.eCommerce.Web.Store.MasterTemplates.Ignify.Modules.LicenseAgreementModule.BindCartData(strAddToCartQuery, '', '', '', '', '', '','',false,location.href,function(result) {OpenFloatingCartWithItem(result,1)});
                strAddToCartQuery="";
            }
            else
            {           
                //setTimeout("window.opener.ShowProcessing('Adding to your cart, please wait...')",1000);
                //window.opener.postRequest(url);                
                Ignify.eCommerce.Web.Store.MasterTemplates.Ignify.Modules.LicenseAgreementModule.BindCartData(strAddToCartQuery, '', '', '', '', '', '','',false,parent.location.href,function(result) {OpenFloatingCartWithItem(result,2)});
                strAddToCartQuery="";
            }
            return true;
        }
        else
        {
            if (strAddToCartQuery == '')
                strAddToCartQuery =  strvalue ; 
            else
                strAddToCartQuery = strAddToCartQuery + ';'+ strvalue ; 
            
            PopupCont = PopupCont + 1;
            closePopUp();
            var t=setTimeout("Additem()",300)
        }
        return false;
    }
    
    function OpenFloatingCartWithItem(sResult,param)
    {
        
        if(param == "1")
        {
            if(sResult.value[0] == "SUCCESS")
            {   
                if(Minitemplate==true)
                {         
                    setTimeout("parent.ShowProcessing(ADDING_TO_CART_MSG)",100);
                    setTimeout("parent.getCartItems()",100);
                }
                else
                {
                    setTimeout("ShowProcessing(ADDING_TO_CART_MSG)",100);
                    setTimeout("getCartItems()",1000);
                }
                ClearAllMessages();
                //if(document.getElementById("lblShowMessage")!=null)                               
                        //setTimeout("document.getElementById('lblShowMessage').innerHTML ='Item(s) added successfully.';",100);
                document.location.href = sResult.value[4] ; //Added to redirect to Shoppingcart.
                if(Minitemplate==true)
                {    
                    if(parent.IsFloatingCartEnabled=="True")
                    {
                        parent.CloseFloatingCart();
                        setTimeout("window.parent.scrollTo(0, 0);",100);
                        setTimeout("parent.OpenFloatingCart();",500);
                    }   
                    setTimeout("parent.StopProcessing()",100);                    
                }
                else
                {
       
                }         
            }
            else if(sResult.value[0] == "REDIRECTLOGIN")
            {
                window.open(sResult.value[1],"_top");
            }
            else
            {
                if(Minitemplate==true)
                {
                    setTimeout("parent.StopProcessing()",100);  
                }
                else
                {
                    setTimeout("StopProcessing()",100); 
                }
                setTimeout("document.getElementById('lblShowMessage').innerHTML ='"+ sResult.value[0] +"');",100);
            }
        }
        if(param =="2")
        {
            if(sResult.value[0] == "SUCCESS")
            {
                setTimeout("parent.ShowProcessing('Adding to your cart, please wait...')",100);
                if(window.parent.IsFloatingCartEnabled=="True")
                {
                    window.parent.CloseFloatingCart();
                    setTimeout("window.parent.scrollTo(0, 0);",100);
                    setTimeout("window.parent.OpenFloatingCart();",500);
                }
                setTimeout("window.parent.getCartItems()",1000);                            
                if(document.getElementById("lblShowMessage")!=null)                               
                setTimeout("document.getElementById('lblShowMessage').innerHTML ='Item added successfully.';",100);
                
                setTimeout("window.parent.StopProcessing()",100);                                               
   
            }
            else if(sResult.value[0] == "REDIRECTLOGIN")
            {
                window.parent.location.href = sResult.value[1];
            }                                
            else
            {                        
                    var returnurl = window.parent.document.getElementById("hdnGetRedirectURL").value;
                    returnurl = returnurl.replace("~","../");
                    window.parent.location.href = returnurl;
            }
        }
    }

    //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_CART_MSG)",1000);
                        var url = baseurl+"Basket/Purchase.aspx?skus="+str;
                        postRequest(url);
                        //alert("2");
                            setTimeout("getCartItems()",1000);                           
                        
                        setTimeout("StopProcessing()",1000);                        
                        /*
                        if(panel != null)
                            setTimeout("panel.show()",1000);
                        
                        setTimeout("PanelVisibility(false);",2250); */
                    }
                } 
                else
                {  
                //alert(4);             
                    str=Code+"_"+Qty;
                    setTimeout("ShowProcessing(ADDING_TO_CART_MSG)",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);
                    alert("3");
                        setTimeout("getCartItems()",1000);                      
                    
                    setTimeout("StopProcessing()",1000);                                         
                    /*
                    if(panel != null)
                         setTimeout("panel.show()",1000); 
                    
                    setTimeout("PanelVisibility(false);",2250);   */      
                }   
            }
            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_CART_MSG)",1000);
            var url = baseurl+"Basket/Purchase.aspx?skus="+str;
            postRequest(url);
            //alert("4");
            /*
           
                setTimeout("getCartItems()",1000);
               
            setTimeout("StopProcessing()",1000);            
            /*
            if(panel != null)
                setTimeout("panel.show()",1000);
            
            setTimeout("PanelVisibility(false);",2250); */
                        
        }
        return false;
    }
function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
}
function LoadUrl(Url)
{
    parent.document.location.href=Url;
}
/*Floating cart + Mini Cart Javascript merges here so there is no extra file called FloatingCart.js*/
var SubTotal="0";
var ToTalRowCount = 0;
var NoOfItems = null;
var cartItemsAndSubTotal=null;
var formatcurrency=null;


 function getCartItems()
 {
    try
    {
       Ignify.eCommerce.Web.Store.CommonObjects.ClientCart.GetCartItems(function(result){getResult(result.value);}); 
    }
   catch(ex)
   {
    var exception = ex.description;
    
   }               
       return false;       
 }
 
 function RemoveAll()
 {
    try
    {
       //Ignify.eCommerce.Web.Store.MasterTemplates.Ignify.Modules.SharedModules.FloatingCart.GetCartItems(function(result){AssignData(result);}); 
       if(confirm(DELETE_ALL_ITEMS_CONFIRMATION_MSG))
       {
       serverRequest('removeall');      
       HighSlideClose();
       }
    }
   catch(ex)
   {
    var exception = ex.description;
    
   }               
       return false;       
 }
 
 function getCartItemsServer(cartItemsAndSubTotal1)
 {
    try
    { 
    
    var cartitems =null;
    var mycartarray =null;       
    cartItemsAndSubTotal1 = cartItemsAndSubTotal1.replace(/putq/g,"\"");
    var splitRawData = cartItemsAndSubTotal1.split("~~SubTotal~~");
    if(splitRawData!=null && splitRawData.length>0)
    {
       NoOfItems =  splitRawData[1];
       SubTotal =   splitRawData[2];
       formatcurrency = splitRawData[3];
    }
     GetSubTotal();   
    }
       catch(ex)
       {
        var exception = ex.description;
        //alert(exception);
       }
               
       return false;
 }
//Sub Total Calculation here
//Get the Shopping cart sub total
function GetSubTotal()
{
    var objTd = document.getElementById("lblSubTotal");
    var objSubTotal = "";
    if(objTd!=null)
    {    
       var objLblItemCount = document.getElementById("lblItemCount");
             if(objLblItemCount!=null)
                objLblItemCount.innerHTML = NoOfItems +  " " + FLOATCART_ITEMCOUNT;
      var tempformatcurrency = "0";
            try
            {
                if(parseFloat(SubTotal) < 0)
                    SubTotal = "0";
                if(formatcurrency!=null)
                    tempformatcurrency = formatcurrency;
            }
            catch(Ex)
            {
                  if(document.getElementById("hdnTempCurrencyCode")!=null)
                  {
                     var currencycode = document.getElementById("hdnTempCurrencyCode").value;
                        if(currencycode =="USD" && SubTotal == "0")
                            tempformatcurrency = "$0.00";
                  }
            }
      var objItemSubTotal = document.getElementById("lblItemSubTotal");
      if(objItemSubTotal!=null)
        objItemSubTotal.innerHTML = tempformatcurrency;
        if(SubTotal == "0" && NoOfItems == null)
        {
            objTd.style.visibility="hidden";
        }
         else
         {
            objTd.style.visibility="";
         }  
    }   
    setTimeout("WipeMessage('lblShowProcess');",1);  
}
function RemoveAllCartItems()
{
    var response = Ignify.eCommerce.Web.Store.MasterTemplates.Ignify.Modules.SharedModules.FloatingCart.RemoveAllCartItems();
            try
            {
                getCartItems();
            }
            catch(ex)
            {var exception = ex.description;}
            GetSubTotal();
    
    return false;
}
function callServer(arguments)
{
    setTimeout("SetMessage(PROCESS_MSG_FLOATING_CART,'lblShowProcess');",1);
    setTimeout('serverRequest("'+arguments+'" ,"server context");',1);    
    //serverRequest(arguments);
}
function getResult(result, context){
WipeMessage("lblMessage"); 
getCartItemsServer(result); 
}

/*Moving common JS functions to common.js instead of writing it on all controls */
function Loadwindow(ProductCode)
    {
     //var win = window.open("../Profile/SendToFriend.aspx?Id="+ProductCode, "SendToFriend", "width= 900, height=800");
      var win = window.open("../Profile/SendToFriend.aspx?Id="+ProductCode , "SendToFriend", "location=no,resizable=yes,top=20,left=70,height=700,width=860,status=no,toolbar=no,scrollbars=yes");
	 win.focus();
    }
function isNumber(ThisObject)
{
	if(ThisObject.length== 0)
		return false;

	for(var i=0; i< ThisObject.length; i++) 
		if ("0123456789".indexOf(ThisObject.charAt(i))== -1) 
			return false; 

	return true; 
} 
		

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
// Added by Sudhir on 20072307 to solve the problem of overlapping tooltip.
var divTag = document.getElementById("price");
var iFrameTag = document.getElementById("selectblocker");
var tableTag = document.getElementById("prodPrices");
<!--var AnchorPos = getAnchorPosition("name")-->
var ddbx = document.getElementById("ddlShippingAddresses");
 // var tmp = document.getElementById("ddlShippingAddresses").style.zIndex
 //alert((document.getElementById("ddlShippingAddresses").style.zIndex).value);
 //ddbx.style.zIndex = iFrameTag.style.zIndex-2; 

iFrameTag.style.zIndex = divTag.style.zIndex-1;
tableTag.style.zIndex = divTag.style.zIndex;
// Added by Sudhir on 20072307 ends here

  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

 function LoadwindowDiscountPopUp(ProductCode)
{
   var win = window.open("../catalog/DiscountDescription.aspx?Id="+ ProductCode , "VarAddtoCart", "height=500,width=500,scrollbars=yes,screenX=250,screenY=250,left=250,top=250");
 win.focus();
}
function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
}

function alternate(table) {
	// Take object table and get all it's tbodies.
	var tableBodies = table.getElementsByTagName("tbody");
	// Loop through these tbodies
	for (var i = 0; i < tableBodies.length; i++) {
		// Take the tbody, and get all it's rows
		var tableRows = tableBodies[i].getElementsByTagName("tr");
		// Loop through these rows
		for (var j = 0; j < tableRows.length; j++) {
			// Check if j is even, and apply classes for both possible results
			if ( (j % 2) == 0  ) {
				if (tableRows[j].className == 'odd' || !(tableRows[j].className.indexOf('odd') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'odd', 'even');
				} else {
					tableRows[j].className += " even";
				}
			} else {
				if (tableRows[j].className == 'even' || !(tableRows[j].className.indexOf('even') == -1) ) {
					tableRows[j].className = replace(tableRows[j].className, 'even', 'odd');
				}
				tableRows[j].className += " odd";
			} 
		}
	}
}

/* Get Discount for the selected SKU of the Product */
function getDiscounts(SubFrequencyID, LabelDiscount, RowID)
{    
    if(SubFrequencyID != null && SubFrequencyID!=0)
    {
      var id = SubFrequencyID;      
      var result = Ignify.eCommerce.Web.Store.MasterTemplates.Subscription.GetDiscountbySubFreqId(SubFrequencyID);      
      document.getElementById(RowID).style.visibility = 'visible';
      document.getElementById(LabelDiscount).innerHTML = result.value;      
    }
    else
    {
      document.getElementById(RowID).style.visibility = 'hidden';  
    }
}
 function trimspace(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
    }
//Clear all message
function ClearAllMessages()
{
    //alert(document.getElementById(objlblAddToCartMsg).id);
    if(document.forms[0].elements.length != null)
	 {
        for(i=0; i < document.forms[0].elements.length; i++)
        {
            strElement = document.forms[0].elements[i].id;
            if(strElement.substring(strElement.length-6, strElement.length) == 'txtQty')
            {
                var crtl = document.getElementById(strElement.substring(0,strElement.length-6)+'lblAddToCartMsg');
                crtl.innerHTML = "";
            }
        }
    }
}

//Get Accessories if exists
function GetAccessories()
{
    var straccessorieslist="";
    //Accessories List Updating here
    var arrayLength = 0;
   
    if(typeof(ecf_PurchaseModule_CheckboxesArray) != "undefined")
    {
        
        for(var index = 0; index < ecf_PurchaseModule_CheckboxesArray.length; index++)
        {
            var checked = document.getElementById(ecf_PurchaseModule_CheckboxesArray[index]);      
            if(checked !=null && checked.checked)
                arrayLength++;
        }

        var items = new Array(arrayLength);
        for(var index = 0; index<ecf_PurchaseModule_CheckboxesArray.length; index++)
        {
            var checked = document.getElementById(ecf_PurchaseModule_CheckboxesArray[index]);
            var id = document.getElementById(ecf_PurchaseModule_CheckboxesArray[index]).getAttribute('accessoryid');
            
            if(checked.checked)
            {
                if(straccessorieslist==null || straccessorieslist =="")   
                    straccessorieslist = id;
                 else
                    straccessorieslist = straccessorieslist + "~" + id;
            }
        }
    }
    
    return straccessorieslist;
}

//Being used on purchase module & components module
function GetSkuId()
{
    if(typeof(m_ecf_PurchaseModule_ItemCodehdnControlId) != "undefined")
    {
        return document.getElementById(m_ecf_PurchaseModule_ItemCodehdnControlId).value;
    }
    else if(typeof(m_ecf_ComponentsModule_ItemIDhdnControlId) != "undefined")
    {
        return document.getElementById(m_ecf_ComponentsModule_ItemIDhdnControlId).value;
    }
    else
        return "";
}

//Get selected Components details
function GetConfigurationDetails()
{
    if(typeof(m_ecf_ComponentsModule_ComponentsValue) != "undefined")
    {
        return document.getElementById(m_ecf_ComponentsModule_ComponentsValue).value;
    }
    else
        return "";
}

//Get selected Components Price
function GetConfigurationPrice()
{
    if(typeof(m_ecf_ComponentsModule_RetailPriceControlId) != "undefined")
    {
        return document.getElementById(m_ecf_ComponentsModule_RetailPriceControlId).value;
    }
    else
        return "";
}
// Get selected frequency
function GetShipmentFreq()
{
    var tempshipfreq = "";
    if(typeof(m_ecf_PurchaseModule_shipmentFreq) != "undefined")
    {   
        if(document.getElementById(m_ecf_PurchaseModule_shipmentFreq) !=  null )
        {
            tempshipfreq = document.getElementById(m_ecf_PurchaseModule_shipmentFreq).value;
        }
    }
    return tempshipfreq;
}
// Get selected Count
function GetShipmentCount()
{
    var tempshipcnt = "";
    if(typeof(m_ecf_PurchaseModule_txtShipmentCount) != "undefined")
    {
        if(document.getElementById(m_ecf_PurchaseModule_txtShipmentCount) != null)
        {
            tempshipcnt =  document.getElementById(m_ecf_PurchaseModule_txtShipmentCount).value;
        }
    }
    return tempshipcnt; 
}
function trim(inputString) 
{
    // Removes leading and trailing spaces from the passed string. Also removes
    // consecutive spaces and replaces it with one space. If something besides
    // a string is passed in (null, custom object, etc.) then return the input.
    if (typeof inputString != "string") 
    { 
        return inputString; 
    }
   
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    
    while (ch == " ") 
    { // Check for spaces at the beginning of the string
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
   
    ch = retValue.substring(retValue.length-1, retValue.length);
    
    while (ch == " ") 
    { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
    }
   
    while (retValue.indexOf("  ") != -1) 
    { // Note that there are two spaces in the string - look for multiple spaces within the string
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
    }
    return retValue; // Return the trimmed string back to the user
}

function SearchKeyword(txtSearchBox,selSearchFilter,options,searchUrl,searchCategory,AlertMsg)
{
    var SearchValue = txtSearchBox.value;
    SearchValue = FormatSearchValue(SearchValue);
    txtSearchBox.value = SearchValue;
    
    if(SearchValue !=null)
    {
        if((SearchValue == "") && (SearchValue.length == 0))
        {
            alert(AlertMsg);            
        }
        else
        {
            filterDescription = "";
            if (selSearchFilter != null && selSearchFilter.value != "1")
            {
                filterDescription = selSearchFilter.value;
            }
            searchFilder = "";
            option = "";
            if(selSearchFilter)
                searchFilder = selSearchFilter.value; 
            if(options)
                option = options.value;
            url = FormatURL(searchUrl,searchFilder ,SearchValue,'q',option,searchCategory,filterDescription)
            window.location.href = url;
        }
    }
}
function FormatURL(str)
{
    //arguments is an in-built JS variable which indicates all arguments (array list of arguments) in the function
    //So, str is a comma seperated array of arguments
    //Example: how to call this function: FormatURL('Hello {0} & {1} & {2} & {3}', 'John','Jane','Kristina','Alex'); 
    //Output will be: 'Hello John & Jane & Kristina & Alex'

  for(i = 1; i < arguments.length; i++)
  {
    str = str.replace('{' + (i-1) + '}', arguments[i]);
  }
  return str;
}
function FormatSearchValue(searchtext)
{
    //removing unneccessory chars from the keyword input
    searchtext = searchtext.replace(/[^-a-zA-Z0-9_,.\s;]/g, '');

    //replacing consicutive chars with single char in the keyword input
    searchtext = searchtext.replace(/[\-]+/g, "-");
    searchtext = searchtext.replace(/[\.]+/g, ".");
    searchtext = searchtext.replace(/[\,]+/g, ",");
    searchtext = searchtext.replace(/[\_]+/g, "_");
    searchtext = searchtext.replace(/[\;]+/g, ";");
	
    //trimming the keyword input
    searchtext = trim(searchtext);
    return searchtext;
}
function PopupReview(ProductID)
{
    var win = window.open("../Catalog/ProductReview.aspx?Id="+ProductID, "ProductReview", "height=390,width=503,scrollbars=yes");
    win.focus();
}
/* Append selected checkboxs id & assign it to hdnSelectedValue control. Also clear hdnSeeMore value. Being used for Narrow search*/
function GetSelectedItems(HdnSelectedValobj, hdnSeeMoreobj)
{
    var SelectedIds = "";
    if(document.forms[0].elements.length != null)
	{
        for(i=0; i < document.forms[0].elements.length; i++)
        {
           if(document.forms[0].elements[i].type == "checkbox")
           {
                if(document.forms[0].elements[i].checked == true)
                {
                    SelectedIds += document.forms[0].elements[i].id + "#";
                }
            }
        }
    }
    document.getElementById(HdnSelectedValobj).value = SelectedIds;
    document.getElementById(hdnSeeMoreobj).value = "";
    return true;
}
//This will search selecetd MetaFieldID
function SelectItems(HdnSelectedValobj, selectedId, hdnSeeMoreobj)
{
    document.getElementById(HdnSelectedValobj).value = selectedId + "#";
    document.getElementById(hdnSeeMoreobj).value = "";
    __doPostBack();
    return true;
}
//This will open Accordion depending upon MetaDictionaryID
function OpenSeeMore(hdnSeeMoreObj, MetaFieldId, HdnSelectedValobj)
{
    var SelectedIds = "";
    if(document.forms[0].elements.length != null)
	{
        for(i=0; i < document.forms[0].elements.length; i++)
        {
           if(document.forms[0].elements[i].type == "checkbox")
           {
                if(document.forms[0].elements[i].checked == true)
                {
                    SelectedIds += document.forms[0].elements[i].id + "#";
                }
            }
        }
    }
    var len = SelectedIds.length;
    if(len > 0)
    {
        document.getElementById(HdnSelectedValobj).value = SelectedIds;
    }

    len = document.getElementById(hdnSeeMoreObj).value.length;

    if(len = 0)
        document.getElementById(hdnSeeMoreObj).value = MetaFieldId;
    else
        document.getElementById(hdnSeeMoreObj).value = document.getElementById(hdnSeeMoreObj).value + "#" + MetaFieldId;

    __doPostBack();
    return true;
}
function Load(value,divvale)
{
    var var1 = document.getElementById(value);
    var1.style.overflow="auto";
    divvale.style.visibility="hidden";
}
function HideArrow()
{
if(document.getElementById("arrow")!=null)
    document.getElementById("arrow").style.visibility="hidden";
aSubmenuData="";
 return true;
}
function ValidateEmail(emailAdd)
{
    var emailad=emailAdd;
    var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;                                  
    var check=/@[\w\-]+\./;                                   
    var checkend=/\.[a-zA-Z]{2,3}$/;                                  

    if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1))
    {
	    return false;
    }
    else
    {
        return true;
    }
}
function parentExists()
{
 return (parent.location == window.location)? false : true;
}

