function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*FUNCION PARA EL GRAFICO*/
function valida_graficar(form)
{
	var popup;
	var url;

	if (form.tema.value == "")
		{ alert("Por favor seleccione un tema"); return; }
	if (form.anno.value == "")
		{ alert("Por favor seleccione un año"); return; }
		
	url = "grafico/grafico.php?&tema=" + form.tema.value + "&anno=" + form.anno.value;
	popup=window.open(url,"_blank","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1");
	popup.focus();
	popup.moveTo(0,0);
	popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));
}
/*CHAT*/
function open_chat()
{
	popup_configurable("modulos/Chat/index.php",560,400,0,1,0,0)
}
/*ABRIR POPUP CONFIGURABLE*/
	/**
	url = determina la ruta del archivo que se quiere abrir en el popup, URL DEBE ESTA PRESENTE EN SU PROYECTO
	ancho = define el ancho de la pagina
	alto = define el alto de la imagen
	full = si full es = a 1, el popup se abrira a pantalla completa.... si es cero o blanco se abrira al tamaño que determina ancho y alto
	centrado = si centrado es = a 1, el popup se centrara en tu pantalla.... si es cero o blanco se abrira en el top de la pantalla
	scrollb= 1 = con popup con scroll...si es cero o blanco estara desabilitado
	resize= 1 popup que se puede agrandar...si es cero o blanco estara desabilitado
	*/
	function popup_configurable(url,ancho,alto,full,centrado,scrollb,resize)
	{
		var popup;
		var left_point;
		var top_point;
		var screen_height 	= screen.height;	/*ENTREGA EL ALTO DE SU PANTALLA*/
		var screen_width 	= screen.width; 	/*ENTREGA EL ANCHO DE SU PANTALLA*/
		
		/*VALIDAMOS SI EL POPUP CONTARA CON PROPIEDADES*/
			if(scrollb!=1){scrollb=0;}
			if(resize!=1){resize=0;}
			
		/*ABRIMOS EL POPUP*/
			popup=window.open(url,"pop","toolbar=0,location=0,status=0,menubar=0,width="+ancho+",height="+alto+",scrollbars="+scrollb+",resizable="+resize);
			popup.focus();
		
		/*VALIDAMOS SI SE DEBE CENTRAR EL POPUP, SINO QUEDARA SIEMPRE EN EL TOP=0 LEFT=0*/
			if(centrado==1)
			{
				ancho	= ancho*1;
				alto	= alto*1;
				left_point = parseInt(screen.availWidth/2)-(ancho/2);
				top_point = parseInt(screen.availHeight/2)-(alto/2);
				popup.moveTo(left_point,top_point);
			}
			else{popup.moveTo(0,0);}
			
			
	
			
		/*DEJAMOS EL POPUP FULLSCREAM*/
			if(full==1){popup.resizeTo(parseInt(screen.availWidth),parseInt(screen.availHeight));}
	} 
/*_____________________________________*/
function IsPopupHabilitados(){
	var w = window.open();
	
	if (!w) {
		//popups Bloqueados
		return false;
	} else {
		//popups Habilitados
		if (!w.closed) w.close();
		return true;
	}
}

function popUpWin (url, win, width, height, options) {
	var leftPos = (screen.availWidth - width) / 2;
	var topPos = (screen.availHeight - height) / 2;
	options += 'width=' + width + ',height=' + height + ',left=' + leftPos + ',top=' + topPos;
	
	//return window.open(url, win, options);
	var w = window.open(url, win, options);
	
	if (!w) {
		//popups Bloqueados
		alert('Su navegador tiene activado un sistema de bloqueo de ventanas emergentes.\n La pagina solicitada no se pudo abrir');
	}

}

//_FUNCION QUE DA EL FOCO A UNA FILA O CAMPO ESPECIFICO, RETORNANDO EL MISMO COLOR DEL FOCO UNA VEZ QUE SE PIERDE EL FOCO
var old_color;
function foco_tr(fila){
	old_color=document.getElementById(fila).bgColor;document.getElementById(fila).bgColor="#FFFEDD";
}
function lost_foco_tr(fila){
	document.getElementById(fila).bgColor=old_color;
}
	
//_FUNCION QUE PERMITE HACER UN EFECTO SOBRE LA IMAGEN
var iex = navigator.appName=="Microsoft Internet Explorer"?true:false;
var fi = iex?'filters.alpha.opacity':'style.MozOpacity'
var opaMax= iex?100:1;
var opaMin= iex?50:0.5;
var inc = iex?70:00; 
function subir(cual){opa = new Number(eval('cual.' + fi));eval('cual.' + fi + '= opa + inc')}
function bajar(cual){opa = new Number(eval('cual.' + fi));eval('cual.' + fi + '= opa - inc')}


//_FUNCIONA PARA ABRIR POPUP CON WEB MAIL
function correo(){
	var opciones = 'scrollbars=1,resizable=1,';
	popUpWin('http://webmail.cmvm.cl', 'WebMail', 660, 500, opciones);
}

//_Permite ocultar el contenido de una tabla
function show_frame(id){
	if(document.getElementById(id).className=='abierto'){
		document.getElementById(id).className='cerrado';
	}
	else
	{
		document.getElementById(id).className='abierto';
	}
}
//esta funcion permite abrirun TR o IFRAME o DIV, etc ademas permite agregar una imagen + - 
function abrir_cerrar(nombre,img,themes)
{
	/*
	nombre : corresponde al nombre de la fila o iframe que queremos que se expanda
	img    : corresponde a la imagen que representara el icono + o - segun sea el caso
	*/
	var clase=document.getElementById(nombre).className;
	if(clase=="abierto")
	{
		document.getElementById(nombre).className="cerrado";
		if(img!=""){document.getElementById(img).src="themes/"+themes+"/img/controles/FILA_mas.gif";}
	}
	else
	{
		document.getElementById(nombre).className="abierto";
		if(img!=""){document.getElementById(img).src="themes/"+themes+"/img/controles/FILA_menos.gif";}
	}
}
//fncion que permite cambiar de stylo al contenedore de imagen
function color_foco(nombre)
{
	document.getElementById(nombre).className='margen_img_FOCO';
}

function color_focolost(nombre)
{
	document.getElementById(nombre).className='margen_img';
}
//
//_FUNCION QUE DA EL FOCO A UNA FILA O CAMPO ESPECIFICO, RETORNANDO EL MISMO COLOR DEL FOCO UNA VEZ QUE SE PIERDE EL FOCO
var old_color="";
function color_foco_grid(nombre)
{
	old_color=document.getElementById(nombre).className;
	document.getElementById(nombre).className="tr_lista_foco";
}

function color_focolost_grid(nombre)
{document.getElementById(nombre).className=old_color;}

function crearAjax()
{
var xmlhttp=false;
try{xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}catch (e){try{xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}catch (E){xmlhttp = false;}}if (!xmlhttp && typeof XMLHttpRequest!='undefined'){xmlhttp = new XMLHttpRequest();}return xmlhttp;
}

function ENVIO_CONTACTO()
{
	var t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, content;
	content = document.getElementById('content');
	t1 = document.getElementById('empresa').value;
	t2 = document.getElementById('nombre').value;
	t3 = document.getElementById('cargo').value;
	t4 = document.getElementById('direccion').value;
	t5 = document.getElementById('ciudad').value;
	t6 = document.getElementById('fono').value;
	t7 = document.getElementById('fax').value;
	t8 = document.getElementById('mail').value;
	t9 = document.getElementById('pais').value;
	t10 = document.getElementById('motivo').value;
	t11 = escape(document.getElementById('comentarios').value); 
	if(t2==""){alert("Debe especificar un nombre"); return;}    
	if(t3==""){alert("Debe especificar cargo"); return;}    
	if(t6==""){alert("Debe especificar un teléfono"); return;}    
	if(t8==""){alert("Debe especificar un email"); return;}  
	ajax=crearAjax();
	ajax.open("GET", "envio_contacto_ajax.php?empresa="+t1+"&nombre="+t2+"&cargo="+t3+"&direccion="+t4+"&ciudad="+t5+"&fono="+t6+"&fax="+t7+"&mail="+t8+"&pais="+t9+"&motivo="+t10+"&comentarios="+t11,true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4)
		{content.innerHTML = "MENSAJE ENVIADO CON EXITO";}
	}
	ajax.send(null);
	document.getElementById('empresa').value="";
	document.getElementById('nombre').value="";
	document.getElementById('fono').value="";
	document.getElementById('mail').value="";    
	document.getElementById('motivo').value="";
	//document.getElementById('dirigido').value="";
	document.getElementById('comentarios').value="";
}

function ENVIO_SOLICITUD()
{
	var t1, t2, t3, t4, t5, content;
	content = document.getElementById('content');
	t1 = document.getElementById('empresa').value;
	t2 = document.getElementById('nombre').value;
	t3 = document.getElementById('fono').value;
	t4 = document.getElementById('mail').value;    
	t5 = document.getElementById('plan').value;
	if(t1==""){alert("FALTAN DATOS OBLIGATORIOS"); return;}  
	if(t2==""){alert("FALTAN DATOS OBLIGATORIOS"); return;}    
	if(t3==""){alert("FALTAN DATOS OBLIGATORIOS"); return;}    
	if(t4==""){alert("FALTAN DATOS OBLIGATORIOS"); return;}    
	if(t5==""){alert("FALTAN DATOS OBLIGATORIOS"); return;}        
	ajax=crearAjax();
	ajax.open("GET", "solicitar.php?empresa="+t1+"&nombre="+t2+"&fono="+t3+"&mail="+t4+"&plan="+t5,true);
	ajax.onreadystatechange=function(){
		if (ajax.readyState==4)
		{content.innerHTML = "MENSAJE ENVIADO CON EXITO";}
	}
	ajax.send(null);
	document.getElementById('empresa').value="";
	document.getElementById('nombre').value="";
	document.getElementById('fono').value="";
	document.getElementById('mail').value="";    
	document.getElementById('plan').value="";
}

function muestra(id){
	document.getElementById(id).className="visible"
}

function ocultar(id){
	document.getElementById(id).className="hide"
}

function cambiaPagina(id,pagina){
	var divRecarga;
	divRecarga = document.getElementById('page_galleries');
	ajax=crearAjax();
	ajax.open("GET", "modulos/Categorias/tipos/pagina/adm_galeria.php?id="+id+"&pagina="+pagina);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divRecarga.innerHTML = ajax.responseText;
		}
	}
  	ajax.send(null);
}

function guardaGaleria(id){
	var divRecarga, gnombre, gdescripcion, sv_type, idregistro, pagina;
	divRecarga = document.getElementById('page_galleries');
	gnombre = document.getElementById('gnombre').value;
	gdescripcion = document.getElementById('gdescripcion').value;
	sv_type = document.getElementById('sv_type').value;
	pagina = document.getElementById('pagina').value;
	if(gnombre == ""){
		alert("Debe especificar un nombre");
		document.getElementById('gnombre').focus();
		return false;
	}else if(gdescripcion == ""){
		alert("Debe especificar una descripción");
		document.getElementById('gdescripcion').focus();
		return false;
	}
	if(sv_type == 2){
		idgaleria = document.getElementById('idgaleria').value;
		ajax=crearAjax();
		ajax.open("GET", "modulos/Categorias/tipos/pagina/adm_galeria.php?id="+id+"&gnombre="+gnombre+"&gdescripcion="+gdescripcion+"&action=guardar&sv_type="+sv_type+"&idgaleria="+idgaleria+"&pagina="+pagina);
	}else{
		ajax=crearAjax();
		ajax.open("GET", "modulos/Categorias/tipos/pagina/adm_galeria.php?id="+id+"&gnombre="+gnombre+"&gdescripcion="+gdescripcion+"&action=guardar&sv_type="+sv_type+"&pagina="+pagina);
	}
	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
			divRecarga.innerHTML = ajax.responseText;
		}
	}
  	ajax.send(null);
}

function showIndexControl(control){
	div = $(control);
	if(div.className == 'ctrl_indice_activo'){
		div.className = 'ctrl_indice_inactivo';
	}else{
		div.className = 'ctrl_indice_activo';
	}
}

function resizeIframe(iframeId)
{
	var miIframe=$(iframeId);
	var alturaPagina=miIframe.contentWindow.document.body.scrollHeight;
	miIframe.style.height=alturaPagina+"px";
}
