

function _Oversaleweb(dv){

	document.getElementById("salirweb").style.display = "block";
	document.getElementById("salirweb").style.opacity = 1;

}// end function _Oversaleweb

function _Outsaleweb(dv){
	
	document.getElementById("salirweb").style.display = "none";
	document.getElementById("salirweb").style.opacity = 0;	

}// end function _Outsaleweb


function _Over(dv){

	document.getElementById(dv).style.backgroundColor = "#b22e20";
	document.getElementById(dv).getElementsByTagName("a")[0].style.color = "#ffffff";
	//dos formas mas de hacer cambiar el mismo link
	//document.getElementById(dv).childNodes[0].style.color = "#ffffff";
	//document.getElementById(dv).firstChild.style.color = "#ffffff";

}// end function _Over

function _Out(dv){
	
	document.getElementById(dv).style.backgroundColor = "#e0e0e0";
	document.getElementById(dv).getElementsByTagName("a")[0].style.color = "#4c4b4b";
	//dos formas mas de hacer cambiar el mismo link	
	//document.getElementById(dv).childNodes[0].style.color = "#4c4b4b";	
	//document.getElementById(dv).firstChild.style.color = "#4c4b4b";	

}// end function _Out

function _subOver(dv){

	document.getElementById(dv).style.backgroundColor = "#b2554b";
	document.getElementById(dv).getElementsByTagName("a")[0].style.color = "#ffffff";
	//dos formas mas de hacer cambiar el mismo link
	//document.getElementById(dv).childNodes[0].style.color = "#ffffff";
	//document.getElementById(dv).firstChild.style.color = "#ffffff";

}// end function _Over

function _subOut(dv){
	
	document.getElementById(dv).style.backgroundColor = "#d2d1d1";
	document.getElementById(dv).getElementsByTagName("a")[0].style.color = "#b52c1e";
	//dos formas mas de hacer cambiar el mismo link	
	//document.getElementById(dv).childNodes[0].style.color = "#4c4b4b";	
	//document.getElementById(dv).firstChild.style.color = "#4c4b4b";	

}// end function _Out



/**** Funciones para cambiar estilos en onmuoseover y onmouseout, cambia las pestaņas para los eventos over y normal****/


function _Overpst(node, pst){


	if(node!="" && pst!=""){
		document.getElementById(pst).style.backgroundImage = "url(img/bt"+node+".gif)";
	}

	
}//end function _Overpst


function _Outpst(node, pst){

	var chr;
	var str;
	
	chr = node.indexOf("-");
	str = node.substring(0,chr);


	document.getElementById(pst).style.backgroundImage = "url(img/bt"+str+".gif)";
	
}//end function _Outpst


function _Showpst(node){
	
/** -----------------------------------------------------

Programado para la cantidad de pestaņas que quieras
muestra una capa y oculta el resto.
introduce en el array la cantidad de pestaņa que uses

------------------------------------------------------ **/
	
	var chr;
	var str;
	var ln;		
	var btns = new Array("01","02","03"); 
	var num;
	var tmp;
	
	chr = node.indexOf("over");
	ln = node.length;
	str = node.substring(chr+4,ln);

	num = btns.length;

	for(i=0; i<num; i++){
		
		if(btns[i] == str){
			
			document.getElementById("pstbt"+str).style.visibility = "visible";			
			
		}else{
			tmp = btns[i];
			document.getElementById("pstbt"+tmp).style.visibility = "hidden";		
		
		}//end if
	
	}//end for(i=0; i<=num; i++)
	
	
}//end function _Showpst


/**** Precarga de Imagenes ****/

var i;
var imgs = new Array("img/bt01-over02.gif","img/bt01-over03.gif","img/bt02-over01.gif","img/bt02-over03.gif","img/bt03-over01.gif","img/bt03-over02.gif"); 
var imglist = new Array(); 

function _Preloadimgs(){

   for(i in imgs){
     imglist[i] = new Image();
     imglist[i].src = imgs[i];

   } 

}//end function _Preloadimgs


/**** Funciones para cambiar estilos en onmuoseover y onmouseout ****/

function _Bgfilaover(lista){

	//alert(lista);
	var lnktr = 0; /* cantidad de links del tr */
	var lnkcolor = 0; /* color del link que habia antes de seleccionarlo */
	
	lista.style.backgroundColor = '#ececec';
	lista.style.color = '#ac3a2f';

	//saca la cantidad de links en el tr y los pinta todos
	lnktr = lista.getElementsByTagName("a").length;
	for (i=0; i!=lnktr; i++){
		
		//no necesitas array son el mismo color en toda la fila
		lnkcolor = lista.getElementsByTagName("a")[i].style.color;
		document.getElementById("hidden1").value = lnkcolor;
		lista.getElementsByTagName("a")[i].style.color = "#ac3a2f";
		
	}//end for

	/*
	lista.getElementsByTagName("A")[0].style.color = "#006690";
	lista.getElementsByTagName("A")[1].style.color = "#006690";	
	*/
	
}//end function _Bgfilaover


function _Bgfilaout(lista){

	
	//alert(lista);
	var lnktr = 0; /* cantidad de links del tr */
	var lnkcolor = 0; /* color del link que habia antes de seleccionarlo */
	

	
	lnkcolor = document.getElementById("hidden1").value;	
	lista.style.backgroundColor = '#f5f5f5';
	lista.style.color = '#5e5e5e';

	lnktr = lista.getElementsByTagName("a").length;
	for (i=0; i!=lnktr; i++){
		lista.getElementsByTagName("a")[i].style.color = lnkcolor;
	}//end for
	
	// vacia el valor del hidden
	document.getElementById("hidden1").value = '#5e5e5e';
	/*
	lista.getElementsByTagName("A")[0].style.color = "#666666";
	lista.getElementsByTagName("A")[1].style.color = "#666666";
	*/
	
}//end function _Bgfilaout

function _funcion(f){

	if(f == 1){
		document.getElementById("hactualizar").value = 1;
		document.carro.submit();
	}
	
	if(f == 2){
		document.getElementById("hborrar").value = 1;
		document.carro.submit();
	}	



}//end function _funcion



function _Dropdown(){

	//recoge los valores que necesitas
	var user = document.getElementById("user").value;
	var pass = document.getElementById("pass").value;
	var nif = document.getElementById("nif").value;
	var nombre = document.getElementById("nombre").value;
	var apellido1 = document.getElementById("apellido1").value;
	var apellido2 = document.getElementById("apellido2").value;
/*
	//numindice
	var indice = document.forms.registro.provincia.selectedIndex; 
	//valor del indice escogido
    var provincia = document.forms.registro.provincia.options[indice].value;	
	
	//numindice
	var indice2 = document.forms.registro.municipio.selectedIndex; 
	//valor del indice escogido
    var municipio = document.forms.registro.municipio.options[indice2].value;
*/	
	var direccion = document.getElementById("direccion").value;
	var email = document.getElementById("email").value;
	var fax = document.getElementById("fax").value;
	var telefono = document.getElementById("telefono").value;
	var movil = document.getElementById("movil").value;	
	
	var datos = document.getElementById("datos").value;		
	if(datos != 1){
		var privacidad = document.getElementById("condiciones").checked;
	}//end if
	var newsletter = document.getElementById("newsletter").checked;		
	
	var fact2 = document.getElementById("fact2").checked;
	var direccion2 = document.getElementById("direccion2").value;
	var codpostal2 = document.getElementById("codpostal2").value;
	var provincia2 = document.getElementById("provincia2").value;
	var municipio2 = document.getElementById("municipio2").value;

	var pos;
	
	//numindice
	var indice = document.forms.registro.provincia.selectedIndex; 
	//valor del indice escogido
    var valor = document.forms.registro.provincia.options[indice].value;

	var url = location.href;
	pos = url.lastIndexOf("?sind");

	if(pass != ""){
		var password = base64_encode(pass);
	}else{
		var password = pass;
	}//end if
	
	if(pos == -1){
		document.location.assign(url+'?sind='+valor+'&user='+user+'&pass='+password+'&nif='+nif+'&nombre='+nombre+'&apellido1='+apellido1+'&apellido2='+apellido2+'&direccion='+direccion+'&email='+email+'&fax='+fax+'&telefono='+telefono+'&movil='+movil+'&privacidad='+privacidad+'&fact2='+fact2+'&direccion2='+direccion2+'&codpostal2='+codpostal2+'&provincia2='+provincia2+'&municipio2='+municipio2+'&newsletter='+newsletter);		
	}else{
		url = url.substring(0,pos);
		document.location.assign(url+'?sind='+valor+'&user='+user+'&pass='+password+'&nif='+nif+'&nombre='+nombre+'&apellido1='+apellido1+'&apellido2='+apellido2+'&direccion='+direccion+'&email='+email+'&fax='+fax+'&telefono='+telefono+'&movil='+movil+'&privacidad='+privacidad+'&fact2='+fact2+'&direccion2='+direccion2+'&codpostal2='+codpostal2+'&provincia2='+provincia2+'&municipio2='+municipio2+'&newsletter='+newsletter);		
	}//end if(pos == -1)


	
}//end function _Dropdown



function _Dropdownemp(){


	//recoge los valores que necesitas
	var user = document.getElementById("user").value;
	var pass = document.getElementById("pass").value;
	var cif = document.getElementById("cif").value;
	var empresa = document.getElementById("inpempresa").value;	
	var nombre = document.getElementById("nombre").value;
	var apellido1 = document.getElementById("apellido1").value;
	//var formemp = document.getElementById("formemp").value;	uncomment por que solo es un div id="formemp" en registro.php y en registroped.php y en datos.php da error por que esa capa no esta, y no es ningun elemento de formulario que necesite checkear para validar.

/*
	//numindice
	var indice = document.forms.registro.provincia.selectedIndex; 
	//valor del indice escogido
    var provincia = document.forms.registro.provincia.options[indice].value;	
	
	//numindice
	var indice2 = document.forms.registro.municipio.selectedIndex; 
	//valor del indice escogido
    var municipio = document.forms.registro.municipio.options[indice2].value;
*/	
	var direccion = document.getElementById("direccion").value;
	var email = document.getElementById("email").value;
	var fax = document.getElementById("fax").value;
	var telefono = document.getElementById("telefono").value;
	var movil = document.getElementById("movil").value;	
	
	var datos = document.getElementById("datos").value;		
	if(datos != 1){
		var privacidad = document.getElementById("condiciones").checked;
	}//end if
	var newsletter = document.getElementById("newsletter").checked;	
	
	var fact2 = document.getElementById("fact2").checked;
	var direccion2 = document.getElementById("direccion2").value;
	var codpostal2 = document.getElementById("codpostal2").value;
	var provincia2 = document.getElementById("provincia2").value;
	var municipio2 = document.getElementById("municipio2").value;	
	


	var pos;
	
	//numindice
	var indice = document.forms.registro.provincia.selectedIndex; 
	//valor del indice escogido
    var valor = document.forms.registro.provincia.options[indice].value;

	var url = location.href;
	pos = url.lastIndexOf("?sind");
	
	
	var password = base64_encode(pass);	
	
		
	if(pos == -1){
		document.location.assign(url+'?sind='+valor+'&user='+user+'&pass='+password+'&cif='+cif+'&empresa='+empresa+'&nombre='+nombre+'&apellido1='+apellido1+'&direccion='+direccion+'&email='+email+'&fax='+fax+'&telefono='+telefono+'&movil='+movil+'&privacidad='+privacidad+'&emp=on'+'&fact2='+fact2+'&direccion2='+direccion2+'&codpostal2='+codpostal2+'&provincia2='+provincia2+'&municipio2='+municipio2+'&newsletter='+newsletter);		
	}else{
		url = url.substring(0,pos);
		document.location.assign(url+'?sind='+valor+'&user='+user+'&pass='+password+'&cif='+cif+'&empresa='+empresa+'&nombre='+nombre+'&apellido1='+apellido1+'&direccion='+direccion+'&email='+email+'&fax='+fax+'&telefono='+telefono+'&movil='+movil+'&privacidad='+privacidad+'&emp=on'+'&fact2='+fact2+'&direccion2='+direccion2+'&codpostal2='+codpostal2+'&provincia2='+provincia2+'&municipio2='+municipio2+'&newsletter='+newsletter);		
	}//end if(pos == -1)


	
}//end function _Dropdownemp


function _Registro(){
	

	//recoge los valores que necesitas
	var user = document.getElementById("user").value;
	var pass = document.getElementById("pass").value;
	var nif = document.getElementById("nif").value;
	var nombre = document.getElementById("nombre").value;
	var apellido1 = document.getElementById("apellido1").value;
	var apellido2 = document.getElementById("apellido2").value;
	
	var datos = document.getElementById("datos").value;	


	//numindice
	var indice = document.forms.registro.provincia.selectedIndex; 
	//valor del indice escogido
    var provincia = document.forms.registro.provincia.options[indice].value;	
	
	//numindice
	var indice2 = document.forms.registro.municipio.selectedIndex; 
	//valor del indice escogido
    var municipio = document.forms.registro.municipio.options[indice2].value;
	
	var direccion = document.getElementById("direccion").value;
	var email = document.getElementById("email").value;
	var fax = document.getElementById("fax").value;
	var telefono = document.getElementById("telefono").value;
	var movil = document.getElementById("movil").value;	



	var error = 0;

	//comprueba contraseņa, error 3

	var cpass = _Pass(pass);
	if(cpass == 1){
		var error3 = 0;
	}else{
		error = 3;
		document.getElementById('status').innerHTML='La contrase&ntilde;a ha de tener como m&iacute;nimo 6 car&aacute;cteres.';	
	}	

	//comprueba email, error 2
	var cemail = _eMail(email);
	
	if(cemail == 1){
		var error2 = 0;
	}else{
		error = 2;
		document.getElementById('status').innerHTML='Escriba una direcci&oacute;n de e-Mail v&aacute;lida.';	
	}
	
	//comprueba campos vacios, error 1
	var vuser = _Vacio(user);
	var vpass = _Vacio(pass);
	var vnif = _Vacio(nif);
	var vnombre = _Vacio(nombre);
	var vapellido1 = _Vacio(apellido1);
	var vprovincia = _Vacio(provincia);
	var vmunicipio = _Vacio(municipio);
	var vdireccion = _Vacio(direccion);
	var vemail = _Vacio(email);
	
	
	if(vuser == 1 && vpass == 1 && vnif == 1 && vnombre == 1 && vapellido1 == 1 && vprovincia == 1 && vmunicipio == 1 && vdireccion == 1 && vemail == 1){
		
		var error1 = 0;
		
	}else{
		error = 1;
		document.getElementById('status').innerHTML='Rellene los campos obligatorios.';
	}

	//saber si comprobar el error 4, en la pagina de modificacion no es necesario el chechbox condiciones
	//comprueba si hay alta para usar error4 en condiciones
	//var alta = document.getElementById("idalta").value;

	//alert(datos);
	if(datos != 1){
		//comprueba privacidad, error 4
		var privacidad = document.getElementById("condiciones").checked;
	
		if(privacidad == true){
			var error4 = 0;	
		}else{
			error = 4;
			document.getElementById('status').innerHTML='Ha de indicar haber leido la pol&iacute;tica de privacidad.';	
		}//end if privacidad
	}else{
		var error4 = 0;	
	}//end if(datos != 1)
	
		
		//comprueba facturacion2 si estan vacios
		var fact2 = document.getElementById("fact2").checked;
		if(fact2 == true){

			var provincia2 = document.getElementById("provincia2").value;
			var municipio2 = document.getElementById("municipio2").value;
			var direccion2 = document.getElementById("direccion2").value;
			var codpostal2 = document.getElementById("codpostal2").value;	
			
			//comprueba campos vacios de facturacion2 
			var vprovincia2 = _Vacio(provincia2);
			var vmunicipio2 = _Vacio(municipio2);
			var vdireccion2 = _Vacio(direccion2);
			var vcodpostal2 = _Vacio(codpostal2);

				if(vprovincia2 == 1 && vmunicipio2 == 1 && vdireccion2 == 1 && vcodpostal2 == 1){
					var error5 = 0;
				}else{
					error = 5;
					error5 = 1;
					document.getElementById('status').innerHTML='Rellene los campos obligatorios.';
				}//end if(vprovincia2 == 1 && vmunicipio2 == 1 && vdireccion2 == 1 && vcodpostal2 == 1)
				

		}//end if(fact2 == true)

		//si todo errores 0, submit
		switch(fact2){
			case true:
			
				if(error1 == 0 && error2 == 0 && error3 == 0 && error4 == 0 && error5 == 0){
					document.forms.registro.pass.value = base64_encode(pass);						
					document.forms.registro.submit();			
				}//end if errorx
				
			break;
			case false:
			
				if(error1 == 0 && error2 == 0 && error3 == 0 && error4 == 0){
					document.forms.registro.pass.value = base64_encode(pass);					
					document.forms.registro.submit();			
				}//end if errorx
				
			break;
		}//end switch(fact2)
	
}//end function _Registro

// registro y registroemp controlo que si viene de la pagina datos.php no controle el error de condiciones por que no es un elemento de datos.php

function _Registroemp(){
	
	
	//recoge los valores que necesitas
	var user = document.getElementById("user").value;
	var pass = document.getElementById("pass").value;
	var cif = document.getElementById("cif").value;
	var empresa = document.getElementById("inpempresa").value;	
	var nombre = document.getElementById("nombre").value;
	var apellido1 = document.getElementById("apellido1").value;
	
	var datos = document.getElementById("datos").value;	


	//numindice
	var indice = document.forms.registro.provincia.selectedIndex; 
	//valor del indice escogido
    var provincia = document.forms.registro.provincia.options[indice].value;	
	
	//numindice
	var indice2 = document.forms.registro.municipio.selectedIndex; 
	//valor del indice escogido
    var municipio = document.forms.registro.municipio.options[indice2].value;
	
	var direccion = document.getElementById("direccion").value;
	var email = document.getElementById("email").value;
	var fax = document.getElementById("fax").value;
	var telefono = document.getElementById("telefono").value;
	var movil = document.getElementById("movil").value;	


	var error = 0;

	//comprueba contraseņa, error 3

	var cpass = _Pass(pass);
	if(cpass == 1){
		var error3 = 0;
	}else{
		error = 3;
		document.getElementById('status').innerHTML='La contrase&ntilde;a ha de tener como m&iacute;nimo 6 car&aacute;cteres.';	
	}	

	//comprueba email, error 2
	var cemail = _eMail(email);
	
	if(cemail == 1){
		var error2 = 0;
	}else{
		error = 2;
		document.getElementById('status').innerHTML='Escriba una direcci&oacute;n de e-Mail v&aacute;lida.';	
	}
	
	//comprueba campos vacios, error 1
	var vuser = _Vacio(user);
	var vpass = _Vacio(pass);
	var vcif = _Vacio(cif);
	var vempresa = _Vacio(empresa);	
	var vprovincia = _Vacio(provincia);
	var vmunicipio = _Vacio(municipio);
	var vdireccion = _Vacio(direccion);
	var vemail = _Vacio(email);
	
	
	if(vuser == 1 && vpass == 1 && vcif == 1 && vempresa == 1 && vprovincia == 1 && vmunicipio == 1 && vdireccion == 1 && vemail == 1){
		
		var error1 = 0;
		
	}else{
		error = 1;
		document.getElementById('status').innerHTML='Rellene los campos obligatorios.';
	}

	//saber si comprobar el error 4, en la pagina de modificacion no es necesario el chechbox condiciones
	//comprueba si hay alta para usar error4 en condiciones
	//var alta = document.getElementById("idalta").value;


	if(datos != 1){
		//comprueba privacidad, error 4
		var privacidad = document.getElementById("condiciones").checked;
	
		if(privacidad == true){
			var error4 = 0;	
		}else{
			error = 4;
			document.getElementById('status').innerHTML='Ha de indicar haber leido la pol&iacute;tica de privacidad.';	
		}//end if privacidad
	}else{
		var error4 = 0;	
	}//end if(datos != 1)

		//comprueba facturacion2 si estan vacios
		var fact2 = document.getElementById("fact2").checked;

		if(fact2 == true){

			var provincia2 = document.getElementById("provincia2").value;
			var municipio2 = document.getElementById("municipio2").value;
			var direccion2 = document.getElementById("direccion2").value;
			var codpostal2 = document.getElementById("codpostal2").value;	
			
			//comprueba campos vacios de facturacion2 
			var vprovincia2 = _Vacio(provincia2);
			var vmunicipio2 = _Vacio(municipio2);
			var vdireccion2 = _Vacio(direccion2);
			var vcodpostal2 = _Vacio(codpostal2);

				if(vprovincia2 == 1 && vmunicipio2 == 1 && vdireccion2 == 1 && vcodpostal2 == 1){
					var error5 = 0;
				}else{
					error = 5;
					error5 = 1;
					document.getElementById('status').innerHTML='Rellene los campos obligatorios.';
				}//end if(vprovincia2 == 1 && vmunicipio2 == 1 && vdireccion2 == 1 && vcodpostal2 == 1)
				

		}//end if(fact2 == true)

		//si todo errores 0, submit
		switch(fact2){
			case true:
			
				if(error1 == 0 && error2 == 0 && error3 == 0 && error4 == 0 && error5 == 0){
					document.forms.registro.pass.value = base64_encode(pass);						
					document.forms.registro.submit();	
				}//end if errorx
				
			break;
			case false:
			
				if(error1 == 0 && error2 == 0 && error3 == 0 && error4 == 0){
					document.forms.registro.pass.value = base64_encode(pass);						
					document.forms.registro.submit();		
				}//end if errorx
				
			break;
		}//end switch(fact2)
		
		
		
	
}//end function _Registroemp


function _Pass(pass){

	var ok = 1;
	var num = pass.lastIndexOf(""); 

	//comprueba 6 caracteres en la contraseņa
	if(num >= 6){
		return ok;
		//error = 3;
		//url = _Url();
		//document.location.assign(url+'?error='+error);	
	}
}//end function _Pass


function _Vacio(campo){

	var ok = 1;	
	if (campo != "" && campo != "undefined" && campo != "none") {
		return ok;
	}
	
}//end function _Vacio

function _eMail(email){

	var ok = 1; 
	var arr = email.lastIndexOf("@"); 
	var pto = email.lastIndexOf(".");

	if(arr != -1 && pto != -1){
		return ok;
		//error = 2;
		//url = _Url();
		//document.location.assign(url+'?error='+error);	
	}
	
}//end function _eMail


function _Privregistro() {

//document.getElementById("privacidad").style.visibility = "visible";
//document.layers("privacidad").style.visibility = "visible";
var popup = null;

	popup=open('privacidad/registro.html',"popup","width=475,height=300,SCROLLBARS=1,RESIZE=NO,TOOLBAR=no,MENUBAR=0,LOCATION=0,STATUS=1");
	popup.focus();

}


function _Fpago(){

	var fpago1 = document.getElementById('fpago1').checked;
	var fpago2 = document.getElementById('fpago2').checked;
	
	
	if(fpago1 == true || fpago2 == true){

		document.forms.formapago.submit();		
	}else{
		document.getElementById('status').innerHTML='Ha de seleccionar al menos una forma de pago.';		
	}//end if

	
}//end function _Fpago

function _Facturacion2(fact2){
	//alert(fact2);
	if(fact2 == true){
		document.getElementById("facturacion2").style.visibility = "visible";
		document.getElementById("hfact2").value = 1;
	}else{
		document.getElementById("facturacion2").style.visibility = "hidden";
		document.getElementById("hfact2").value = 0;	
		document.getElementById("provincia2").value = "";
		document.getElementById("municipio2").value = "";	
		document.getElementById("direccion2").value = "";
		document.getElementById("codpostal2").value = "";		
	}//end if
	

	
}//end function _Facturacion2

function _Newsletter(news){
	//alert(news);
	if(news == true){
		document.getElementById('hnewsletter').value = 1;
	}else{
		document.getElementById('hnewsletter').value = 0;
	}//end if

	
}//end function _Newsletter

function _Privacidad(priv){
	//alert(news);
	if(priv == true){
		document.getElementById('hprivacidad').value = 1;
	}else{
		document.getElementById('hprivacidad').value = 0;
	}//end if

	
}//end function _Privacidad

function _Ifnum(num, cod){

	var form_name = "productos"+cod;	

	if(!isNaN(num) && (num >= 1)){
		document.forms[form_name].submit();
	}//end if

}

function _Ifnumind(num, cod){

	//alert(cod);
	var codigo;
	codigo = document.getElementById('cod').value;
	var form_name = "productos"+cod;

	if(!isNaN(num) && (num >= 1)){
		
		document.forms[form_name].submit();
		
	}//end if
	
}

function base64_encode(data) {


    var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    var o1, o2, o3, h1, h2, h3, h4, bits, i = ac = 0, enc="", tmp_arr = [];
    data = utf8_encode(data);
    
    do { // pack three octets into four hexets
        o1 = data.charCodeAt(i++);
        o2 = data.charCodeAt(i++);
        o3 = data.charCodeAt(i++);
 
        bits = o1<<16 | o2<<8 | o3;
 
        h1 = bits>>18 & 0x3f;
        h2 = bits>>12 & 0x3f;
        h3 = bits>>6 & 0x3f;
        h4 = bits & 0x3f;
 
        // use hexets to index into b64, and append result to encoded string
        tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
    } while (i < data.length);
    
    enc = tmp_arr.join('');
    
    switch( data.length % 3 ){
        case 1:
            enc = enc.slice(0, -2) + '==';
        break;
        case 2:
            enc = enc.slice(0, -1) + '=';
        break;
    }

    return enc;
}//end function base64_encode


function utf8_encode ( string ) {

 
    string = (string+'').replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if((c1 > 127) && (c1 < 2048)) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc != null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}//end function utf8_encode


function _Contacto(){

	//recoge los valores que necesitas
	var nombre = document.getElementById("nombre").value;
	var email = document.getElementById("email").value;
	var titulo = document.getElementById("titulo").value;
	var mensaje = document.getElementById("mensaje").value;	

	//comprueba email, error 2
	var cemail = _eMail(email);
	
	if(cemail == 1){
		var error2 = 0;
	}else{
		error = 2;
		document.getElementById('status').innerHTML='Escriba una direcci&oacute;n de e-Mail v&aacute;lida.';	
	}

	//comprueba campos vacios, error 1
	var vnombre = _Vacio(nombre);
	var vemail = _Vacio(email);
	var vtitulo = _Vacio(titulo);
	var vmensaje = _Vacio(mensaje);	
	
	//comprueba privacidad
		var compra = document.getElementById("condicionescompra").checked;
		if(compra == true){
			var error3 = 0;
		}else{
			var error3 = 1;
			document.getElementById('status').innerHTML='Acepte las condiciones de privacidad.';	
		}//end if	
	
	
	if(vnombre == 1 && vemail == 1 && vtitulo == 1 && vmensaje == 1){
		
		var error1 = 0;
		
	}else{
		error = 1;
			document.getElementById('status').innerHTML='Rellene los campos obligatorios.';

	}
	
	
	
	//validad si todo ok
	
	if(error1 == 0 && error2 == 0 && error3 == 0){
		document.forms.contacto.submit();			
	}//end if errorx	
	
}//end function _Contacto


function _Enviaamigo(){

	//recoge los valores que necesitas
	var nombre = document.getElementById("nombre").value;
	var email = document.getElementById("email").value;
	var nombreamigo = document.getElementById("nombreamigo").value;
	var emailamigo = document.getElementById("emailamigo").value;	
	//var titulo = document.getElementById("titulo").value;
	var mensaje = document.getElementById("mensaje").value;	

	//comprueba email, error 2
	var cemail = _eMail(email);
	
	if(cemail == 1){
		var error2 = 0;
	}else{
		error = 2;
		document.getElementById('status').innerHTML='Escriba una direcci&oacute;n de e-Mail v&aacute;lida.';	
	}

	//comprueba campos vacios, error 1
	var vnombre = _Vacio(nombre);
	var vemail = _Vacio(email);
	var vnombreamigo = _Vacio(nombreamigo);
	var vemailamigo = _Vacio(emailamigo);	
	//var vtitulo = _Vacio(titulo);
	var vmensaje = _Vacio(mensaje);	
	
	//comprueba privacidad
		var compra = document.getElementById("condicionescompra").checked;
		if(compra == true){
			var error3 = 0;
		}else{
			var error3 = 1;
			document.getElementById('status').innerHTML='Acepte las condiciones de privacidad.';	
		}//end if	
	
	
	if(vnombre == 1 && vemail == 1 && vnombreamigo == 1 && vemailamigo == 1 && vmensaje == 1){
		
		var error1 = 0;
		
	}else{
		error = 1;
			document.getElementById('status').innerHTML='Rellene los campos obligatorios.';

	}
	
	
	
	//validad si todo ok
	
	if(error1 == 0 && error2 == 0 && error3 == 0){
		document.forms.enviaamigo.submit();			
	}//end if errorx	
	
}//end function _Enviaamigo


function _Buscador(){

	//recoge los valores que necesitas
	var pclave = document.getElementById("pclave").value;
	//alert("palabra: "+pclave);
	
		//numindice
	var indice = document.forms.buscador.selbusca.selectedIndex;
	document.getElementById("indsel").value = indice;
	//valor del indice escogido
    //var valor = document.forms.registro.provincia.options[indice].value;
	
	//comprueba campos vacios, error 1
	if(pclave != "" && indice != 0){
		document.forms.buscador.submit();
	}//end if

	
}//end function _Buscador


function _Printpedido(order, iduser, idpedido) {

//document.getElementById("privacidad").style.visibility = "visible";
//document.layers("privacidad").style.visibility = "visible";
var popup = null;

	popup=open('printpedido.php?order='+order+'&iduser='+iduser+'&idpedido='+idpedido+'',"popup","width=600,height=400,SCROLLBARS=1,RESIZE=NO,TOOLBAR=no,MENUBAR=0,LOCATION=0,STATUS=1");
	popup.focus();

}//end function _Printpedido

function _Log(){

	var pass = document.getElementById("pass").value;
	if(pass != ""){
		document.forms.identificacion.pass.value = base64_encode(pass);
	}//end if
	document.forms.identificacion.submit();
	//document.forms.item(1).submit();
	//var name = document.forms.item(1).name;
	//alert(name);
	//document.forms.identificacion.submit();
	//document.getElementById("identificacion").submit();
	//document.forms["identificacion"].submit();
	
}

	function _Comprar(){
		
		var compra = document.getElementById("condicionescompra").checked;
		if(compra == true){
			document.forms.confirmar.submit();
		}else{
			alert("Para comprar, aceptar las condiciones de compra");
		}//end if
		
		
	}//end function _Comprar


function _Condicionescompra() {

var popup = null;

	popup=open('privacidad/condicionescompra.html',"popup","width=475,height=300,SCROLLBARS=1,RESIZE=NO,TOOLBAR=no,MENUBAR=0,LOCATION=0,STATUS=1");
	popup.focus();

}//end function _Condicionescompra