/*****************************************************************************************************************************/
/* page load */
//window.onload = function(){
//	
//	//if JS is enabled, warning will be hidden
//	$("divJSTest").className = "hide";
//
//
//}

function initNav(){
	
	var pagePath = window.location.pathname;
	var pageName = pagePath.substring(pagePath.lastIndexOf('/') + 1);

	switch(pageName)
	{
		case "event.php":
			$("lnkEventInfo").style.backgroundPosition = "0px -10px";
			break;
		case "accomodations.php":
			
			$("lnkAccomodations").style.backgroundPosition = "0px -10px";
			break;
		case "gallery.php":
			$("lnkGallery").style.backgroundPosition = "0px -10px";
			break;
		case "rsvp.php":
			$("lnkRSVP").style.backgroundPosition = "0px -10px";
			break;
	}
	
}





/*****************************************************************************************************************************/
/* 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
	});
	
}





/*****************************************************************************************************************************/
/* admin search */
function searchRequest(){
	
	$('btnSearch').disabled = "disabled";
	
	if($("tabRecords").style.display != "none"){
		$("tabRecords").style.display = "none";
	}
	
	allNodes = Form.serialize("frmSearch");
	
	new Ajax.Request("rsvp_search.php",
	{
		method:"post",
		postBody:allNodes,
		onComplete:showSearchResults,
		onFailure:ajaxError
	});
	
}




/*****************************************************************************************************************************/
/* rsvp request */
function RSVPRequest(){
	
	$("btnSubmit").disabled = "disabled";
	$("imgAjaxLoader").toggle();
	
	allNodes = Form.serialize("frmRSVP");
	
	new Ajax.Request("rsvpprocess.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();
		$('frmRSVP').reset();
	}
}





/*****************************************************************************************************************************/
function showSearchResults(req){
	
	$("records_container").innerHTML = req.responseText;
	$("btnSearch").disabled = false;


}





/*********************************************************************************************************/
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));
}

