/****************************************************************************************
	filename:	global.js
	version:	1.0
	title:		global js scripts
	author:		caspar blattmann
	modified:	june 10 2009
****************************************************************************************/


//	description:	closes a temporary messagebox div
//	arguments:		divID => div id
//					gotoUrl (optional) => url to go to
//					form (optional) => reset form if there is one
//	return value:	none
function closeDivWindow(divID, /*optional*/ gotoUrl, form) {
	var docElem = document.getElementById(divID); // get div to close

	try {
		docElem.style.cursor = "wait"; // set the cursor to a hourglass
		docElem.style.display = "none"
		if (form) {document[form].reset();} // empty form
		if (gotoUrl) {window.location = gotoUrl;}
	} 
	finally {
		docElem.style.cursor = "default"; // set cursor back to default
	}
} // closeDivWindow


//	description:	validates the structure of an email address
//	arguments:		email => email address need to be validated
//	return value:	true: valid email address, false: invalid email address
function verifyEmailAddress(email) {
	return true;
} // verifyEmailAddress


//	description:	process involvment signup
//	arguments:		form => reference to the form the user filled out
//					processUrl => for what does the user sign up
//					message (optional) => optional message to display if there is no 
//					error message provided by HTTP.post
//	return value:	none
function processForm(form, processUrl, /*optional*/ message) {
	// signup verified email address
	var httpUrl = processUrl + "&&rand="+Math.random();

	processHTTPResponse.responseMessage = ((message) ? message : "There was a problem " +
		"with your submission. Please try again or call Susan Doyle at (407) 826-2483.");

	function processHTTPResponse(responseHTML) {
		// there is no error handler supplied; catch error here
		if (responseHTML == null) {
			document.getElementById("g-msgbox").innerHTML = 
				processHTTPResponse.responseMessage;
		} 
		else {
			document.getElementById("g-msgbox").style.display = "block";
			document.getElementById("g-msgbox").innerHTML = responseHTML;
			document.getElementById("g-msgbox").focus();
		} // end if
	} // processHTTPResponse
	
	function errorHandleHTTPResponse(statusID, statusText) {
		alert("Request Status: " + statusID + " -- " + statusText);
	} // errorHandleHTTPResponse
	
	HTTP.post(httpUrl, form, processHTTPResponse, errorHandleHTTPResponse);	
} // end processForm



//	description:	process involvment signup
//	arguments:		email => email to be added to virtual walk email list
//	return value:	none
function processVirtualWalkEmailSignup(email) {
	// signup verified email address
	strURL = "php/involvement-virtualwalksignup.exe.php?email="+email+"&&rand="+Math.random();
	
	function processHTTPResponse(responseText) {
		document.getElementById("virtual-walk-signup-form").innerHTML = responseText;
	}
	
	HTTP.getText(strURL, processHTTPResponse);
} // end processVirtualWalkEmailSignup


//	description:	process involvment signup
//	arguments:		command => type of action that needs to be taken
//					tabName => name of the tab that was clicked
//	return value:	none
function loadInvolvementTabContent(command, tabName) {
	var httpUrl;
	var printPreviewWidth = '650';
	var printPreviewHeight = '600';

	// determine which initiative content needs to be loaded  
	httpUrl = "";
	switch(tabName) {
		// prayer tab selected
		case "tab1_mc":	
			if (command == "loadcontent") {
				httpUrl += "includes/involvement-prayer.inc.php";
			} 
			break;

		// network tab selected
		case "tab2_mc":
			if (command == "loadcontent") {
				httpUrl += "includes/involvement-network.inc.php";
			} 
			break;
	} //switch
	
	// add a random id so the the server does not get the data from its cache
	httpUrl = httpUrl+"?id="+Math.random();
	
	function processHTTPResponse(responseHTML) {
		document.getElementById("involvement-tab-content").innerHTML = responseHTML;
	} // end processHTTPResponse
		
	if (command == "loadcontent") {
		HTTP.getText(httpUrl, processHTTPResponse);
	} // end if
} // end loadInvolvementTabContent




//	description:	process involvment signup
//	arguments:		command => type of action that needs to be taken
//					tabName => name of the tab that was clicked
//	return value:	none
function loadLeadershipTabContent(command, tabName) {
	var httpUrl;
	var printPreviewWidth = '650';
	var printPreviewHeight = '600';

	// determine which initiative content needs to be loaded  
	httpUrl = "";
	switch(tabName) {
		// me tab selected
		case "tab1_mc":	
			if (command == "loadcontent") {
				httpUrl += "includes/leadership-me.inc.php";
			} 
			break;

		// ew tab selected
		case "tab2_mc":
			if (command == "loadcontent") {
				httpUrl += "includes/leadership-ew.inc.php";
			} 
			break;

		// ee tab selected
		case "tab3_mc":
			if (command == "loadcontent") {
				httpUrl += "includes/leadership-ee.inc.php";
			} 
			break;
	} //switch
	
	// add a random id so the the server does not get the data from its cache
	httpUrl = httpUrl+"?id="+Math.random();
	
	function processHTTPResponse(responseHTML) {
		document.getElementById("leadership-tab-content").innerHTML = responseHTML;
	} // end processHTTPResponse
		
	if (command == "loadcontent") {
		HTTP.getText(httpUrl, processHTTPResponse);
	} // end if
} // end loadInvolvementTabContent

function displayPaymentInstructions(userSelection) {
	if (userSelection == 'By Credit Card') {
		document.getElementById("instructions").innerHTML = "<p>Please call Susan Doyle at (407) 826-2483 after registering for this event.</p>";
} else if (userSelection == 'By Check') {
		document.getElementById("instructions").innerHTML = "<p>Send a check made out to Campus Crusade for Christ to: <br \>Susan Doyle<br \>Campus Crusade for Christ  <br \>100 Lake Hart Dr., #4200  <br \>Orlando, FL 32832</p>";
	} // end if
} // displayPaymentInstructions

