﻿// JavaScript Document

var g_Email;
var g_Password1;
var g_Password2;
//		if($('input[@name=sex_input]').get(1).checked==true)sex=1;


$(document).ready(function()
{		
//		window.open("agreements.htm");
		$("#fm_CreateAccount").show();
		$("#fm_Success").hide();
				
	$('#btn_Submit').click(function()
	{

		var Error = 0;
		g_Email = $("#tb_Email").val();
		g_Password1 = $("#tb_Password").val();
		g_Password2 = $("#tb_Password2").val();
		
		g_Email = VerifyEChars(g_Email);
				
		if(g_Email.indexOf("@")<0)
		{
			$("#msg_Email").html("This E-mail address is invalid, have a check please");
			Error = 1;
		}

		if(g_Email=="")
		{
			$("#msg_Email").html("E-mail is required");
			Error = 1;
		}		

		if(g_Password1=="")
		{
			$("#msg_Password").html("Password is required");
			Error = 1;
		}

		if(g_Password2=="")
		{
			$("#msg_Password2").html("Type the same password again please");
			Error = 1;
		}
		
		if(g_Password1!=g_Password2)
		{
			$("#msg_Password2").html("Password does not match with the one above");
			Error = 1;
		}
		
		
		if(Error==1)return;
		
		var httpObj = getHttpObject();

		httpObj.onreadystatechange = function(){
			if(httpObj.readyState == 4){
				if(httpObj.status == 200){
					var conttext = httpObj.responseText;
					if(conttext.indexOf("SUCCESS")>=0)
					{
						$("#fm_CreateAccount").hide();
						$("#fm_Success").show();
										
					}
					else
					{
						$("#msg_Email").html("This E-mail address is already registered. If you forgot the Password, Click <a href=\"getbackpassword.htm\" target=\"_blank\">here</a> to get it back.");
					}
				}
			}
		}		
		
		httpObj.open("POST", domainname+"register.php", true);
		httpObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		httpObj.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
		httpObj.send("Email="+g_Email+"&Password="+g_Password1);
		httpObj.send(null);

	});
	
	$('#btn_Reset').click(function()
	{
		$("#tb_Email").val("");
		$("#tb_Password").val("");
		$("#tb_Password2").val("");
	});
	
	

});


