var zipSelectPopped = false;

function findPosition( oLink ) {
          if( oLink.offsetParent ) {
            for( var posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
              posX += oLink.offsetLeft;
              posY += oLink.offsetTop;
            }
            return [ posX, posY ];
          } else {
            return [ oLink.x, oLink.y ];
          }
        }

function RePositionZipSelectPopup()
{

   var positionTop =  findPosition(document.getElementById('lowerTopNav')); 
   var positionBottom =  findPosition(document.getElementById('lowerBottomNav')); 
   var height = positionBottom[1] -  positionTop[1];
   var leftOffSet=180+positionTop[0];
   var  topOffSet=110+positionTop[1];
   
    //var newImageHeight = (parseInt(imageHeight) + 40);
    //var yPos = ((screen.height / 2) - (parseInt(newImageHeight) / 2));
	var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  	xPos = (myWidth / 2) - 228;
	//Window.width / 2 = centerpoint on window.  Subtract the div width divided by 2 to center on the div centerpoint.
   
   document.getElementById('zipForm').style.position="absolute";
   document.getElementById('zipForm').style.top=positionTop[1]+"px";
   document.getElementById('zipForm').style.left=positionTop[0]+"px";
   document.getElementById('zipForm').style.height=height+"px";
		    
   document.getElementById('zipPanel').style.top=topOffSet+"px";
   document.getElementById('zipPanel').style.left=xPos+"px";
   document.getElementById('zipPanel').style.position="absolute";
   
}     
        
function HideZipSelect()
{  
		HideElement('zipForm');
		HideElement('zipPanel');   
		//HideElement("zipSelectError");
		//showElementsByName("qty");
		//showElementsByName("srt");
		//showElementsByName("zip");
	 
		 zipSelectPopped = false;              
}

function HideElement(elm)
{
	document.getElementById(elm).style.visibility="hidden";
}

var blurzipSelect = function(){
                   
	document.getElementById('continue').focus();
  
}
   
var blurBtnZipSelect = function()
{
	document.getElementById('zipSelectPopUp').focus();
}
        
var resizeHandler =  function(){
               
    if(zipSelectPopped)
    {
   
		RePositionZipSelectPopup();
    }

}

function writeLowerDiv() {
	
	document.write('<div id="lowerBottomNav"></div>');
}

function showzipSelect(friendly)
{
					 
	   
	   window.onresize=resizeHandler;
					  
	   var positionTop =  findPosition(document.getElementById('lowerTopNav')); 
	   var positionBottom =  findPosition(document.getElementById('lowerBottomNav')); 
	   var height = positionBottom[1] -  positionTop[1];
	   var leftOffSet=180+positionTop[0];
	   var  topOffSet=110+positionTop[1];
	   //document.getElementById("zipSelectError").style.visibility="hidden";
		//document.getElementById("cookieRequiredError").style.visibility="hidden";
	  RePositionZipSelectPopup();  
		 
		 if(friendly == false){
			
			 document.getElementById('zipForm').style.visibility="visible";
		 }
		 
		 
		 document.getElementById('zipPanel').style.visibility="visible";  
		 
		 
		 
		// document.getElementById("zipSelectPopUp").focus();
		 //document.getElementById("zipSelectPopUp").onblur = blurZipSelect;
		 //document.getElementById("btnZipSelectShop").onblur = blurBtnZipSelect;
		 
		//cookieRequiredError
	  
		  //Hide drop downs so they do not cover up zip select box
		  //hideElementsByName("qty");
		  //hideElementsByName("srt");
		  //hideElementsByName("zip");
		  
		  zipSelectPopped =true;
		  
		  /*if (document.cookie == "") 
		  {
			document.getElementById("cookieRequiredError").style.visibility="visible";
		  }*/
		 
} 
// JavaScript Document