var xmlHttp;

  var win=null;
  var materialInput='';
  var widthInput='';
  var heightInput='';
  var quantityInput='';
  var widthAlert='No';
  var keyStrike='';

  function printIt(printThis)
  {
    win = window.open();
    self.focus();
    win.document.open();
    win.document.write('<'+'html'+'><'+'head'+'><'+'style'+'>');
    win.document.write('body, td { font-family: Verdana; font-size: 10pt;}');
    win.document.write('<'+'/'+'style'+'><'+'/'+'head'+'><'+'body'+'>');
    win.document.write(printThis);
    win.document.write('<'+'/'+'body'+'><'+'/'+'html'+'>');
    win.document.close();
    win.print();
    win.close();
  }





function makeGenerate(str) 
{
if (str != "NA")
 { 
 document.getElementById("qtboder").innerHTML="<input type='image' class='noner' src='images/generate.png' value='GENERATE' onMouseUp='showQUOTE(this.value)'>";
 } 
else
{
document.getElementById("qtboder").innerHTML="";
}
}



function showWIDTH(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=matChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



function showSIZE(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="getsize.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=shapeChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function showQ(mat, wid, hei)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="vinylquant.php";
url=url+"?mat="+mat+"&wid="+wid+"&hei="+hei;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=heightChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function showPRICE(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="vinylprice.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=qChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
makeGenerate(str);
}


function showQUOTE()
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="vinylquote.php";

xmlHttp.onreadystatechange=quoteChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function changeTRADE(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="gettrade.php";
url=url+"?q="+str
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=tradeChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function showCOMPANY(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="getcompany.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=companyChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function orderAlertw()
{
alert('Fields must be completed in order from 1-4 starting with Material');
document.getElementById("widthField").blur();
}

function orderAlerth()
{
alert('Fields must be completed in order from 1-4 starting with Material');
document.getElementById("heightField").blur();
}

function testWidth()
{
wValue = document.getElementById("widthField").value;
if(parseInt(wValue)<10){
alert('Width must be between 10mm and 650mm');
document.getElementById("widthField").value='';

widthInput='';
document.getElementById("materialField").focus();
} else if(parseInt(wValue)>650){
alert('Width must be between 10mm and 650mm');
document.getElementById("widthField").value='';

widthInput='';
document.getElementById("materialField").focus();
}
else{
materialInput=document.getElementById("materialField").value;
widthInput=document.getElementById("widthField").value;
document.getElementById("heightField").value = '';
heightInput=document.getElementById("heightField").value;
document.getElementById("heightField").onfocus='';
document.getElementById("heightField").onchange=testHeight;
	if (materialInput !='' && heightInput!=''){
			widthInput = document.getElementById("widthField").value;
			showQ(materialInput, widthInput, heightInput);
			<!--showPRICE('preset');-->
			document.getElementById("quote").innerHTML='';
			document.getElementById("qtboder").innerHTML="";
			<!--document.getElementById("heightField").value='materialInput';-->
	}
}
}

function testHeight()
{
hValue = document.getElementById("heightField").value;
if(parseInt(hValue)<10){
alert('Height must be between 10mm and 650mm')
document.getElementById("heightField").value='';

heightInput='';
document.getElementById("widthField").focus();
} else if(parseInt(hValue)>650){
alert('Height must be between 10mm and 650mm')
document.getElementById("heightField").value='';

heightInput='';
document.getElementById("widthField").focus();
}
else{
materialInput=document.getElementById("materialField").value;
widthInput=document.getElementById("widthField").value;
heightInput=document.getElementById("heightField").value;
	showQ(materialInput, widthInput, heightInput);
	<!--document.getElementById("quantity").innerHTML="<select name='quantityField' id='quantityField' onchange='showPRICE(this.value)'><option value='NA'>Select a Quantity</option><option value='10'>10</option></select>";-->
	document.getElementById("quantityField").focus();
	document.getElementById("quote").innerHTML='';
	document.getElementById("qtboder").innerHTML="";
}
}


function wkeyStroked(e){
if (e.keyCode==9 && document.getElementById("widthField").value==''){
alert('Width must be between 10mm and 650mm');
document.getElementById("widthField").focus();
}else if (e.keyCode==9 && parseInt(document.getElementById("widthField").value)<10){
alert('Width must be between 10mm and 650mm');
document.getElementById("widthField").focus();
}else if (e.keyCode==9 && parseInt(document.getElementById("widthField").value)>650){
alert('Width must be between 10mm and 650mm');
document.getElementById("widthField").focus();
}else if (e.keyCode==9){
document.getElementById("heightField").focus();


}
}

function hkeyStroked(e){
if (e.keyCode==9 && document.getElementById("heightField").value==''){
alert('Height must be between 10mm and 650mm');
document.getElementById("heightField").focus();
}else if (e.keyCode==9 && parseInt(document.getElementById("heightField").value)<10){
alert('Height must be between 10mm and 650mm');
document.getElementById("heightField").focus();
}else if (e.keyCode==9 && parseInt(document.getElementById("heightField").value)>650){
alert('Height must be between 10mm and 650mm');
document.getElementById("heightField").focus();
}else if (e.keyCode==9){
document.getElementById("quantityField").focus();

}
}

function displayunicodew(e){

var unicode=e.keyCode? e.keyCode : e.charCode;
actualkey=String.fromCharCode(unicode);
if (actualkey !='0' && actualkey !='1' && actualkey !='2' && actualkey !='3' && actualkey !='4' && actualkey !='5' && actualkey !='6' && actualkey !='7' && actualkey !='8' && actualkey !='9' && unicode !=96 && unicode !=97 && unicode !=98 && unicode !=99 && unicode !=100 && unicode !=101 && unicode !=102 && unicode !=103 && unicode !=104 && unicode !=105 && unicode !=37 && unicode !=38 && unicode !=39 && unicode !=40 && unicode !=8 && unicode !=46){
	return false;
}
widthInput=document.getElementById("widthField").value;
}


function displayunicodeh(e){
var unicode=e.keyCode? e.keyCode : e.charCode
actualkey=String.fromCharCode(unicode);
if (actualkey !='0' && actualkey !='1' && actualkey !='2' && actualkey !='3' && actualkey !='4' && actualkey !='5' && actualkey !='6' && actualkey !='7' && actualkey !='8' && actualkey !='9' && unicode !=96 && unicode !=97 && unicode !=98 && unicode !=99 && unicode !=100 && unicode !=101 && unicode !=102 && unicode !=103 && unicode !=104 && unicode !=105 && unicode !=37 && unicode !=38 && unicode !=39 && unicode !=40 && unicode !=8 && unicode !=46){
	return false;
}
heightInput=document.getElementById("heightField").value;
}


function matChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
document.getElementById("widthField").value = '';
document.getElementById("widthField").onfocus='';
<!--document.getElementById("widthField").onkeyup='displayunicodew(event)';-->
document.getElementById("widthField").onchange=testWidth;
materialInput = document.getElementById("materialField").value;
<!--alert(materialInput);-->
<!--alert(widthInput);-->
<!--alert(heightInput);-->

document.getElementById("widthField").focus();
	if (widthInput !='' && heightInput!=''){
			showQ(materialInput, widthInput, heightInput);
			document.getElementById("quote").innerHTML='';
			document.getElementById("qtboder").innerHTML="";
			<!--showPRICE('preset');-->
	}
 } 
}



function heightChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("quantity").innerHTML=xmlHttp.responseText;
 } 
}


function qChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("quote").innerHTML=xmlHttp.responseText;
 quantityInput=document.getElementById("quantityField").value;
 } 
}


function tradeChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
var myresponse=xmlHttp.responseText;
var responsearray=myresponse.split("/");

  if (responsearray[1] == 1)
  {
  document.getElementById("tcode").innerHTML="<input class='tcode' type='text' name='tcode' value='Welcome "+responsearray[0]+"' onFocus='this.blur();'>";
			showQ(materialInput, widthInput, heightInput);
			document.getElementById("quote").innerHTML='';
			document.getElementById("qtboder").innerHTML="";
  } 

 }
}


function quoteChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("qqbody").innerHTML=xmlHttp.responseText+"<br><br><a href='vinylfriend.php' onclick=\"window.open(this.href, '','height=750,width=700');return false;\"><img src='images/printquote.png' border='0' target='_blank'></a></td></tr></table></p>";
 } 
}


function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}



