
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://benjamin.bevia.net"; 
      var titulo="FOBOSTEC ::: Diseño WEB Profesional";
      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 informes de seguimiento \ndel cliente: '+nombre+' ?.'))
	{
		window.location = "http://www.aliproser.es/admin/informes_deleteall.php?id_cliente="+id;
	}
};

//filtra los informes por el cliente seleccionado en el dropdown
function filtrarClientes(){
	id_cliente = document.clientes.clientes_form.options[document.clientes.clientes_form.selectedIndex].value;
	window.location = "http://www.aliproser.es/admin/informes_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-z]+([_\\.-][a-z]+)*@([a-z]+([\.-][a-z]+)*)+.[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 comprobarFormInformes(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.titulo_form.value=="") {
		textError += "\nERROR: Se requiere un Titulo de informe.";
		form.titulo_form.focus();
		allOK = false;
	}

	if (!comprobarFecha(form.fecha_form)) {
		textError += "\nERROR: Fecha Invalida!.";
		allOK = false;
	}

	if (form.informe_form.value=="") {
		textError += "\nERROR: Se requiere un informe de seguimiento (PDF).";
		form.informe_form.focus();
		allOK = false;
	}

	if (!allOK)
		alert(textError);

	return allOK;
};


function comprobarFormUpdateInformes(formulario) {

	//Flag de allOK
	var allOK = true;
	var textError = "";
	form = document.getElementById(formulario);

	if (form.titulo_form.value=="") {
		textError += "\nERROR: Se requiere un Titulo de informe.";
		form.titulo_form.focus();
		allOK = false;
	}

	if (!comprobarFecha(form.fecha_form)) {
		textError += "\nERROR: Fecha Invalida!.";
		allOK = false;
	}

	if ((form.informe_update.checked) && (form.informe_form.value=="")) {
		textError += "\nERROR: Se requiere un informe de seguimiento (PDF).";
		form.informe_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.asunto.value=="") {
		textError += "\nERROR: Se requiere un texto para el Asunto.";
		document.contactar.asunto.focus();
		allOK = false;
	}
	
	if (document.contactar.cuerpo.value=="") {
		textError += "\nERROR: Se requiere un texto para el Cuerpo del mensaje.";
		document.contactar.cuerpo.focus();
		allOK = false;
	}

	if (document.contactar.el_correo_ele.value=="") {
		textError += "\nERROR: Se requiere un e-mail.";
		document.contactar.el_correo_ele.focus();
		allOK = false;
	}
	
		if (!comprobarEmail(document.contactar.el_correo_ele)) {
		
		
		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 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);
};

