function SlideColors(img,j) {
	
	var mifoto = "/images/colores/"+j+".gif";

	if (document.all) {
		document.getElementById(img).filters.blendTrans.apply() 
		document.getElementById(img).src=mifoto
		document.getElementById('t_colores').innerHTML = document.getElementById('t_colores_'+j).innerHTML;
		document.getElementById(img).filters.blendTrans.play() 
	} else {
		document.getElementById(img).src=mifoto
		document.getElementById('t_colores').innerHTML = document.getElementById('t_colores_'+j).innerHTML;
	}

	if (j<7) {
		j=j+1;
	} else {
		j=1;
	}

	setTimeout("SlideColors('"+img+"',"+j+")", 2000);

	

}



function ShowHome() {
	SlideTd('td_1_oe','/images/bg_verde.gif');
	SlideTd('td_2_oe','/images/sep.gif');
	SlideTd('td_3_oe','/images/sep_2.gif');
	setTimeout("STabla('m_clientes','m_clientes_auth')", 1000);
	setTimeout("STabla('c_contenidos','index_2')", 1000);
	setTimeout("STabla('index_2','m_vacio')", 1000);
	setTimeout("SlideColors('img_color',1)", 1000);

}

function SlideTd(i,j,n) {
	if (document.all) {
		document.getElementById(i).filters.blendTrans.apply()
		document.getElementById(i).style.background='url('+j+')'
		document.getElementById('slideshow_oe').style.visibility='visible';
		// document.getElementById('c_contenidos').style.display='none';
		STabla('m_principal','m_catalogo');
		document.getElementById(i).filters.blendTrans.play()
	} else {
		document.getElementById(i).style.background='url('+j+')'
		document.getElementById('slideshow_oe').style.visibility='visible';
		// document.getElementById('c_contenidos').style.display='none';
		STabla('m_principal','m_catalogo');
	}
}



function manda_email() {
	window.location.href=String.fromCharCode(109,97,105,108,116,111,58,98,97,115,101,99,111,110,101,120,12521536/195649,98,97,115,101,99,111,110,101,120,46,99,111,109);
}

function validaConsulta() {
	var ok=0;
	var campo_actual="";

	var ff=window.document.Registro;
	validacion = /[^a-z-.@0-9A-Z áéíóúÁÉÓÚ+-¿?!¡]/g;
	validacionTelefono = /[^+ 0-9]/g;

	if (ff.Empresa.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Empresa'.\n");
	} else {
		if (validacion.test(ff.Empresa.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Empresa'.\n");
		}
	}


	if (ff.Persona_de_Contacto.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Persona de Contacto'.\n");
	} else {
		if (validacion.test(ff.Persona_de_Contacto.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Persona de Contacto'.\n");
		}
	}


	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'eMail'.\n");
	}


	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}


	if (ff.consulta.value.length < 5){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Consulta'.\n");
	} else {
		if (validacion.test(ff.consulta.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Consulta'.\n");
		}
	}



	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;
	}


}


function validaRegistro() {
	var ok=0;
	var campo_actual="";

	var ff=window.document.Registro;
	validacion = /[^a-z-.@0-9A-Z áéíóúÁÉÓÚ,.]/g;
	validacionTelefono = /[^+ 0-9]/g;

	if (ff.Empresa.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Empresa'.\n");
	} else {
		if (validacion.test(ff.Empresa.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Empresa'.\n");
		}
	}


	if (ff.Persona_de_Contacto.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Persona de Contacto'.\n");
	} else {
		if (validacion.test(ff.Persona_de_Contacto.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Persona de Contacto'.\n");
		}
	}


	if (ff.login.value.length < 3){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Identificador de usuario deseado'.\n");
	} else {
		if (validacion.test(ff.login.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Identificador de usuario deseado'.\n");
		}
	}


	if (checkEmail(ff.eMail.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'eMail'.\n");
	}

	if (checkEmail(ff.email_2.value)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'eMail (repítalo)'.\n");
	}

	if (ff.eMail.value != ff.email_2.value){
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\nLos eMails facilitados no coinciden.\n");
	}

	if (validacionTelefono.test(ff.Telefono.value) || (ff.Telefono.value.length<6)) {
		ok=1;
		alert("Se ha detectado un error en la validación del formulario de datos :\n\nRellene correctamente el campo 'Teléfono'.\nLos únicos caracteres válidos para este campo son '+', ' ' y números del 0 al 9\n\n");
	}


	if (ff.NIF.value.length == 9 ){
		if ( !(CalculaNif(ff.NIF.value) || CalculaCif(ff.NIF.value) || CalculaNie(ff.NIF.value)) ) {
			ok=1;
			alert("Se ha detectado un error en la inserción de datos del fomulario.\nRevise atentamente el campo 'NIF / CIF / NIE'\n\n");
		} else {
			ff.NIF.value = ff.NIF.value.toUpperCase();
		}
	} else {
		ok=1;
		alert("Se ha detectado un error en la inserción de datos del fomulario.\nRevise atentamente el campo 'NIF / CIF / NIE'\n\n");
	}


	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;
	}


}


function borraConsulta() {
	var ff=window.document.Registro;
	ff.Empresa.value="";
	ff.Persona_de_Contacto.value="";
	ff.Telefono.value="";
	ff.eMail.value="";
	ff.consulta.value="";
}



function borraRegistro() {
	var ff=window.document.Registro;
	ff.Empresa.value="";
	ff.Persona_de_Contacto.value="";
	ff.login.value="";
	ff.Telefono.value="";
	ff.NIF.value="";
	ff.eMail.value="";
	ff.email_2.value="";
}



function ilumina(imagen,base_imagen) {
	if ((document.images[imagen].src.indexOf("_i.gif")) > -1) {
		MM_swapImage(imagen,'',base_imagen+'.gif',1);
	} else {
		MM_swapImage(imagen,'',base_imagen+'_i.gif',1);
	}
}

function validaAuth() {
	var ok=0;
	var campo_actual="";

	var ff=window.document.mi_form;
	validacion = /[^a-z-.@0-9A-Z]/g;

	if (ff.usuario.value.length >0){
		if (validacion.test(ff.usuario.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Usuario'.\n");
		}
	}

	if (ff.passwd.value.length >0){
		if (validacion.test(ff.passwd.value)) {
			ok=1;
			alert("Se ha detectado un error en la validación del formulario de datos :\nRellene correctamente el campo 'Usuario'.\n");
		}
	}

	if (ok==0){
		ff.submit();
	} else {
		event.returnValue=false;
	}


}



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 MM_showHideLayers() { //v2.0
   var i, visStr, args, theObj;
   args = MM_showHideLayers.arguments;
   for (i=0; i<(args.length-2); i+=3) { //with arg triples (objNS,objIE,visStr)
     visStr   = args[i+2];
     if (navigator.appName == 'Netscape' && document.layers != null) {
       theObj = eval(args[i]);
       if (theObj) theObj.visibility = visStr;
     } else if (document.all != null) { //IE
       if (visStr == 'show') visStr = 'visible'; //convert vals
       if (visStr == 'hide') visStr = 'hidden';
       theObj = eval(args[i+1]);
       if (theObj){
		pageWidth=(ie)?document.body.offsetWidth:innerWidth;
		theObj.style.left=(pageWidth - 780)/2;
		theObj.style.visibility = visStr;
		}
  } }
}

function SlidePic(img,j) {
	if (document.all) {
		document.getElementById(img).filters.blendTrans.apply() 
		document.getElementById(img).src=j
		document.getElementById(img).filters.blendTrans.play() 
	} else {
		document.getElementById(img).src=j
	}
}

function STabla(tbl1,tbl2) {
	if (document.all) {
		document.getElementById(tbl1).filters.blendTrans.apply() 
		document.getElementById(tbl1).innerHTML = document.getElementById(tbl2).innerHTML;
		document.getElementById(tbl1).filters.blendTrans.play() 
	} else {
		document.getElementById(tbl1).innerHTML = document.getElementById(tbl2).innerHTML;
	}

	if (tbl2 == 'm_clientes_auth') {
		document.getElementById(tbl1).innerHTML = document.getElementById(tbl1).innerHTML.replace('oeoeoeoe','');
	}
}


function MM_displayStatusMsg(msgStr) {
   status=msgStr;
   document.MM_returnValue = true;
}

function rnulo() {
}


function checkEmail(emailStr) {
   if (emailStr.length == 0)
     return true;
   var emailPat=/^(.+)@(.+)$/;
   var specialChars="()<>@,;:\".[]";
   var validChars="[^s" + specialChars + "]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^(d{1,3})[.](d{1,3})[.](d{1,3})[.](d{1,3})$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(." + atom + ")*$");
   var matchArray=emailStr.match(emailPat);

   if (matchArray == null)
      return false;

   var user=matchArray[1];
   var domain=matchArray[2];

   if (user.match(userPat) == null)
      return false;

   var IPArray = domain.match(ipDomainPat);
   if (IPArray != null) {
      for (var i = 1; i <= 4; i++) {
         if (IPArray[i] > 255)
         	return false;
   		}

   return true;
	 }

   var domainArray=domain.match(domainPat);
   if (domainArray == null)
      return false;

   var atomPat=new RegExp(atom,"g");
   var domArr=domain.match(atomPat);
   var len=domArr.length;

   if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 3)
      return false;

   if (len < 2)
      return false;

   return true;
}


function CalculaNifCif(nif) {
	nif = replaceSubstring(nif, " ", "");
	nif = replaceSubstring(nif, "-", "");
	nif = replaceSubstring(nif, ".", "");
	if ( !(CalculaNif(nif) || CalculaCif(nif) || CalculaNie(nif)) ) {
		alert("El NIF / CIF / NIE insertado no es válido.\n");
	} else {
		window.document.FClientes.NIF.value = nif.toUpperCase();
	}
}

function CalculaNie(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';

	var letraNie    = nif.substring(0,1);
	var dni    = nif.substring(1,8);
	var letraNif = nif.substring(8,9);
	var letraAux;
	var letraInicio="X";

	var numero = dni%23;

	letraAux = letras.substring(numero,numero+1);

	if ( (letraAux == letraNif.toUpperCase()) && (letraInicio==letraNie.toUpperCase()) ) {
		return true;
	}else{
		return false;
	}
}
function CalculaNif(nif){
	var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';

	var dni    = nif.substring(0,8);
	var letraNif = nif.substring(8,9);
	var letraAux;

	var numero = dni%23;

	letraAux = letras.substring(numero,numero+1);

	if(letraAux == letraNif.toUpperCase()){
		return true;
	}else{
		return false;
	}
}


function CalculaCif(elCIF)
  {
    var resul = false;
    var temp = elCIF.toUpperCase();

    if (!/^[A-Za-z0-9]{9}$/.test(temp)) {
      resul = false;
    } else {
    	if (!/^[ABCDEFGHKLMNPQS]/.test(temp)) {
    	  resul = false;
		} else {
		  resul = ValidaCIF(temp);
    	}
    }
    return resul;
}


function ValidaCIF(elCIF)
  {
  	var resul = false;
    var v1 = new Array(0,2,4,6,8,1,3,5,7,9);

    var temp = 0;
    var temp1;

    for( i = 2; i <= 6; i += 2 )
    {
      temp = temp + v1[ parseInt(elCIF.substr(i-1,1)) ];
      temp = temp + parseInt(elCIF.substr(i,1));
    }

    temp = temp + v1[ parseInt(elCIF.substr(7,1)) ];
    temp = (10 - ( temp % 10));

    if( temp == 10 ) {
      if ((elCIF.substring(8,9)=="J") || (elCIF.substring(8,9)=="0")) {
      	resul = true;
      } else {
      	resul = false;
      }
    } else {
      if (elCIF.substring(8,9)==temp) {
      	resul = true;
      } else {
      	resul = false;
      }
	}
	return resul;
  }

