/*****************************************************
	GUI Support Scripting.	
	Sears Roebuck de México.
	Sears Internet.

Version 0.1  Feb/2008
*******************************************************/


	/*********************************
	Restores the state of a button
	**********************************/
	function buttonOut(img){
		var url=img.src;
		var li=url.lastIndexOf("_over.");
		img.src=(li!=-1)?url.substring(0,li)+url.substr(li+5):url;
	}


		/******************************************************
			Gets the X position of a Node(HTML Element)
		********************************************************/
		function getMyAbsoluteLeft(node){
				var ourLeft=0;
				while(node.offsetParent!=null){
							
						
							if (node.offsetLeft !="undefined" && node.offsetLeft !=null)
								ourLeft+=node.offsetLeft;	
							
							node=node.offsetParent;	
													
						}	
				return ourLeft;	
		
		}

		/******************************************************
			Gets the  Y  position of a node (HTML Element)
		********************************************************/
		function getMyAbsoluteTop(node){
				var ourTop=0;
				while(node.offsetParent!=null){
							
						
							if (node.offsetTop !="undefined" && node.offsetTop !=null)
								ourTop+=node.offsetTop;	
							
							node=node.offsetParent;	
													
						}		
			return ourTop;
		}

        	/******************************
	Gets the KeyCode
	***************************/
	function getKeyCode(e){
		var tkey;
		if(window.event){
			tkey=event.keyCode;
		}else{
			tkey=e.which;
		}
		return tkey;
	}
	/************************
	Get's if the key code is enter
	*************************/
	function isEnterKey(e){
		return (getKeyCode(e)==13);
	}
	/************************
	Gets the source of  a event
	*************************/
	function getSource(e){		
		if (window.event){
			return event.srcElement;
		}else
		{
			return e.target;
		}
	}
			
	
	/******************************
	 Handles the Enter key so no to autopostback while pressing 
	*******************************/
	function handleNoEnter(e){
	
		
		if (isEnterKey(e)){
			//Get the type..
			var src;
			src= getSource(e);
			//If it's text..don't apply the enter key
			if (src.type=='text')return false;
		}
	}
	
	//Set the Handler
	for (i=0;i<document.forms.length;i++){		
		document.forms [i].onkeypress=handleNoEnter;		
	}


	/***************************
	Shows a Nice Pop Up
	****************************/
	function ShowCustomPopUp(w,h,page,winTitle,scroll){

		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;		
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
		win = window.open(page, winTitle, winprops);
		if (!parseInt(navigator.appVersion) <= 4) { 
			win.window.focus(); 
			}		
			return win;
	}
	/********************************
	Set the Over of the current button
	*********************************/
	function buttonOver(img){
		var url=img.src;
		var li=url.lastIndexOf(".");		
		img.src=(li!=-1)?url.substring(0,li)+"_over"+url.substr(li):url;
	}
	



////////////////////////////////////////////////////////////////////////////////////////////
/** Header Specific */


	
	/***********************
	submitSearch
	***********************/
	function hSubmitSearch(e){
		
		if (getKeyCode(e)==13){
			document.getElementById("Header1_btnSearch").click();
			}
	}
	/***********************
	Show the Catalog
	***********************/	
	function showSearsCatalog() {
	var w=850;
	var h=430;
	var scroll="no";
	var mypage=getRootPath("micrositios/contemporary/index.htm");
	ShowCustomPopUp(w,h,mypage,"EscaparateSears",scroll);
	}
	
	var isShowingSB=0;

	var SBmaxHeight=90;
	var SBtimeOut=6000;
	/********************************
	    Get the Sliding Bar
	********************************/
	function showSB(){
	    if (isShowingSB==0){	        
	        isShowingSB=1;
	        var tag=document.getElementById ('colLogin');
	        //var myleft= getMyAbsoluteLeft(tag);
	        //var mytop=getMyAbsoluteTop(tag);
	        var lay=document.getElementById ("mySBlayer");
	        lay.style.height="0px";
	        //lay.style.left=(myleft-10)+"px";
	        //lay.style.top=(mytop+80)+"px";
	        showElement("mySBlayer");
	        moveUpHideSB();
	    }
	}

	/********************************
	   Change the Position
	********************************/	
    function setSBLayer(x,y){
        var lay=document.getElementById ("mySBlayer");
        if (lay!=null){
	        lay.style.left=x+"px";
	        lay.style.top=y+"px";        
        }
    }

	/********************************
	    Triggered on Load if needed
	********************************/	
		function showSBOnLoad(){
	    if(hasSB())showSB();
	}
	/********************************
	    Verify if we have something to show
	********************************/	
	function hasSB(){
	    return retrieveSBHTML()!="";
	}
	
	/********************************
	    Retrieve the SBHTML
	********************************/
	function retrieveSBHTML(){
	
	    if (typeof retrieveSB != "undefined")return retrieveSB();
	    return "";
	}
	
	/******************************************************
			Move Up the  Sliding Bar
	********************************************************/
	function moveUpHideSB(){
	
	       var lay=document.getElementById ("mySBlayer");
	        if(isShowingSB<=SBmaxHeight){
	            isShowingSB+=5;
	            lay.style.height=isShowingSB+"px";
	            setTimeout(moveUpHideSB,50);	
	        }else{

                //Set Items
                lay.innerHTML='<table style="border-style:dotted;width:100%;height:100%"  id="SBcontainerTable"><tr><td valign="top" style="height:11px" align="right"><a href="#" class="gris" onclick="hideSB()"><span class="gris">[X]</span></a></td></tr><tr><td>'+ retrieveSBHTML() + '</td></tr></table>'
                setTimeout(hideSB,SBtimeOut);
            }    
     
	}
		/******************************************************
			Hide the  Sliding Bar
		********************************************************/
	
	function hideSB(){
	    
	    var lay=document.getElementById ("mySBlayer");
	    if (isShowingSB>0){
	            lay.innerHTML="";
                isShowingSB-=5;
                if(isShowingSB>0){
	                    lay.style.height=isShowingSB+"px";
	                }else{
	                    hideElement("mySBlayer");	
	                }
        	    setTimeout(hideSB,25);       
	          	    
	    }else{
	        hideElement("mySBlayer");	
	        isShowingSB=0;
	    }
	    
	}
	
		/******************************************************
			Verify the Buttons of a given Path
		********************************************************/
	
	function verifyMainBarPath(){
	
	
	    var ops=[["mesaRegalo/","mesa_regalos.gif"],
	                  ["promotion.aspx","promociones.gif"],
	                  ["credito/","credito.gif"]
	                 ];
	
	
	    var menuTable=document.getElementById ("mainTableMen1");
	    var nodes=menuTable.getElementsByTagName("a");
        var passesCondition=false;
	     for (var i=0;i<nodes.length;i++){	    
	                var node=nodes[i];
	                passesCondition=false;    
	                //E-Commerce
	             if (typeof parentDept_aspx_id!="undefined"){
                    
                    var dept=parentDept_aspx_id;
                    if (dept==0)dept=dept_aspx_id;
                        var regExpDept=/dept\.aspx\?deptid=(\d+)&?/;
                        var regExpRes=regExpDept.exec(node.href.toLowerCase());
                        if(regExpRes!=null){
                            if (regExpRes.length>=2){
                                passesCondition=(regExpRes[1]==dept);
                            }
                        }
                    }else{
                        //Other Sections
                        for (var j=0;j<ops.length;j++){                            
                            var pairs=ops[j];
                            if(!passesCondition)                     
                                passesCondition=curSearsPath.toLowerCase().indexOf(pairs[0].toLowerCase())>0  && node.href.toLowerCase().indexOf(pairs[0].toLowerCase())>0;
                        }
                    
                    }
	                	                
	                if (passesCondition){
	                    var img=node.getElementsByTagName("img");
	                    if (img.length>0){
	                            img=img[0];            
	                            img.onmouseover(img);//Invoke
	                            var tmp=img.onmouseover;
	                            img.onmouseover=null;
	                            img.onmouseout=null;  
	                    } 
        	            
	                }	        
	            }	    	    
	}