// JavaScript Document
showAlert=false;

function do_changePassword_cb(res) {
	if (res["result"]=="true") {
		document.cookie = "UID=" + res["cookiecontent"];
		document.location.href="index.php?page=private";	
	} else {
		var _msg="";
		if (res["Empty"]!="") 			{ _msg=_msg+="Oops! Please include:\n"+res["Empty"]+"\n"; }
		if (res["NotAllowedChars"]!="") { _msg=_msg+"Oops! These characters can't be used in:\n"+res["NotAllowedChars"]+"\n"; }
		if (res["Error"]!="")			{ _msg=_msg+res["Error"]+"\n"; }
		alert(_msg+"\nOops! Your email address, Yooster name and your current password don't match.\n\nPlease check your details and try again.");
	}
}
function do_changePassword() {
	var _mail = $("txtEmailAddress").value;
	var _yname = $("txtNickname").value;
	var _pwdOld = $("txtPwd1").value;
	var _pwd1 = $("txtNewPassword").value;
	var _pwd2 = $("txtRetypePassword").value;
	x_changePassword(_mail, _yname, _pwdOld, _pwd1, _pwd2, do_changePassword_cb);
}

function do_cancelAccount_cb(res) {
	if (res["result"]=="true") {
		document.cookie="UID=''; expires=Thu, 01-Jan-70 00:00:01 GMT;";
		document.location.href="index.php?page=confirm_cancel";			
	} else {
		var _msg="";
		if (res["Empty"]!="") 			{ _msg=_msg+"Oops! Please include:\n"+res["Empty"]+"\n"; }
		if (res["NotAllowedChars"]!="") { _msg=_msg+"Oops! These characters can't be used in:\n"+res["NotAllowedChars"]+"\n"; }
		if (res["Error"]!="")			{ _msg=_msg+res["Error"]; }
		alert(_msg+"\nPlease try again.");		
	}
}
function do_cancelAccount() {
	x_cancelAccount($("txtPwd1").value, $("txtComments").value, do_cancelAccount_cb);
}

function edit_profile() {
	var myUTC = new Date();		
	document.location.href="index.php?page=signup_profile&dur="+myUTC.getTime();	
}
function do_accountLogin_cb(res) {
	if (res["result"]=="true") {
		document.cookie = "UID=" + res["cookiecontent"];
		if (res["profilquestion_step"]=="all") {
			document.location.href="index.php?page=private";			
		} else {
			// profil-questions	
			var myUTC = new Date();		
			document.location.href="index.php?page=signup_profile&dur="+myUTC.getTime();			
		}
	} else {		
		var _msg="";
		if (res["Empty"]!="") 			{ _msg=_msg+"Oops! Please include:\n"+res["Empty"]+"\n"; }
		if (res["NotAllowedChars"]!="") { _msg=_msg+"Oops! These characters can't be used in:\n"+res["NotAllowedChars"]+"\n"; }
		if (res["Error"]!="")			{ _msg=_msg+res["Error"]+"\n"; }
		alert(_msg);
	}
}
function do_accountLogin() {
	var _err=false;
	var strLogin = $("txtLogin").value;
	var strPwd = $("txtPwd").value;
	if (strLogin=="" || strPwd=="") {
		alert("Oops! Please type in your email address and password to access My Yooster.");
	} else {
		x_accountLogin(strLogin, strPwd, do_accountLogin_cb);
	}
}
function do_sendPwd_cb(res) {
	if (res["result"]!="true") {		
		var _msg="";
		if (res["Empty"]!="") 			{ _msg=_msg+"Oops! Please include:\n"+res["Empty"]+"\n"; }
		if (res["NotAllowedChars"]!="") { _msg=_msg+"Oops! These characters can't be used in:\n"+res["NotAllowedChars"]+"\n"; }
		if (res["Error"]!="")			{ _msg=_msg+res["Error"]; }
		alert(_msg+"\nOops! Your email address is not correct.\nPlease try again.");
	} else {
		/* sw_Login(); */
		$("txtForgot").value = "";
		alert("Thanks for requesting a new password. We've emailed it to you.");
	}
}
function do_sendPwd() {
	var strForgot = $("txtForgot").value;
	if (strForgot=="") {
		alert("Oops! Please type in your email address so we can send you a new password.");
	} else {
		x_sendPwd(strForgot, do_sendPwd_cb);
	}
}
function sw_Forgot() {
	$("pwdforgot").style.display="block";
	$("login").style.display="none";
}
function sw_Login() {
	$("pwdforgot").style.display="none";
	$("login").style.display="block";
}