// declare new variables for each new div that you add, and link to the div by ID
// var region_div = document.getElementById("region_div");
var doc = null;

function ajax() {
	// Make a new XMLHttp object
	if (typeof window.ActiveXObject != 'undefined' ) doc = new ActiveXObject("Microsoft.XMLHTTP");
	else doc = new XMLHttpRequest();
}

function SelectCountry(section, destination){
	ajax();
	// Load the result from the response page
	// ** As far a I know firefox will only load a document on the SAME domain!!	
	if (doc){
		destination.innerHTML = "Loading data...";
		doc.open("GET", "location.php?sec=" + section + "&sel=country", false);
		doc.send(null);
		// Write the response to the div	    	
		destination.innerHTML = doc.responseText;
	}else{
		destination.innerHTML = 'Browser unable to create XMLHttp Object';
	}
}

function SelectRegion(section, id_country, destination, destination2){
	if (id_country != '') {
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
		if (doc){
			destination.innerHTML = "Loading data...";
			doc.open("GET", "location.php?sec=" + section + "&sel=region&id_country=" + id_country, false);
			doc.send(null);
			// Write the response to the div	    	
			destination.innerHTML = doc.responseText;
		}else{
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	}else{
		destination.innerHTML = "Country is not selected";
	}
	destination2.innerHTML = "";
}

function SelectCity(section, id_region, destination){
	if (id_region != '') {
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
		if (doc){
			destination.innerHTML = "Loading data...";	
			doc.open("GET", "location.php?sec=" + section + "&sel=city&id_region=" + id_region, false);
			doc.send(null);
			// Write the response to the div	    	
			destination.innerHTML = doc.responseText;
		}else{
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	}else {
		destination.innerHTML = "Region is not selected";
	}
}

function CheckLogin(section, login, destination){
	if (login != '') {
		ajax();
		// Load the result from the response page
		// ** As far a I know firefox will only load a document on the SAME domain!!	
		if (doc){
			destination.innerHTML = "Loading data...";	
			doc.open("GET", "location.php?sec=" + section + "&sel=login&login=" + login, false);
			doc.send(null);
			// Write the response to the div
			destination.innerHTML = doc.responseText;
		}else{
			destination.innerHTML = 'Browser unable to create XMLHttp Object';
		}
	}else {
		destination.innerHTML = "Nick is empty";
	}
}

function unCheckbox(obj, text){
		var warning_div = document.getElementById('un_checkbox_warning');
		if(warning_div == null){
			var width=250;
			var tmp = getAbsolutePos(obj);
			var top = tmp.y + obj.offsetHeight+2;
			var left = tmp.x+ obj.offsetWidth+2;
			var lineup = document.createElement("DIV");
			var close_btn = '<div style="text-align: right"><a href="#" onclick="javascript: CloseWindow(\'un_checkbox_warning\'); return false;"><img src="/templates/pilot_2_theme/images/close1.gif" border="0" /></a></div>';
			lineup.id = "un_checkbox_warning";
			lineup.className = "div_warning";
			lineup.style.width = width+"px";
			lineup.style.position = "absolute";
			lineup.style.top = top+"px";
			lineup.style.left = left+"px";
			lineup.innerHTML = close_btn+text;
			document.body.appendChild(lineup);
		}else{
			warning_div.style.display = 'block';
		}
		obj.checked = false;
		setTimeout("CloseWindow('un_checkbox_warning');", 4000);
}

function CloseWindow(div){
	document.getElementById(div).style.display = 'none';
}
function getAbsolutePos(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}