// JavaScript Document

var request_id;

function ajax_validatelogin(username, pass){
	new ajax ('ajax.php', {postBody: 'method=validate_login&username='+username+'&pass='+pass, onComplete: validatelogin_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function check_username(username, email){
	if(username==""){
		alert("Please enter your login username");
		return;
	}else if(email==""){
		alert("Please enter your email address");
		return;
	}else{
		new ajax ('ajax.php', {postBody: 'method=check_username&username='+username+'&email='+email, onComplete: checkusername_callback});
		document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
		document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
		document.getElementById("WAIT").style.display = '';
		document.getElementById("COVER").style.display = '';
		document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	}	
}

function checkusername_callback(request, uservar){
	if(request.responseText=="OK"){
		document.frm_register.submit();
	}else if(request.responseText=="DUPEMAIL"){
		alert("This email address is already registered !!");
	}else if(request.responseText=="DUPUSER"){
		alert("This username has already been used !! Please choose another one");
	}else if(request.responseText=="INVALIDDATA"){
		alert("Failed processing. Please checked the username and email !!");
	}
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
}


function check_password(password,user_id){
	new ajax ('ajax.php', {postBody: 'method=checkpassword&password='+password+"&user_id="+user_id, onComplete: check_password_callback});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
	return false;
}

function check_password_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request.responseText=="OK"){
		if(document.frm_change_password.login_password.value == document.frm_change_password.login_password_new.value){
			alert('Your current password and new password can not be same!!');
		}else{
			document.frm_change_password.submit();	
		}
	}else if(request.responseText=="INVALID"){
		alert('Your current password does not match with our record');	
	}else{
		alert('There was a problem communicating with the server\nPlease try later');
	}
}

function validate_captcha(captcha_value, frm){
	new ajax ('ajax.php', {postBody: 'method=validate_captcha&captcha_value='+captcha_value, onComplete: validate_captcha_callback, userVariable: frm});
	document.getElementById("WAIT").style.left = (Screen.getViewportWidth()/2 - (300/2))+"px";
	document.getElementById("WAIT").style.top = (Screen.getScrollTop()+(Screen.getViewportHeight()/2)-50)+"px";
	document.getElementById("WAIT").style.display = '';
	document.getElementById("COVER").style.display = '';
	document.getElementById("COVER").style.height = Screen.getDocumentHeight()+'px';
}

function validate_captcha_callback(request, uservar){
	document.getElementById("WAIT").style.display = 'none';
	document.getElementById("COVER").style.display = 'none';
	if(request!=null){
		if(request.responseText=="OK"){
			uservar.submit();
		}else if(request.responseText=="INVALID"){
			alert("Invalid Verification Code !!");
			captchaNew();
		}else{
			captchaNew();
			alert("There was a problem communicating with the server\n\nPlease try later on");
		}
	}else{
		captchaNew();
		alert("There was a problem communicating with the server\n\nPlease try later on");
	}
}
