// JavaScript Document

function callSearchType(type)
 {
	var types = 3;
	var i=0;
	
	for (i=1;i<=types;i++) 
	{
		//alert('type_'+i);
		var obj = new getObj('type_'+i);
			
		if (i != type) {
			obj.style.display = "none";
		} 
		else {
			obj.style.display = "inline";
		}
	}
 }
 
var req;

function loadXMLDoc(url) 
{
	//window.open (url);

    if (window.XMLHttpRequest) { // branch for native XMLHttpRequest object
        req = new XMLHttpRequest();
        req.onreadystatechange = processSelector;
        req.open("GET", url, true);
        req.send(null);
    } 
	else if (window.ActiveXObject) { // branch for IE/Windows ActiveX version
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processSelector;
            req.open("GET", url, true);
            req.send();
        }
    }
}


function processSelector() 
{
	var obj = new getObj("body");
    // only if req shows "complete"
    switch (req.readyState) {
		case 1:
			//obj.obj.innerHTML = "<img src='/images/loading-anim.gif'>";
		break;

		case 4:
			// only if "OK"
			if (req.status == 200) {
				obj.obj.innerHTML = req.responseText;
			} 
			else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
			}
		break;
    }
}

function callState()
{
	var search_type = "";
	var postcode = "";
	var state = "";
	var keyword = "";
	var suburb = "";
	var country = "";
	 
			
	// var search_type = document.agentlocator.search_type.value;
	
	for (i=0;i<document.agentlocator.search_type.length;i++)
	{
		if (document.agentlocator.search_type[i].checked)
		{
			search_type = document.agentlocator.search_type[i].value;
		}
	}


	//state set for australia only
	country = document.agentlocator.country.value;
	
	//alert(country);

	switch (country)
	{
		case "au":
			state = document.agentlocator.state.options[document.agentlocator.state.selectedIndex].value;
		break
	}
  
	

	var url = 'agent_locator.asp?'
			+'search_type=' + search_type
			+'&postcode=' + postcode
			+'&state=' + state
			+'&keyword=' + keyword
			+'&suburb=' + suburb
	
	//alert(url);
	loadXMLDoc (url);
	// window.open (url);
	
   return false;
}
	
	


function callAgents(week,agents)
 {
	var weeks = 0;
	var currentWeek = 1;
	weeks = agents 
	//alert(weeks);
	var i=1;
	
	for (i=1;i<=weeks;i++) 
	{
		//alert(week);
		var agent = new getObj('agent_'+i);
		var links = new getObj('link_'+i);
		
		if (i != week) {
			agent.obj.style.display = "none";
			links.obj.className = "notselected";
		} 
		else {
			agent.obj.style.display = "inline";
			links.obj.className = "selected";
		}
	}
	
	// To change the Bottom Links Highlight
	for (i=1;i<=weeks;i++) 
	{		
		var links1 = new getObj('link_'+i+'_'+i);
			
	   	if (i != week) {
			links1.obj.className = "notselected";
		} 
		else {
			links1.obj.className = "selected";
		}
	}
}

function getObj(name)
{ //alert("Name"+name);
	if (document.getElementById) {
		
		this.obj = document.getElementById(name);
		//this.style = document.getElementById(name).style;
	} else if (document.all) {
		this.obj = document.all[name];
		//this.style = document.all[name].style;
	} else if (document.layers) {
		if (document.layers[name]) {
			this.obj = document.layers[name];
			//this.style = document.layers[name];
		}
	}
}