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";
	}
}
function validatemail(address) {
	check = address.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
	if (check == null) {
		return "no";
	}
	else {
		return "ok";
	}
}
/* 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 vmailc(address) {

	check = address.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);


	if (check == null) {
		return "no";
	}
	else {
		return "ok";
	}
}
function capitalizeMe(obj) {
        val = obj.value;
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
        }
		newVal = newVal.replace(" The ", " the ");
		newVal = newVal.replace(" Of ", " of ");
		newVal = newVal.replace(" Ii ", " II ");
		newVal = newVal.replace(" Iii ", " III ");
		newVal = newVal.replace(" And ", " and ");
		newVal = newVal.replace(" In ", " in ");
		newVal = newVal.replace(" On ", " on ");
		newVal = newVal.replace(" An ", " an ");
		newVal = newVal.replace(" To ", " to ");
		newVal = newVal.replace(" For ", " for ");
		newVal = newVal.replace(" Is ", " is ");
		newVal = newVal.replace(" A ", " a ");

        obj.value = stripSpaces(newVal);
}
function stripSpaces(data) {
    xxx = data;
    while (xxx.substring(0,1) == ' ') xxx = xxx.substring(1);
    while (xxx.substring(xxx.length-1,xxx.length) == ' ') xxx = xxx.substring(0,xxx.length-1);
    return xxx;
}
/* xForm ~ makes my default form functions! */
function xform(cursor, ONbg, OFFbg, ONcolor, OFFcolor, ONborder, OFFborder) {
	FindForms = document.getElementsByTagName("form");	//get all forms in document
	for (f=0; f<FindForms.length; f++) {
		if (FindForms[f].getAttribute("rel") == "xform") {
			/* This is where we assign the effects to the form */
			xform = FindForms[f];			//xform object
			for (hh=0; hh<xform.length; hh++) {
				var xElem = xform.elements[hh];	//xform element obj
				if (xElem.name == cursor && cursor != null) {
					xElem.focus();
					highlighter(xElem, "on");
				}
				/* highlights */
				xElem.onfocus = function() {
					highlighter(this, "on", ONbg, OFFbg, ONcolor, OFFcolor, ONborder, OFFborder);
				}
				xElem.onblur = function() {
					highlighter(this, "off", ONbg, OFFbg, ONcolor, OFFcolor, ONborder, OFFborder);
				}
				xElem.onchange = function() {
					caps(this);
				}
				xElem.onclick = function() {
					dorun(this);
				}
			}
			xform.onsubmit = function() {
				validateForm(this);
				return false;
			}
		}
	}
}
function highlighter(field, state, ONbg, OFFbg, ONcolor, OFFcolor, ONborder, OFFborder) {
	/* Define Highlights */
	if (!ONbg) ONbg = "#fff";
	if (!OFFbg) OFFbg = "#e1e1e1";
	if (!ONcolor) ONcolor = "#000";
	if (!OFFcolor) OFFcolor = "#666";
	if (!ONborder) ONborder = "inset 1px #330000";
	if (!OFFborder) OFFborder = "inset 1px #666";
	thisone = "no";
	if (field.getAttribute("rel") != null && field.getAttribute("rel").match("highlight") == "highlight") thisone = "high";
	if (field.type == "text" || field.type == "textarea" || field.getAttribute("rel") == "highlight" || thisone == "high") {
		if (state == "on") {
			field.style.background = ONbg;
			field.style.border = ONborder;
			field.style.color = ONcolor;
		}
		else if (state == "off") {
			field.style.background = OFFbg;
			field.style.border = OFFborder;
			field.style.color = OFFcolor;
		}
	}
}
function caps(field) {
	if (field.value != undefined && field.value != "on" && field.type == "text") {
		OBJrel = field.getAttribute("rel");
		if (OBJrel.match("Cap") == "Cap") {
			capitalizeMe(field);

		}
	}
}
function run(e, func) {
	if (typeof window[func] != 'undefined') {
		window[func](e);
	}
	else alert('unknown function: ' + func);
}
function dorun(click) {
	/* function to scan passed clicked object for rel="Function, functionname" and then run it */
	if (click.getAttribute("rel") != null) {
		if (click.getAttribute("rel").match("Function") == "Function") {
			var broken = click.getAttribute("rel").split(",");
			run(click, stripSpaces(broken[1]));
		}
	}
}

function validateForm(theform) {
	/* time to validate! */
	errorx = 0;
	for (v=0; v<theform.length; v++) {
		eleobj = theform.elements[v].getAttribute("rel");
		if (eleobj && eleobj.match("req") == "req" && theform.elements[v].value == "") {
			errorx++;
			errorz = "One or more required fields left blank. The field(s) have been highlighted in red.";
			theform.elements[v].style.background = "#ccc";
			theform.elements[v].style.border = "solid 1px #ff3300";
			theform.elements[v].style.color = "#000";
		}
		else if (eleobj && eleobj.match("EmailAddress") == "EmailAddress" && vmailc(theform.elements[v].value) == "no") {
			errorx++;
			errorz = "Invalid Email Address";
			theform.elements[v].style.background = "#ccc";
			theform.elements[v].style.border = "solid 1px #ff3300";
			theform.elements[v].style.color = "#000";

		}
		else var blah = "stuff";
	}
	if (errorx != 0) {
		alert(errorz);
	}
	else {
		theform.submit();
	}
}


function autolink(s)
{
   var hlink = /\s(ht|f)tp:\/\/([^ \,\;\:\!\)\(\"\'\<\>\f\n\r\t\v])+/g;
   return (s.replace (hlink, function ($0,$1,$2) { s = $0.substring(1,$0.length);
                                                   // remove trailing dots, if any
                                                   while (s.length>0 && s.charAt(s.length-1)=='.')
                                                      s=s.substring(0,s.length-1);
                                                   // add hlink
                                                   return " " + s.link(s);
                                                 }
                     )
           );
}
function divsizetowin(divid) {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var fxdiv = document.getElementById(divid);
  fxdiv.style.width = myWidth;
  fxdiv.style.height = myHeight;
}
function firstletter(tsize) { //modified
	if (FIRSTletter == "yes") {
	insize = this.value.length;
	currr = this.value.substring(insize-1);
	backtwo = this.value.substring(insize-3,insize-1);
	if (insize == 1) { this.value = this.value.toUpperCase(); NEXTchar = "false"; }
	else if (NEXTchar == "true") {
		this.value = this.value = this.value.substring(0,insize-1) + this.value.substring(insize-1).toUpperCase();
		NEXTchar = "false";
	}
	else if (backtwo == ". " || backtwo == "! " || backtwo == "? ") { this.value = this.value.substring(0,insize-1) + this.value.substring(insize-1).toUpperCase(); }
	else if (currr == "\n") {
		NEXTchar = "true";
	}
	this.value = this.value.replace(" i "," I ");
	this.value = this.value.replace("  "," ");
	this.value = this.value.replace(" i'll "," I'll ");
	this.value = this.value.replace(". .","..");
	this.value = this.value.replace(" i'd "," I'd ");
	this.value = this.value.replace(" i've "," I've ");
	this.value = this.value.replace(" i'm "," I'm ");
	this.value = this.value.replace("Http", "http");
	this.value = this.value.replace("Www.", "http://www.");
	this.value = this.value.replace(" www.", " http://www.");
	this.value = this.value.replace(" russ "," Russ ");
	this.value = this.value.replace(" sonya ", " Sonya ");
	this.value = this.value.replace(" russ. "," Russ. ");
	this.value = this.value.replace(" sonya. ", " Sonya. ");
	this.value = this.value.replace(" russ! "," Russ! ");
	this.value = this.value.replace(" sonya! ", " Sonya! ");
	this.value = this.value.replace(" russ? "," Russ? ");
	this.value = this.value.replace(" sonya? ", " Sonya? ");
	this.value = this.value.replace(" teh", " the");
	this.value = this.value.replace(" hte ", " the ");
	this.value = this.value.replace(" im ", " I'm ");
	}
	// Prevent Hacks - This only stops the most basic hacks such as <script> eval() and javascripts
   	this.value = this.value.replace(/[\"\'][\s]*javascript:(.*)[\"\']/gi, "\"\"");
    	this.value = this.value.replace(/<script(.*)/gi, " script");
    	this.value = this.value.replace(/eval\((.*)\)/gi, "");
	//this.rows = countLines(this.value,this.cols, 5)+1;
	sz(this);

}
/*
	sz(text): resize textarea to contain current amount of text
	Usage: sz(textarea)
*/
function sz(t) {
a = t.value.split('\n');
b=1;
for (x=0;x < a.length; x++) {
 if (a[x].length >= t.cols) b+= Math.floor(a[x].length/t.cols);
 }
b+= a.length;
if (b > t.rows) t.rows = b;
}
/*
	AjaxUploader() ~ rel="AjaxUploader, formDIV, loadingDIV, iframe Name"
	requires:
		<div id="%Loading div name%"></div>
		<div id="%Form div name%"><form with rel="AjaxUploader"></div>
		<iframe name="% ajax iframe name%" class="AjaxPortal"></iframe>


*/
function AjaxUploader() {
	//get all forms in document
	FindAjax = document.getElementsByTagName("form");
	//scroll through all forms
	for (xf=0; xf<FindAjax.length; xf++) {
		//current form
		var AjaxForm = FindAjax[xf];
		//if this form has our rel="AjaxUploader" attribute
		if (AjaxForm.getAttribute("rel").match("AjaxUploader") == "AjaxUploader") {
			/* Get Values: (first build array with attributes taken from rel="" */
			relGET = AjaxForm.getAttribute("rel").split(", ");
			//0 = our initial declaration
			//1 = form div
			xDiv = relGET[1];
			//2 = loading... div
			loadDiv = relGET[2];
			//3 = target iframe
			iFrame = relGET[3];
			AjaxForm.target = iFrame;
			/* Now let's start the magic! */
			AjaxForm.onsubmit = function() {
				for (ajx=0; ajx<this.length; ajx++) {
					var ai = this.elements[ajx];
					if (ai.type == "file") {
						if (ai.value == "") { alert('Please select a file'); return false; }
					}
				}
				document.getElementById(xDiv).style.display = "none";
				document.getElementById(loadDiv).style.display = "block";
			}
		}
	}
}
function AjaxHTML(html, unhide, hide) {
	alert(html);
	//document.getElementById(unhide).style.display = "block";
	//document.getElementById(hide).style.display = "none";
	document.getElementById(unhide).innerHTML = "<p>TEST</p>" + html;
	alert(document.getElementById(unhide).innerHTML);
}
/* My first attempt at AJAX for REALS */
function createRequestObject() {
    var tmpXmlHttpObject;

    //depending on what the browser supports, use the right way to create the XMLHttpRequest object
    if (window.XMLHttpRequest) {
        // Mozilla, Safari would use this method ...
        tmpXmlHttpObject = new XMLHttpRequest();

    } else if (window.ActiveXObject) {
        // IE would use this method ...
        tmpXmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }

    return tmpXmlHttpObject;
}

//call the above function to create the XMLHttpRequest object
var http = createRequestObject();

function makeGetRequest(wordId, filename, variable, divid) {
    //make a connection to the server ... specifying that you intend to make a GET request
    //to the server. Specifiy the page name and the URL parameters to send
    //This is where it needs some personalizing
    http.open('get', filename + '?' + variable + '=' + wordId);

    //assign a handler for the response
    http.onreadystatechange = processResponse;

    //actually send the request to the server
    http.send(null);
}
/*
*
*	Coming Soon...
*	http://www.openjs.com/articles/ajax_xmlhttp_using_post.php

function makePostRequest(form) {
	var url = "get_data.php";
	var params = "lorem=ipsum&name=binny";
	http.open("POST", url, true);

	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");

	http.onreadystatechange = function() {//Call a function when the state changes.
		if(http.readyState == 4 && http.status == 200) {
			alert(http.responseText);
		}
	}
	http.send(params);
}
*/
function processResponse() {
    //check if the response has been received from the server
    if(http.readyState == 4){

        //read and assign the response from the server
        var response = http.responseText;
        //do additional parsing of the response, if needed


        //in this case simply assign the response to the contents of the <div> on the page.


        //PERSONALIZATION: Add x button to div to remove innerHTML
        document.getElementById("sresults").innerHTML = response;

        //If the server returned an error message like a 404 error, that message would be shown within the div tag!!.
        //So it may be worth doing some basic error before setting the contents of the <div>
    }
}
function sxform() {
	/* NEW Ajax Search Form! */
	Bodysx = document.getElementsByTagName("body");
	Bodysx[0].onclick = function() {
		document.getElementById("sresults").style.display = "none";
	}
	FindFormsx = document.getElementsByTagName("form");	//get all forms in document
	for (sxf=0; sxf<FindFormsx.length; sxf++) {
		if (FindFormsx[sxf].getAttribute("rel") == "sxform") {
			var searchForm = FindFormsx[sxf];
			searchForm.onsubmit = function() {
				document.getElementById("sresults").innerHTML = "<img src=\"../img/checking.gif\" />";
				if (searchForm.elements[1].value.length > 2) {
					document.getElementById("sresults").style.display = "none";
					makeGetRequest(searchForm.elements[1].value, "search.php", "searchtxt", "sresults");
				}
				else { alert('Search text must be at least 3 chars long'); document.getElementById("sresults").innerHTML = ""; }
				//return false;
			}
			/*
			Auto-Complete :: in progress...
			*/
			document.getElementById("searchtxt").onkeyup = function() {
				var slen = document.getElementById("searchtxt").value.length;
					document.getElementById("sresults").innerHTML = "";
					if (document.getElementById("searchtxt").value == "") document.getElementById("sresults").style.display = "none";
					else if (document.getElementById("searchtxt").value.length >= 1) {
						makeGetRequest(document.getElementById("searchtxt").value, "search.php", "searchtxt", "sresults");
						document.getElementById("sresults").style.display = "block";
					}
			}
		}
	}
}
function remJXinner(divid) {
	document.getElementById(divid).innerHTML = "";
}
/* BACKBUTTON-DISABLE This script pushes you back forward if you try to get to it with the back button ;) */
//To run this script:
//window.onload = backButtonOverride();
function backButtonOverride()
{
  // Work around a Safari bug
  // that sometimes produces a blank page
  setTimeout("backButtonOverrideBody()", 1);

}

function backButtonOverrideBody()
{
  // Works if we backed up to get here
  try {
    history.forward();
  } catch (e) {
    // OK to ignore
  }
  // Every quarter-second, try again. The only
  // guaranteed method for Opera, Firefox,
  // and Safari, which don't always call
  // onLoad but *do* resume any timers when
  // returning to a page
  setTimeout("backButtonOverrideBody()", 500);
}
/* /END OF BACKBUTTON-DISABLE */