// JavaScript Document

document.tempuser ="";
document.temppass ="";

function forgot()
{
	window.open('/forgot','forgot','width=300,height=300');	
}

function cancelRegistration()
{
	document.getElementById("homepage_registration_area").innerHTML = document.regStart;
	sndReq('killses','1');
}
function homelogin(obj)
{
	orgmsg = '';
	errormsg = '';
	he = obj.lu.value;
	sh = obj.lp.value;
	if(!he.length > 0)
		errormsg += " - username \n";
	if(!sh.length > 0)
		errormsg += " - password \n";
		
	if(orgmsg != errormsg)
		alert("Please enter missing information: \n" + errormsg + "\n\n");
	else
		sndReq('login','1&he='+he+'&sh='+sh);
}

function doLogin()
{	
	document.location = '/members/';
}

function startRegistration()
{
	sndReq('startRegistration','1&div=homepage_registration_area');
}
function checkNewUser(obj)
{
	var val = obj.tryuser.value;
	if(val.length > 0)
	{	
		sndReq('startRegistration','1&div=homepage_registration_area&tryu=' + val);
		
	}
	
}
function checkPass(obj)
{
	var p1 = obj.password.value;
	var p2 = obj.password2.value;
	if(p1.length > 0 && p2.length > 0 )
	{
		if(p1 == p2)
		{
			sndReq('startRegistration','1&div=homepage_registration_area&step=3&p='+p1);
		}
		else
		{
			alert('Passwords do not match, please re-enter');	
		}
		
	}	
}

function checkEmail(obj)
{
	var e1 = obj.email.value;
	var e2 = obj.email2.value;
	if(e1.length > 0 && e2.length > 0 )
	{
		if(e1 == e2)
		{
			 var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	    	 var regex = new RegExp(emailReg);
			 
   		  
		  	 if(regex.test(e1))
			 {
				 sndReq('startRegistration','1&div=homepage_registration_area&step=4&e=' + e1);
			 }
			 else
			 	alert('Please enter a vaild email Address');
		}
		else
		{
			alert('Email Addresses do not match, please re-enter');	
		}
		
	}	
}

function hearaboutus(obj)
{
 
 	if(obj[obj.selectedIndex].value == "other")
	{
		document.getElementById("hearabout_other").innerHTML = '<input type="text" id="hear_other" name="hear_other" value="how?" class="loginfields" maxlength="80"/>';
	}
	else
	{
			document.getElementById("hearabout_other").innerHTML = '';	
	}

}

function checkSource(obj)
{
	
	if(obj.selectedIndex == 0)
		alert("Please tell us how you heard about us");
	else
	{
		sndReq('createUser','1&div=homepage_registration_area&step=5&how_hear=' + obj[obj.selectedIndex].value);
	}
	
}



function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('{' != -1)) {
            update = response.split('{{||}}');
			 jsupdate = response.split('{{js}}');
			
			if(jsupdate[1] != null)
			{
				
				javascript:eval(jsupdate[1]);
				
			}
				if(document.getElementById(update[0]) != null)
          		  document.getElementById(update[0]).innerHTML = update[1];
			
			if(update[2] != null && update[3] != null)
			{
				//alert ("update " + update[2]);
				if(document.getElementById(update[2]) != null)
					document.getElementById(update[2]).innerHTML = update[3];
			}
        }
    }
}




function sndReq(action,extra) {

	 http = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http = new XMLHttpRequest();
            if (http.overrideMimeType) {
                http.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http.onreadystatechange = handleResponse;
        http.open('GET', '/includes/aj.php?action='+action+'&extra='+extra, true);
        http.send(null);
		
	
	/*
    http.open('GET', 'includes/aj.php?action='+action+'&extra='+extra, true);
    http.onreadystatechange = handleResponse;
    http.send(null);*/
}



