﻿/*
	Common functions and variables to go in this file
*/

function expandTheSynopsis(expander, synopsisFull, synopsisSmall)
{
	if (synopsisFull.style.display == 'none')
	{
		synopsisFull.style.display = '';
		synopsisSmall.style.display = 'none';
		expander.innerHTML = "-";
	}
	else
	{
		synopsisFull.style.display = 'none';
		synopsisSmall.style.display = '';
		expander.innerHTML = "+";
	}
}

function expandAllSynopsis(expandAllLink, otherExpandAllLink, linkId, synopsisFull, synopsisShort)
{
	var re_synFull = new RegExp('ctl([\\d]+)_' + synopsisFull);
	var re_synShort = new RegExp('ctl([\\d]+)_' + synopsisShort);
	var re_exp  = new RegExp('ctl([\\d]+)_' + linkId);
	var arr_links  = document.getElementsByTagName('a');
	var arr_labels  = document.getElementsByTagName('span');
	var otherLink = document.getElementById(otherExpandAllLink);
	
	if (arr_links.length == 0) return;
	if (arr_labels.length == 0) return;
	
	var visible = false;
	if (expandAllLink.innerHTML == "Expand All")
	{
		visible = true;
		expandAllLink.innerHTML = "Collapse All";
		otherLink.innerHTML = expandAllLink.innerHTML;
	}
	else
	{
		expandAllLink.innerHTML = "Expand All";
		otherLink.innerHTML = expandAllLink.innerHTML;
	}

	for(i = 0; i < arr_labels.length; i++) 
	{
		elm = arr_labels[i];
		if (re_synFull.test(elm.id))
		{
			//elm is the full synopsis element
			if (visible)
				elm.style.display = '';
			else
				elm.style.display = 'none';
		}

		if (re_synShort.test(elm.id))
		{
			//elm is the shorter synopsis element
			if (visible)
				elm.style.display = 'none';
			else
				elm.style.display = '';
		}
	}
	
	for (i = 0; i < arr_links.length; i++)
	{
		elm = arr_links[i];

		if (re_exp.test(elm.id))
		{
			//elm is the expander link element
			if (visible) elm.innerHTML = "-";
			else elm.innerHTML = "+";
		}
	}
}


function showInfo(elId, vis)
{
	var ele = document.getElementById(elId);
	if (ele != null)
	{
		if (vis) { ele.style.display = 'block'; }
		else { ele.style.display = 'none'; }
	}
}


function vid(src, wid, hei)
{
	//IE Code
	document.write ('<object ID="MediaPlayer" ');
	document.write (' classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6"');
	document.write (' standby="Loading Microsoft Windows Media Player components..."');
	document.write (' type="application/x-oleobject" width="' + wid + '" height="' + hei + '">');
	//document.write ('<param name="FileName" value="' + src + '">');
	document.write ('<param name="url" value="' + src + '">');
	document.write ('<param name="AutoStart" value="true">');
	document.write ('<param name="ShowControls" value="1">');
	document.write ('<param name="uiMode" value="mini">');

	//Netscape code
	document.write ('    <embed type="application/x-mplayer2"');
	document.write ('        pluginspage="http://www.microsoft.com/windows/windowsmedia/"');
	document.write ('        filename="' + src + '"');
	document.write ('        src="' + src + '"');
	document.write ('        Name="MediaPlayer"');
	document.write ('        ShowControls=1');
	document.write ('        ShowDisplay=1');
	document.write ('        ShowStatusBar=1');
	document.write ('        width=' + wid);
	document.write ('        height=' + hei + '>');
	document.write ('    </embed>');

	document.write ('</object>');
}


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

//function ScrollView(elId)
//{
//	var el = document.getElementById(elId);
//	if (el != null)
//	{
//		el.scrollIntoView();
//		el.focus();
//	}
//}
function ScrollView(elId)
{
	ss.smoothScroll(elId);
}

var ss =
{
	INTERVAL: null,
	STEPS: 25,
	MINSTEP: 2,

	smoothScroll: function(eltId)
	{
		var elt = document.getElementById(eltId);
		if (!elt) return true;

		var destx = elt.offsetLeft;
		var desty = elt.offsetTop;
		var thisNode = elt;
		while (thisNode.offsetParent &&
			  (thisNode.offsetParent != document.body))
		{
			thisNode = thisNode.offsetParent;
			destx += thisNode.offsetLeft;
			desty += thisNode.offsetTop;
		}

		clearInterval(ss.INTERVAL);

		cypos = ss.getCurrentYPos();

		ss_stepsize = parseInt((desty - cypos) / ss.STEPS);
		if (desty > cypos)
		{
			if (ss_stepsize < ss.MINSTEP)
				ss_stepsize = ss.MINSTEP;
		}
		else if (desty < cypos)
		{
			if (ss_stepsize > -ss.MINSTEP)
				ss_stepsize = -ss.MINSTEP;
		}
		else
		{
			return true;
		}
		ss.INTERVAL = setInterval('ss.scrollWindow(' + ss_stepsize + ',' + desty + ', "' + eltId + '")', 10);
	},

	scrollWindow: function(scrAmount, dest, eltId)
	{
		wascypos = ss.getCurrentYPos();
		isAbove = (wascypos < dest);
		window.scrollTo(0, wascypos + scrAmount);
		iscypos = ss.getCurrentYPos();
		isAboveNow = (iscypos < dest);
		if ((isAbove != isAboveNow) || (wascypos == iscypos))
		{
			window.scrollTo(0, dest);
			clearInterval(ss.INTERVAL);
			var elt = document.getElementById(eltId);
			if (elt)
				elt.focus();
		}
	},

	getCurrentYPos: function()
	{
		if (document.body && document.body.scrollTop)
			return document.body.scrollTop;
		if (document.documentElement && document.documentElement.scrollTop)
			return document.documentElement.scrollTop;
		if (window.pageYOffset)
			return window.pageYOffset;
		return 0;
	}
}


function enableCCFields(checked, nameId, monthId, yearId, numberId, typeId)
{
	var nameBox = document.getElementById(nameId);
	var monthList = document.getElementById(monthId);
	var yearList = document.getElementById(yearId);
	var numberBox = document.getElementById(numberId);
	var typeList = document.getElementById(typeId);
	
	nameBox.disabled = !checked;
	monthList.disabled = !checked;
	yearList.disabled = !checked;
	numberBox.disabled = !checked;
	typeList.disabled = !checked;
}