function swapPQ(strValue) {
    var tmpStr = strValue.split('|');
    var PQDiv = 'divPQ' + tmpStr[1];
    var PQDisplay = tmpStr[2];

    //alert(PQDiv);

    if (PQDiv != "divPQundefined") {
        //alert(PQDiv);
        document.getElementById(PQDiv).innerHTML = PQDisplay;
    }


}

//Global XMLHTTP Request object
var XmlHttp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Gets called when country combo box selection changes
function YearSelected(ProductID) 
{

	
	var YearList = document.getElementById("ddlYear");

	//Getting the selected country from country combo box.
	var selectedYear = YearList.options[YearList.selectedIndex].value;
	
	// URL to get states for a given country
	var requestUrl = "ajaxGetMakeModelSubModel.aspx" + "?ProductID=" + ProductID + "&Year=" + selectedYear;
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);		
	}
}


//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			//ClearAndSetYearListItems(XmlHttp.responseXML.documentElement);
			ClearAndSetMakeModelSubModelListItems(XmlHttp.responseText );			
		}
		else
		{
			alert("There was a problem retrieving data from the server." );
		}
	}
}

//Clears the contents of state combo box and adds the states of currently selected country
function ClearAndSetMakeModelSubModelListItems(strIn)
{
    var MakeModelSubModelList = document.getElementById("ddlMakeModelSubModel");
	//Clears the state combo box contents.
	for (var count = MakeModelSubModelList.options.length-1; count >-1; count--)
	{
		MakeModelSubModelList.options[count] = null;
	}
	
	
	//var stateNodes = countryNode.getElementsByTagName('state');
	var textValue; 
	var optionItem;
	var maxLength;
	maxLength = 0;
	
	//Add new states list to the state combo box.
	//for (var count = 0; count < stateNodes.length; count++)
	//{
   	//	textValue = GetInnerText(stateNodes[count]);
		optionItem = new Option( textValue, textValue,  false, false);
		
		//optionItem = new Option(strIn, strIn,  false, false);
		//YearList.options[YearList.length] = optionItem;
		
		//document.getElementById("YearArrow").src="images/redarrow.gif";
		//document.getElementById("MakeModelArrow").src="images/spacer.gif";
		MakeModelSubModelList.disabled=false;
		optionItem = new Option('Select model', '',  false, false);
		MakeModelSubModelList.options[MakeModelSubModelList.length] = optionItem;

		var addMakeModelSubModel = strIn.split('|');		
		for(i=0; i!=addMakeModelSubModel.length; i++)
			{
				if(addMakeModelSubModel[i] != '') {
				
					var tmpStr = addMakeModelSubModel[i].split('*/*');					
					var tmpStr2 = tmpStr[3] + ' ' + tmpStr[4] + ' ' + tmpStr[5] + ' ' + tmpStr[6]
					optionItem = new Option(tmpStr2, addMakeModelSubModel[i], false, false);
					MakeModelSubModelList.options[MakeModelSubModelList.length] = optionItem;

										
					if(tmpStr2.length > maxLength) {
						maxLength = tmpStr2.length
					}
					
					//alert(tmpStr2.length + '---' + maxLength);
				
					//optionItem = new Option(addMakeModelSubModel[i], addMakeModelSubModel[i],  false, false);
					//MakeModelSubModelList.options[MakeModelSubModelList.length] = optionItem;
					
					
					}
			}
			
		adjustMakeModelSubmodelStyle(maxLength);
			
	//}
}

function adjustMakeModelSubmodelStyle(numCharacters)
{
	//alert(numCharacters);
	var newSubmodelStyleForIE	= "";
	var selectWidth = numCharacters * 8 + 1;	// 5 pixels/char + 10 extra
	
	// var submitVehicleButton = document.getElementById("submitVehicleImage");
	var ddlList = document.getElementById("ddlMakeModelSubModel");	

	//only set style if greater than 40 characters	
	if (numCharacters > 40 && isIE())
	{
	
		newSubmodelStyleForIE = "style=\"position: absolute; z-index: 100; width: " + selectWidth + "px;\"";
		ddlList.style.marginTop = "2px";
		ddlList.style.position = "absolute";
		ddlList.style.zindex = "100";
		ddlList.style.width = selectWidth + "px";	

		
		var DrillDownSpacer = document.getElementById("DrillDownSpacer");	
		DrillDownSpacer.innerHTML="<img src=/images/spacer.gif height=23 width=1>";
		
	}
	

	
	//alert(newSubmodelStyleForIE);
	//return newSubmodelStyleForIE;
}

function isIE()
{
	var isMac		= (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
	var NS4			= (document.layers) ? true : false;
	var IEmac		= ((document.all) && (isMac)) ? true : false;
	var IE4plus		= (document.all) ? true : false;
	var IE4			= ((document.all) && (navigator.appVersion.indexOf("MSIE 4.") != -1)) ? true : false;
	var IE5			= ((document.all) && (navigator.appVersion.indexOf("MSIE 5.") != -1)) ? true : false;
	var IE6			= ((document.all) && (navigator.appVersion.indexOf("MSIE 6.") != -1)) ? true : false;
	var ver4		= (NS4 || IE4plus) ? true : false;
	var NS6			= (!document.layers) && (navigator.userAgent.indexOf('Netscape') != -1) ? true : false;
	return (IEmac || IE4plus || IE4 || IE5 || IE6) ? true : false;
}

//Returns the node text value 
//function GetInnerText (node)
//{
//	 return (node.textContent || node.innerText || node.text) ;
//}