var alerta=false;
var tipo_pago=1;
var a=0;

/*
=============================================================
Estilo
=============================================================
*/
function cambiarcss(id, newClass){
	var identity=document.getElementById(id);
	identity.className=newClass;
}

function menu (id, action){
   var style = document.getElementById(id).style;
	var x=0;
	var y=0;
	switch(id)
	{
   case "manga":
		x= " -0px";
		break;
   case "usa":
		x= " 105px";
		break;
   case "europa":
		x= " 79px";
		break;
   case "catala":
		x= " 53px";
		break;
   case "figuras":
		x= " 27px";
		break;

	}
	switch (action)
	{
      case "over":
		y=" -190px"
		break;
		case "out":
		y=" 0px"
		break;
		case "click":
		y=" -380px"
		break;
	}
	valor =y +" " + x;
	style.backgroundPosition = valor;

}

function cambiarimg(id, newName){
	var identity=document.getElementById(id);
	identity.src=newName;
}



/*
=============================================================
Tratamiento de fechas
=============================================================
*/

var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

function fecha() {
	var dows,months,now,dow,d,m,h,y
	dows = new Array("Domingo","Lunes","Martes","Miércoles","Jueves","Viernes","Sábado");
	months = new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	now = new Date();
	dow = now.getDay();
	d = now.getDate();
	m = now.getMonth();
	h = now.getTime();
	y = now.getFullYear();
	document.write(dows[dow]+" "+d+", de "+months[m]+" de "+y);
	}


/*
navegando por el menú
*/

function abrirpagina(pag,id)
{
 var url
 url=pag+"?id="+id
 window.location=url
}

function abrirVentana(url)
{
	var x
	var y
	x=screen.width;
	 var opciones="left=100,top=100,width=600,height=500,scrollbars=yes";
	var ventana = window.open (url,"detalle",opciones);
	//   mi_ventana.document.write("Una prueba de abrir ventanas");

	//ventana.moveTo(400,100);
	//ventana.focus();
}

 function activeBoton(id, newClass,imageSrc){
	imageSrc="images/Menu/"+imageSrc;
	//alert(imageSrc);

	var identity=document.getElementById(id);
	identity.className=newClass;
	identity.src=imageSrc
}


/*
=============================================================
Formularios
=============================================================
*/



function cambiarenvio(aa)
{

//modificado el 27 de enero de 2010

    var a   =   document.getElementById("paisdestino").selectedIndex;

    var direc                       = location.href;
    var pos_direc                   = direc.indexOf('paisD')
    var fs3                         = direc.indexOf('fs3')

    var datosPago_temp  =  document.getElementById("datosPago");

    if (pos_direc == -1) {
	    var formadepago		=	' <span >Para formalizar el pedido es necesario que escoja una forma de pago.</span> <br /><br /><center><input value="Escoja una forma de pago" type="button" onclick="abrirVentana(\'formadepago.asp?paisD='+a+'\');"></center>';
	    var formadepago_i	=	' <span >Para formalizar el pedido es necesario que escoja una forma de pago.</span> <br /><br /><center><input value="Escoja una forma de pago" type="button"  onclick="abrirVentana(\'formadepago_i.asp?paisD='+a+'\');"></center>';
    }else {
    	//alert(a);
        var formadepago		=	' <center><span ></span><input value="Modifica la forma de pago" type="button" onclick="abrirVentana(\'formadepago.asp?paisD='+a+'\');"></center>';
	    var formadepago_i	=	' <center><span ></span><input value="Modifica la forma de pago" type="button"  onclick="abrirVentana(\'formadepago_i.asp?paisD='+a+'\');"></center>';
    }

	var divFormulario 		= 	document.getElementById("avisoentrega");
	var divFormulario_txt	=	document.getElementById("txtavisoentrega");
	var divFormulario2 		= 	document.getElementById("formaEntrega");
	var divFormulario2_txt	=	document.getElementById("txtformaEntrega");
	var divFormulario3 		= 	document.getElementById("formaPago");
	var divFormulario3_txt	=	document.getElementById("txtformaPago");
	var divFormulario4 		= 	document.getElementById("formaEnvio");
	var divFormulario4_txt	=	document.getElementById("txtformaEnvio");

	var motivoError			=	"No podemos calcular su pedido en las actuales circunstacias. Motivo: no llega al pedido mínimo.";
	var atencionAviso		=	"" // Podemos hacer salir un texto.. en el los avisos

	var formaEnvio			= "<p>En caso de que no tengamos todo el material en stock la tienda, ¿qué deseas hacer? </p><input id='formaEnvio' name='formaEnvio' type='radio' value='1' onclick='activar();' />Enviar solamente lo que haya en stock en la tienda<br /><input  id='formaEnvio' name='formaEnvio' type='radio' value='2' onclick='activar();'/>Pedir y enviar todo lo que podais conseguir en 15 días como mucho<br /><input  id='formaEnvio' name='formaEnvio' type='radio' value='3' onclick='activar();'/>Pedir y enviar todo lo que podais conseguir en 5 semanas como mucho  ";
//alert(a);

if (a==0){
//alert ("solucionar");
}

if (a==1){
		var totalpedido_1=document.compra.total.value;
        var totalpedido_1=totalpedido_1.replace(".","");
        var totalpedido_1=totalpedido_1.replace(",","");
        var totalpedido=totalpedido_1/100;

       // var totalpedido=totalpedido_1.replace(",",".");

		divFormulario_txt.innerHTML	=	atencionAviso;
		divFormulario.innerHTML 	=	"Entre 24 horas y 20 días una vez eniado el paquete (según forma de envío).<a onclick='abrirVentana(\"condiciones_esp.htm\");' href=\"#\" >Ver Condiciones de venta nacionales </a>";

		if (totalpedido>=20){

         divFormulario3.style.visibility =   "visible";
         divFormulario3_txt.style.visibility =   "visible";
			divFormulario3_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>SEGUNDO PASO:</b></span><br /> Forma de pago:";
			divFormulario3.innerHTML 		=	formadepago;

            if (pos_direc != -1){
                  divFormulario2.style.visibility =   "visible";
                  divFormulario2_txt.style.visibility =   "visible";
        				divFormulario2_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>TERCER PASO:</b></span><br /> Selecciona una transporte:";
          			divFormulario2.innerHTML		=	'<input type=radio name="envio1"  id="envio1" value="Seur o MRW" onclick="ver4();"/>&nbsp;&nbsp;<b>Transporte Urgente (Mensajería)</B> <br/>Importe 7,00&euro;&nbsp;(V&aacute;lido s&oacute;lo para Espa&ntilde;a peninsular)<br />¿Cuándo prefieres que te entreguen el paquete en tu domicilio?   <select name="hora" id="hora"><option value="INDIFERENTE" selected>Indiferente.</option>  <option value="ENTREGAR POR LA MAÑANA">por la mañana</option><option value="ENTREGAR POR LA TARDE" >por la tarde</option> </select><br /><br /><input type=radio name="envio1" onclick="javascript:ver4();"  id="envio1" value="Correos">Correos Importe 7,00 &euro;<br>(V&aacute;lido para Espa&ntilde;a y Andorra)';
            }
            if (fs3 != -1){
           			divFormulario4_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>CUARTO PASO:</b></span><br /> Stock:";
        			divFormulario4.innerHTML 		=	formaEnvio;
                    divFormulario4.style.visibility =       "visible";
                    divFormulario4_txt.style.visibility =   "visible";
                }else{

           			divFormulario4_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>CUARTO PASO:</b></span><br /> Stock:";
        			divFormulario4.innerHTML 		=	formaEnvio;

                    divFormulario4.style.visibility =       "hidden";
                    divFormulario4_txt.style.visibility =   "hidden";
            }

		} else{
			frase	=	motivoError;
			divFormulario2_txt.innerHTML	=	'!!ATENCION¡¡';
			divFormulario2.innerHTML 		= 	frase;

            divFormulario2.style.visibility =   "visible";
            divFormulario2_txt.style.visibility =   "visible";
		    }
		document.compra.gastosEnvio.value	=	7;
		}

if (a==2){
		var totalGastos=0;
		var totalpedido_1=document.compra.total.value;
        var totalpedido_1=totalpedido_1.replace(".","");
        var totalpedido_1=totalpedido_1.replace(",","");
        var totalpedido=totalpedido_1/100;
		var frase='';
	//	alert(totalpedido);
		divFormulario.innerHTML = "Unas 2 semanas, una vez enviado el paquete.<a onclick='abrirVentana(\"condiciones_int.htm\");' href=\"#\" >Ver Condiciones de venta internacionales</a>"
				if (totalpedido>=50 && totalpedido<=90){
					totalGastos=35;
					}
				if (totalpedido>=91 && totalpedido<=120){
					totalGastos=40;
					}
				if (totalpedido>=121 && totalpedido<=300){
					totalGastos=50;
					}
				if (totalpedido>=301 && totalpedido<=500){
					totalGastos=60;
					}
				if (totalpedido>=501){
					totalGastos=75;
					}
		document.compra.gastosEnvio.value=totalGastos;
		if (totalGastos!=0){
			frase='Los gastos de envio para su pedido serán de ' + totalGastos + '.-€';
			divFormulario3_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>TERCER PASO:</b></span><br /> Forma de pago:"
			divFormulario3.innerHTML 		=	formadepago_i;
			divFormulario2_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>SEGUNDO PASO:</b></span><br /> Gastos de transporte:"
			divFormulario2.innerHTML		=	frase;
			divFormulario4_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>CUARTO PASO:</b></span><br /> Forma de pago:"
			divFormulario4.innerHTML 		=	formaEnvio;

            divFormulario3.style.visibility =   "visible";
            divFormulario3_txt.style.visibility =   "visible";

            divFormulario2.style.visibility =   "visible";
            divFormulario2_txt.style.visibility =   "visible";

            divFormulario4.style.visibility =   "visible";
            divFormulario4_txt.style.visibility =   "visible";
			}
			else{
			frase	=	motivoError;
			divFormulario2_txt.innerHTML	=	'!!ATENCION¡¡';
			divFormulario2.innerHTML		=	frase;
			divFormulario3_txt.innerHTML	= '';
			divFormulario3.innerHTML 		= '';
            divFormulario3.style.visibility =   "visible";
            divFormulario3_txt.style.visibility =   "visible";

            divFormulario2.style.visibility =   "visible";
            divFormulario2_txt.style.visibility =   "visible";

            divFormulario4.style.visibility =   "visible";
            divFormulario4_txt.style.visibility =   "visible";}
			}
if (a==3){
		divFormulario.innerHTML = "Unas 8 semanas, una vez enviado el paquete.<a onclick='abrirVentana(\"condiciones_int.htm\");' href=\"#\">Ver Condiciones de venta internacionales </a>";
		var totalGastos=0;
		var totalpedido_1=document.compra.total.value;
        var totalpedido_1=totalpedido_1.replace(".","");
        var totalpedido_1=totalpedido_1.replace(",","");
        var totalpedido=totalpedido_1/100;
		var frase='';
//		alert(totalpedido);
				if (totalpedido>=50 && totalpedido<=90){
					totalGastos=40;
					}
				if (totalpedido>=91 && totalpedido<=120){
					totalGastos=50;
					}
				if (totalpedido>=121 && totalpedido<=300){
					totalGastos=70;
					}
				if (totalpedido>=301 && totalpedido<=500){
					totalGastos=100;
					}
				if (totalpedido>=501 ){
					totalGastos=150;
					}
		document.compra.gastosEnvio.value=totalGastos;
		if (totalGastos!=0){
			frase='Los gastos de envio para su pedido serán de ' + totalGastos + '.-€';
			divFormulario3_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>TERCER PASO:</b></span><br /> Forma de pago:"
		  	divFormulario3.innerHTML 		=	formadepago_i;
			divFormulario2_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>SEGUNDO PASO:</b></span><br /> Gastos de transporte:"
			divFormulario2.innerHTML		=	frase;
			divFormulario4_txt.innerHTML	=	"<span style=\"font:0.6em Verdana, Arial, Helvetica, sans-serif;\"><b>CUARTO PASO:</b></span><br /> Forma de pago:"
			divFormulario4.innerHTML 		=	formaEnvio;

            divFormulario3.style.visibility =   "visible";
            divFormulario3_txt.style.visibility =   "visible";

            divFormulario2.style.visibility =   "visible";
            divFormulario2_txt.style.visibility =   "visible";

            divFormulario4.style.visibility =   "visible";
            divFormulario4_txt.style.visibility =   "visible";
			}
			else
			{
			frase	=	motivoError;
			divFormulario2_txt.innerHTML	='!!ATENCION¡¡';
			divFormulario2.innerHTML		=	frase;
			divFormulario3_txt.innerHTML	= '';
			divFormulario3.innerHTML 		= '';

            divFormulario3.style.visibility =   "visible";
            divFormulario3_txt.style.visibility =   "visible";

            divFormulario2.style.visibility =   "visible";
            divFormulario2_txt.style.visibility =   "visible";

            divFormulario4.style.visibility =   "visible";
            divFormulario4_txt.style.visibility =   "visible";
			}
 		}
comprobar();
}

function ver4(){
          	var divFormulario4 		= 	document.getElementById("formaEnvio");
        	var divFormulario4_txt	=	document.getElementById("txtformaEnvio");
            divFormulario4.style.visibility =   "visible";
            divFormulario4_txt.style.visibility =   "visible";
            }

function activar(){
      	var tablacesta 		= 	document.getElementById("cestacompra");
        tablacesta.style.visibility="visible";

}







function SendCompra()
{
comprobar();
alerta=false;
comprobarCampos();

if (alerta==false)
	{
	document.compra.submit();
	}
}

/*CONFIRMA LA FORMA DE COMPRA*/

function confirma(txt,pais)
{
	var mensaje

	mensaje	= " Esta seguro que  desea hacer su compra mediante \n "  + txt + "\n"

if (confirm(mensaje))
	{
	comprobarformadepago(pais);
	}
	else{

	}

}


/*
==================================================================
Comprueba los importes de venta
==================================================================
*/
function comprobar()
{

var mensaje="";

mensaje = '¡¡ATENCIÓN!! ' +'\n'
mensaje=mensaje+'Hemos intentado realizar su pedido pero hemos tendido el siguiente problema:'+'\n'+'\n'
//comprobamos el mínimo
var a=document.compra.paisdestino.value;

var t_1=document.compra.total.value;
var t=t_1.replace(",",".");

var envio=document.compra.envio1;

var vMEsp=30;
var vMEur=50;
var vMInt=90;
var alerta2=false;

//alert("TotalCompra:" +t+" Pais Destino: " + a);
// comprobar el importe minimo
	if (a==1 && t < vMEsp){
		alerta2=true;
		mensaje=mensaje +'Valor mínimo de '+vMEsp+'€ para compras con destino a España.'+ '\n';
		}
	if (a==2 && t < vMEur){
		alerta2=true;
		mensaje=mensaje +'Valor mínimo de '+vMEur+'€ para compras con destino a Europa.'+ '\n';
		}
	if (a==3 && t < vMInt){
		alerta2=true;
		mensaje=mensaje +'Valor mínimo de '+vMInt+'€ para compras con destino al Resto del Mundo.'+ '\n';
		}
// imprimimos la alerta;
if (alerta2==true){
		//alert(mensaje);
	}
}

/*
==================================================================
Comprueba todos los campos del formulario de envio.
==================================================================

*/


function comprobarCampos(){
	//comprobar que ningun campo este vacio.

var email 		= 	Trim(document.compra.email.value.toString());
var nombre		=	Trim(document.compra.nombre.value.toString());
var apellidos	=	Trim(document.compra.apellidos.value.toString());
//var dni			=	Trim(document.compra.dni.value.toString());
var calle		=	Trim(document.compra.calle.value.toString());
var cp			=	Trim(document.compra.cp.value.toString());
var poblacion	=	Trim(document.compra.poblacion.value.toString());
var provincia	=	Trim(document.compra.provincia.value.toString());
var pais		=	Trim(document.compra.pais.value.toString());
var tel			=	Trim(document.compra.tel.value.toString());
var mensaje		= 	"";
var paisF		=	document.getElementById("paisdestino").value;

//Solo para españa
if (paisF==1 ){
	if(document.compra.envio1[0].checked || document.compra.envio1[1].checked)
		{
		}else
		{
			alerta=true;
			mensaje=mensaje +'Debes elegir una forma de transporte.'+ '\n';
		}
}

if(document.compra.formaEnvio[0].checked || document.compra.formaEnvio[1].checked || document.compra.formaEnvio[2].checked)
	{
	}else
	{
		alerta=true;
		mensaje=mensaje +'Debes elegir una forma de envio.'+ '\n';
	}


if (email.length<1){
	alerta=true
	mensaje=mensaje +'El campo Email está vacío.'+ '\n';
	};

if (nombre.length<1){
	alerta=true
	mensaje=mensaje +'El campo Nombre está vacío.'+ '\n';
	};

if (apellidos.length<1){
	alerta=true
	mensaje=mensaje +'El campo Apellidos está vacío.'+ '\n';
	};
//if (dni.length<1){
//	alerta=true
//	mensaje=mensaje +'El campo D.N.I. está vacío.'+ '\n';
//	};

if (calle.length<1){
	alerta=true
	mensaje=mensaje +'El campo Calle está vacío.'+ '\n';
	};
if (cp.length<1){
	alerta=true
	mensaje=mensaje +'El campo Código Postal está vacío.'+ '\n';
	};
if (provincia.length<1){
	alerta=true
	mensaje=mensaje +'El campo Provincia está vacío.'+ '\n';
	};
if (poblacion.length<1){
	alerta=true
	mensaje=mensaje +'El campo Población está vacío.'+ '\n';
	};

if (pais.length<1){
	alerta=true
	mensaje=mensaje +'El campo País está vacío.'+ '\n';
	};

if (tel.length<1){
	alerta=true
	mensaje=mensaje +'El campo Teléfono está vacío.'+ '\n';
	};

//alert("esto es un peligor"+alerta);

// imprimimos la alerta;
if (alerta==true){
		alert(mensaje);
		}
}

/*
==================================================================================
COMPROBAR LA FORMA DE PAGO
==================================================================================
*/



function encryptIt(direc) {
  // the following letters are going to be encrypted.
  var letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  var letterCode = new Array(
  '%61','%62','%63','%64','%65','%66','%67','%68','%69','%6a',
  '%6b','%6c','%6d','%6e','%6f','%70','%71','%72','%73','%74',
  '%75','%76','%77','%78','%79','%7a',
  '%41','%42','%43','%44','%45','%46','%47','%48','%49','%4a',
  '%4b','%4c','%4d','%4e','%4f','%50','%51','%52','%53','%54',
  '%55','%56','%57','%58','%59','%5a','%30','%31','%32','%33',
  '%34','%35','%36','%37','%38','%39');

//  var _form = document.exf1;
  var _formIn = direc.split("~");

  var output="";
  var kk = _formIn[0];

for(var z=1;z<_formIn.length;z++)
	{
	output += "~";
 	 for(var i = 0; i < _formIn[z].length; i++) {
	    if(letters.indexOf(_formIn[z].charAt(i))!=-1) {
		  if (letters.indexOf(_formIn[z].charAt(i))!=-1) {
		    // its a letter
			var x = (Math.random()*1000)%10;
			var j = letters.indexOf(_formIn[z].charAt(i));
			if (x > 7) {
			  // j should be 0 through 25 for lowercase and 26 through 51 for uppercase
			  // switch them
			  if (j < 26) j += 0;
			  else        j -= 0;
			}
			if (x < 3) { output += _formIn[z].charAt(i);
			} else { output += letterCode[j]; }
		  } else { output += escape(_formIn[z].charAt(i)); }
		} else { output += _formIn[z].charAt(i); }
	  }

}
kk += output;
return kk;
}


function tipo(id)
{
	tipo_pago=id;
}


function comprobarformadepago(pais){
var mensaje="";
var alerta=false;
mensaje = '¡¡ATENCIÓN!! ' +'\n' ;
mensaje=mensaje+'Las formas de pago deben cumplir con los siguientes requisitos:'+'\n'+'\n' ;

var ti = Trim(document.pago.titular.value.toString());
var n1 = Trim(document.pago.numero1.value.toString());
var n2 = Trim(document.pago.numero2.value.toString());
var n3 = Trim(document.pago.numero3.value.toString());
var n4 = Trim(document.pago.numero4.value.toString());
var n5 = Trim(document.pago.numero5.value.toString());
var cm = document.pago.caducidad_mes.value;
var ca = document.pago.caducidad_anyo.value;
var tt = escape(document.pago.tarjeta_tipo.value);

var tc = Trim(document.pago.titular_cyber.value.toString()); 
var c1 = Trim(document.pago.numero1_cyber.value.toString());
var c2 = Trim(document.pago.numero2_cyber.value.toString());
var c3 = Trim(document.pago.numero3_cyber.value.toString());
var c4 = Trim(document.pago.numero4_cyber.value.toString());
var cm2 = document.pago.caducidad_mes_cyber.value;
var ca2 = document.pago.caducidad_anyo_cyber.value;


var pi= Trim(document.pago.PayPal_ID.value.toString());

//alert("n1:" + n1.length+"n2:" + n2.length +"n3:" + n3.length+"n4:" + n4.length +"n5:" + n5.length  );


if (tipo_pago==3){
	
	if (ti.length<1) {
		alerta=true;
		mensaje = mensaje +'Falta introducir el titular de la tarjeta.' + '\n' + '\n' ;
	}
	if (n1.length!=4 || n2.length!=4 || n3.length!=4 || n4.length!=4 ){
		 alerta=true;
		  mensaje = mensaje +'El número de cuenta introducido es incorrecto.' +'\n'+'\n';
		  }
	if (n5.length!=3)
		{ alerta=true;
		  mensaje = mensaje +'El número de cuenta introducido es incorrecto.' +'\n'+'\n';
		  }
	
}

if (tipo_pago==4){

	if (tc.length<1) {
		alerta=true;
	mensaje = mensaje +'Falta introducir el titular de la tarjeta.' +'\n'+'\n';
	}
	if (c1.length!=4 || c2.length!=4 || c3.length!=4 || c4.length!=4 ){
		 alerta=true;
	  mensaje = mensaje +'El número de cuenta introducido es incorrecto.' +'\n'+'\n';
		  }
	
}
if (tipo_pago==5){
	
	if (pi.length<1) {
		alerta=true;
		mensaje = mensaje +'Falta introducir el id PAYPAL.' +'\n'+'\n';
	}

}

if (alerta==true){
		alert(mensaje);}
	
if (alerta==false){
//fp=forma de pago
	if(tipo_pago==1 || tipo_pago==2){
		valores='';
		}
		
	if (tipo_pago==3){
		valores=tt+"~"+ti+"~"+n1+"~"+n2+"~"+n3+"~"+n4+"~"+n5+"~"+cm+"~"+ca;
	}
	if (tipo_pago==4){
		valores=tc+"~"+c1+"~"+c2+"~"+c3+"~"+c4+"~"+cm2+"~"+ca2;
	}
	if (tipo_pago==5){
		valores=pi;
	}
	a=location.search;

	lanzaReserva(tipo_pago,encryptIt(valores),a,pais);
	}
}


function lanzaReserva(fp,v,p,pais)
{
 var url
 url="http://www.libreriamanga.com/cesta.asp"+p+"&fp="+fp+"&v="+v+"&pais="+pais;
//alert(url);
	opener.focus();
	opener.location=url;
	window.close();
}





/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}
/*
=============================================================
Cambio de país.
=============================================================
*/

function cambiarpais(id)
{
 var url
 url="cambiarpais.asp?id="+id
 window.location=url

}


/*
=============================================================
Imaganes
=============================================================
*/




function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}


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_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];}}
}
