
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
};


function confirmar_borrado(nombre){
	return confirm('Confirmar borrado de\n'+nombre+' ?.');
};


function numbersonly(e){
	var key;
	var keychar;
	if (window.event)
 		key = window.event.keyCode;
	else if (e)
 		key = e.which;
	else
 		return true;
	keychar = String.fromCharCode(key);
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
 		(key==9) || (key==13) || (key==27) )
 		return true;
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
		return true;
	else
 		return false;
};

//Comprueba que un campo de texto WHAT no tenga mas de LIMIT caracteres
//uso: onKeyPress="return maxchars(this, 280)" onBlur="return maxchars(this, 280)"
function maxchars(what,limit){
	if (what.value.length > limit){
		what.value = what.value.substring(0, limit);
	}
};

function comprobarFecha(campo){
	if(campo.value.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/)){
		return true;
	}
	else{
		alert("Fecha Invalida!");
		campo.focus();
		return false;
	}
}

function comprobarEmail(campo){
	if(campo.value.match(/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+.[a-z]{2,}$/i)){
		return true;
	}
	else{
		alert("E-mail Invalido!");
		campo.focus();
		return false;
	}
}

function comprobarWeb(campo){
	if(campo.value.match(/[a-z0-9]+.[a-z]{2,4}$/i)){
		return true;
	}
	else{
		alert("URL Invalida!");
		campo.focus();
		return false;
	}
}

function comprobarFormFincas() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.fincas.ref_form.value=="") {
		textError = "ERROR: Se requiere una referencia.";
		document.fincas.ref_form.focus();
		allOK = false;
	}

	if (document.fincas.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un nombre.";
		document.fincas.nombre_form.focus();
		allOK = false;
	}

	if (document.fincas.precio_form.value=="") {
		textError += "\nERROR: Se requiere un precio.";
		document.fincas.precio_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarFormPromociones() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.promociones.ref_form.value=="") {
		textError = "ERROR: Se requiere una referencia.";
		document.promociones.ref_form.focus();
		allOK = false;
	}

	if (document.promociones.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un nombre.";
		document.promociones.nombre_form.focus();
		allOK = false;
	}
	
	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarvender() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.venderfinca.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.venderfinca.nombre.focus();
		allOK = false;
	}

	if (document.venderfinca.telefono.value=="") {
		textError += "\nERROR: Se requiere un Teléfono.";
		document.venderfinca.telefono.focus();
		allOK = false;
	}

	if (document.venderfinca.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.venderfinca.email.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarcomprar() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.comprarfinca.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.comprarfinca.nombre.focus();
		allOK = false;
	}

	if (document.comprarfinca.telefono.value=="") {
		textError += "\nERROR: Se requiere un Teléfono.";
		document.comprarfinca.telefono.focus();
		allOK = false;
	}

	if (document.comprarfinca.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.comprarfinca.email.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarcontactar() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.contactar.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.contactar.nombre.focus();
		allOK = false;
	}

	if (document.contactar.telcontacto.value=="") {
		textError += "\nERROR: Se requiere un Teléfono.";
		document.contactar.telcontacto.focus();
		allOK = false;
	}
	
	if (document.contactar.acepto.checked == false) {
		textError += "\nERROR: Ha de aceptar haber leído las codiciones de uso.";
		document.contactar.acepto.focus();
		allOK = false;
	}

	if (document.contactar.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.contactar.email.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function desactivador(origen, valor, objetivo){
	if(origen.value == valor)
		objetivo.disabled = false
	else
		objetivo.disabled = true;
}

function terrenos(origen){
	desactivador(origen, "1", document.fincas.texto1_form);
	desactivador(origen, "1", document.fincas.texto2_form);
}
