// Environment library

function error_handler(message,url,line){
		alert("Warning:\nAn error has occurred during the operation of DATPresenter.\nThis may be due to a Network related issue, or an internal application issue.\n\nThis error is described as: '"+message+"'\nERROR CODE: "+Date()+"_"+line+"\nIn script: "+url+"\n\nPlease report this error to DATMedia.\nsupport@datmedia.co.uk\n\nPlease close and relaunch DATPresenter if you suspect your network was unavailable.");
	return true;
}

// Global script initialisation
var key					=	'';
var system_speed=	80;
var bandwidth		=	80;
var offset_x		=	5;
var offset_y		=	9;
var w						=	800;
var h						=	920;
var player_open	=	true;

// Set defaults for posted options
var cmd					=	'';
var tstart			=	'';
var sstart			=	'';
var size				=	'';
var type				=	'';
var bw					=	''
var media				=	'';
var live				=	false;
var debug				=	false;
var verbose			=	false;
var pres				=	'';
var single			=	'';
var category		=	'';
var poll				=	0;
var muted 			= false;

getArgs();

if(!verbose){
	window.onerror=error_handler;
}

poll	=	((poll=='0')		||	(poll=='false')	||	(poll==''))?false:true;
size	=	((size=='full')	||	(size=='false')	||	(size==''))?'full':'mini';

var build_finished	=	false;
var vbrunsok				=	false;
var versionCode 		= parseFloat(navigator.appVersion);
var activeX 				= (navigator.appName == "Microsoft Internet Explorer" && versionCode >= 4.0) ? true : false;


var theAgent		= navigator.userAgent.toLowerCase();
var cookiesOk		= navigator.cookieEnabled;
var	isAOL 			= (theAgent.indexOf("aol") != -1) || (theAgent.indexOf("iweng") != -1);
var	isKhtml 		= (theAgent.indexOf("khtml") != -1);
var	isOpera 		= (theAgent.indexOf("opera") != -1);
var	isFirefox		= ((theAgent.indexOf("firefox") != -1)||(theAgent.indexOf("iceweasel") != -1));
var	isGecko 		= !isKhtml && !isOpera && (theAgent.indexOf("gecko/") != -1);
var	isSafari 		= (theAgent.indexOf("safari") != -1);
var	isKonqueror = (theAgent.indexOf("konqueror") != -1);
var	isNetscape 	= !isOpera && ((theAgent.indexOf('mozilla')!=-1) && ((theAgent.indexOf('spoofer')==-1)	&& (theAgent.indexOf('compatible') == -1)));
var	isWebtv 		= (theAgent.indexOf("webtv") != -1);
var	isIE 				= !isWebtv && !isOpera && (theAgent.indexOf("msie") != -1);

// Get platform type
var	osMac 	= (theAgent.indexOf("mac")!=-1);
var	osWin 	= (navigator.platform == "Win32") || (theAgent.indexOf("windows")!=-1) || (theAgent.indexOf("winnt")!=-1) || (theAgent.indexOf("winme")!=-1) || (theAgent.indexOf("win9")!=-1) || (theAgent.indexOf("win16")!=-1) ;
var isXP		=	(theAgent.indexOf("windows nt 5.1")!=-1)?true:false;
var isVista	=	(theAgent.indexOf("windows nt 6.0")!=-1)?true:false;

browserTest();

if(!isFlashMedia && !isWinMedia && !isRealMedia && !isQtMedia){
	alert('No stream player found or detectable!');
}

function preStartUpCheck(){
     if (!document) return false;
     //if (!document.body) return false;
     if (!document.getElementById) return false;
     if (!document.getElementById('store')) return false;
     if (!document.getElementById('store').style) return false;
     if (!document.getElementById('store').innerHTML) return false;
     return true;
   }

function client_interrogator(){
	//getLocalTime();
	//getBrowserProperties();
	//getMachineProperties();
	//getVisualProperties();
}

function network_interrogator(){
}

function detectIE(ClassID,name) { result = false; document.write('<SCR'+'IPT LANGUAGE=VBScript>\n on error resume next\n vbrunsok=1\n result = IsObject(CreateObject("' + ClassID + '"))</SCR'+'IPT>\n'); if (result) return name+','; else return ''; }
function detectNS(ClassID,name) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n; }

function browserTest(){
	if (isIE && osWin){
 		pluginlist = detectIE("Adobe.SVGCtl","SVG Viewer") + detectIE("SWCtl.SWCtl.1","Shockwave Director") + detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") + detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") + detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") + detectIE("PDF.PdfCtrl.5","Acrobat Reader");
 		if(vbrunsok){
 			say('Visual basic found.')
		}else{
			say("Sorry, Internet Explorer requires VBScript to provide your browser with information about your browser plugins!\nThere has been no visual basic found, please install or enable VBSript if you wish to launch this application.");
		}
	}
	if ((isFirefox && osWin) || isOpera || isNetscape || !osWin){
		nse = "";
		for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("image/svg-xml","SVG Viewer") + detectNS("application/x-director","Shockwave Director") + detectNS("application/x-shockwave-flash","Shockwave Flash") + detectNS("audio/x-pn-realaudio-plugin","RealPlayer") + detectNS("video/quicktime","QuickTime") + detectNS("application/x-mplayer2","Windows Media Player") + detectNS("application/pdf","Acrobat Reader");
		say('Found mimetypes '+nse);
	}

	// Add java test result to pluginlist
	pluginlist += navigator.javaEnabled() ? "Java," : "";
	if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);
	cookieMessage	=	(cookiesOk)?'Yes':'No';
	say(pluginlist+"\n"+'in '+theAgent+"\n"+'0n '+navigator.platform+"\n"+'Cookies '+cookieMessage);

	isWinMedia 		=	(pluginlist.indexOf("Windows Media Player")!=-1)?true:false;
	isRealMedia		=	(pluginlist.indexOf("RealPlayer")!=-1)?true:false;
	isQtMedia		 	=	(pluginlist.indexOf("QuickTime")!=-1)?true:false;
	isFlashMedia	=	(pluginlist.indexOf("Flash")!=-1)?true:false;
}

function getArgs(){ //Gather arguments from calling page
	fromparent=location.search.substr(1);
	if (fromparent){
    fromparent=unescape(fromparent);
    pairs=fromparent.split("&");
    for(i=0; i<pairs.length; i++){
      pair=pairs[i].split("=");
			if (pair[0]!='admin'){
      	eval(pair[0]+"=pair[1]");
			}
    }
  }
}

function say(message){
	if(debug){
		if(document.getElementById('txtarea')){
			txt('INFO:',message);
		}else{
			alert(message);
		}
	}
}

function button_ctrl( id,state ){
	// Check button node exists
	if(document.getElementById(id)){
		src_temp	=	document.getElementById(id).src.split('/');
		cc				=	src_temp[src_temp.length-1].split('.');

		// cc[0] = filename without extension eg 'my_big_fat_button'
		cdw				=	cc[0].split('_');
		srcend		=	cdw[cdw.length-1];

		// If the image filename ends in 'button' then add the state to the end of the filename array. eg 'my_big_fat_button_over'
		if(srcend=='button'){
			cdw[cdw.length]		=	state;
		}else{
			// button image's filename array already ends in a state suffix so just change it to the required state
			cdw[cdw.length-1]	=	state;
		}

		// Check before joining the array back together if the required state was the default state.  eg ''.
		flnm			=	(state=='')?cdw.slice(0,cdw.length-1).join('_'):cdw.join('_');

		// Put the dot the path and the extension back
		flnmtemp	=	flnm	+	'.'	+	cc[cc.length-1];
		flnmtempa	=	src_temp.slice(0,src_temp.length-1).join('/');
		ftb				=	flnmtempa	+	'/'	+	flnmtemp;

		// Finally set the new image src
		document.getElementById(id).src=ftb;
 	}
 }  // button_ctrl


 function button_mute( id,state ){
	if(document.getElementById(id)){
 		src_temp				=		document.getElementById(id).src.split('/');
		cc							=		src_temp[src_temp.length-1].split('.');
		cdw							=		cc[0].split('_');
		newstate				=		(state=='out')?'':state;
 		cdw[4]					=		newstate
		bfk							=		(newstate=='')?1:0;
 		fnmutetype			=		(muted)?'muted':'unmuted';
		cdw[3]					=		fnmutetype;
		flnm						=		cdw.slice(0,cdw.length-bfk).join('_');
		flnmtemp			  =		flnm	+	'.'	+	cc[cc.length-1]
		flnmtempa				=		src_temp.slice(0,src_temp.length-1).join('/');
		ftb							=		flnmtempa	+	'/'	+	flnmtemp;
		document.getElementById(id).src	=	ftb;
 	}
 }  // button_mute

function LastMod (){
	the_Date = Date.parse( document.lastModified );
	theDate = new Date( the_Date );
	if ( the_Date != 0 ){
		var stringDate = (theDate.toLocaleDateString())? theDate.toLocaleDateString() : theDate.toString();
	}
}
