// JavaScript Document

function gotoPage(pg) {
window.location = pg;
}

function openPage(pg) {
newWin = window.open(pg,"print");
if (typeof newWin != "object") {
	gotoPage(pg);
	}
}

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 != "") {
		window.location = act;
		}
	if (frm != "pageForm") {
		return true;
		}
	}
else
	{
	return false ;	
	}
}

function printResults() {
window.print();	
}

function previewPage(formName) {
document.forms[formName].target = "previewWindow";
document.getElementById(formName).action = "/process.cfm?task=main.pagePreview";
	document.getElementById(formName).submit();
}
function resetFormAction(formName) {
if (document.getElementById(formName).action != window.location) {
	document.getElementById(formName).target = "_self";
	document.getElementById(formName).action = window.location;
	}
}

function stripString(val) {
val = val.toLowerCase();
reSplit = /\W/;
splitStr = val.split(reSplit);
str = splitStr.join("-");
while (str.indexOf("--") != -1) {
	str = str.replace("--","-");
	}
return str.toLowerCase();
}

function createURL(val) {
retUrl = stripString(val);
return retUrl;
}

function previewURL(urlObj) {
var urlValue = $(urlObj).val();
if (urlValue != "") {
	$.Boxen.open(this, {urlAttribute: null, url:urlValue, modal:true});
	}
}

function updateMenu(val,idVal) {
url = "process.cfm?task=menus.update&sortOrder=" + val + "&menuId=" + idVal;
makeServerCall(url);
}
function deleteMenu(parentId,subId) {
url = "process.cfm?task=menus.delete&parentMenuItemId=" + parentId + "&subMenuItemId=" + subId;
makeServerCall(url);
}
function makeServerCall(url) {
$.ajax({
	type: "GET",
	url: url,
	success: function(){ return true }
	});
}
var returnData = "";
function getServerData(url,objId,type) {
$.get(
	url, 
	function(data) {
		$(objId).html(data);
	});
}

function changeLocationType(loc) {
	$("#companyNameItem").hide();
	$("#CompanyName").val(loc);
	if (loc == "Commercial") {
		$("#CompanyName").val("");
		$("#companyNameItem").show();
		}
}
