
function hidediv(id) {
	//safe function to hide an element with a specified id
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

function showdiv(id) {
	//safe function to show an element with a specified id

	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

function stripSpan(str) {

	if (str.indexOf('<span') > -1)
	{
		str = str.substring(str.indexOf('>')+1);
		str = str.substring(0,str.indexOf('<'));	
	}
	return str;
}

function insertOption(element, optionText, optionValue) {

	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

	element.disabled = false;

	if (browser == "Microsoft Internet Explorer" && version < 5){
		element.add(new Option(optionText, optionValue));

		for (var i=element.options.length-1; i > 0; i--){

			element.options[i].text = element.options[i-1].text;
			element.options[i].value = element.options[i-1].value;
		}
		element.options[0].text = optionText;
		element.options[0].value = optionValue;
	}
	else if (element.options.length == 0){
		element.options[0] = new Option(optionText, optionValue);
	}
	else {
		element.add(new Option(optionText, optionValue), element.options[0]);
	}

	element.selectedIndex = 0;
}

function CreateOSList()
{
	var j = 1;
	document.forms[0].type.options.length = 0;
	document.forms[0].type.options[0] = new Option(name_Option2,"");

    for (var i=0;i<operatingSystems.length;i++) {
    	
		if (document.forms[0].productLine.options[document.forms[0].productLine.selectedIndex].value == "tv")
	    {	
	    	//If TV Tuner: remove Windows7, Linux, Mac and Bootcamp OS
	    	if ((operatingSystems[i].value.indexOf("win7") == -1) && (operatingSystems[i].value.indexOf("linux") == -1) && (operatingSystems[i].value.indexOf("mac") == -1) && (operatingSystems[i].value.indexOf("boot") < 0))
	    	{
				document.forms[0].type.options[j] = new Option(operatingSystems[i].name, operatingSystems[i].value);
				j++;
			}
		}
		else if (document.forms[0].productLine.options[document.forms[0].productLine.selectedIndex].value == "chip")
		{
		    //If Chipset: remove Mac and Bootcamp OS
			if ((operatingSystems[i].value.indexOf("mac") == -1) && (operatingSystems[i].value.indexOf("boot") == -1))
	    	{
				document.forms[0].type.options[j] = new Option(operatingSystems[i].name, operatingSystems[i].value);
				j++;
			}
		}
		else 
		{
			document.forms[0].type.options[j] = new Option(operatingSystems[i].name, operatingSystems[i].value);
			j++;
		}
	}
   	

}

function HPprocessTracking()
{
	var str = '';
	var element;
	var tmpAcct = hbx.acct;
	var pathArray = new Array();
	
	pathArray = top.location.pathname.split( '/' );

	element = document.getElementById("productLine");
	if (!element.disabled && !element.selectedIndex == 0)
	{
		str = str + element[element.selectedIndex].value;

		element = document.getElementById("type");
		if (!element.disabled && !element.selectedIndex == 0)
			str = str + '_' + element[element.selectedIndex].value;
		else
			str = str + '_NA';
	
		element = document.getElementById("prodType");
		if (!element.disabled && !element.selectedIndex == 0)
			str = str + '_' + element[element.selectedIndex].value;
		else
			str = str + '_NA';
		
		element = document.getElementById("prod");
		if (!element.disabled && !element.selectedIndex == 0)
			str = str + '_' + element[element.selectedIndex].text;
		else
			str = str + '_NA';
	}
	
	str = str.replace(/series/i, '');
	str = str.replace(/radeon/i, 'rad-');
	str = str.replace(/all-in-wonder/i, 'AIW-');
	str = str.replace(/Crossfire/i, 'xfire-');
	str = str.replace(/Mobility/i, 'mob-');
	str = str.replace(/\s+/g,'');
	str = str.replace(/[^a-zA-Z_ 0-9]+/g,'');
	
	if (str!='')
	{
		str = 'HmPgDriver-' + pathArray[1] + '_' + str;
		if (70 < String(str).length)   // Invalid bound, return
			str = String(str).substring(0,70);
			
		//Set HBX Account information
		_hbSet("hb", "DM590416PMSA28EN3");

		//Process HBX Tracking
		_hbLink(str);
		
		//Reset HBX Account information
		_hbSet("hb", tmpAcct);
	}
}



function HPchangePage()
{

	var searchType;
	
	searchType = document.forms[0].productLine.value;

	if ((searchType == "gpu") || (searchType == "tv") || (searchType == "chip")){

		//Opiont 2 not selected	
		if (document.forms[0].type.options.selectedIndex < 1) {
				alert(name_PleaseSelect + ' ' + name_Option2);
				return false;
		}
		//Opiont 3 not selected		
		else if ((document.forms[0].prodType.options.selectedIndex < 1) && (document.forms[0].prodType.disabled == false)) {
				alert(name_PleaseSelect + ' ' + name_Option3);
				return false;
		}
		//Opiont 4 not selected	
		else if (document.forms[0].prod.options.selectedIndex < 1){
				alert(name_PleaseSelect + ' ' + name_Option4);
				return false;
		}
		else{
			HPprocessTracking();
			document.forms[0].productLine.selectedIndex = 0;
			return changePage();
		}
	}

	else if (searchType  == "cpu"){
		HPprocessTracking();
		document.forms[0].productLine.selectedIndex = 0;
		top.location.href = buildURLprefix() + 'psearch/Pages/psearch.aspx?type=2.1&product=&contentType=Tech%20Download%20Processor';
		return false;
	}

	else if (searchType  == "emb"){
		HPprocessTracking();
		document.forms[0].productLine.selectedIndex = 0;
		top.location.href = buildURLprefix() + 'psearch/Pages/psearch.aspx?type=2.2&product=&contentType=Tech+Download+Embedded&ostype=&keywords=&items=20';
		return false;
	}
	else{
		//Opiont 1 not selected
		alert(name_PleaseSelect + ' ' + name_Option1);
	}
}

function HPpopulateList(elementName)
{
	document.forms[0].type.disabled = false;
	document.forms[0].prodType.disabled = false;
	document.forms[0].prod.disabled = false;

	populateList(elementName);

	if (elementName == 'type')
	{
		document.forms[0].type.options[0].text = name_Option2;
		document.forms[0].type.selectedIndex = 0;
		document.forms[0].prodType.selectedIndex = 0;
		document.forms[0].prod.selectedIndex = 0;

		if ((document.forms[0].productLine.value == "gpu") ||
			(document.forms[0].productLine.value == "tv")  ||
			(document.forms[0].productLine.value == "chip")) {

			CreateOSList();

			document.forms[0].prodType.options.length = 0;
			document.forms[0].prod.options.length = 0;

			document.forms[0].type.disabled = false;

			document.getElementById('driver_submit').className = btn_InactiveClass;
		}
		else {

			document.forms[0].type.options.length = 0;
			document.forms[0].type.options[0] = new Option(short_Option2 + ' - ' + name_NA, '');
			document.forms[0].prodType.options.length = 0;
			document.forms[0].prodType.options[0] = new Option(short_Option3 + ' - ' + name_NA, '');
			document.forms[0].prod.options.length = 0;
			document.forms[0].prod.options[0] = new Option(short_Option4 + ' - ' + name_NA, '');
			document.forms[0].type.disabled = true;

			document.getElementById('driver_submit').className = btn_ActiveClass;
		}

		document.forms[0].prodType.disabled = true;
		document.forms[0].prod.disabled = true;

	}
	else if (elementName == 'os')
	{
		insertOption(document.forms[0].prodType, name_Option3, '')

		document.forms[0].prod.selectedIndex = 0;

		document.forms[0].type.disabled = false;
		document.forms[0].prod.disabled = true;


		if (document.forms[0].productLine.value == "tv"){
		
			document.forms[0].prodType.disabled = false;
			document.forms[0].prodType.options.length = 0;

			insertOption(document.forms[0].prodType, short_Option3 + ' - ' + name_NA, 'tvtuner')

			HPpopulateList('prod');

			document.forms[0].prodType.disabled = true;
		}
		else if (document.forms[0].productLine.value == "chip"){
			document.forms[0].prodType.options.length = 0;
			insertOption(document.forms[0].prodType, short_Option3 + ' - ' + name_NA, 'im')

			HPpopulateList('prod');

			document.forms[0].prodType.disabled = true;
		}

		document.getElementById('driver_submit').className = btn_InactiveClass;

	}
	else if (elementName == 'prod')
	{
		insertOption(document.forms[0].prod, name_Option4, '')

		document.forms[0].type.disabled = false;
		document.forms[0].prodType.disabled = false;

		document.getElementById('driver_submit').className = btn_InactiveClass;
	}

}
