
/*  Explanation of URL Variables and their Use !!Important!!  ------------------
    Page will NOT WORK if these guidelines are not followed!

    Below you will find a list of URL variable that can be used
    to control the contact page.

    mode :  controls what is to be displayed on the page
	    
	Values:  email ( shows email form )
		 directory (shows directory spreadsheet)
		 emailSent ( used ONLY by the asp script to show that email was sent)

    reason: controls what option or "reason for contact" is selected in the dropdown
	    and who the email and CC are sent to....very important to get this right!
	    ** Addition values can be added here as needed, as long as the script is updated **
	    
	Values: 
		documentInquiry - used for links for questions on docs
  		graduateInfo - used for links on graduate information
 		undergradInfo - used for links on undergraduate information
  		contactDean	- used for direct email to the dean
  		generalInquiry - used for all links on "Contact Us" or "Request Information"
    
   address: contains the email address of the recipient -- used for direct email links such
	    as those found on the faculty web page.  

	    IMPORTANT!!!!! This property
	    MUST BE USED IN CONJUNCTION with the "fname" and "lname" url variables
	    so that the first and last name of the recipient is displayed 
	
	Values: any pluto email address - will not send email to anyone outside the domain.

   fname:  contains the first name of the email recipient...used in with "address" and "lname"
	   Gets put together with the "lname" and placed in the "reason for contact" list
   
   lname:  contains the last name of the email recipient...used in with "address" and "fname"
	   Gets put together with the "fname" and placed in the "reason for contact" list

*/

function validateForm()
{
	if(document.getElementById('senderEmail').value == "")
	{
		alert(" -- Please Enter an Email Address --");
		return false;
	}
	else
	{
		return true;
	}
}

function getUrlCommand()
{	

	//  Get all URL Parameters from the query string ------------------------------------
	//Create New Query String Object
		var qs = new Querystring();
	
	//pageMode and reason
		var pageMode = qs.get("mode","default");
		var reason = qs.get("reason","default");

	//Address is the email address passed in  
		var address = qs.get("address","default");
		var copy = qs.get("copy","default");	
	
	//fname and lname are the first and last names passed in 
		var fname = qs.get("fname","default");
		var lname = qs.get("lname","default");


//Determine the Page Mode -- email, directory or emailSent  -------------------

//If page mode is directory , show the directory pane

	if(pageMode == "directory")
	{
		showhide("directory");
	}

//If page mode is email and no reason specified, then it is a direct email contact
	else if(pageMode == "email")
	{ 
		//Hide all panels except for the email section
		showhide("emailDiv");
		
		//If No reason passed in , process direct email request
		if(reason == "default")
		{	
			//Get the email address and copy ( if any) that was passed in 
			//and populate the "recipient" and "copy" form elements with them
			if(address != "default")
			{
			   document.getElementById('recipient').value = address;
			}
			if(copy != "default")
			{
			   document.getElementById('copy').value = copy;
			}
			//Show the dropdownEmail list item
			document.getElementById('dropdownEmail').style.display='block';
	
			//disable dropdown
			document.getElementById('subject').disabled=true;
	
			//Set the Dropdown box text with the first and last name of the person they sent in
			document.getElementById('dropdownEmail').innerHTML='Contact ' + fname + ' ' + lname;
			
			//Select the dropdownEMail in the list now that it has been added
			document.getElementById('dropdownEmail').selected = true;
		}
		
		//If a reason has been passed in, compare it against pre-defined values, assign email and copy 
		else
		{
			// Each If statement below, sets the recipient and copy (CC) of the form
			// Based upon what reason value is passed in from the link
			//It also selects the reason in the lists and locks it down
	
			if(reason == "documentInfo")
			{ 
			  document.getElementById('recipient').value = "billie.hoekman@dsu.edu"; 
			  document.getElementById('copy').value = "shelly.rawstern@dsu.edu";
			  document.getElementById('documentInfo').selected=true;

		
			}
			else if(reason == "graduateInfo")
			{
			  document.getElementById('recipient').value = "mark.hawkes@dsu.edu"; 
			  document.getElementById('copy').value = "judy.dittman@dsu.edu";
			  document.getElementById('graduateInfo').selected=true;

			}
			
			else if(reason == "undergradInfo")
			{ 
			  document.getElementById('recipient').value = "judy.dittman@dsu.edu"; 
			  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
			  document.getElementById('undergradInfo').selected=true;
			  
			}
			
			else if(reason == "generalInfo")
			{ 
			  document.getElementById('recipient').value = "billie.hoekman@dsu.edu"; 
			  document.getElementById('copy').value = "shelly.rawstern@dsu.edu";
			  document.getElementById('generalInfo').selected=true;

			}
			
			else if(reason == "SDSUCoopInfo")
			{ 
			  document.getElementById('recipient').value = "don.wiken@dsu.edu"; 
			  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
			  document.getElementById('SDSUCoopInfo').selected=true;
			}
			
			else if(reason == "transferInfo")
			{ 
			  document.getElementById('recipient').value = "don.wiken@dsu.edu"; 
			  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
			  document.getElementById('transferInfo').selected=true;
			}
	
			else if(reason == "contactDean")
			{ 
			  document.getElementById('recipient').value = "judy.dittman@dsu.edu"; 
			  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
			  document.getElementById('contactDean').selected=true;

			}
			
			else if(reason == "directorFieldServices")
			{ 
			  document.getElementById('recipient').value = "crystal.pauli@dsu.edu";
			  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
			  document.getElementById('directorFieldServices').selected=true;
			}
			
			
			else if(reason == "suggestion")
			{ 
			  document.getElementById('recipient').value = "ajbinder@pluto.dsu.edu";
			  document.getElementById('copy').value = "drewsl@pluto.dsu.edu";
			  document.getElementById('suggestion').selected=true;
			}
						
			else //Anything else will go to default email address
			{ 	
			  document.getElementById('recipient').value = "billie.hoekman@dsu.edu"; 
			  document.getElementById('copy').value = "";
			  document.getElementById('generalInfo').selected=true;

			}			
		//set focus to textbox
		document.getElementById('senderName').focus();//disable dropdown
		//document.getElementById('subject').disabled=true;

		}
	}

//If page Mode == emailSent then Email Has been sent, Show Status Message

	else if(pageMode =="emailSent")
	{	
		document.getElementById("emailDiv").style.display = 'none';
		document.getElementById("directory").style.display = 'none';
		document.getElementById("emailSent").style.display = 'block';
	}
	else //Is default
	{	
		showhide("emailDiv");
	}

}// EOF



// This function controls the showing and hiding of the email. emailSend and directory panels
function showhide(layer_ref) 
{ 
	if(document.all) 
	{ 	
		//IS IE 4 or 5 (or 6 beta) 
		if(layer_ref == 'emailDiv')
		{	
			//Show emailDiv div/ Hide Directory Div
			eval( "document.all.emailDiv.style.display = 'block'");
			eval( "document.all.directory.style.display = 'none'");	
			eval( "document.all.emailSent.style.display = 'none'");

		}
		else
		{
			//Show Directory, hide emailDiv
			eval( "document.all.emailDiv.style.display = 'none'");
			eval( "document.all.emailSent.style.display = 'none'");
			eval( "document.all.directory.style.display = 'block'");	
		}
	}
	if (document.layers) 
	{ 
		//IS NETSCAPE 4 or below 
		if(layer_ref == 'emailDiv')
		{	
			//Show emailDiv div/ Hide Directory Div
			document.layers[layer_ref].display = 'block'; 
			document.layers['directory'].display = 'none'; 
			document.layers['emailSent'].display = 'none'; 

		}
		else
		{
			//Show Directory, hide emailDiv
			document.layers[layer_ref].display = 'none';
			document.layers['emailSent'].display = 'none'; 
			document.layers['directory'].display = 'block'; 
		} 
	} 
	if (document.getElementById &&!document.all)
	{ 
		//IS NETSCAPE 4 or below 
		if(layer_ref == 'emailDiv')
		{	
			//Show emailDiv div/ Hide Directory Div
			hza = document.getElementById(layer_ref); 
			hza.style.display = 'block'; 
			document.getElementById('directory').style.display = 'none';
			document.getElementById('emailSent').style.display = 'none';  
		}
		else
		{
			//Hide emailDiv div/ show Directory Div
			document.getElementById('emailDiv').style.display = 'none';
			document.getElementById('emailSent').style.display = 'none';  
 			hza = document.getElementById(layer_ref); 
			hza.style.display = 'block'; 
			
		} 
	} 
} 

function selectedOptionChanged(reason)
{

		if(reason == "documentInfo")
		{ 
		  document.getElementById('recipient').value = "billie.hoekman@dsu.edu"; 
		  document.getElementById('copy').value = "shelly.rawstern@dsu.edu";
	
		}
		else if(reason == "graduateInfo")
		{
		  document.getElementById('recipient').value = "mark.hawkes@dsu.edu"; 
		  document.getElementById('copy').value = "judy.dittman@dsu.edu";
		}
		
		else if(reason == "undergradInfo")
		{ 
		  document.getElementById('recipient').value = "judy.dittman@dsu.edu"; 
		  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
		}
		
		else if(reason == "generalInfo")
		{ 
		  document.getElementById('recipient').value = "billie.hoekman@dsu.edu"; 
		  document.getElementById('copy').value = "shelly.rawstern@dsu.edu";
		}
		
		else if(reason == "SDSUCoopInfo")
		{ 
		  document.getElementById('recipient').value = "don.wiken@dsu.edu"; 
		  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
		}
		
		else if(reason == "transferInfo")
		{ 
		  document.getElementById('recipient').value = "don.wiken@dsu.edu"; 
		  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
		}

		else if(reason == "contactDean")
		{ 
		  document.getElementById('recipient').value = "judy.dittman@dsu.edu"; 
		  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
		}
		
		else if(reason == "directorFieldServices")
		{ 
		  document.getElementById('recipient').value = "crystal.pauli@dsu.edu";
		  document.getElementById('copy').value = "billie.hoekman@dsu.edu";
		}
		
		else if(reason == "suggestion")
		{ 
			 document.getElementById('recipient').value = "ajbinder@pluto.dsu.edu";
			 document.getElementById('copy').value = "drewsl@pluto.dsu.edu";
     	}

		
		else //Anything else will go to default email address
		{ 	
		  document.getElementById('recipient').value = "billie.hoekman@dsu.edu"; 
		  document.getElementById('copy').value = "";
		}

}
