
function popup(theURL,winName,features) { 
  var w = window.open(theURL,winName,features);
  w.focus();
};

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
};


function agregar(){
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.grupofergo.com"; 
      var titulo="GRUPO FERGO ::: inmobiliario";
      window.external.AddFavorite(url,titulo);
   } else { 
      if(navigator.appName == "Netscape") 
         alert("Presione Crtl+D para agregar este sitio en sus Bookmarks"); 
   }
};


function confirmar_borrado(nombre){
	return confirm('Confirmar borrado de\n'+nombre+' ?.');
};


//pide confirmacion y lanza el borrado de todos los informes de un cliente dado
function borrarTodos(nombre,id){
	if (confirm('Realmente desea borrar todos los documentos \ndel usuario: '+nombre+' ?.'))
	{
		window.location = "http://www.grupofergo.com/admin/documentos_deleteall.php?id_user="+id;
	}
};

//filtra los informes por el cliente seleccionado en el dropdown
function filtrarClientes(){
	id_user = document.users.users_form.options[document.users.users_form.selectedIndex].value;
	window.location = "http://www.grupofergo.com/admin/documentos_admin.php?id_cliente="+id_cliente;
};


//filtra el loscaracteres y deja solo los numeros
//uso: <input name="precio_form" type="text" onkeypress="return numbersonly(event)" />
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 no valida!");
		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 no valido!");
		campo.focus();
		return false;
	}
};

function comprobarWeb(campo){
	if(campo.value.match(/[a-z0-9]+.[a-z]{2,4}$/i)){
		return true;
	}
	else{
		alert("URL no valida!");
		campo.focus();
		return false;
	}
};

function comprobarEditBanners(formulario) {
	if(document.getElementById(formulario).ref_form.value == '')
		return false;
};


function comprobarFormInmuebles(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.tipo_form.value==0) {
		textError += "\nERROR: Se requiere un TIPO de inmueble.";
		form.tipo_form.focus();
		allOK = false;
	}

	if (form.ref_form.value=="") {
		textError += "\nERROR: Se requiere una REFERENCIA de inmueble.";
		form.ref_form.focus();
		allOK = false;
	}

	if (form.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un NOMBRE de inmueble.";
		form.nombre_form.focus();
		allOK = false;
	}

	if (form.direccion_form.value=="") {
		textError += "\nERROR: Se requiere una DIRECCION del inmueble.";
		form.direccion_form.focus();
		allOK = false;
	}

	if (form.zona_form.value=="") {
		textError += "\nERROR: Se requiere una ZONA.";
		form.zona_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarFormUsers(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un NOMBRE de usuario.";
		form.nombre_form.focus();
		allOK = false;
	}

	if (form.apellidos_form.value=="") {
		textError += "\nERROR: Se requiere unos APELLIDOS de usuario.";
		form.direccion_form.focus();
		allOK = false;
	}
	
	if (!form.email_form.value.match(/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+.[a-z]{2,}$/i)) {
		textError += "\nERROR: Email no valido!.";
		form.email_form.focus();
		allOK = false;
	}

	if (form.user_form.value=="") {
		textError += "\nERROR: Se requiere un NOMBRE DE USUARIO.";
		form.user_form.focus();
		allOK = false;
	}

	if (form.password_form.value=="") {
		textError += "\nERROR: Se requiere una CONTRASEÑA de usuario.";
		form.password_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarFormDocumentos(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (!form.fecha_form.value.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/)) {
		textError += "\nERROR: FECHA no valida!.";
		form.fecha_form.focus();
		allOK = false;
	}

	if (form.titulo_form.value=="") {
		textError += "\nERROR: Se requiere un TITULO de documento.";
		form.titulo_form.focus();
		allOK = false;
	}

	if (form.documento_form.value=="") {
		textError += "\nERROR: Se requiere un Documento (PDF).";
		form.documento_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarFormUpdateDocumentos(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (!form.fecha_form.value.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/)) {
		textError += "\nERROR: FECHA no valida!.";
		form.fecha_form.focus();
		allOK = false;
	}

	if (form.titulo_form.value=="") {
		textError += "\nERROR: Se requiere un TITULO de documento.";
		form.titulo_form.focus();
		allOK = false;
	}

	if ((form.update_documento.checked) && (form.documento_form.value=="")) {
		textError += "\nERROR: Se requiere un Documento (PDF).";
		form.documento_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarFormNoticias(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.fecha_form.value=="") {
		textError += "\nERROR: Se requiere una fecha.";
		form.fecha_form.focus();
		allOK = false;
	}

	if (form.titulo_form.value=="") {
		textError += "\nERROR: Se requiere un titulo de noticia.";
		form.titulo_form.focus();
		allOK = false;
	}

	if (form.texto_form.value=="") {
		textError += "\nERROR: Se requiere un texto de noticia.";
		form.texto_form.focus();
		allOK = false;
	}

	if (!comprobarFecha(form.fecha_form)) {
		textError += "\nERROR: Fecha Invalida!.";
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};

function comprobarFormClientes(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.nombre_form.value=="") {
		textError += "\nERROR: Se requiere un nombre de empresa.";
		form.nombre_form.focus();
		allOK = false;
	}

	if (form.user_form.value=="") {
		textError += "\nERROR: Se requiere un nombre de usuario.";
		form.user_form.focus();
		allOK = false;
	}

	if (form.pass_form.value=="") {
		textError += "\nERROR: Se requiere un password.";
		form.pass_form.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 de contacto.";
		document.contactar.telcontacto.focus();
		allOK = false;
	}

	if (document.contactar.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.contactar.email.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.contactar.email)) {
		
		
		allOK = false;
		}
	
	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarbolsatrabajo() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.bolsatrabajo.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.bolsatrabajo.nombre.focus();
		allOK = false;
	}

	if (document.bolsatrabajo.telcontacto1.value=="") {
		textError += "\nERROR: Se requiere almenos un Teléfono de contacto.";
		document.bolsatrabajo.telcontacto1.focus();
		allOK = false;
	}

	if (document.bolsatrabajo.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.bolsatrabajo.email.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.bolsatrabajo.email)) {
		allOK = false;
		}
	
	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarpresupuesto() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.presupuesto.empresa.value=="") {
		textError = "ERROR: Se requiere un nombre de Empresa.";
		document.presupuesto.empresa.focus();
		allOK = false;
	}

	if (document.presupuesto.contacto.value=="") {
		textError += "\nERROR: Se requiere una persona de contacto.";
		document.presupuesto.contacto.focus();
		allOK = false;
	}

	if (document.presupuesto.telcontacto.value=="") {
		textError += "\nERROR: Se requiere un teléfono de contacto.";
		document.presupuesto.telcontacto.focus();
		allOK = false;
	}

	if (document.presupuesto.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.presupuesto.email.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.presupuesto.email)) {
		allOK = false;
		}

	if (document.presupuesto.numfolletos.value=="") {
		textError += "\nERROR: Se requiere una catidad de folletos.";
		document.presupuesto.numfolletos.focus();
		allOK = false;
	}

	if (document.presupuesto.zonasreparto.value=="") {
		textError += "\nERROR: Se requiere alguna zona de reparto.";
		document.presupuesto.zonasreparto.focus();
		allOK = false;
	}

	if (document.presupuesto.tipofolleto.value=="") {
		textError += "\nERROR: Se requiere un tipo de folleto.";
		document.presupuesto.tipofolleto.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarregistro() {

	//Flag de allOK
	var allOK = true;
	var textError = "";

	if (document.registro.nombre.value=="") {
		textError = "ERROR: Se requiere un Nombre.";
		document.registro.nombre.focus();
		allOK = false;
	}

	if (document.registro.apellidos.value=="") {
		textError += "\nERROR: Se requieren unos Apellidos.";
		document.registro.apellidos.focus();
		allOK = false;
	}

	if (document.registro.empresa.value=="") {
		textError += "\nERROR: Se requiere un nombre de Empresa.";
		document.registro.empresa.focus();
		allOK = false;
	}
	
	if (document.registro.direccion.value=="") {
		textError += "\nERROR: Se requiere una Dirección.";
		document.registro.direccion.focus();
		allOK = false;
	}

	if (document.registro.codpostal.value=="") {
		textError += "\nERROR: Se requiere un Código Postal.";
		document.registro.codpostal.focus();
		allOK = false;
	}

	if (document.registro.localidad.value=="") {
		textError += "\nERROR: Se requiere una Localidad.";
		document.registro.localidad.focus();
		allOK = false;
	}

	if (document.registro.provincia.value=="") {
		textError += "\nERROR: Se requiere una Provincia.";
		document.registro.provincia.focus();
		allOK = false;
	}

	if (document.registro.pais.value=="") {
		textError += "\nERROR: Se requiere un País.";
		document.registro.pais.focus();
		allOK = false;
	}

	if (document.registro.telcontacto3.value=="") {
		textError += "\nERROR: Se requiere un Teléfono de Contacto.";
		document.registro.telcontacto3.focus();
		allOK = false;
	}

	if (document.registro.email.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.registro.email.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.registro.email)) {
		allOK = false;
		}

	if (document.registro.user.value=="") {
		textError += "\nERROR: Es obligatorio que elija un Nombre de Ususario.";
		document.registro.user.focus();
		allOK = false;
	}

	if (document.registro.pass.value=="") {
		textError += "\nERROR: Es obligatorio que elija una contraseña de Acceso.";
		document.registro.pass.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);
};
