function validateContact(form) {
	var nombre = form.nombre.value;
	var mensaje = form.mensaje.value;
	var email = form.email.value;

	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(!nombre.match(nameRegex)) {
		inlineMsg('nombre','Ingrese un nombre v&aacute;lido',2);
		return false;
	}
	if(!email.match(emailRegex)) {
		inlineMsg('email','Ingrese un email v&aacute;lido',2);
		return false;
	}
	if(mensaje.length < 6) {
		inlineMsg('mensaje','Ingrese un mensaje',2);
		return false;
	}

	return true;
}

function validateSearch(form) {
	var query = form.query.value;
	
	if(query == "" || query.length < 3) {
		inlineMsg('query','Ingrese una b&uacute;squeda de al menos 3 caracteres',2);
		return false;
	}
	
	return true;
}

function submitSearch() {
	var query = document.forms["searchform"].query.value;
	
	if(query == "" || query.length < 3) {
		inlineMsg('query','Ingrese una b&uacute;squeda de al menos 3 caracteres',2);
	} else {
		document.forms['searchform'].submit();  	
	}
}

function detallePopUp(id) {
	mywindow = window.open ("detalle.php?id="+id,
							"Detalle"+id,
							"location=0,status=0,scrollbars=1,toolbar=0,width=600,height=550");
} 

function updateCiudad(select) {
	if (select != '') {
		//var url = base_url+"ajax/ciudades/";
		var url = "/ajax/ciudades/";
	    
	    $.post(url, { departamento: select.value },
		   function(data){
		     $('#searchformajaxciudades').html('<select name="selectedCiudad" onchange="updateBarrio(this)" id="selectedCiudad" style="width:150px">'+data+'</select>');
		});
		
		 $('#searchformajaxbarrios').html('<select name="selectedBarrio" id="selectedBarrio" style="width:150px"><option value="">Todos</option></select>');
	}
};

function updateBarrio(select) {
	if (select != '') {
		//var url = base_url+"ajax/barrios/";
		var url = base_url+"/ajax/barrios/";

	    $.post(url, { ciudad: select.value },
		   function(data){
		     $('#searchformajaxbarrios').html('<select name="selectedBarrio" id="selectedBarrio">'+data+'</select>');
		});

	}
};

function validateEnviarPorMail(form) {
	var enviarnombre = form.enviarnombre.value;
	var enviarmensaje = form.enviarmensaje.value;
	var enviaremail = form.enviaremail.value;

	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(!enviarnombre.match(nameRegex)) {
		inlineMsg('enviarnombre','Ingrese un nombre v&aacute;lido',2);
		return false;
	}
	if(!enviaremail.match(emailRegex)) {
		inlineMsg('enviaremail','Ingrese un email v&aacute;lido',2);
		return false;
	}
	if(enviarmensaje.length < 6) {
		inlineMsg('enviarmensaje','Ingrese un mensaje',2);
		return false;
	}
	
	return true;
}

function validateEnviarProp(form) {
	var propnombre = form.propnombre.value;
	var propmensaje = form.propmensaje.value;
	var propemail = form.propemail.value;

	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(!propnombre.match(nameRegex)) {
		inlineMsg('propnombre','Ingrese un nombre v&aacute;lido',2);
		return false;
	}
	if(!propemail.match(emailRegex)) {
		inlineMsg('propemail','Ingrese un email v&aacute;lido',2);
		return false;
	}
	if(propmensaje.length < 6) {
		inlineMsg('propmensaje','Ingrese un mensaje',2);
		return false;
	}
	
	return true;
}

function validateEnviarPorMail2(form) {
	var enviarnombre = form.enviarnombre.value;
	var enviarmensaje = form.enviarmensaje.value;
	var enviaremail = form.enviaremail.value;

	var nameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	var emailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
	var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
	
	if(!enviarnombre.match(nameRegex)) {
		inlineMsg('enviarnombre2','Ingrese un nombre v&aacute;lido',2);
		return false;
	}
	if(!enviaremail.match(emailRegex)) {
		inlineMsg('enviaremail2','Ingrese un email v&aacute;lido',2);
		return false;
	}
	if(enviarmensaje.length < 6) {
		inlineMsg('enviarmensaje2','Ingrese un mensaje',2);
		return false;
	}
	
	return true;
}

enviarcorreo = false;
function showEnviarCorreo() {
	/*if (enviarcorreoagente) {
		$('#enviarcorreoagente').fadeOut('slow');
		enviarcorreoagente = false;
	} */
	if (!enviarcorreo) {
		$('#enviarcorreo').fadeIn('slow');
		enviarcorreo = true;
	} else {
		$('#enviarcorreo').fadeOut('slow');
		enviarcorreo = false;	
	}
	return false;
}

propcorreo = false;
function showPropCorreo() {
	/*if (enviarcorreoagente) {
		$('#enviarcorreoagente').fadeOut('slow');
		enviarcorreoagente = false;
	} */
	if (!propcorreo) {
		$('#propcorreo').fadeIn('slow');
		propcorreo = true;
	} else {
		$('#propcorreo').fadeOut('slow');
		propcorreo = false;	
	}
	return false;
}

//$.fn.cycle.defaults.speed   = 900;
//$.fn.cycle.defaults.timeout = 6000;

var Choice, Selection;
function country_jump() {
	Choice = document.country_select.your_country.selectedIndex;
	Selection=document.country_select.your_country.options[Choice].value;
	//location=Selection;
	window.open(Selection,"_blank");
}

function lang_jump() {
	Choice = document.selectlang.selectlang.selectedIndex;
	Selection=document.selectlang.selectlang.options[Choice].value;
	//alert(Selection);
	//location=Selection;
	window.open(Selection,"_blank");
}
