// JavaScript Document
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

var tableRowDisp = "table-row";
if (document.all) {
	tableRowDisp = "block";
}

function pageInit() {
initjsDOMenu();
}

function deleteConfirm(type,loc) {
var agree = confirm("Are you sure you wish to delete this " + type + "?");
if (agree == false) {
	return false ;	
	}
gotoPage(loc);
}

function fieldFocus(field,defaultVal) {
if ($(field).value == defaultVal) {
	$(field).value = "";
	}
}
function fieldBlur(field,defaultVal) {	
if ($(field).value == "") {
	$(field).value = defaultVal;
	}
}

function fieldActivate(field) {
dis = true;
curr = $(field).disabled;
if (curr == true) {
	dis = false;
}
$(field).disabled = dis;
}

function gotoPage(pg) {
window.location = pg;
}

function openPage(pg) {
newWin = window.open(pg,"print");
if (typeof newWin != "object") {
	gotoPage(pg);
	}
}

function previewURL(objId) {
url = $(objId).value;
if (url != "") {
	if (url.indexOf("http://") == -1) {
		url = "http://" + url;
		}
	//window.open(url,"previewWin");
	dhtmlwindow.open("previewWin", "iframe", url, "Preview Window", "width=1024px,height=480px,resize=1,scrolling=1,center=1", "recal");
	}
}

function checkZip(zipVal) {
var zipRE = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
//zipVal = document.getElementById(obj).value;
isValid = zipRE.test(zipVal);

if (isValid == false) {
	alert("Zipcode is invalid, please try again.");
	return false;
	}
}

function deleteRecord(frm,nm,act) {
var agree = confirm("Are you sure you wish to permanently delete the following:\n\n\t" + nm + "?");
if (agree) {
	if (act != "") {
		//document.getElementById(frm).action = act;
		window.location = act;
		}
	}
else
	{
	return false ;	
	}
}

function printResults() {
window.print();	
}


function previewPage(formName,circuit) {
document.forms[formName].target = "previewWindow";
document.forms[formName].action = "?task=" + circuit;
}

function populateSiteName() {
fName = $("FirstName").value;
lName = $("LastName").value;
$("SiteName").value = fName + lName;
}

//seo
function addWord(word,obj) {
currVal = $(obj).value;
$(obj).value = currVal + word;
}

function findKeywords(val,retId) {
Effect.Fade('indicator1');
$(retId).innerHTML = "";
if (val.length >= 3) {
	url = "process.cfm?task=feeds.search&keyword=" + val;
	makeServerCall(url,retId);
	}
}
function makeServerCall(url,retId) {
new Ajax.Request	(
					url, 
						{
						method: 'get', 
						onSuccess: function(req) {
							getReturnResults(req.responseText,retId);
							Effect.Appear('indicator1');
							}
						}
					);
}
function getReturnResults(str,retId) {
Effect.Appear(retId);
$(retId).innerHTML = str.trim();
}

function selectItem(val) {
$("siteSearch").value = val;
$('siteSearchForm').submit();
}

/*
document.onkeyup = keyListener;
function keyListener(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
switch(KeyID) {
	case 13: //enter key
	$('siteSearchForm').submit();
	break;
	case 38: //up arrow
	alert("up");
	break;
	case 40: //down arrow
	alert("down");
	break;
	}
}
*/