function LogOut()
{
question = "Are you sure you wish to logout?";

if (confirm(question))
{
URL = "logout.php";
window.location.href= URL;
}

}

function isDefined(property)
{
return (typeof property != 'undefined');
}

// Targets
function externalLinks()
{

if (!document.getElementsByTagName)
return;

var anchors = document.getElementsByTagName("a");

for (var i=0; i<anchors.length; i++)
{ 
var anchor = anchors[i];

if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
{
anchor.target = "_blank"; 
}

}

}

function RunFunctions()
{
externalLinks();
}


// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener))
{
window.addEventListener('load', RunFunctions, false);
}

else if (isDefined(window.attachEvent))
{
window.attachEvent('onload', RunFunctions);
}

function CheckUser()
{

var alertsay = ""; 

if ((document.forms.AddUser.userName) && (document.forms.AddUser.userName.value == ""))
{
alertsay += "- Please enter a username\n";
}

if (document.forms.AddUser.userLevel.value == "")
{
alertsay += "- Please select a user level\n";
}

if (document.forms.AddUser.departmentID.value == "")
{
alertsay += "- Please select a department\n";
}

if ((document.forms.AddUser.userPassword.value != "") || (document.forms.AddUser.ProcessType.value == "AddRecord"))
{

if (document.forms.AddUser.userPassword.value == "")
{
alertsay += "- Please enter a Password\n";
}

else if ((document.forms.AddUser.userPassword.value != "") && (document.forms.AddUser.userPassword2.value == ""))
{
alertsay += "- Please enter your Confirm your Password\n";
}

else if (document.forms.AddUser.userPassword.value != document.forms.AddUser.userPassword2.value)
{
alertsay += "- Your Passwords do not match\n";
}

}

if (!alertsay)
{
return true;
}

else
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
}

return false;
}

function CheckDepartment()
{

var alertsay = ""; 

if (document.forms.AddDepartment.department.value == "")
{
alertsay += "- Please enter the departments name\n";
}

if (document.forms.AddDepartment.departmentEmail.value == "")
{
alertsay += "- Please enter the departments email\n";
}

if (!alertsay)
{
return true;
}

else
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
}

return false;
}

function CheckMenu()
{

var alertsay = ""; 

if (document.forms.AddMenu.menuTypeID.value == "")
{
alertsay += "- Please select the main menu type\n";
}

if (document.forms.AddMenu.menuCourse.value == "")
{
alertsay += "- Please enter course name\n";
}

if (!alertsay)
{
return true;
}

else
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
}

return false;
}

function CheckFixture()
{

var alertsay = ""; 

if ((document.forms.editPage.gameYear.value == "") || (document.forms.editPage.gameMonth.value == "") || (document.forms.editPage.gameDay.value == ""))
{
alertsay += "- Please fill in the game date\n";
}

if ((document.forms.editPage.gameHour.value == "") || (document.forms.editPage.gameMinute.value == ""))
{
alertsay += "- Please fill in the game time\n";
}

if (document.forms.editPage.homeTeam.value == "")
{
alertsay += "- Please select the home team\n";
}

if (document.forms.editPage.awayTeam.value == "")
{
alertsay += "- Please select the away team\n";
}

if (document.forms.editPage.awayTeam.value == document.forms.editPage.homeTeam.value)
{
alertsay += "- Please select the two different teams\n";
}

if (!alertsay)
{
return true;
}

else
{
alert("The following error(s) occurred:\n" + alertsay.substring(alertsay,alertsay.length-1) + "\n\nForm will not be processed");
}

return false;
}

function DeleteRecord(ID,title,page,PageA)
{

question = "Are you sure you want to remove " + title + "?";

if (confirm(question))
{
URL = page + ".php?action=delete&ID=" + ID + PageA;
window.location.href= URL;
}

}


function Empty()
{

question ="Are you sure you want to Empty & Delete all data from this table?";

if (confirm(question))
{
URL = "eMail.php?action=Empty";
window.location.href= URL;
}

}


function setselectbyvalue(theSelect, avalue)
{

if (theSelect)
{

for ( var i=0,n=theSelect.options.length; i<n; i++ )
{

if (theSelect.options[i].value == avalue )
{
return( theSelect.selectedIndex = i );
}
}

return(-1);
}


}

function imagePicker(imageID, imageCat) 
{
URL= "imagepicker.php?Selectedimage=" + imageID + "&imageCat=" + imageCat;
window.open(URL, "", "scrollbars=yes,width=760,height=400");
}

function MemOption(Box)
{
ChBox	= Box + "_Ch";
PrBox	= Box + "Price";

if (document.forms.editPage[ChBox].checked == true)
{
document.forms.editPage[PrBox].disabled = false;
document.forms.editPage[Box].value = "1";
}

else
{
document.forms.editPage[PrBox].disabled = true;
document.forms.editPage[Box].value = "0";
}

}