var xmlHttp;
var preselectOC="";
var preselectDoctype="";
var preselectModel="";

function setWidgetHeight3Up()
{
	// do nothing in tier2
}

function DocSignIn()
{
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
 	{
  		alert ("Your browser does not support AJAX!");
  		return;
	} 

	var url="getocs.asp";
	url=url+"?sid="+Math.random();
	url=url+"&pwd="+document.signinform.password.value;
	xmlHttp.onreadystatechange=stateChangedDocSignIn;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	return false;
} 

function showOCs()
{
	loadingMessage();
	loadingOCs();

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
 	{
  		alert ("Your browser does not support AJAX!");
  		return;
	} 

	var url="getocs.asp";
	url=url+"?sid="+Math.random();
	if (preselectOC!="")
	{
		url=url+"&preselectOC="+preselectOC;
	}
	xmlHttp.onreadystatechange=stateChangedOCs;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

	resetDoctypes();
	resetProducts();
	resetResults();
} 

function showDoctypes(poc)
{
	loadingMessage();

	resetDoctypes();
	resetProducts();

	if (poc!="")
	{
		loadingDoctypes();
		
		section = document.productdownloads.section.value;
		category = document.productdownloads.category.value;

		xmlHttp=GetXmlHttpObject();

		if (xmlHttp==null)
	 	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
		} 

		var url="getocs.asp";
		url=url+"?sid="+Math.random();
		url=url+"&poc="+poc;
		if (preselectDoctype!="")
		{
			url=url+"&preselectDoctype="+preselectDoctype;
		}
		if (section!="")
		{
			url=url+"&section="+section;
		}
		if (category!="")
		{
			url=url+"&category="+category;
		}

		xmlHttp.onreadystatechange=stateChangedDoctypes;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}

	resetResults();
} 

function showProducts(doctype)
{
	loadingMessage();

	resetProducts();

	if (doctype!="")
	{
		loadingProducts();
		
		poc = document.productdownloads.poc.value;
		category = document.productdownloads.category.value;

		xmlHttp=GetXmlHttpObject();

		if (xmlHttp==null)
	 	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
		} 

		var url="getocs.asp";
		url=url+"?sid="+Math.random();
		url=url+"&poc="+poc;
		url=url+"&pdoc="+doctype;

		if (category!="")
		{
			url=url+"&category="+category;
		}

		xmlHttp.onreadystatechange=stateChangedProducts;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}

	resetResults();
} 

function showDownloads(product)
{
	if (product=="")
	{
		resetResults();
	}
	else
	{
		loadingDownloads();

		poc  = document.productdownloads.poc.value;
		pdoc = document.productdownloads.pdoc.value;
		category = document.productdownloads.category.value;

		xmlHttp=GetXmlHttpObject();

		if (xmlHttp==null)
	 	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
		} 

		var url="getocs.asp";
		url=url+"?sid="+Math.random();
		url=url+"&poc="+poc;
		url=url+"&pdoc="+pdoc;
		url=url+"&product="+product;

		if (category!="")
		{
			url=url+"&category="+category;
		}

//alert(url);

		xmlHttp.onreadystatechange=stateChangedDownloads;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
} 

function showDownload(download)
{
	if (download=="")
	{
		resetResults();
	}
	else
	{
		loadingMessage();

		poc  = document.productdownloads.poc.value;
		pdoc = document.productdownloads.pdoc.value;
		product = document.productdownloads.product.value;
		category = document.productdownloads.category.value;

		xmlHttp=GetXmlHttpObject();

		if (xmlHttp==null)
	 	{
	  		alert ("Your browser does not support AJAX!");
	  		return;
		} 

		var url="getocs.asp";		
		url=url+"?sid="+Math.random();
		url=url+"&poc="+poc;
		url=url+"&cache=off";
		url=url+"&pdoc="+pdoc;
		url=url+"&product="+product;
		url=url+"&download="+escape(download);

		if (category!="")
		{
			url=url+"&category="+category;
		}

		xmlHttp.onreadystatechange=stateChangedDownload;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}


function loadingMessage()
{
	document.getElementById("results").innerHTML="loading...";
}

function resetDoctypes()
{
	document.getElementById("dropdownDoctypes").innerHTML="<select disabled=\"disabled\" class=\"downloads\"/>";
}

function resetProducts()
{
	document.getElementById("dropdownProducts").innerHTML="<select disabled=\"disabled\" class=\"downloads\"/>";
}

function loadingOCs()
{
	document.getElementById("dropdownOCs").innerHTML="<select disabled=\"disabled\" class=\"downloads\"><option>loading...</option></select>";
}

function loadingDoctypes()
{
	document.getElementById("dropdownDoctypes").innerHTML="<select disabled=\"disabled\" class=\"downloads\"><option>loading...</option></select>";
}

function loadingProducts()
{
	document.getElementById("dropdownProducts").innerHTML="<select disabled=\"disabled\" class=\"downloads\"><option>loading...</option></select>";
}

function loadingDownloads()
{
	document.getElementById("dropdownDownloads").innerHTML="<select disabled=\"disabled\" class=\"downloads\"><option>loading...</option></select>";
}


function resetResults()
{
	document.getElementById("results").innerHTML="...";
}

function stateChangedOCs() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("dropdownOCs").innerHTML=xmlHttp.responseText;

		if (preselectOC!="")
		{
			showDoctypes(preselectOC);
			preselectOC="";
		}
	}
}

function stateChangedDoctypes() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("dropdownDoctypes").innerHTML=xmlHttp.responseText;

		if (preselectDoctype!="")
		{
			if (document.productdownloads.pdoc.value!="")
			{
				showProducts(preselectDoctype);
			}
			preselectDoctype="";
		}
	}
}

function stateChangedProducts() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("dropdownProducts").innerHTML=xmlHttp.responseText;

		if (preselectModel!="")
		{
			if (document.productdownloads.product.value!="")
			{
				showDownloads(preselectModel);
			}
			preselectModel="";
		}
	}
}

function stateChangedDownloads() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("dropdownDownloads").innerHTML=xmlHttp.responseText;
	}
}

function stateChangedDownload() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		document.getElementById("results").innerHTML=xmlHttp.responseText;

	}
}



function stateChangedDocSignIn() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		if (xmlHttp.responseText == "true")
		{
			showDownloads(document.productdownloads.product.value);
		}
		else
		{
			alert("invalid password");
			document.signinform.password.value = "";
		}
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
  	{
  		// Firefox, Opera 8.0+, Safari
  		xmlHttp=new XMLHttpRequest();
  	}
	catch (e)
  	{
  		// Internet Explorer
  		try
    	{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    	}
  		catch (e)
    	{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    	}
  	}

	return xmlHttp;
}
