
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function doConfirm(theMsg) {
	if (confirm(theMsg)) {
		return true;
	} else {
		return false;
	}
}

function verifyDomain(theForm) {
	errors = "";
	if (!testString(theForm["domain"].value, domainName)) {
		errors += "Domain Name appears to be invalid;\n";
	}
	if (!testString(theForm["dateregistered"].value, aDate)) {
		errors += "Date Registered appears to be invalid;\n";
	}
	if (!testString(theForm["expirydate"].value, aDate)) {
		errors += "Expiry Date appears to be invalid;\n";
	}
	if (!testString(theForm["lastcontact"].value, aDate)) {
		errors += "Last Contact Date appears to be invalid;\n";
	}
	if (errors != "") {
		alert("There was something wrong with your form:\n\n" + errors + "\nPlease fix these errors and resubmit your form.");
		return false;
	} else {
		return true;
	}
}

function verifyServer(theForm) {
	errors = "";
	if (!testString(theForm["dateregistered"].value, aDate)) {
		errors += "Date Registered appears to be invalid;\n";
	}
	if (!testString(theForm["expirydate"].value, aDate)) {
		errors += "Expiry Date appears to be invalid;\n";
	}
	if (!testString(theForm["lastcontact"].value, aDate)) {
		errors += "Last Contact Date appears to be invalid;\n";
	}
	if (!testString(theForm["price"].value, aNumber)) {
		errors += "Price appears to be invalid;\n";
	}
	if (errors != "") {
		alert("There was something wrong with your form:\n\n" + errors + "\nPlease fix these errors and resubmit your form.");
		return false;
	} else {
		return true;
	}
}

// just numbers, any amount of them
aNumber = /^[0-9]*$/

// 18/11/2003
aDate = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/

// numbers and brackets + spaces
telephoneNumber = /^[ 0-9\(\)\+]*$/
singleTextLine = /^[ a-zA-Z0-9]*$/
domainName = /^[a-zA-Z0-9\-]*$/
multiTextLine = /^[ a-zA-Z0-9\s]*$/
emailAddress = /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,6}$/

function testString(testString, thePattern) {
	if (testString != "") {
		if (thePattern.test(testString)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}

function isAnyNoteChecked(selectedNote) {
	if (selectedNote == false) {
		alert("Please select a note first!");
		return false;
	} else {
		return true;
	}
}

function isAnyFileChecked(selectedFile) {
	if (selectedFile == false) {
		alert("Please select a file first!");
		return false;
	} else {
		return true;
	}
}

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 quickWin(url, name, source) {
	showPopup(url, name, 450, 450, 0, 0, 1, 'default');
	if (source != "quickfind") {
		return false;
	}
}

function checkForPageDeleteClick(theForm) {
	if (theForm.action == "delete.asp") {
		if (confirm("Are you sure you want to delete this page?")) {
			return true;
		} else {
			return false;
		}
	}
}

function checkForDefaultValue(theFormField, isFocused) {
	if (isFocused) {
		if (theFormField.value == theFormField.defaultValue) {
			theFormField.value = "";
		}
	} else {
		if (theFormField.value == "") {
			theFormField.value = theFormField.defaultValue;
		}
	}
}

firstLetterTest = /^[a-z]$/
illegalChars = / /gi;
function checkWikiPageName(theFormField) {
	theNewValue = String(theFormField.value).toLowerCase();
	if (theNewValue != "") {
		if (!testString(theNewValue.charAt(0), firstLetterTest)) {
			alert("The first letter of a page name must be a character [a-zA-Z]!");
			theFormField.focus();
		}
		theNewValue = theNewValue.replace(illegalChars, ".");
		theFormField.value = theNewValue;
	}
}

function checkWikiPageTitle(theFormField) {
	theNewValue = String(theFormField.value).toLowerCase();
	if (theNewValue != "") {
		if (!testString(theNewValue.charAt(0), firstLetterTest)) {
			alert("The first letter of a page name must be a character [a-zA-Z]!");
			theFormField.focus();
		}
		theFormField.value = theNewValue;
	}
}

function changeStyle(element, strClass) {
	element.className = strClass;
}


var isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;

function reSizeToImage() {
	width = document.images[0].width+40;
	height = document.images[0].height+140;
	if (isIE) {
		//alert("ie: " + width + ", " +height);
		window.resizeTo(width, height);
	} else {
		//alert("other: " + width + ", " +height);
		window.resizeTo(width, height);
	}
	window.moveTo((screen.availWidth - width) / 2, (screen.availHeight - height) / 2);
}
function checkFileDetails() {
	f = document.forms["upload"];
	msg = "";

	unsafeCharList = new Array("#", "@", "'", "\"", "|", "<", ">", "?", "*");
	safeExtList = String("gif,jpg,png,tga");

	// 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 + "\n";
		}

		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] + "\n";
			}
		}

		if (strFile.slice(strFile.lastIndexOf("\\")+1).indexOf(" ") != -1) {
			msg += "You have spaces in your filename, this could cause linking problems.\n";
		}
	}

	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;
	}
}
