
/*#####################################################

          Libreria de funciones para manejo de capas

		  (C) Grupo5.com By Eduardo Fernandez Martínez
          http://www.grupo5.com




#####################################################*/


/*#####################################################
###  Funcion que OCULTA UNA CAPA
#####################################################*/
function oculta_div(id) {
		/*safe function to hide an element with a specified id*/
		if (document.getElementById) { /* DOM3 = IE5, NS6*/
		   if (typeof(document.getElementById(id))!='undefined' ){
			   document.getElementById(id).style.display = 'none';
		   }else{
			   document.write("Elemento ["+id+"] No encontrado");
		   }
		}else {
			if (document.layers) { /* Netscape 4*/
				document.id.display = 'none';
			}else { /* IE 4 */
				document.all.id.style.display = 'none';
			}
		}
}

/*#####################################################
###  Funcion que MUESTRA una capa
#####################################################*/

//Funcion que muestra un elemento div - con un id determinado
function muestra_div(id) {

	   if (typeof(id)=='undefined' ){ alert (id+" undefined"); }

		if (document.getElementById) { /* DOM3 = IE5, NS6 */
		   if (document.getElementById(id)){ document.getElementById(id).style.display = 'block'; }
		}else {
			if (document.layers) { /* Netscape 4*/
				document.id.display = 'block';
			}else { /* IE 4 */
				document.all.id.style.display = 'block';
			}
		}
}

/*####################################################################
###  Funcion que MUESTRA / OCULTA una capa en funciona del estado
####################################################################*/
function muestra_oculta_div(id) {

	if (document.getElementById) { /* DOM3 = IE5, NS6*/
		if (document.getElementById(id).style.display != 'none'){
			document.getElementById(id).style.display = 'none';
		}else{
			document.getElementById(id).style.display = 'block';
		}
	}else {
		if (document.layers) { /* Netscape 4 */
			if ( document.id.display != 'none' ){
				document.id.display = 'none';
			}else{
				document.id.display = 'block';
			}
		}else { /* IE 4*/
		    if (document.all.id.style.display != 'none'){
			   document.all.id.style.display = 'none';
			}else{
				document.all.id.style.display = 'block';
			}
		}
	}
}





/*#####################################################
###  Funcion que CARGA CONTENIDO EN UNA CAPA
#####################################################*/
function carga_div(capa,contenido){
	if (document.getElementById) { /*  DOM3 = IE5, NS6*/
	    document.getElementById(capa).innerHTML = contenido;
	}else{
	    if (document.layers) { // Netscape 4
			document.capa.innerHTML = contenido;
	    }else{
			document.all.capa.innerHTML = contenido;
		}
	}
}

/*#####################################################
###  IMPRIMIR EL CONTENIDO DE UNA CAPA
#####################################################*/
function imprimir_capa(capa,auto) {
   var ventana = window.open("", "", "");
   var contenido = "<style>.impresion {text-decoration: none;font-family: Tahoma;font-size: 6pt;color: black;}</style>";
   if (auto==true){ /*impresion automática.*/
	   contenido += "<html><body onload='window.print();window.close();'>" + document.getElementById(capa).innerHTML + "</body></html>";
   }else{
	   contenido += "<html><body>" + document.getElementById(capa).innerHTML + "</body></html>";
   }
   ventana.document.open();
   ventana.document.write(contenido);
   ventana.document.close();
}



/*#####################################################
###  CREAR UNA CAPA DINAMICAMENTE
#####################################################*/
function crear_capa(id, html, width, height, left, top,center) {

   var newdiv = document.createElement('div');
   newdiv.setAttribute('id', id);

   newdiv.style.background = "#FFFFFF";
   newdiv.style.border = "1px solid #C0C0C0";
   newdiv.style.zIndex = "1000";


   if (html) {
       newdiv.innerHTML = html;
   } else {
       newdiv.innerHTML = "nothing";
   }


   if (width) {newdiv.style.width = width;}else{newdiv.style.width = 640;}
   if (height) { newdiv.style.height = height; }else{newdiv.style.height = 480;}

   if (center && center=='center' ){

	   if  ( ( browser=="msie" ) &&  (browser_version < 7 ) ){
		   newdiv.style.position = "absolute"; 
	   }else{
		   newdiv.style.position = "fixed"; 
	   }

	   newdiv.style.left = "50%";
	   newdiv.style.top = "50%";
	   newdiv.style.marginLeft = "-"+(width/2)+"px"; /* poner la mitad del ancho */
	   newdiv.style.marginTop = "-"+(height/2)+"px"; /* poner la mitad del alto */
   }else{
	   if ((left || top) || (left && top)) {
	   	   newdiv.style.position = "relative"; 
		   if (left) {newdiv.style.left = left;}
		   if (top) {newdiv.style.top = top;}
	   }
   }


   document.body.appendChild(newdiv);
}



/*#####################################################
###  CREAR IFRAME DINAMICAMENTE
#####################################################*/
function crear_iframe(id, iframe, width, height, left, top,center) {
   if (typeof(document.getElementById('transparencia'))!='undefined' ){ muestra_div ('transparencia'); }
	//crear_capa(id,'aqui el iframe de '+width+'x'+height, width, height, left, top,center);
	var iframe='<iframe src="'+iframe+'&capa='+id+'"  width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"></iframe>';
	crear_capa(id,iframe, width, height, left, top,center);

}

/*#####################################################
###  CERRA IFRAME
#####################################################*/
function cerrar_iframe(id) {
	/*Ocultar la capa del iframe */
	if (typeof(document.getElementById('pop_div'))!='undefined' ){ oculta_div ('pop_div'); }
	/*Ocultar la transparencia del iframe */
	/*if (typeof(document.getElementById('transparencia'))!='undefined' ){ oculta_div ('transparencia'); }*/
	/*Guardar los datos que esten el en formulario */
	send_form('formulario_plantilla','accion','Guardar');
}




/*#####################################################
###  Cargar un iframe en una capa
#####################################################*/
function pop_iframe(capa, iframe, width, height, left, top,center) {
	//crear_capa(id,'aqui el iframe de '+width+'x'+height, width, height, left, top,center);
	var iframe='<iframe src="'+iframe+'&capa='+capa+'"  width="'+width+'" height="'+height+'" frameborder="0" scrolling="no"></iframe>';
	var capa_destino=document.getElementById(capa);


	capa_destino.style.background = "#FFFFFF";
	capa_destino.style.border = "1px solid #C0C0C0";
	capa_destino.style.zIndex = "1000";

	if (iframe) {
	   capa_destino.innerHTML = iframe;
	} else {
	   capa_destino.innerHTML = "nothing";
	}

	if (width) {capa_destino.style.width = width;}else{capa_destino.style.width = 640;}
	if (height) { capa_destino.style.height = height; }else{capa_destino.style.height = 480;}

	if (center && center=='center' ){

	   if  ( ( browser=="msie" ) &&  (browser_version < 7 ) ){
		   capa_destino.style.position = "absolute"; 
	   }else{
		   capa_destino.style.position = "fixed"; 
	   }

	   capa_destino.style.left = "50%";
	   capa_destino.style.top = "50%";
	   capa_destino.style.marginLeft = "-"+(width/2)+"px"; /* poner la mitad del ancho */
	   capa_destino.style.marginTop = "-"+(height/2)+"px"; /* poner la mitad del alto */
	}else{
	   if ((left || top) || (left && top)) {
		   capa_destino.style.position = "relative"; 
		   if (left) {capa_destino.style.left = left;}
		   if (top) {capa_destino.style.top = top;}
	   }
	}

	capa_destino.style.display = 'block';
}


/*#####################################################
###  Funcion que elimina UNA CAPA en caliente
#####################################################*/
function eliminar_div(id) {

		/*safe function to hide an element with a specified id*/
		if (document.getElementById) { /* DOM3 = IE5, NS6*/
		   if (typeof(document.getElementById(id))!='undefined' ){
			   oculta_div(id);
			   eliminar_div=document.getElementById(id);
	   		   document.body.removeChild(eliminar_div);
		   }else{
   			   alert("ELIMINANDO ["+id+"]["+eliminar_div+"] ");
		   }
		}else {
			if (document.layers) { /* Netscape 4*/
			     alert("Explorador web no compatible no se puede eliminar la capa ["+id+"] ");
			}else { /* IE 4 */
				 alert("Explorador web no compatible no se puede eliminar la capa ["+id+"] ");
			}
		}
}



