

//varcargando="<br />Cargando, Espere por favor...<br /><br />";
varcargando="";
//***************************************************************************** AJAX FUNCTIONS
//********************************************************************************************
function XHConn(){
    var xmlhttp, bComplete = false;
    try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { try { xmlhttp = new XMLHttpRequest(); }
    catch (e) { xmlhttp = false; }}}
    if (!xmlhttp) return null;
    this.connect = function(sURL, sMethod, sVars, fnDone){
        if (!xmlhttp) return false;
        bComplete = false;
        sMethod = sMethod.toUpperCase();
		sVars = arreglaplus(sVars);
       try {
            if (sMethod == "GET"){
                xmlhttp.open(sMethod, sURL+"?"+sVars, true);
                sVars = "";
            }else{
                xmlhttp.open(sMethod, sURL, true);
                xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
                xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            }
            xmlhttp.onreadystatechange = function(){
                if (xmlhttp.readyState == 4 && !bComplete)
                { 
                    bComplete = true;
                    fnDone(xmlhttp);
                }};
            xmlhttp.send(sVars);
        }
        catch(z) { return false; }
        return true;
    };
    return this;
}

function cargar_contenido(destino,div,metodo,parametros,msg,afterl){
	if (!msg || msg==""){
		document.getElementById(div).innerHTML = '<br /><div align="center"><img src="/'+images_dir+'/loading2.gif" alt="Cargando..."></div><br /><br />'; 
	}else if (msg=="same"){
		//document.getElementById(div).innerHTML = '<div style="float:left"><img src="/'+images_dir+'/loa.gif"/" alt="Loading..."></div>'+document.getElementById(div).innerHTML; 
	}else{
		document.getElementById(div).innerHTML = '<span class="message_updating">'+msg+'</span>'; 
	}
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP no disponible, POR FAVOR ACTUALIZA TU NAVEGADOR A UNO MAS RECIENTE."); 
	var peticion = function (oXML) {document.getElementById(div).innerHTML = oXML.responseText; after_load(afterl);};
	return myConn.connect(destino, metodo, parametros, peticion);
}

function arreglaget(cadena){
	cadena = cadena.replace(/&/gi, "yyy");
	if (cadena=="-00-00"){
		cadena="";
	}
	return cadena;
}

function arreglaplus(cadena){
	cadena = cadena.replace(/\+/gi, "--plus--");
	return cadena;
}

//************************************************************************* END AJAX FUNCTIONS
//********************************************************************************************
//THIS FUNCTION IS CALLED AFTER EACH AJAX CALL
function after_load(afterl){
	if (afterl=="seleccionamenu2"){
		m_seleccion(2);	
	}else if (afterl=="seleccionamenu3"){
		m_seleccion(3);
	}else if (afterl=="seleccionamenu6"){
		m_seleccion(6);
	}else if (afterl=="seleccionamenu8"){
		m_seleccion(8);
	}
}
//**************************************************************** SEND EVENT GOOGLE ANALYTICS
//********************************************************************************************
function googleanalyticsreg(pagina){
	pageTracker._trackPageview("home-"+pagina);
}
function muestra_esconde_div(div_id){
	var existediv=document.getElementById(div_id);
	if (existediv){
		if (document.getElementById(div_id).style.display=='none'){
			muestra_div(div_id);
		}else{
			esconde_div(div_id);
		}
	}
}
function muestra_div(div_id){
	var existediv=document.getElementById(div_id);
	if (existediv){
		document.getElementById(div_id).style.display = '';
	}
}
function esconde_div(div_id){
	var existediv=document.getElementById(div_id);
	if (existediv){
		document.getElementById(div_id).style.display = 'none';
	}
}

function m_desseleccion(){
	if (document.getElementById('w0')){
		document.getElementById('w0').className = "item w";
		document.getElementById('w1').className = "item w";
		document.getElementById('w2').className = "item w";
		document.getElementById('w3').className = "item w";
		document.getElementById('w4').className = "item w";
		document.getElementById('w5').className = "item w";
		document.getElementById('w6').className = "item w";
		document.getElementById('w7').className = "item w";
		document.getElementById('w8').className = "item w";
		document.getElementById('w9').className = "item w";
	}
}
function m_seleccion(cual){
	m_desseleccion();
	if (document.getElementById('w'+cual)){
		document.getElementById('w'+cual).className = "item current w";
	}
}
//**************************************************************** SIMPLE NAVEGATION FUNCTIONS
//********************************************************************************************
function goto_index(){
	m_desseleccion();
	cargar_contenido('index.php','home_main','GET','menuajax=ajax_index',varcargando);
	googleanalyticsreg('home');
}
function goto_caracteristicas(){
	if (document.getElementById('home_main_int')){
		cargar_contenido('index.php','home_main_int','GET','menuajax=ajax_caracteristicas_int',varcargando,'seleccionamenu2');
	}else{
		cargar_contenido('index.php','home_main','GET','menuajax=ajax_caracteristicas',varcargando,'seleccionamenu2');
	}
	
	googleanalyticsreg('caracteristicas');
}
function goto_funcionamiento(){
	if (document.getElementById('home_main_int')){
		cargar_contenido('index.php','home_main_int','GET','menuajax=ajax_funcionamiento_int',varcargando,'seleccionamenu3');
	}else{
		cargar_contenido('index.php','home_main','GET','menuajax=ajax_funcionamiento',varcargando,'seleccionamenu3');
	}
	googleanalyticsreg('funcionamiento');
}
function goto_aboutus(){
	if (document.getElementById('home_main_int')){
		cargar_contenido('index.php','home_main_int','GET','menuajax=ajax_aboutus_int',varcargando,'seleccionamenu6');
	}else{
		cargar_contenido('index.php','home_main','GET','menuajax=ajax_aboutus',varcargando,'seleccionamenu6');
	}
	googleanalyticsreg('about_us');
}
function goto_afiliados(){
	if (document.getElementById('home_main_int')){
		cargar_contenido('index.php','home_main_int','GET','menuajax=ajax_afiliados_int',varcargando,'seleccionamenu8');
	}else{
		cargar_contenido('index.php','home_main','GET','menuajax=ajax_afiliados',varcargando,'seleccionamenu8');
	}
	googleanalyticsreg('afiliados');
}

//****************************************************************** PARTICULAR PAGE FUNCTIONS
/* VALIDAR LISTA DE REGALOS */
    function valida_contacto(){
		if(document.contactanos.minombre.value.length==0){
			alert('Por favor completa el campo "Tu Nombre"');
			document.contactanos.minombre.focus()
			return 0;
		}
				
		if(document.contactanos.mimail.value.length==0){
			alert('Por favor completa el campo "Tu E-mail"');
			document.contactanos.mimail.focus()
			return 0;
		}
		
		if(document.contactanos.phone_pais.value.length==0 || document.contactanos.phone_area.value.length==0 || document.contactanos.phone.value.length==0){
			alert('Por favor completa el campo "Teléfono" Con el Código del País ("1" para Estados Unidos) y Código de Área para poder contactarte!');
			document.contactanos.phone_pais.focus()
			return 0;
		}
		
		var str= document.contactanos.mimail.value;
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		   document.contactanos.mimail.focus()
		   return false
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		   document.contactanos.mimail.focus()
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		    document.contactanos.mimail.focus()
			return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		    document.contactanos.mimail.focus()
			return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		    document.contactanos.mimail.focus()
			return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		    document.contactanos.mimail.focus()
			return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert('"Dirección de  E-mail" inválida, por favor revísala e intenta nuevamente')
		    document.contactanos.mimail.focus()
			return false
		 }
		 
		if(document.contactanos.mensaje.value.length==0){
			alert('Por favor completa el campo "Mensaje"');
			document.contactanos.mensaje.focus()
			return 0;
		}
		if(document.contactanos.captchaon.value=="Y"){
			if(document.contactanos.code.value=="" || document.contactanos.code.value.length==0){
				alert('Please complete the "Código de Verificación"');
				document.contactanos.code.focus()
				return 0;
			}
		}
  	document.contactanos.submit();  	
}
