/*Shop by Manufacturer*/
function shopMfg(mfgform){
	//alert(mfgform.searchBrand.value);
	if(mfgform.searchBrand.value == ""){
		return false;
	}
	if(mfgform.searchBrand.value == "99999"){
		mfgform.dsp.value=90700;
		mfgform.actn.value="";
		mfgform.searchBrand.value="";
		mfgform.PCR.value="1:50000";
	}
	return true;
}

/*Shop by Products*/
function shopProducts(prdform){
	if(prdform.searchAttribute1.value == ""){
		return false;
	}
	if(prdform.searchAttribute1.value == "99999"){
		prdform.dsp.value=90600;
		prdform.actn.value="";
		prdform.searchAttribute1.value="";
		prdform.PCR.value="1:60000";
	}
	return true;
}

function createStaticPopup(A){
	newHref="/atd/Shop?dsp=staticpopups&fid=/html/"+A;
	window.open(newHref,name,"fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=400,height=460")
}
function submitRequestQuote(){
	document.forms.requestQuoteForm.submit()
}
function shopOther(B){
	var A=B.options[B.selectedIndex].value;
	if(A.length>0){
		if(A!="http://www.atdamerican.com"){
			window.open(A,"shopother")
		}
		else{
			location.href=A
		}
	}
}

function openSimplePopup(href, name) {
	window.open(href, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width=480,height=460,scrollbars=1");
}

function openSizedPopup(href, name, width, height) {
	window.open(href, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width="+width+",height="+height+",scrollbars=1");
}

function openHelpMePopup(href, name) {
  window.open(href, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,directories=no,location=no,width=475,height=600,scrollbars=1");
}

function printPage(){
window.print();
window.close();
}

// from ab-pop.js
function closewithstatus(name) {
		setCookie('abpopunder','yes','/atd/');
  	if(name==null){
  		self.close(); 
  	}
  	else{
  		openMain(name);
  	}
}

function submitwithstatus(name) {
		setCookie('abpopunder','yes','/atd/');

}
function loadwithstatus(name) {
		setCookie(name,'yes','/atd/');
}
//--------- Code for cookies--------- 
function resetcookie(){
var expireDate = new Date()
expireDate.setMinutes(expireDate.getMinutes()-10)
document.cookie = "abpopunder=;path=/;expires=" + expireDate.toGMTString()
}

function setCookie(NameOfCookie, value,path) 
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (0.02 * 24 * 3600 * 1000));
	//document.cookie = NameOfCookie + "=" + escape(value) + "; expires=" + ExpireDate.toGMTString()
	document.cookie = NameOfCookie + "=" + escape(value) + "; expires=" + ExpireDate.toGMTString()+
	((path == null) ? "" : ("; path=" + path));
}

function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return null;
}
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1){
    endstr = document.cookie.length;
   }
  return unescape(document.cookie.substring(offset, endstr));
}


function openMain(url) { 
	  if (window.opener && !window.opener.closed) { 
	   window.close();
	   window.opener.location.href = url; 
	   window.opener.focus(); 
	  } else {
	   window.open(url);	
	  }
	  return false; 
	}

var exitblockDomain=new Array(5);
exitblockDomain[0]="www.google.com";
exitblockDomain[1]="www.shop.com";
exitblockDomain[2]="www.search.yahoo.com";
exitblockDomain[3]="www.search.live.com";
exitblockDomain[4]="www.search.msn.com";

function unpopup()
{
	var showpopup=true;
	var refurl=document.referrer;
	var parsestr=refurl.split("/");
	var i=exitblockDomain.length;
	for(var j=0;j<i;j++){
		if(exitblockDomain[j]==parsestr[2]){
			showpopup=false;
		}
	}
	if((navigator.userAgent.toUpperCase().indexOf("GOOGLE")!=-1) ||
	   (navigator.userAgent.toUpperCase().indexOf("MSNBOT")!=-1) ||
	   (navigator.userAgent.toUpperCase().indexOf("SLURP")!=-1) ||
	   (navigator.userAgent.toUpperCase().indexOf("JEEVES")!=-1) ||
	   (navigator.userAgent.toUpperCase().indexOf("INKTOMI")!=-1) ||
	   (navigator.userAgent.toUpperCase().indexOf("YAHOO")!=-1) )  {
		showpopup=false;
	}
	if(showpopup==true){
		 if (GetCookie('abpopunder')==null && GetCookie('unpopup')==null){
			setTimeout("unpopupdelay()",3000);
		}
	}
}

function unpopupdelay()
{
	    var popunder="/atd/html/ab-global.html";
	    var winWidth=1;
		var winHeight=1;
		var screenWidth=screen.width
		var screenHeight=screen.Height
		var xPos=1
		var yPos=800
		var option = "width="+winWidth+",height="+winHeight+",scrollbars=no,fullScreen=no,location=0,resizable=0,status=0,directories=0,top="+yPos+",left=" +xPos+"";
	    var winfeatures="width=1,height=1,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0";
		win3=window.open(popunder,"null",option);
		setCookie('unpopup','yes','/atd/');
		if(win3!=null){
		  	win3.blur();
		}
}

function submitABEmailCart() {
	var C = "";
	var B = "janet@atd.com";
	var A = "";
	if (document.savecart.email1.value == "" && document.savecart.email2.value == "" ) {
		C = "<br/> At least one email to address is required" + C;
	}
	if (document.savecart.email.value == "") {
		C = "<br/> Your email is required" + C;
	}
	if (document.savecart.email.value.indexOf("@") == "-1" || document.savecart.email.value.indexOf(".") == "-1") {
		C = "<br/> Please enter a valid email address" + C;
	}
	if (C.length > 0) {
		if (C.length > 0) {
			C = "Please enter all required fields :" + C;
		}
		document.getElementById("ccjsalert").innerHTML = C;
		window.location.href = "#ccjs";
		return false;
	} else {
		if (document.savecart.sendto.checked) {
			A = document.savecart.email.value;
		}
		if (document.savecart.email1.value != "") {
			if (A.length > 0) {
				if (B.length > 0) {
					B += "," + document.savecart.email1.value;
				} else {
					B = document.savecart.email1.value;
				}
			} else {
				A = document.savecart.email1.value;
			}
		}
		if (document.savecart.email2.value != "") {
			if (A.length > 0) {
				if (B.length > 0) {
					B += "," + document.savecart.email2.value;
				} else {
					B = document.savecart.email2.value;
				}
			} else {
				A = document.savecart.email2.value;
			}
		}
		document.savecart.emailFrom.value = document.savecart.email.value;
		document.savecart.emailAddress.value = A;
		document.savecart.emailCCAddresses.value = B;
		document.savecart.submit();
	}
}
//----------------
function showViewSavedCart() {
	document.savecart.basketid.value = "";
	document.savecart.cartname.value = "";
	document.savecart.ACTN.value = "40320";
	document.savecart.submit();
}
//-----------------
var i=0;

function checkParent(){
	i++;
	if (window.opener && !window.opener.closed){}
	else{	
		myinterval = window.clearInterval(myinterval);
	  setTimeout("showSurvey()",1000);
	}
	if(i > 112){ 
		myinterval = window.clearInterval(myinterval);
		self.close();
	}
} 

function showSurvey() {
  var popunder="/atd/Shop?dsp=90510";
  var winfeatures="width=500,height=500,scrollbars=0,resizable=1,toolbar=0,location=0,menubar=0,status=0,directories=0";
  if (GetCookie('abpopunder')==null){
    win2=window.open(popunder,"ATD",winfeatures);
    setCookie('abpopunder','yes','/atd/');
  }
  self.close();
}

function zMinimize(){
	window.resizeTo(0,0);
	window.moveTo(0,screen.height-50);
}