﻿// JScript File

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)
            currenturl = "http://" + document.domain + "/publicstore";
        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")
            {
               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("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
                    }
                   
                }
		    }
	    }
	}
}
 
/*****************************************************************/
/*Not required this script function

/**********Added by Gowri for the refresh the perticular page*********/
/*
function ObjRefresh(varObj)
{
/*Please added this script in Checkout.Master page if required
    ---  onclick="javascript:ObjRefresh('ObjRefresh');--  */
/*
var Obj=document.getElementById(varObj);
 
    if(Obj.Value=="LoginVerification")
        {
            window.location.href="../Profile/Login.aspx";
           
        }  
        
}
*/
/* For Displaying the Ongoing Processing while adding to cart*/

function ShowDiv(Flag)
 {
 if (Flag == 'true')
 {
   
    var str = "<table id='processingImg'   >  <tr><td  valign='middle' align='center' ><img src='../App_Themes/spectrumTheme/images/processing.gif'  alt='Processing' height='50px' /></td></tr><tr><td valign='middle' align='center' >Please Wait,<br /> We are Processing Your Request...</td></tr></table><table border='0' width='100%'>"
    var dialogTop =  document.documentElement.clientHeight;
    var dialogLeft = document.documentElement.clientWidth;
    
   
    dialogTop = parseInt((dialogTop-200)/2);
    dialogLeft = parseInt((dialogLeft )/2);
    var Left = dialogLeft + document.documentElement.scrollLeft;
    var Top = dialogTop + document.documentElement.scrollTop;
    
   
    var divH=document.getElementById('popupHead');
    
    if(!divH)
    {
        var divH=document.createElement('div');
        divH.setAttribute('id','popupHead');
        divH.className='PopUpforWait';
        //div.appendChild(document.('123 <br />'));
        var el = document.createElement('span');
        el.innerHTML =str;
        divH.appendChild(el);
        divH.style.top=Top + 'px';
        divH.style.left=Left +'px';
        divH.style.Height='100px';
        document.getElementsByTagName('body')[0].appendChild(divH);  
    }
 }else
 {
    var divH=document.getElementById('popupHead');
    if(!divH){return};
    divH.parentNode.removeChild(divH);    
 }
 return false;
}

/* For Displaying the Ongoing Processing while adding to cart on the Customer Specific Home Page*/

function ShowHomePageDiv(Flag)
 {
 if (Flag == 'true')
 {
   
    var str = "<table id='processingImg'   >  <tr><td  valign='middle' align='center' ><img src='../App_Themes/spectrumTheme/images/processing.gif'  alt='Processing' height='50px' /></td></tr><tr><td valign='middle' align='center' >Please Wait,<br /> We are Processing Your Request...</td></tr></table><table border='0' width='100%'>"
    var dialogTop =  document.documentElement.clientHeight;
    var dialogLeft = document.documentElement.clientWidth;
    
   
    dialogTop = parseInt((dialogTop-200)/2);
    dialogLeft = parseInt((dialogLeft )/2);
    var Left = dialogLeft + document.documentElement.scrollLeft;
    var Top = dialogTop + document.documentElement.scrollTop;
    
   
    var divH=document.getElementById('popupHead');
    
    if(!divH)
    {
        var divH=document.createElement('div');
        divH.setAttribute('id','popupHead');
        divH.className='PopUpforWait';
        //div.appendChild(document.('123 <br />'));
        var el = document.createElement('span');
        el.innerHTML =str;
        divH.appendChild(el);
        divH.style.top=Top + 'px';
        divH.style.left=Left +'px';
        divH.style.Height='100px';
        document.getElementsByTagName('body')[0].appendChild(divH);  
    }
 }else
 {
    var divH=document.getElementById('popupHead');
    if(!divH){return};
    divH.parentNode.removeChild(divH);    
 }
 return false;
}
