function Querystring(a){
    this.params={};
    
    if(a==null){
        a=location.search.substring(1,location.search.length)
        }
        if(a.length==0){
        return
    }
    a=a.replace(/\+/g," ");
    var c=a.split("&");
    for(var d=0;d<c.length;d++){
        var f=c[d].split("=");
        var b=decodeURIComponent(f[0]);
        var e=(f.length==2)?decodeURIComponent(f[1]):b;
        this.params[b]=e
        }
    }
    Querystring.prototype.get=function(a,b){
    var c=this.params[a];
    return(c!=null)?c:b
    };
    
Querystring.prototype.contains=function(a){
    var b=this.params[a];
    return(b!=null)
    };
    
function movieEnd(){
    document.getElementById("xswfmovie").style.display="none";
    document.getElementById("xswfmovie").style.visibility="hidden";
    document.getElementById("xslideshow").style.display="block"
    }
    function instr(b,a){
    for(i=0;i<Len(b);i++){
        if(a==b.substring(i,1)){
            return i
            }
        }
    return -1
}
function SwapPic(a){
    document.getElementById("sitemap").style.height="0px";
    document.getElementById("sitemap").style.width="0px";
    document.getElementById("sitepic").style.height="273px";
    document.getElementById("sitepic").style.width="400px";
    document.getElementById("sitepic").src=a
    }
    function SwapMap(a){
    document.getElementById("sitemap").style.height="273px";
    document.getElementById("sitemap").style.width="400px";
    document.getElementById("sitepic").style.height="0px";
    document.getElementById("sitepic").style.width="0px";
    switch(a){
        case"tulsa":
            document.getElementById("sitemap").src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=606+n.+145th+east+ave+tulsa&amp;sll=37.0625,-95.677068&amp;sspn=40.409448,75.761719&amp;ie=UTF8&amp;ll=36.174258,-95.81357&amp;spn=0.018915,0.034332&amp;z=14&amp;output=embed"
            }
        }
function PlayMovie(){
    document.getElementById("MovieFrame").style.width="0px";
    document.getElementById("MovieFrame").style.height="0px";
    document.getElementById("IPS-TOP").style.width="320px";
    document.getElementById("IPS-TOP").style.height="213px";
    document.getElementById("IPS-TOP").Play();
    setTimeout("ResetMovie()",65000)
    }
    function ResetMovie(){
    document.getElementById("IPS-TOP").StopPlay();
    document.getElementById("MovieFrame").style.width="320px";
    document.getElementById("MovieFrame").style.height="213px";
    document.getElementById("IPS-TOP").style.width="0px";
    document.getElementById("IPS-TOP").style.height="0px"
    }
    function loadPage(b,a){
    var c=document.getElementById("content");
    if(c!=null){
        resp=getHtml("pages/"+b);
        if(resp!=null){
            c.innerHTML=resp
            }
            if(a!=null){
            document.title=a
            }
        }
}
function getHtml(a){
    var c="";
    var b="";
    if(window.XMLHttpRequest){
        b=new XMLHttpRequest()
        }else{
        if(window.ActiveXObject){
            b=new ActiveXObject("Microsoft.XMLHTTP")
            }
        }
    b.open("GET",a,false);
b.send(null);
if(b.status==200){
    var c=b.responseText
    }
    return c
}
function doPage(a,b){
    document.getElementById(b).innerHTML=getHtml("pages/"+a)
    }
    function doPhoto(a,b){
    document.getElementById(b).src="images/"+a
    }
    function setCookie(b,d){
    var e=new Date();
    var a=(365*24*60*60*1000);
    var c=e.getTime()+(a*2);
    e.setTime(c);
    document.cookie=b+"="+d+"; expires="+e.toGMTString()
    }
    function getResults(){
    var e=document.getElementById("mtr-target");
    if(e!=null){
        e.innerHTML="<i>Searching database, please wait ...</i>";
        var d="http://"+document.location.host+"/pomtr/MtrViewer";
        var b=document.getElementById("sdlonly");
        var a=document.getElementById("ponum");
        if(a!=null&&b!=null){
            d+=safeString("?username=","uid");
            d+=safeString("&userpo=","ponum");
            d+=safeBool("&sdlonly=","sdlonly");
            var c=syncSendHtml(d);
            if(c!=null){
                e.innerHTML=c;
                if(!b.checked&&c.indexOf("Sorry")==-1){
                    setTimeout("window.open('http://"+location.hostname+"/ipsmtr/"+cleanString(a.value)+".pdf','_blank')",500)
                    }
                }
        }
}
}
function cleanString(a){
    stPoFileName=a.replace("/","-");
    if(stPoFileName!=null){
        stPoFileName=stPoFileName.replace(" ","_")
        }
        return escape(stPoFileName)
    }
    function safeString(c,a){
    var b=document.getElementById(a);
    if(b!=null){
        if(b.value!=null){
            return c+b.value
            }
        }
    return""
}
function safeBool(d,b){
    var c=document.getElementById(b);
    if(c!=null){
        var a=c.checked?"on":"off";
        return d+a
        }
        return""
    }
    function SubmitMTRResults(){
    document.location.href="index.html?action=online&sub=mtrs&tc="+document.getElementById("tc").value+"&tp="+document.getElementById("tp").value+"&sdlonly="+((document.getElementById("sdlonly").checked==true)?"on":"off")
    }
    function wait(b){
    var c=new Date().getTime();
    var a=c;
    while(a-c<b){
        a=new Date().getTime()
        }
    }
// jrp 1/17/12 new stuff to keep the end user informed

function getStatus()
{
	if(!complete)
	{
		showStatus();
		setTimeout('getStatus()',500);
	}
}
function getFilename()
{
	var sresp=syncSendHtml("http://www.ipipes.com/pomtr/SessionStatus?id=yes");
	if(sresp != null)
		filename=sresp;
}
function showStatus()
{
	var stgt=document.getElementById("status");
	if(stgt != null)
	{
		alert("not null");
		var sresp=syncSendHtml("http://www.ipipes.com/pomtr/SessionStatus");
		if(sresp != null)
		{
		alert(sresp);
			stgt.innerHTML=sresp;
		}
	}
}
function getMtrData()
{
	var cReturnText;
	var oPO;
	var cTemp;
	var x;
	var y;
	var z;
	var z1;
	var cThisRelease = "ksjdhfiauw4fr78aw367a"
	var a = 0;
	var cCustomerNumber = qs.get("tc");
	var cPONumber = qs.get("tp");
	
	if(cCustomerNumber == null || cPONumber == null)
		return;
	if(cCustomerNumber.length ==0 || cPONumber.length ==0)
		return;
		
	// start mtr retrieval in the background
	asyncSend("http://www.ipipes.com/pomtr/jsonPo?username=" + cCustomerNumber + "&userpo=" + cPONumber + "&sdlonly=" + qs.get("sdlonly") , getMtrCallback);
	complete=false;
	// start looped status update to give the user some feedback
	setTimeout('getStatus()',500);	
}
function getMtrCallback()
{							
	if (areq.readyState == 4)
	{
		if (areq.status == 200)
		{
			complete=true;
			getFilename();
			if (cReturnText != "")
			{
				//document.write( cReturnText );
												
				oPO = JSON.parse(cReturnText);
				//debugger;
				//document.write("oPO");
				
				cTemp = oPO["CustPoNumber"];
												
				if (cTemp != undefined) 
				{
					document.write("<TABLE width=100% style='margin-left:20px;padding-right:20px;'>");
					document.write("	<TR>");
					document.write("		<TD width=50%>Purchase Order #: " + cTemp + "</TD>");
					document.write("		<TD width=46% align=right>Click <a href=http://mtr.ipipes.com/ipsmtr/" + filename + ".pdf target=_blank><font color=red>here</font></a> for MTRs&nbsp;</TD width=*>");
					document.write("		<TD>&nbsp;</TD>");
					document.write("	</TR>");
					document.write("</TABLE>");
														
					setTimeout("window.open('http://mtr.ipipes.com/ipsmtr/" + filename + ".pdf','_blank')",500);
				}
																	
				document.write("<TABLE width=96% align=center cellpadding=4 cellspacing=0 border=1 class=thinsilverline  bgcolor=white style='font-family:arial;font-size:10pt;margin-left:20px;margin-right:20px;'>");
				document.write("	<TR bgcolor='#F4F3E3' style='font-weight:bold;'>");
				document.write("		<TD>Release#</TD>");
				document.write("		<TD>Mfg Code</TD>");
				document.write("		<TD>Product Code</TD>");
				document.write("		<TD>Description</TD>");
				document.write("		<TD>Heat Code</TD>");
				document.write("	</TR>");
				var rowCount=0;
				// jrp This was re-worked on 5/24/2011. If there were no MTRs it didn't print any SDTs
				//  also it was only showing mtrs not the products on the line item
				for (x in oPO.Orders) 
				{
					for (y in oPO.Orders[x].Releases)
					{
						document.write("<TR>");
						rowCount=0;
						if (oPO.Orders[x].Releases[y].ReleaseKey == cThisRelease)
						document.write("<TD bgcolor='#F4F3E3' id='aa'>&nbsp</TD>");
						else
						{
						if (oPO.Orders[x].Releases[y].SdtKey != null )
							document.write("<TD bgcolor='#F4F3E3' id='ab'><a href=http://www.ipipes.com/pomtr/sdtDoc?pl=" + oPO.Orders[x].Releases[y].SdtKey + " target=_blank>" + oPO.Orders[x].Releases[y].ReleaseKey.substring(3,oPO.Orders[x].Releases[y].ReleaseKey.length) + "</a></TD>");
						else
							document.write("<TD bgcolor='#F4F3E3' id='ac'>" + oPO.Orders[x].Releases[y].ReleaseKey.substring(3,oPO.Orders[x].Releases[y].ReleaseKey.length) + "</TD>");
						}
						cThisRelease = oPO.Orders[x].Releases[y].ReleaseKey;
						for (z in oPO.Orders[x].Releases[y].Lineitems )
						{
							if(oPO.Orders[x].Releases[y].Lineitems[z].Mtrs.length > 0)
							{
								for (z1 in oPO.Orders[x].Releases[y].Lineitems[z].Mtrs )
								{
								if(rowCount > 0)
									document.write("<tr><TD bgcolor='#F4F3E3' id='ba'>&nbsp</TD>");
								document.write("<TD>" + oPO.Orders[x].Releases[y].Lineitems[z].Mtrs[z1].Mfg + "</TD>");
								document.write("<TD>" + oPO.Orders[x].Releases[y].Lineitems[z].Mtrs[z1].Prod + "</TD>");
								document.write("<TD>" + oPO.Orders[x].Releases[y].Lineitems[z].DescLineOne + "</TD>");
								document.write("<TD>" + oPO.Orders[x].Releases[y].Lineitems[z].Mtrs[z1].Heat + "</TD>");
								if(rowCount > 0)
									document.write("</tr>");
								a = 1;
								rowCount++;
								}
							}
							else
							{
								var prodNum=oPO.Orders[x].Releases[y].Lineitems[z].StProdNum;
								var shipQty=oPO.Orders[x].Releases[y].Lineitems[z].ShipQty;
								if(prodNum != "C" && prodNum != "CN" && prodNum != "CP" && prodNum!= "FREIGHT" && shipQty != "0" && shipQty != "")
								{
								if(rowCount > 0)
									document.write("<tr><TD bgcolor='#F4F3E3' id='ba'>&nbsp</TD>");
								document.write("<TD>&nbsp;</TD>");
								document.write("<TD>" + prodNum + "</TD>");
								document.write("<TD>" + oPO.Orders[x].Releases[y].Lineitems[z].DescLineOne + "</TD>");
								document.write("<TD>&nbsp;</TD>");
								if(rowCount > 0)
									document.write("</tr>");
								rowCount++;
								}
							}
						}
						if(rowCount == 0)
						{
							document.write("</TR>");
							rowCount++;
						}
					}
				}
				document.write("</TABLE><br><br><br>&nbsp;");
			}
		}
	}
}

function SubmitEmail(){
    if(document.getElementById("txt_Name").value.indexOf("<")>-1||document.getElementById("txt_Company").value.indexOf("<")>-1||document.getElementById("txt_Address_1").value.indexOf("<")>-1||document.getElementById("txt_City").value.indexOf("<")>-1||document.getElementById("txt_State").value.indexOf("<")>-1||document.getElementById("txt_Zip").value.indexOf("<")>-1||document.getElementById("txt_Phone").value.indexOf("<")>-1||document.getElementById("txt_EMail").value.indexOf("<")>-1||document.getElementById("txt_Body").value.indexOf("<")>-1){
        alert("Avast!  Ye cannot enter either ''<'' or ''>'' up in here!");
        return false
        }
        if(document.getElementById("txt_spamcheck").value.toLowerCase()!="red"&&document.getElementById("txt_spamcheck").value.toLowerCase()!='"red"'){
        document.getElementById("txt_spamcheck").style.background="red";
        alert("Please enter the Spam Check-Word");
        return false
        }else{
        document.getElementById("txt_spamcheck").style.background="white"
        }
        if(document.getElementById("txt_Body").value.length<=1){
        alert("You at least need to enter a comment or question before the form can be sent.");
        return false
        }
        var a="";
    a="<BR><HTML><BODY style='font-family:cabali, arial, tahoma;font-size:10pt;'><TABLE width='100%' cellpadding=4 cellspacing=0 border=1 style='font-family:cabali, arial, tahoma;font-size:10pt;'><TR><TD colspan=2 bgcolor=#E4EDF1><font size=4>IPS Website Inquiry</font></TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>Name:     </TD><TD width=*>"+document.getElementById("txt_Name").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>Company:  </TD><TD width=*>"+document.getElementById("txt_Company").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>Address1: </TD><TD width=*>"+document.getElementById("txt_Address_1").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>City:     </TD><TD width=*>"+document.getElementById("txt_City").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>State:    </TD><TD width=*>"+document.getElementById("txt_State").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>Zip:      </TD><TD width=*>"+document.getElementById("txt_Zip").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>Phone:    </TD><TD width=*>"+document.getElementById("txt_Phone").value+" </TD></TR><TR><TD width=120 align=right bgcolor=#E4EDF1><b>eMail:    </TD><TD width=*>"+document.getElementById("txt_EMail").value+" </TD></TR></TABLE><br><br>"+document.getElementById("txt_Body").value+"</TABLE></BODY></HTML>";
    postEMail("ips@ipipes.com","no-reply@ipipes.com","IPS Website Inquiry",a);
    postEMail("tech@ipipes.com","no-reply@ipipes.com","IPS Website Inquiry",a);
    if(document.getElementById("txt_EMail").value!=""){
        postEMail(document.getElementById("txt_EMail").value,"no-reply@ipipes.com","Confirmation of Your IPS Website Inquiry",a)
        }
        window.location="http://www.ipipes.com/index.html?action=about&sub=contact";
    alert("Your message has been sent.  Thank you for contacting IPS.")
    }
    function postEMail(a,d,f,e){
    var c=new XMLHttpRequest();
    var b="http://www.ipipes.com/gcMailer/drop";
    var g="t="+escape(a)+"&f="+escape(d)+"&s="+escape(f)+"&h="+escape(e);
    c.open("POST",b,false);
    c.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    c.setRequestHeader("Content-length",g.length);
    c.setRequestHeader("Connection","close");
    c.send(g)
    };

