// JavaScript Document

///////////////////////////////////////
///  Cambio de select               ///
///////////////////////////////////////

var xOp7Up,xOp6Dn,xIE4Up,xIE4,xIE5,xNN4,xUA=navigator.userAgent.toLowerCase();if(window.opera){var i=xUA.indexOf('opera');if(i!=-1){var v=parseInt(xUA.charAt(i+6));xOp7Up=v>=7;xOp6Dn=v<7;}}else if(navigator.vendor!='KDE' && document.all && xUA.indexOf('msie')!=-1){xIE4Up=parseFloat(navigator.appVersion)>=4;xIE4=xUA.indexOf('msie 4')!=-1;xIE5=xUA.indexOf('msie 5')!=-1;}else if(document.layers){xNN4=true;}xMac=xUA.indexOf('mac')!=-1;
function enviar(){
	window.document.frm.submit();
}



function xGetElementById(e){if(typeof(e)!='string') return e;if(document.getElementById) e=document.getElementById(e);else if(document.all) e=document.all[e];else e=null;return e;}

function xInnerHtml(e,h){if(!(e=xGetElementById(e)) || !xStr(e.innerHTML)) return null;var s = e.innerHTML;if (xStr(h)) {e.innerHTML = h;}return s;}
function xStr(s){for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}return true;}



function Cambia_texto(texto,valor){

 xInnerHtml('tipo_obra',texto);
 document.getElementById('desplegable').style.visibility = 'hidden';
 window.document.formulario_presupuesto.tipo_obra_id.value=valor;
 window.document.formulario_presupuesto.tipo_obra_nombre.value=texto;
}





///////////////////////////////////////////////
///// Compruebo que todos los datos obligatorios estan rrellenos
///////////////////////////////////////////////
function comprobar_formulario(formulario){
 var text="Han ocurrido los siguientes errores: ";
 var bien=true;

  if (formulario.presupuestos_nombre.value.length==0){
		   bien=false;
		   text+="\n   * Escribir Nombre."; 
	}		


	 if (formulario.presupuestos_email.value.length==0){
	   bien=false;
	   text+="\n   * Escribir E-mail.";
	 }else{
		 if (!validarEmail(formulario.presupuestos_email.value)){
				bien=false;
				text+="\n   * Formato del e-mail es incorrecto.";
			 }
	 }


 	if (formulario.tipo_obra_id.value=="0"){
		   bien=false;
		   text+="\n   * Selecionar tipo de proyecto.";
		}	
		
 	if (formulario.presupuestos_observaciones.value.length==0){
		   bien=false;
		   text+="\n   * Escribir Observaciones.";
		}		



  if (bien==true){
    formulario.submit();
  }  else{
   alert(text);
  }
}



	function validarEmail(valor)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor))
		{
			return (true)
		} 
		else 
		{
	    	return (false);
	  	}
	 }


