function createReq(){
	try	{	return new ActiveXObject("msxml2.XMLHTTP");	}	catch (e)	{	}
	try	{	return new ActiveXObject("Microsoft.XMLHTTP");	}	catch (e)	{	}
	try	{	return new XMLHttpRequest();	}	catch (e)	{	}
	alert("Not supported!");
	return null;
}

function LoadPrinter(brand){
	document.getElementById('sel_printers').innerHTML = "<select name=printers id=printers><option>Loading, please wait...</option></select>";
	var xml = createReq();
	xml.open("GET","selector.aspx?mode=code&brands="+brand, false);
	xml.send(null);
	var resptext = xml.responseText;
	if(resptext.indexOf("<option")<=0)
	    resptext = "Sorry, Internal Server Error";
	document.getElementById('sel_printers').innerHTML = resptext;
	xml = null;
}

function LoadCartridges(brand){
	document.getElementById('selcartridges').innerHTML = "<select name=cartridges id=cartridges><option>Loading, please wait...</option></select>";

	var xml = createReq();
    if(brand=='hewlettpackard') brand='hp';
	xml.open("GET","selector.aspx?mode=cart&brands="+brand, false);
	xml.send(null);
	var resptext = xml.responseText;
	if(resptext.indexOf("<option")<=0)
	    resptext = "Sorry, Internal Server Error";
    document.getElementById('selcartridges').innerHTML = resptext;
	xml = null;
	
}
function onChangeBrands_1(){
	if(document.formtop.selcartbrand.value==""){
		document.formtop.cartridges.disabled=true;
		document.formtop.submit_cart.disabled=true;
		
	}else{
		LoadCartridges(document.formtop.selcartbrand.value);
		document.formtop.cartridges.disabled=false;
		//onChangePrinters();
	}
}
function onChangeBrands_2(){
	if(document.formtop.selprinterbrand.value==""){
		document.formtop.printers.disabled=true;
		document.formtop.submit_printer.disabled=true;
	}else{
		LoadPrinter(document.formtop.selprinterbrand.value);
		document.formtop.printers.disabled=false;
		//onChangePrinters();
	}
}
function onChangePrinters(){
	if(document.formtop.printers.value==""){
		document.formtop.submit_printer.disabled=true;
	}else{
		SubmitForm(document.formtop,0);
		document.formtop.submit_printer.disabled=false;
	}
}
function onChangeCartridges(){
	if(document.formtop.cartridges.value==""){
		document.formtop.submit_cart.disabled=true;
	}else{
		SubmitForm(document.formtop,1);
		document.formtop.submit_cart.disabled=false;
	}
}

function SubmitForm(obj,t){
	if((t==1)&&(obj.selcartbrand.value==""))
    {
		window.alert("Choose Your Brand");
		return false;
	}else
	if((t==0)&&(obj.selprinterbrand.value==""))
	{
	    window.alert("Choose Your Brand");
		return false;
    }
	else
	{
      if(t==1){
        if(obj.cartridges.value!="")
        window.location.href=obj.cartridges.value;
      }
      if(t==0){
	    if(obj.printers.value.indexOf(",")>0)
		    	  window.location.href=obj.printers.value;
		    else
			      window.location.href=obj.selprinterbrand.value.toLowerCase().replace(' ','').replace('hewlettpackard','hp')+"-"+obj.printers.value+".html";
     }
	}
}
