// JavaScript Document
var pageRequest = false;
var top = 0;
var left = 0;

function popup()
{	
	
	var iMyWidth;
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (screen.availWidth/2) - (250);
	
	document.getElementById("msg").style.left = iMyWidth + 'px';
	
	document.getElementById("msg").style.visibility = "visible";
	document.getElementById("msg").innerHTML = "Loading...";
	document.getElementById("back").style.visibility = "visible";
	
	
	//check browser
	if (window.XMLHttpRequest)
	{		
		//Mozilla, Safari, Netscape
		pageRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		//Internet Explorer
		pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
	}
	
	getData();
}

function getData()
{
	pageRequest.open('GET', 'shipping.html', true);
	pageRequest.send(null);
		
	pageRequest.onreadystatechange = function()
	{	
		var object = document.getElementById("header");	
		
		if(pageRequest.readyState == 4 && pageRequest.status == 200)
		{	
			document.getElementById("msg").innerHTML = pageRequest.responseText;			
		}		
	}	
}

function hide()
{
	document.getElementById("msg").style.visibility = "hidden";
	document.getElementById("back").style.visibility = "hidden";
	document.getElementById("grade").style.visibility = "hidden";
}

function hover(msg, grd)
{		
	//find mouse location
	var object = document.getElementById(msg);
	
	if (grd == 1)
	{
	//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hoverfindMouseLocation1;		
	}
	else if (grd == 2)
	{
		//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hoverfindMouseLocation2;
	}
	else if (grd == 3)
	{
		//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hoverfindMouseLocation3;
	}
	else if (grd == 4)
	{
		//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hoverfindMouseLocation4;
	}
}

function hoverfindMouseLocation1(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "&nbsp;Kitted&nbsp;";
	document.getElementById("grade").style.visibility = "visible";	
}

function hoverfindMouseLocation2(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "&nbsp;Untested&nbsp;";
	document.getElementById("grade").style.visibility = "visible";	
}
function hoverfindMouseLocation3(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "&nbsp;Fall Out&nbsp;";
	document.getElementById("grade").style.visibility = "visible";	
}
function hoverfindMouseLocation4(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "&nbsp;Tested&nbsp;";
	document.getElementById("grade").style.visibility = "visible";	
}

function hover2(msg, grd)
{		
	//find mouse location
	var object = document.getElementById(msg);
	
	if (grd == 1)
	{
	//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hover2findMouseLocation1;		
	}
	else if (grd == 2)
	{
		//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hover2findMouseLocation2;
	}
	else if (grd == 3)
	{
		//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hover2findMouseLocation3;
	}
	else if (grd == 4)
	{
		//window.document.onmouseover = findMouseLocation;
	object.onmouseover = hover2findMouseLocation4;
	}
}

function hover2findMouseLocation1(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "<strong>Kitted</strong>-Fully functional phones that come with a back, battery, charger, and generic retail box";
	document.getElementById("grade").style.visibility = "visible";	
}

function hover2findMouseLocation2(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "<strong>Untested</strong>-No tests have been performed.  Historically, 70% of the phones will power up with good LCDs.  The newer the model then the lower the yield.  The older the model then the higher the yield.  50% or more will come with back and battery.";
	document.getElementById("grade").style.visibility = "visible";	
}
function hover2findMouseLocation3(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "<strong>Fall Out</strong>- These phones have been tested and are known to have issues ranging from a bad keypad button to frozen software to a torn flex cable.  20% or so will have backs and batteries.";
	document.getElementById("grade").style.visibility = "visible";	
}
function hover2findMouseLocation4(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "Tested-Fully functional phones of which 90% come with battery and back.  No charger or retail box is included.";
	document.getElementById("grade").style.visibility = "visible";	
}

function clicks(msg, grd)
{	
	//find mouse location
	var object = document.getElementById(msg);
	
	if (grd == 1)
	{
		//window.document.onmouseover = findMouseLocation;
		object.onclick = clicksfindMouseLocation1;		
	}
	else if (grd == 2)
	{
		//window.document.onmouseover = findMouseLocation;
		object.onclick = clicksfindMouseLocation2;
	}
	else if (grd == 3)
	{
		//window.document.onmouseover = findMouseLocation;
		object.onclick = clicksfindMouseLocation3;
	}
	else if (grd == 4)
	{
		//window.document.onmouseover = findMouseLocation;
		object.onclick = clicksfindMouseLocation4;
	}
}

function clicksfindMouseLocation1(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "<strong>Kitted</strong>-Fully functional phones that come with a back, battery, charger, and generic retail box";
	document.getElementById("grade").style.visibility = "visible";		
}
function clicksfindMouseLocation2(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "<strong>Untested</strong>-No tests have been performed.  Historically, 70% of the phones will power up with good LCDs.  The newer the model then the lower the yield.  The older the model then the higher the yield.  50% or more will come with back and battery.";
	document.getElementById("grade").style.visibility = "visible";
		
}
function clicksfindMouseLocation3(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "<strong>Fall Out</strong>- These phones have been tested and are known to have issues ranging from a bad keypad button to frozen software to a torn flex cable.  20% or so will have backs and batteries.";
	document.getElementById("grade").style.visibility = "visible";	
}
function clicksfindMouseLocation4(evt)
{	
	var evt = (evt) ? evt : ((window.event) ? window.event : null);
	
	top = evt.clientY + 10 + 'px';
	left = evt.clientX + 8 + 'px';
	
	document.getElementById("grade").style.left = left;
	document.getElementById("grade").style.top = top;
	document.getElementById("grade").innerHTML = "Tested-Fully functional phones of which 90% come with battery and back.  No charger or retail box is included.";
	document.getElementById("grade").style.visibility = "visible";
}

function productSearch(product, page, man, desc, srt, order)
{
	
	var object = document.getElementById(product);
	var loading = document.getElementById("loading");
	
	var iMyWidth;
	var iMyHeight;
	
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (screen.availWidth/2);	
	iMyHeight = (screen.availHeight/4);
	
	loading.style.left = iMyWidth + 'px';
	loading.style.top = iMyHeight + 'px';
	
	document.getElementById("back2").style.visibility = "visible";
	loading.style.visibility = "visible";
	
	
		//check browser
	if (window.XMLHttpRequest)
	{		
		//Mozilla, Safari, Netscape
		pageRequest = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) 
	{
		//Internet Explorer
		pageRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
	}
	
	if (desc != '')
		{
		var pattern = / /g;
		desc=desc.replace(pattern,"+");
	}
	
	var sendData = "man=" + man + "&desc=" + desc + "&sort=" + srt + "&order=" + order;	
	pageRequest.open('POST', page, true);
	pageRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	pageRequest.send(sendData);
		
	pageRequest.onreadystatechange = function()
	{	
		if(pageRequest.readyState == 4 && pageRequest.status == 200)
		{	
			object.innerHTML = pageRequest.responseText;
			document.getElementById("back2").style.visibility = "hidden";
			loading.style.visibility = "hidden";
		}		
	}
}
