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
            sztarget-> target que referencia desde quin document excutem el clic i el registrem
* @return   RES
*******************************************/
function cambiaMenu(tag, sztitulo, szid , szidPare,  sztipo, szurl , sztarget) {  
     if(sztipo == " t_04" || sztipo == " t_03" ){
        if (defecteSel[0] == ""){
             if($('#campo48').val() != "" )  
                defecteSel[0] = "#" + $('#campo48').val();
             if($('#campo45').val() != "" )  
                defecteSel[1] = "#" + $('#campo45').val();
              if($('#campo42').val() != "" )  
                defecteSel[2] = "#" + $('#campo2').val();
        }
        if (funct == 0){
            funct ++;
        }                  
        if (window.top.document.getElementById(abierta))
            cambiaMenu2( abierta, true);
        if(document.getElementById('campo45').value != "" )  {
            $("#"+ szid + "_ico").css('backgroundColor' , "#" +$('#campo45').val());
        }
        if(document.getElementById('campo42').value != "" )  
                $("#"+ szid + "_fill").css('color',"#" +$('#campo42').val()); 
        if(document.getElementById('campo48').value != "" )  
                $("#"+ szid + "_fill").css('backgroundColor',"#" + $('#campo48').val()); 
        if(sztipo == " t_03"){       
            document.getElementById('titulo').innerHTML = "<span style=\"float:left;valign:top;color:"+ color +"\">" + sztitulo + "</span>";
        } 
        else{ 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=\"printCuerpoCentral();\"/></div>";
        }         
        abierta = tag.id;  
    }  
    cargaContenido(szid , szidPare,  sztipo, szurl, sztarget);

                           
}
/*****************************************
* 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, target){
    switch (sztipo){
        case " t_01":
            window.top.document.getElementById("cuerpoCentral").src="/aecoc/admin/web/gc_search.php?entidad=45&target="+target+"&tipo=3&plantilla=117&id=" + szid ; 
        break;
        case " t_02":
            window.top.document.getElementById("cuerpoCentral").src="/aecoc/admin/web/gc_search.php?entidad=45&target="+target+"&tipo=9&parentid=" + szidPare + "&typerel=2&childrentype=12&plantilla=60&orden=373&tipoorden=asc&typefieldorden=N&id=" + szid ; 
        break;
        case " t_03":
            window.top.document.getElementById("cuerpoCentral").src="/aecoc/admin/web/gc_search.php?entidad=45&target="+target+"&tipo=9&parentid=" + szidPare + "&typerel=2&childrentype=11&plantilla=78&orden=372&tipoorden=asc&typefieldorden=N&login=1&id=" + szid ; 
            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.");
    }
}

function cambiaMenuAnterior(szid) {  
    tag = $('#'+szid+" td");
    variables = tag.attr('onClick').toString().split("'");
    sztitulo = variables[1];
    sztipo = variables[7];
    if (defecteSel[0] == ""){
         if($('#campo48').val() != "" )  
            defecteSel[0] = "#" + $('#campo48').val();
         if($('#campo45').val() != "" )  
            defecteSel[1] = "#" + $('#campo45').val();
          if($('#campo42').val() != "" )  
            defecteSel[2] = "#" + $('#campo42').val();
    }
    if (funct == 0){
        funct ++;
    }              
    if (document.getElementById(abierta)){
        cambiaMenu2(abierta, true);
    }
    if($('#campo45').val() != "" )  {
            $("#"+ szid + "_ico").css('backgroundColor' , "#" + $('#campo45').val());
    }
    if($('#campo42').val() != "" )  
             $("#"+ szid + "_fill").css('color',"#" + $('#campo42').val()); 
    if($('#campo48').val() != "" )  
             $("#"+ szid + "_fill").css('backgroundColor',"#" + $('#campo48').val()); 
    if($('#campo43').val() != "" ) 
        color = "#" +$('#campo43').val();
    else 
        color = "";
    if(sztipo == " t_02"){       
        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=\"printCuerpoCentral();\"/></div>";
    }
    else if(sztipo == " t_03"){       
        document.getElementById('titulo').innerHTML = "<span style=\"float:left;valign:top;color:"+ color +"\">" + sztitulo + "</span>";
    } 
    else{ 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=\"printCuerpoCentral();\"/></div>";
    } 
    
    abierta = szid + "_fill";                       
}


/*****************************************
* 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(id) {
    id_ico = id.split("_");
    if(id != abierta){   
        if(document.getElementById('campo46').value != "" )  
            defecte[0] = "#" + document.getElementById('campo46').value;
        if(document.getElementById('campo43').value != "" )  
            defecte[1] = "#" + document.getElementById('campo43').value;
        if(document.getElementById('campo40').value != "" )  
            defecte[2] = "#" + document.getElementById('campo40').value;
        if(document.getElementById('campo46').value != "" )  
            defecte[3] = "#" + document.getElementById('campo46').value;
        if(document.getElementById('campo43').value != "" )  
            $("#" + id_ico[0] + "_ico").css('backgroundColor' , "#" + window.top.document.getElementById('campo43').value);
        if(window.top.document.getElementById('campo40').value != "" )  
            $('#' + id ).css('color',"#" + document.getElementById('campo40').value);
        if(window.top.document.getElementById('campo46').value != "" )  
            $('#' + id ).css('backgroundColor',"#" + 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(id, oBandera) {
    id_ico = id.split("_");
    if(id != abierta){    
        if(document.getElementById('campo44').value != "" )                                                    
            $("#" + id_ico[0] + "_ico").css('backgroundColor' , "#" + window.top.document.getElementById('campo44').value);
        if(document.getElementById('campo41').value != "" )                                                    
            $('#' + id).css('color',"#" + document.getElementById('campo41').value);
        if(document.getElementById('campo47').value != "" )                                                    
             $('#' + id).css('backgroundColor', "#" + document.getElementById('campo47').value);
    } else if( oBandera ){
        if(defecte[1] != "" )   
            $("#" + id_ico[0]  + "_ico").css('backgroundColor' , defecte[1]);
        if(defecte[2] != "" )   
            $('#' + id ).css('color', defecte[2]);
        if(defecte[3] != "" )   
            $('#' + id ).css('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],targeturls);
	}                               
}

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();      
}  

function printCuerpoCentral(){
    if( window.frames['cuerpoCentral'] == null) {
         window.frames['cuerpoCentral'].focus();
         window.frames['cuerpoCentral'].printPage();
    } else {
         window.cuerpoCentral.focus();
         window.cuerpoCentral.printPage();
    } 
}  
