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(palabra){
    if(document.fBusca.buscar.value!=palabra){
        document.onclick = processClicks;
        document.onkeypress=processKeys;
        //document.fBusca.boton_Buscar.disabled=true;
        document.fBusca.buscar.readOnly=true;
        if (!rapidaenviada){ rapidaenviada=true;document.fBusca.submit();}
     }
     return false;
}

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=='quick') {
      form1=true;
      form2=false;
  }
  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 formatFloatSinDecimales (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 isNotEmpty(field) {
    var inputStr = Trim(field.value)
    if (inputStr == "" || inputStr == null) {
        return false
    }
    return true
}

var dvdgovisitor= getCookie("dvdgovisitor");
var uNombre= getUNombre();
var uFavoritos= getUFavoritos();
var uId= getUId();

function getUNombre() {
	uNombre='';
	if (dvdgovisitor!=null) {
        var campos=dvdgovisitor.split("-");
        if(campos.length>=2)
            uNombre=campos[2];
	}
	return uNombre;
}

function getUFavoritos() {
	var uFavoritos='';
	if (dvdgovisitor!=null) {
		var i1= dvdgovisitor.indexOf("-");
		if (i1>=0) {
			var resto= dvdgovisitor.substring(i1+1);
			var i2= resto.indexOf("-");
			if (i2>=0) {
				uFavoritos= resto.substring(0,i2);
			}
		}
	}
	return uFavoritos;
}

function getUId() {
	var uId='0';
		if (dvdgovisitor!=null) {
		var i1= dvdgovisitor.indexOf("-");
		if (i1>=0) {
			uId= dvdgovisitor.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 escribirEnlaces(id,urlDatosUsuario,urlSalir,urlPedidos,urlFavoritos,urlSegundaMano,urlEntrar,urlRegistrar,urlLogPedidos){
    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>"+"&nbsp;&nbsp;|&nbsp;&nbsp;<a class=\"a1\" href=\"/vendedor/ayudaSegundaMano\">"+segundaMano+"</a>" +"&nbsp;&nbsp;|&nbsp;&nbsp;<a class=\"a1\" href=\""+urlLogPedidos+"\">"+tuspedidos+"</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>" +"&nbsp;&nbsp;|&nbsp;&nbsp;<a href=\""+urlSegundaMano+"\" onclick=\"javascript:addOrigen('mfCvj')\">"+segundaMano+"</a>";
        }
    }
}

function validaPedidos(){
	var valida=true;
	var message="";
    if(!isNotEmpty(document.formAtc.fnumero)){
        valida=false;
        message=message+pedidoOblig;
    }
	if (!isEmail(document.formAtc.fmail.value)) {
		message=message+emailnocorrecto;
		valida=false;
	}
	if  (!isNotEmpty(document.formAtc.fnombre)){
		valida=false;
		message=message+nombreOblig;
	}
	if (!isNotEmpty(document.formAtc.fapellidos)){
		valida=false;
		message=message+apellidosOblig;
	}

	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+preguntaOblig;
                    }
                }
                check=true;
	        break;
            }
    	}
	if(!check){
            valida=false;
            message=message+noSeleccionConsulta;
	}
	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+pedidoOblig;
	}
	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+nombreOblig;
	}
	if (!isNotEmpty(document.formAtc.fapellidos)){
		valida=false;
		message=message+apellidosOblig;
	}
 	 if (!isNotEmpty(document.formAtc.fpregunta)){
		valida=false;
		message=message+preguntaOblig;
	}

	if ( !isEmail(document.formAtc.fmail.value) ) {
		message=message+emailIncorrecto;
		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;
	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="Debe marcar una respuesta.";
	}
    if(!isNotEmpty(document.formAtc.fcomentarios)){
        valida=false;
        message="Confirme la direccion, por favor.";
    }
	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){
    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" class="active">NGAGE</a></li>';
    }else {
        texto=texto+'<li><a href="/plataforma-ngage/2918/1/1" class="">NGAGE</a></li>';
    }
    if(pestana=='psone'){
        texto=texto+'<li><a href="/plataforma-psone/33/1/1" class="active">PSONE</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-psone/33/1/1" class="">PSONE</a></li>';
    }
    if(pestana=='gcube'){
        texto=texto+'<li><a href="/plataforma-gcube/32/1/1" class="active">GCUBE</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-gcube/32/1/1" class="">GCUBE</a></li>';
    }
    if(pestana=='xbox'){
        texto=texto+'<li><a href="/plataforma-xbox/21/1/1" class="active">XBOX</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-xbox/21/1/1" class="">XBOX</a></li>';
    }
    if(pestana=='gba'){
        texto=texto+'<li><a href="/plataforma-gba/29/1/1" class="active">GBA</a></li>';
    }else{
        texto=texto+'<li><a href="/plataforma-gba/29/1/1" class="">GBA</a></li>';
    }
    texto=texto+'</ul></div>';
    subpestanas.innerHTML=texto;
}

function writeSubmenu(plataforma,activa){
    var subpestanas=document.getElementById("subpestanas");
    var texto="";
    texto=texto+'<div id="e_top_submenu"><ul>';
    texto=texto+'<li><a href="/videojuegos/otros/52/'+plataforma+'" class="';
    if(activa=='otros'){
        texto=texto+'active';
    }
    texto=texto+'">'+otros+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/pack/25/'+plataforma+'" class="';
    if(activa=='pack'){
        texto=texto+'active';
    }
    texto=texto+'">'+packjuegos+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/infantil/1/'+plataforma+'" class="';
    if(activa=='infantil'){
        texto=texto+'active';
    }
    texto=texto+'">'+infantil+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/arcade/4/'+plataforma+'" class="';
    if(activa=='arcade'){
        texto=texto+'active';
    }
    texto=texto+'">'+arcade+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/plataformas/21/'+plataforma+'" class="';
    if(activa=='plataformas'){
        texto=texto+'active';
    }
    texto=texto+'">'+plataformas+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/simulacion/5/'+plataforma+'" class="';
    if(activa=='simulacion'){
        texto=texto+'active';
    }
    texto=texto+'">'+simulacion+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/guias/285/'+plataforma+'" class="';
    if(activa=='guias'){
        texto=texto+'active';
    }
    texto=texto+'">'+guias+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/habilidad/7/'+plataforma+'" class="';
    if(activa=='habilidad'){
        texto=texto+'active';
    }
    texto=texto+'">'+habilidad+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/estrategia/6/'+plataforma+'" class="';
    if(activa=='estrategia'){
        texto=texto+'active';
    }
    texto=texto+'">'+estrategia+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/rol/9/'+plataforma+'" class="';
    if(activa=='rol'){
        texto=texto+'active';
    }
    texto=texto+'">'+rol+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/consolas/1317/'+plataforma+'" class="';
    if(activa=='consolas'){
        texto=texto+'active';
    }
    texto=texto+'">'+consolas+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/lucha/43/'+plataforma+'" class="';
    if(activa=='lucha'){
        texto=texto+'active';
    }
    texto=texto+'">'+lucha+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/musica/69/'+plataforma+'" class="';
    if(activa=='musica'){
        texto=texto+'active';
    }
    texto=texto+'">'+musica+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/deportes/2/'+plataforma+'" class="';
    if(activa=='deportes'){
        texto=texto+'active';
    }
    texto=texto+'">'+deportes+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/conduccion/17/'+plataforma+'" class="';
    if(activa=='conduccion'){
        texto=texto+'active';
    }
    texto=texto+'">'+conduccion+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/shooter/14/'+plataforma+'" class="';
    if(activa=='shooter'){
        texto=texto+'active';
    }
    texto=texto+'">'+shooter+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/accesorios/307/'+plataforma+'" class="';
    if(activa=='accesorios'){
        texto=texto+'active';
    }
    texto=texto+'">'+accesorios+'</a></li>';
    texto=texto+'<li><a href="/videojuegos/accion/3/'+plataforma+'" class="';
    if(activa=='accion'){
        texto=texto+'active';
    }
    texto=texto+'">'+accion+'</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){
    if(url.indexOf("videojuegos/otros")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==52)){
        writeSubmenu(plataforma,'otros');
    }else if(url.indexOf("videojuegos/pack")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==25)){
        writeSubmenu(plataforma,'pack');
    }else if(url.indexOf("videojuegos/infantil")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==1)){
        writeSubmenu(plataforma,'infantil');
    }else if(url.indexOf("videojuegos/arcade")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==4)){
        writeSubmenu(plataforma,'arcade');
    }else if(url.indexOf("videojuegos/plataformas")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==21)){
        writeSubmenu(plataforma,'plataformas');
    }else if(url.indexOf("videojuegos/simulacion")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==5)){
        writeSubmenu(plataforma,'simulacion');
    }else if(url.indexOf("videojuegos/guias")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==285)){
        writeSubmenu(plataforma,'guias');
    }else if(url.indexOf("videojuegos/habilidad")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==7)){
        writeSubmenu(plataforma,'habilidad');
    }else if(url.indexOf("videojuegos/estrategia")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==6)){
        writeSubmenu(plataforma,'estrategia');
    }else if(url.indexOf("videojuegos/rol")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==9)){
        writeSubmenu(plataforma,'rol');
    }else if(url.indexOf("videojuegos/consolas")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==1317)){
        writeSubmenu(plataforma,'consolas');
    }else if(url.indexOf("videojuegos/lucha")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==43)){
        writeSubmenu(plataforma,'lucha');
    }else if(url.indexOf("videojuegos/musica")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==69)){
        writeSubmenu(plataforma,'musica');
    }else if(url.indexOf("videojuegos/deportes")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==2)){
        writeSubmenu(plataforma,'deportes');
    }else if(url.indexOf("videojuegos/conduccion")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==17)){
        writeSubmenu(plataforma,'conduccion');
    }else if(url.indexOf("videojuegos/shooter")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==14)){
        writeSubmenu(plataforma,'shooter');
    }else if(url.indexOf("videojuegos/accesorios")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==307)){
        writeSubmenu(plataforma,'accesorios');
    }else if(url.indexOf("videojuegos/accion")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idcategoria']==3)){
        writeSubmenu(plataforma,'accion');
    }
}
function writePesta() {
        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','');
        }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','');
        }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','');
        }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','');
        }else if (url.indexOf("videojuegos-x360")>-1 || url.indexOf("plataforma-x360")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==21)){
                                            pest=document.getElementById("pestana5");
                                            pest.innerHTML='<img src="/im/menu_x360_on.jpg.png" />';
                                            writeSubmenu('21','');
        }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','');
        }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','');
        } else if(url.indexOf("plataforma-otras")>-1  || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==9)){
            writeSubmenuEspecial('');
        } else if(url.indexOf("plataforma-ngage")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==2918)){
            writeSubmenuEspecial('ngage');
        } else if(url.indexOf("plataforma-psone")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==33)){
            writeSubmenuEspecial('psone');
        } else if(url.indexOf("plataforma-gcube")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==32)){
            writeSubmenuEspecial('gcube');
        } else if(url.indexOf("plataforma-xbox")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==21)){
            writeSubmenuEspecial('xbox');
        } else if(url.indexOf("plataforma-gba")>-1 || (url.indexOf("secciones/plataforma")>-1 && qsParm['idplat']==29)){
            writeSubmenuEspecial('gba');
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/10")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==10)){//PS3
            pest=document.getElementById("pestana1");
            pest.innerHTML='<img src="/im/menu_PS3_on.jpg.png" />';
            writeTematica(url,10);
        }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);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/13")>-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);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/14")>-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);
        }else if(url.indexOf("videojuegos/")>-1 && url.indexOf("/21")>-1 || (url.indexOf("temas/tematica")>-1 && qsParm['idplat']==21)){//X360
            pest=document.getElementById("pestana5");
            pest.innerHTML='<img src="/im/menu_x360_on.jpg.png" />';
            writeTematica(url,21);
        }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);
        }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);
        }
	}catch(e){};
}
function inputAlt(src, flag, value){
    if (flag)
    {
        if (Trim(src.value) == value)
        {
            src.value = '';
            src.style.color = '#000000';
        }
    }
    else
    {
        if (Trim(src.value) == '')
        {
            src.value = value;
            src.style.color = '#CCCCCC';
        }
    }
}

function filtrarCategoria(idCat, elementCat, catProhibida, nameCat)
{
    var coment=document.getElementById(elementCat);
    for(var ii=0;ii<coment.options.length;ii++){
        if((coment.options[ii].id=='') || (coment.options[ii].id == (nameCat+idCat) && coment.options[ii].id != (nameCat+catProhibida))){
            coment.options[ii].style.visibility="visible";
            coment.options[ii].style.display="block";
        }else{
            coment.options[ii].style.visibility="hidden";
            coment.options[ii].style.display="none";
            if(coment.options[ii].selected)
                coment.options[ii].selected=false;
        }
    }

}

var idCatAnterior='12';
function filtrarCategoriaBusqueda(idCat,idSelect)
{
    if(idCat=='')
        idCat='12';
    var coment=document.getElementById(idSelect+idCat);
    if(coment!=null){
        if(coment.style.visibility=="hidden"){
            var comentAnterior=document.getElementById(idSelect+idCatAnterior);
            if(comentAnterior!=null && comentAnterior.style.visibility=="visible"){
                comentAnterior.style.visibility="hidden";
                comentAnterior.style.display="none";
            }
            coment.style.visibility="visible";
            coment.style.display="block";
            idCatAnterior=idCat;
            darValorCatBusq(coment.value,idSelect);
        }
    }
}
var idCatAnteriorX='26';
function filtrarCategoriaBusquedaX(idCat,idSelect)
{
    if(idCat=='')
        idCat='26';
    var coment=document.getElementById(idSelect+idCat);
    if(coment!=null){
        if(coment.style.visibility=="hidden"){
            var comentAnterior=document.getElementById(idSelect+idCatAnteriorX);
            if(comentAnterior!=null && comentAnterior.style.visibility=="visible"){
                comentAnterior.style.visibility="hidden";
                comentAnterior.style.display="none";
            }
            coment.style.visibility="visible";
            coment.style.display="block";
            idCatAnteriorX=idCat;
            darValorCatBusq(coment.value,idSelect);
        }
    }
}

function darValorCatBusq(value,idSelect){
    var divCatBusq=document.getElementById(idSelect);
    if(divCatBusq!=null){
        divCatBusq.value=value;
    }
}

function calcage(secs, num1, num2) {
  s = ((Math.floor(secs/num1))%num2).toString();
  if (s.length < 2)
    s = "0" + s;
  return "<b>" + s + "</b>";
}

function CountBack(targetYear,targetMonth,targetDay,targetElement,dateFormat) {
  var dthen = new Date(targetYear,targetMonth-1,targetDay);
  var dnow = new Date();
  var ddiff = new Date(dthen-dnow);
  var secs = Math.floor(ddiff.valueOf()/1000);
  if (secs < 0) {
    secs=0;
  }
  displayFormat =  dateFormat.toUpperCase();
  var displayStr = displayFormat.replace(/%%D%%/g, calcage(secs,86400,100000));
  displayStr = displayStr.replace(/%%H%%/g, calcage(secs,3600,24));
  displayStr = displayStr.replace(/%%M%%/g, calcage(secs,60,60));
  displayStr = displayStr.replace(/%%S%%/g, calcage(secs,1,60));
  jQuery('#'+targetElement)[0].innerHTML = displayStr;
  setTimeout("CountBack('" + targetYear+"','"+ targetMonth+"','"+ targetDay+"','"+targetElement+"','"+dateFormat + "')", 1000);
}

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 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 mostrarFormulario(tipoFormulario){
    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(tipoFormulario, "POST", "", peticion);
}

function enviarAgotadoAjax(formulario){

    if (isEmail(formulario.email.value)){
        var variables="idproducto="+formulario.idproducto.value+"&email="+formulario.email.value;
        if (formulario.dvdgoNewsletter.checked){
            variables+="&dvdgoNewsletter="+formulario.dvdgoNewsletter.value;
        }
        if (formulario.dvdgoComercial.checked){
            variables+="&dvdgoComercial="+formulario.dvdgoComercial.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 enviarCarteleraAjax(formulario){

    if (isEmail(formulario.email.value)){
        var variables="idcartelera="+formulario.idproducto.value+"&email="+ formulario.email.value + "&idafiliado="+formulario.idafiliado.value  ;
        if (formulario.dvdgoNewsletter.checked){
            variables+="&dvdgoNewsletter="+formulario.dvdgoNewsletter.value;
        }
        if (formulario.dvdgoComercial.checked){
            variables+="&dvdgoComercial="+formulario.dvdgoComercial.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/alarmaCartelera", "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="";
}

function cerrarCapaConformidad(obje){

        var element = document.getElementById(obje);
         if(element!=null && element!='undefined' && element.style.display=='block'){
            element.style.display="none";
         }
}
