<?php
/**
 **	sn_javascript.inc
 ** 	header file
 **
 **	Original Author:	Robby Anderson
 **	Original Date:		March 2001
 **
 **	Modified By:
 **	Modified On:
 **	Modifications:
 **
 ** This shows the standard javascript.
 **/

	// Clear the JavaScript variable
	$thisJS = "";

	// Always add the doOnce javascript
	//

	$thisJS .= "\n\n";
	$thisJS .= '

			var doOnceActions = new Array();
			function doOnce ( thisAction ) {

				if ( typeof(doOnceActions[thisAction]) == "undefined" ) {
					doOnceActions[thisAction] = 1;
					return true;
				} else {
					'.( $showError ? 'alert("Please wait...");' : '' ).'
					return false;
				}
			}';
	$thisJS .= "\n\n";

	// If there is checkSubmit javascript, add it
	if ( $this->getProp("jsCheckSubmit") ) {
		$thisJS .= "\n\n";
		$thisJS .= '

			var didSubmit = false;
			function checkSubmit ( thisForm ) {

				if ( didSubmit ) {
					alert("You have already Submitted this data. Please wait.");
					return false;
				}

				'.$this->getProp("jsCheckSubmitPre").'
				'.$this->getProp("jsCheckSubmit").'
				'.$this->getProp("jsCheckSubmitPost").'

				// If we are here, things went okay - submit the form
				//
				didSubmit = true;
				return true;
			}';
		$thisJS .= "\n\n";
	}

	// If there is custom javascript, add it
	if ( $this->getProp("jsCustom") ) {
		$thisJS .= "\n\n";
		$thisJS .= $this->getProp("jsCustom");
		$thisJS .= "\n\n";
	}

	// If any script functions are listed, run each one of them
	if ( $jsArray = $this->getProp("jsList") ) {
		// Make sure the script functions are in an array
		if ( gettype($jsArray) != "array" ) { $jsArray = preg_split("/ /",$jsArray); }

		// Loop through the jsList var - this should have a list that names
		// one of the javascript functions
		foreach ( $jsArray as $thisScript ) {
			// Execute the command, appending it to the pageJS
			$thisJS .= "\n\n";
			$thisJS .= $thisScript();
			$thisJS .= "\n\n";
		}
	}

	// If the script exists, show it
	if ( $thisJS ) {
	echo <<<EOJS
	<script language="JavaScript">
		{$thisJS}
	</script>

EOJS;
	}
?>

