// Copyright Acro Media Inc. 1998-2009, www.acromediainc.com 

entryPoint = document.referrer;
entryPoint.toLowerCase();
if(entryPoint.indexOf("tonsoftoner") == -1){
	var expires = new Date();
	expires.setTime(expires.getTime() + 3E11);   // about 10 years = "forever"
	setCookie("entryPoint", document.referrer, 0, "/", ".tonsoftoner.com");
}

function openUp(windowURL, windowWidth, windowHeight) {
	var topPos = "";
	var leftPos = "";
	if(!windowWidth) windowWidth = 0;
	if(!windowHeight) windowHeight = 0;
	if(windowWidth == 0){
		if(screen){
			windowWidth = screen.availWidth -10;
		}
		else{
			windowWidth = 790;
		}
		leftPos = ",left=0";
	}
	if(windowHeight == 0){
		if(screen){
			windowHeight = screen.availHeight -30;
		}
		else{
			windowHeight = 790;
		}
		topPos = ",top=0";
	}
	newWin = window.open(windowURL,"acromedia","toolbar=no,menubar=0,width="+windowWidth+",height="+windowHeight+topPos+leftPos+",scrollbars=yes,resizable=no");
}

function load_phplive(){
  var refer = document.URL;
  window.open('http://www.tonsoftoner.com/phplive/request.php?l=tonerlive&x=1&deptid=0&page='+refer, '', 'scrollbars=no,menubar=no,resizable=0,location=no,screenX=50,screenY=100,width=450,height=350');
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = 0 + dc.indexOf(prefix);
	if (begin == -1){
		return 0;
	}
	begin += prefix.length;
	var end = 0 + document.cookie.indexOf(";", begin);
	if (end == -1){
		end = dc.length;
	}
	return unescape(dc.substring(begin, end));
}	

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
			((expires) ? "; expires=" + expires.toGMTString() : "") +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function checkValue(name){
	if(eval("document.detailsForm."+name+".value") == ""){
		eval("document.detailsForm."+name+".value = '1'");
	}
	else{
		eval("document.detailsForm."+name+".value = ''");
	}

}

function checkBox(name, otherName){
	if(eval("document.detailsForm."+otherName+".value") == ""){
		eval("document.detailsForm."+name+".checked = false");
	}
	else{
		eval("document.detailsForm."+name+".checked = true");
	}
}

function showModels(path){

  if (path.length==0){
    return;
  }

  xmlHttp=GetXmlHttpObject();

  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  }

  var url="/processList.php?q="+path;

  xmlHttp.onreadystatechange = stateChanged;
  xmlHttp.open("POST",url,true);
  xmlHttp.send(null);
}

function stateChanged(){
  if(xmlHttp.readyState==4){
    document.getElementById('selectedModels').innerHTML=xmlHttp.responseText;
  }
}

function doRedirect(){
  var manufactureLink = document.getElementById("workingManufacturer");
  var modelsLink = document.getElementById("machines");

  if(modelsLink.value != ""){
    document.location.href = modelsLink.value;
  }
  else{
    return;
  }
}

$(function() {
  $('#cartForm').submit(function() {    
    $('#cartForm input[name*="formaction"]').attr("name", "action");  
  });
});

function secureCart() {
  theAction = $('#cartForm').attr("action");    
  theAction = theAction.replace("http", "https");    
  $('#cartForm').attr("action", theAction);
}
 
// external links 
$(function() {
  $("a[rel='external']").each(function() {
    $(this).attr("target", "_blank");
  });
});