var procesado=false;
var referencia='WEB';
var resultado='';

function isObject(o){
	return (typeof(o) == "object");
}

 function xmlhttpPost(){
	var strURL = "http://clubmm.movilmarket.com/ajx_fnc.php";
	//var strURL = "http://stage.naranya.net/chat_naranya/LandigXRay/web/ajx_fnc.php";

	var xmlHttpReq = false;
	var self = this;

	if(window.XMLHttpRequest){// Mozilla/Safari
		self.xmlHttpReq = new XMLHttpRequest();
	}else if(window.ActiveXObject){// IE
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function(){
		if(self.xmlHttpReq.readyState == 4){
			resultado=self.xmlHttpReq.responseText;
			updatepage();
		}
	}
	self.xmlHttpReq.send(getquerystring());
}


function getquerystring(){
	var qstr = "";
	if(isObject(document.club.clave)){
		var mi_clave = document.club.clave.value;
		if(mi_clave.length <= 4){
			alert("Ingresa la clave que se ha enviado por SMS al tel"+'\u00e9'+"fono proporcionado\nSi no te ha llegado espera un momento.");
			return 'telefono=00000&clave=0000&referencia=WEB';
		}else{
			proceso = 2;
			qstr = 'telefono='+document.club.telefono.value+'&clave='+document.club.clave.value;
		}
	}else{
		if(document.club.telefono.value.length <= 8){
				alert("Proporciona correctamente tu tel"+'\u00e9'+"fono.");
			return 'telefono=00000';
		}else{
			if(document.getElementById("permission").checked){
				proceso = 1;
				qstr = 'telefono='+document.club.telefono.value;
			}else{
				actualizarModal("acepto.html?height=250&width=550&modal=true");
				//alert ("Debes aceptar los terminos y condiciones");
				return 'telefono=00000';
			}
		}
	}

	if(qstr.length >= 16){
		procesado = true;
	}
	qstr += '&referencia='+document.club.referencia.value+'&ident='+idSponsor+'&ref='+document.referrer+'&ps='+proceso+'&token='+token;
	return qstr;
}


function updatepage(){
	str = resultado;
	to_user = '';
	var datos=str.split('|');
	if(datos.length == 3){
		proceso++;
	if(datos[0] == 1){
		referencia = datos[2];
		actualizaDatos(1, 1);
		to_user = 'Clave: <input type=hidden name=telefono value="'+datos[1]+'"><input type=text name=clave maxlength=16>';
		}
		if(datos[0] == 2){
			actualizaDatos(2, datos[1]);
			to_user = datos[2];
		}
	}
	// document.getElementById("avance").innerHTML=to_user;
}
