var abierta = "";
var funct = 0;
var defecte = new Array();
defecte[0] = "";
defecte[1] = "";
defecte[2] = "";
defecte[3] = "";
var campo = "0";
var defecteSel = new Array();
defecteSel[0] = "";
defecteSel[1] = "";
defecteSel[2] = "";

/*function cambiaMenu(oTd, szColorFondo, szColorIcono, szColorTexto, szTitulo, id , tipo) {
	
    if (defecteSel[0] == ""){
		defecteSel[0] = szColorFondo;
		defecteSel[1] = szColorIcono;
		defecteSel[2] = szColorTexto;
	}
	if (funct == 0){
		funct ++;
	}
	if (document.getElementById(abierta))
		cambiaMenu2(document.getElementById(abierta),defecte[0],defecte[1],defecte[2], true);
	document.getElementById(oTd.id + "_ico").style.backgroundColor = szColorIcono;
	oTd.style.color = szColorTexto;
	oTd.style.backgroundColor = szColorFondo;
	if(szTitulo == 'Inscripción' || szTitulo == 'Ponencias'){
		document.getElementById('titulo').innerHTML = "<span style=\"float:left;valign:top;\">" + szTitulo + "</span>";

	} else {
		document.getElementById('titulo').innerHTML = "<span style=\"float:left;valign:top;\">" + szTitulo + "</span><div style=\"margin-right:40px;float:right;valign:top;cursor:pointer\"><img src=\"/imagenes/botones/printV.gif\" alt=\"Imprimir pagina\" title=\"Imprimir pagina\" onclick=\"document.frames['cuerpoCentral'].focus();document.frames['cuerpoCentral'].print();\"/></div>";
	}
	
	cargaCentro(id, tipo);
	abierta = oTd.id;
}*/

/*****************************************
* Nom: cambiaMenu
* Descripció: marca en el menu lateral el seleccionat i executa la funcio per cargar el contingut i carrega el titol si s'escau
* @Params:  tag --> contenedor en el menu lateral seleccionat
            sztitulo--> titol del seleccionat
            szid--> identificador del document seleccionat
            szidPare--> identificador del mini-site que conté aquest document 
            sztipo--> tipus de document (t_01:contingut, t_02:Protagonistes, t_03:Penencies, t_04:url )
            szurl--> url a carregar en el frame central si és del tipus t_04
* @return   RES
*******************************************/
function cambiaMenu(tag, sztitulo, szid , szidPare,  sztipo, szurl ) {  
    if (defecteSel[0] == ""){
         if(window.top.document.getElementById('campo48').value != "" )  
            defecteSel[0] = "#" + window.top.document.getElementById('campo48').value;
         if(window.top.document.getElementById('campo45').value != "" )  
            defecteSel[1] = "#" + window.top.document.getElementById('campo45').value;
          if(window.top.document.getElementById('campo42').value != "" )  
            defecteSel[2] = "#" + window.top.document.getElementById('campo42').value;
    }
    if (funct == 0){
        funct ++;
    }                  
    if (window.top.document.getElementById(abierta))
		cambiaMenu2(document.getElementById(abierta), true);
    if(window.top.document.getElementById('campo45').value != "" )  
            window.top.document.getElementById(tag.id + "_ico").style.backgroundColor =  "#" + window.top.document.getElementById('campo45').value;
    if(window.top.document.getElementById('campo42').value != "" )  
            tag.style.color =  "#" + window.top.document.getElementById('campo42').value;
    if(window.top.document.getElementById('campo48').value != "" )  
            tag.style.backgroundColor = "#" + window.top.document.getElementById('campo48').value;
    if(window.top.document.getElementById('campo43').value != "" ) 
        color = "#" + window.top.document.getElementById('campo43').value;
    else 
        color = "";
    if(sztipo == " t_02"){       
        window.top.document.getElementById('titulo').innerHTML = "<div style=\"margin-right:40px;float:right;valign:top;cursor:pointer\"><img src=\"/imagenes/botones/printV.gif\" alt=\"Imprimir pagina\" title=\"Imprimir pagina\" onclick=\"document.frames['cuerpoCentral'].focus();document.frames['cuerpoCentral'].print();\"/></div>";
    }
	else if(sztipo == " t_03"){       
		window.top.document.getElementById('titulo').innerHTML = "<span style=\"float:left;valign:top;color:"+ color +"\">" + sztitulo + "</span>";
	} 
	else{ window.top.document.getElementById('titulo').innerHTML = "<span style=\"float:left;valign:top;color:"+ color +"\">" + sztitulo + "</span><div style=\"margin-right:40px;float:right;valign:top;cursor:pointer\"><img src=\"/imagenes/botones/printV.gif\" alt=\"Imprimir pagina\" title=\"Imprimir pagina\" onclick=\"document.frames['cuerpoCentral'].focus();document.frames['cuerpoCentral'].print();\"/></div>";
	} 
    cargaContenido(szid , szidPare,  sztipo, szurl);
    abierta = tag.id;                         
}
/*****************************************
* Nom: cargaContenido
* Descripció: carrega el contingut en el frame central
* @Params:  szid--> identificador del document seleccionat
            szidPare--> identificador del mini-site que conté aquest document 
            sztipo--> tipus de document (t_01:contingut, t_02:Protagonistes, t_03:Penencies, t_04:url )
            szurl--> url a carregar en el frame central si és del tipus t_04
* @return   RES
*******************************************/
function cargaContenido(szid , szidPare,  sztipo, szurl){
    switch (sztipo){
        case " t_01":
            window.top.document.getElementById("cuerpoCentral").src="/aecoc/admin/web/gc_search.php?entidad=45&tipo=3&plantilla=117&id=" + szid; 
        break;
        case " t_02":
            window.top.document.getElementById("cuerpoCentral").src="/aecoc/admin/web/gc_search.php?entidad=45&tipo=9&parentid=" + szidPare + "&typerel=2&childrentype=12&plantilla=60&orden=373&tipoorden=asc&typefieldorden=N";
        break;
        case " t_03":
            window.top.document.getElementById("cuerpoCentral").src="/aecoc/admin/web/gc_search.php?entidad=45&tipo=9&parentid=" + szidPare + "&typerel=2&childrentype=11&plantilla=78&orden=372&tipoorden=asc&typefieldorden=N&login=1";
            redimensionaMiniSite ('cuerpoCentral');
        break;
        case " t_04":
            window.top.document.getElementById("cuerpoCentral").src = szurl;
            window.top.document.getElementById("cuerpoCentral").style.height = "2100px";
        break;
        default:
            alert("No se ha encontrado contenido, para el detalle minisite tipo " + sztipo + " \n\t\t Contacte con el administrador de la web.");
    }
}

/*****************************************
* Nom: cargaDestacado en el frame central
* Descripció: carrega el contingut de un dels detalls del minisete desde un patrocinador que es troba en el frame lateral dret 
* @Params:  id--> identificador del document detalle minisite               
* @return   RES
*******************************************/
function cargaDetalleMiniSite(id){
    if(window.top.document.getElementById(id)){
        if (document.all) {                                                 
            primerTag = window.top.document.getElementById(id).cells[0];   
            primerTag.click();
        }else{                                                                
            var primerTag = window.top.document.getElementById(id).cells[0];
            var a = primerTag.getAttribute("onclick");  
            var b = a.split("'");
            cambiaMenu(primerTag,b[1],b[3],b[5],b[7],b[9]);
        }      
    }                         

}

function cargaCentro(id, tipo){
	
    var	szUrl = "";
	szUrl = "/aecoc/admin/web/gc_search.php?entidad=14";
	
    
    switch(tipo){
	case 1:
  		campo = "0";
		szUrl = szUrl + "&tipo=3&plantilla=51&Id=" + id;
	    break;    
	case 2:
		campo = "6";
  		szUrl = szUrl + "&tipo=3&plantilla=51&Id=" + id;
	    break;
	case 3:
        szUrl = szUrl + "&tipo=9&parentid=" + id + "&typerel=2&childrentype=12&plantilla=60&orden=373&tipoorden=asc&typefieldorden=N";
	    break;
	case 4:
  		szUrl = szUrl + "";
	    break;
	case 5:
  		szUrl = szUrl + "&tipo=9&parentid=" + id + "&typerel=2&childrentype=11&plantilla=78&orden=372&tipoorden=asc&typefieldorden=N&login=1";
		break;
	case 6:
		campo = "8";
  		szUrl = szUrl + "&tipo=3&plantilla=51&Id=" + id;
	    break;
	case 7:
         campo = "9";
          szUrl = szUrl + "&tipo=3&plantilla=51&Id=" + id;   
         break;
   default:
	    campo = "campo"+tipo;
        szUrl = szUrl + "&tipo=3&plantilla=51&Id=" + id;	
	}
    window.top.document.getElementById("cuerpoCentral").src = szUrl;
}


/* Funcion que llamamos cuando se quiere recortar un texto a un numero determinado de caracteres */
function recortaTexto(texto, numCaracteres) {
	texto = stripTags (texto);
	
	if ( texto.length > numCaracteres ) {
		texto = texto.substring(0, numCaracteres) + "..." ;
	}
	//Si trobem un punt i apart. Fem que la cadena vagi desde el primer caracter fins al punt. En la base de dades trobem el punt i apart amb la etiqueta <br/>
	if (texto.search('<br/>') != -1) {
		var posicio = texto.search('<br/>')	;
		texto = texto.substring(0, posicio);
	}
	
	return texto ;
}

/* Funcion que recibe un texto HTML (con etiquetas) i devuelve solo el texto, eliminando las etiquetas */
function stripTags (t) {
	while (t.match(/<.*>/)) t = t.replace(/<[^>]*>/, "");
	return t;
}

/*function cambiaMenu3(oTd, szColorFondo, szColorIcono, szColorTexto) {
	if(oTd.id != abierta){
		defecte[0] = szColorFondo;
		defecte[1] = szColorIcono;
		defecte[2] = szColorTexto;
		defecte[3] = szColorFondo;
		document.getElementById(oTd.id + "_ico").style.backgroundColor = szColorIcono;
		oTd.style.color = szColorTexto;
		oTd.style.backgroundColor = szColorFondo;
	}
}
function cambiaMenu2(oTd, szColorFondo, szColorIcono, szColorTexto, oBandera) {
	if(oTd.id != abierta || oBandera){
		document.getElementById(oTd.id + "_ico").style.backgroundColor = szColorIcono;
		oTd.style.color = szColorTexto;
		oTd.style.backgroundColor = szColorFondo;
	}
}*/
/*****************************************
* Nom: cambiaMenu3
* Descripció: fa el mouseOut i guarda el contingut en el javascript
* @Params:  tag--> tag en el que es fa el mouseOver
* @return   RES
*******************************************/
function cambiaMenu3(tag) {
    if(tag.id != abierta){   
        if(window.top.document.getElementById('campo46').value != "" )  
            defecte[0] = "#" + window.top.document.getElementById('campo46').value;
        if(window.top.document.getElementById('campo43').value != "" )  
            defecte[1] = "#" + window.top.document.getElementById('campo43').value;
        if(window.top.document.getElementById('campo40').value != "" )  
            defecte[2] = "#" + window.top.document.getElementById('campo40').value;
        if(window.top.document.getElementById('campo46').value != "" )  
            defecte[3] = "#" + window.top.document.getElementById('campo46').value;
        if(window.top.document.getElementById('campo43').value != "" )  
            window.top.document.getElementById(tag.id + "_ico").style.backgroundColor = "#" + window.top.document.getElementById('campo43').value;
        if(window.top.document.getElementById('campo40').value != "" )  
            tag.style.color = "#" + window.top.document.getElementById('campo40').value;
        if(window.top.document.getElementById('campo46').value != "" )  
            tag.style.backgroundColor = "#" + window.top.document.getElementById('campo46').value;
    }
}


/*****************************************
* Nom: cambiaMenu2
* Descripció: fa el mouse over i guarda el contingut en el javascript
* @Params:  tag--> tag en el que es fa el mouseOver
            oBandera--> boolea per saber si s'ha de fer o no l'accio
* @return   RES
*******************************************/
function cambiaMenu2(tag, oBandera) {
    if(tag.id != abierta){    
        if(window.top.document.getElementById('campo44').value != "" )                                                    
            window.top.document.getElementById(tag.id + "_ico").style.backgroundColor =  "#" + window.top.document.getElementById('campo44').value;
        if(window.top.document.getElementById('campo41').value != "" )                                                    
            tag.style.color =  "#" + window.top.document.getElementById('campo41').value;
        if(window.top.document.getElementById('campo47').value != "" )                                                    
            tag.style.backgroundColor =  "#" + window.top.document.getElementById('campo47').value;
    } else if( oBandera ){
        if(defecte[1] != "" )   
            window.top.document.getElementById(tag.id + "_ico").style.backgroundColor = defecte[1];
        if(defecte[2] != "" )   
            tag.style.color = defecte[2] ;
        if(defecte[3] != "" )   
            tag.style.backgroundColor =  defecte[3];
    }
}

/*****************************************
* Nom: cargaPrimer
* Descripció: detecta el primer detalle minisite i el carga
* @Params:  RES
* @return   RES
*******************************************/

function cargaPrimer(){   
	if (document.all) {                                                 
		primerTag = document.getElementById("taulaMenu").rows[0].cells[0];   
		primerTag.click();
	}else{                                                                
		var primerTag = document.getElementById("taulaMenu").rows[0].cells[0];
		var a = primerTag.getAttribute("onclick");  
		var b = a.split("'");
        cambiaMenu(primerTag,b[1],b[3],b[5],b[7],b[9]);
	}                               
}

function toTop() {
	window.parent.scrollTo(0, 0);
}

function redimensionaLateral(id){
	var y = parseInt(document.body.scrollHeight,10);    
	if(parent.document.getElementById(id)){
		parent.document.getElementById(id).style.height	= (y +"px");	
		if( y < 120){
			parent.document.getElementById(id).style.height = '500px';
		}		
	}
}

function redimensiona(id){                            
		if (!window.opera && !document.mimeType && document.all && document.getElementById){
		   
			iframme=window.top.window.document.getElementById("cuerpoCentral");
			//parent.document.getElementById(id).style.height=this.document.body.offsetHeight+"px";
			
		}
		else if(document.getElementById) {
			parent.document.getElementById(id).style.height= ( parseInt(this.document.body.scrollHeight, 10) + 25 ) +"px";
		}	
		toTop();
	}	      

function redimensionaMiniSite(id){     
    window.top.document.getElementById(id).style.height = "250px";
    if(window.top.document.getElementById(id)){
            window.top.document.getElementById(id).style.height    = ( parseInt(this.document.body.scrollHeight, 10) + 25 ) +"px";      
    }
}

/**********
**
** Aquesta funcio fa la redireccio i carrega les pagines en el frame central dels
** destacados especials.
**
***********/

function cargaCentro2(id, tipo){
	
    switch(tipo){
	case 1:
		cambiaMenu(document.getElementById('tecnomarketing'), defecteSel[0], defecteSel[1], defecteSel[2], 'Conozca', id , tipo);
	break;    
	case 2:
		cambiaMenu(document.getElementById('programa'), defecteSel[0], defecteSel[1], defecteSel[2], 'Programa', id , tipo);
	break;
	case 3:
		cambiaMenu(document.getElementById('protagonistas'), defecteSel[0], defecteSel[1], defecteSel[2], 'Protagonistas', id , tipo);
	break;
	case 4:
		cambiaMenu(document.getElementById('inscripcion'), defecteSel[0], defecteSel[1], defecteSel[2], 'Inscripción', id , tipo);
	break;
	case 5:
		cambiaMenu(document.getElementById('ponencias'), defecteSel[0], defecteSel[1], defecteSel[2], 'Ponencias', id , tipo);
	case 6:
		cambiaMenu(document.getElementById('patrocinadores'), defecteSel[0], defecteSel[1], defecteSel[2], 'Patrocinadores', id , tipo);
	break;
	default:
		cambiaMenu(document.getElementById('alojamientos'), defecteSel[0], defecteSel[1], defecteSel[2], 'Alojamiento', id , tipo);
	}

}


function printPage(){
    window.print();      
}  