// JavaScript Document

function password_validation(text_id)
{

	if($('#'+text_id).attr('value').length<6)
	{		
		return false;
	}
	else
	{
		return true;
	}	
}
function email_validation()
{
	if(document.loginForm.userEmail.value=='' || document.loginForm.userEmail.value=='User Email')
	{	
		alert('Your E-mail is a mandatory field');
	
		return false;
	}		
	else if ((document.loginForm.userEmail.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{		
		alert('Wrong Email formate');
		return false;
	}else{
		if(document.loginForm.checkID.checked==true){
			set_cookie_val('user',document.loginForm.userEmail.value);
			set_cookie_val('pass',document.loginForm.userPassword.value);
		}else{
			deleteCookie('user');
			deleteCookie('pass');
		}
		return true;
	}

	
}
function email_contacts()
{
	var emailH=document.contactForm.email.value;
	var fullNameH=document.contactForm.fullName.value;
	var countryH=document.contactForm.country.options[document.contactForm.country.selectedIndex].text;
	var cityH=document.contactForm.city.options[document.contactForm.city.selectedIndex].text;
	var messageH=document.contactForm.message.value;
	var mobH=document.contactForm.mob.value;
	

	if(emailH=='' || emailH=='Your email ...')
	{	
		alert('Your E-mail is a mandatory field');
	
		return false;
	}		
	else if ((emailH.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) == -1)
	{		
		alert('Wrong Email formate');
		return false;
	}else{
		sR('contactmail.php?email='+emailH+'&fullName='+fullNameH+'&country='+countryH+'&city='+cityH+'&message='+messageH+'&mob='+mobH,'','GET','contact_message');
		return false;
	}

	
}


function fillCity(code)
{
	sR('cities.php?thecode='+code,'','GET','city_container');
	
}
function fillSelects(code)
{
	sR('fillSelects.php?thecode='+code,'','GET','search_container');
	
}
function fillDistricts(code)
{
	
	sR('districts.php?thecode='+code,'','GET','newww');
	
}
function do_search(countryCode,cityID,disID,coName)
{
	sR('search.php?countryCode='+countryCode+'&cityID='+cityID+'&disID='+disID+'&coName='+coName,'','GET','search_results_container');
	
}
function keyword_search(keyword)
{
	if(keyword!=''){
		sR('search_key.php?keyword='+keyword,'','GET','search_results_container');
	}else{
		alert('You must insert a keyword to search.');
	}
	return false;
}

function get_cookie_val(Name) { 
		var search = Name + "="
		var returnvalue = "";
		if (document.cookie.length > 0) {
			offset = document.cookie.indexOf(search)			
			if (offset != -1) { 
				offset += search.length
				end = document.cookie.indexOf(";", offset);
				if (end == -1) end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end))
				}
		}
		return returnvalue;
	}
function set_cookie_val(cookiename,cookievalue){
		document.cookie=cookiename+"="+cookievalue;
}
function deleteCookie(name) {
	if ( get_cookie_val(name) ) document.cookie = name + '=' +';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
