var voiphost=document.location.hostname;

//unique identifier for commerce partner
var lpid = "f1c863a8-86c0-4a6c-86dc-238cd42f";

function advsearch()
{
	top.location="http://www.voipreview.org/service.all2.aspx?adv=1&lpid="+lpid;
}
function populateSelects(item)
{
	function stateHandler() 
	{ 
		clearOptionList(SelectRef);
		SelectRef.options[0]= new Option("Loading...",0)
				
		if (oHTTP.readyState == 4) 
		{ 
			if (oHTTP.status == 200) 
			{ 
				var result = oHTTP.responseText;
				var finalResult = result.split(";");
				
				if(finalResult.length!=0 && finalResult[0]!='')
				{
					for(i=0;i<finalResult.length;i++)
					{
						var s,ss;
						s = finalResult[i];
						ss = s.split("=");
						SelectRef.options[i] = new Option(ss[1],ss[0]);
					}
					if(item!="servicetype")
					{
						var oOption = new Option("- All -",0);
						
						SelectRef.options.add(oOption,0);
						SelectRef.selectedIndex = 0;
					}
					else
					{
						var oOption = new Option("- All -",0);
						
						SelectRef.options.add(oOption,0);
						SelectRef.selectedIndex = 1;
					}
				}
				else
				{
					SelectRef.options[0]= new Option("...",0);
				}
				
			} 
			else 
			{ 
				failure(); 
			} 
		}
	return true;
	}
	
	function failure()
	{
		alert("We apologise, but the service is not availabel at the moment.");
	}
	var SelectRef;
	var sURL;
	
	//determining what to populate
	switch (item)
	{
		case "providers":
		{
			sURL = 'providerslist.aspx';
			SelectRef = document.VoIPform.GlobalFilter_Providers;
			break;
		}
		
		
		case "servicetype":
		{
			sURL = 'servicetypelist.aspx';
			SelectRef = document.VoIPform.GlobalFilter_ServiceType;
			break;
		}
		
		case "area":
		{
			SelectCountry = document.getElementById('GlobalFilter_Country');
			sURL = 'arealist.aspx?country='+SelectCountry[SelectCountry.selectedIndex].value;
			SelectRef = document.VoIPform.GlobalFilter_Area;
			break;
		}
	}
	
	//Creating XMLHttpRequest object
	try 
	{ 
		var oHTTP = new XMLHttpRequest(); 
		
	} 
	catch (error) 
	{ 
		try 
		{ 
			var oHTTP = new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch (error) 
		{ 
			return false; 
		} 
	}


  if (oHTTP != null)
  {
	oHTTP.onreadystatechange = stateHandler;
	oHTTP.open('GET', sURL, true);
	oHTTP.send(null);
	
	delete oHTTP;
  }


	
return true; 
}

function OnSubmit() {
	top.location = 'http://www.voipreview.org/service.all2.aspx?lpid='+lpid+'&Country=' +document.getElementById('GlobalFilter_Country').value+'&CallingArea=0&provider='+document.getElementById('GlobalFilter_Providers').value+'&area_code='+document.getElementById('GlobalFilter_Area').value+'&ServiceType='+document.getElementById('GlobalFilter_ServiceType').value;
}

//clears select
function clearOptionList(selectObjRef) {
	var prntNode = selectObjRef;
	var nLength = prntNode.length
	for(i=0; i < nLength ; i++) {
		prntNode.remove(0);
	}   	
}

