//Copyright (c) 1992-2012 PMComplete Pty Ltd.  All rights reserved.//
//All getElementById need to be normalised for other browsers.//
function checkAudioCompat()
{
    var myAudio = document.createElement('audio');

    if (myAudio.canPlayType) {
        // CanPlayType returns maybe, probably, or an empty string.

        if ( "" != myAudio.canPlayType('audio/mpeg')) {
            alert("mp3 supported");
        }

        if ( "" != myAudio.canPlayType('audio/ogg; codecs="vorbis"')) {
            alert("ogg supported");
        }

        if ( "" != myAudio.canPlayType('audio/mp4; codecs="mp4a.40.5"')) {
            alert("aac supported");
        }
    }
    else {
        alert("no audio support");
    }
}
function ClearAll()
{
	for (j=0;j<parent.MainFrame.document.forms[0].elements.length;++j)
	{
		if (parent.MainFrame.document.forms[0].elements[j].type == 'checkbox')
		{
			if (parent.MainFrame.document.forms[0].elements[j].disabled == false)
			{
				parent.MainFrame.document.forms[0].elements[j].checked = false;
			}
		}
	}
}
function ClearColour(elem, culla)
{
	elem.style.color = culla;
	elem.style.textDecoration = 'none';
}
function ClearStatus(elem)
{
	window.status = '';
	var elemstyle = elem.style;
	elemstyle.backgroundColor = 'oldlace';
}
function ClearStatusSpecial(elem, realelem)
{
	window.status = '';
    var elemstyle = elem.style;
	elemstyle.backgroundColor = 'oldlace';
	if (elem.value == "")
	{
		xxx = eval(document.getElementById(realelem));
		xxx.value = "999999";
	}
}
function CollapseAll()
{
	var MaxNumber = 100;
	for (j=1;j<MaxNumber;++j)
	{
		try {
			parent.MainFrame.document.getElementById('TopicSpan' + j).style.display = 'none';
			parent.MainFrame.document.getElementById('ExpandButton' + j).style.display = '';
			parent.MainFrame.document.getElementById('CollapseButton' + j).style.display = 'none';
		}
		catch(e) {
			break
		}
	}
}
function CollapseAllDetails(LastNumber)
{
	var MaxNumber = LastNumber + 1;
	for (j=1;j<MaxNumber;++j)
	{
		parent.document.getElementById('TopicSpan' + j).style.display = 'none';
	}
}
function CopyFieldsValue(elem)
{
//*	var myField = elem + '_DE'; *//
//*	var myField1 = dijit.byId(myField);  *//
//*	var myField2 = dojo.byId(elem);  *//
//*	var myField1V = myField1.getValue();  *//
//*	var myField2V = myField2.value;  *//
//*	myField2V = myField1V; *//
//*	myField2.value = myField2V; *//
//*//*	alert('F2V: ' + myField2.value); *// *//
	dojo.byId(elem).value = dijit.byId(elem + '_DE').getValue();
}
function DetectStuff(cDate, cTime, ScrWidth, ScrHeight)
{
	var today = new Date();
	var timenow = today.getTime();
	var theWidth = getBrowserWidth();
	document.Login.ScrWidth.value=theWidth;
	var theHeight = getBrowserHeight();
	document.Login.ScrHeight.value=theHeight;
}
function DisplayAdvanced()
{
	var b5 = parent.MainFrame.document.getElementById('AdvancedSpan');
	var b6 = parent.MainFrame.document.getElementById('AdvancedButton');
	var b7 = parent.MainFrame.document.getElementById('BasicButton');
	if (b5.style.display == '')
	{
		b5.style.display = 'none';
		b6.style.display = '';
		b7.style.display = 'none';
	}
	else
	{
		b5.style.display = '';
		b6.style.display = 'none';
		b7.style.display = '';
	}
}
function DisplayDay(elem, fldname, USASpell)
{
	dowArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
	var elemvalue;
	if (USASpell = "False")
	{
		var tdate = elem.value;
		var dpos = tdate.indexOf("/", 0);
		var tday = tdate.substring(0, dpos);
		var mpos = tdate.indexOf("/", dpos+1);
		if (mpos == -1)
		{
			mpos = tdate.length;
			var tmonth = tdate.substring(dpos+1);
			var tcurr = new Date();
			var tyear = tcurr.getFullYear();
		}
		else
		{
			var tmonth = tdate.substring(dpos+1, mpos);
			var tyear = tdate.substring(mpos+1, 99);
		}
		elemvalue = new Date(tmonth + "/" + tday + "/" + tyear);
	}
	else
	{
		elemvalue = new Date(elem.value);
	}
	var theday = elemvalue.getDay();
	dayname = ' (' + dowArray[theday] + ')';
	eval('document.Maint.DATENAME_' + fldname + '.value = dayname');
}
function DisplayPrinterDialogue()
{
	window.print();
//*21/9/2011	history.go(-1); *//
}
function DisplayStatus(elem, e)
{
	window.status = e;
    var elemstyle = elem.style;
	elemstyle.backgroundColor = '#E3E5EB';
}
function DisplayTopic(TopicNo)
{
	var b5 = parent.document.getElementById('TopicSpan' + TopicNo);
	if (b5.style.display == '')
	{
		b5.style.display = 'none';
	}
	else
	{
		b5.style.display = '';
	}
}
function DisplayTopicandCollapse(TopicNo)
{
	var b5 = parent.MainFrame.document.getElementById('TopicSpan' + TopicNo);
	var b6 = parent.MainFrame.document.getElementById('ExpandButton' + TopicNo);
	var b7 = parent.MainFrame.document.getElementById('CollapseButton' + TopicNo);
	if (b5.style.display == '')		//If the topic is currently displayed...
	{
		b5.style.display = 'none';	//Hide the topic
		b6.style.display = '';		//Unhide the expand button
		b7.style.display = 'none';	//Hide the collapse button.
	}
	else							//Else, if the topic is currently hidden...
	{
		b5.style.display = '';		//Unhide the topic
		b6.style.display = 'none';	//Hide the expand button
		b7.style.display = '';		//Unhide the collapse button.
	}
}
function DisplayUT(FrameName)
{
	if (FrameName == 'MainFrame')
	{
		var b5 = parent.MainFrame.document.getElementById('UTSpan');
		var b6 = parent.MainFrame.document.getElementById('ExpandButton');
		var b7 = parent.MainFrame.document.getElementById('CollapseButton');
	}
	else
	{
		var b5 = eval(parent.document.getElementById('UTSpan'));
		var b6 = eval(parent.document.getElementById('ExpandButton'));
		var b7 = eval(parent.document.getElementById('CollapseButton'));
	}
	if (b5.style.display == '')
	{
		b5.style.display = 'none';
		b6.style.display = '';		//Unhide the expand button
		b7.style.display = 'none';	//Hide the collapse button.
	}
	else
	{
		b5.style.display = '';
		b6.style.display = 'none';	//Hide the expand button
		b7.style.display = '';		//Unhide the collapse button.
	}
}
function DoNav(theUrl)
{
	document.location.href = theUrl;
}
function DoNavRecList(theUrl, e)
{
	var targ
	if (!e) var e = window.event
	if (e.target) targ = e.target
	else if (e.srcElement) targ = e.srcElement
	if (targ.nodeType == 3) 
   	targ = targ.parentNode
	var tname
	tname=targ.tagName
	if (tname !== "INPUT")
	{
		document.location.href = theUrl;
	}
}
function ExpandAll()
{
	var MaxNumber = 100;
	for (j=1;j<MaxNumber;++j)
	{
		try {
			parent.MainFrame.document.getElementById('TopicSpan' + j).style.display = '';
			parent.MainFrame.document.getElementById('ExpandButton' + j).style.display = 'none';
			parent.MainFrame.document.getElementById('CollapseButton' + j).style.display = '';
		}
		catch(e) {
			break
		}
	}
}
function ExpandAllDetails(LastNumber)
{
	var MaxNumber = LastNumber + 1;
	for (j=1;j<MaxNumber;++j)
	{
		parent.document.getElementById('TopicSpan' + j).style.display = '';
	}
}
function FlipImage(NewURL)
{
	if (window.event.srcElement.tagname = "IMG")
	{
		window.event.srcElement.src = NewURL;
	}
}
function getBrowserHeight()
{
if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight != 0)
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		return document.body.clientHeight;
	}
	return 0;
}
function getBrowserWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}
	return 0;
}
function MinimiseAgent(TheAgent)
{
	var b5 = eval(parent.MainFrame.document.getElementById('AgentDiv' + TheAgent));
	var b6 = eval(parent.MainFrame.document.getElementById('AgentMaxButton' + TheAgent));
	var b7 = eval(parent.MainFrame.document.getElementById('AgentMinButton' + TheAgent));
	if (b5.style.display == 'table')
	{
		b5.style.display = 'none';
		b6.style.display = '';
		b7.style.display = 'none';
	}
	else
	{
		b5.style.display = 'table';
		b6.style.display = 'none';
		b7.style.display = '';
	}
}
function PassBack1(FID,DID,DNAME)
{
	self.close();
	window.opener.TakeBackDialogueForm(FID,DID,DNAME);
	window.opener.focus();
}
function PassBack2(FID,DID,DNAME)
{
	opener.TakeBackDialogueForm(FID,DID,DNAME);
	opener.focus();
	self.close();
}
function PlayClick(PlaySounds)
/*	For all non-text-based links.	*/
{
	if (PlaySounds == 'True')
	{
		document.all.beep.src='gif/ButtonOver.wav';
	}
}
function PlayClickColourRed(PlaySounds, elem)
/*	For all text-based links.		*/
{
	if (PlaySounds == 'True')
	{
		document.all.beep.src='gif/ButtonOver.wav';
	}
	elem.style.color = 'red';
	elem.style.textDecoration = 'underline';
}
function SendButton(elem)
{
	parent.MainFrame.document.forms[0].OKButton.value = 'X';
	xx = eval('parent.MainFrame.document.forms[0].' + elem);
	xx.value = '*';
	for (j=0;j<parent.MainFrame.document.forms[0].elements.length;++j)
	{
		if (parent.MainFrame.document.forms[0].elements[j].id == 'TBBUTTON')
		{
			if (parent.MainFrame.document.forms[0].elements[j].name != xx.name)
			{
				parent.MainFrame.document.forms[0].elements[j].value = 'X';
			}
		}
	}
	SendHerOff();
}
function SendButtonPopUp(elem)
{
	parent.document.forms[0].OKButton.value = 'X';
	xx = eval('parent.document.forms[0].' + elem);
	xx.value = '*';
	for (j=0;j<parent.document.forms[0].elements.length;++j)
	{
		if (parent.document.forms[0].elements[j].id == 'TBBUTTON')
		{
			if (parent.document.forms[0].elements[j].name != xx.name)
			{
				parent.document.forms[0].elements[j].value = 'X';
			}
		}
	}
	SendHerOffPopUp();
}
function SendHerOff()
{
	parent.MainFrame.document.forms[0].submit();
}
function SendHerOffPopUp()
{
	parent.document.forms[0].submit();
}
function SetAll()
{
	for (j=0;j<parent.MainFrame.document.forms[0].elements.length;++j)
	{
		if (parent.MainFrame.document.forms[0].elements[j].type == 'checkbox')
		{
			if (parent.MainFrame.document.forms[0].elements[j].disabled == false)
			{
				parent.MainFrame.document.forms[0].elements[j].checked = true;
			}
		}
	}
}
function ShowPageEMail(FKField,FID)
{
	if (FID == "")
	{
		window.open('DialogueEMailAddresses.asp' + FKField + '', 'Popup', 'toolbar=no,help=no,scrollbars=yes,resizable=yes,location=no,copyhistory=no,directories=no,width=425,height=500,left=5,top=200');
	}
	else
	{
		if (isNaN(eval('document.DialogueForm.' + FID + '.value')))
		{
			window.open('DialogueEMailAddresses.asp' + FKField + '', 'Popup', 'toolbar=no,help=no,scrollbars=yes,resizable=yes,location=no,copyhistory=no,directories=no,width=425,height=500,left=5,top=200');
		}
		else
		{
			window.open('DialogueEMailAddresses.asp' + FKField + eval('document.DialogueForm.' + FID + '.value') + '', 'Popup', 'toolbar=no,help=no,scrollbars=yes,resizable=yes,location=no,copyhistory=no,directories=no,width=425,height=500,left=5,top=200');
		}
	}
}
function ShowPageGeo(FKField, FID)
{
	var newWindow;
	newWindow = window.open('DialogueGeographic.asp' + FKField + '', 'Popup', 'toolbar=no,help=no,scrollbars=yes,resizable=yes,location=no,copyhistory=no,directories=no,width=730,height=287,left=260,top=415');
	newWindow.focus();
}
function ShowPageMaint(FKField,FKID,FID,FKName,FName)
{
	var newWindow;
	var xx;
	var xy;
	var xz;
	xx = eval('document.Maint.' + FKName + '.value');
	xz = FKID;
	if (xz == "")
	{
		newWindow = window.open('DialogueFKey.asp?Full=Y' + FKField + '&FKValue=' + xx + '&FKND=' + FName + '', 'Popup', 'toolbar=no,help=no,scrollbars=yes,resizable=yes,location=no,copyhistory=no,directories=no,width=425,height=500,left=5,top=200');
	}
	else
	{
		xy = eval('document.Maint.' + FID + '.value');
		newWindow = window.open('DialogueFKey.asp?Full=Y' + FKField + xz + xy + '&FKValue=' + xx + '&FKND=' + FName + '', 'Popup', 'toolbar=no,help=no,scrollbars=yes,resizable=yes,location=no,copyhistory=no,directories=no,width=425,height=500,left=5,top=200');
	}
	newWindow.focus();
}
function TakeBackDialogueForm(FID,DID,DNAME)
{
	eval('document.DialogueForm.' + FID + '.value = document.DialogueForm.' + FID + '.value + DID');
}
function form_onsubmit()
{
// Create a random session identifier.
	var Session = new String();
	Session = Math.floor(Math.random() * 0xFFFFFF).toString(16);

// build URL for upload status
	var ProgressUrl = "UploadProgress_Status.asp?Session=" + Session;

// define features for pop-up window
	var Features = new String("");

	Features += "toolbar=no, ";
	Features += "menubar=no, ";
	Features += "status=no, ";
	Features += "resizable=no, ";
	Features += "width=200, ";
	Features += "height=200";

// open the pop-up window
	UploadProgress = window.open(ProgressUrl, "upload", Features);

// append identification of session
	document.upload.action += "?Session=" + Session;

	return true;
}
function window_onunload()
{
// if progress doesn't exist, return
	if(UploadProgress == null){return;}

// if progress doesn't expose closed method
	if(UploadProgress.closed){return}

// close progress window
	UploadProgress.close();
}

