var xmlHttp;

  var win=null;

  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 showSHAPE(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="getshape.php";
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(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 } 
var url="getquant.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=sizeChanged;
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="getprice.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="getquote.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 matChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("shape").innerHTML=xmlHttp.responseText;
 document.getElementById("size").innerHTML="<select name='size' onchange='showQ(this.value)'><option value='NA'>Select a material and shape</option></select>";
 document.getElementById("quantity").innerHTML="<select name='quantity' onchange='showPRICE(this.value)'><option value='NA'>Select above options first</option></select>";
 document.getElementById("quote").innerHTML="";
 document.getElementById("qtboder").innerHTML="";
 } 
}



function shapeChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("size").innerHTML=xmlHttp.responseText;
 document.getElementById("quantity").innerHTML="<select name='quantity' onchange='showPRICE(this.value)'><option value='NA'>Select above options first</option></select>";
 document.getElementById("quote").innerHTML="";
 document.getElementById("qtboder").innerHTML="";
 } 
}

function sizeChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("quantity").innerHTML=xmlHttp.responseText;
 document.getElementById("quote").innerHTML="";
 document.getElementById("qtboder").innerHTML="";
 } 
}


function qChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("quote").innerHTML=xmlHttp.responseText;
 } 
}


function tradeChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
var myresponse=xmlHttp.responseText;
var responsearray=myresponse.split("/");

  if (responsearray[1] == 1)
  {
  showSHAPE('NA');
  document.getElementById("tcode").innerHTML="<input class='tcode' type='text' name='tcode' value='Welcome "+responsearray[0]+"' onFocus='this.blur();'>";
  document.getElementById("material").innerHTML='<select name="material" onchange="showSHAPE(this.value)"><option value="NA">Select a material</option><option value="Matt Paper Permanent">Matt Paper Permanent</option><option value="Matt Paper Removable">Matt Paper Removable</option><option value="Gloss Paper Permanent">Gloss Paper Permanent</option><option value="Gloss Paper Removable">Gloss Paper Removable</option><option value="Fluoro Yellow Permanent">Fluoro Yellow Permanent</option><option value="Fluoro Orange Permanent">Fluoro Orange Permanent</option><option value="Fluoro Green Permanent">Fluoro Green Permanent</option><option value="Fluoro Pink Permanent">Fluoro Pink Permanent</option><option value="Fluoro Red Permanent">Fluoro Red Permanent</option><option value="Polylaser Clear Permanent">Polylaser Clear Permanent</option><option value="Datapol White Matt Permanent">Datapol White Matt Permanent</option></select>';
  } 

 }
}


function quoteChanged() 
{ 
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("qqbody").innerHTML=xmlHttp.responseText+"<br><br><a href='printerfriend.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;
}


