
function showPopup(url, name, width, height, scroll, resizable, statusbar, screenpos) {
	var Xwin = width;
	var Ywin = height;
	var Xsize = screen.availWidth;
	var Ysize = screen.availHeight;
	var Xpos = 0;
	var Ypos = 0;
	switch(screenpos) {
		case "topleft":
			Xpos = 0;
			Ypos = 0;
			break;
		case "topright":
			Xpos = Xsize - width;
			Ypos = 0;
			break;
		case "bottomleft":
			Xpos = 0;
			Ypos = Ysize - height;
			break;
		case "bottomright":
			Xpos = Xsize - width;
			Ypos = Ysize - height;
			break;
		default:
			Xpos = (Xsize - width) / 2;
			Ypos = (Ysize - height) / 2;
			break;
	}
	var popwin;
	var opts = "status=" + statusbar + ",resizable=" + resizable + ",scrollbars=" + scroll + ",height=" + Ywin + ",width=" + Xwin + ",left=" + Xpos + ",top=" + Ypos;
	popwin = window.open(url, name, opts);
	popwin.focus();
}

function submitForm(url, name) {
	showPopup(url, name, 300, 150, 0, 0, 1, "default");
}

function openRichTextEditor(theFormSource) {
	showPopup("/fckeditor/edit.asp?source=" + theFormSource + "", "rte", 640, 480, 0, 0, 0, 'default');
}

function showConfirm() {
	if (confirm("Are you sure?")) return true;
	else return false;
}

function getCookie(name) {
	var start = document.cookie.indexOf(name+"=");
	var len = start+name.length+1;
	if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
	if (start == -1) return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

function setCookie(name, value, expires, path, domain, secure) {
	path = "/";
	document.cookie = name + "=" +escape(value) +
	((expires) ? ";expires=" + expires.toGMTString() : "") +
	((path) ? ";path=" + path : "") + 
	((domain) ? ";domain=" + domain : "") +
	((secure) ? ";secure" : "");
}

var today = new Date();
var expires = new Date(today.getTime() + (365 * 86400000));

function pickRandomNumber(num) {
	return Math.round(num*Math.random());
}

function arrayShuffle(u_array, n) {
	var i, j, k;
	var temp;
	for (i = 0; i < n; i++)
	for (j = 0; j < u_array.length; j++) {
		k = Math.floor(Math.random() * u_array.length);
		temp = u_array[j];
		u_array[j] = u_array[k];
		u_array[k] = temp;
	}
}

function cancelEditArticle(theForm) {
	theForm.action = "cancelEdit.asp";
	theForm.submit();
}

function cancelEditCategory(theForm) {
	theForm.action = "cancelEdit.asp";
	theForm.submit();
}

function editNews(NewsID, CategoryID) {
	if (NewsID == "new") {
		location.href = "add.asp?CategoryID="+CategoryID;
	} else {
		location.href = "edit.asp?NewsID="+NewsID;
	}
}

function viewCommentsForEntry(NewsID) {
	location.href = "comments/?NewsID="+NewsID;
}

function deleteNewsEntry(theForm) {
	document.forms["editForm"+theForm]["delete"].value = "yes";
}

function openSubmitWindow() {
	showPopup("about:blank", "savePage", 300, 150, 0, 0, 1, 'default');
}

function changeStyle(element, strClass) {
	element.className = strClass;
}

function checkSupportDetails(f) {

	msg = "";

	if (f["n"].value == "") {
		msg += "You didn't specify your Name;\n";
	}

	if (f["e"].value == "") {
		msg += "You didn't specify your Email address;\n";
	}

	if (f["pr"].value == "") {
		msg += "You didn't specify your problems that require assistance;\n";
	}

	if (msg != "") {
		msg = "You cannot continue because:\n\n" + msg + "\nClick OK and go back and fill in all required fields.";
		alert(msg);
		return false;
	} else {
		var ms;
		today = new Date();
		ms = Date.parse(today)
		ms += today.getMilliseconds();
		f["id"].value = ms;
		return true;
	}
}

function validateAccountForm() {

	d = document.forms["accForm"];

	if (d["thePassword1"].value != d["thePassword2"].value) {
		alert("Passwords don't match!");
		d["thePassword1"].focus();
		return false;
	}

	return true;
}

function checkFileDetails() {
	f = document.forms["upload"];
	msg = "";

	unsafeCharList = new Array("#", "@", "'", "\"", "|", "<", ">", "?", "*");
	safeExtList = String("gif,jpg,ppt,zip,rar,pdf,doc,xls,png,tga,txt,mp3");

	// jpg,gif,css,asp,php,ai,avi,bmp,cs,dll,doc,exe,fla,htm,js,mdb,mp3,pdf,ppt,rdp,swf,swt,txt,vsd,xls,xml,zip

	strFile = String(f["f"].value);

	if (strFile == "") {
		msg += "You didn't specify a file for upload;\n";
	} else {
		fileExt = strFile.slice(strFile.lastIndexOf(".")+1).toLowerCase();

		if (safeExtList.indexOf(fileExt) == -1) {
			msg += "You cannot upload this file, it's file type is forbidden: " + fileExt + "";
		}

		for (i = 0; i <= unsafeCharList.length; i++) {
			if (strFile.indexOf(unsafeCharList[i]) != -1) {
				msg += "Your file has inappropriate characters in it's name: " + unsafeCharList[i];
			}
		}
	}

	if (msg != "") {
		msg = "You cannot continue, here is why:\n\n" + msg + "\nClick OK and try again.";
		alert(msg);
		return false;
	} else {
		f["uploadbtn"].disabled = true;
		ShowProgress();
		return true;
	}
}

function initLoginFocus() {
	document.forms["login"].a.focus();
}

function pick(thePath, theFile) {
	
	window.opener.SetUrl("http://" + location.hostname + thePath + "" + theFile + "", 11, 12, "alt text required.");
	window.close();
}