function gebi( id )
{
	return document.getElementById( id )
}

function visibility( id )
{
	var blockId = gebi( id );
	blockId.style.display = blockId.style.display == "none" ? "" : "none";
}

function go_to( href )
{
	location.href = href;
	return true;
}

function selectAll(form) 
{
	var checked = form.checkAll.checked;
	
	for (var i = 0; i < form.length; i++) {
		if (form[i].getAttribute("type") == "checkbox" && form[i].getAttribute("name") != "checkAll") {
			form[i].checked = checked;
		}
	}
}

function selectOne(form) 
{
	var checked =0;
	var all = 0;
	
	for (var i = 0; i < form.length; i++) {
		if (form[i].getAttribute("type") == "checkbox" && form[i].getAttribute("name") != "checkAll") {
			if (form[i].checked == true) {
				checked++;
				all++;
			}
			else {
				all++;
			}
		}
	}
	if (all == checked) {
		form.checkAll.checked = true;
	}
	if(checked != 0 && checked < all) {
		form.checkAll.checked = false;
	}
}

function locationCountry()
{
	var country = document.getElementById("country");
	var region = document.getElementById("region");
	var city = document.getElementById("city");
	var container = document.getElementById("region-block");
	
	new Ajax.Request("/modules/ajax/location.php", {
		encoding: 'UTF-8',
		method: 'post',
		parameters: { country: country.value, region: region.value, city: city.value, type: 'region', name: region.name },
				onSuccess: function( transport ) {
					container.innerHTML = transport.responseText; 
				},
				onFailure: function( transport ) { 
					container.innerHTML = transport.responseText; 
				}
	});
	
	locationRegion()();
}

function locationRegion()
{
	var country = document.getElementById("country");
	var region = document.getElementById("region");
	var city = document.getElementById("city");
	var container = document.getElementById("city-block");
	
	new Ajax.Request("/modules/ajax/location.php", {
		encoding: 'UTF-8',
		method: 'post',
		parameters: { country: country.value, region: region.value, city: city.value, type: 'city', name: city.name },
				onSuccess: function( transport ) {
					container.innerHTML = transport.responseText; 
				},
				onFailure: function( transport ) { 
					container.innerHTML = transport.responseText; 
				}
	});
}

function locationCity()
{

}

function queryString(parameter) { 
	var loc = location.search.substring(1, location.search.length);
	var param_value = false;
	var params = loc.split("&");
	
	for (i=0; i<params.length;i++) {
		param_name = params[i].substring(0,params[i].indexOf('='));
		
		if (param_name == parameter) {
			param_value = params[i].substring(params[i].indexOf('=')+1)
		}
	}
  
	if (param_value) {
		return param_value;
	}
	else {
		return false;
	}
}


function refreshCaptcha()
{
	var t = new Date();
	var timestamp = t.getTime();	
	
	captcha = new Image();
	captcha.src = '/captcha.jpg?' + timestamp;
	
	
	captcha.onload = function () { 
		document.images['captcha'].width  = captcha.width;
		document.images['captcha'].height = captcha.height;
		document.images['captcha'].src    = captcha.src;
	}
}