var EmailCorrecto;
var LoginCorrecto;
var CaptchaCorrecto;
var PasswordMatch;
var Cliente;


function showTagHelp() {
	}
	
	function hideTagHelp() {
	}
	
	function switch_1_2_tip(s) {
		if (s) {
			//document.getElementById('plan_1_2_tip').style.display = 'block';
		} else {
			//document.getElementById('plan_1_2_tip').style.display = 'none';
		}
	}

	function switchPlan() {
		hide('plan_wh_0');hide('plan_wh_1');hide('plan_wh_2');hide('plan_wh_3');
		hide('plan_wh_il'); hide('plan_res_1');hide('plan_res_2');hide('plan_res_3');hide('plan_res_4');
		hide('plan_res_5'); hide('plan_res_6');
		// Para los dedicados
		//hide('plan_res_7');hide('plan_res_8');
		document.getElementById('div_modo_per').style.display = 'block';
		switch_1_2_tip(0);
		switch (document.getElementById('plan').value) {
			case '0'://Sin plan
				document.getElementById('div_modo_per').style.display = 'none';
				show('plan_wh_0');
				break;
			case '19'://Plan 1
				show('plan_wh_1');
				showMonths(3);
				switch_1_2_tip(1);
				break;
			case '20'://Plan 2
				show('plan_wh_2');
				showMonths(3);
				switch_1_2_tip(1);
				break;
			case '21'://Plan 3
				show('plan_wh_3');
				showMonths(3);
				break;
			case '28'://Ilimitado
				show('plan_wh_il');
  				showMonths(3);
				break;
			case '29'://Reseller D7
				show('plan_res_1');
				showMonths(1);
				break;
			case '22'://Reseller D14
				show('plan_res_2');
				showMonths(1);
				break;
			case '23'://Reseller D25
				show('plan_res_3');
				showMonths(1);
				break;
			case '30'://Reseller D100
				show('plan_res_4');
				showMonths(1);
				break;
			case '26'://VPS 1
				show('plan_res_5');
				showMonths(1);
				break;
			case '27'://VPS 2
				show('plan_res_6');
				showMonths(1);
				break;
			case '16'://DEDICADO 1
				show('plan_res_7');
				showMonths(1);
				break;
			case '17'://DEDICADO 2
				show('plan_res_8');
				showMonths(1);
				break;
		}
		CalcularMonto();
	}

	function gid(nom) {
		return (document.getElementById(nom));
	}
	
	function gn(nom) {
		return (document.getElementsByName(nom)[0]);
	}
	
function cambiaDom(tldactual) {
		AlgunoSeleccionado=true;
		var radObj = getRadioObj(document.getElementsByName('radominio'));
		var tipo = radObj.className;
		//document.getElementById('submitBtn').disabled = false;
		//document.getElementById('submitBtn').style.color = "";

		div0s = document.getElementsByTagName('div');
		for (i=0;i<div0s.length;i++) {
			if (div0s[i].className == 'tldMsg')
				div0s[i].style.display = 'none';
		}
		
		for (i=0;i<div0s.length;i++) {
			if (div0s[i].id == 'div' + radObj.value)
				div0s[i].style.display = 'block';
		}
		
		if (tipo == 'disp') {
			var r1 = new RegExp(/(.*)(.org.ar|.net.ar|.edu.ar|.gob.ar|.gov.ar|.mil.ar)/i);
			if (r1.test(radObj.value)) {
				document.getElementById('tipodom').innerHTML = '<b>'+tldactual+'</b>';
				document.getElementById('aviso_noregistro').style.display = 'block';
				document.getElementById('dom_reg').checked = false;
				document.getElementById('dom_reg').disabled = true;
			} else {
				//document.getElementById('dom_reg').checked = false;
				document.getElementById('aviso_noregistro').style.display = 'none';
				document.getElementById('dom_reg').disabled = false;
			}
		} else if (tipo == 'nodisp') {
			//document.getElementById('dom_reg_lbl').style.color = "#C0C0C0";
			document.getElementById('aviso_noregistro').style.display = 'none';
			document.getElementById('dom_reg').checked = false;
			document.getElementById('dom_reg').disabled = true;
		}
	}

	
	
	function CheckLogin(){
		num_cli = document.getElementById('num_cli').value;
		pass_cli = document.getElementById('pass_cli').value;
		
		if (num_cli && pass_cli){
			
			var checkingemail = document.getElementById('checkingemail');
			checkingemail.style.display='inline';
			oXML = AJAXCrearObjeto();
			oXML.open('GET', 'checklogin.php?id='+num_cli+'&pass='+pass_cli);
			oXML.onreadystatechange = leerDatos;
			oXML.send('');
		} else {
			
		}
	}
	
	function leerDatos(){
	  if (oXML.readyState  == 4) {
		var checkingemail = document.getElementById('checkingemail');
		checkingemail.style.display='none';
		infologin = document.getElementById('infologin');
		if (oXML.responseText=='granted'){
			infologin.innerHTML="<b><font color='#339900'>Cliente correcto</font></b>";
			LoginCorrecto=true;
		} else {
			infologin.innerHTML="<b><font color='#CF0000'>Cliente o contraseña incorrecto</font></b>";
			LoginCorrecto=false;
		}
	  }
	}

	function AJAXCrearObjeto(){
	  var obj;
	  if(window.XMLHttpRequest) { // no es IE
		obj = new XMLHttpRequest();
	  } else { // Es IE o no tiene el objeto
		 try {
		   obj = new ActiveXObject("Microsoft.XMLHTTP");
		}  catch (e) {
		  alert('El navegador utilizado no está soportado');
		}
	  }
	  return obj;
	} 

function ajax_open (url, id_contenedor)
{
    var oAjax = false;
    if (window.XMLHttpRequest)
    {
        // Para los exploradores como la gente
        oAjax = new XMLHttpRequest();
    } else if (window.ActiveXObject)
    {
        // Para fucking IE
        try 
        {
            oAjax = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            // Si es version antigua
            try
            {
                oAjax = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
            }
        }
    }
    else
    return false;
    oAjax.onreadystatechange = function ()
    {
        // Llegada de datos
        cargar (oAjax, id_contenedor);
    }
    oAjax.open ('GET', url, true); // asignamos los metodos open y send
    oAjax.send (null);
}

function cargar(oAjax, id_contenedor){
	HTTP_ROOT_PATH = 'http://www.neolo.com.ar/';
	if (oAjax.readyState == 4 && (oAjax.status == 200 || window.location.href.indexOf ("http") == -1)){
		document.getElementById (id_contenedor).innerHTML = oAjax.responseText;
		$('.extraspace').hide('slow');
	}else{
		document.getElementById (id_contenedor).innerHTML = '<div id="loadingbox"><img src="' + HTTP_ROOT_PATH + 'ads/loading.gif" style="margin-bottom:5px" /><br/>Buscando dominio...</div>';
	}
}

function isEmail (s)
{   if (s=="") 
       if (isEmail.arguments.length == 1) return false;
       else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    if (s=="") return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}


function CheckEmail(direccion){
	if (!isEmail(direccion)){
		ReportarErrorEmail("Direccion de Email invalida");
		EmailCorrecto=false;
	} else {
		var infoemail = document.getElementById('infoemail');
		infoemail.innerHTML =  "<img src='wait.gif' border='0'>";
		oXML = AJAXCrearObjeto();
		oXML.open('GET', 'checkemail.php?direccion='+direccion);
		oXML.onreadystatechange = leerDatosMail;
		oXML.send('');
	}

}

function ReportarErrorEmail(cadena){
	var infoemail = document.getElementById('infoemail');
	if (cadena.indexOf('ok')!=-1) {
		infoemail.innerHTML = "<br><font color='#339900'><b>Direccion de Email valida</b></font>";
		EmailCorrecto=true;
	} else {
		infoemail.innerHTML = "<br><font color='#CF0000'><b>"+cadena+"</b></font>";
		EmailCorrecto=false;
	}
	
}

function leerDatosMail(){
	  if (oXML.readyState  == 4) {
		 ReportarErrorEmail(oXML.responseText);
	  }
	} 

function CheckPass(){
	passb = document.getElementById('passb');
	passb2 = document.getElementById('passb2');
	
	if (passb.value && passb2.value){
		if (passb.value!=passb2.value){
			passb.style.borderWidth="2px";
			passb.style.borderStyle="solid";
			passb.style.borderColor="#CF0000";
			passb2.style.borderWidth="2px";
			passb2.style.borderStyle="solid";
			passb2.style.borderColor="#CF0000";
			PasswordMatch=false;
		} else {
			passb.style.borderWidth="2px";
			passb.style.borderStyle="solid";
			passb.style.borderColor="#339900";
			passb2.style.borderWidth="2px";
			passb2.style.borderStyle="solid";
			passb2.style.borderColor="#339900";
			PasswordMatch=true;
		}
	}
}



function ValidaForm2(){
	if (Cliente){
		CheckLogin();
		if (!LoginCorrecto){
			alert("Usuario o Contraseña incorrecto");
			document.getElementById('passb2').focus();
			return false;
		}
	} else {
		if (!EmailCorrecto){
			alert("Email incorrecto");
			document.getElementById('mail').focus();
			return false;
		}
		CheckPass();
		if (!PasswordMatch){
			alert("Verificacion de contraseña no coincide");
			document.getElementById('passb2').focus();
			return false;
		}
		// SI Email y Pass correctos:
		//return true;
	}
	
	plan = document.getElementById('plan');
	if (plan.value==0){
		dnsp = document.getElementById('dnsp');
		dnss = document.getElementById('dnss');
		if (!dnsp.value && !dnss.value){
			alert("Debe definir al menos el servidor DNS principal");
			dnsp.style.borderWidth="2px";
			dnsp.style.borderStyle="solid";
			dnsp.style.borderColor="#CF0000";
			dnsp.focus();
			return false;
		}
	}
	
	validacion = document.getElementById('validacion');
	if (!validacion.value){
		alert("Falta codigo de seguridad");
		validacion.style.borderWidth="2px";
		validacion.style.borderStyle="solid";
		validacion.style.borderColor="#CF0000";
		validacion.focus();
		return false;
	}
	CheckCaptcha();
	if (!CaptchaCorrecto){
		alert("Codigo de seguridad erroneo");
		validacion.focus();
		return false;
	}
}

//VALIDACION DEL CAPTCHA

function iniciaCaptcha() {
	validacion = document.getElementById('validacion');
	clearTimeout(toCaptcha);
	if (validacion.value.indexOf(' ') == -1)
		toCaptcha = setTimeout("validaCaptcha()", 500);
}

function validaCaptcha() {
	clearTimeout(toCaptcha);
	CheckCaptcha();
}

function CheckCaptcha(){
	validacion = document.getElementById('validacion');
	oXML = AJAXCrearObjeto2();
	oXML.open('GET', 'checkcaptcha.php?codigo='+validacion.value);
	oXML.onreadystatechange = leerDatosCaptcha;
	oXML.send('');
}

function AJAXCrearObjeto2(){
	  var obj;
	  if(window.XMLHttpRequest) { // no es IE
		obj = new XMLHttpRequest();
	  } else { // Es IE o no tiene el objeto
		 try {
		   obj = new ActiveXObject("Microsoft.XMLHTTP");
		}  catch (e) {
		  alert('El navegador utilizado no está soportado');
		}
	  }
	  return obj;
} 

function leerDatosCaptcha(){
	  if (oXML.readyState  == 4) {
		  if (oXML.responseText.indexOf('ok')!=-1) {
				CaptchaCorrecto=true;
			} else {
				CaptchaCorrecto=false;
			}
	  }
} 

