<!-- Begin

////////////////////////////////////////////////////////////////////////////////
//	confirmSubmit()
//	delete confirmation
////////////////////////////////////////////////////////////////////////////////
function confirmSubmit()
	{
	var agree=confirm("Are you sure you want to delete this item?");
	if (agree)
		return true ;
	else
		return false ;
	}

////////////////////////////////////////////////////////////////////////////////
//	validateStudent()
//	check that password and confirmation are equal
////////////////////////////////////////////////////////////////////////////////
function validateStudent(form)
	{
	var elem = form.elements;
	if(elem['password'].value != elem['confirm'].value)
		{
		alert('Password and Confirmation must match.');
		return false;
		}
	return true;
	}

////////////////////////////////////////////////////////////////////////////////
//	validateRecommendation()
//	
////////////////////////////////////////////////////////////////////////////////
function validateRecommendation(form)
	{
	var elem = form.elements;

	if (varAction == 'Cancel')	// Don't validate if they pressed the Cancel button.
		{
		return true;
		}

//	Check recommend_url
	if (recommend_url_status != "unstarted")	// Don't validate if cursor was never in field.
		{
		if (elem['recommend_url'].value.length > 0)
			{
			if ((recommend_url_status == 'new') || (recommend_url_status == 'sent')) // In the middle of varifying, give it a chance to finish
				{
//				setTimeout("retcode = final_recommend_check();", 250);	//	Pause for 1/4 second
				alert('Checking connection to ' + elem['recommend_url'].value + '.  Click OK to continue');
				}
			if (recommend_url_status == 'bad')
				{
				alert('recommend link does not exist.');
				return false;
				}
			else if (recommend_url_status != 'good')
				{
				alert('Unable to validate recommend url.');
				return false;
				}
			}
		}

	if(elem['name'].value.length < 1)
		{
		alert('Each recommendation must have a name.');
		return false;
		}
	if(elem['existing_category'].value == '*NEW*')
		{
		if(elem['new_category'].value.length < 1)
			{
			alert('Please enter a name for the new category.');
			return false;
			}
		}
	return true;
	}

////////////////////////////////////////////////////////////////////////////////
//	checkNumeric()
//	check that the value entered is numeric
//		call: onBlur="checkNumeric(this,1,100,'','','');"
////////////////////////////////////////////////////////////////////////////////
function checkNumeric(objName,minval, maxval,comma,period,hyphen)
	{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
		{
		numberfield.select();
		numberfield.focus();
		return false;
		}
	else
		{
		return true;
		}
	}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
	{
	// only allow 0-9 to be entered, plus any values passed
	// (can be in any order, and don't have to be comma, period, or hyphen)
	var checkOK = "0123456789" + comma + period + hyphen;
	var checkStr = objName;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	
	for (i = 0;  i < checkStr.value.length;  i++)
		{
		ch = checkStr.value.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
			{
			allValid = false;
			break;
			}
		if (ch != ",")
			allNum += ch;
		}
	if (!allValid)
		{	
		alertsay = "Please enter only these values \""
		alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
		alert(alertsay);
		return (false);
		}
	
	// set the minimum and maximum
	var chkVal = allNum;
	var prsVal = parseInt(allNum);
	if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
		{
		alertsay = "Please enter a value greater than or "
		alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
		alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
		alert(alertsay);
		return (false);
		}
	}

/*******************************************************************************
*	pause_milliseconds(millis)
*		Pause for specified number of milliseconds.
*		Not currently used.
*******************************************************************************/
function pause_milliseconds(millis)
	{
	var date = new Date();
	var curDate = null;
	do
		{
		curDate = new Date();
		}
		while(curDate-date < millis);
	}


////////////////////////////////////////////////////////////////////////////////
//	validateEventPicture()
//		check that urls are reasonable
////////////////////////////////////////////////////////////////////////////////
var varAction = '';

function submitFunction(i)
	{
	if (i == 0) varAction = 'Cancel';
	if (i == 1) varAction = 'Submit';
	}
var recommend_url_status = "unstarted";
var picture_url_status = "unstarted";
var video_url_status = "unstarted";

function validateEventPicture(form)
	{
	var elem = form.elements;

	if (varAction == 'Cancel')	// Don't validate if they pressed the Cancel button.
		{
		return true;
		}

//this is a valid url I can test with: "www.imdb.com/media/rm3596916736/tt0026778"

//	Check picture_url
//alert ('picture_url_status=' + picture_url_status);
	if (picture_url_status != "unstarted")	// Don't validate if cursor was never in field.
		{
		if (elem['picture_url'].value.length > 0)
			{
			if ((picture_url_status == 'new') || (picture_url_status == 'sent')) // In the middle of varifying, give it a chance to finish
				{
//				setTimeout("retcode = final_picture_check();", 250);	//	Pause for 1/4 second
				alert('Checking connection to ' + elem['picture_url'].value + '.  Click OK to continue');
				}
			if (picture_url_status == 'bad')
				{
				alert('Picture link does not exist.');
				return false;
				}
			else if (picture_url_status != 'good')	// It might still be 'new' or 'sent'
				{
				alert('Unable to validate picture url.');
				return false;
				}
			}
		}

//	Check video_url
	if (video_url_status != "unstarted")	// Don't validate if cursor was never in field.
		{
		if (elem['video_url'].value.length > 0)
			{
			if ((video_url_status == 'new') || (video_url_status == 'sent'))	// In the middle of varifying, give it a chance to finish
				{
				alert('Checking connection to ' + elem['video_url'].value + '.  Click OK to continue');
				}
			if (video_url_status == 'bad')
				{
				alert('Video link does not exist.');
				return false;
				}
			else if (video_url_status != 'good')	// It might still be 'new' or 'sent'
				{
				alert('Unable to validate video url.');
				return false;
				}
			}
		}
	return true;
	}


////////////////////////////////////////////////////////////////////////////////
//	validateUrl(str)
//	
//		call: onblur="validateUrl('test');"
//		call: onsubmit="validateUrl('test');"
////////////////////////////////////////////////////////////////////////////////
var xmlHttp;
var xmlHttp_recommend;
var xmlHttp_picture;
var xmlHttp_video;

/*******************************************************************************
*	check_recommend_url
*******************************************************************************/
function check_recommend_url(form)
	{
	str = document.getElementById('recommend_url').value;
//alert ('str=' + str);
	str = normalize_url(str);
	document.getElementById('recommend_url').value = str;
	recommend_url_status = 'new';
	xmlHttp_recommend = checkUrl(str);
	recommend_url_status = 'sent';
	}

/*******************************************************************************
*	check_picture_url
*******************************************************************************/
function check_picture_url(form)
	{
	str = document.getElementById('picture_url').value;
	str = normalize_url(str);
	document.getElementById('picture_url').value = str;
	picture_url_status = 'new';
	xmlHttp_picture = checkUrl(str);
	picture_url_status = 'sent';
	}

/*******************************************************************************
*	check_video_url
*******************************************************************************/
function check_video_url(form)
	{
	str = document.getElementById('video_url').value;
	str = normalize_url(str);
	document.getElementById('video_url').value = str;
	video_url_status = 'new';
	xmlHttp_video = checkUrl(str);
	video_url_status = 'sent';
	}

/*******************************************************************************
*	normalize_url
*******************************************************************************/
function normalize_url(given)
	{
	len = 0;
	if (given.substring(0,7) == 'http://')
		len = 7;
	else if (given.substring(0,8) == 'https://')
		len = 8;
	else if (given.substring(0,6) == 'ftp://')
		len = 6;
	str = given.substring(len);
	return str;
	}

/*******************************************************************************
*	checkUrl
*******************************************************************************/
function checkUrl(str)
	{
	if (str.length == 0)
		{
		return;
		}
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
		{
		alert ("Your browser does not support AJAX!");
		return;
		}
	var url = "validateUrl.php";
	url = url + "?q=" + str;
	url = url + "&sid=" + Math.random();
	if (picture_url_status == 'new')
		{
		xmlHttp.onreadystatechange = stateChanged_picture;
		}
	else if (recommend_url_status == 'new')
		{
		xmlHttp.onreadystatechange = stateChanged_recommend;
		}
	else
		{
		xmlHttp.onreadystatechange = stateChanged_video;
		}
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	return xmlHttp;
	}

/*******************************************************************************
*	stateChanged_picture
*******************************************************************************/
function stateChanged_picture()
	{
	if (xmlHttp_picture.readyState == 4)
		{
		picture_url_status = xmlHttp_picture.responseText;
		}
	}

/*******************************************************************************
*	stateChanged_video
*******************************************************************************/
function stateChanged_video()
	{
	if (xmlHttp_video.readyState == 4)
		{
		video_url_status = xmlHttp_video.responseText;
		}
	}

/*******************************************************************************
*	stateChanged_recommend
*******************************************************************************/
function stateChanged_recommend()
	{
	if (xmlHttp_recommend.readyState == 4)
		{
		recommend_url_status = xmlHttp_recommend.responseText;
		}
	}

/*******************************************************************************
*	GetXmlHttpObject
*******************************************************************************/
function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
		{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	catch (e)
		{
		// Internet Explorer
		try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
		catch (e)
			{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	return xmlHttp;
	}

//  End -->

