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+$/,"");
}

function deleteConfirm(type,loc) {
var agree = confirm("Are you sure you wish to delete this " + type + "?");
if (agree == false) {
	return false ;	
	}
gotoPage(loc);
}

function deleteFile(loc) {
if (deleteConfirm('file',loc) == false) {
	return false;
	}
}

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 validCategory(cat) {
instance = new site();
instance.setCallbackHandler(categoryReturn);
instance.checkCategory(cat);
}

var catExists = 0;

function categoryReturn(result) {
catExists = 0;
if (parseInt(result) > 0 && result != "0") {
	catExists = 1;
	}
}

function categorySelection(val) {
dis = true;
if (val == "") {
	dis = false;
	}
$("categoryId").disabled = dis;
}

function checkCategoryName() {
alertTxt = "";
if ($('categoryId').selectedIndex) {
	catSel = $('categoryId').selectedIndex;
	catVal = $('categoryId').options[catSel].value;
	if ($('categoryName').value.trim() == "" && catVal == "") {
		alertTxt += "\nCategory or Category Name is required";
		}
	}
else {
	if ($('categoryName').value.trim() == "") {
		alertTxt += "\nCategory Name is required";
		}
	}
if (catExists == 1) {
	alertTxt += "\nThe category entered already exists.";
	}
return alertTxt;
}

function checkListingForm() {
alertTxt = "";
if (checkCategoryName() != "") {
	alertTxt += checkCategoryName();
	}
if ($('businessName').value.trim() == "") {
	alertTxt += "\nBusiness Name is required";
	}
	
if (alertTxt != "") {	
	alert("Please correct the following to continue:\n" + alertTxt);
	catExists = 0;
	return false;
	}
}

function checkCategoryForm() {
if (checkCategoryName() != "") {
	alert(checkCategoryName());
	catExists = 0;
	return false;
	}
}

function viewCategory(idVal) {
catObj = "category_" + idVal;

new Effect.BlindDown(catObj);
activeLink = "hide_" + idVal;
inactiveLink = "view_" + idVal;

Element.hide(inactiveLink);
Element.show(activeLink);
}
function hideCategory(idVal) {
catObj = "category_" + idVal;

new Effect.BlindUp(catObj, {duration:0.3});
activeLink = "view_" + idVal;
inactiveLink = "hide_" + idVal;

Element.hide(inactiveLink);
Element.show(activeLink);
}

function sortRecords(type,col,ord) {
sortURL = type + '.cfm?sort=' + col + '&order=' + ord;
gotoPage(sortURL);
}