function extlinks() { 
	if (!document.getElementsByTagName) return;
	var lynkz = document.getElementsByTagName("a");
	for (a=0; a<lynkz.length; a++) {
		var lynk = lynkz[a];
		if (lynk.getAttribute("href") && lynk.getAttribute("rel") == "new") lynk.target = "_blank";
	}
}
/* Additional Functionality using Cookie */
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}
function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function formvalidationz(FORMrel, targ) {
	//req 	//vmail //targ 	//begin by identifying our form and then cancelling it's standard functionality
	var frms = document.getElementsByTagName("form");
	for (fs=0; fs<frms.length; fs++) {
		var frm = frms[fs];
		if (frm.getAttribute("rel") == FORMrel) {
			//alert(frm.method);
			frm.onsubmit = ValiDator;
		}
	}
	
}
function vmailc(address) {
	
	check = address.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
	

	if (check == null) {
		return "no";
	}
	else {
		return "ok";
	}
}
function ValiDator() {
	badness = 0;
	document.getElementById("adderrors").innerHTML = "";
	var reqs = document.getElementsByTagName("input");
		for (r=0; r<reqs.length; r++) {
			var req = reqs[r];
			if (req.getAttribute("rel") == "req") {
				if (!req.value) {
					document.getElementById("adderrors").innerHTML = document.getElementById("adderrors").innerHTML + "<p>The field: "+req.name+" cannot be left blank</p>";
					badness++;
				}
				else {
					if (req.name == "email") {
						vmail = vmailc(req.value);
						if (vmail == "no") {
							document.getElementById("adderrors").innerHTML = document.getElementById("adderrors").innerHTML + "<p>Invalid Email Address: "+ req.value +"</p>";
							badness++;
						}
					}
				}
			}
	}
	var txts = document.getElementsByTagName("textarea");
	for (t=0; t<txts.length; t++) {
		var tex = txts[t];
		if (tex.getAttribute("rel") == "req") {
			if (!tex.value) {
				document.getElementById("adderrors").innerHTML = document.getElementById("adderrors").innerHTML + "<p>You must enter a message</p>";
				badness++;
			}
		}
	}
	if (badness != 0) return false;
	else {
		document.getElementById("adderrors").innerHTML = "<span><img src=\"../img/Processingani.gif\" style=\"border: 0;\" /> Processing...</span>";
		document.getElementById("addcomment").style.opacity = ".50";
		document.getElementById("addcomment").style.filter = "alpha(opacity=50)";
	}
}
/* Contact Form Functions */
//Call this form validator with rel="formvalidator"
	/*
	This function will disable forms with that rel from submitting.
	It scans for required fields left blank, invalid email addresses,
	and then it adds some effect to the submission =)
	*/
function formvalidator(emailtag) {
	var formz = document.getElementsByTagName("form");
	var blankz = 0;
	var errorz = 0;
	var ermail = "false";
	for (fs=0; fs<formz.length; fs++) {
		var fOrm = formz[fs];
		if (fOrm.getAttribute("rel") == "formvalidator") {
			fOrm.onsubmit = function() {
				/*
				works with rel="req"
				class="txt" class="etxt" class="msg" class="emsg"
				*/
				var inputz = document.getElementsByTagName("input");
				for (iz=0; iz<inputz.length; iz++) {
					var inPoot = inputz[iz];
					if (inPoot.getAttribute("rel") == "req" && !inPoot.value) {
						inPoot.className = "etxt";
						errorz++;
						blankz++;
					}
					else {
						if (inPoot.name == emailtag) {
							vmail = vmailc(inPoot.value);
							if (vmail == "no") {
								inPoot.className = "etxt";
								errorz++;
								ermail = "true";
	
							}
						}
					}
				}
				var textareas = document.getElementsByTagName("textarea");
				for (tx=0; tx<textareas.length; tx++) {
					var txtar = textareas[tx];
					if (txtar.getAttribute("rel") == "req" && txtar.value == "") {
						txtar.className = "emsg";
						errorz++;
						blankz++;

					}
				}
				//errorz blankz ermail
				if (errorz != 0) {
					ehead = "<div id=\"errordiv\"><p class=\"errortop\">Your message contains <u>" + errorz + "</u> errors:</p>";
					if (blankz != 0) bhtml = "<p><b>" + blankz + "</b> required fields are blank. They are highlighted for you to fix...</p>";
					else bhtml = "";
					if (ermail == "true") mhtml = "<p>The email address you supplied is invalid. Please check it again.</p>";
					else mhtml = "";
					document.getElementById("errormsg").innerHTML = ehead + bhtml + mhtml + "<div style=\"display: block; text-align: center;\"><a href=\"#\" onclick=\"closeemsg(); return false;\">Continue</a></div></div>";
					errorz = 0;
					blankz = 0;
					return false;
				}
				else document.getElementById("errormsg").innerHTML = "<div id=\"msgdiv\"><p style=\"font-weight: bold; color: #000; font-size: 18px;\">Submitting Message! Please wait...</p></div>";
			}
		}
	}
}
function formhighlights() {
	//Adds Highlights to form inputs and textareas on focus =)
	var txts = document.getElementsByTagName("input");
	for (izz=0; izz<txts.length; izz++) {
		var inpt = txts[izz];
		if (inpt.name) {
			inpt.onfocus = txtfocus;
			inpt.onblur = txtblur;
		}
	}
	var tareas = document.getElementsByTagName("textarea");
	for (ta=0; ta<tareas.length; ta++) {
		var taa = tareas[ta];
		taa.onfocus = textareafocus;
		taa.onblur = textareablur;
	}
}
function txtfocus() {
	this.className = "itxt";
}
function txtblur() {
	this.className = "txt";
}
function textareafocus() {
	this.className = "imsg";
}
function textareablur() {
	this.className = "msg";
}
function closeemsg() {
	document.getElementById("errormsg").innerHTML = "";
}
function xlink() {
	var xlink = document.getElementById("xlist");
	xlink.onclick = function() {
		//Effect.BlindUp("mailinglist");
		document.getElementById("mailinglist").style.display = "none";
		return false;
	}
}
function mailinglist() {
	document.getElementById("mailinglist").style.display = "inline";
	//Effect.BlindDown("mailinglist", {duration:5});
}
function clientIMG() {
	var domimages = document.getElementsByTagName("a");
	for (g=0; g<domimages.length; g++) {
		var Dimage = domimages[g];
		if (Dimage.getAttribute("rel") == "noloadimg") {
			Dimage.onclick = function() {
				document.getElementById("clientIMG").src = this.href;
				return false;
			}
		}
	}
	/* NOT IMPLEMENTED = OPEN NEW WINDOW WITH FULLSIZE IMAGE
	var dlimg = document.getElementById("clientIMG");
	dlimg.onclick = function() {
		var fullsize = this.src.replace(/img\//,"");
		window.open(fullsize, 'img', 'status=0, toolbar=0, location=0, menubar=1, width=500, height=500, resizable=1');
	}
	*/
}
function dlimg() {
	alert(this.src);
}