

// ************************************************* FUNCIONES COMUNES DE JAVASCRIPT *************************************
//funcion validar formulario propia para el formulario de bolsa de empleo 
function validar_formulario_contacto(form) { 
  resultado = false; 
  if(form.nombre.value == '' ){
      return alert('Por favor introduzca su Nombre');
  }else{  
      if (form.apellidos.value == "")  {
          return alert('Por favor introduzca sus Apellidos');
      }else{
          if (form.telefono.value == ''){
	          return alert('Por favor introduzca un Teléfono de contacto');
              }else{
	      if ((form.correo.value == "") || (form.correo.value.indexOf('@') == -1) || (form.correo.value.indexOf('.') == -1)) {
	          return alert('Por favor rellene correctamente el campo Email, es obligatorio.');              
	      }else{ 	      
	          if (form.asunto.value == ''){
		      return alert('Por favor indique el asunto de su consulta');
		  }else{
		      if (confirm('¿Está seguro de enviar el formulario?')){
		          return form.submit();					  	      			
		      }
		  }
	      }
	  }
      }
  } 
}
function validar_formulario_presupuesto(form) { 
  resultado = false; 
  if(form.nombre.value == '' ){
      return alert('Por favor introduzca su Nombre');
  }else{  
      if (form.apellidos.value == "")  {
          return alert('Por favor introduzca sus Apellidos');
      }else{
          if (form.telefono2.value == ''){
	          return alert('Por favor introduzca un Teléfono de contacto');
              }else{
	      if ((form.correo.value == "") || (form.correo.value.indexOf('@') == -1) || (form.correo.value.indexOf('.') == -1)) {
	          return alert('Por favor rellene correctamente el campo Email, es obligatorio.');              
	      }else{ 	      
	          if (form.observaciones.value == ''){
		      return alert('Por favor indique las observaciones');
		  }else{
		      if (confirm('¿Está seguro de enviar el formulario?')){
		          return form.submit();					  	      			
		      }
		  }
	      }
	  }
      }
  } 
}
function validar_formulario_empleo(form) { 
  resultado = false; 
  if(form.nombre.value == '' ){
      return alert('Por favor introduzca su Nombre');
  }else{  
      if(form.apellidos.value == '' ){
          return alert('Por favor introduzca sus Apellidos');
      }else{ 
          if(form.fecha_nacimiento.value == '' ){
	      return alert('Por favor introduzca su Fecha de Nacimiento');
	  }else{ 
	      if(form.telefono.value == '' ){
	          return alert('Por favor introduzca un Teléfono de Contacto');          
              }else{
	          if ((form.correo.value == "") || (form.correo.value.indexOf('@') == -1) || (form.correo.value.indexOf('.') == -1)) {
		      return alert('Por favor rellene correctamente el campo Email, es obligatorio.');              
		  }else{
		      if(form.direccion.value == '' ){
		          return alert('Por favor introduzca su Dirección');          
		      }else{
		          if(form.codigo.value == '' ){
			      return alert('Por favor introduzca su Código Postal');          
			  }else{
			      if(form.ciudad.value == '' ){
	                          return alert('Por favor introduzca la Ciudad');          
			      }else{
			          if(form.provincia.value == '' ){
				      return alert('Por favor introduzca la Provincia');          
				  }else{
				      if (confirm('¿Está seguro de enviar el formulario?')){
				          return true;			  
				      }else{
				          return false;
				      }
				  }
			      }
			  }
		      }
		  }
	      }
	  }
      }
   }
}

//CAMBIACOLOR_CELDA: Se le pueden pasar 2 objetos para el caso en que se
//use para cambiar el color en un marcador u omitiendo el objeto2 y usándola, 
//por ejemplo, en un menu para resaltar la celda
function cambiacolor_celda(objeto,color,puntero,objeto2){
    objeto.style.backgroundColor = color;    
    objeto2.style.cursor = puntero;
}

//CAMBIA_IMG: se pasa el objeto y la img con ruta 
function cambia_img(objeto,img){
  objeto.src=img;
  objeto.style.cursor='pointer';
}
// CAMBIAIMAGEN_CELDA cambiar la imagen de background de una objeto
function cambiaimagen_celda(objeto,imagen,puntero){
  objeto.style.background = "url("+imagen+")";
  objeto.style.cursor = puntero;
}



function confirmaBorrado () {
  if (confirm('¿Está seguro de eliminar el registro seleccionado?')){
    return true
  } else {
    return false
  }
}

//función abre ventana sin barra de herramientas
function abrir_ventana (pagina) {
var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=500, height=600, top=85, left=140";
window.open(pagina,"",opciones);
}

/************************************* FUNCIONES PARA AJAX ***************************************************** */
var RUTA_RAIZ='http://www.avant-desarrollo.com';
var net = new Object();
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;

// Constructor
net.CargadorContenidos = function(url, funcion, metodo, parametros,contentType,funcionError) {
    this.url = url;
    this.req = null;
    this.onload = funcion;
    this.onerror = (funcionError) ? funcionError : this.defaultError;
    this.cargaContenidoXML(url, metodo, parametros, contentType);
}

net.CargadorContenidos.prototype = {
    cargaContenidoXML: function(url, metodo, parametros, contentType) {
	if (window.XMLHttpRequest) {
	    this.req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	    this.req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if(this.req) {
	    try {
		var loader = this;
		this.req.onreadystatechange = function() {
		    loader.onReadyState.call(loader);
		}
		this.req.open(metodo, url, true);
		if(contentType) {
		    this.req.setRequestHeader("Content-Type", contentType);
		}
		this.req.send(parametros);
	    } catch (err) {
		this.onerror.call(this);
	    }
	}
    },onReadyState: function() {
	var req = this.req;
	var ready = req.readyState;
	if (ready == net.READY_STATE_COMPLETE) {
	    var httpStatus = req.status;
	    if(httpStatus == 200 || httpStatus == 0) {
		this.onload.call(this);
	    }else {
		this.onerror.call(this);
	    }
	}
    },defaultError: function() {
	alert("Se ha producido un error al obtener los datos" + "\n\nreadyState:" + this.req.readyState	+ "\nstatus: " + this.req.status + "\nheaders: " + this.req.getAllResponseHeaders());
    }
}
