	var http_request	= false;
	var requesting		= false;
	var already_sent	= false;
	var post_url		= "/buy/";
	//var login_url		= "login_ajax.php";
	var login_url		= "/login_ajax/";
	var formName		= "buy_form";
	var poststr = true;
	var userLogged		= false;
	
	function gotoStep1()
	{
		activate('paso-1');
	}
	
	function gotoStep2(_validate)
	{
		if(_validate)
		{
			if(validateStep1())
			{
				activate('paso-2');
			}
		}else
		{
			activate('paso-2');
		}
	}
	
	function gotoStep3(_validate)
	{
		if(_validate)
		{
			if(validateStep2())
			{
				activate('paso-3');
			}
		}else
		{
			activate('paso-3');
		}
	}
	
	function gotoStep4(_validate)
	{
		if(_validate)
		{
			if(already_sent)
			{
				alert("El formulario ya ha sido enviado");
			}else
			{
				if(validateStep1())
				{
					if(validateStep2())
					{
						if(validateStep3())
						{
							if(!requesting)
							{
								requesting	= true;
//Error en ie
poststr = "sent=1" + "&user_document_type=" + document.getElementById("user_document_type").value;
poststr += "&user_document=" + document.getElementById("user_document").value + "&user_fullname=";
poststr += document.getElementById("user_fullname").value; 
poststr +=  "&user_gender=" + (document.getElementById("user_genderF").checked?document.getElementById("user_genderF").value:document.getElementById("user_genderM").value); 
poststr += "&useremail=" + document.getElementById("useremail").value + "&useremail2=" ;
poststr += document.getElementById("useremail2").value + "&user_birth_day=";
poststr += document.getElementById("user_birth_day").value + "&user_birth_month=" + document.getElementById("user_birth_month").value ;
poststr += "&user_birth_year=" + document.getElementById("user_birth_year").value + "&user_address=" ;
poststr += document.getElementById("user_address").value + "&user_zip=" + document.getElementById("user_zip").value ;
poststr += "&user_country=" + document.getElementById("user_country").value + "&user_city=" ;
poststr += document.getElementById("user_city").value + "&user_state=" + document.getElementById("user_state").value ;
poststr += "&user_phone_number=" + document.getElementById("user_phone_number").value +"&user_movil_number=" ;
poststr += document.getElementById("user_movil_number").value +"&user_ocupation=";
poststr += document.getElementById("user_ocupation").value +"&person_document_type=" ;
poststr += document.getElementById("person_document_type").value + "&person_document=";
poststr += document.getElementById("person_document").value + "&person_fullname=" ;
poststr += document.getElementById("person_fullname").value + "&person_gender=" ;
poststr += (document.getElementById("person_genderF").checked?document.getElementById("person_genderF").value:document.getElementById("person_genderM").value) ;
poststr += "&person_relation=" + document.getElementById("person_relation").value ;
poststr += "&person_email=" + document.getElementById("person_email").value ;
poststr += "&person_email2=" + document.getElementById("person_email2").value ;
poststr += "&person_birth_day=" + document.getElementById("person_birth_day").value ;
poststr += "&person_birth_month=" + document.getElementById("person_birth_month").value ;
poststr += "&person_birth_year=" + document.getElementById("person_birth_year").value ;
poststr += "&person_address=" + document.getElementById("person_address").value ;
poststr += "&person_zip=" + document.getElementById("person_zip").value ;
poststr += "&person_country=" + document.getElementById("person_country").value ;
poststr += "&person_city=" + document.getElementById("person_city").value ;
poststr += "&person_state=" + document.getElementById("person_state").value;
poststr += "&person_phone_number=" + document.getElementById("person_phone_number").value ;
poststr += "&person_movil_number=" + document.getElementById("person_movil_number").value ;
poststr += "&person_ocupation=" + document.getElementById("person_ocupation").value ;
poststr += "&user_id=" + document.getElementById("user_id").value ;
poststr += "&product=" + document.getElementById("product").value;

								// datos paso 2
								if(document.getElementById("buymode") != null) { buymode = document.getElementById("buymode").value; }
								else { buymode = "nada"; }
								poststr += "&buymode=" + buymode;
								if(buymode=="hosting" || buymode=="multicuenta") { // HOSTING
									poststr += 	"&login_pass=" + hex_md5(document.getElementById("login_pass").value) + 
												"&login_user=" + document.getElementById("login_user").value + 
												"&www_domain=" + document.getElementById("www_domain").value +
												"&cupon=" + document.getElementById("cupon").value +
												"&www_domain_reg=" + $("input[name='www_domain_reg']:checked", '#buy_form').val() +
												"&clave_txt=" + document.getElementById("login_pass").value +
												"&host_comentarios=" + document.getElementById("host_comentarios").value;
								} else if(buymode=="dedicados") {
									poststr += "&dedi_comentarios=" + URLEncode(document.getElementById("dedi_comentarios").value);											
								} else if(buymode=="SSL") {
									poststr += 	"&ssl_domain=" + document.getElementById("ssl_domain").value +
												"&ssl_empresa=" + document.getElementById("ssl_empresa").value +
												"&ssl_domicilio=" + document.getElementById("ssl_domicilio").value +
												"&ssl_ciudad=" + document.getElementById("ssl_ciudad").value +
												"&ssl_cp=" + document.getElementById("ssl_cp").value + 
												"&ssl_country=" + document.getElementById("ssl_country").value +
												"&ssl_state=" + document.getElementById("ssl_state").value +
												"&ssl_phone=" + document.getElementById("ssl_phone").value +
												"&ssl_owner=" + document.getElementById("ssl_owner").value +
												"&ssl_cargo=" + document.getElementById("ssl_cargo").value +
												"&ssl_email=" + document.getElementById("ssl_email").value +
												"&ssl_csrdata=" + document.getElementById("ssl_csrdata").value;
								} else if(buymode=="SEM") {
									poststr += "&www_domain=" + document.getElementById("www_domain").value;
									//if(document.getElementById("sem_moneda").value==0) { poststr += "&sem_moneda=pesos"; }
									//else { poststr += "&sem_moneda=dolares"; }
									//poststr += "&sem_inversion=" + document.getElementById("sem_inversion").value +
									poststr +=	"&sem_paises=" + URLEncode(document.getElementById("sem_paises").value) +
												"&sem_keywords=" + URLEncode(document.getElementById("sem_keywords").value) +
												"&sem_comentarios=" + URLEncode(document.getElementById("sem_comentarios").value);
								} else if(buymode=="streaming") { 
									poststr += 	"&login_pass=" + hex_md5(document.getElementById("login_pass").value) + 
												"&login_user=" + document.getElementById("login_user").value + 
												"&clave_txt=" + document.getElementById("login_pass").value +
												"&st_comentarios=" + document.getElementById("st_comentarios").value;								
								
								} else if(buymode=="CP") {
									poststr += "&cp_ip=" + document.getElementById("cp_ip").value;
								}
								poststr += "&cost=" + obtenerRadioSeleccionado(document.getElementById(formName), "cost").value;
								// datos paso 3
								poststr += "&pay_type=" + obtenerRadioSeleccionado(document.getElementById(formName), "pay_type").value
								// mandamos el post
								makePOSTRequest(post_url, poststr);
								overlay();
							}
						}
					}
				}
			}
		}else
		{
			activate('paso-4');
		}
	}
	
	
	function validateStep3()
	{
		activate('paso-3');
		form_ok	= true;
		formRef	= document.getElementById("buy_form");
		var err_div	= document.getElementById('err_div_3');
		err_div.innerHTML	= "";
		
		form_ok	= validateOptionBox(formRef, "pay_type",	"Debe seleccionar un MEDIO DE PAGO", "err_div_3", form_ok);
		
		return(form_ok);
	}
	
	function validateStep2()
	{
		activate('paso-2');
		form_ok	= true;
		var formRef	= document.getElementById("buy_form");
		//err_div	= document.getElementById("err_div_2");
		//err_div.innerHTML	= "";
		
		// Validacion HOSTING
		form_ok	= validateTextField("www_domain", "El DOMINIO es requerido", "err_div_2", form_ok);
		form_ok	= validateDomainField("www_domain", "El DOMINIO no es válido: Debe tener sólamente letras y números, un punto y una extension (ej: .com, .com.ar, .net). Es válido el guión (-), pero no como último ni como primer caracter.", "err_div", form_ok);
		form_ok	= validateDomainFieldCombo("www_domain", "El DOMINIO no es válido: Debe solicitar un dominio .com, .net, .org, .info, o similar. ", "err_div", form_ok, $('#product').val());
		//form_ok	= validateOptionBox("buy_form","www_domain_reg",		"Debe indicarnos si el dominio se encuentra registrado o no.", "err_div_2", form_ok);
		form_ok	= validateOptionBox(formRef, "www_domain_reg",	"Debe indicarnos si el dominio se encuentra registrado o no.", "err_div", form_ok);
		
		form_ok	= validateTextField("login_user",		"El USUARIO es requerido", "err_div_2", form_ok);
		
		if(formRef.login_user!=null) {
			if(!alphanumeric(formRef.login_user.value) && form_ok)
			{
				form_ok	= false;
				formRef.login_user.focus();
				alert("El USUARIO debe tener solo letras y números");
			}
			
			if(IsNumeric(formRef.login_user.value.charAt(0)) && form_ok)
			{
				form_ok	= false;
				formRef.login_user.focus();
				alert("El USUARIO no puede comenzar con un número");
			}
			
			if(formRef.login_pass!=null) {
				if(formRef.login_user.value == formRef.login_pass.value && form_ok)
				{
					form_ok	= false;
					formRef.login_user.focus();
					alert("La CONTRASEÑA no puede ser igual al USUARIO");
				}
				
				if(formRef.login_pass.value != formRef.login_pass.value.replace(formRef.login_user.value,"")) {
					form_ok	= false;
					formRef.login_pass.focus();
					alert("La CONTRASEÑA no puede contener al USUARIO");
				}
			}
			
			if((formRef.login_user.value.length < 4 || formRef.login_user.value.length > 8) && form_ok )
			{
				form_ok	= false;
				formRef.login_user.focus();
				alert("El USUARIO debe tener 4 caracteres mínimo y 8 maximo");
			}
		}
			
		form_ok	= validateTextField("login_pass",		"La CLAVE es requerida", "err_div_2", form_ok);
		form_ok	= validateTextField("login_pass2",		"Debe repetir la CLAVE", "err_div_2", form_ok);
		form_ok	= validateConfirmField("login_pass",	"login_pass2",	"Las CLAVES no coinciden", "err_div_2", form_ok);
		
		if(formRef.login_pass!=null) {
			if(formRef.login_pass.value.length < 6 && form_ok)
			{
				form_ok	= false;
				formRef.login_user.focus();
				alert("La CONTRASEÑA debe tener 6 caracteres mínimo");
			}
		}
		
			
		// Valida Dedicados
		form_ok	= validateTextField("dedi_comentarios", "Es necesario que aclares las necesidades del servidor", "err_div_2", form_ok);
		
		// Validación SSL
		form_ok	= validateTextField("ssl_domain", "El DOMINIO es requerido", "err_div_2", form_ok);
		form_ok	= validateDomainField("ssl_domain", "El DOMINIO no es válido: Debe tener sólamente letras y números, un punto y una extension (ej: .com, .com.ar, .net). Es válido el guión (-), pero no como último ni como primer caracter.", "err_div", form_ok);
		campo = document.getElementById("ssl_domain");
		if(campo!=null && campo.value != "" && form_ok) {
			punto1 = campo.value.indexOf(".");
			punto2 = campo.value.lastIndexOf(".");
			//if(punto1==0 || punto1==null || punto2==0 || punto2==null || punto1==punto2) {
			if(punto1==0 || punto1==null) {
				form_ok	= false;
				formRef.ssl_domain.focus();
				alert("El SUBDOMINIO SEGURO debe ser un subdominio y no un dominio, por ejemplo secure.nuthost.com, o www.nuthost.com, o *.nuthost.com");
			}
		}
		form_ok	= validateTextField("ssl_empresa", "La EMPRESA es requerida", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_domicilio", "El DOMICILIO es requerido", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_ciudad", "La CIUDAD es requerida", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_cp", "El CÓDIGO POSTAL (CP) / ZIP CODE es requerido", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_country", "El PAÍS es requerido", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_state", "La PROVINCIA / ESTADO es requerida", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_phone", "El TELÉFONO es requerido", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_owner", "El NOMBRE Y APELLIDO del titular es requerido", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_cargo", "El CARGO es requerido", "err_div_2", form_ok);
		form_ok	= validateTextField("ssl_email", "El EMAIL es requerido", "err_div_2", form_ok);

		field	= document.getElementById("ssl_email");
		if(field != null && field.value!="" && form_ok) {
			form_ok	= validateEmailField("ssl_email",	"El EMAIL no es válido", "err_div", form_ok);
			dominio_seguro = formRef.ssl_domain.value.substr(formRef.ssl_domain.value.indexOf(".")+1);
			if(form_ok && formRef.ssl_email.value == formRef.ssl_email.value.replace(dominio_seguro,"")) {
				form_ok	= false;
				formRef.ssl_email.focus();
				alert("El EMAIL debe pertenecer al mismo DOMINIO que el SUBDOMINIO SEGURO");
			}
		}

		// Validación SEM
		form_ok = calcularSEM("sem_inversion","sem_moneda","priceMensual",form_ok);
		form_ok	= validateTextField("sem_inversion", "La INVERSIÓN es requerida.", "err_div_2", form_ok);
		form_ok = validateTextField("sem_paises", "Los PAÍSES DONDE APUNTAR LA CAMPAÑA son requeridos.", "err_div_2", form_ok);
		form_ok = validateTextField("sem_keywords", "Las PALABRAS CLAVES (KEYWORDS) son requeridas.", "err_div_2", form_ok);
				
		// Validación LICENCIAS
		form_ok	= validateTextField("cp_ip", "La IP es requerida. Debe ser una IP dedicada.", "err_div_2", form_ok);
		form_ok	= validateIPField("cp_ip", "La IP no es válida.", "err_div_2", form_ok);
		
		// Planes
		if(form_ok) form_ok	= validateOptionBox(formRef, "cost",	"Debe seleccionar el TIPO DE PAGO", "err_div_2", form_ok);
		
		// Terminos
		if(form_ok && !formRef.bases.checked)
		{
			form_ok	= false;
			//err_div.innerHTML	= "Debe aceptar las bases y condiciones";
			formRef.bases.focus();
			alert("Debe leer y aceptar los Términos y Condiciones, Política de Privacidad y Política Anti-SPAM de NUTHOST");
		}
		
		return(form_ok);
		
	}
	
	function validateStep1()
	{
		activate('paso-1');
		
		form_ok	= true;
		formRef	= document.getElementById("buy_form");
		//err_div = document.getElementById("err_div");
		//err_div.innerHTML = "";
		
		form_ok	= validateTextField("user_document",		"El DNI/CUIT es requerido", "err_div", form_ok);
		form_ok	= validateTextField("user_fullname",		"El NOMBRE O RAZÓN SOCIAL es requerido", "err_div", form_ok);
		form_ok	= validateOptionBox(formRef, "user_gender",	"El SEXO es requerido", "err_div", form_ok);
		
		if(!document.getElementById("user_birth_month").disabled && !document.getElementById("user_birth_day").disabled && !document.getElementById("user_birth_year").disabled) {
			var dt	= document.getElementById("user_birth_month").value+"/"+document.getElementById("user_birth_day").value+"/"+document.getElementById("user_birth_year").value;
			if (!isDate(dt) && form_ok)
			{
				alert("La FECHA DE NACIMIENTO no es válida");
				document.getElementById("user_birth_day").focus();
				form_ok	= false;
			}
		}
		
		form_ok	= validateTextField("useremail",			"El EMAIL es requerido", "err_div", form_ok);
		form_ok	= validateEmailField("useremail",			"El EMAIL no es válido", "err_div", form_ok);
		// form_ok	= validateTextField("user_inter_phone",		"El CODIGO INTERNACIONAL es requerido", "err_div", form_ok);
		// form_ok	= validateTextField("user_area_phone",		"El CODIGO DE AREA es requerido", "err_div", form_ok);
		form_ok	= validateTextField("user_phone_number",	"El NUMERO DE TELEFONO es requerido", "err_div", form_ok);
		form_ok	= validateTextField("user_address",			"La DIRECCION es requerida", "err_div", form_ok);
		form_ok	= validateTextField("user_zip",				"El CODIGO POSTAL es requerido", "err_div", form_ok);
		form_ok	= validateTextField("user_country",			"El PAIS es requerido", "err_div", form_ok);
		form_ok	= validateTextField("user_city",			"La CIUDAD es requerida", "err_div", form_ok);
		//form_ok	= validateTextField("user_state",			"La PROVINCIA es requerida", "err_div", form_ok);
		
		field	= document.getElementById("useremail2");
		if(field.value!="" && form_ok)
		{
			form_ok	= validateEmailField("useremail2",		"El EMAIL SECUNDARIO no es válido", "err_div", form_ok);
		}
		
		
		div = document.getElementById('col2');
		if(div.style.display!="none")
		{
			//alert("VALIDATE!!!");
			form_ok	= validateTextField("person_document",		"El DNI es requerido", "err_div", form_ok);
			form_ok	= validateTextField("person_fullname",		"El NOMBRE Y APELLIDO es requerido", "err_div", form_ok);
			form_ok	= validateOptionBox(formRef, "person_gender",	"El SEXO es requerido", "err_div", form_ok);

			if(!document.getElementById("person_birth_month").disabled && !document.getElementById("person_birth_day").disabled && !document.getElementById("person_birth_year").disabled) {
				var dt	= document.getElementById("person_birth_month").value+"/"+document.getElementById("person_birth_day").value+"/"+document.getElementById("person_birth_year").value;
				if (!isDate(dt) && form_ok)
				{
					alert("La FECHA DE NACIMIENTO no es válida");
					document.getElementById("person_birth_day").focus();
					form_ok	= false;
				}
			}
				
			form_ok	= validateTextField("person_email",			"El EMAIL es requerido", "err_div", form_ok);
			form_ok	= validateEmailField("person_email",		"El EMAIL no es válido", "err_div", form_ok);
			//form_ok	= validateTextField("person_inter_phone",	"El CODIGO INTERNACIONAL es requerido", "err_div", form_ok);
			//form_ok	= validateTextField("person_area_phone",	"El CODIGO DE AREA es requerido", "err_div", form_ok);
			form_ok	= validateTextField("person_phone_number",	"El NUMERO DE TELEFONO es requerido", "err_div", form_ok);
			form_ok	= validateTextField("person_address",		"La DIRECCION es requerida", "err_div", form_ok);
			form_ok	= validateTextField("person_zip",			"El CODIGO POSTAL es requerido", "err_div", form_ok);
			form_ok	= validateTextField("person_country",		"El PAIS es requerido", "err_div", form_ok);
			form_ok	= validateTextField("person_city",			"La CIUDAD es requerido", "err_div", form_ok);
			form_ok	= validateTextField("person_state",			"La PROVINCIA es requerido", "err_div", form_ok);
			
			field	= document.getElementById("person_email2");
			if(field.value!="" && form_ok)
			{
				form_ok	= validateEmailField("person_email2",	"El EMAIL SECUNDARIO no es válido", "err_div", form_ok);
			}
			
			//alert(document.getElementById("user_email").value);
		}
		
		return(form_ok);
	}
	
	function loginUser()
	{
		formRef	= document.getElementById(formName);
		
		user_name	= formRef.wuser_login_name.value;
		user_pass	= formRef.wuser_login_pass.value;

		makeLogin(user_name, user_pass);
	}
	
	function showSecUserEmail()
	{
		toggleLayer("secUserEmail");
	}
	
	function makeLogin(user_name, user_pass)
	{
		overlay();
		var poststr	=	"sent=1" +
						"&user_name=" + user_name + 
						"&user_pass=" + user_pass 
						
						
		makePOSTLoginRequest(login_url, poststr);
	}
	
	function makePOSTLoginRequest(url, parameters)
	{
		http_request = false;
		
		if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
		 http_request = new XMLHttpRequest();
		 if (http_request.overrideMimeType) {
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		 }
		} else if (window.ActiveXObject)
		{ // IE
		 try
		 {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e)
		 {
			try
			{
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
		}
		if (!http_request)
		{
			alert('Cannot create XMLHTTP instance');
			return false;
		}
		
		http_request.onreadystatechange = alertLoginContents;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}
	
	function alertLoginContents()
	{
	   	requesting	= false;
		if (http_request.readyState == 4)
		{
			overlay();
			if (http_request.status == 200)
			{
				result	= http_request.responseText;
				result	= parseParams(result);
				
				//alert(http_request.responseText);
				
				if(result["login"]==1)
				{
					formRef							= document.getElementById(formName);
					formRef.user_document.disabled	= true;
					formRef.user_fullname.value		= result["nombrea"];
					formRef.user_fullname.disabled		= true;
					formRef.user_document.value		= result["nro"];
					
					date_arr						= result["fnac"].split("-");
					so								= ((result["sex"]*1)==0)? 1 : 0;
					formRef.user_gender[so].checked	= true;
					formRef.useremail.value			= result["usemail"];
					formRef.useremail2.value		= result["usemail2"];
					
					formRef.user_birth_day.selectedIndex 	= date_arr[0];
					formRef.user_birth_month.selectedIndex 	= date_arr[1];
					selectComboAtItem(formRef.user_birth_year, date_arr[2]);
					
					formRef.user_address.value		= result["domicilio"];
					
					formRef.user_city.value			= result["ciudad"];
					formRef.user_zip.value			= result["cp"];
					
					selectComboAtItem(formRef.user_country, result["pais"]);
					formRef.user_state.value = result["provincia"];
					
					if(result["pais"]=="Argentina") {
						hideShowProvincias("Argentina",formRef,"user");
						selectComboAtItem(formRef.user_state_arg, result["provincia"]);
					}
					
					formRef.user_phone_number.value	= result["tel"];
					formRef.user_id.value			= result["id"];
					
					div					= document.getElementById('col2B');
					div.style.display	= 'none';
					userLogged			= true;
				}
				else
				{
					alert("El LOGIN es incorrecto");
				}
			} else {
				alert('Redireccionando...');
			}
		}
	}
   
	function selectComboAtItem(cmb, item_str)
	{
		
		for(i=0;i<cmb.options.length;i++)
		{
			//debug("'"+cmb.options[i].value+"'=='"+item_str+"'")
			if(cmb.options[i].text == item_str || cmb.options[i].value == item_str || cmb.options[i].text == URLDecode(item_str) || cmb.options[i].value == URLDecode(item_str))
			{
				cmb.selectedIndex	= i;
			}
		}
	}
	
	function debug(_s)
	{
		if(console!=null)
		{
			console.log(_s);
		}
	}
	
	function makePOSTRequest(url, parameters)
	{
		http_request = false;
		
		if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
		 http_request = new XMLHttpRequest();
		 if (http_request.overrideMimeType) {
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		 }
		} else if (window.ActiveXObject)
		{ // IE
		 try
		 {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e)
		 {
			try
			{
			   http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		 }
		}
		if (!http_request)
		{
			alert('Cannot create XMLHTTP instance');
			return false;
		}
		
		http_request.onreadystatechange = alertContents;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}

   function alertContents()
   {
	   	requesting	= false;
		if (http_request.readyState == 4)
		{
			overlay();
			if (http_request.status == 200)
			{
				result	= http_request.responseText;
				result	= parseParams(result);
				
				if(result["err"]==0)
				{
					already_sent	= true;
					activate('paso-4');
				}else
				{
					alert(result["errmsg"]);
				}
			} else {
				alert('Lo sentimos! Hubo algún problema con el inicio de sesión :(');
			}
		}
   }

	
	
	function parseParams(es)
	{
		var keyvalue	= es.split("&");
		var i;
		var stipped;
		var key;
		var value;
		var params	= new Array();
		for(i=0;i<keyvalue.length;i++)
		{
			stipped		= keyvalue[i].split("=");
			key			= stipped[0];
			value		= URLDecode(stipped[1]);
			params[key]	= value;
		}
		return(params);
	}
	
	function URLEncode(ds)
	{
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
	
		var plaintext = ds;
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) {
			var ch = plaintext.charAt(i);
			if (ch == " ") {
				encoded += "+";				// x-www-urlencoded, rather than %20
			} else if (SAFECHARS.indexOf(ch) != -1) {
				encoded += ch;
			} else {
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) {
					alert( "Unicode Character '" 
							+ ch 
							+ "' cannot be encoded using standard URL encoding.\n" +
							  "(URL encoding only supports 8-bit characters.)\n" +
							  "A space (+) will be substituted." );
					encoded += "+";
				} else {
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
	
		/*document.URLForm.F2.value = encoded;
		document.URLForm.F2.select();*/
		return(encoded);
	};
	
	function URLDecode(es)
	{
	   if(es!=null && es!="undefined")
	   {
		   var HEXCHARS = "0123456789ABCDEFabcdef"; 
		   var encoded = es;
		   var plaintext = "";
		   var i = 0;
		   while (i < encoded.length) {
			   var ch = encoded.charAt(i);
			   if (ch == "+") {
				   plaintext += " ";
				   i++;
			   } else if (ch == "%") {
					if (i < (encoded.length-2) 
							&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
							&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
						plaintext += unescape( encoded.substr(i,3) );
						i += 3;
					} else {
						alert( 'Bad escape combination near ...' + encoded.substr(i) );
						plaintext += "%[ERROR]";
						i++;
					}
				} else {
				   plaintext += ch;
				   i++;
				}
			}
			return(plaintext);
		}else
		{
			return("");
		}
	};


var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

/*function ValidateForm(){
	var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }*/
 
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
	{
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		{
		}
		else
		{
			//alert("Your Alpha Numeric Test Failed");
			return false;
		}
	}
	//alert("Your Alpha Numeric Test Passed");
	return true;
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
