function wtbpop(url){window.open(url,'popup','screenX=0,screenY=0,resizable=yes,scrollbars=yes, height=300, width=400');}
function disclaimer(){wtbpop('/static/wtb_disclaimer.html');}
function ppp(){wtbpop('/static/wtb_featured_store.html');}
function trusted(){wtbpop('/static/wtb_trusted_store.html');}
function smart(){wtbpop('/static/wtb_smart_buy.html');}
function popsl(url,w,h,x,y){window.open(url,'popup','screenX='+x+',screenY='+y+',top='+y+',left='+x+',resizable=yes,scrollbars=yes,height='+h+',width='+w)}
linkName2Index=new Object();
function getLinkNamed(name){
var d=document;
if(linkName2Index[name]>=0){return d.links[linkName2Index[name]];}
for(i=d.links.length-1;i>=0;i--){
if(typeof d.links[i].name!="undefined"){if(d.links[i].name==name){linkName2Index[d.links[i].name]=i;return d.links[i];}}
}return null;
}

function cpl(from,to,ct) {
   var flnk=getLinkNamed(from);
   var tlnk=getLinkNamed(to);
   if(flnk!=null&&tlnk!=null){
      var ltxt=tlnk.innerHTML;
      ctidx=flnk.href.lastIndexOf('&CT=');
      if(ctidx!=-1){tlnk.href=flnk.href.replace(/&CT=./g,"&CT="+ct);}
      else{tlnk.href=flnk.href;}
      tlnk.innerHTML=ltxt;tlnk.target=flnk.target;tlnk.className="";tlnk.onclick=flnk.onclick;
    }
}
var MerchWinName = null;
var popWin;
function cb(anch, url) {
  if(anch && anch.target) merchWinName = anch.target;
  if (window.showModelessDialog) setTimeout("showRebate('"+url+"','popup')",50);
  else showRebate(url, 'popup');
}
function showRebate(url, wName){
 var wSpecs = 'width=290,height=535,screenX=100,screenY=270,top=270,left=100,scrollbars=yes,toolbar=no,menu=no';
 if (window.showModelessDialog) {
  window.showModelessDialog("javascript:function noerror(){return true;} window.onerror = noerror; function doit(){window.open('','"+wName+"', '"+wSpecs+"', true);self.close();} doit();","","dialogTop=12355; dialogLeft=12355; dialogHeight:0px; dialogWidth:0px; status:no; help:no");
  popWin = null;
 } else {
  popWin = window.open(url, wName, wSpecs);
 }
 setTimeout("focusInOrder('"+url+"','"+wName+"','"+wSpecs+"')",1000);
}

function focusInOrder(url, wname, wspecs){
 var mWin = null;
 if (document.hasFocus) {
  if (document.hasFocus() == true) {
   if (merchWinName && merchWinName != "_blank") mWin = window.open("", merchWinName, "");
  }
 } else {
    if(merchWinName && merchWinName != "_blank") mWin = window.open("", merchWinName, "");
 }
 if (mWin) mWin.focus();
 if (!popWin) popWin = window.open(url, wname, wspecs);
 if (popWin) popWin.focus();
}

function reload(){window.location.reload()}

function isMaxLength(obj){
   var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
   if (obj.getAttribute && obj.value.length>mlength)
      obj.value=obj.value.substring(0,mlength)
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

var mouseVerticalPos;
var mouseHorizontalPos;
var popContent = "popContent";
var popArea = "popArea";
var popArrowLeft = "popArrowLeft";
var popArrowRt = "popArrowRt";
var popArrowTop = "popArrowTop";
var popArrowBtm = "popArrowBtm";

function getPopupTopPos(e, maxHeight) {
     if (navigator.appName == "Netscape") {
         // netscape
         if((window.innerHeight - (e.pageY - window.pageYOffset)) < maxHeight) {
             mouseVerticalPos = "bottom";
         } else {
             mouseVerticalPos = "top";
         }
         return e.pageY;
     } else if (navigator.appName == "Microsoft Internet Explorer") {
         // IE
         if ((document.documentElement.clientHeight - window.event.y) < maxHeight) {
             mouseVerticalPos = "bottom";
         } else {
             mouseVerticalPos = "top";
         }
         return window.event.y;
     }
 }

 function getPopupLeftPos(e, maxWidth) {
     if (navigator.appName == "Netscape" ) {
        // netscape
        if ((window.innerWidth - (e.pageX - window.pageXOffset)) < maxWidth) {
            mouseHorizontalPos = "left";
        } else {
            mouseHorizontalPos = "right";
        }
         return e.pageX;
    } else if (navigator.appName == "Microsoft Internet Explorer"){
        // IE
        if ((document.documentElement.clientWidth - window.event.x) < maxWidth) {
            mouseHorizontalPos = "left";
        } else {
            mouseHorizontalPos = "right";
        }
        return window.event.x;
    }
 }

 function displayPopup(url, parameter, targetElementId, event, popupWidth, popupHeight) {

 	topPos = getPopupTopPos(event, popupHeight);
 	leftPos = getPopupLeftPos(event, popupWidth);

 	showPopup(targetElementId, topPos, leftPos, popupWidth, popupHeight);

 	document.onmousedown = detectClick;
 }

  function preloadPopupImages() {
    image1 = new Image();
    image1.src = "http://img.shopping.com/jfe/bb/popups/popArrowLeft.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/popArrowRt.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/cornerTopLeft.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/cornerTopRt.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/popTopRepeat.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/popLeftRepeat.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/popRtRepeat.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/cornerBtmLeft.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/cornerBtmRt.gif";
    image1.src = "http://img.shopping.com/jfe/bb/popups/popBtmRepeat.gif";
 }


 function showPopup(targetDiv, topPos, leftPos, popupWidth, popupHeight) {
 	var offset = getOffset(targetDiv, popupHeight);

 	document.getElementById(targetDiv).style.display='block';
 	document.getElementById(targetDiv).style.display='none';

 	if (navigator.appName == "Netscape") {
 		// netscape
 		if (mouseVerticalPos == "bottom") {
 			document.getElementById(popArea).style.top = (topPos - offset + 30) + "px";
 		} else {
 			document.getElementById(popArea).style.top = (topPos - 30) + "px";
 		}
 		if (mouseHorizontalPos == "left") {
 			document.getElementById(popArea).style.left = (leftPos - popupWidth + 30) + "px";
 		} else {
 			document.getElementById(popArea).style.left = (leftPos + 12) + "px";
 		}
 	} else if (navigator.appName == "Microsoft Internet Explorer"){
 		// IE
 		if (mouseVerticalPos == "bottom") {
 			document.getElementById(popArea).style.top = (topPos + document.body.scrollTop - offset + 30) + "px";
 		} else {
 			document.getElementById(popArea).style.top = (topPos + document.body.scrollTop - 30) + "px";
 		}
 		document.getElementById(popArea).style.zIndex = document.getElementById(popArea).style.zIndex + 10;
 		if (mouseHorizontalPos == "left") {
 			document.getElementById(popArea).style.left = (leftPos - popupWidth + 12) + "px";
 		} else {
 			document.getElementById(popArea).style.left = (leftPos + 12) + "px";
 		}
 	}
 	document.getElementById(popArea).style.width = popupWidth + "px";
 	document.getElementById(popArea).style.display = 'block';
 	document.getElementById(targetDiv).style.display = 'block';
 }

 function getOffset(targetDiv, popupHeight) {
    if (targetDiv != "whatIsArea") {
        return popupHeight;
    } else {
        if (navigator.appName == "Netscape") {
           return document.getElementById(popContent).offsetHeight;
         } else if (navigator.appName == "Microsoft Internet Explorer"){
            if (document.getElementById(popContent).offsetHeight < 450) {
                h = document.getElementById(popContent).offsetHeight + 200;
            } else {
                h = document.getElementById(popContent).offsetHeight;
            }
            h = (h - 160) * 0.23;
            if ( h > 280) {
                h = 280;
            }
            return h;
         }
    }
}

function detectClick(e) {
	var targ;
	if (!e) e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;
	if (e.type == "mousedown" && isOutsidePopup(targ)) {
		closeAllPopups();
	}
}

function isOutsidePopup(targ) {
	if (targ && targ.id != 'popText' && targ.id != 'popTitle' && targ.id != 'popAction' && targ.id != 'popMidRt' && targ.id.substring(0, 9) != 'okgnauhc.' && targ.tagName != 'HTML') {
		return true;
	}
	return false;
}

function closeAllPopups() {
	var popups = new Array('enterZipArea', 'popArea', 'popContent');
	for (i=0; i < popups.length; i++) {
		if(document.getElementById(popups[i]) != null) {
			closePopup(popups[i]);
		}
	}
	document.onmousedown = null;
}

function closePopup(targetDiv) {
	document.getElementById(targetDiv).style.display='none';
}

