//===========Zen Library===============

//==== checkForm function that checks for blank and valid email in a form ====
//pre-condition: Must have an Email field with id='Email' for it to check Email properly
//Can use real world names for ids of other form fields, such as id="First Name"
//HTMLcontent can be used to ignore the HTML flag as an ID
function checkForm(formID)
{
	if(document.getElementById(formID))
	{
		theForm		= document.getElementById(formID);
		numofInputs	= theForm.length-2; //minus the submit button and key
		
		for(i=0;i<numofInputs;i++)
		{
			if(theForm[i].value == "")
			{
			alert("Please specify a value for: " + theForm[i].id);
			theForm[i].focus();
			return false;
			}
			else
			{
				if(theForm[i].id != "HTMLcontent")
				{
				var HTMLtemp = NoHTML(theForm[i].value);

				if(!HTMLtemp)
				{
				alert("< > are invalid characters.");
				theForm[i].focus();
				return false;					
				}
				}
			
			
			if(theForm[i].id == "Email")
			{
				var isEmailTemp = IsEmail(theForm[i].value);
				if(!isEmailTemp)
				{
				alert("Please enter a valid email.");
				theForm[i].focus();
				return false;					
				}		
			}
			
			}	//end else
		} //end for	
		
		document.getElementById('key').value = getURL();
	}
	else
	alert("No Form Specified with that ID.");
}

//==== Email Check function ====

function IsEmail(sText)
{
var whereisAT = sText.indexOf('@');

if(whereisAT == -1)
return false;
   
var whereisDOT = sText.indexOf('.');  

if(whereisDOT == -1)
return false;

//if makes through checks, return true     
return true;
}

//==== HTML Check function ====
//checks to make sure no HTML tags are in the form

function NoHTML(sText)
{
var whereisAT = sText.indexOf('>');

if(whereisAT != -1)
return false;
   
var whereisDOT = sText.indexOf('<');  

if(whereisDOT != -1)
return false;

//if makes through checks, return true     
return true;

}


//==== getURL function ====
//returns the URL in a hidden field to make sure people are not injecting our mail form
//by checking where the form is coming from
//pre-condition: requires a field with an id='key'
function getURL()
{
test = location.href;

test= test.split("/");
str = "";
for(i=0;i<(test.length-1);i++)
{
	if(i == 0)
	str = test[i]+"/";
	else
	str = str + test[i] + "/";
}
return str;
}


//FOR DELETING

function verifyDeleteItem(theItem)
{
for (i=0;i<document.getElementById(theItem).length;i++)
   {
     var current = document.getElementById(theItem).options[i];
		
		if(current.selected == true)
		groupname = document.getElementById(theItem).options[i].text;	
   }
var answer = confirm ("Are you sure you want to delete the item: " + groupname + "?")	

if(answer)
return true;
else
return false;	
}


function verifyApproveItem(theItem)
{
for (i=0;i<document.getElementById(theItem).length;i++)
   {
     var current = document.getElementById(theItem).options[i];
		
		if(current.selected == true)
		groupname = document.getElementById(theItem).options[i].text;	
   }
var answer = confirm ("Are you sure you want to approve the item: " + groupname + "?")	

if(answer)
return true;
else
return false;	
}