//********************************************************
// Written by:  Mike Van Waas
//		User Driven Applications
//		mvw@udapps.com
//		541-728-3196
//********************************************************
// Last updated: 02 Sept 09
//********************************************************
// Purpose:      - JavaScript library services the CGT family of Audition/Application pages
//
// Included by:  - Every one of the family of those pages
//
// Notes:        - 
//********************************************************

     //=== Validation global vars ===
     var gs_validation_message = "";
     var gs_CumMsg = "";
     
     var defs_DefaultSubmitMsg = 'Please fill out all fields before continuing ';
     var defs_FailedSubmitMsg = '<b> It looks like the application is incomplete. Please review the following items before submitting again: </b>';

     var defs_BadEmail = ',';
     var defs_BadPhone = ',';
     var defs_BadMusic = ',';
     var defs_BadDesc = ',';
     
     var defs_RequiredFieldPrefix = ' - ';
     var defs_RequiredFieldSuffix = '';

	function js_Initialize_ShowRosterTable(psDivID)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - psDivID: Name of "DIV" object to fill in with the table	 							 	
	//********************************************************
	// Purpose:     - Initializes main table on ShowRoster page
	//
	// Called by:   -  U_ShowRoster.php:	<select name="ShowDate" ID="showSysID" onchange="js_Initialize_ShowRosterTable('divRoster')">
	//              -  U_ShowRoster.php:	line after '</body>'
	//
	// Notes:       - Parameter can be dropped/hard-wired;
	//				- The call after </body> is to insure that the "showSysID" object exists and has a value
	//				- Combine with js_rebuild_ShowRosterTable()?
	//********************************************************
    {
	     var XMLHttpRequestObject = false;
         if (window.XMLHttpRequest)
         {
             XMLHttpRequestObject = new XMLHttpRequest();
         }
         else if (window.ActiveXObject)
         {
             XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
         }

        //Only do something if you have an XMLHttpRequestObject object handy
        if(XMLHttpRequestObject)
        {
            //Initialize the DIV object
            var obj = document.getElementById(psDivID);
            var showSysID=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters = "showSysID=" + showSysID;

            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_rosterSupport.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
            }
            // Gopher it!
            XMLHttpRequestObject.send(parameters);
        }
    }
    /*

	function js_rebuild_ShowRosterTable(psDivID)
	//********************************************************
	// Last updated: 26 Aug 2009 by MVW; 06 July 2009
	//********************************************************
	// Parameters:  - psDivID: Name of "DIV" object to fill in with the table 							 	
	//********************************************************
	// Purpose:     - Rebuild main table on ShowRoster page
	//
	// Called by:   -  U_ShowRoster.php:	<input type="button" name="button" value="Update"  onclick="js_rebuild_ShowRosterTable();">
	//
	// Notes:       - Combine with js_Initialize_ShowRosterTable()?
	//				- iRowCount is a convenience/performance boost
	//				- sName and sName2 prefixes must match tthe values of 'defs_IDPrefix' and 'defs_OrderPrefix' values 
	//					in appDefaults.app respectively	
	//				- 26 Aug 2009 Major re-write as earlier version did not scale.	
	//					This version loops through all folks listed and batches them by 10's into
	//					the XMLHttpRequest object. When I get really bored, I'll split the .php files
	//					so that the comic interruptions are sent separately from the rawSysID/Order #s
	//					Comic #s work in this version because cmoic #'s higher than the highest Order #
	//					fall through to the bottom anyway. In a sense then, by cycling through the Order #s
	//					while pushing the comic #s each time, the Oreder #'s "catch up" to the comic numbers
	//					and the final call to the PHP file should sort everything out.
	//********************************************************
	{
        var sFullURL = "U_Libraries/U_rosterSupport2.php";
   
		var s = "";		
        var obj = document.getElementById(psDivID);
		var iRowCount = document.getElementById("rowCountID").value;

        var showSysID=document.getElementById("showSysID").value;
		var sParametersPrefix ="ShowDate=" + encodeURIComponent(showSysID);

        var c1 = document.getElementById("comic1ID").value;
		var c2 = document.getElementById("comic2ID").value;
		var c3 = document.getElementById("comic3ID").value;
		var c4 = document.getElementById("comic4ID").value;
		var c5 = document.getElementById("comic5ID").value;
		sParametersPrefix += "&comic1ID=" + encodeURI(c1) + "&comic2ID=" + encodeURI(c2) + "&comic3ID=" + encodeURI(c3) + "&comic4ID=" + encodeURI(c4) + "&comic5ID=" + encodeURI(c5); 

		var iDec = 0
		var sParameters = "";
        for (i=1; i <= iRowCount; i++)
        {
			iDec += 1;

			// Accumulate ID/order parameters
   			var sName ="txtSysID" + i;
   	        var IDvalue = document.getElementById(sName).value;
   			sParameters += "&" + sName + "=" + encodeURI(IDvalue);
   
   			var sName2 ="txtOrder" + i;
   	        var IDvalue2 = document.getElementById(sName2).value;
   			sParameters += "&" + sName2 + "=" + encodeURI(IDvalue2);

			//Every 10 sets, or at end of list; invoke XMLHttp
			if ((iDec == 10) || (i == iRowCount))
			{
				var sFullParam = sParametersPrefix + sParameters;

        	   	var XMLHttpRequestObject = false;
        	   	
        		if (window.XMLHttpRequest)
        	   	{
        	   		 XMLHttpRequestObject = new XMLHttpRequest();
        	   	}
        	   	else if (window.ActiveXObject)
        	   	{
        	   	    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
           		}

        		XMLHttpRequestObject.open('POST', sFullURL, true);
        		XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        		XMLHttpRequestObject.setRequestHeader("Content-length", sFullParam.length);

                XMLHttpRequestObject.onreadystatechange = function()
                {
                     if (XMLHttpRequestObject.readyState == 4) 
                     {
                        if (XMLHttpRequestObject.status == 200) 
               			{
                           result = XMLHttpRequestObject.responseText;
                           obj.innerHTML = result;            
                       	} 
        	       		else 
            	   		{
                           alert('There was a problem with the request.');
        				}
                     }
                }
				// Define the full parameter string for this round

        		XMLHttpRequestObject.send(sFullParam);

				// re-init
				iDec = 0;    
				sParameters = "";
			}
		}
	}

*/


	function js_rebuild_ShowRosterTable(psDivID)
	//********************************************************
	// Last updated: 26 Aug 2009 by MVW; 06 July 2009
	//********************************************************
	// Parameters:  - psDivID: Name of "DIV" object to fill in with the table 							 	
	//********************************************************
	// Purpose:     - Rebuild main table on ShowRoster page
	//
	// Called by:   -  U_ShowRoster.php:	<input type="button" name="button" value="Update"  onclick="js_rebuild_ShowRosterTable();">
	//
	// Notes:       - Combine with js_Initialize_ShowRosterTable()?
	//				- iRowCount is a convenience/performance boost
	//				- sName and sName2 prefixes must match tthe values of 'defs_IDPrefix' and 'defs_OrderPrefix' values 
	//					in appDefaults.app respectively	
	//				- 26 Aug 2009 Major re-write as earlier version did not scale.	
	//					This version loops through all folks listed and batches them by 10's into
	//					the XMLHttpRequest object. When I get really bored, I'll split the .php files
	//					so that the comic interruptions are sent separately from the rawSysID/Order #s
	//					Comic #s work in this version because cmoic #'s higher than the highest Order #
	//					fall through to the bottom anyway. In a sense then, by cycling through the Order #s
	//					while pushing the comic #s each time, the Oreder #'s "catch up" to the comic numbers
	//					and the final call to the PHP file should sort everything out.
	//********************************************************
	{
        var sFullURL = "U_Libraries/U_rosterSupport2.php";
   
		var s = "";		
        var obj = document.getElementById(psDivID);
		var iRowCount = document.getElementById("rowCountID").value ;

        var showSysID=document.getElementById("showSysID").value;
		var sParametersPrefix ="ShowDate=" + encodeURIComponent(showSysID);

        var c1 = document.getElementById("comic1ID").value;
		var c2 = document.getElementById("comic2ID").value;
		var c3 = document.getElementById("comic3ID").value;
		var c4 = document.getElementById("comic4ID").value;
		var c5 = document.getElementById("comic5ID").value;
		sParametersPrefix += "&comic1ID=" + encodeURI(c1) + "&comic2ID=" + encodeURI(c2) + "&comic3ID=" + encodeURI(c3) + "&comic4ID=" + encodeURI(c4) + "&comic5ID=" + encodeURI(c5); 

		var iDec = 0
		var sParameters = "";
        for (i=1; i <= iRowCount; i++)
        {
			iDec += 1;

			// Accumulate ID/order parameters
   			var sName ="txtSysID" + i;
   	        var IDvalue = document.getElementById(sName).value;
   			sParameters += "&" + sName + "=" + encodeURI(IDvalue);
   
   			var sName2 ="txtOrder" + i;
   	        var IDvalue2 = document.getElementById(sName2).value;
   			sParameters += "&" + sName2 + "=" + encodeURI(IDvalue2);

			//Every 10 sets, or at end of list; invoke XMLHttp
			if ((iDec == 10) || (i == iRowCount))
			{
				var sFullParam = sParametersPrefix + sParameters;

        	   	var XMLHttpRequestObject = false;
        	   	
        		if (window.XMLHttpRequest)
        	   	{
        	   		 XMLHttpRequestObject = new XMLHttpRequest();
        	   	}
        	   	else if (window.ActiveXObject)
        	   	{
        	   	    XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
           		}

        		XMLHttpRequestObject.open('POST', sFullURL, true);
        		XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        		XMLHttpRequestObject.setRequestHeader("Content-length", sFullParam.length);

                XMLHttpRequestObject.onreadystatechange = function()
                {
                     if (XMLHttpRequestObject.readyState == 4) 
                     {
                        if (XMLHttpRequestObject.status == 200) 
               			{
                           result = XMLHttpRequestObject.responseText;
                           obj.innerHTML = result;            
                       	} 
        	       		else 
            	   		{
                           alert('There was a problem with the request.');
        				}
                     }
                }
				// Define the full parameter string for this round

        		XMLHttpRequestObject.send(sFullParam);

				// re-init
				iDec = 0;    
				sParameters = "";
			}
		}
	}



	function js_callPHPFile(psFileNameInLibDir, psDivName)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - psFileNameInLibDir: Name of PHP file within 'U_Libraries/' to invoke 		
	//				- psDivID: ID of DI object to fill with results					 	
	//********************************************************
	// Purpose:     - Wrapper for named PHP file 
	//
	// Called by:   - U_Admin*.php: (various)
	//
	// Notes:       - A generic way of calling a named PHP file (w/no parameters) without duplicating a lot of library code.
	//				- The "U_Libraries/" directory is hard-wired
	//				- Use this to replace other js functions?
	//********************************************************
    {

		// Create XMLRequest object
	     var XMLHttpRequestObject = false;
         if (window.XMLHttpRequest)
         {
             XMLHttpRequestObject = new XMLHttpRequest();
         }
         else if (window.ActiveXObject)
         {
             XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
         }

        //Only do something if you have an XMLHttpRequestObject object handy
        if(XMLHttpRequestObject)
        {
            //Initialize the DIV object
            var obj = document.getElementById(psDivName);

            // Point to the PHP file
            XMLHttpRequestObject.open("get", "U_Libraries/" + psFileNameInLibDir, true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML += XMLHttpRequestObject.responseText;
                }
            }
            // Make it happen
            XMLHttpRequestObject.send("");
        }
    }
    function js_updateShowMgr(divID)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - divID: Name of "DIV" object to fill in with the table	 							 	
	//********************************************************
	// Purpose:     - Initializes top table on ShowMgr form
	//
	// Called by:   -  U_ShowMgr.php:	<select name="ShowDate" ID="showSysID" onchange="js_updateShowMgr('divRoster')">
	//				-  U_ShowMgr.php:	below </body> 
	//
	// Calle:		- U_Libraries/U_rehearsalSupport.php
	//				- U_Libraries/U_rehearsalSupport2.php
	//
	// Notes:       -  Function servicing the rehearsal date drop-down
    // 				-  Starts two separate XMLHttpRequest objects to populate two different DIV objects
	//********************************************************
    {

        var XMLHttpRequestObject = false;
        var XMLHttpRequestObject3 = false;
    
        //Manage flavor of XMLHttpRequestObject3 object; Microsoft is a special case
        if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
            XMLHttpRequestObject3 = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
            XMLHttpRequestObject3 = new ActiveXObject("Microsoft.XMLHTTP");
        }

        //Only do something if you have an XMLHttpRequestObject object handy
        if(XMLHttpRequestObject)
        {

            //Initialize the DIV object
            var obj = document.getElementById("divRoster");
            var showSysID=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters = "showSysID=" + showSysID;

            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_rehearsalSupport.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
            }
            //Initialize the email list DIV object
            var obj3 = document.getElementById("divRoster2");
            var showSysID3=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters3 = "showSysID=" + showSysID3;

            // Point to the PHP file generating the email list
            XMLHttpRequestObject3.open("POST", "U_Libraries/U_rehearsalSupport2.php", true);
            XMLHttpRequestObject3.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject3.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject3.readyState == 4 && XMLHttpRequestObject3.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj3.innerHTML = XMLHttpRequestObject3.responseText;
                }
            }

            // Gopher it
            XMLHttpRequestObject.send(parameters);
            XMLHttpRequestObject3.send(parameters);
        }
    }


	function js_validateApplicationMgr(pfrmAppForm)	
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - form being validate (not in use)
	// Returns:		- none
	//********************************************************
	// Purpose:     - Manages validation of CGTApp form 
	//
	// Called by:   - U_CGTApp.php:
	//
	// Returns:		- Whether form was fully valid
	//
	// Notes:       - If validated, then submits the form (i.e. invokes the <form action=...>
	//********************************************************
	{

		bResults = js_AppPageValid();

		if (bResults == true)
		{
      		document.getElementById("warningID").style.display = 'block';
      		document.getElementById("warningID").innerHTML = defs_DefaultSubmitMsg;

            document.getElementById("warningDetailsID").style.display = 'none';
			document.getElementById("warningDetailsID").innerHTML = '' ;
			document.appForm.submit(); 
			return true;
		}
		else
		{
      		document.getElementById("warningID").style.display = 'block';
			document.getElementById('warningID').style.color = 'red';
      		document.getElementById("warningID").innerHTML = defs_FailedSubmitMsg;

            document.getElementById("warningDetailsID").style.display = 'block';
			document.getElementById("warningDetailsID").innerHTML = gs_CumMsg ;
			return false;
		}
	}

    function js_AppPageValid()
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - form being validate (not in use) 							 	
	// Returns:		- True if each field is valid, else false
	//					(gs_CumMsg: cumulates teh details)	  							 	
	//********************************************************
	// Purpose:     - Runs through validation of each input field 
	//
	// Called by:    - js_validateApplicationMgr
	//
	// Notes:        - 
	//********************************************************
    {	
		gs_CumMsg = "";
        var bAllOK = true;
        var sMsg = ""

 		// Generally going in the order of the fields on the form; unusual syntax for ease of reading
        if (validate_requiredField(document.getElementById("FNameID").value,"First Name")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

        if (validate_requiredField(document.getElementById("LNameID").value,"Last Name")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

		// Need something in phone and email (content is evaluated separately)
        if (validate_requiredField(document.getElementById("EMailID").value,"Email")==false)
        {
			bAllOK = false;   gs_CumMsg += gs_validation_message;  
		}
		else // Something is there. Is it valid?
		{
	        if (validate_EmailAddress(document.getElementById("EMailID").value,"EMail")==false)
    	    	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }
		}

        if (validate_requiredField(document.getElementById("PhoneID").value,"Phone #")==false)
       	{
			bAllOK = false;   gs_CumMsg += gs_validation_message;  
		}
		else // Something is there. Is it valid?
		{ 
			if (validate_PhoneNumber(document.getElementById("PhoneID").value)==false)
       		{ bAllOK = false;	gs_CumMsg += gs_validation_message;	}
		}

		//------------------
        if (validate_requiredField(document.getElementById("ArtDescID").value,"What best describes...")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

        if (validate_requiredField(document.getElementById("DoingWhatID").value,"What will you be doing?")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

		//------------------
        if (validate_MusicButtons()== false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

		//------------------
        if (validate_requiredField(document.getElementById("HobbiesID").value,"What are your hobbies/interests")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

        if (validate_requiredField(document.getElementById("IntroID").value,"Give us a few sentences...")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

		// Drop-downs
        if (validate_requiredField(document.getElementById("OtherOnStageID").value,"Anything else on stage...")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

        if (validate_requiredField(document.getElementById("MicSetupID").value,"How shall we set the mics...")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }

        if (validate_requiredField(document.getElementById("HowHearID").value,"How did you hear...")==false)
        	{bAllOK = false;   gs_CumMsg += gs_validation_message;  }


	    return bAllOK;
    }

	function validate_MusicButtons()
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - None (hard-wired) 							 	
	// Returns:		- True if either is checked, else false
	//********************************************************
	// Purpose:     - Validates the music buttons on the form 
	//
	// Called by:    - js_AppPageValid
	//
	// Notes:        - Radio buttons are a pain. getElementById() is used here for consistency
	//********************************************************
	{
		var bOK;
		bOK = true;
		gs_validation_message = ""

		var radMusicYes = document.getElementById("MusicYesID");
		var radMusicNo =  document.getElementById("MusicNoID");
		if  ((radMusicYes.checked == false) && (radMusicNo.checked == false))
		{
			bOK = false;
			gs_validation_message = "- Will you be using recorded music?";
		}

		return bOK;
	}

    function validate_requiredField(fieldvalue, fieldname)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - fieldvalue: Value of the field you're interested in
	//				- fieldname: Name of field (final destination is gCsCum) 							 	
	// Returns:		- True if something, anything is in the field, else false
	//********************************************************
	// Purpose:     - Tests whether anything at all is in the field
	//
	// Called by:    - js_AppPageValid
	//
	// Notes:        - Doesn't check for white space 
	//********************************************************
    {
        gs_validation_message = "";
        if (fieldvalue==null||fieldvalue=="")
        {
			gs_validation_message = defs_RequiredFieldPrefix + fieldname ;
			gs_validation_message += defs_RequiredFieldSuffix; 
            return false;
        }
        else
        {
            return true;
        }
    }

    function validate_PhoneNumber(fieldvalue)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - Value of the Phone # ield you're interested in 							 	
	// Returns:		- True if field is valid, else false
	//********************************************************
	// Purpose:     - Validates that passed field has a valid phone #  
	//
	// Called by:   - js_validateApplicationMgr
	//
	// Notes:       - Cookie cutter stuff. Doesn't check things like initial # being 0 or 1, etc. etc. 
	//********************************************************
    {

		var bOK;

		bOK = true;

        if (fieldvalue==null||fieldvalue=="")
        {
            gs_validation_message=defs_BadPhone;
            bOK = false;
        }

        var stripped = fieldvalue.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
        if (isNaN(parseInt(stripped)))
        {
            gs_validation_message = defs_BadPhone;
            bOK = false;
        }
        if (!(stripped.length == 10))
        {
            gs_validation_message = defs_BadPhone;
            bOK = false;
        }

		if (bOK == false)
		{
	        gs_validation_message = " - Phone # (10 digits required) ";
		}
		return bOK;
    }

    function validate_DropDownChoice(fieldvalue)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - Value of the drop-down field you're interested in 							 	
	// Returns:		- True if field is valid, else false
	//********************************************************
	// Purpose:     - Validates that passed field (a drop-down) has some value  
	//
	// Called by:   - js_validateApplicationMgr
	//
	// Notes:       - Cookie cutter stuff. 
	//				- In CGT, drop-downs are all initialized to this test always passes
	//********************************************************
    {
        gs_validation_message = "";
        if (fieldvalue==null||fieldvalue=="")
        {
            gs_validation_message=defs_BadDesc;
            return false;
        }
        else
        {
            return true;
        }
    }


    function validate_EmailAddress(fieldvalue)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - Value of the email address field you're interested in		 	
	// Returns:		- True if field is valid, else false
	//********************************************************
	// Purpose:     - Validates passed field for a valid email address 
	//
	// Called by:    - js_validateApplicationMgr
	//
	// Notes:        - Could be one long link of 'or', but this is more sane  
	//********************************************************
    {
        gs_validation_message = "";

        var at="@";
        var dot=".";
        var lat=fieldvalue.indexOf(at);
        var lfieldvalue=fieldvalue.length;
        var ldot=fieldvalue.indexOf(dot);
		var bOK;
		
		// Start an optimist
		bOK = true;
        if (fieldvalue.indexOf(at)==-1)
        {   gs_validation_message = defs_BadEmail + fieldvalue;  bOK = false; }

        if (fieldvalue.indexOf(at)==-1 || fieldvalue.indexOf(at)==0 || fieldvalue.indexOf(at)==lfieldvalue)
        {   gs_validation_message = defs_BadEmail + fieldvalue;  bOK = false; }

        if (fieldvalue.indexOf(dot)==-1 || fieldvalue.indexOf(dot)==0 || fieldvalue.indexOf(dot)==lfieldvalue)
        {   gs_validation_message = defs_BadEmail +  fieldvalue;  bOK = false; }

        if (fieldvalue.indexOf(at,(lat+1))!=-1)
        {   gs_validation_message = defs_BadEmail +  fieldvalue;  bOK = false; }

        if (fieldvalue.substring(lat-1,lat)==dot || fieldvalue.substring(lat+1,lat+2)==dot)
        {   gs_validation_message = defs_BadEmail + fieldvalue;  bOK = false; }

        if (fieldvalue.indexOf(dot,(lat+2))==-1)
        {   gs_validation_message = defs_BadEmail + fieldvalue;  bOK = false; }

        if (fieldvalue.indexOf(" ")!=-1)
        {   gs_validation_message = defs_BadEmail + fieldvalue;  bOK = false; }

		if(bOK == false)
		{
			gs_validation_message = " - Invalid Email address";
		}

        return bOK;
    }

	function js_maxTextLength(fieldToLimit, piMaxLen, divID)
	//********************************************************
	// Last updated: 10 July 2009
	//********************************************************
	// Parameters:  - fieldToLimit: Field (e.g. textarea) whose length you want to limit
	//				- piMaxLen:	Maximum allowable # of characters		 	
	// Returns:		- True if field is valid, else false
	//********************************************************
	// Purpose:     - Limits number of characters which can be entered in the specified field 
	//
	// Called by:    - U_CGTapp.php
	//
	// Notes:        - If yuo're typing things in and you go beyond the fixed limit,
	//					you'll just keep over-writing the last character
	//				 - If you 'cut and paste' something in, the content is just truncated
	//					at the limit set here,
	//				  - Minor quirk when person uses back-space to bring things back into limits
	//						in IE, at least.
	//******************************************************** 	
	{
    	if (fieldToLimit.value.length <= piMaxLen) 
		{
      		document.getElementById(divID).style.display = 'none';
    	} 
		else
		{
	        fieldToLimit.value = fieldToLimit.value.substring(0, piMaxLen);
			document.getElementById(divID).innerHTML = 'Maximum length (' + piMaxLen + ') reached.' ;
      		document.getElementById(divID).style.display = 'inline';
			document.getElementById(divID).style.color = 'red';
		}
	}	

    function js_fillinRehearsalForm(divID)
	//********************************************************
	// Last updated: 10 July 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Updates top and bottom tables on ShowMgr and RehearsalMgr
	//
	// Called by:   - js_ShowMgrMgr()
	//				- js_rehearsalMgr
	//
	// Notes:       -  Starts two separate XMLHttpRequest objects to populate two different DIV objects
	//********************************************************    
	{
        var XMLHttpRequestObject = false;
        var XMLHttpRequestObject3 = false;
    
        //Manage flavor of XMLHttpRequestObject3 object; Microsoft is a special case
        if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
            XMLHttpRequestObject3 = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
            XMLHttpRequestObject3 = new ActiveXObject("Microsoft.XMLHTTP");
        }

        //Only do something if you have an XMLHttpRequestObject object handy
        if(XMLHttpRequestObject)
        {

            //Initialize the "Folks Accepted" DIV object
            var obj = document.getElementById("divRoster");
            var showSysID=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters = "showSysID=" + showSysID;

            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_rehearsalSupport.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
            }

            // === Initialize the email/name list DIV object ====
            var obj3 = document.getElementById("divRoster2");
            var showSysID3=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters3 = "showSysID=" + showSysID3;

            // Point to the PHP file generating the email list
            XMLHttpRequestObject3.open("POST", "U_Libraries/U_rehearsalSupport2.php", true);
            XMLHttpRequestObject3.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject3.onreadystatechange = function()
            {
                // If the request was successful and complete
                if (XMLHttpRequestObject3.readyState == 4 && XMLHttpRequestObject3.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj3.innerHTML = XMLHttpRequestObject3.responseText;
                }
            }

            // Close things out
            XMLHttpRequestObject.send(parameters);
            XMLHttpRequestObject3.send(parameters);
        }
    }


	function js_rehearsalMgr()
	//********************************************************
	// Last updated: 10 July 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Manages processing of the RehearsalMgr form
	//
	// Called by:    - <input type="button" name="button" value="Submit"  onclick="js_rehearsalMgr(this);">		
	//
	// Notes:        -  
	//******************************************************** 	
	{
        var objVIsible = document.getElementById('ID_Invites');
    	var selected = new Array(); 
    	
    	// Build the array of selected IDs
    	for (var i = 0; i < objVIsible.options.length; i++) 
    	{ 
    		if (objVIsible.options[ i ].selected) 
    		{ 	
    			selected.push(objVIsible.options[ i ].value);
    		}
    	}

		if (selected.length == 0)
		{
			alert('Nobody chosen yet');
			return false;
		}

        //Manage flavor of XMLHttpRequestObject3 object; Microsoft is a special case
        var XMLHttpRequestObject = false;
	    if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
		// Update the MySQL database 
        if(XMLHttpRequestObject)
        {
		    var obj = document.getElementById("divOutID");
			var s = document.getElementById("showSysID").value
            var showSysID=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters = "showSysID=" + showSysID;

            var iAction=encodeURIComponent(document.getElementById("ActionToTakeID").value)
            parameters += "&ActionToTake=" + iAction;
			
            var aInvites=encodeURIComponent(selected)
            parameters += "&Invites=" + aInvites;
			
            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_processRehearsalMgr.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
            }
            XMLHttpRequestObject.send(parameters);
		}

		// Update the drop-downs on the form
		js_fillinRehearsalForm('divRoster');
	}

	function js_ShowMgrMgr() 
	//********************************************************
	// Last updated: 27 July 2009 by MVW; 10 July 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Manages processing of the SHowMgr form
	//
	// Called by:    - U_ShowMgr.php: <input type="button" name="button" value="Update"  onclick="js_ShowMgrMgr()">
	//
	// Notes:        -  27 July 2009: Ends with call to js_fillinShowMgrForm() now
	//******************************************************** 	
	{
        var objVIsible = document.getElementById('ID_Invites');
    	var selected = new Array(); 
    	
    	// Build the array of selected IDs
    	for (var i = 0; i < objVIsible.options.length; i++) 
    	{ 
    		if (objVIsible.options[ i ].selected) 
    		{ 	
    			selected.push(objVIsible.options[ i ].value);
    		}
    	}

		if (selected.length == 0)
		{
			alert('Nobody chosen yet');
			return false;
		}
 
        //Manage flavor of XMLHttpRequestObject3 object; Microsoft is a special case
        var XMLHttpRequestObject = false;
	    if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }

		// Update the MySQL database 
        if(XMLHttpRequestObject)
        {
		    var obj = document.getElementById("divOutID");
			var s = document.getElementById("showSysID").value

            var showSysID=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters = "showSysID=" + showSysID;

            var iAction=encodeURIComponent(document.getElementById("ActionToTakeID").value)
            parameters += "&ActionToTake=" + iAction;
			
            var aInvites=encodeURIComponent(selected)
            parameters += "&Invites=" + aInvites;
			
            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_processShowMgr.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
            }
            XMLHttpRequestObject.send(parameters);
		}

		// Update the major table on the form
		js_fillinShowMgrForm();
	}
	
	function js_callPHPFile(psFileNameInLibDir, psDivName)
	//********************************************************
	// Last updated: 06 July 2009
	//********************************************************
	// Parameters:  - psFileNameInLibDir: Name of PHP file within 'U_Libraries/' to invoke 		
	//				- psDivID: ID of DI object to fill with results					 	
	//********************************************************
	// Purpose:     - Wrapper for named PHP file 
	//
	// Called by:   - U_Admin*.php: (various)
	//
	// Notes:       - A generic way of calling a named PHP file (w/no parameters) without duplicating a lot of library code.
	//				- The "U_Libraries/" directory is hard-wired
	//				- Use this to replace other js functions?
	//********************************************************
    {

		// Create XMLRequest object
	     var XMLHttpRequestObject = false;
         if (window.XMLHttpRequest)
         {
             XMLHttpRequestObject = new XMLHttpRequest();
         }
         else if (window.ActiveXObject)
         {
             XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
         }

        //Only do something if you have an XMLHttpRequestObject object handy
        if(XMLHttpRequestObject)
        {
            //Initialize the DIV object
            var obj = document.getElementById(psDivName);

            // Point to the PHP file
            XMLHttpRequestObject.open("get", "U_Libraries/" + psFileNameInLibDir, true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML += XMLHttpRequestObject.responseText;
                }
            }
            // Make it happen
            XMLHttpRequestObject.send("");
        }
    }

    function js_fillinShowMgrForm()
	//********************************************************
	// Last updated: 27 July 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Updates top and bottom tables on ShowMgr and RehearsalMgr
	//
	// Called by:   - js_ShowMgrMgr()
	//
	// Notes:       -  Starts two separate XMLHttpRequest objects to populate two different DIV objects
	//				- See also: js_fillinRehearsalMgr
	//********************************************************    
	{
        var XMLHttpRequestObject = false;
        var XMLHttpRequestObject2 = false;
    
        //Manage flavor of XMLHttpRequestObject2 object; Microsoft is a special case
        if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
            XMLHttpRequestObject2 = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
            XMLHttpRequestObject2 = new ActiveXObject("Microsoft.XMLHTTP");
        }

        //Only do something if you have an XMLHttpRequestObject object handy
        if(XMLHttpRequestObject)
        {

            //Initialize the "Folks Accepted" DIV object
            var obj = document.getElementById("divRoster");
            var showSysID=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters = "showSysID=" + showSysID;

            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_showSupport.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj.innerHTML = XMLHttpRequestObject.responseText;
                }
            }

            // === Initialize the email/name list DIV object ====
            var obj3 = document.getElementById("divRoster2");
            var showSysID3=encodeURIComponent(document.getElementById("showSysID").value)
            var parameters3 = "showSysID=" + showSysID3;

            // Point to the PHP file generating the email list
            XMLHttpRequestObject2.open("POST", "U_Libraries/U_showSupport2.php", true);
            XMLHttpRequestObject2.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject2.onreadystatechange = function()
            {
                // If the request was successful and complete
                if (XMLHttpRequestObject2.readyState == 4 && XMLHttpRequestObject2.status == 200)
                {
                    //Fill in the DIV object wit whatever the PHP file sends back
                    obj3.innerHTML = XMLHttpRequestObject2.responseText;
                }
            }

            // Close things out
            XMLHttpRequestObject.send(parameters);
            XMLHttpRequestObject2.send(parameters);
        }
	}


	function js_launchCustom()
	//********************************************************
	// Last updated: 17 Aug 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Luanches custom email page
	//
	// Called by:   - "Custom email" button		
	//
	// Notes:       -  
	//******************************************************** 	
	{
        var objVIsible = document.getElementById('ID_Invites');
    	var selected = new Array(); 

   	for (var i = 0; i < objVIsible.options.length; i++) 
    	{ 
    		if (objVIsible.options[ i ].selected) 
    		{ 	
    			selected.push(objVIsible.options[ i ].value);
    		}
    	}

		if (selected.length == 0)
		{
			alert('Nobody chosen yet');
			return false;
		}
		else
		{
			var $sURL = "http://www.funnydinner.com/U_CustomEmail2.php?sOrigin=CGT&sPage=Rehearsal&iaRawID=" + selected;
			window.open($sURL,"CustomEmail","width=750,height=750,status=yes,menubar=yes");
		}
 	}

	function js_reschedMgr()
	//********************************************************
	// Last updated: 14 Aug 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Manages processing of the RehearsalMgr form
	//
	// Called by:    - <input type="button" name="button" value="Submit"  onclick="js_rehearsalMgr(this);">		
	//
	// Notes:        -  lstReschedID
	//******************************************************** 	
	{
        var objVIsible = document.getElementById('ID_Invites');
    	var selected = new Array(); 
    	
    	// Build the array of selected IDs
    	for (var i = 0; i < objVIsible.options.length; i++) 
    	{ 
    		if (objVIsible.options[ i ].selected) 
    		{ 	
    			selected.push(objVIsible.options[ i ].value);
    		}
    	}

		if (selected.length == 0)
		{
			alert('Nobody chosen yet');
			return false;
		}

        //Manage flavor of XMLHttpRequestObject3 object; Microsoft is a special case
        var XMLHttpRequestObject = false;
	    if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
		// Update the MySQL database 
        if(XMLHttpRequestObject)
        {
		    var obj = document.getElementById("divDummyID");
            var parameters = "Invites=" + encodeURIComponent(selected)
            parameters += "&newShowSysID=" + document.getElementById("lstReschedID").value;
			
            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_processRehearsalResched.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            // When you hear anything back, gopher it
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
					document.getElementById("divOutID").innerHTML = XMLHttpRequestObject.responseText;
                    //Rebuild form
                    js_fillinRehearsalForm('divRoster');
                }
            }
            XMLHttpRequestObject.send(parameters);
		}

		// Update the drop-downs on the form
		js_fillinRehearsalForm('divRoster');
	}


	function js_deleteNewAppMgr()
	//********************************************************
	// Last updated: 30 Aug 2009 by MVW: 27 Aug 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Responds to 'Delete' button on NewApplication Manager
	//
	// Called by:   -    <input type="button" name="btnDelete" value="Delete them!"  onclick="js_deleteNewAppMgr(this);">
	//
	// Notes:       - Note this is a "<Form" based form, and doesn't use JavaScript to build/re-build itself.
	//					Thus I'm doing a simple '.reload' for a screen refresh  
	//				- 30 Aug: Re-write w/parameter
	//******************************************************** 	
	{
		js_deleteCGTRecs("NewApp");
	}

	function js_deleteRecsRehearsalMgr()
	//********************************************************
	// Last updated: 30 Aug 2009 by MVW: 26 Aug 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Responds to 'Delete' button on RehearsalMgr
	//
	// Called by:   - <input type="button" name="btnDelete" value="Delete them!"  onclick="js_deleteRecs(this);">		
	//
	// Notes:       - Delete records, rebuild form  
	//				- 30 Aug: Re-write w/parameter
	//******************************************************** 	
	{

		js_deleteCGTRecs("Rehearsal");
		//js_fillinRehearsalForm('divRoster');
	}

	function js_deleteRecsShowMgr()
	//********************************************************
	// Last updated: 24 Aug 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Responds to 'Delete' button on RehearsalMgr
	//
	// Called by:    - <input type="button" name="btnDelete" value="Delete them!"  onclick="js_deleteRecs(this);">		
	//
	// Notes:        - Delete records, rebuild form  
	//******************************************************** 	
	{
		js_deleteCGTRecs("ShowMgr");
		//js_fillinShowMgrForm();
	}

	function js_deleteCGTRecs(psSource)
	//********************************************************
	// Last updated: 30 Aug 2009 by MVW: 10 Aug 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Deletes the chosen employee/application
	//
	// Called by:    - 		
	//
	// Notes:        -  30 AUg 2009: Re-write to validate password, not just confirmation click.
	//						Parameter also added to unify processing 
	//******************************************************** 	
	{
		//Bail if no password
		var objPWD = document.getElementById('deletePWDID');
		if (objPWD.value ==null||objPWD.value =="")
		{
			alert("No 'Password for deletions' has been supplied");
			return false;
		}

        var objNames = document.getElementById('ID_Invites');
    	var selected = new Array(); 
    	// Build the array of selected IDs
    	for (var i = 0; i < objNames.options.length; i++) 
    	{ 			
    		if (objNames.options[ i ].selected) 
    		{ 	
    			selected.push(objNames.options[ i ].value);
    		}
    	}

		// Bail if nobody chosen    	
		if (selected.length == 0)
		{
			alert('Nobody chosen yet');
			return false;
		}

        //Manage flavor of XMLHttpRequestObject_Delete object; Microsoft is a special case
        var XMLHttpRequestObject_Delete = false;
	    if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject_Delete = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject_Delete = new ActiveXObject("Microsoft.XMLHTTP");
        }

        var XMLHttpRequestObject_Validate = false;
	    if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject_Validate = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject_Validate = new ActiveXObject("Microsoft.XMLHTTP");
        }

        if(XMLHttpRequestObject_Validate)
        {
		    var sPWD =encodeURIComponent(objPWD.value)
            var paramPWD = "&PWD=" + sPWD;
            // Point to the PHP file
            XMLHttpRequestObject_Validate.open("POST", "U_Libraries/U_ValidatePWD.php", true);
            XMLHttpRequestObject_Validate.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

            XMLHttpRequestObject_Validate.onreadystatechange = function()
            {
                // If the request was successful, refresh the main tables 
                if (XMLHttpRequestObject_Validate.readyState == 4 && XMLHttpRequestObject_Validate.status == 200)
                {
                    var sResponse = XMLHttpRequestObject_Validate.responseText;
                    if (sResponse == "Gopherit")
                    {
                		// Gopher the deletions 
                        if(XMLHttpRequestObject_Delete)
                        {
                            var aInvites=encodeURIComponent(selected);
                            var parameters = "&Invites=" + aInvites;
                			
                            // Point to the PHP file
                            XMLHttpRequestObject_Delete.open("POST", "U_Libraries/U_processCGTDeletes.php", true);
                            // Point to the PHP file
                            XMLHttpRequestObject_Delete.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
                            XMLHttpRequestObject_Delete.onreadystatechange = function()
                            {
                                // If the request was successful, refresh the main tables 
                                if (XMLHttpRequestObject_Delete.readyState == 4 && XMLHttpRequestObject_Delete.status == 200)
                                {
                                   	switch(psSource)
									{

										case "ShowMgr":
											js_fillinShowMgrForm();
											break;

										case "Rehearsal":
											js_fillinRehearsalForm('divRoster');
											break;

										case "NewApp":
                                   			location.reload(true);
											break;

										default:
											alert("Unknown");
											break;
									}
                                }
			                    document.getElementByID('divVersion').innerHTML = XMLHttpRequestObject_Delete.responseText;
                            }
                            XMLHttpRequestObject_Delete.send(parameters);
                		}
                    }
                    else
                    {
                        alert("Invalid password. No deletions done");
                        return false;
                    }
                }
            }
            XMLHttpRequestObject_Validate.send(paramPWD);
		}

	}

	function js_deleteCGTDateSelected(piIndex)
	//********************************************************
	// Last updated: 01 Sept 2009
	//********************************************************
	// Parameters:  - piIndex: Index of row within table  	 							 	
	//********************************************************
	// Purpose:     - Deletes user-chosen row, upon confirmation
	//
	// Called by:   -
	//
	// Notes:       - 
	//********************************************************
	{
		var table = document.getElementById('mainTableID');
		var row = table.rows[piIndex];
		var iSysID = row.cells[0].firstChild.nodeValue;

		// Final reality check
		var confirmDelete =confirm("Do you really want to delete this set of dates? If you click '<OK>' it will disappear forever, with no way to recover the data later.")
		if (!confirmDelete)
		{
			return false;
		}

        //Manage flavor of XMLHttpRequestObject3 object; Microsoft is a special case
        var XMLHttpRequestObject = false;
	    if (window.XMLHttpRequest)
        {
            XMLHttpRequestObject = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        }
		// Update the MySQL database
        if(XMLHttpRequestObject)
        {
            var intDateSysID = encodeURIComponent(iSysID);
            var parameters = "showSysID=" + intDateSysID;
			
            // Point to the PHP file
            XMLHttpRequestObject.open("POST", "U_Libraries/U_deleteShowSchedule.php", true);
            XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
            XMLHttpRequestObject.onreadystatechange = function()
            {
                /// If the request was successful and complete
                if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
                {
                    location.reload(true);
						
                }
            }
            XMLHttpRequestObject.send(parameters);
		}
	}

	function js_editCGTDateSelected(piIndex)
	//********************************************************
	// Last updated: 01 Sept 2009
	//********************************************************
	// Parameters:  - piIndex: Index of row within table  	 							 	
	//********************************************************
	// Purpose:     - Reveals 'edit' Div, moves chosen data into editable fields in revealed 'div' 
	//
	// Called by:   - U_CGTDates.php: "Edit" button on top table
	//
	// Notes:       - 
	//********************************************************
	{
    	var table = document.getElementById('mainTableID');
    	var row = table.rows[piIndex];
    	document.getElementById("divEditID").style.visibility = "visible";
    	var iSysID = row.cells[0].firstChild.nodeValue;
    	var cell1 = row.cells[1].firstChild.nodeValue;
    	var cell2 = row.cells[2].firstChild.nodeValue;
    	var cell3 = row.cells[3].firstChild.nodeValue;
    	var cell4 = row.cells[4].firstChild.nodeValue;
    	var cell5 = row.cells[5].firstChild.nodeValue;
    
    
    	document.getElementById("techEditStartTimeID").value = cell2;
    	document.getElementById("techEditEndTimeID").value = cell3;
    	document.getElementById("showEditStartTimeID").value = cell5;
    	document.getElementById("iChosenSysID").value = iSysID;
    
        var iDateSysID = encodeURIComponent(iSysID);
    	var parameters = "iDateSysID=" + iDateSysID;
    		parameters +=  "&sOrigin=" + encodeURIComponent("CGT");
        	parameters +=  "&sCalName=" + encodeURIComponent("ShowDateCal");
    
    		// Create XMLRequest object
    	     var XMLHttpRequestObject = false;
             if (window.XMLHttpRequest)
             {
                 XMLHttpRequestObject = new XMLHttpRequest();
             }
             else if (window.ActiveXObject)
             {
                 XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
             }
    
    	//Build calendar object
        XMLHttpRequestObject.open("POST", "U_Libraries/U_makeCal.php", true);
        XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
        XMLHttpRequestObject.onreadystatechange = function()
        {
            /// If the request was successful and complete
            if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
            {
    			document.getElementById("divShowID").innerHTML = XMLHttpRequestObject.responseText;
    			js_buildCGTTechDate(iDateSysID);
            }
        }
        XMLHttpRequestObject.send(parameters);
    }

	function js_buildCGTTechDate(piSysID)
	//********************************************************
	// Last updated: 01 Sept 2009
	//********************************************************
	// Parameters:  - piSysID: SysID of row in database whose tech date you want  	 							 	
	//********************************************************
	// Purpose:     - Builds tech date calendar in edit area 
	//
	// Called by:   - js_editCGTDateSelected
	//
	// Notes:       - 
	//********************************************************
	{

        var intDateSysID = encodeURIComponent(piSysID);
    	var parameters = "iDateSysID=" + piSysID;
    		parameters +=  "&sOrigin=" + encodeURIComponent("CGT");
        	parameters +=  "&sCalName=" + encodeURIComponent("TechDateCal");
    		parameters +=  "&sDateColName=" + encodeURIComponent("TechDateQ");

		// Create XMLRequest object
	     var XMLHttpRequestObject = false;
         if (window.XMLHttpRequest)
         {
             XMLHttpRequestObject = new XMLHttpRequest();
         }
         else if (window.ActiveXObject)
         {
             XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
         }

    	//Build calendar object
        XMLHttpRequestObject.open("POST", "U_Libraries/U_makeCal.php", true);
        XMLHttpRequestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
        XMLHttpRequestObject.onreadystatechange = function()
        {
            /// If the request was successful and complete
            if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
            {
    			document.getElementById("divTechID").innerHTML = XMLHttpRequestObject.responseText;
            }
        }
        XMLHttpRequestObject.send(parameters);
    }
	
	function js_editCGTApp()
	//********************************************************
	// Last updated: 02 Sept 2009
	//********************************************************
	// Parameters:  - None		 	
	// Returns:		- Nothing
	//********************************************************
	// Purpose:     - Opens up edit for application data
	//
	// Called by:    - U_RehearsalMgr.php	
	//
	// Notes:        -  
	//******************************************************** 	
	{
		var objVisible = document.getElementById('ID_Invites');
    	var selected = new Array(); 

   		for (var i = 0; i < objVisible.options.length; i++) 
    	{ 
    		if (objVisible.options[ i ].selected) 
    		{ 	
    			selected.push(objVisible.options[ i ].value);
    		}
    	}

		// Bail if nobody chosen    	
		if (selected.length == 0)
		{
			alert('Nobody chosen yet');
			return false;
		}

		if (selected.length > 1)
		{
			alert('Can only edit 1 application at a time.');
			return false;
		}            

		var $i = selected[0];
		var $sURL = "http://www.funnydinner.com/U_EditCGTApp.php?rawSysID=" + $i;
		window.location = $sURL;
	}

