/**
 * flash methods
 */
var artist = "Unknown";
var song_ttl = "Unknown";
function setSong(val1,val2)
	{
	artist = val1;
	song_ttl = val2;
	}
function getFlashMovie(movie)
	{
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? parent.frames[1].window[movie] : parent.frames[1].document[movie];
	}
function stopMusic()
	{
	getFlashMovie("juke_player").stopMusic();
	}
function playMusic()
	{
	getFlashMovie("juke_player").playMusic();
	}
function setVolume(val)
	{
	getFlashMovie("juke_player").setVolume(val);
	}

function findObj(n, d)
	{
	var p,i,x;
	if (!d) d=document;
	if ((p=n.indexOf("?"))>0&&parent.frames.length)
		{
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
		}
	if (!(x=d[n])&&d.all) x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for (i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
	if (!x && d.getElementById) x=d.getElementById(n);
	return x;
	}

function imageSwap()
	{
	var i,j=0,x,a=imageSwap.arguments;
	document.sr=new Array;
	for (i=0;i<(a.length-2);i+=3)
		{
		if ((x=findObj(a[i]))!=null)
			{
			document.sr[j++]=x;
			if (!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
			}
		}
	}

function imageRestore()
	{
	var i,x,a=document.sr;
	for (i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

// validation constants
var TEXT = 1;
var CHECKBOX = 2;
var RADIO = 3;

// validation for required fields
function validateForm(params,formname) {
	// true if no items passed
	if (params == null || params.length == 0) return true;
	if (formname == null) formname = "form";
	var form = eval("document."+formname);
	// doesn't validate if it can't find the form
	if (!form) return true;
	var invalidFields = "";
	for (var i = 0; i < params.length; i++) {
		var param = params[i];
		var p_name = param[0];
		var p_type = param[1];
		var p_req = param[2];

		// validate fields by field type
		if (p_type == TEXT && p_req) invalidFields += checkText(p_name);
		else if (p_type == CHECKBOX && p_req) invalidFields += checkCheckbox(p_name);
		else if (p_type == RADIO && p_req) invalidFields += checkRadio(p_name);
	}

	// return error message
	if (invalidFields.length > 0) {
		alert("The following fields are required:\n"+invalidFields);
		return false;
	} else return true;

	// text field validation
	function checkText(n) {
		var field = form[n];
		if (!field) return "";	// valid if field doesn't exist
		if (field.disabled) return "";	// valid if disabled
		if (field.value.length == 0) return "\n - "+field.title;
		return "";
	}
	// checkbox validation
	function checkCheckbox(n) {
		var check = form[n];
		if (!check || !check[0]) return "";		// valid if check doesn't exist
		var hasCheck = false;
		var isDisabled = true;
		for (var j = 0; j < check.length; j++) {
			var chk = check[j];
			if (!chk.disabled) isDisabled = false;
			if (chk.checked) {
				hasCheck = true;
				break;
			}
		}
		if (!isDisabled && !hasCheck) return "\n - "+check[0].title;
		return "";
	}
	// radio button validation
	function checkRadio(n) {
		var radio = form[n];
		if (!radio || !radio[0]) return "";		// valid if radio doesn't exist
		var hasCheck = false;
		var isDisabled = true;
		for (var j = 0; j < radio.length; j++) {
			var rdo = radio[j];
			if (!rdo.disabled) isDisabled = false;
			if (rdo.checked) {
				hasCheck = true;
				break;
			}
		}
		if (!isDisabled && !hasCheck) return "\n - "+radio[0].title;
		return "";
	}
}

/**
 * Email Validation
 */
var invalidFlds = "";
function chkEmail(obj1, divID)
	{
	var field_value = obj1.value.toLowerCase();
	var invalid = isEmailIllegal(field_value);

	if (invalid) { obj1.style.background = '#E6B8AD'; } //'#fecdcd'; }
	else obj1.style.background = '#FDFDAA';

	// style div object
	if (divID != null)
		{
		var div = document.getElementById(divID);
		if (invalid) div.style.visibility = 'visible';
		else div.style.visibility = 'hidden';
		}
	}
function isEmailIllegal(field_value)
	{
	if (field_value.length == 0) return false;
	if (field_value.length < 5) return true;

	// reject illegal chars
	var nmbs = "abcdefghijklmnopqrstuvwxyz0123456789._@-+";
	var letters = field_value.split("");
	for (var n = 0; n < field_value.length; n++)
		{
		if (nmbs.indexOf(letters[n]) < 0) return true;
		}

	// verify 1 and only 1 '@' and that strings on boths sides of it have length > 0
	var parts = field_value.split("@");
	if (parts.length != 2) return true;
	if (parts[0].length == 0 || parts[1].length < 3) return true;

	// verify that domain part has at least one '.' and that all substrings around '.' have a length > 0
	var domainParts = parts[1].split(".");
	if (domainParts.length < 2) return true;
	for (var n = 0; n < domainParts.length; n++)
		{
		if (domainParts[n].length < 1) return true;
		}

	return false;
	}

/**
 * Delete confirmation
 */
function confirmDelete(url)
	{
	//return confirm("Are you sure you want to delete this item"+
	//	((desc != null) ? " ("+desc+")" : "")+"?");
	var confirmed = confirm("Are you sure you want to permanently delete this record?");
	if (url && confirmed) location = url;
	else if (url == null) return confirmed;
	else return;
	}

/******************************************************
 * Window Opener
 *
 * This method opens a new method with the specified
 * size and url.
 *****************************************************/
function openWin(URL, width, height, name)
	{
	var settings = "toolbar=0,location=0,statusbar=0,menubar=0,resizable=1";
	var windowname = (name != null) ? name : 'openwin';
	if (name == null)
		{
		if (URL.indexOf(".aspx") > -1) windowname = URL.substring(0,URL.indexOf(".aspx"));
		while (windowname.indexOf("/") > -1)
			{ windowname = windowname.substring(windowname.indexOf("/")+1); }
		if (windowname.length > 20) windowname = windowname.substring(0,20);
		}

	/** scrollbars */
	settings += ",scrollbars=1";

	/** dimensions for specific pages */
	if (width == null) settings += ",width=450,height=350";
	else settings += ",width="+width+",height="+height;

	window.child = window.open(URL, windowname, settings);
	if (window.opener == null) window.opener = self;
	child.focus();
	}

