/*function ajaxEditPage(pageId){
	new Ajax.Updater('mainContentEditTextarea','includes/ajax_test.php',{
		method:'get',
	onSuccess: function showHideDivs(){
		document.getElementById('mainContent').style.display="none";
		document.getElementById('mainContentEdit').style.display="block";
    },
    onFailure: function(){ alert('Something went wrong...') }
		});
	
	}
*/

/****************************************************************************************************

---------------------------------------------Global Javascript Variables----------------------------

*****************************************************************************************************/



/****************************************************************************************************

---------------------------------------------Form Processing Functions----------------------------

*****************************************************************************************************/
/*javascript submit Update Form*/
function jsUpdatePage(){
	document.getElementById("editMain").submit();
	}
	
function jsNewCal(){
	new Ajax.Request('includes/ajax_newCal.php',{
		method:'post', 
		onSuccess: function(calendar){
			var calStatus = calendar.responseXML.getElementsByTagName('status');
		//	alert(calStatus.length);
		//	alert(calStatus);
			var msgCode=calStatus[0].getAttribute('msgCode');
			var msgReason=calStatus[0].getAttribute('reason');
		//	alert(msgCode);
			
			switch(msgCode){
				case 'success':
				//	alert(msgReason);
					document.getElementById("newCal").reset();
				break;
					alert("Calendar Event Entered");
				case 'failed':
				
				break;
				}
			
			},
		parameters: $('newCal').serialize(true)
		
		});
	
	}
		
	function jsEditCal(){
	new Ajax.Request('includes/ajax_editCal.php',{
		method:'post', 
		onSuccess: function(calendar){
			var calStatus = calendar.responseXML.getElementsByTagName('status');
		//	alert(calStatus.length);
			//alert(calStatus);
			var msgCode=calStatus[0].getAttribute('msgCode');
			var msgReason=calStatus[0].getAttribute('reason');
		//	alert(msgCode);
			
			switch(msgCode){
				case 'success':
					alert(msgReason);
					 window.location = 'http://caycemill.net/page.php?page=cal'
				break;
					//alert("Calendar Event Entered");
				case 'failed':
				
				break;
				}
			
			},
		parameters: $('editCal').serialize(true)
		
		});
	}


/********General Form Validation Functions******/

function phpValidate(valForm,id){
	alert('validating via PHP');
	new Ajax.Request('includes/ajax_phpValidate.php',{
		method:'post',
		onSuccess:function(val){
			alert('testing');
			var response = val.responseXML.getElementsByTagName('status');
			alert(response);
			var msgCode=response[0].getAttribute('msgCode');
			alert(msgCode);
			},
			 // onFailure: function(){ alert('Something went wrong...') ,
			parameters:{formType: valForm, uid:id}
		});
		if(msgCode == 'failed'){return false;}
	
	}





/*Validate Required Fields*/
function validateRequired(field,alerttxt)
{
	//alert('checking field '+field);
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false;}
else {return true;}
}
}
/*Checks to see if passwords match*/
function validatePasswordMatch(pass1,pass2){
	var pwd1 = getInputValue(document.forms['resetPass'].pass1);
	var pwd2 = getInputValue(document.forms['resetPass'].pass2);
	
	if(pwd1 == pwd2){return true;}
	else {alert('Passwords Do Not Match.');
		return false;}	
	}


function validatePasswordReset(thisform){

	with(thisform){
	if (validateRequired(pass1,"Input Password field must be filled out")==false)
  {pass1.focus();return false;}
  
  if (validateRequired(pass2,"Confirm Password field must be filled out")==false)
  {pass2.focus();return false;}
  
  if (validatePasswordMatch(pass1,pass2) == false){
  	setInputValue(document.forms['resetPass'].pass1, '');
  	setInputValue(document.forms['resetPass'].pass2, '');
  	pass1.focus();
  	return false;
  	}		
	}
	}


/*validate edit user*/
function validateEditUser(thisform){
	with(thisform){	
			if (validateRequired(location,"Location must be entered.")==false)
 		 {location.focus();return false;}		
	}
	}




/*Validate New User Form
Checks for all fields to be filled out, passwords to match and at least one right assigned*/

function validateNewUser(thisform){
	with(thisform){	
		
		
		if (validateRequired(username,"Username must be entered.")==false)
 		 {username.focus();return false;}

		if (validateRequired(displayName,"Display Name must be entered.")==false)
 		 {displayName.focus();return false;}
 		 
 			if (validateRequired(location,"Location must be entered.")==false)
 		 {location.focus();return false;}
 	
 		if (validateRequired(title,"Title must be entered.")==false)
 		 {title.focus();return false;} 	 

 		  		 
	if (validateRequired(pass1,"Enter Password field must be filled out")==false)
  {pass1.focus();return false;}
  
  if (validateRequired(pass2,"Confirm Password field must be filled out")==false)
  {pass2.focus();return false;}
   if (validatePasswordMatch2(pass1,pass2) == false){
  	setInputValue(document.forms['newUser'].pass1, '');
  	setInputValue(document.forms['newUser'].pass2, '');
  	pass1.focus();
  	return false;
  	}	
	}	
	var username =getInputValue(document.forms['newUser'].username);

	}
function validatePasswordMatch2(pass1,pass2){
	var pwd1 = getInputValue(document.forms['newUser'].pass1);
	var pwd2 = getInputValue(document.forms['newUser'].pass2);
	
	if(pwd1 == pwd2){return true;}
	else {alert('Passwords Do Not Match.');
		return false;}	
	}




function validateNewPage(thisform){
	with(thisform){	
		
		if (validateRequired(title,"Page Title must be entered.")==false)
 		 {title.focus();return false;}
 		 		
		if (validateRequired(section,"Section must be entered.")==false)
 		 {section.focus();return false;}

	}
}

function validateSpecials(thisform){
	with(thisform){	
		
		if (validateRequired(item,"Item must be entered.")==false)
 		 {item.focus();return false;}


	}
}


/****************************************************************************************************

---------------------------------------------Specials Section Functions----------------------------

*****************************************************************************************************/

function jsSpecialsShowExpired(){
	//alert('Getting Expired Specials');
	new Ajax.Updater('expired', 'includes/ajax_expiredSpecials.php',{});

	}
	
	function jsSpecialsShowDeleted(){
	//alert('Getting Deleted Specials');
	new Ajax.Updater('deleted', 'includes/ajax_deletedSpecials.php',{});
	
	}