/*****************************************************************************************************************************/
/* page load */
//window.onload = function(){
//
//}


/*****************************************************************************************************************************/
/* ajax requests */
/*****************************************************************************************************************************/

/*****************************************************************************************************************************/
/* admin login request */
function adminLoginRequest(){
	
	$("btnSubmit").disabled = "disabled";
	$("imgAjaxLoader").toggle();	
	
	allNodes = Form.serialize("frmAdminLogin");
	
	new Ajax.Request("login_process.php",
	{
		method:"post",
		postBody:allNodes,
		onComplete:showResponse,
		onFailure:ajaxError
	});
	
}





/*****************************************************************************************************/
function addAdminRequest(){
	
	$("btnSubmit").disabled = "disabled";
	$("imgAjaxLoader").toggle();
	
	allNodes = Form.serialize("frmAddAdmin");
	
	new Ajax.Request("addadmin_process.php",
	{
		method:"post",
		postBody:allNodes,
		onComplete:showResponse,
		onFailure:ajaxError
	});
	
}





/*****************************************************************************************************/
function editAdminRequest(){
	
	$("btnSubmit").disabled = "disabled";
	$("imgAjaxLoader").toggle();
	
	$("admin_user").innerHTML = "<a href=\"editadmin.php\" title=\"Edit Your Profile\">" + $("txtEmail").value + "</a>";
	
	allNodes = Form.serialize("frmEditAdmin");
	
	new Ajax.Request("editadmin_process.php",
	{
		method:"post",
		postBody:allNodes,
		onComplete:showResponse,
		onFailure:ajaxError
	});
	
}

function changeEmail(el){

	$('divStatus').innerHTML = "Please note that your email"
			+ " addressed is used as your login and/or username.<br /> Are you sure you wish to change your login information?<br />"
			+ " <a href=\"javascript:void(0);\" onclick=\"changeEmailDenied();\">No, do not change it.</a>&nbsp;&nbsp;<a href=\"javascript:void(0);\" onclick=\"changeEmailConfirmed();\">Yes</a> ";

}

function changeEmailConfirmed(){
	if(document.getElementById){
		$('txtEmail').readOnly = false;
		$('divStatus').innerHTML = "";
		$('txtEmail').focus();
		$('txtEmail').select();
	}
}

function changeEmailDenied(){
	$('divStatus').innerHTML = "";	
}





/*****************************************************************************************************/
function forgotPasswordRequest(){
	
	$("btnSubmit").disabled = "disabled";
	$("imgAjaxLoader").toggle();
	
	allNodes = Form.serialize("frmForgotPassword");
	
	new Ajax.Request("forgot_password_process.php",
	{
		method:"post",
		postBody:allNodes,
		onComplete:showResponse,
		onFailure:ajaxError
	});
	
}





/*****************************************************************************************************************************/
/* ajax responses */
/*****************************************************************************************************************************/

/*****************************************************************************************************************************/
function showResponse(req){

	if(req.responseText == "adminLoginRequest"){
		window.location = "index.php";
	}else{
		$("divStatus").innerHTML = req.responseText;
		$("btnSubmit").disabled = false;
		$("imgAjaxLoader").toggle();
	}
}





/*********************************************************************************************************/
function ajaxError(){
	$("divStatus").innerHTML = "There was a problem processing the Ajax Request";
}





/*********************************************************************************************************/
/* cookie check */
function cookieCheck(){
	//set test cookie
	setCookie("cookieCheck", "cookietest", 5);
	//check if cookie was accepted
	if(readCookie("cookieCheck") != "cookietest"){
		Effect.BlindDown('cookieCheck');
		$('wrapper').className = 'hide';
		//alert('enable cookies');
	}
	//delete cookie
	setCookie("cookieCheck", "", -1);
}//cookieCheck

function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
					 + ";expires="+expire.toGMTString();
}//setCookie

function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

