
//Global Variables
var menuitem = "FALSE";	//If true then fold out menu wont work
var lastmenu = "";		//Specifies which menu opened last so that it can't open again (stops flickering)
var req;				//This is for fetching documents as part of the SendQuery function
function pviiClassNew(obj, new_style) { //v2.7 by PVII
  obj.className=new_style;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

if ((navigator.appVersion.substring(0,1) == "5" && navigator.userAgent.indexOf('Gecko') != -1) || navigator.userAgent.search(/Opera/) != -1) {
   document.write('<META HTTP-EQUIV="pragma" CONTENT="no-cache">');
}


function sendIt(form)
{

	if(form.id == "country")
	{
		var myindex=form.country.selectedIndex;
		if ((form != "") && ((form.country.options[myindex].text)!=""))
		{
			document.location.href="/dynamic/main.cgi?myaction=changecountry&country="+(form.country.options[myindex].text);
		}
	}


	if(form.id == "callbacklogin")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callmelogin&regusername="+(form.regusername.value)+"&whatpage="+(form.whatpage.value)+"&whataction="+(form.whataction.value);
	}
	
	if(form.id == "showregister")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callmelogin&regusername="+(form.regusername.value)+"&whatshow="+(form.whatshow.value)+"&whataction="+(form.whataction.value);
	}
	
	if(form.id == "submitquote")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callmelogin&regusername="+(form.regusername.value)+"&sessionid="+(form.sessionid.value)+"&whataction="+(form.whataction.value)+"&sessionid="+(form.sessionid.value);
	}
	
	if(form.id == "viewquote")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=viewquote&whichquote="+(form.quoteref.value);
	}
	
	if(form.id == "download")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callmelogin&whatdownload="+(form.whatdownload.value)+"&regusername="+(form.regusername.value)+"&whataction="+(form.whataction.value);
	}
	
	if(form.id == "lximate")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callmelogin&whataction="+(form.whataction.value)+"&regusername="+(form.regusername.value);
	}
	
	if(form.id == "changewikis")
	{

		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?"+(form.frompage.value)+"&setwiki="+(form.setwiki.value)+"&editwiki="+(form.editwiki.value);
	}
	
	if(form.id == "callbackregistration")
	{
		
		if(
		   form.email1.value != "" &&
		   form.firstname.value != "" &&
		   form.lastname.value != "" &&
		   form.company.value != "" &&
		   form.address1.value != "" &&
		   form.address2.value != "" &&
		   form.town.value != "" &&
		   form.city.value != "" &&
		   form.region.value != "" &&
		   form.postcode.value != "" &&
		   form.country.value != "" &&
		   form.phone1.value != ""
		   )
		{
		var formstring;
		formstring = "http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callbacksub"
		formstring = formstring+"&whatpage="+form.whatpage.value;
		formstring = formstring+"&whatshow="+form.whatshow.value;
		formstring = formstring+"&whatdownload="+form.whatdownload.value;
		formstring = formstring+"&username="+form.email1.value;
		formstring = formstring+"&title="+form.title.value;
		formstring = formstring+"&firstname="+form.firstname.value;
		formstring = formstring+"&lastname="+form.lastname.value;
		formstring = formstring+"&company="+form.company.value;
		formstring = formstring+"&jobtitle="+form.jobtitle.value;
		formstring = formstring+"&address1="+form.address1.value;
		formstring = formstring+"&address2="+form.address2.value;
		formstring = formstring+"&town="+form.town.value;
		formstring = formstring+"&city="+form.city.value;
		formstring = formstring+"&region="+form.region.value;
		formstring = formstring+"&postcode="+form.postcode.value;
		formstring = formstring+"&country="+form.country.value;
		formstring = formstring+"&phone1="+form.phone1.value;
		formstring = formstring+"&email1="+form.email1.value;
		formstring = formstring+"&language="+form.language.value;
		formstring = formstring+"&website="+form.website.value;
		formstring = formstring+"&sessionid="+form.sessionid.value;
		document.location.href=formstring;
		}else{
		ShowDiv('fieldrequired');	
		}
	}
	
	if(form.id == "callmedetails")
	{
		//	alert(form.message.value);
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=callmesend&userid="+(form.userid.value)+"&whatpage="+(form.whatpage.value)+"&requesttype="+(form.requesttype.value)+"&requestdetail="+(form.requestdetail.value)+"&usetel="+(form.usetel.value)+"&usemail="+(form.usemail.value);
	}
}


function checksave(form)
{
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=detailschecked&save=yes&whataction="+(form.whataction.value)+"&settingone="+(form.settingone.value)+"&settingtwo="+(form.settingtwo.value)+"&telephone="+(form.telephone.value)+"&email="+(form.email.value)+"&sessionid="+(form.sessionid.value);
}

function checknosave(form)
{
		document.location.href="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=detailschecked&save=no&whataction="+(form.whataction.value)+"&settingone="+(form.settingone.value)+"&settingtwo="+(form.settingtwo.value)+"&telephone="+(form.telephone.value)+"&email="+(form.email.value)+"&sessionid="+(form.sessionid.value);
}

function Initialize() //Initialize Http Request (Page fetching)
{
try
{
req=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
    req=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
    req=null;
}
}

if(!req&&typeof XMLHttpRequest!="undefined")
{
req= new
XMLHttpRequest();

}

}


function SendQuery(key) // Sets up Page fetching
{

if (key=="")
{
HideDiv("autocomplete");
}
    Initialize();
    var url=key;
	//var url="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=dev4";
    if(req!=null)
    {
        req.onreadystatechange = Process;
        req.open("GET", url, true);
        req.send(null);
    }
}

function Process() //Fetches Page and inserts into document
{

    if (req.readyState == 4)
        {
        // only if "OK"
          if (req.status == 200)
            {

                if(req.responseText=="")
                    HideDiv("autocomplete");
                else
                {
					
                    ShowDiv("autocomplete");
					
					//alert(req.responseText.length);
					var tmpvar;
					tmpvar = req.responseText;
                    document.getElementById("autocomplete").innerHTML = tmpvar;
					
                }
            }
            else
            {
                document.getElementById("autocomplete").innerHTML="There was a problem retrieving data:<br>"+req.statusText;
            }
        }
}

function SendQuery2(product)
{

if (product=="")
{
HideDiv("mainsection");
}
    Initialize();
    var url="http://www.pickeringswitch.com/dynamic/dev.cgi?product="+product;
	//var url="http://www.pickeringswitch.com/dynamic/main.cgi?myaction=dev";

  if(req!=null)
    {
        req.onreadystatechange = Process2;
        req.open("GET", url, true);
        req.send(null);
    }
}



function Process2()
{
    if (req.readyState == 4)
        {
        // only if "OK"
            if (req.status == 200)
            {
//              alert(req.responsetext);
                if(req.responseText=="")
                    HideDiv("mainsection");
                else
                {
                    ShowDiv("mainsection");
                    document.getElementById("mainsection").innerHTML = req.responseText;
                }
            }
            else
            {
                document.getElementById("mainsection").innerHTML="There was a problem retrieving data:<br>"+req.statusText;
            }
        }
}



function ShowDiv(divid) //Show any given 'DIV'
{	
   if (document.layers) document.layers[divid].visibility="show";
   else document.getElementById(divid).style.visibility="visible";
}

function HideDiv(divid)	// Hides any given 'DIV'
{
   if (document.layers) document.layers[divid].visibility="hide";
   else document.getElementById(divid).style.visibility="hidden";
}

function ShowHideDiv(divid)
{
	if (document.layers)
	{
		if(document.layers[divid].visibility == "show")
		{
			document.layers[divid].visibility="hide";
		}else{
			document.layers[divid].visibility="show";
		}
	}else{
		if(	document.getElementById(divid).style.visibility == "visible")
		{
			document.getElementById(divid).style.visibility="hidden";
		}else{
			document.getElementById(divid).style.visibility="visible";
		}
	}
}

function BodyLoad()		// Sets up the dynamic search by hiding DIVs
{
    HideDiv("autocomplete");
	HideDiv("mainsection");
    document.form1.keyword.focus();
    //sendquery("main");
}

function insertdiv(divid)	// This is for the menu.
{
if(menuitem=="FALSE")
{
	tempvar = 0;
	menuitem="TRUE"
	//graddivclose(lastmenuitem);
	//lastmenuitem=divid;
	delay=100;	
	
if(divid=='menu1' && lastmenu!='menu1')
{
	
	lastmenu='menu1';
//	menuitem=="TRUE"
	tempvar++;
	document.getElementById('menu2').innerHTML = "";
	document.getElementById('menu3').innerHTML = "";
	document.getElementById('menu4').innerHTML = "";
	document.getElementById('menu5').innerHTML = "";
	document.getElementById('menu6').innerHTML = "";
	
	astring1="<div class='submenubox'><a href='main.cgi?myaction=parse;hgt=1831;file=PXI%20New%20Products.html'><font color='#000000'>&nbsp;&nbsp;&nbsp;PXI New Products</font></a></div>";
	astring2=astring1+"<div class='submenubox'><a href='main.cgi?myaction=pxiinst'><font color='#000000'>&nbsp;&nbsp;&nbsp;PXI Instruments</font></a></div>";
	astring3=astring2+"<div class='submenubox'><a href='main.cgi?myaction=pxi'><font color='#000000'>&nbsp;&nbsp;&nbsp;PXI Switch Modules</font></a></div>";
	astring4=astring3+"<div class='submenubox'><a href='main.cgi?myaction=pxichas'><font color='#000000'>&nbsp;&nbsp;&nbsp;PXI Chassis</font></a></div>";
	astring5=astring4+"<div class='submenubox'><a href='main.cgi?myaction=pxicables' ><font color='#000000'>&nbsp;&nbsp;&nbsp;PXI Cables</font></a></div>";
	
	string1="document.getElementById('menu1').innerHTML = \""+ astring1 +"\";setTimeout(string2,delay);";
	string2="document.getElementById('menu1').innerHTML = \""+ astring2 +"\";setTimeout(string3,delay);";
	string3="document.getElementById('menu1').innerHTML = \""+ astring3 +"\";setTimeout(string4,delay);";
	string4="document.getElementById('menu1').innerHTML = \""+ astring4 +"\";setTimeout(string5,delay);";
	string5="document.getElementById('menu1').innerHTML = \""+ astring5 +"\";menuitem=\"FALSE\";";

	setTimeout(string1,delay);
}

if(divid=='menu2' && lastmenu!='menu2')
{
	lastmenu='menu2';
//	menuitem=="TRUE"
	tempvar++;
	document.getElementById('menu1').innerHTML = "";
	document.getElementById('menu3').innerHTML = "";
	document.getElementById('menu4').innerHTML = "";
	document.getElementById('menu5').innerHTML = "";
	document.getElementById('menu6').innerHTML = "";
	
	astring1="<div class='submenubox'><a href='main.cgi?myaction=lxi' ><font color='#000000'>&nbsp;&nbsp;&nbsp;LXI Test</font></a></div>";
	astring2=astring1+"<div class='submenubox'><a href='main.cgi?myaction=pci' ><font color='#000000'>&nbsp;&nbsp;&nbsp;PCI Switch</font></a></div>";
	astring3=astring2+"<div class='submenubox'><a href='main.cgi?myaction=gpib' ><font color='#000000'>&nbsp;&nbsp;&nbsp;IEEE-488 Systems</font></a></div>";
	astring4=astring3+"<div class='submenubox'><a href='main.cgi?myaction=vxi' ><font color='#000000'>&nbsp;&nbsp;&nbsp;VXI Switch</font></a></div>";
	
	string1="document.getElementById('menu2').innerHTML = \""+ astring1 +"\";setTimeout(string2,delay);";
	string2="document.getElementById('menu2').innerHTML = \""+ astring2 +"\";setTimeout(string3,delay);";
	string3="document.getElementById('menu2').innerHTML = \""+ astring3 +"\";setTimeout(string4,delay);";
	string4="document.getElementById('menu2').innerHTML = \""+ astring4 +"\";menuitem=\"FALSE\";";
	
	setTimeout(string1,delay);
}

if(divid=='menu3' && lastmenu!='menu3')
{
	lastmenu='menu3';
//	menuitem=="TRUE"
	tempvar++;
	document.getElementById('menu1').innerHTML = "";
	document.getElementById('menu2').innerHTML = "";
	document.getElementById('menu4').innerHTML = "";
	document.getElementById('menu5').innerHTML = "";
	document.getElementById('menu6').innerHTML = "";
	
	astring1="<div class='submenubox'><a href='main.cgi?myaction=automotive' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Automotive Test</font></a></div>";
	astring2=astring1+"<div class='submenubox'><a href='main.cgi?myaction=radio' ><font color='#000000'>&nbsp;&nbsp;&nbsp;RF & Microwave</font></a></div>";
	astring3=astring2+"<div class='submenubox'><a href='main.cgi?myaction=optical' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Optical Test</font></a></div>";
	
	string1="document.getElementById('menu3').innerHTML = \""+ astring1 +"\";setTimeout(string2,delay);";
	string2="document.getElementById('menu3').innerHTML = \""+ astring2 +"\";setTimeout(string3,delay);";
	string3="document.getElementById('menu3').innerHTML = \""+ astring3 +"\";menuitem=\"FALSE\";";

	setTimeout(string1,delay);
}


if(divid=='menu4' && lastmenu!='menu4')
{
	lastmenu='menu4';
//	menuitem=="TRUE"
	tempvar++;
	document.getElementById('menu1').innerHTML = "";
	document.getElementById('menu2').innerHTML = "";
	document.getElementById('menu3').innerHTML = "";
	document.getElementById('menu5').innerHTML = "";
	document.getElementById('menu6').innerHTML = "";
	
	astring1="<div class='submenubox'><a href='main.cgi?myaction=cables' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Cables</font></a></div>";
	astring2=astring1+"<div class='submenubox'><a href='main.cgi?myaction=relays' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Reed Relays</font></a></div>";
	astring3=astring2+"<div class='submenubox'><a href='main.cgi?myaction=modules' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Modules</font></a></div>";
	astring4=astring3+"<div class='submenubox'><a href='main.cgi?myaction=spares' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Service Parts</font></a></div>";
	
	string1="document.getElementById('menu4').innerHTML = \""+ astring1 +"\";setTimeout(string2,delay);";
	string2="document.getElementById('menu4').innerHTML = \""+ astring2 +"\";setTimeout(string3,delay);";
	string3="document.getElementById('menu4').innerHTML = \""+ astring3 +"\";setTimeout(string4,delay);";
	string4="document.getElementById('menu4').innerHTML = \""+ astring4 +"\";menuitem=\"FALSE\";";
	
	setTimeout(string1,delay);
}


if(divid=='menu5' && lastmenu!='menu5')
{
	lastmenu='menu5';
//	menuitem=="TRUE"
	tempvar++;
	document.getElementById('menu1').innerHTML = "";
	document.getElementById('menu2').innerHTML = "";
	document.getElementById('menu3').innerHTML = "";
	document.getElementById('menu4').innerHTML = "";
	document.getElementById('menu6').innerHTML = "";
	
	astring1="<div class='submenubox'><a href='main.cgi?myaction=catalog'><font color='#000000'>&nbsp;&nbsp;&nbsp;Catalogs</font></a></div>";
	astring2=astring1+"<div class='submenubox'><a href='main.cgi?myaction=advancedsearch' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Search</font></a></div>";
	astring3=astring2+"<div class='submenubox'><a href='main.cgi?myaction=drivers' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Software Download</font></a></div>";
	astring4=astring3+"<div class='submenubox'><a href='main.cgi?myaction=appnotes'><font color='#000000'>&nbsp;&nbsp;&nbsp;Application Notes</font></a></div>";
	astring5=astring4+"<div class='submenubox'><a href='main.cgi?myaction=supportforum' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Forum</font></a></div>";
	astring6=astring5+"<div class='submenubox'><a href='main.cgi?myaction=viewdocs' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Documentation</font></a></div>";
	
	string1="document.getElementById('menu5').innerHTML = \""+ astring1 +"\";setTimeout(string2,delay);";
	string2="document.getElementById('menu5').innerHTML = \""+ astring2 +"\";setTimeout(string3,delay);";
	string3="document.getElementById('menu5').innerHTML = \""+ astring3 +"\";setTimeout(string4,delay);";
	string4="document.getElementById('menu5').innerHTML = \""+ astring4 +"\";setTimeout(string5,delay);";
	string5="document.getElementById('menu5').innerHTML = \""+ astring5 +"\";setTimeout(string6,delay);";
	string6="document.getElementById('menu5').innerHTML = \""+ astring6 +"\";menuitem=\"FALSE\";";
		
	setTimeout(string1,delay);
}


if(divid=='menu6' && lastmenu!='menu6')
{
	lastmenu='menu6';
//	menuitem=="TRUE"
	tempvar++;
	document.getElementById('menu1').innerHTML = "";
	document.getElementById('menu2').innerHTML = "";
	document.getElementById('menu3').innerHTML = "";
	document.getElementById('menu4').innerHTML = "";
	document.getElementById('menu5').innerHTML = "";
	
	astring1="<div class='submenubox'><a href='main.cgi?myaction=request' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Email</font></a></div>";
	astring2=astring1+"<div class='submenubox'><a href='main.cgi?myaction=showexhibit' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Exhibitions</font></a></div>";
	astring3=astring2+"<div class='submenubox'><a href='main.cgi?myaction=presentations' ><font color='#000000'>&nbsp;&nbsp;&nbsp;Presentations</font></a></div>";
	
	string1="document.getElementById('menu6').innerHTML = \""+ astring1 +"\";setTimeout(string2,delay);";
	string2="document.getElementById('menu6').innerHTML = \""+ astring2 +"\";setTimeout(string3,delay);";
	string3="document.getElementById('menu6').innerHTML = \""+ astring3 +"\";menuitem=\"FALSE\";";

	setTimeout(string1,delay);
}

	
	//document.getElementById(divid).innerHTML = htmlcontent;
		
	//ShowDiv(divid);
	if(tempvar >= 1)
	{
	menuitm="TRUE";	
	}else{
	menuitem="FALSE";
	}
}
}


function catcvsfiles(filename)
{
	
	input_box=confirm("Click Ok to continue with generating catalogue this could take several hours! \n You may close the browser if you wish.\n The Catalogue will be availiable at: \n http://www.pickeringswitch.com/pdf/catalogue/"+filename+"\n ");
	if (input_box==true)	
	{ 
	// Output when OK is clicked
	document.location.href="/dynamic/main.cgi?myaction=cvsfiles2&build=true&filename="+filename;
	}else
	{
	// Output when Cancel is clicked
	
	}
		
	
}

function removecvs(filename)
{
	document.location.href="/dynamic/main.cgi?myaction=cvsfiles&remove="+filename;
}

function addcvs(filename)
{
	document.location.href="/dynamic/main.cgi?myaction=cvsfiles&add="+filename;
}

function testsplit(form)
{
	var tmpvar;
	tmpvar = form.testloc.value;
	tmpvar = tmpvar+"<br>";
	tmpvar = tmpvar+"Hi Test!";
    document.getElementById("testsplit").innerHTML = tmpvar;	
}

function demobody(whattext)
{
	document.getElementById('demobody').innerHTML = whattext;	
}