//--------------------------------------------------------------------------
////////////////////// VARIABLES ////////////////////////
//--------------------------------------------------------------------------
var reqList;
var regionList;
var ISVList;
var IndustryList;
var HorizontalList;
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function trimStr(inputString)
 {
 
	if (typeof inputString != "string")	return inputString;
	
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	
	retValue = retValue.replace("&amp;", "&")
	
	while (ch == " ") 
	{ 
	
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
	  
	}
	
	ch = retValue.substring(retValue.length-1, retValue.length);
	
	while (ch == " ") 
	{
	
	  retValue = retValue.substring(0, retValue.length-1);
	  ch = retValue.substring(retValue.length-1, retValue.length);
	  
	}
	
	while (retValue.indexOf("  ") != -1)
	{ 
	
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length);
	
	}
	
	return retValue;
	
} 
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function textItem(txtId,valueId)
{

	var txt = document.getElementById(txtId);

	txt.value = valueId;

}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function checkedItem(checkId,valueId)
{

	var check = document.getElementById(checkId);

	if(check.value == valueId)	check.checked = true;

}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function mapViewDefaultValues()
{

	var elem = document.getElementById("Industry");
	elem.selectedIndex = 0;

	elem = document.getElementById("Horizontal");
	elem.selectedIndex = 0;
	
}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function listViewDefaultValues()
{

	var elem = document.getElementById("region");
	elem.selectedIndex = 0;

	elem = document.getElementById("ISV_LIST");
	elem.selectedIndex = 0;

	elem = document.getElementById("ISV");
	elem.value = "Type Partner Name";

	elem = document.getElementById("validated");
	elem.checked = false;
	
}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function selectedItemList(listId,valueId)
{

	var sel = document.getElementById(listId);

	for(i = 0; i < sel.length; i++)
	{
	
		if(sel.options[i].value == valueId)
		{
		
			sel.selectedIndex = i;
			break;
		
		}
	
	}
	
}
//--------------------------------------------------------------------------
////////////////////// FUNCTION ////////////////////////
//--------------------------------------------------------------------------
function getParameter ( queryString, parameterName )
{   
	// Add "=" to the parameter name (i.e. parameterName=value)
	var parameterName = parameterName + "=";

	if ( queryString.length > 0 )
	{
		// Find the beginning of the string
		begin = queryString.indexOf ( parameterName );      
		// If the parameter name is not found, skip it, otherwise return the value
		if ( begin != -1 ) 
		{         
		
			// Add the length (integer) to the beginning
			begin += parameterName.length;         
			// Multiple parameters are separated by the "&" sign         
			end = queryString.indexOf ( "&" , begin );
			if ( end == -1 ) end = queryString.length; 
			// Return the string      
			return unescape ( queryString.substring ( begin, end ) );   
		
		}   
		
		// Return "null" if no parameter has been found   
		return "null";   

	}

}
//--------------------------------------------------------------------------
////////////////////// FUNCTION ////////////////////////
//--------------------------------------------------------------------------
function resetSelect(idElement)
{

	var sel = document.getElementById(idElement);
	sel.selectedIndex = 0;

}
//--------------------------------------------------------------------------
////////////////////// FUNCTION ////////////////////////
//--------------------------------------------------------------------------
function setList(idElement, arr) 
{
	
	var list = document.getElementById(idElement);

	tmp = document.createElement("option");
	tmp.text = list.options[0].text;
	tmp.value = list.options[0].value;
	tmp.title = list.options[0].title;
	tmpOld = list.options[list.selectedIndex]; 
	
	try {
		list.add(tmp, tmpOld); 
	}
	catch(e) {
		list.add(tmp, list.selectedIndex); 
	}

	
	for(var i = 0; i < arr.length; i++)
	{
		
		option = document.createElement("option");	option.text = arr[i];	option.value = arr[i];
		option.title = arr[i];
		optionOld = list.options[list.selectedIndex];  
		
		try {
			list.add(option, optionOld); 
		}
		catch(e) {
			list.add(option, list.selectedIndex); 
		}
	
	}
	
	list.remove(arr.length + 1);

}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function retrieveList() 
{

	var x = reqList.responseXML.getElementsByTagName("List");

	regionList = new Array();
	ISVList = new Array();
	IndustryList = new Array();
	HorizontalList = new Array();
	
	for (i = 0;i < x.length; i++)
	{
			
		for (j = 0;j < x[i].childNodes.length; j++)
		{
	
			if (x[i].childNodes[j].nodeType != 1)	continue;
			//alert(x[i].childNodes[j].firstChild.nodeValue);

			switch(i)
			{
				case 0:	regionList.push(x[i].childNodes[j].firstChild.nodeValue);
						break;
				case 1:	ISVList.push(x[i].childNodes[j].firstChild.nodeValue);
						break;
				case 2:	IndustryList.push(x[i].childNodes[j].firstChild.nodeValue);
						break;
				case 3:	HorizontalList.push(x[i].childNodes[j].firstChild.nodeValue);
						break;
						
			}
			
		}
		
	}
	
}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function processReqChangeLoadList()
{
	// only if req shows "loaded"
	if (reqList.readyState == 4) 
	{
		// only if "OK"
		if (reqList.status == 200) {

			retrieveList();
			setList("region",regionList);
			setList("ISV_LIST",ISVList);
			setList("regionMap",regionList);
			setList("Industry",IndustryList);
			setList("Horizontal",HorizontalList);
			
		} 
		else	alert("There was a problem retrieving the XML data:\n" + reqList.statusText);
				
	}
	
}
//--------------------------------------------------------------------------
////////////////////// FUNCTIONS ///////////////////////
//--------------------------------------------------------------------------
function loadList(url)
{
	
	try 
	{
    
	    reqList = new XMLHttpRequest();
        reqList.onreadystatechange = processReqChangeLoadList;
        reqList.open("GET", url, true);
        reqList.send(null);
		
    } catch (e){
        
        reqList = new ActiveXObject("Microsoft.XMLHTTP");
        
		if (reqList) {
            reqList.onreadystatechange = processReqChangeLoadList;
            reqList.open("GET", url, true);
            reqList.send();
        }
		
    }
		
}
//--------------------------------------------------------------------------
////////////////////// FUNCTION ////////////////////////
//--------------------------------------------------------------------------
function initList()
{

	loadList("Data/List.xml");

}
