
var xmlhttp = false;

function ajaxRequest() {
	var args = ajaxRequest.arguments;
	var x = getAjaxObject();

	if(x) {
		if(5 != args.length) {
			args[4] = true;
		}

		if(true == args[4]) {
			x.onreadystatechange = function() {
				if(x.readyState == 4 && x.status == 200)
				{
					args[2](x);
					x = null;
				}
			}
		}

		if(x.overrideMimeType) {
			x.overrideMimeType('text/xml');
		}

		x.open(args[0],args[1],args[4]);
		
		if(args[3]) {
			x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		} else	{
			x.send(null);
		}

		if(false == args[4]) {
			var ret_for_sync_call = args[2](x);
			x = null;
			return ret_for_sync_call;
		} else {
			alert("No AJAX Support");
		}
	}
}

function getAjaxObject() {
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch (e) {}
	alert("XMLHttpRequest not Supported");
	return null;
}

function doReset() {
	$('username').value="";
	$('password').value="";
	return false;
}

function checklogin(formId) {
	var username = formId.txtUserName;
	var password = formId.txtUserPassword;

	if(!xmlhttp) {
		xmlhttp = getAjaxObject();
	}

	if(trim(username.value) == '') {
		alert("Please enter the username");
		username.focus();
		username.select();
		return false;
	}

	if(trim(password.value) == '') {
		alert("Please enter the password");
		password.focus();
		password.select();
		return false;
	}

	var url = 'ajax_general.php';
	var param="&username="+username.value+"&password="+password.value;
	xmlhttp.open("POST",url,false);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("call=login"+param);

	var result = xmlhttp.responseText;
	if(result == 1) {
		formId.action	=	"members_area.php";//membersarea.php
		formId.submit();
		//return true;
	} else {
		var msgToDisplay	=	'Invalid login details. If you are seeing this message it is for one of two reasons.';
		msgToDisplay	+=	'\r\n 1. You have entered the wrong Login Details or ';
		msgToDisplay	+=	'\r\n 2. You have just regisitered with A.T.C. and have not had your account activated.';
		msgToDisplay	+=	'\r\n If this problem last for more then 24 hrs please contact register@asisn-travel-club.com.com. ';
		alert(msgToDisplay);
		return false;
	}
}


function recoverPwd(formId,siteURL) {
	var username		=	formId.userName;
	var passwordHint	=	formId.passwdHint;
	var answerValue		=	formId.answerVal;

	if(!xmlhttp) {
		xmlhttp = getAjaxObject();
	}

	if(trim(username.value) == '') {
		alert("Please enter the username");
		username.focus();
		username.select();
		return false;
	}

	if(trim(passwordHint.value) == '') {
		alert("Please enter the password");
		passwordHint.focus();
		passwordHint.select();
		return false;
	}

	var url = siteURL + 'ajax_general.php';
	var param="&username="+username.value+"&passwordHint="+passwordHint.value + "&answerVal="+answerValue.value;
	xmlhttp.open("POST",url,false);
	xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xmlhttp.send("call=recoverPwd"+param);
	var result = xmlhttp.responseText;

	if(result == 1) {
		alert("Password Sent To Your Email Address");
		//window.location.href = siteURL+'startnew.htm';
		var myUrl	=	siteURL+'startnew.htm';
		window.parent.location.href=myUrl;
		//formId.action	=	myUrl;
		//formId.submit();
	} else {
		var msgToDisplay	=	'Invalid login details. If you are seeing this message it is for one of two reasons.';
		msgToDisplay	+=	'\r\n 1. You have entered the wrong Login Details or ';
		msgToDisplay	+=	'\r\n 2. You have just regisitered with A.T.C. and have not had your account activated.';
		msgToDisplay	+=	'\r\n If this problem last for more then 24 hrs please contact register@asisn-travel-club.com.com. ';
		alert(msgToDisplay);
		return false;
	}

}
