IE4 = (document.all);
NS4 = (document.layers);
if (!IE4) {
    if (!NS4)
        NS4 = (document.getElementById);
}

var form1=false;
var form2=false;

if (NS4) document.captureEvents(Event.KEYPRESS);
document.onkeypress = doKey;

function processClicks() {
    return false;
}

function processKeys() {
    return false;
}
var rapidaenviada=false;
var avanzenviada=false;
function busqueda(){
    document.onclick = processClicks;
    document.onkeypress=processKeys;
    document.fBusca.boton_Buscar.disabled=true;
    document.fBusca.buscar.readOnly=true;
    if (!rapidaenviada){
        rapidaenviada=true;document.fBusca.action='/busquedas/busqueda';document.fBusca.submit();
    }
    return false;
}
function busqueda2(palabra, formName){
    var form=document.forms[formName];
    if(form.buscar.value!=palabra && form.buscar.value!=''){
        document.onclick = processClicks;
        document.onkeypress=processKeys;
        form.buscar.readOnly=true;
        if (!rapidaenviada){
            rapidaenviada=true;
            form.action='/busquedas/busqueda';
            form.submit();
        }
    }
    return false;
}
function busqAvanzSegundaMano(form){
       var titulo = form.titbus.value;
       var plat = form.platbus.value;
       var myConn = new XHConn();
       if (!myConn) alert("XMLHTTP no esta disponible. Intentalo con un navegador m?s actual.");
       myConn.connect("/busquedas/resultadosSegundaMano", "POST", "titbus="+titulo+"&platBus="+plat, peticion);
}

function doKey(e) {
    whichASC = (NS4) ? e.which : event.keyCode;
    whichKey = String.fromCharCode(whichASC).toLowerCase();

    if (whichASC == 13) {
        if (form1) {
            document.onkeypress=processKeys;
            document.fBusca.boton_Buscar.disabled=true;
            document.fBusca.buscar.readOnly=true;

            busqueda();
        }
        if (form2){
            busqAvanz();
        }
    }
}

function setFormModified(formName) {
    if (formName=='fBusca' || formName=='fBuscaPie' || formName=='quick') {
        form1=true;
        form2=false;
    }else if (formName=='advanced') {
        form1=false;
        form2=true;
    }
}

function busqAvanz(){
    document.fBusquedaAvanzada.action='/busquedas/resultados';
    document.fBusquedaAvanzada.onkeypress=processKeys;
    document.fBusquedaAvanzada.titbus.readOnly=true;
    document.fBusquedaAvanzada.platbus.readOnly=true;
    document.fBusquedaAvanzada.catbus.readOnly=true;
    document.fBusquedaAvanzada.pegibus.readOnly=true;
    document.fBusquedaAvanzada.distbus.readOnly=true;
    var boton=document.fBusquedaAvanzada.bot_ava;
    if (boton!=null && typeof(boton)!='undefined' && boton.nodeType==1) document.fBusquedaAvanzada.bot_ava.disabled=true;
    if (!avanzenviada){
        avanzenviada=true;document.fBusquedaAvanzada.submit();
    }
    return false;
}
function XHConn(){
    var xmlhttp, bComplete = false;
    try {
        xmlhttp = new XMLHttpRequest();
    }catch (e){
        var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0','MSXML2.XMLHTTP.4.0','MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP' );
        var success = false;
        for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
            try {
                xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
                success = true;
            } catch (e) {}
        }
        if (!success) xmlhttp = false;
    }

    if (!xmlhttp) return null;
    this.connect = function(sURL, sMethod, sVars, fnDone){
        if (!xmlhttp) return false;
        bComplete = false;
        sMethod = sMethod.toUpperCase();

        try {
            if (sMethod == "GET"){
                xmlhttp.open(sMethod, sURL+"?"+sVars, true);
                sVars = "";
            }else{
                xmlhttp.open(sMethod, sURL, true);
                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            }
            xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && !bComplete){
                    bComplete = true;
                    fnDone(xmlhttp);
                }
            };
            xmlhttp.send(sVars);
        }catch(z) {
            return false;
        }
        return true;
    };
    return this;
}
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

function isFloat (s){
    var i;
    var seenDecimalPoint = false;
    if (isEmpty(s))
        if (isFloat.arguments.length == 1) return defaultEmptyOK;
        else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    for (i = 0; i < s.length; i++){
        // Check that current character is number.bu
        var c = s.charAt(i);
        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isWhitespace (s){
    var i;
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}

function LTrim(str) {
    return str.toString().replace(/^\s+/g, '');
}
function RTrim(str) {
    return str.toString().replace(/\s+$/g, '');
}
function Trim(str) {
    return LTrim(RTrim(str));
}
function isEmpty (s) {
    return ((s == null) || (Trim(s).length == 0));
}
function isEmail(StrObj) {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(StrObj)) {
        return true;
    } else {
        return false;
    }
}
function replaceChars(entry, replace_this, with_this) {
    temp = "" + entry; // temporary holder

    while (temp.indexOf(replace_this)>-1) {
        pos= temp.indexOf(replace_this);
        temp = "" + (temp.substring(0, pos) + with_this + temp.substring((pos + replace_this.length), temp.length));
    }
    return temp;
}
function setCookie(name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}
function formatFloat (s) {
    var maxFraction= 2;
    var dotSeen= false;
    var k=0;
    var result="";
    var str=new String(s);
    for (var i = 0; (i < str.length) && (k <= maxFraction); i++){
        var c = str.charAt(i);
        if ((c == '.') || (dotSeen)) {
            dotSeen=true;
            k=k+1;
        }
        result=result+c;
    }
    if(dotSeen && k==maxFraction)
        result=result+'0';
    if(!dotSeen)
        result=result+'.00';
    return result;
}
function formatoFloatSinDecimales (s) {
    var maxFraction= 2;
    var dotSeen= false;
    var k=0;
    var result="";
    var str=new String(s);
    for (var i = 0; (i < str.length) && (k <= maxFraction); i++){
        var c = str.charAt(i);
        if ((c == '.') || (dotSeen)) {
            dotSeen=true;
            k=k+1;
        }
        result=result+c;
    }
    if(dotSeen && k==maxFraction)
        result=result+'0';
    if(!dotSeen)
        result=result+'.00';

    dotSeen=false;
    var stop=false;
    var resultFinal=result;
    for (var j = (result.length - 1); !stop && (j >=0); j--){
        var car = result.charAt(j);
        if (car == '.') {
            stop=true;
            resultFinal= result.substring(0,j);
        }
        if(car=='0'){
            resultFinal= result.substring(0,j);
        }else{
            stop=true;
        }
    }

    return resultFinal;
}
function formatInt (s) {
    var maxFraction= 0;
    var dotSeen= false;
    var k=0;
    var result="";
    var str=new String(s);
    for (var i = 0; (i < str.length) && (k <= maxFraction); i++){
        var c = str.charAt(i);
        if ((c == '.') || (dotSeen)) {
            dotSeen=true;
            k=k+1;
        }
        if(!dotSeen)
            result=result+c;
    }
    return result;
}
function isNotEmpty(field) {
    var inputStr = Trim(field.value)
    if (inputStr == "" || inputStr == null) {
        return false
    }
    return true
}

var cvjvisitor= getCookie("cvjvisitor");
var uNombre= getUNombre();
var uFavoritos= getUFavoritos();
var uId= getUId();

function getUNombre() {
    uNombre='';
    if (cvjvisitor!=null) {
        var campos=cvjvisitor.split("-");
        if(campos.length>=2)
            uNombre=campos[2];
    }
    return uNombre;
}

function getUFavoritos() {
    var uFavoritos='';
    if (cvjvisitor!=null) {
        var i1= cvjvisitor.indexOf("-");
        if (i1>=0) {
            var resto= cvjvisitor.substring(i1+1);
            var i2= resto.indexOf("-");
            if (i2>=0) {
                uFavoritos= resto.substring(0,i2);
            }
        }
    }
    return uFavoritos;
}

function getUId() {
    var uId='0';
    if (cvjvisitor!=null) {
        var i1= cvjvisitor.indexOf("-");
        if (i1>=0) {
            uId= cvjvisitor.substring(0,i1);
        }
    }
    return uId;
}

function escribirNombre(id){
    nombre = getUNombre();
    var targetObj = document.getElementById(id);
    if (targetObj!=null && typeof(targetObj)!='undefined' && targetObj.nodeType==1){
        targetObj.innerHTML=nombre;
    }
}

function escribirFavorito(id){
    favorito = getUFavoritos();
    var targetObj = document.getElementById(id);
    if (targetObj!=null && typeof(targetObj)!='undefined' && targetObj.nodeType==1){
        targetObj.innerHTML=favorito;
    }
}

function validaPedidos(){
    var valida=true;
    var message="";
    if (!isEmail(document.formAtc.fmail.value)) {
        message=message+emailnocorrecto;
        valida=false;
    }
    if  (!isNotEmpty(document.formAtc.fnombre)){
        valida=false;
        message=message+nombreobligatorio;
    }
    if (!isNotEmpty(document.formAtc.fapellidos)){
        valida=false;
        message=message+apellidosobligatorios;
    }

    var i;
    var check=false;
    for (i=0;i<document.formAtc.subtipoIncid.length;i++){
        if (document.formAtc.subtipoIncid[i].checked) {
            if ((i==1) || (i==3)){
                if (!isNotEmpty(document.formAtc.fpregunta)){
                    valida=false;
                    message=message+preguntaobligatoria;
                }
            }
            check=true;
            break;
        }
    }
    if(!check){
        valida=false;
        message=message+seleccionarconsulta;
    }
    if (!valida) {
        document.formAtc.error_msn.value=message;
        document.formAtc.action="/atc/incidenciaPedido";
        document.formAtc.submit();
    }else{
        /*if (!esES()) {
                document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
		document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
		document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
            }*/
        document.formAtc.submit();
    }
}



function validaModificacionPedido(numPed){
    var valida=true;
    var message="";
    if  (!isNotEmpty(document.formAtc.fnumero)){
        valida=false;
        message=message+pedidoobligatorio;
    }
    if (!isEmail(document.formAtc.fmail.value)) {
        message=message+emailnocorrecto;
        valida=false;
    }
    if  (!isNotEmpty(document.formAtc.fnombre)){
        valida=false;
        message=message+nombreobligatorio;
    }
    if (!isNotEmpty(document.formAtc.fapellidos)){
        valida=false;
        message=message+apellidosobligatorios;
    }

    var i;
    var check=false;
    for (i=0;i<document.formAtc.subtipoIncid.length;i++){
        if (document.formAtc.subtipoIncid[i].checked) {
            if ((i==1) || (i==2) || (i==0) ){
                if (!isNotEmpty(document.formAtc.fpregunta)){
                    valida=false;
                    message=message+preguntaobligatoria;
                }
            }
            check=true;
            break;
        }
    }
    if(!check){
        valida=false;
        message=message+seleccionarmodificacion;
    }
    if (!valida) {
        document.formAtc.error_msn.value=message;
        document.formAtc.action="/atc/modificacionPedido?codPed="+numPed;
        document.formAtc.submit();
    }else{
        /*if (!esES()) {
                document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
		document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
		document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
            }*/
        document.formAtc.submit();
    }
}

function validaOtros() {
    var message="";
    var valida=true;
    var urldest="";
    if  (!isNotEmpty(document.formAtc.fnombre)) {
        valida=false;
        message=message+nombreobligatorio;
    }
    if (!isNotEmpty(document.formAtc.fapellidos)){
        valida=false;
        message=message+apellidosobligatorios;
    }
    if (!isNotEmpty(document.formAtc.fpregunta)){
        valida=false;
        message=message+preguntaobligatoria;
    }

    if ( !isEmail(document.formAtc.fmail.value) ) {
        message=message+emailnocorrecto;
        valida=false;
    }
    urldest=document.formAtc.url.value;
    if (!valida) {
        document.formAtc.error_msn.value=message;
        document.formAtc.action=urldest;
        document.formAtc.submit();
    } else {
        if (!esES()) {
            document.formAtc.fnombre.value=escape(document.formAtc.fnombre.value);
            document.formAtc.fapellidos.value=escape(document.formAtc.fapellidos.value);
            document.formAtc.fpregunta.value=escape(document.formAtc.fpregunta.value);
        }
        document.formAtc.submit();
    }
}
function validaRespuestas(){ //para las respuestas con radiobutton si/no
    var valida=true;
    message="";
    var urldest="";
    var check=false;
    var i;
    urldest=document.formAtc.url.value;
    for (i=0;i<document.formAtc.respuesta.length;i++){
        if (document.formAtc.respuesta[i].checked){
            check=true;
        }
    }
    if (!check){
        valida=false;
        message=noSeleccionResp;
    }
    if(!isNotEmpty(document.formAtc.fcomentarios)){
        valida=false;
        message=confirmeDireccion;
    }
    if (!valida) {
        document.formAtc.error_msn.value=message;
        document.formAtc.action=urldest;
        document.formAtc.submit();
    }else{
        /*if (!esES()) {
			document.formAtc.fcomentarios.value=escape(document.formAtc.fcomentarios.value);
		}*/
        document.formAtc.submit();
    }
}

function validaRespuestaSin() {
    if(isNotEmpty(document.formAtc.fcomentarios)){
        document.formAtc.fcomentarios.value=escape(document.formAtc.fcomentarios.value);
        document.formAtc.submit();
    }
}

var DINNERSCLUB = 1;
var MASTERCARD = 2;
var VISA = 3;
var AMERICANEXPRESS = 4;
var CONTRAREEMBOLSO = 5;
var CUENTALIBRERIA = 6;
var UNDEFINED = 7;
var BPE = 8;

function isDigit (c) {
	return ((c >= "0") && (c <= "9"));
}

function isInteger (s) {
	if ((s == null) || (s.length == 0)) return false;
	var i;
	for (i = 0; i < s.length; i++){
		// Check that current character is number.
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	// All characters are numbers.
	return true;
}

function esTarjetaValidaRes() {
	var index= document.formAtc.ftipo.selectedIndex;
	if (eval(document.formAtc.ftipo[index].value)==VISA) {
		return isVisa(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==MASTERCARD) {
		return isMasterCard(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==AMERICANEXPRESS) {
		return isAmericanExpress(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==DINNERSCLUB) {
		return isDinersClub(document.formAtc.ftarjeta.value);
	} else if (eval(document.formAtc.ftipo[index].value)==CUENTALIBRERIA) {
		return isCuentaLibreria(document.formAtc.ftarjeta.value);
	} else return false;
}


function validaTarjetaRes(){ //para las respuestas con radiobutton si/no
	var valida=true;
	var message="";
	var urldest="";
	var check=false;
	var i;
	urldest=document.formAtc.url.value;

	for (i=0;i<document.formAtc.respuesta.length;i++){
		if (document.formAtc.respuesta[i].checked){
			check=true;
		}
	}
	if (!check){
		valida=false;
		message="<li>Debe marcar una respuesta.</li>";
	}
	if (check && document.formAtc.respuesta[0].checked){
		if (!isNotEmpty(document.formAtc.ftitular) ) {
			message += '<li>Titular de la Tarjeta.</li>';
			valida=false;
		}
		if( eval(document.formAtc.ftipo[document.formAtc.ftipo.selectedIndex].value) == -1 ) {
			message += '<li>Tipo de Tarjeta.</li>';
			valida=false;
		} else {
			if( !esTarjetaValidaRes() ) {
				message += '<li>N&uacute;mero de la Tarjeta.</li>';
				valida=false;
			}
		}
		if( !esFechaValida() ) {
			message += '<li>Fecha de caducidad.</li>';
			valida=false;
		}
		if (!valida) {
			document.formAtc.error_msn.value='<ul>'+message+'</ul>';
			document.formAtc.action=urldest;
			document.formAtc.submit();
		}else{
			/*if (!esES()) {
				document.formAtc.ftitular.value=escape(document.formAtc.ftitular.value);
				document.formAtc.fcomentarios.value=escape(document.formAtc.fcomentarios.value);
			}*/
			document.formAtc.submit();
		}
	}else {
		if (!check){
			document.formAtc.error_msn.value='<ul>'+message+'</ul>';
			document.formAtc.action=urldest;
			document.formAtc.submit();
		}else{
			if(document.formAtc.respuesta[1].checked) document.formAtc.submit();
		}
	}
}

function isVisa(cc){
	if (((cc.length == 16) || (cc.length == 13)) && (cc.substring(0,1) == 4)){
		return isCreditCard(cc);
	}else return false;
}

function isMasterCard(cc){
	firstdig = cc.substring(0,1);
	seconddig = cc.substring(1,2);
	if ((cc.length == 16) && (firstdig == 5) && ((seconddig >= 1) && (seconddig <= 5)))
		return isCreditCard(cc);
	return false;
}

function isAmericanExpress(cc){
	firstdig = cc.substring(0,1);
	seconddig = cc.substring(1,2);
	if ((cc.length == 15) && (firstdig == 3) && ((seconddig == 4) || (seconddig == 7)))
		return isCreditCard(cc);
	return false;
}

function isDinersClub(cc){
	firstdig = cc.substring(0,1);
	seconddig = cc.substring(1,2);
	if ((cc.length == 14) && (firstdig == 3) && ((seconddig == 0) || (seconddig == 6) || (seconddig == 8)))
		return isCreditCard(cc);
	return false;
}

function isCuentaLibreria(cc){
	if ((cc.length == 6) || (cc.length == 7))
		return isInteger(cc);
	return false;
}

function isCreditCard(st) {
	if (st.length > 19)
		return (false);

	sum = 0; mul = 1; l = st.length;
	for (i = 0; i < l; i++) {
		digit = st.substring(l-i-1,l-i);
		tproduct = parseInt(digit ,10)*mul;
		if (tproduct >= 10)
			sum += (tproduct % 10) + 1;
		else
			sum += tproduct;
		if (mul == 1)
			mul++;
		else
			mul--;
	}
	if ((sum % 10) == 0)
		return (true);
	else
		return (false);
}
function esFechaValida() {
	var mesActual= document.formAtc.mesActual.value * 1;
	var anoActual= document.formAtc.anoActual.value *1;
	var mesTarjeta= document.formAtc.mes[document.formAtc.mes.selectedIndex].value * 1;
	var anoTarjeta= document.formAtc.ano[document.formAtc.ano.selectedIndex].value * 1;
	if (anoTarjeta>anoActual) {
		return true;
	} else {
		if (anoTarjeta==anoActual) {
			if (mesTarjeta>=mesActual) {
				return true;
			} else  {
				return false;
			}
		} else {
			return false;
		}
	}
}


function esES() {
    var idioma='';
    var isIE= (window.navigator.appName.indexOf('Explorer')>0);
    if (isIE) idioma= navigator.userLanguage.toLowerCase();
    else idioma= navigator.language;
    if ((idioma!='es') && (idioma!='es-es')) return false;
    else return true;
}

function writeSubmenuEspecial(pestana,lang){
    var subpestanas=document.getElementById("subpestanas");
    var texto="";
    texto=texto+'<div id="e_top_submenu"><ul>';
    if(pestana=='ngage'){
        texto=texto+'<li><a href="/plataforma-ngage/2918/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="active">NGAGE</a></li>';
    }else {
        texto=texto+'<li><a href="/plataforma-ngage/2918/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="">NGAGE</a></li>';
    }
    if(pestana=='psone'){
        texto=texto+'<li><a href="/plataforma-psone/33/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="active">PSONE</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-psone/33/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="">PSONE</a></li>';
    }
    if(pestana=='gcube'){
        texto=texto+'<li><a href="/plataforma-gcube/32/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="active">GCUBE</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-gcube/32/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="">GCUBE</a></li>';
    }
    if(pestana=='xbox'){
        texto=texto+'<li><a href="/plataforma-xbox360/18/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="active">XBOX360</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-xbox360/18/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="">XBOX360</a></li>';
    }
    if(pestana=='gba'){
        texto=texto+'<li><a href="/plataforma-gba/29/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="active">GBA</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-gba/29/1/1';
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="">GBA</a></li>';
    }
    texto=texto+'</ul></div>';
    subpestanas.innerHTML=texto;
}

function writeSubmenu(plataforma,activa,lang){
    var subpestanas=document.getElementById("subpestanas");
    var texto="";
    texto=texto+'<div id="e_top_submenu"><ul>';
    texto=texto+'<li><a href="/videojuegos/pack/25/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='pack'){
        texto=texto+'active';
    }
    texto=texto+'">'+'pack'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/infantil/1/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='infantil'){
        texto=texto+'active';
    }
    texto=texto+'">'+'infantil'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/arcade/4/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='arcade'){
        texto=texto+'active';
    }
    texto=texto+'">'+'arcade'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/plataformas/21/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='plataformas'){
        texto=texto+'active';
    }
    texto=texto+'">'+'plataformas'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/simulacion/5/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='simulacion'){
        texto=texto+'active';
    }
    texto=texto+'">'+'simulacion'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/habilidad/7/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='habilidad'){
        texto=texto+'active';
    }
    texto=texto+'">'+'habilidad'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/estrategia/6/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='estrategia'){
        texto=texto+'active';
    }
    texto=texto+'">'+'estrategia'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/rol/9/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='rol'){
        texto=texto+'active';
    }
    texto=texto+'">'+'rol'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/lucha/43/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='lucha'){
        texto=texto+'active';
    }
    texto=texto+'">'+'lucha'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/musica/63/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='musica'){
        texto=texto+'active';
    }
    texto=texto+'">'+'musica'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/deportes/2/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='deportes'){
        texto=texto+'active';
    }
    texto=texto+'">'+'deportes'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/conduccion/17/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='conduccion'){
        texto=texto+'active';
    }
    texto=texto+'">'+'conduccion'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/shooter/14/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='shooter'){
        texto=texto+'active';
    }
    texto=texto+'">'+'shooter'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/accion/3/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='accion'){
        texto=texto+'active';
    }
    texto=texto+'">'+'accion'+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/aventuragrafica/13/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='aventuragrafica'){
        texto=texto+'active';
    }
    texto=texto+'">'+'aventura grafica'+'</a></li>';

     texto=texto+'<li><a href="/videojuegos/aventura/11167/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='aventura'){
        texto=texto+'active';
    }
    texto=texto+'">'+'aventura'+'</a></li>';

     texto=texto+'<li><a href="/videojuegos/educativo/11168/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='educativo'){
        texto=texto+'active';
    }
    texto=texto+'">'+'educativo'+'</a></li>';

     texto=texto+'<li><a href="/videojuegos/inteligencia/11169/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='inteligencia'){
        texto=texto+'active';
    }
    texto=texto+'">'+'inteligencia'+'</a></li>';

     texto=texto+'<li><a href="/videojuegos/puzzle/11170/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='puzzle'){
        texto=texto+'active';
    }
    texto=texto+'">'+'puzzle'+'</a></li>';

     texto=texto+'<li><a href="/videojuegos/terror/11171/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='terror'){
        texto=texto+'active';
    }
    texto=texto+'">'+'terror'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/guias/285/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='guias'){
        texto=texto+'active';
    }
    texto=texto+'">'+'guias'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/memorias/1901/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='memorias'){
        texto=texto+'active';
    }
    texto=texto+'">'+'memorias'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/perifericos/11172/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='perifericos'){
        texto=texto+'active';
    }
    texto=texto+'">'+'perifericos'+'</a></li>';

    texto=texto+'<li><a href="/videojuegos/tarjetas/1295/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='tarjetas'){
        texto=texto+'active';
    }
    texto=texto+'">'+'tarjetas prepago'+'</a></li>';

    /*texto=texto+'<li><a href="/videojuegos/accesorios/307/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='accesorios'){
        texto=texto+'active';
    }
    texto=texto+'">'+'accesorios'+'</a></li>';
    */
    texto=texto+'<li><a href="/videojuegos/consolas/1317/'+plataforma;
    if(lang!=null && lang!='null'){
        texto=texto+'/'+lang;
    }
    texto=texto+'" class="';
    if(activa=='consolas'){
        texto=texto+'active';
    }
    texto=texto+'">'+'consolas'+'</a></li>';
    var idListaLiq=0;
    var idListaChollo=0;
    var nombrePlat='-';
    if(plataforma=='14'){ //nds
        idListaLiq=229;
        idListaChollo=239;
        nombrePlat='nds';
    }else if(plataforma=='11'){ //pc
        idListaLiq=231;
        idListaChollo=0;
        nombrePlat='pc';
    }else if(plataforma=='15'){ //ps2
        idListaLiq=232;
        idListaChollo=240;
        nombrePlat='ps2';
    }else if(plataforma=='10'){ //ps3
        idListaLiq=233;
        idListaChollo=241;
        nombrePlat='ps3';
    }else if(plataforma=='20'){ //psp
        idListaLiq=235;
        idListaChollo=242;
        nombrePlat='psp';
    }else if(plataforma=='13'){ //wii
        idListaLiq=236;
        idListaChollo=243;
        nombrePlat='wii';
    }else if(plataforma=='18'){ //x360
        idListaLiq=237;
        idListaChollo=244;
        nombrePlat='x360';
    }
    /*if(eval(idListaLiq)>0){
        texto=texto+'<li><a href="/lista/liquidacion-'+nombrePlat+'/1'+'/'+idListaLiq+"/1";
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="';
        if(activa=='liquidaciones'){
            texto=texto+'active';
        }
        texto=texto+'" style="color:#2D2D2D">'+'liquidaciones'+'</a></li>';
    }*/
    if(eval(idListaChollo)>0){
        texto=texto+'<li><a href="/lista/chollos-'+nombrePlat+'/1'+'/'+idListaChollo+"/1";
        if(lang!=null && lang!='null'){
            texto=texto+'/'+lang;
        }
        texto=texto+'" class="';
        if(activa=='chollos'){
            texto=texto+'active';
        }
        texto=texto+'" style="color:#DB1E24"><b>'+'chollos'+'</b></a></li>';
    }
    texto=texto+'</ul></div>';
    subpestanas.innerHTML=texto;

}
var qsParm = new Array();
function qs() {
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) {
        var pos = parms[i].indexOf('=');
        if (pos > 0) {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
}
function writeTematica(url,plataforma,lang){
    if(url.indexOf("videojuegos/pack")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==25)){
        writeSubmenu(plataforma,'pack',lang);
    }else if(url.indexOf("videojuegos/infantil")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==1)){
        writeSubmenu(plataforma,'infantil',lang);
    }else if(url.indexOf("videojuegos/arcade")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==4)){
        writeSubmenu(plataforma,'arcade',lang);
    }else if(url.indexOf("videojuegos/plataformas")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==21)){
        writeSubmenu(plataforma,'plataformas',lang);
    }else if(url.indexOf("videojuegos/simulacion")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==5)){
        writeSubmenu(plataforma,'simulacion',lang);
    }else if(url.indexOf("videojuegos/guias")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==285)){
        writeSubmenu(plataforma,'guias',lang);
    }else if(url.indexOf("videojuegos/habilidad")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==7)){
        writeSubmenu(plataforma,'habilidad',lang);
    }else if(url.indexOf("videojuegos/estrategia")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==6)){
        writeSubmenu(plataforma,'estrategia',lang);
    }else if(url.indexOf("videojuegos/rol")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==9)){
        writeSubmenu(plataforma,'rol',lang);
    }else if(url.indexOf("videojuegos/consolas")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==1317)){
        writeSubmenu(plataforma,'consolas',lang);
    }else if(url.indexOf("videojuegos/lucha")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==43)){
        writeSubmenu(plataforma,'lucha',lang);
    }else if(url.indexOf("videojuegos/musica")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==63)){
        writeSubmenu(plataforma,'musica',lang);
    }else if(url.indexOf("videojuegos/deportes")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==2)){
        writeSubmenu(plataforma,'deportes',lang);
    }else if(url.indexOf("videojuegos/conduccion")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==17)){
        writeSubmenu(plataforma,'conduccion',lang);
    }else if(url.indexOf("videojuegos/shooter")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==14)){
        writeSubmenu(plataforma,'shooter',lang);
    /*}else if(url.indexOf("videojuegos/accesorios")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==307)){
        writeSubmenu(plataforma,'accesorios',lang);*/
    }else if(url.indexOf("videojuegos/accion")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==3)){
        writeSubmenu(plataforma,'accion',lang);
    }else if(url.indexOf("videojuegos/aventuragrafica")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==13)){
        writeSubmenu(plataforma,'aventuragrafica',lang);
    }else if(url.indexOf("videojuegos/aventura")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==11167)){
        writeSubmenu(plataforma,'aventura',lang);
    }else if(url.indexOf("videojuegos/educativo")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==11168)){
        writeSubmenu(plataforma,'educativo',lang);
    }else if(url.indexOf("videojuegos/inteligencia")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==11169)){
        writeSubmenu(plataforma,'inteligencia',lang);
    }else if(url.indexOf("videojuegos/puzzle")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==11170)){
        writeSubmenu(plataforma,'puzzle',lang);
    }else if(url.indexOf("videojuegos/terror")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==11171)){
        writeSubmenu(plataforma,'terror',lang);
     }else if(url.indexOf("videojuegos/memorias")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==1901)){
        writeSubmenu(plataforma,'memorias',lang);
     }else if(url.indexOf("videojuegos/perifericos")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==11172)){
        writeSubmenu(plataforma,'perifericos',lang);
     }else if(url.indexOf("videojuegos/tarjetas")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==1295)){
        writeSubmenu(plataforma,'tarjetas',lang);
    }
}
function writePesta(lang) {
    url=window.location.pathname;
    qs();
    var pest;
    try{
        if (url=='' || url=='/' || url.indexOf("home")>-1){
        //pest=document.getElementById("ps1");
        //if (esNodo(pest))
        //	pest.className="pestaAct";
        }else if (url.indexOf("videojuegos-ps3")>-1 || url.indexOf("plataforma-ps3")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==10)){
            pest=document.getElementById("pestana1");

            pest.innerHTML='<img src="/im/menu_PS3_on.jpg.png" />';
            writeSubmenu('10','',lang);
        }else if (url.indexOf("videojuegos-ps2")>-1 || url.indexOf("plataforma-ps2")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==15)){
            pest=document.getElementById("pestana2");
            pest.innerHTML='<img src="/im/menu_PS2_on.jpg.png" />';
            writeSubmenu('15','',lang);
        }else if (url.indexOf("videojuegos-wii")>-1 || url.indexOf("plataforma-wii")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==13)){
            pest=document.getElementById("pestana3");
            pest.innerHTML='<img src="/im/menu_WII_on.jpg.png" />';
            writeSubmenu('13','',lang);
        }else if (url.indexOf("videojuegos-nds")>-1 || url.indexOf("plataforma-nds")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==14)){
            pest=document.getElementById("pestana4");
            pest.innerHTML='<img src="/im/menu_NDS_on.jpg.png" />';
            writeSubmenu('14','',lang);
        }else if (url.indexOf("videojuegos-x360")>-1 || url.indexOf("plataforma-x360")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==18)){
            pest=document.getElementById("pestana5");
            pest.innerHTML='<img src="/im/menu_x360_on.jpg.png" />';
            writeSubmenu('18','',lang);
        }else if (url.indexOf("videojuegos-psp")>-1 || url.indexOf("plataforma-psp")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==20)){
            pest=document.getElementById("pestana6");
            pest.innerHTML='<img src="/im/menu_PSP_on.jpg.png" />';
            writeSubmenu('20','',lang);
        }else if (url.indexOf("videojuegos-pc")>-1 || url.indexOf("plataforma-pc")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==11)){
            pest=document.getElementById("pestana7");
            pest.innerHTML='<img src="/im/menu_PC_on.jpg.png" />';
            writeSubmenu('11','',lang);
        } else if(url.indexOf("plataforma-otras")>-1  || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==9)){
            writeSubmenuEspecial('',lang);
        } else if(url.indexOf("plataforma-ngage")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==2918)){
            writeSubmenuEspecial('ngage',lang);
        } else if(url.indexOf("plataforma-psone")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==33)){
            writeSubmenuEspecial('psone',lang);
        } else if(url.indexOf("plataforma-gcube")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==32)){
            writeSubmenuEspecial('gcube',lang);
        } else if(url.indexOf("plataforma-xbox")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==18)){
            writeSubmenuEspecial('xbox',lang);
        } else if(url.indexOf("plataforma-gba")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==29)){
            writeSubmenuEspecial('gba',lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/10")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==10)){//PS3
            pest=document.getElementById("pestana1",lang);
            pest.innerHTML='<img src="/im/menu_PS3_on.jpg.png" />';
            writeTematica(url,10,lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/15")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==15)){//PS2
            pest=document.getElementById("pestana2");
            pest.innerHTML='<img src="/im/menu_PS2_on.jpg.png" />';
            writeTematica(url,15,lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/13")>-1 && url.indexOf("/1317/14")==-1 && url.indexOf("/1317/21")==-1 && url.indexOf("/1317/20")==-1 && url.indexOf("/1317/11")==-1 && url.indexOf("/1317/18")==-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==13)){//WII
            pest=document.getElementById("pestana3");
            pest.innerHTML='<img src="/im/menu_WII_on.jpg.png" />';
            writeTematica(url,13,lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/14")>-1 && url.indexOf("/14/21")==-1 && url.indexOf("/14/20")==-1 && url.indexOf("/14/11")==-1 && url.indexOf("/14/18")==-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==14)){//NDS
            pest=document.getElementById("pestana4");
            pest.innerHTML='<img src="/im/menu_NDS_on.jpg.png" />';
            writeTematica(url,14,lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/18")>-1 && url.indexOf("/18/20")==-1 && url.indexOf("/18/11")==-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==18)){//X360
            pest=document.getElementById("pestana5");
            pest.innerHTML='<img src="/im/menu_x360_on.jpg.png" />';
            writeTematica(url,18,lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/20")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==20)){//PSP
            pest=document.getElementById("pestana6");
            pest.innerHTML='<img src="/im/menu_PSP_on.jpg.png" />';
            writeTematica(url,20,lang);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/11")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==11)){//PC
            pest=document.getElementById("pestana7");
            pest.innerHTML='<img src="/im/menu_PC_on.jpg.png" />';
            writeTematica(url,11,lang);
        }
    }catch(e){};
}

function cambiaLangWeb(idioma){
    var actual=window.location;
    var nueva=location.pathname;
    if (nueva==null || nueva=="" || nueva=="/"){
        nueva=location.protocol+"//"+location.host;
    }
    var inclu=false;
    var querystring=location.search.substring(1,location.search.length);
    if (querystring==null || querystring==""){
        var posIdi=nueva.lastIndexOf("/");
        var idiOrig=nueva.substring(posIdi+1,nueva.length);
        idiOrig=idiOrig.toLowerCase();
        if (idiOrig!="" && (idiOrig=="es_es" || idiOrig=="ca_es" || idiOrig=="fr_fr" || idiOrig=="en_gb" || idiOrig=="pt_pt")){
            nueva=nueva.substring(0,posIdi)+"/"+idioma;
        }else{
            nueva=nueva+"/"+idioma;
        }
    }else{
        var args = querystring.split('&');
        if (args.length==1){
            var pair = args[0].split('=');
            if (pair[0]=="lang"){
                nueva=nueva+"?lang="+idioma;
            }else{
                nueva=nueva+"?"+args[0]+"&lang="+idioma;
            }
        }else{
            nueva=nueva+"?";
            var i=0;
            do {
                if (i>0){
                    nueva=nueva+"&";
                }
                var pair = args[i].split('=');
                if (pair[0]=="lang"){
                    nueva=nueva+"lang="+idioma;
                    inclu=true;
                }else{
                    nueva=nueva+args[i];
                }
                i++;
            } while(i < args.length);
            if (!inclu){
                nueva=nueva+"&lang="+idioma;
            }
        }
    }
    window.location=nueva;
}
function inputAlt(src, flag, value){
    if (flag){
        if (src.value == value){
            src.value = '';
            src.style.color = '#000000';
        }
    }else{
        if (src.value == ''){
            src.value = value;
            src.style.color = '#CCCCCC';
        }
    }
}

function ismaxlength(obj){
    var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
    if (obj.getAttribute && obj.value.length>mlength)
        obj.value=obj.value.substring(0,mlength)
}

function mostrarFormulario(tipoFormulario){
    var contenido=document.getElementById("formularios");
    contenido.innerHTML="<img src=\"/im/loading.gif\" alt=\"Cargando\" style=\"width:21px;heigth:21px;\" class=\"vmiddle\" /><span style=\"color:red;font-weight:bold;font-size:12px;\"> Cargando...</span>";
    var myConn = new XHConn();
    if (!myConn) alert("XMLHTTP no esta disponible. Int&eacute;ntalo con un navegador m&aacute;s actual.");
    var peticion = function (oXML) {
        contenido.style.display = 'inline';
        contenido.style.visibility = 'visible';
        contenido.innerHTML=oXML.responseText;
    }
    myConn.connect(tipoFormulario, "POST", "", peticion);
}
function irAComentar(elemID, idProducto, idExterno){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
    offsetLeft += offsetTrail.offsetLeft;
    offsetTop += offsetTrail.offsetTop;
    offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined" && navigator.appName=="Microsoft Internet Explorer" ) {
    offsetLeft += parseInt(document.body.leftMargin);
    offsetTop += parseInt(document.body.topMargin);
    }
    window.scrollTo(offsetLeft,offsetTop);
    mostrarFormulario('/fichas/cajaComentarioUp?idproducto='+idProducto+'&idexterno='+idExterno);
}

function enviarAgotadoAjax(formulario){

    if (isEmail(formulario.email.value)){
        var variables="idproducto="+formulario.idproducto.value+"&email="+formulario.email.value;
        if (formulario.cvjNewsletter.checked){
            variables+="&cvjNewsletter="+formulario.cvjNewsletter.value;
        }
        if (formulario.cvjComercial.checked){
            variables+="&cvjComercial="+formulario.cvjComercial.value;
        }
        var contenido=document.getElementById("formularios");
        contenido.innerHTML="<img src=\"/i/cargando.gif\" alt=\"Cargando\" class=\"vmiddle\" /> Cargando...";
        var myConn = new XHConn();
        if (!myConn) alert("XMLHTTP no esta disponible. Int&eacute;ntalo con un navegador m&aacute;s actual.");
        var peticion = function (oXML) {
            contenido.innerHTML=oXML.responseText;
        }
        myConn.connect("/fichas/alarmaAgotado", "POST", variables, peticion);
    }else{
        var contenido=document.getElementById("errorAgotado");
        contenido.innerHTML="<span style='color:red'>El email es incorrecto</span>"
    }
}
function cerrarAgotado(){
    var contenido=document.getElementById("formularios");
    contenido.innerHTML="";
}

var imagen1;
function mantenerCapa(obje){
        var element = document.getElementById(obje);
        if(element!=null && element!='undefined'){
            imagen1=element.style;
            //element.style.clip="rect(0px 0px 0px 0px)";
            element.style.display="block";
            //RestaurarImagen(196,14,11,35);
        }
}
function ocultarCapa(obje){
        var element = document.getElementById(obje);
         if(element!=null && element!='undefined'){
            element.style.display="none";
        }
	var selects=document.getElementsByTagName('SELECT');
	if (selects!=null){
		for (var pos=0;pos<selects.length;pos++){
			selects[pos].style.visibility="visible";
		}
	}
}

var accion;
var limite;
function RecorteRelativo (objeto,superior,derecho,inferior,izquierdo) {
	objeto.clip = "rect("+(this.LeeRecorte(objeto,'superior')+superior)+"px "+(this.LeeRecorte(objeto,'derecho')+derecho)+"px "+Number(this.LeeRecorte(objeto,'inferior')+inferior)+"px "+Number(this.LeeRecorte(objeto,'izquierdo')+izquierdo)+"px)"
}

function RestaurarImagen(limite,derecho,izquierda,velocidad){
	if (LeeRecorte(imagen1,'derecho') < limite){
		RecorteRelativo (imagen1,0,derecho,izquierda,0);
		if(accion) clearTimeout(accion);
		accion = setTimeout ("RestaurarImagen("+limite+","+derecho+","+izquierda+","+velocidad+")",velocidad)
	}
}
function LeeRecorte (objeto,borde){
	var vectorRecorte = objeto.clip.split("rect(")[1].split(")")[0].replace(/,/g, "").split("px");
	if (borde=="superior")
		return Number(vectorRecorte[0])
	if (borde=="derecho")
		return Number(vectorRecorte[1])
	if (borde=="inferior")
		return Number(vectorRecorte[2])
	if (borde=="izquierdo")
		return Number(vectorRecorte[3])
}
function doFilter(idplataforma,page){
    var catg = document.getElementById('idcategoria');
    var frm = document.getElementById('busqFilt');
    var url =  '/secciones/plataforma?idcategoria='+catg.value+'&idplat='+idplataforma+'&page='+page;
    if (catg.value==-2){
        if (idplataforma == 10)
            url  = '/lista/chollos-ps3/1/241/1';
        else if(idplataforma == 13)
            url  = '/lista/chollos-wii/1/243/1';
        else if(idplataforma == 14)
            url  = '/lista/chollos-nds/1/239/1';
        else if(idplataforma == 15)
            url  = '/lista/chollos-ps2/1/240/1';
        else if(idplataforma == 18)
            url  =  '/lista/chollos-x360/1/244/1';
        else if(idplataforma == 20)
            url  =  '/lista/chollos-psp/1/242/1';
    }
    window.location.href = url;
}
function escribirEnlaces(id,urlDatosUsuario,urlSalir,urlPedidos,urlFavoritos,urlEntrar,urlRegistrar){
    var nombre = getUNombre();
    var favorito = getUFavoritos();
    var targetObj = document.getElementById(id);
    if (targetObj!=null && typeof(targetObj)!='undefined' && targetObj.nodeType==1){
        if (favorito==null || isEmpty(favorito)) {
            targetObj.innerHTML="<a class=\"a1\" href=\""+urlEntrar+"\">"+entrar+"</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a class=\"a1\" href=\""+urlRegistrar+"\">"+registrarte+"</a>";
        }else{
            targetObj.innerHTML="<span >"+hola+"</span>&nbsp;<a class=\"a1\" href=\""+urlDatosUsuario+"\">amig@</a><b>&nbsp;&nbsp;[<a class=\"a1\" href=\""+urlSalir+"\">"+salir+"</a>]</b>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\""+urlDatosUsuario+"\">"+tusdatos+"</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\""+urlPedidos+"\">"+tuspedidos+"</a>&nbsp;&nbsp;|&nbsp;&nbsp;<img src=\"/im/icon_heart.gif\" align=\"middle\" />&nbsp;&nbsp;<a href=\""+urlFavoritos+"\" onclick=\"javascript:addOrigen('mfCvj')\">"+tusfavoritos+"</a>";
        }
    }
}