function getXMLHTTPRequest() 
{
	try 
    {
     	req = new XMLHttpRequest();
    } 
	catch(err1) 
	{
      	try 
		{
           req = new ActiveXObject("Msxml2.XMLHTTP");
        } 
		catch(err2) 
		{
           try 
		   {
              req = new ActiveXObject("Microsoft.XMLHTTP");
           }
		   catch (err3)
		   {
              req = false;
           }
        }
    }
	return req;
}
var http = getXMLHTTPRequest();
var id_pr;
var id_val;
var id_cou;
var app_all ;		

function useHttpResponseAdv1()
{
	if (http.readyState == 4) 
	{
		document.getElementById('adv_box').innerHTML = '';
	 	if(http.status == 200) 
		{
		    var response = http.responseText;
			var cities = response.split('|');
			removeAllOptions(document.getElementById('province_change1'));
			addOption(document.getElementById('province_change1'),'all', 'Select All')
			removeAllOptions(document.getElementById('city_change1'));
			for (i=1; i<cities.length; i++) {
				var sep = cities[i].split('~');
				addOption(document.getElementById('province_change1'),sep[0], sep[1])
		    }
		    
      	}
	}
	else
	{
 		//document.getElementById('adv_box').innerHTML = '<img src="javascript/loading.gif" />';
	}
	
}

function useHttpResponseAdv2()
{
	if (http.readyState == 4) 
	{
		
	 	if(http.status == 200) 
		{
		    var response = http.responseText;
			var cities = response.split('|');
			removeAllOptions(document.getElementById('province_change1'));
			removeAllOptions(document.getElementById('city_change1'));
			addOption(document.getElementById('province_change1'),'all', 'Select All');
			for (i=1; i<cities.length; i++) {
				var sep = cities[i].split('~');
				addOption(document.getElementById('province_change1'),sep[0], sep[1])
		    }
		    var selectBox= document.getElementById('province_change1');
		    
   			for (var no = 0; no < selectBox.options.length; no++)
   			{
       			if (selectBox.options[no].value == id_pr)
	   			{
            		selectBox.selectedIndex = no;
            		if(id_pr == 'all' || !id_pr || id_pr == null)
					{
						removeAllOptions(document.getElementById('city_change1'));
					}
					else
					{
            			changeCityAdv1('city_change1',id_pr,'canada');
            		}	
            		break;
       			}
   			}
   			if(id_pr != 'all'){
            setTimeout ("document.getElementById('city_change1').options[0].selected = false;var selectBox= document.getElementById('city_change1'); var sep = id_val.split('~'); for(var i=0;i < sep.length ;i++){ for (var no = 0; no < selectBox.options.length; no++){if (selectBox.options[no].value == sep[i]){selectBox.options[no].selected = true;break;}}}"
			, 2400 ); 
			}
   		}
	}
	else
	{
 		//document.getElementById('box').innerHTML = '<img src="javascript/loading.gif" />';
	}
	
}		  


function fillCityAdv()
{
	if (http.readyState == 4) 
	{
		document.getElementById('adv_box1').innerHTML = '';
	 	if(http.status == 200) 
		{
		    var response = http.responseText;
			var cities = response.split('|');
			removeAllOptions(document.getElementById('city_change1'));
			addOption(document.getElementById('city_change1'),'all', 'Select');
			addOption(document.getElementById('city_change1'),'all', 'Select All')
			for (i=1; i<cities.length; i++) {
				var sep = cities[i].split('~');
				addOption(document.getElementById('city_change1'),sep[0], sep[1])
		    }
		    document.getElementById('city_change1').options[0].selected = true;
      	}
	}
	else
	{
 		//document.getElementById('adv_box1').innerHTML = '<img src="javascript/loading.gif" />';
	}
	
}



function useHttpResponseAdv()
{
	if (http.readyState == 4) 
	{
		document.getElementById('adv_box').innerHTML = '';
	 	if(http.status == 200) 
		{
		    var response = http.responseText;
			var cities = response.split('|');
			removeAllOptions(document.getElementById('province_change1'));
			removeAllOptions(document.getElementById('city_change1'));
			addOption(document.getElementById('province_change1'),'all', 'Select');
			addOption(document.getElementById('province_change1'),'all', 'Select All')
			for (i=1; i<cities.length; i++) {
				var sep = cities[i].split('~');
				addOption(document.getElementById('province_change1'),sep[0], sep[1])
		    }
		    var selectBox= document.getElementById('province_change1');
   			for (var no = 0; no < selectBox.options.length; no++)
   			{
       			if (selectBox.options[no].value == '9')
	   			{
            	//	selectBox.selectedIndex = no;
            		changeCityAdv('city_change1','0','canada');
            		break;
       			}
   			}
   			
   			
   		}
	}
	else
	{
 		//document.getElementById('adv_box').innerHTML = '<img src="javascript/loading.gif" />';
	}
	
}

			  

function changeProvinceAdv1(id,value)
{
	var myurl = 'index2.php';
	var modurl = myurl+"?com_route=country&value="+value+"&id="+id;
	http.open("GET", modurl, true);
	http.onreadystatechange = useHttpResponseAdv1;
	http.send(null); 
}

function changeCityAdv1(id,value,country)
{
	if(value == 'all' || !value || value == null)
	{
		removeAllOptions(document.getElementById('city_change1'));
		addOption(document.getElementById('city_change1'),'all', 'Select');
	}
	else
	{
		var myurl = 'index2.php';
		var modurl = myurl+"?com_route=country&value="+value+"&city=1&id="+id+"&country="+country;
		http.open("GET", modurl, true);
		http.onreadystatechange = fillCityAdv;
		http.send(null);
	}	 
}
function changeProvinceAdv(id,value)
{
	var myurl = 'index2.php';
	var modurl = myurl+"?com_route=country&value="+value+"&id="+id;
	http.open("GET", modurl, true);
	http.onreadystatechange = useHttpResponseAdv;
	http.send(null); 
}

function changeCityAdv(id,value,country)
{
	if(value == 0)
	{
		removeAllOptions(document.getElementById('city_change1'));
		addOption(document.getElementById('city_change1'),'all', 'Select');
	}
	else
	{
		var myurl = 'index2.php';
		var modurl = myurl+"?com_route=country&value="+value+"&city=1&id="+id+"&country="+country;
		http.open("GET", modurl, true);
		http.onreadystatechange = fillCityAdv;
		http.send(null);
	}	 
}

function changeProvinceAdv2(id,value,pr,val)
{
	
		var myurl = 'index2.php';
		var modurl = myurl+"?com_route=country&value="+value+"&id="+id;
		http.open("GET", modurl, true);
		id_pr = pr;
		id_val = val;
		http.onreadystatechange = useHttpResponseAdv2;
		http.send(null);
	 
}



