// this file is exactly the same as intranet/js/global.js
// Utility Functions
function popupWindow(url,width,height,scrollbars,name) {
	var handle;
	if(arguments.length < 4) {scrollbars = 'no';}
	if(arguments.length < 5) {name = 'popup';}
	if(handle != null && !handle.closed) {handle.close();}
	handle = window.open(url,name,'toolbar=no,location=no,directories=no,status=no,scrollbars='+scrollbars+',resizable=yes,width='+width+',height='+height);
	handle.focus();
}
function popup(url,width,height) { popupWindow(url,width,height,'yes','popup'); }

// Require Flash 6 or higher
var flashOK = false;
if(navigator.plugins["Shockwave Flash"]) {
	var flashVersion = navigator.plugins["Shockwave Flash"].description.split('Shockwave Flash ')[1];
	if(flashVersion >= '6') { flashOK = true; }
} else if(window.ActiveXObject) {
	objFlash=eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');");
	if(objFlash) { flashOK = true; }
}
function showFlash(url,width,height,base) {
	if(arguments.length < 4) {base = '.';}
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab##version=6,0,29,0" width="'+width+'" height="'+height+'"><param name="movie" value="'+url+'"><param name="quality" value="high"><param name="BASE" value="'+base+'"><embed src="'+url+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" base="'+base+'"></embed></object>');
}

function focusSearch(t) { t.className='x_formelem'; t.value=''; }
function doSearch() { document.fSearch.submit(); }

function navOver(t,l) { if(arguments.length<2) l=''; t.className = 'x_navOver'+l; }
function navOut(t,l) { if(arguments.length<2) l=''; t.className = 'x_nav'+l; }
var allowGoTo = true;
function stopGoTo() { allowGoTo = false; }
function goToPage(id) { if(allowGoTo) window.location = relPath + 'index.cfm?p='+id; }
function goToURL(url) { if(allowGoTo) window.location = url; }

function imgroll(obj,newsrc) {
	obj.src=newsrc;
}


var _x; var _y;
if (!document.all) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
function getMousePosition(e) {
  if (!document.all) { _x = e.pageX; _y = e.pageY; } 
  else { _x = event.clientX + document.body.scrollLeft; _y = event.clientY + document.body.scrollTop; }
  return true;
}
var currentNote = "";
function showNote(divid,divpos){
	if(arguments.length < 2) { divpos = 'right'; }
	var hn; var cn = currentNote; currentNote = divid; if(cn != "") { hideNoteAction(cn); }
	if(document.all){hn=document.all[divid];}else if(document.getElementById){hn=document.getElementById(divid);}
	if(divpos == 'right') { hn.style.left=_x+5;hn.style.top=_y; } else { hn.style.left=_x-135;hn.style.top=_y; }
	hn.style.visibility="visible";
}
function hideNoteAction(divid) {
	var hn;
	if(divid != currentNote) {
		if(document.all){hn=document.all[divid];}else if(document.getElementById){hn=document.getElementById(divid);}
		hn.style.visibility = "hidden";
	}
}
function hideNote(divid) { currentNote = ""; setTimeout("hideNoteAction('"+divid+"')",100); }

/* definitely, this is not the perfect spot to put my js function for specific form validation, but i don't know where should i put them though, so I put here */
function trimString(str) { return str.replace(/^\s+/g,'').replace(/\s+$/g,''); }

function validateMediaUploadForm() {
	var formObj = document.forms["MediaUploadForm"];
	var error = "";	
	error += fv_textRequired(formObj,"Title","Title of submission");
	error += fv_textRequired(formObj,"ClassYear","Class year");
	error += fv_textRequired(formObj,"SchoolName","School name");
	error += fv_textRequired(formObj,"Suburb","Suburb");
	error += fv_textRequired(formObj,"State","State");
	error += fv_checkboxRequired(formObj,"Consent","The consent box");
	if(trimString(formObj.MediaFile.value) == "") { error += "Please select a file from your computer to upload\n"; }
	if(error != "") { alert(error); return false; } else {	return true; }
}

var pageLoaded = false;
window.onload = new function() { pageLoaded = true; }