aMenu = ["B&uacute;squeda im&aacute;genes","B&uacute;squeda de cds","B&uacute;squeda avanzada","Ofertas","Servicios"]
//aPropiedades = ["ideas","gente","vista","composicion","propiedadesDetalle","colecciones","numImg"];

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("menuList");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}
window.onload=startList;

function printMenu(idOpcion,idSubOpcion){

  sHTML = '<div id="first">&nbsp;</div>';
	sHTML += "<ul id='menuList'>";
	
	
	for (i=0;i<aMenu.length;i++){
		sHTML += '<li>';

		if (i==1) {
			sHTML += '<a href="#" ';
			if (i==idOpcion) sHTML+='id="selected" ';
			sHTML +='>'+aMenu[i]+'</a>';
	//		sHTML +='<!--[if IE 7]><!--></a><!--<![endif]-->';
	//		sHTML +='<!--[if lte IE 6]><table><tr><td><![endif]-->';
			sHTML +='<ul>';
			sHTML +='<li><a href="#" onClick="printMenu('+i+',0);">Por colecciones</a></li>';
			sHTML +='<li><a href="#" onClick="printMenu('+i+',1);">Por temas</a></li>';
	//		sHTML +='<li><a href="#" onClick="printMenu('+i+',2);">Por catalogos</a></li>';
			sHTML +='</ul>';
	//		sHTML +='<!--[if lte IE 6]></td></tr></table></a><![endif]-->';
		}	else if (i==2) {
			sHTML += '<a href="#" ';
			if (i==idOpcion) sHTML+='id="selected" ';
			sHTML +='>'+aMenu[i]+'</a>';
	//		sHTML +='<!--[if IE 7]><!--></a><!--<![endif]-->';
	//		sHTML +='<!--[if lte IE 6]><table><tr><td><![endif]-->';
			sHTML +='<ul>';
			sHTML +='<li><a href="#" onClick="printMenu('+i+',0);">Por colecciones</a></li>';
			sHTML +='<li><a href="#" onClick="printMenu('+i+',1);">Por criterios</a></li>';
			sHTML +='</ul>';
	//		sHTML +='<!--[if lte IE 6]></td></tr></table></a><![endif]-->';
		}	else if (i<4) {
			sHTML += '<a href="#" ';
			if (i==idOpcion) sHTML+='id="selected" ';
			sHTML +=' onClick="printMenu('+i+');">'+aMenu[i]+'</a>';
		} else {
			sHTML += '<a>'+aMenu[i]+'</a>';
		}
		
		sHTML +='</li>';

	}
	
	sHTML += '</ul>'
	
	document.getElementById("menu").innerHTML = sHTML;
	if (document.getElementById("headerFuncion")) {
    document.getElementById("headerFuncion").style.display="block"; 
    document.getElementById("headerFuncion").innerHTML = printFuncBuscar("",idOpcion, idSubOpcion);
		if (idOpcion==0) 	document.forms["fSearch"].elements["q"].focus(); 
		if (idOpcion==3) {
      document.getElementById("search").src="ofertas.php";
      document.getElementById("headerFuncion").style.display="none"; 
      document.getElementById("propiedades").style.display="none"; 
		}
		
	}
}

function init(){
	initFrame("search");
	if (document.forms["fSearch"].elements["q"]) document.forms["fSearch"].elements["q"].focus(); 
}

function LoadCombo(element,selection){
	var sLink='id='+selection;
	if (element==1){
		sLink+='&editor=1';
	} 
	if (selection!="undefined") LoadSeccion(4,sLink,'search');
}

function LoadSeccion (nAccion,sParams,sIframe){

	var oIFrame = document.getElementById("lightbox");
	if (sIframe)  oIFrame = document.getElementById(sIframe);
	
	var sUrl =""
	switch (nAccion) {
		case 1: sUrl = "registro.php?page=registro"; wonPage(); break;
		case 2: sUrl = "carrito.php"; break;
		case 3: sUrl = "registro.php"; wonPage(); break;
		case 4: 
			sUrl = "buscar_cds.php"; 
			document.getElementById("propiedades").style.display="none";
			break;
		case 5: sUrl = "ampliacion.php"; oIFrame = parent.document.getElementById("lightbox"); parent.wonPage(); break;
		case 6: sUrl = "carrito.php"; oIFrame = parent.document.getElementById("lightbox"); parent.wonPage(); break;
		
	}
	if (sParams) sUrl += "?"+sParams;
	oIFrame.src = sUrl;

}

function prepareURL(url){
  var newURL=url;
    
  if (url[1]=="%"){
    var params = url.split("&");
//alert(params);
    newURL=params[1]+" "+params[0].substring(5);
    for (i=2;i<params.length;i++){
//alert(params[i]);
      newURL+="&"+params[i];
    }
  }
  return newURL;
}

function doSearch(f){
  var url="./search.php";
  var conj="?";

  if (f.qb && f.qb.value!=""){
    if (f.qa) { url+=conj+'qa='+escape(f.qa.value); conj="&"; }
    if (f.qb) { url+=conj+'qb='+escape(f.qb.value); conj="&"; }
    if (f.qc) { url+=conj+'qc='+escape(f.qc.value); conj="&"; }
    if (f.qd) { url+=conj+'qd='+escape(f.qd.value); conj="&"; }
    f.qb.value="";
  } else {
    if (!f.tipoBusqueda || f.tipoBusqueda[0].checked) { // Nueva búsqueda:
       if (f.d)
         url+='?q='+encodeURI(f.q.value)+'&d='+encodeURI(f.d.value);
       else
         url+='?q='+encodeURI(f.q.value);  
    } else { // Búsqueda en resultados
       url+='?q%2B='+encodeURI(f.q.value)+"&"+prepareURL(top.search.location.search.substring(1));
    }
  }

  top.search.location.href=url;
  document.getElementById("headerFuncion").innerHTML=printFuncBuscar("",-1);
  //document.getElementById("propiedades").style.display="block";
}

function printFuncBuscar(valueQ,idOpcion,auxQ){
		var sHTML = "";
		
    if (idOpcion==-1){
			sHTML +='<table cellpadding="0" cellspacing="0"><tr><td id="qField"><input type="text" name="q" class="w250" value="" /></td><td id="qFieldImg" style="padding-left:8px;"><a href="#" onMouseOver="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda_on.gif\';" onMouseOut="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda.gif\';" onClick="doSearch(document.forms[\'fSearch\']);return false;"><img id="fl_bus" border="0" src="./pix/fl_busqueda.gif" /></a></td>';
			sHTML +='<td style="padding-left:65px;"><input type="radio" class="radio" name="tipoBusqueda" value="0" checked />nueva b&uacute;squeda</td><td style="padding-left:20px;"><input type="radio" class="radio" name="tipoBusqueda" value="1" />b&uacute;squeda en resultados</td></tr></table>';
	} else if (idOpcion==0){
			sHTML +='<table cellpadding="0" cellspacing="0"><tr><td><input type="text" name="q" class="w250" value="'+valueQ+'"/></td><td style="padding-left:8px;"><a href="#" onMouseOver="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda_on.gif\';" onMouseOut="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda.gif\';" onClick="doSearch(document.forms[\'fSearch\']);return false;"><img border="0" id="fl_bus" src="./pix/fl_busqueda.gif" /></a></td></tr></table>';
	} else if (idOpcion==1){
        if (auxQ==0)
        {
          sHTML +='<table cellpadding="0" cellspacing="0"><tr><td>'+g_cEditores+'</td></tr></table>';
        } else 
        {
          sHTML +='<table cellpadding="0" cellspacing="0"><tr><td>'+g_cTemas+'</td></tr></table>';
        }
	} else if (idOpcion==2){
        if (auxQ==0)
        {
          sHTML +='<table cellpadding="0" cellspacing="4">'; //<tr><td></td><td></td></tr>
          sHTML +='<tr><td id="qField"><input type="text" name="q" class="w250" value="" /></td><td style="">'+g_cEditoresAdv+'</td><td><a href="#" onMouseOver="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda_on.gif\';" onMouseOut="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda.gif\';" onClick="doSearch(document.forms[\'fSearch\']);return false;"><img id="fl_bus" border="0" src="./pix/fl_busqueda.gif" /></a></td></tr></table>';
        }
        else {
          sHTML +='<table cellpadding="0" cellspacing="4">';
         // sHTML +='<tr><td>Con todas las palabras</td><td id="qField"><input type="text" name="qa" class="w250" value="" /></td>';
          sHTML +='<tr><td>Con la frase exacta</td><td id="qField"><input type="text" name="qb" class="w250" value="" /></td>';
       //   sHTML +='<tr><td>Con alguna de las palabras</td><td id="qField"><input type="text" name="qc" class="w250" value="" /></td>';
          sHTML +='<tr><td>Sin las palabras</td><td id="qField"><input type="text" name="qd" class="w250" value="" /></td><td><a href="#" onMouseOver="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda_on.gif\';" onMouseOut="document.getElementById(\'fl_bus\').src=\'./pix/fl_busqueda.gif\';" onClick="doSearch(document.forms[\'fSearch\']);return false;"><img id="fl_bus" border="0" src="./pix/fl_busqueda.gif" /></a></td>';
          sHTML +='</tr></table>';
        }
	
		} 
	
		
		return sHTML;
}


function initFrame(idFrame, vSize) {
	if (!vSize)
		document.getElementById(idFrame).height = document.getElementById(idFrame).contentWindow.document.body.scrollHeight+40;
	else
		document.getElementById(idFrame).height = vSize + "px";
}

function activate(idDiv){

		var obj = document.getElementById(idDiv);
		var objActivated = document.getElementById(parent.g_filtroActivo);
	
		var objBro = document.getElementById(idDiv).previousSibling;
		var objBroActivated = document.getElementById(parent.g_filtroActivo).previousSibling;
		
		if (obj.className=="divOff") {
      objActivated.className="divOff";
			objBroActivated.childNodes[0].src="./pix/fl_negra_dch.gif";
			obj.className="divOn";
			objBro.childNodes[0].src="./pix/fl_negra_dwn.gif";
			parent.g_filtroActivo=idDiv;
		}
		else {
			obj.className="divOff";
			objBro.childNodes[0].src="./pix/fl_negra_dch.gif";
		}
		
		var frameRealSize=109;
		if (!parent.document.frames)			frameRealSize+=obj.clientHeight;
		else      	frameRealSize+=obj.offsetHeight;
		parent.initFrame("stats",frameRealSize); 
		
}


function wonPage() {
	// calculate top offset for the lightbox and display
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var lightboxTop = arrayPageScroll[1] + (arrayPageSize[3] / 15);
	$("#overlay").css("height",arrayPageSize[1]+"px");

	$("#overlay").fadeIn('fast',function() {
		$("#lightbox_container").css("top",lightboxTop + "px").css("display","block");
		return false;
	}
);
}


// [9] Auxiliares
function GetType(vObj, bExists){
	var vType=0;
	if(bExists){
		if(typeof(vObj)=="string"){
			vType =(eval("typeof("+vObj+")")!="undefined")? eval("typeof("+vObj+")") : 0;
			if(vType=="object"){
				vType=eval(vObj+".constructor");
				if(typeof(vType)=="undefined") vType=eval(vObj);
			}
		}
		else alert("GetType: Debes pasar 'vObj' entre comillas si quieres saber si la variable ha sido definida.");
	}
	else {
		if(vObj!=null){
			vType= vObj.constructor
			if(typeof(vType)=="undefined") vType=vObj;
		}
	}
	if(typeof(vType)=="undefined" || vType=="undefined") vType=0;

	return (vType);
}

function IsArray(vVar){
	var bReturn = 0;
	if (vVar && String(GetType(vVar)).toUpperCase().indexOf("FUNCTION ARRAY()")!=-1) bReturn = 1;
	//if (vVar && typeof(vVar)=="object" && vVar.constructor==Array)
	return( bReturn );
}

function CreaCombo(sSelectName,sFuncion,vTitulo,a_sNombre,a_sValor,vValorSelected) {
	var i,nValue
	var nValor=0
	if (a_sValor==-1) {
		a_sValor=a_sNombre
		nValor=1
	}

	if (IsArray(a_sNombre[0])) a_sNombre = GetCol (a_sNombre[0],a_sNombre[1],a_sNombre[2])
	if (IsArray(a_sValor[0])) a_sValor = GetCol (a_sValor[0],a_sValor[1],a_sValor[2])

	if (typeof(a_sValor)=="number") {
		nValue=a_sValor
		a_sValor=[]
		for (i=0;i<a_sNombre.length;i++){	// X
			a_sValor[i]=i+nValue
		}
	}

	var a_sCombo = [];
	var sCombo ='<SELECT class="select" name="'+sSelectName+'"'
	if (sFuncion) sCombo+= " " +sFuncion
	sCombo+='>'
	a_sCombo[a_sCombo.length]=sCombo;
	if (vTitulo!=""){
		var sTitulo=vTitulo
		var sValue=""
		if (IsArray(vTitulo)){
			sTitulo = vTitulo[0]
			sValue = vTitulo[1]
		}
		sCombo = "<OPTION value='"+sValue+"'"
		if (vValorSelected && (sTitulo==vValorSelected || sValue==vValorSelected)) sCombo +=" selected"
		sCombo += ">" + sTitulo + "</OPTION>"

		a_sCombo[a_sCombo.length]=sCombo;

	}

	for (i=0;i<a_sNombre.length-nValor;i+=1+nValor){
		if (a_sNombre[i]){
			sCombo = "<OPTION "
			sCombo += 'value="' + a_sValor[i+nValor] + '"'
			if (vValorSelected && (a_sValor[i+nValor]==vValorSelected || a_sNombre[i]==vValorSelected)) sCombo +=" selected"
			sCombo += ">" + a_sNombre[i] + "</OPTION>"
			a_sCombo[a_sCombo.length]=sCombo;
		}
	}
	sCombo='</SELECT>'
	a_sCombo[a_sCombo.length]=sCombo;
	return a_sCombo.join(" ");
}
