/*
 * Simple encryption to hide email addresses from crawlers in webpages.
 * This code is Free Software provided under an MIT License.
 * http://www.dynamicobjects.com/d2r/
 */
var result;
var linkText;
var key = "BAD4@.56CEGFHIJKLVWdfTUhijXYZbacemngMNOPQRSopqrstuvz018923klwxy7";
var base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@.0123456789";

function generateMailLink(encoded, linkText)
{
  document.write("<a hr"+"ef=\"ma"+"ilto"+":"+decode(encoded)+"\">"+linkText+"</"+"a>");
}

function encode(str)
{
	return codec(base, key, str);
}
 
function decode(str)
{
	return codec(key, base, str);
}

/*
 * Encrypt/Decrypt a string using a simple substitution cypher
 */
function codec(from, to, str)
{
  var codedResult = "";                                      
  for (i = 0; i < str.length; i++) {     
		current = str.charAt(i);                  
		idx = from.indexOf(current);             
		nextVal =  (idx == -1) ? current : to.charAt(idx);
		codedResult += nextVal;
	}
	return codedResult;
}

function test_wmark()
{
	if ( document.location.href.indexOf("test") > 0 )
	{
		document.body.style.backgroundImage = "url(/images/testing_wMark_pcfs.gif)";
		document.body.style.backgroundAttachment = "fixed";
//		alert("document.body.style.backgroundImage " + document.body.style.backgroundImage);
	}
}

document.onkeyup = function(e)
{
	var e = window.event || e;
	if ( document.location.href.indexOf("test") > 0 )
	{
		if ( e.keyCode == 120 )
		{
			if ( document.body.style.backgroundImage == "" )
				document.body.style.backgroundImage = "url(/images/testing_wMark_pcfs.gif)"
			else
				document.body.style.backgroundImage = ""
		}
	}
}

String.prototype.trim = function()
{
	return this.replace(/^\s+|\s+$/g,"");
}
function UT(strWork)
{
 return strWork.toUpperCase().trim();
}
function LT(strWork)
{
 return strWork.toLowerCase().trim();
}

function PageNav(oForm, sURL)
{
	oForm.action = sURL;
	oForm.submit();
}

function StripTags(xStr)
{
	var regExp = /<\/?[^>]+>/gi;
	xStr = xStr.replace(regExp,"");
	return xStr;
}

function Is_Dirty(sForm, blnShowChange)
{
	var bIsDirty = new Boolean(false);
	var intNumElems;
	var intNumOpts;
	var cOpts;
	var el;
	var eOpt;
	var x;
	var y;
	
	bIsDirty = false;
	var objForm = document.getElementById(sForm);
	intNumElems = objForm.elements.length;

	for ( x=0; x < intNumElems; x++ )
	{
		el = objForm.elements[x];
		switch (true)
		{
			case UT(el.type) == "TEXT":
				if ( UT(el.value) != UT(el.defaultValue) )
				{
					bIsDirty = true;
					if ( blnShowChange )
					{
						window.alert("Form is DIRTY - dirty field is " + el.id + String.fromCharCode(13) + "  Initial value: " + 
										 el.defaultValue + String.fromCharCode(13) + "  Modified value: " + el.value);
					}
				}
				break;
			case UT(el.tagName) == "TEXTAREA":
				if ( UT(el.value) != UT(el.defaultValue) )
				{
					bIsDirty = true;
					if ( blnShowChange )
					{
						window.alert("Form is DIRTY - dirty field is " + el.id + String.fromCharCode(13) + "  Initial value: " + 
										 el.defaultValue + String.fromCharCode(13) + "  Modified value: " + el.value);
					}
				}
				break;
			case UT(el.type) == "RADIO":
				if ( el.checked != el.defaultChecked )
				{
					bIsDirty = true;
					if ( blnShowChange )
					{
						window.alert("Form is DIRTY - dirty field is " + el.id + String.fromCharCode(13) + "  Initial value: " +
										 el.defaultChecked + String.fromCharCode(13) + "  Modified value: " + el.checked);
					}
				}
				break;
			case UT(el.type) == "CHECKBOX":
				if ( el.checked != el.defaultChecked )
				{
					bIsDirty = true;
					if ( blnShowChange )
					{
						window.alert("Form is DIRTY - dirty field is " + el.id + String.fromCharCode(13) + "  Initial value: " +
										 el.defaultChecked + String.fromCharCode(13) + "  Modified value: " + el.checked);
					}
				}
				break;
			case UT(el.tagName) == "SELECT":
				cOpts = el.options;
				intNumOpts = cOpts.length;
				for ( y=0; y < intNumOpts; y++ )
				{
					eOpt = cOpts[y];
					if ( eOpt.selected != eOpt.defaultSelected )
					{
						bIsDirty = true;
						if ( blnShowChange )
						{
							window.alert("Form is DIRTY - dirty field is " + el.id + String.fromCharCode(13) + "  Initial value: " +
											 eOpt.defaultSelected + String.fromCharCode(13) + "  Modified value: " + eOpt.selected + String.fromCharCode(13) + 
											 "  Innertext: " + eOpt.innerText);
						}
						break;
					}
				}
		}
		if ( bIsDirty )
		{
			break;
		}
	}

	if ( bIsDirty )
		return true;
	else
		return false;
}
