//Codigo para rollOver menu principal
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];}
}
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;
}
//Codigo para impresion de contenidos
function nuevoAjax(){ 
	var xmlhttp=false;
	try{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e){
		try{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E){
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
		}
	}
	return xmlhttp; 
}
function persiana(){
	document.getElementById ('persiana').style.visibility = "hidden";
}
function contenido(zona, archivo){
	if(zona == 0){
		var lo = new SWFObject("media/home.swf", "home", "970", "371", "6", "#FFFFFF");
			lo.addParam("quality", "high");
			lo.addParam("wmode", "transparent");
			lo.write("contenido");
	}else{
		var ajax=nuevoAjax();
		ajax.open("GET", "includes/nocache.php?archivo="+archivo, true);
		ajax.onreadystatechange=function() { 
			if (ajax.readyState==1){
				document.getElementById ('persiana').style.visibility = 'visible';
			}
			if (ajax.readyState==4){
				document.getElementById ('contenido').innerHTML=ajax.responseText;
				setTimeout("persiana()",1000);
			} 
		}
		ajax.send(null);
	}
}
//Codigo control interno de contenidos
function verpagina(total, ver){
	for(i=1; i<=total; i++){
		nombre = 'pagina'+i;
		if(document.getElementById(nombre)){
			document.getElementById(nombre).style.display = 'none';
		}
	}
	nombre = 'pagina'+ver;
	if(document.getElementById(nombre)){
		document.getElementById(nombre).style.display = 'block';
	}
}
function cambiarClase(total, cambiar){
	for(i=1; i<=total; i++){
		nombre = 'opcion'+i;
		if(document.getElementById(nombre)){
			document.getElementById(nombre).setAttribute('class', 'submenu');
			document.getElementById(nombre).setAttribute('className', 'submenu');
		}
	}
	nombre = 'opcion'+cambiar;
	if(document.getElementById(nombre)){
		document.getElementById(nombre).setAttribute('class', 'submenuActivo');
		document.getElementById(nombre).setAttribute('className', 'submenuActivo');
	}		
}
//Codigo envio de correo
function enviar(){
	var continuar = 0;
	var mensaje = "*** ERROR ***\n\n";
	if(document.getElementById("nombre").value == ""){
		continuar = 1;
		mensaje += "El campo nombre es requerido\n";
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.getElementById("correo").value))){
		continuar = 1;
		mensaje += "El campo correo electronico no es valido\n";
	}
	if(document.getElementById("mensaje").value == ""){
		continuar = 1;
		mensaje += "Escriba algun mensaje";
	}
	if(continuar == 0){
		parametros = "nombre="+document.getElementById("nombre").value+"&correo="+document.getElementById("correo").value+"&mensaje="+document.getElementById("mensaje").value;
		var ajax=nuevoAjax();
		ajax.open("GET", "includes/enviar.php?"+parametros, true);
		ajax.onreadystatechange=function() { 
			if (ajax.readyState==1){
				document.getElementById ('persiana').style.visibility = 'visible';
			}
			if (ajax.readyState==4){
				if(ajax.responseText == "correcto"){
					setTimeout("persiana()",1000);
					alert("Su mensaje fue enviado");
					document.getElementById("nombre").value = "";
					document.getElementById("correo").value = "";
					document.getElementById("mensaje").value = "";
				}else{
					alert("Problemas al enviar, intente nuevamente");
				}
			} 
		}
		ajax.send(null);
	}else{
		alert(mensaje);
	}
}
function checkS(e){
	var posx = 0;
	var posy = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
        posx = e.pageX;
        posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
        posx = e.clientX;
        posy = e.clientY;
    }
	document.getElementById('nota').style.left = (posx+2)+'px';
	document.getElementById('nota').style.top = (posy-190)+'px';
}
function nota(opcion){
	if(opcion == 1){
		document.getElementById('nota').style.visibility = 'visible';
	}else{
		document.getElementById('nota').style.visibility = 'hidden';
	}
}
function distribuidores(){
	var ajax=nuevoAjax();
	ajax.open("GET", "includes/distribuidores.php", true);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==1){
			document.getElementById ('persiana').style.visibility = 'visible';
		}
		if (ajax.readyState==4){
			document.getElementById ('contenido').innerHTML=ajax.responseText;
			setTimeout("persiana()",1000);
		} 
	}
	ajax.send(null);
}
function acceso(){
	if(document.getElementById("usuario").value != "" && document.getElementById("clave").value != ""){
		var ajax=nuevoAjax();
		parametros = 'usuario='+document.getElementById("usuario").value;
		parametros += '&clave='+document.getElementById("clave").value;
		
		ajax.open("GET", "includes/sesion.php?"+parametros, true);
		ajax.onreadystatechange=function() { 
			if (ajax.readyState==1){
				document.getElementById ('persiana').style.visibility = 'visible';
			}
			if (ajax.readyState==4){
				temp = ajax.responseText.split("|");
				if(temp[0] == 'error'){
					document.getElementById ('contenido').innerHTML = temp[1];
					alert('usuario/clave no validos');
				} else {
					document.getElementById ('contenido').innerHTML=temp[0];
				}
				setTimeout("persiana()",1000);
			} 
		}
		ajax.send(null);
	} else {
		alert("Debes proporcionar tu usuario y clave");
	}
}
function leer_noticia(id){
	var ajax=nuevoAjax();
	parametros = 'aID='+id;
	
	ajax.open("GET", "includes/leer_noticia.php?"+parametros, true);
	ajax.onreadystatechange=function() { 
		if (ajax.readyState==1){
			document.getElementById ('persiana').style.visibility = 'visible';
		}
		if (ajax.readyState==4){
			document.getElementById ('contenido').innerHTML=ajax.responseText;
			setTimeout("persiana()",1000);
		} 
	}
	ajax.send(null);
}
function documentos(){
	window.open('quixplorer/index.php?action=login&order=name&srt=yes&p_user=comun&p_pass=comun&lang=es','documentos','width=800,height=600,toolbar=no,scrollbars=yes,resizable=no,menubar=no,status=no,directories=no,location=no');
}