function echeck(str, container) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	var validated = true;
	if (str.indexOf(at)==-1){
		validated = false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		validated = false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		validated = false;
	}
	if (str.indexOf(at,(lat+1))!=-1){
		validated = false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		validated = false;
	}
	if (str.indexOf(dot,(lat+2))==-1){
		validated = false;
	}
	if (str.indexOf(" ")!=-1){
		validated = false;
	}
	if(!validated) {
		return isInvalid(container);
	}
	return isValid(container);
}

function requiredCheck(str, container) {
	var lstr=str.length;
	if(lstr == 0) 
		return isInvalid(container);
	else 
		return isValid(container);
}

function minLengthCheck(str, lenght, container) {
	var lstr=str.length;
	if(lstr < lenght) 
		return isInvalid(container);
	else 
		return isValid(container);
}

function strMatch(str1, str2, container) {
	if(str1 == str2)
		return isValid(container);
	else
		return isInvalid(container);
}

function selectRequiredCheck(val, container) {
	if(val != -1)
		return isValid(container);
	else
		return isInvalid(container);
}

function isValid(container) {
	document.getElementById(container).style.display = 'none';
	return true;
}

function isInvalid(container) {
	document.getElementById(container).style.display = 'inline';
	return false;
}

function validateOwnerRegister() {
	var valid1 = requiredCheck(document.getElementById('name').value, 'name_message');
	var valid2 = minLengthCheck(document.getElementById('password').value, 6, 'password_message');
	var valid3 = strMatch(document.getElementById('password').value, document.getElementById('repeatPassword').value, 'repeat_password_message');
	var valid4 = echeck(document.getElementById('email').value, 'email_message'); 
	return valid1 && valid2 && valid3 && valid4;
}
function validatePropertyLocation() {
	var valid1 = requiredCheck(document.getElementById('address').value, 'address_message');
	var valid2 = requiredCheck(document.getElementById('city').value, 'city_message');
	var valid3 = requiredCheck(document.getElementById('region').value, 'region_message');
	var valid4 = selectRequiredCheck(document.getElementById('country_select').options[document.getElementById('country_select').selectedIndex].value, 'country_message');
	return valid1 && valid2 && valid3 && valid4;
}

function validatePropertyRegister() {
	var valid1 = requiredCheck(document.getElementById('bedrooms').value, 'bedrooms_message');
	var valid2 = requiredCheck(document.getElementById('bathrooms').value, 'bathrooms_message');
	var valid3 = validatePropertyLocation();
	return valid1 && valid2 && valid3;
}


