function check_email(e) 
{
	e = e||"";
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}
	}
	
	if (document.images)
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);
		}
	}
}



function advertismentTypesLoad(responseText, textStatus, XMLHttpRequest)
{
	if(textStatus == "success")
 	{
 		$("ul.cities > li").removeClass("selected");
 		
 		$( "ul.advertisment_types > li").not( $("li" , this) ).remove();
 		
 		var city_id = $(this).parent("ul.cities > li").addClass("selected").attr("id");
 	}
}

function citiesLoad (responseText, textStatus, XMLHttpRequest) 
{
 	
 	if(textStatus == "success")
 	{
 		$("ul.countries > li").removeClass("selected");
 		$("ul.countries ul.cities > li").not( $("li" , this) ).remove();
	 	$(this).parent("li").addClass("selected");
	 	$("ul.cities > li > a" ).click( cityClick );
	 	
	 }
	 
}

function cityClick()
{
		var id = this.id.replace( /[^\d]*/ , "");
		
		var div = $( this ).parent("li").children("ul.advertisment_types");
		 
		
		div.load(  "http://"+location.host + webroot + "advertisment_types/get_available_by_city/"+id , {} , advertismentTypesLoad );
		
		return false; 	 	
}

$( function()
{
	$(".navigation ul.countries > li > a").click
	( 
		function()
		{
			var id = this.id.replace( /[^\d]*/ , "");
			var div = $( this ).parent("li").children("ul.cities");
			
			div.load( "http://"+location.host + webroot + "/cities/by_country/"+id , {} , citiesLoad );
			return false; 
		}
	);
	
 	$("ul.cities > li > a" ).click( cityClick );	
});







