// JavaScript Document
var info_text;
var net=new Object();
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;

net.ContentLoader=function(url, param, onload, onerror) {
	this.url=url;
	this.param=param;
	this.req=null;
	this.onload=onload;
	this.onerror=(onerror) ? onerror : this.defaultError;
	this.loadXMLDoc(url, param);
}

net.ContentLoader.prototype={
	loadXMLDoc:function(url, param){
		if (window.XMLHttpRequest){
			this.req=new XMLHttpRequest();
		} else if (window.ActiveXObject){
			this.req=new ActiveXObject("Microsoft.XMLHTTP");
		} 
		try {
			var loader=this;
			this.req.onreadystatechange=function() {
				loader.onReadyState.call(loader);
			}
			this.req.open('GET',url,true);
			this.req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			this.req.send(param);
		} catch (err) {
				this.onerror.call(this);
		}
	},
	onReadyState:function() {
		var req=this.req;
		var ready=req.readyState;
		if (ready==net.READY_STATE_COMPLETE) {
			this.onload.call(this);
		}
	},
	defaultError:function() { 
	}
}

var now_City= new Array();

function on_load_init() {
	var form1= document.form1;
	if (form1) {
		form1.country.onchange= change_country;
	}
}

function change_country() {
	var form1= document.form1;
    if (form1.country.value=='all') {
    if (form1.now_city) form1.now_city.value='all';
    form1.submit();
    }
    if (form1.country.value!='no' && form1.country.value!='all') {
		var divCity = document.getElementById('div-ñity');
		if (!info_text) info_text='loading...'
		divCity.innerHTML= info_text;
		if (now_City[form1.country.value]) show_select();
		else {
        	var url = shab_url+"?now_country="+form1.country.value;
            var load_cont= new net.ContentLoader(url, null, onLoadCont);
        }
	}
}

function onLoadCont() {
var my_content = this.req.responseText.split('%my_content%') 
now_City[form1.country.value]=my_content[1];
my_content = null;
show_select();
}

function show_select() {
	var divCity = document.getElementById('div-ñity');
    divCity.innerHTML = now_City[form1.country.value];
    document.form1.now_city.onchange= function() {if (document.form1.now_city.value!='no') document.form1.submit();}
}

window.attachEvent?window.attachEvent('onload', on_load_init):window.addEventListener('load', on_load_init, false)

