// JavaScript Document

// Funciones del Dreamwever
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_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_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];}
}
// Funciones del Dreamwever


function popup(ancho,alto,fuente)
{
window.open(fuente,'','menubar=no,directories=no,resizable=no,toolbar=no,scrollbars=no,location=no,left=0,top=0,width='+ancho+',height='+alto);
}

function abrepop(){  
window.open('http://www.hbfsolutions.com/costina/grupo/form_empleo.asp','trabaja','menubar=no,directories=no,resizable=no,toolbar=no,scrollbars=no,location=no,left=0,top=0,width=340,height=250');
//window.open('form_empleo.asp','trabaja','menubar=no,directories=no,resizable=no,toolbar=no,scrollbars=no,location=no,left=0,top=0,width=340,height=250');
}  


function valida(){
if (document.all){
 user=document.all['usuario'].value;
 passvoid=document.all['contra'].value;
}
if ((!document.all)&&(document.getElementById)){
 user=document.getElementById('usuario').value;
 passvoid=document.getElementById('contra').value;
}
if ((user=='')||(passvoid=='')){
if (location.href.indexOf('ingles')!=-1){alert('insert an user and a password, please ...');}
if (location.href.indexOf('galego')!=-1){alert('introduza un usuario e un contrasinal, por favor ...');}
if ((location.href.indexOf('ingles')==-1)&&(location.href.indexOf('galego')==-1)){
alert('indique un cliente y una contraseña, por favor ...');
}

  if (user==''){
   if (document.all){document.all['usuario'].focus();}
   if ((!document.all)&&(document.getElementById)){document.getElementById('usuario').focus();}
  }
  else{
   if (document.all){document.all['contra'].focus();}
   if ((!document.all)&&(document.getElementById)){document.getElementById('contra').focus();}
  }
}
else{
  // condición para que no entren sin el internet explorer
  if (!document.all){
  if (location.href.indexOf('ingles')!=-1){alert('You need Internet Explorer to enter this section ...');}
if (location.href.indexOf('galego')!=-1){alert('Necesítase o Internet Explorer para acceder á sección ...');}
if ((location.href.indexOf('ingles')==-1)&&(location.href.indexOf('galego')==-1)){
alert('Es necesario el internet explorer para acceder a esta sección ...');
}
  
  }
  if (document.all){
		 patron= /\W/ 
		 if ((patron.test(document.all['usuario'].value)==true)||(patron.test(document.all['contra'].value)==true)){
if (location.href.indexOf('ingles')!=-1){alert('insert valid data for user and password ...');}
if (location.href.indexOf('galego')!=-1){alert('introduza datos válidos para cliente e contrasinal ...');}
if ((location.href.indexOf('ingles')==-1)&&(location.href.indexOf('galego')==-1)){
alert('introduzca valores válidos para cliente y contraseña ...');
}
		 document.all['usuario'].value ='';
		 document.all['contra'].value = '';
		 document.all['usuario'].focus();
		 return false;
		 }
		 else{
		 document.all['cliente'].value=document.all['usuario'].value;
		 document.all['cliente_con'].value=document.all['contra'].value;
		 if (location.href.indexOf('ingles')!=-1){alert('This section is off because of updates ...');}
if (location.href.indexOf('galego')!=-1){alert('Esta sección está fora de servicio temporalmente por melloras ...\n\n');}
if ((location.href.indexOf('ingles')==-1)&&(location.href.indexOf('galego')==-1)){
alert('Esta sección está deshabilitada temporalmente por mejoras ...\n\n');
}
		 //document.all['formo'].submit();
		 }
// fin condición para q no entren sin internet explorer			
}
// fin condición para q no entren sin internet explorer
}
}

function enter(){
if (event.keyCode){
if(event.keyCode==13){
if (document.all){
 if(document.all['usuario'].value!=''){
  valida();
 }
 }
 if ((!document.all)&&(document.getElementById)){
 valida();
 }
}
}
/*
// el else de la condición internet explorer 
}
else{
 alert('Se necesita el Internet Explorer para acceder a este servicio ...');
}
*/
}

function valida_formulario(formulario)
{
vacios='';
 if (document.all)
 {
 //////////////////
 email=document.all['email'].value;
     for (i=0;i<document.all[formulario].elements.length;i++)
      {
        valor=document.all[formulario].elements[i].value;
        campo=document.all[formulario].elements[i].name;
		campo=campo.charAt(0).toUpperCase()+campo.substr(1);
		if (campo=='Direccion'){campo='Dirección'};
		if (campo=='Telefono'){campo='Teléfono'};
		if (campo=='Correo'){campo='Email'};
		if ((valor=='')&&(campo!='Empresa')&&(campo!='Observaciones')){vacios+=(' - '+campo+'\n');}
      }
   if (vacios!='')
   { 
    alert('Rellene los siguientes campos, por favor:\n\n'+vacios+'\n\n');
   }
   else
   {  
   
    if (email!='')
	{
	  // Validación del email
      patron_mail_1=/^[0-9,a-z,A-Z]{2,}[@][0-9,a-z,A-Z]{2,}\.[a-z]{3,4}$/
	  patron_mail_2=/^[0-9,a-z,A-Z]{2,}[@][0-9,a-z,A-Z]{2,}\.[0-9,a-z,A-Z]{2,}\.[a-z]{3,4}$/
      if ((!patron_mail_1.test(email))&&(!patron_mail_2.test(email))){
        alert('Indique un email válido, por favor\n\n');
      }
	  else{
	   document.all[formulario].action='http://www.carloscubeiro.com/costina_organica/formo.asp';
	   document.all[formulario].submit();
	  }	 
	}
		
   }
 //////////////////
 }

 if ((!document.all)&&(document.getElementById))
 {

  //////////////////
  email=document.getElementById('email').value;
  
      for (i=0;i<document.forms[0].elements.length;i++)
      {
        valor=document.forms[0].elements[i].value;
        campo=document.forms[0].elements[i].name;
		campo=campo.charAt(0).toUpperCase()+campo.substr(1);
		if (campo=='Direccion'){campo='Dirección'};
		if (campo=='Telefono'){campo='Teléfono'};
		if (campo=='Correo'){campo='Email'};
		if ((valor=='')&&(campo!='Empresa')&&(campo!='Observaciones')){vacios+=(' - '+campo+'\n');}
      }
   if (vacios!='')
   { 
    alert('Rellene los siguientes campos, por favor:\n\n'+vacios+'\n\n');
   }
   else{
    if (email!='')
	{
	  // Validación del email
      patron_mail_1=/^[0-9,a-z,A-Z]{2,}[@][0-9,a-z,A-Z]{2,}\.[a-z]{3,4}$/
	  patron_mail_2=/^[0-9,a-z,A-Z]{2,}[@][0-9,a-z,A-Z]{2,}\.[0-9,a-z,A-Z]{2,}\.[a-z]{3,4}$/
      if ((!patron_mail_1.test(email))&&(!patron_mail_2.test(email))){
        alert('Indique un email válido, por favor\n\n');
      }
	  else{
	   document.forms[0].action='http://www.carloscubeiro.com/costina_organica/formo.asp';
	   document.forms[0].submit();
	  }	 
	}

   }
  //////////////////
  
 }
}


/*

function menu_despl(desplegado,cual,cual_s,cual_ss,cual_sss,va,s_va,ss_vis)
{
if ((document.costina.movie)&&(document.all)){

// Usando las acciones de Flash
  if(desplegado!=''){document.costina.SetVariable('desplegado',Number(desplegado));}
  if(cual!=''){document.costina.SetVariable('cual',Number(cual));}
  if(cual_s!=''){document.costina.SetVariable('cual_s',Number(cual_s));}
  if(cual_ss!=''){document.costina.SetVariable('cual_ss',Number(cual_ss));}
  if(cual_sss!=''){document.costina.SetVariable('cual_sss',Number(cual_sss));}
  if(va!=''){document.costina.SetVariable('_root.smenu0.va',Number(va));}    
  
if (!document.costina.GetVariable('_root.smenu0.va')){
setTimeout(menu_despl(desplegado,cual,cual_s,cual_ss,cual_sss,va,s_va,ss_vis),1000);
}
else{
clearTimeout();
if (ss_vis!=''){
       for (i=1;i<4;i++){
         document.costina.TSetProperty('_root.ssmenu'+i,7, 1);
        }
    }
}
 
}
  // Sin usar las acciones de Flash
else
  {
  cadena_var='';
  if (desplegado!=''){cadena_var+=('?desplegado='+desplegado+'&');}
  if (cual!=''){cadena_var+=('cual='+cual+'&');}
  if (cual_s!=''){cadena_var+=('cual_s='+cual_s+'&');}
  if (cual_ss!=''){cadena_var+=('cual_ss='+cual_ss+'&');}
  if (cual_sss!=''){cadena_var+=('cual_sss='+cual_sss+'&');}
  if (s_va!=''){cadena_var+=('s_va='+s_va+'&');}
  
if (ss_vis!=''){cadena_var+=('ss_vis='+ss_vis+'&');}

 if (document.getElementById('el_menu')){
term_ing=location.href.split('.')[0].substr(location.href.split('.')[0].length-2);
term_gal=location.href.split('.')[0].substr(location.href.split('.')[0].length-3);
fuente='../img/menu_costina_mov.swf';

if (term_ing=='uk'){fuente='../../img/menu_costina_mov_'+term_ing+'.swf';}
if (term_gal=='gal'){fuente='../../img/menu_costina_mov_'+term_gal+'.swf';}

document.getElementById('el_menu').innerHTML='<embed menu="false" name="costina" src="'+fuente+cadena_var+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="330" height="77" swLiveConnect="true"></embed>';
 }

}
}

*/

function galeria(cual,idioma){
ruta='../img/'+cual+'.swf';
if ((idioma=='i')||(idioma=='g')){
ruta+=('?idioma='+idioma);
ruta=ruta='../'+ruta;
}
// Para saber si estamos en idiomas, miramos la terminación de los ficheros
term_ing=location.href.split('.')[0].substr(location.href.split('.')[0].length-2);
term_gal=location.href.split('.')[0].substr(location.href.split('.')[0].length-3);
//if ((term_ing=='uk')||(term_gal=='gal')){ruta='../'+ruta;}
  if (document.multi.movie){
  document.multi.movie=ruta;
  }
  if (!document.multi.movie){
   if (document.getElementById('la_peli')){
  document.getElementById('la_peli').innerHTML='<embed name="multi" menu="false" src="'+ruta+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="330" height="188" swLiveConnect="true"></embed>';
  }
  }
}




