// JavaScript Document

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function verIdentificarse(){
	document.getElementById("fondoBlanco").style.height=document.body.scrollHeight;
	document.getElementById('fondoBlanco').style.visibility='visible';
	document.getElementById('formIdent').style.visibility='visible';
	}
function  ocultarIdentificarse(){
	document.getElementById('fondoBlanco').style.visibility='hidden';
	document.getElementById('formIdent').style.visibility='hidden';
	}
function validar(){
	var error=false;
	usr=document.getElementById('usr').value;
	clave=document.getElementById('clave').value;

	if (usr==""){
		error=true;
		alert('Ha de escribir un usuario.');
	}
	if ((clave=="")&&(!error)){
		alert('Ha de escribir una clave.');
		error=true;
	}else if ((clave!="") && ((clave.length<6) ||  (clave.length>9))){
			alert('Ha de escribir una clave entre 6 y 9 caracteres');
			error=true;
	}
	if (!error){
		var param='usuario='+usr+'&clave='+clave;
		doAjax('validar.php',param,'resValidar','post','0');
	}
}
function resValidar (res){
	if (res=="ok"){
		document.getElementById('usr').value="";
		document.getElementById('clave').value="";
//		ocultarIdentificarse();
		//abrir2('browser.php', 1000,50);
//		document.write("");
//		doAjax('browser.php','','resBrowser','post','0');
//		document.getElementById('browser').style.visibility='visible';
//		document.getElementById('browser').innerHTML="<iframe src='browser.php' width='800' height='400' scrolling='auto' frameborder='0'></iframe>";
		location.href='zonaclientes.php';
	}else{
		alert(res);
	}
}
function logOut(){
	if(confirm("Desea abandonar la sesion")){	
		doAjax('conex/logout.php','','reslogOut','post','0');
	}
}
function reslogOut(res){
	location.href="./";
}
function resBrowser(res){
//	alert(res);
	document.getElementById('browser').style.visibility='visible';
	document.getElementById('browser').innerHTML=res;
	}
function cerrarBrowser(){
	document.getElementById('browser').innerHTML='';
	document.getElementById('browser').style.visibility='hidden';
}
function cargarOpcion(op){
	// función para porque.html
	var op1_0='<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'diferencial\',\'\',\'img/diferencial_on.gif\',1)"><img src="img/diferencial_off.gif" alt="Valor Diferencial" name="diferencial" width="100" height="17" border="0" id="diferencial" onClick="cargarOpcion(1)" /></a>';
	var op2_0='<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'competitivas\',\'\',\'img/competitivas_on.gif\',1)"><img src="img/competitivas_off.gif" alt="Ventajas Competitivas" name="competitivas" width="115" height="17" border="0" id="competitivas" onClick="cargarOpcion(2)"  /></a>';
	var op3_0='<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'modelo\',\'\',\'img/modelo_on.gif\',1)"><img src="img/modelo_off.gif" alt="Modelo de Trabajo" name="modelo" width="99" height="17" border="0" id="modelo" onClick="cargarOpcion(3)" /></a>';
	var op1_1='<img src="img/diferencial_on.gif" alt="Valor Diferencial" name="diferencial" width="100" height="17" border="0" id="diferencial" />';
	var op2_1='<img src="img/competitivas_on.gif" alt="Ventajas Competitivas" name="competitivas" width="115" height="17" border="0" id="competitivas" />';
	var op3_1='<img src="img/modelo_on.gif" alt="Modelo de Trabajo" name="modelo" width="99" height="17" border="0" id="modelo" />';
	switch(op){
		case (1):document.getElementById('tddiferencial').innerHTML=op1_1;
				 document.getElementById('tdcompetitivas').innerHTML=op2_0;
				 document.getElementById('tdmodelo').innerHTML=op3_0;
				 pag='diferencial.html';
				 break;	
		case (2):document.getElementById('tddiferencial').innerHTML=op1_0;
				 document.getElementById('tdcompetitivas').innerHTML=op2_1;
				 document.getElementById('tdmodelo').innerHTML=op3_0;
				  pag='competitivas.html';
				 break;	
		case (3):document.getElementById('tddiferencial').innerHTML=op1_0;
				 document.getElementById('tdcompetitivas').innerHTML=op2_0;
				 document.getElementById('tdmodelo').innerHTML=op3_1;
				  pag='modelo.html';
				 break;	

	}
	
	document.getElementById('cuerpo').src=pag;
}

function cargarSomos(pag){
// funcion para acercade.html	
//alert(pag);
	var op2_0='<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Filosofía de Empresa\',\'\',\'img/filosofia_on.gif\',1)"><img src="img/filosofia_off.gif" alt="Filosofía de Empresa" name="Filosofía de Empresa" width="116" height="17" border="0" id="Filosofía de Empresa" onclick="cargarSomos(\'filosofia.html\')" /></a>';
	var op2_1='<img src="img/filosofia_on.gif" alt="Filosofía de Empresa" name="Filosofía de Empresa" width="116" height="17" border="0" id="Filosofía de Empresa" />';
	var op1_0='<a href="#" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Somos\',\'\',\'img/somos_on.gif\',1)"><img src="img/somos_off.gif" lt="¿Quienes Somos?" width="100" height="17" name="Somos" id="Somos"  border="0" onclick="cargarSomos(\'somos.html\')" /></a>';
	var op1_1='<img src="img/somos_on.gif" alt="¿Quienes Somos?" width="100" height="17" name="Somos" id="Somos" border="0" />';
	switch (pag){
		case ('filosofia.html'):document.getElementById('tdFilosofia').innerHTML=op2_1;
				 				document.getElementById('tdSomos').innerHTML=op1_0;
								document.getElementById('cuerpo').style.height=550+"px";
								break;
		case ('somos.html'):document.getElementById('tdFilosofia').innerHTML=op2_0;
							document.getElementById('tdSomos').innerHTML=op1_1;
							document.getElementById('cuerpo').style.height=450+"px";
							break;
		}
/*	if(screen.width>1024){
		document.getElementById('tableCont').style.height=490+'px';
	}else{
		document.getElementById('tableCont').style.height=370+'px';
	}
*/	
	
	document.getElementById('cuerpo').src=pag;
	}
function abrir(pag){
	width=800;
	//top=100;
	left=100;
	//height='+height+',
	window.open(pag, 'popUpWin', 'toolbar=no,scrollbars=yes ,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=yes,width='+width+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
//	  popUpWin = open(pag, 'popUpWin', 'toolbar=no,scrollbars=yes ,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=yes,width='+width+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}
function abrir2(pag, ancho, izq){
	width=ancho;
	//top=100;
	left=izq;
	//height='+height+',
	  popUpWin = open(pag, 'popUpWin', 'toolbar=no,scrollbars=yes ,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=yes,width='+width+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');

}

function ancho(){
	if(screen.width>1024){
		document.getElementById('tableCont').style.height=490+'px';
	}else{
		document.getElementById('tableCont').style.height=370+'px';
	}	
}
function validarContacto(formname){
	var error=false;
	var nombre=document.getElementById('nombre');
	var apellidos=document.getElementById('apellidos');
	var email=document.getElementById('email');
	var tlf=document.getElementById('tlf');
	var mensaje=document.getElementById('mensaje');
	var pagina=document.getElementById('pagina').value;
	
	if (nombre.value==""){
		error=true;
		alert('Ha de escribir su nombre.');
		nombre.focus();
	}
	if ((apellidos.value=="")&&(!error)){
		alert('Ha de escribir sus apellidos.');
		apellidos.focus();
		error=true;
	}
	if ((tlf.value=="")&&(!error)){
		alert('Ha de escribir un teléfono de contacto.');
		tlf.focus();
		error=true;
	}else if ((!error)&&(tlf.value!="") && !isFinite(tlf.value)){
		alert('Ha de escribir un telefono de 9 digitos.');
		tlf.focus();
		error=true;
	}
	if ((email.value=="")&&(!error)){
		alert('Ha de escribir su E-mail.');
		email.focus();
		error=true;
	}else if((email.value!="")&&(!error)){
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
				
		}else{
			alert('Ha de escribir un E-mail correcto.');
			email.focus();
			error=true;
			}
	}
	if ((mensaje.value=="")&&(!error)){
		alert('Ha de escribir un mensaje de contaco.');
		mensaje.focus();
		error=true;
	}	
	if (!error){
		//document.getElementById(formname).submit();
		var param='nombre='+nombre.value+'&apellidos='+apellidos.value+'&tlf='+tlf.value+'&email='+email.value+'&mensaje='+mensaje.value+'&pagina='+pagina+'&formulario='+formname;
		if(document.getElementById('btnEnviar')){
			document.getElementById('btnEnviar').innerHTML="enviando...";
		}
		if(formname=='formLandin'){
			doAjax('enviarEmail.php',param,'resValidarLandin','post','0');
		}else if(formname=='formSubvenciones'){
			doAjax('enviarEmail.php',param,'resValidarLandin','post','0');
		}else if(formname=='formSubvencionesEmpresa'){
			doAjax('../enviarEmail.php',param,'resValidarLandin','post','0');			
		}else{
			doAjax('enviarEmail.php',param,'resValidarContacto','post','0');
		}
	}	
}
function resValidarContacto(res){
	var aRes=res.split('#&');
	if(aRes[0]=='ok'){
		alert('Gracias por ponerse en contacto con Caela');
		document.getElementById(aRes[1]).reset();
	}else{
		alert(res);
	}
	if(document.getElementById('btnEnviar')){
			document.getElementById('btnEnviar').innerHTML='<img src="images/btnEnviar.gif" width="80" height="33" border="0" style="cursor:hand; cursor:pointer" onClick=" validarContacto(\'frmContactar\')" title="enviar el formulario">'; 
	}
}
function resValidarLandin(res){
	var aRes=res.split('#&');
	if(aRes[0]=='ok'){
		alert('Gracias, nos pondremos en contacto con usted lo antes posible');
		document.getElementById(aRes[1]).reset();
		ocultarIdentificarse();
	}else{
		alert(res);
	}
	if(document.getElementById('btnEnviar')){
		document.getElementById('btnEnviar').innerHTML='<img src="images/btnEnviar.gif" width="80" height="33" border="0" style="cursor:hand; cursor:pointer" onClick=" validarContacto(\''+aRes[1]+'\')" title="enviar el formulario">'; 	
	}
	}