
//////////////////////////////////////
// misc.js
//////////////////////////////////////
// Copyright 2005 Christopher Gronbeck
// christopher@susdesign.com
//////////////////////////////////////



	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Create_Email_Footer
	//
	/////////////////////////////////////////////////////////
	
 		function Create_Email_Footer (toolName, toolURL) {
 		
			var footer = "\
This calculation was performed by the " + toolName + " program:\n\
\n\
\thttp://susdesign.com/" + toolURL + "\n\
\n\
The creation and maintenance of this tool is funded entirely by donations from users.  The suggested donation is $10 for personal use and $25 for commercial use.  Donations can be sent to the author via PayPal to his e-mail address, christopher@susdesign.com.  To donate, please visit the PayPal web site and click on 'Send Money':\n\
\n\
\thttps://www.paypal.com\n\
\n\
Thanks for supporting " + toolName + "!";

			return footer;
 		
 		}
 		
 
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Send_Email
	//
	/////////////////////////////////////////////////////////
	
 		function Send_Email (eMailData) {
 		
 			var processingScript = "/php/send_email.php";
 			
 			eMailData = eMailData.replace("+", "##PLUS##");
 			
 			var ajaxRequestString = processingScript + "?eMailData=" + escape (eMailData);

 			AJAX_Make_Request (ajaxRequestString);
 		}
 		
 		
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Send_Email_Feedback
	//
	/////////////////////////////////////////////////////////
	
 		function Send_Email_Feedback (response) {
 		
			if (response == 'success') {

				alert ("The data has been e-mailed to you.\n\n(If it doesn't arrive, please check your spam filter.  You may also want to add 'christopher@susdesign.com' to your list of trusted e-mail senders.)");
			}
			
			else {

				alert ("Sorry...there was an error e-mailing you the data.  Please contact the author at christopher@susdesign.com for assistance.");			
			}
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ChangeClass
	//
	/////////////////////////////////////////////////////////
	
		function ChangeClass (id, newClass) {
		
			if (document.getElementById) { // DOM3 = IE5, NS6
		
				document.getElementById(id).className = newClass;
			}
		
			else {
		
				if (document.layers) { // Netscape 4
				
					document.id.className = newClass;
				}
				
				else { // IE 4
				
					document.all.id.className = newClass;
				}
			}
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  GetDivContent
	//
	/////////////////////////////////////////////////////////
	
		function GetDivContent (id) {
		
			if (document.getElementById) { // DOM3 = IE5, NS6
			
				divReference = document.getElementById(id);
			}
		
			else {
		
				if (document.layers) { // Netscape 4
				
					divReference = document.id;
				}
				
				else { // IE 4
				
					divReference = document.all.id;
				}
			}
			
			return divReference.innerHTML;
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  SetDivContent
	//
	/////////////////////////////////////////////////////////
	
		function SetDivContent (id, text) {
		
			if (document.getElementById) { // DOM3 = IE5, NS6
		
				document.getElementById(id).innerHTML = text;
			}
		
			else {
		
				if (document.layers) { // Netscape 4
				
					document.id.innerHTML = text;
				}
				
				else { // IE 4
				
					document.all.id.innerHTML = text;
				}
			}
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  NoEnter
	//
	/////////////////////////////////////////////////////////
	
		function NoEnter () {
		
			return !(window.event && window.event.keyCode == 13);
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Trim
	//
	/////////////////////////////////////////////////////////
	
 		function Trim (str) {
 		
 			return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
 		}
 

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  Validate_Email_Address
	//
	/////////////////////////////////////////////////////////
	
		function Validate_Email_Address (str) {

			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   return false
			}
	
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			   return false
			}
	
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				return false
			}
	
			 if (str.indexOf(at,(lat+1))!=-1){
				return false
			 }
	
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
				return false
			 }
	
			 if (str.indexOf(dot,(lat+2))==-1){
				return false
			 }
			
			 if (str.indexOf(" ")!=-1){
				return false
			 }
	
			 return true					
		}



	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  HideDiv
	//
	/////////////////////////////////////////////////////////
	
		function HideDiv (id) {
		
			if (document.getElementById) { // DOM3 = IE5, NS6
		
				document.getElementById(id).style.display = 'none';
			}
		
			else {
		
				if (document.layers) { // Netscape 4
				
					document.id.display = 'none';
				}
				
				else { // IE 4
				
					document.all.id.style.display = 'none';
				}
			}
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ShowDiv
	//
	/////////////////////////////////////////////////////////
	
		function ShowDiv (id) {

			if (document.getElementById) { // DOM3 = IE5, NS6
		
				document.getElementById(id).style.display = 'block';
			}
		
			else {
		
				if (document.layers) { // Netscape 4
		
					document.id.display = 'block';
				}
		
				else { // IE 4
		
					document.all.id.style.display = 'block';
				}
			}
		}
		 		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  HideTableRow
	//
	/////////////////////////////////////////////////////////
	
		function HideTableRow (id) {
		
			if (document.getElementById) { // DOM3 = IE5, NS6
		
				document.getElementById(id).style.display = 'none';
			}
		
			else {
		
				if (document.layers) { // Netscape 4
				
					document.id.display = 'none';
				}
				
				else { // IE 4
				
					document.all.id.style.display = 'none';
				}
			}
			
			return true;
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  ShowTableRow
	//
	/////////////////////////////////////////////////////////
	
		function ShowTableRow (id) {

			if (document.getElementById) { // DOM3 = IE5, NS6
		
				document.getElementById(id).style.display = 'table-row';
			}
		
			else {
		
				if (document.layers) { // Netscape 4
		
					document.id.display = 'table-row';
				}
		
				else { // IE 4
		
					document.all.id.style.display = 'table-row';
				}
			}
			
			return true;
		}
		 				 		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  DeleteDiv
	//
	/////////////////////////////////////////////////////////
	
		function DeleteDiv (parentDivID, divToDeleteID) {
		
			var parentDiv = document.getElementById (parentDivID); 
			
			parentDiv.removeChild (divToDeleteID); 
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  AddDiv
	//
	/////////////////////////////////////////////////////////
	
		function AddDiv (parentDivID, newDivID, newDivContents) {
		
			var newDiv = document.createElement ('div'); 
			
			newDiv.id = newDivID; 
		
			newDiv.innerHTML = newDivContents; 
		
			var parentDiv = document.getElementById (parentDivID); 
		
			parentDiv.appendChild (newDiv); 
		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  DeleteArrayElement
	//
	/////////////////////////////////////////////////////////
	
		function DeleteArrayElement (array, item) {
	
			var i = 0;
	
			while (i < array.length) {
	
				if (array[i] == item) {
		
					array.splice (i, 1);
				} 
				
				else {
		
					i++;
				}
			}
	
			return array;
		}	


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  EscapeHTMLCharacters
	//
	/////////////////////////////////////////////////////////
	
 		function EscapeHTMLCharacters (text) {

			// ampersand
			
 			text = text.replace ('&', "&amp;");

			// single quotes
			
 			text = text.replace ("'", "&rsquo;");

			// double quotes
			
 			text = text.replace ('"', "&quote;");

			// left angle bracket
			
 			text = text.replace ('<', "&lt;");

			// right angle bracket
			
 			text = text.replace ('>', "&gt;");

			// return escaped text
			
 			return (text);
 		}
 		
 		
	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  GetSelectMenuValue
	//
	/////////////////////////////////////////////////////////
	
 		function GetSelectMenuValue (fieldID) {
 		
 			var dataField = document.getElementById (fieldID);
 			
 			var dataFieldValue = dataField.options[dataField.selectedIndex].value;
 			
 			return dataFieldValue;
 		}


	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  GetRadioButtonValue
	//
	/////////////////////////////////////////////////////////
	
		function GetRadioButtonValue (element) {
 		
			for (var i = 0; i < element.length; i++) {
			
				if (element[i].checked) {
				
					var radioButtonValue = element[i].value;
				}
			}
			
			return radioButtonValue;
 		}
  		

	/////////////////////////////////////////////////////////
	//
	//  FUNCTION:  MoveRow
	//
	/////////////////////////////////////////////////////////
	
		function MoveRow (element, movement) {

			while (element.parentNode && ('tr' != element.nodeName.toLowerCase ())) {

				element = element.parentNode;
			}

			var table = element.parentNode;
			
			var i = element.rowIndex + movement;
			
			if (i < 0) i += table.rows.length;
			
			if (i == table.rows.length) i = 0;
			
			table.removeChild (element);

			var nRow = table.insertRow (i);

			table.replaceChild (element, nRow);
		}

	
									