//v2.0
//Copyright 2009 PSU Software Ltd, All rights reserved.
//Agree to Privacy Policy
function agreedToPrivacyPolicy(chk, btn) {
	if (document.getElementsById(chk).checked){
		document.getElementsById(btn).enabled=true;
	}
}
// Admin Loading Screen function
function waitPreloadPage() { //DOM
	if (document.getElementById){
		var loadingScreen = document.getElementById('loadingScreen');
		if(loadingScreen) {
			loadingScreen.style.visibility='hidden';}
	}else{
		if (document.layers){ //NS4
			if(document.loadingScreen){
				document.loadingScreen.visibility = 'hidden';}
		}
		else { //IE4
			if(document.all.loadingScreen){
				document.all.loadingScreen.style.visibility = 'hidden';	}
		}
	}
}
// toggle Admin Loading Screen
var ValidateOnsubmit;
function showPreloadPage() { 
	//alert(ValidateOnsubmit);
	//alert(result);
	var result = ValidateOnsubmit == null ? true : ValidateOnsubmit();
	if (result) {
		if (document.getElementById){
			var loadingScreen = document.getElementById('loadingScreen');
			if(loadingScreen) {
				loadingScreen.style.visibility='visible';}
		}else{
			if (document.layers){ //NS4
				if(document.loadingScreen){
					document.loadingScreen.visibility = 'visible';}
			}
			else { //IE4
				if(document.all.loadingScreen){
					document.all.loadingScreen.style.visibility = 'visible';	}
			}
		}
	}	
	return result;
}
// Hide Admin Loading Screen
function hidePreloadPage() {
	if (document.getElementById){
		var loadingScreen = document.getElementById('loadingScreen');
		if(loadingScreen) {
			loadingScreen.style.visibility = 'hidden';captureSubmitEvent();}
	}else{
		if (document.layers){ //NS4
			if(document.loadingScreen){
				document.loadingScreen.visibility = 'hidden';captureSubmitEvent();}
		}
		else { //IE4
			if(document.all.loadingScreen){
				document.all.loadingScreen.style.visibility = 'hidden';captureSubmitEvent();}
		}
	}
}
window.onload = hidePreloadPage;

function captureSubmitEvent() {
	if(window.captureEvents) {
		window.captureEvents(Event.SUBMIT); 
		ValidateOnsubmit= window.onsubmit;
		window.onsubmit = showPreloadPage; 
	}else{
		ValidateOnsubmit= Form1.onsubmit;
		Form1.onsubmit = showPreloadPage; 
	}
}

//Common function
function getById(ElementId){
	return document.getElementById(ElementId);
}	
// Common Window function
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; 
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
    return oWindow;
}
// Open Edit Dialogs
function OpenEditDialog(url) {
    var oManager = GetRadWindowManager();
	var oWnd = oManager.Open(null, "Edit");
	oWnd.SetTitle("Loading...");
    oWnd.SetUrl(url);
    oWnd.Show();
} 
// Fires when shared File Manager closes
function OnFileManagerClose(oWnd) { 
	oWnd.SetUrl("/Admin/Loading.htm");
} 
// Fires when shared File Manager opens
function OnFileManagerShow(oWnd) { 
	oWnd.SetUrl("/Shared/FileManager/");
} 
// Fires when shared RCE closes
function OnEditorClose(oWnd) { 
	oWnd.SetUrl("/Admin/Loading.htm");
} 
// Fires when shared RCE opens
function OnEditorShow(oWnd) { 
	oWnd.SetUrl("/Admin/Loading.htm");
}
//open edit dialogs
function OpenWnd(WndName, ClientCallBackFn) {
    var oManager = GetRadWindowManager();
	var oWnd = oManager.Open(null, WndName);
	oWnd.ClientCallBackFunction = ClientCallBackFn;
	return oWnd;
}
//get layout window and set colour
function ReturnColourToLayout(returnValue) {
	var windowLayouts = GetRadWindowManager().GetWindowByName("Layouts").GetContentFrame().contentWindow;
	windowLayouts.SetCanvasColour(returnValue);
}
//Open File Manager function
function OpenFileManager() {
    var oManager = GetRadWindowManager();
    var oWnd = oManager.Open(null, "Files");
    oWnd.SetTitle("Loading...");
    oWnd.Show();
}
function OpenFileManagerNoReturnFile() {
    var oManager = GetRadWindowManager();
    var oWnd = oManager.Open(null, "Files");
    oWnd.SetTitle("Loading...");
    oWnd.SetUrl("/Shared/FileManager/?ReturnFile=False");
    oWnd.Show();
}
// QueryString 
function QueryString(variable) {
	var query = window.location.search.substring(1);
	query = query.toLowerCase();
	variable = variable.toLowerCase();
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
		return pair[1];
		}
	} 
}
//popup image
//change to slick layer animation
var oImg = new Image();
function popupImage(f) {
	
	if (f != null) {
	
		if (f.indexOf(".gif") != -1 ||  
			f.indexOf(".jpg") != -1 || 
			f.indexOf(".bmp") != -1 || 
			f.indexOf(".png") != -1 ||
			f.indexOf(".ico") != -1 ||
			f.indexOf(".jpeg") != -1) {

				oImg.onLoad = pImg1();
				oImg.src = f;	

			} else {
				alert("Sorry, but currently you cannot view media of this type.");
			}
	}
	//return false;
}
function pImg1()
{
	if (!oImg.complete) {
		setTimeout("500,pImg1()");
	}
	else
	{
		setTimeout("500,pImg()");
	}
}
function pImg()
{
try {
	var defaultXsize = (oImg.width + 50);
	var defaultYsize = (oImg.height + 125);
	window.showModalDialog("/Engines/Standard/popupImage.htm", oImg.src, "status:yes; center:yes; help:no; minimize:no; maximize:no; scroll:no; border:thin; statusbar:yes; dialogWidth:" + defaultXsize +"px; dialogHeight:" + defaultYsize + "px");					
	return false;
} catch(e) {alert('Popup blocker detected, please disable your popup blocker to allow the website to function correctly.'); }
}
// pop up video
function popupVideo(f) {
	if (f != null) {
	
		f=f.toLowerCase();
	
		if (f.indexOf(".wmv") != -1 ||  
			f.indexOf(".avi") != -1 || 
			f.indexOf(".mpg") != -1 || 
			f.indexOf(".asf") != -1 || 
			f.indexOf(".asx") != -1 || 
			f.indexOf(".wdl") != -1 || 
			f.indexOf(".wm") != -1 || 
			f.indexOf(".wmx") != -1 || 
			f.indexOf(".wmz") != -1 || 
			f.indexOf(".mpeg") != -1) {

			try {
				window.showModalDialog("/Engines/Standard/popupVideo.htm", f, "status:yes; center:yes; help:no; minimize:no; maximize:no; scroll:no; border:thin; statusbar:yes; dialogWidth:680px; dialogHeight:600px");

			} catch(e) { alert('Popup blocker detected, please disable your popup blocker to allow the website to function correctly.'); }
			//return false;

			} else {
				alert("Sorry, but the video popup cannot play the file: " + f);
			}
	}
}
//ClearText
// public function for use my design
/*
function SwitchState() {
	var i = window.location.pathname.indexOf("/ClearText/");
	if (i>=0) {
		document.location.href = window.location.pathname.replace('/ClearText','') + window.location.search;
	} else {
		document.location.href = '/ClearText' + window.location.pathname + window.location.search;
	}	
}

// register key pressed event
document.onkeydown = keyHit;

function keyHit(evt) {
	altPressed  = event.altKey;
	ctrlPressed = event.ctrlKey;
	var CKeybool = false;
	thiskey = window.event.keyCode;
	if (thiskey == 67) {CKeybool = true;}
	
	if (ctrlPressed == true && altPressed == true && CKeybool == true) {
		SwitchState();
	}
}
*/
function printPage() {
	window.focus();
	window.print();
}
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';
  
  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
// Cookie Handling
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
