function popup(URL, title, width, height) {
	popWindow(URL, title, width, height);
}

function popWindow(URL, title, width, height) {
	if (!startNewWindow(URL, title, width, height))
		alert("Ooops\n\nYou seem to have a popup blocker. Please disable it to see the page!");
}

function startNewWindow(URL, title, width, height) {
	var host = document.location.host;
	host = host.replace(/./g, "");
	this.name = host + "Main";
	var w = window.open(URL, title, "menubar=no,scrollbars=yes,width=" + width + ",height=" + height + ",resizable=1,status=yes");
	if (w == null) return false;
	return true;
}

function openVideoWindow(videoFile) {
	var videoWindow = open(videoFile, "VideoWindow", "width=320,height=320,screenX=0,screenY=0");
	if (videoWindow = null)
		alert("Ooops\n\nYou seem to have a popup blocker. Please disable it to see the video!");
}

function openFlashVideo(videoFile, width, height) {
	if (width == null || width == "")
		width = 320;
	if (height == null || height == "")
		height = 283;
	var videoWindow = open("/apps/videos/flash_popup.jsp?f=" + videoFile, "VideoWindow", "width=" + width + ",height=" + height + ",screenX=0,screenY=0");
	if (videoWindow = null)
		alert("Ooops\n\nYou seem to have a popup blocker. Please disable it to see the video!");
}

function donate() {
	var host = document.location.host;
	if (host.indexOf(":") > 0)
		host = host.substring(0, host.indexOf(":"));
	var opened = startNewWindow("/apps/s/donations/index.jsp?h=" + host, "SecureDonations", 700, 480);
	if (!opened) {
		alert("You seem to have a popup blocker. We will continue in the main browser window.");
		window.location.href = "/apps/s/donations/index.jsp?h=" + host;
	}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function P7_autoLayers() { //v1.2 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;
 var a = parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc) {p7c=new Array();document.p7setc=true;
	for (var u=0;u<10;u++) {p7c[u] = new Array();}}
 for(k=0; k<p7c[a].length; k++) {
	if((g=MM_findObj(p7c[a][k]))!=null) {
	 b=(document.layers)?g:g.style;b.visibility="hidden";}}
 for(k=1; k<args.length; k++) {
	if((g=MM_findObj(args[k])) != null) {
	 b=(document.layers)?g:g.style;b.visibility="visible";f=false;
	 for(j=0;j<p7c[a].length;j++) {
		if(args[k]==p7c[a][j]) {f=true;}}
	if(!f) {p7c[a][p7c[a].length++]=args[k];}}}
}

function proxyKiller() {
	var rn = Math.round(Math.random() * 10000);
	var d = document.location.host;
	var a = document.getElementsByTagName("a");
	var ua = navigator.userAgent;
	var isWinIE = ua != null && ua.indexOf("MSIE") >= 0 && ua.indexOf("Windows") >= 0;
	for (i = 0; i < a.length; i++) {
		var h = a[i].href;
		if (h.indexOf("javascript") < 0 && h.indexOf("&rn=") < 0 && h.indexOf("?rn=") < 0 && h.indexOf("#") < 0 && (h.indexOf("http://" + d) == 0 || h.indexOf("http://www.fusd.net") == 0)) {
			var inner = a[i].innerHTML;
			if (h.indexOf("?") >= 0)
				a[i].href += "&rn=" + rn;
			else
				a[i].href += "?rn=" + rn;
			if (a[i].innerHTML != inner)
				a[i].innerHTML = inner;
		}
	}
}

function trimString(inputString) {
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var c = retValue.substring(0, 1);
	
   while (c == " " || c == "\n" || c == "\r" || c == "\t") {
      retValue = retValue.substring(1, retValue.length);
      c = retValue.substring(0, 1);
   }
   c = retValue.substring(retValue.length - 1, retValue.length);
	
   while (c == " " || c == "\n" || c == "\r" || c == "\t") {
      retValue = retValue.substring(0, retValue.length - 1);
      c = retValue.substring(retValue.length - 1, retValue.length);
   }
   return retValue;
}

function validatePositiveInteger(val) {
	if (val == null || val == "")
		return false;
	var alphabet = "0123456789";
	for (i = 0; i < val.length; i++) {
		if (alphabet.indexOf(val.charAt(i)) < 0)
			return false;
	}
	return true;
}

function rotatePics(name, numPics, interval) {
	var pic = document.getElementById(name);
	var path;
	do {
		path = "pics/" + name + "/" + Math.floor(Math.random() * numPics) + ".jpg";
	} while (pic.src.indexOf(path) >= 0);
	
	pic.src = path;
	
	setTimeout('rotatePics("' + name + '",' + numPics + ',' + interval + ')', interval);
}

function setCookie(sName, sValue, expires) {
	if (expires != null && expires != "")
		document.cookie = sName + "=" + escape(sValue) + "; expires=" + expires;
	else
		document.cookie = sName + "=" + escape(sValue) + ";";
}

function getCookie(sName) {
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++) {
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0]) 
			return unescape(aCrumb[1]);
	}
	
	return null;
}

function delCookie(sName) {
	document.cookie = sName + "=x ; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}