
var browserName = navigator.appName; 
var browserVer = parseInt(navigator.appVersion);

if ((browserName == "Netscape" && browserVer >= 3) || (browserName == "Microsoft Internet Explorer" && browserVer >= 4)){
	version= "n3";
	if (browserName == "Microsoft Internet Explorer"){
		ie4 = true;
	}
	else{
		ie4 = false;
	}
}
else {
	version = "n2";
}

if (document.images) {
  image1on = new Image();
  image1on.src = "images/pages/pageicon-off.gif";

  image1off = new Image();
  image1off.src = "images/pages/pageicon-off-on.gif";
}

function imgOn(imageName) {
	if (document.images) {
		document[imageName].src = "images/pages/pageicon-off-on.gif";
	}
}
function imgOff(imageName) {
	if (document.images) {
		document[imageName].src = "images/pages/pageicon-off.gif";
	}
}


function turnOn(id, type) {
	if (ie4) {
		if (type == "subcat") {
			document.all["subcat_" + id].setAttribute("CLASSNAME", "activesubcat", "0");
		}
		else {
			var therow = "row_" + id;
			var thecell = "cell_" + id;
			document.all[therow].setAttribute("CLASSNAME", "selected", "0");
			document.all[thecell].setAttribute("CLASSNAME", "selected", "0");
			document.all[thecell].innerHTML = "<B>&#187;<\/B>";
		}
	}
}

function turnOff(id, type) {
	if (ie4) {
		if (type == "subcat") {
			document.all["subcat_" + id].className = "notselectedsubcat";
		}
		else {
			var therow = "row_" + id;
			var thecell = "cell_" + id;
			document.all[therow].setAttribute("CLASSNAME", "notselected", "0");
			document.all[thecell].setAttribute("CLASSNAME", "notselected", "0");
			document.all[thecell].innerHTML = "&#149;";
		}
	}
}



function howTo(sign){
var thePage = "howto.cfm?sign=" + escape(sign);
	howTosign = window.open(thePage, 'howto', 'height=175,width=350');

}


function chkEmail(address) {
var atpos = address.indexOf("@");
var afterat = address.charAt(atpos + 1);

return (atpos == -1 || atpos == 0 || chkStr(address) || afterat == "" ? true : false);

}

function chkStr(str) {
var strLen = str.length;
var isNotOK = (strLen == "" ? true : false);
var counter = 1;

	if (!isNotOK) {
		for (j = 1; j <= strLen; j++) {
			if (str.charAt(j) == " ") {
				counter++	
			}
		}
		//alert(counter + "-" + strLen);
		if (counter == strLen) {
			isNotOK = true;
		}
	}
	

return isNotOK;

}


function checkform(theform) {
var flag = new Boolean();
flag = true;

	if (theform == "search" || theform == "search2"){
		if (flag && (chkStr(document[theform].searchstring.value))) {
			flag = false;
			validatePrompt (document[theform].searchstring, "Please enter a search word or phrase.");
		}
		if (flag && (document[theform].searchstring.value.length < 3)) {
			flag = false;
			validatePrompt (document[theform].searchstring, "Search word too short. Please specify at least 3 characters.");
		}
	}

	if (theform == "contact"){
		if (flag && (document[theform].name.value == "Name" || chkStr(document[theform].name.value))) {
			flag = false;
			validatePrompt (document[theform].name, "Please enter your name");
		}
		if (flag && (chkEmail(document[theform].email.value) || chkStr(document[theform].email.value))) {
			flag = false;
			validatePrompt (document[theform].email, "Please provide a proper e-mail address");
		}
		if (flag && (document[theform].pagetext.value == "Type your message here..." || chkStr(document[theform].pagetext.value))) {
			flag = false;
			validatePrompt (document[theform].pagetext, "Please enter a message");
		}
	}

	if (theform == "addlink") {
		if (flag && (document[theform].linkcat.selectedIndex == "0")) {
			flag = false;
			validatePrompt (document[theform].linkcat, "Please select a category");
		}
		if (flag && (document[theform].site_title.value == "Site Title" || chkStr(document[theform].site_title.value))) {
			flag = false;
			validatePrompt (document[theform].site_title, "Please enter a site title");
		}		
		if (flag && (document[theform].url.value == "http://" || document[theform].url.value.indexOf("http://") == -1 || chkStr(document[theform].url.value) || document[theform].url.value.indexOf(".") == -1)) {
			flag = false;
			validatePrompt (document[theform].url, "Please enter a proper URL for the site");
			if (document[theform].url.value.indexOf("http://")) {
				document[theform].url.value = "http:\/\/" + document[theform].url.value;
			}
		}
		if (flag && document[theform].url.value.indexOf(" ") > -1) {
			flag = false;
			validatePrompt (document[theform].url, "URL\'s cannot contain spaces.");
		}
		if (flag && document[theform].url.value.length < 14) {
			flag = false;
			validatePrompt (document[theform].url, "To few characters in URL.");
		}

	}
	
return  flag;
}

function validatePrompt (Ctrl, prompt) {
	alert (prompt);
	Ctrl.focus();
	return;
}

function clearField(field) {
	if (field.value == field.defaultValue) {
		field.value = "";
	}
}
function checkField(field) {
	if (field.value == "") {
		field.value = field.defaultValue;
	}
}

function openAnyWindow(url, name) {
  var l = openAnyWindow.arguments.length;
  var w = "";
  var h = "";
  var features = "";

  for (i=2; i<l; i++) {
    var param = openAnyWindow.arguments[i];
    if ( (parseInt(param) == 0) ||
      (isNaN(parseInt(param))) ) {
      features += param + ',';
    } else {
      (w == "") ? w = "width=" + param + "," :
        h = "height=" + param;
    }
  }

  features += w + h;
  var code = "popupWin = window.open(url, name";
  if (l > 2) code += ", '" + features;
  code += "')";
  eval(code);
}
