<!-- //

/* front end JS content */
/* 5.18.04 HDR */

	function winStat(msg) {
		var m = msg.replace(/[']/ig,"\'");
		window.status = m;
		return true;
	}
	
	function openLink(lnk) {
		var l = httpIt(lnk);
		window.open(l);
	}
	
	function openFullSize(lnk) {
		var l = (lnk != "") ? lnk : "ref/FINAL_offerDetails_popup.html";	window.open(l,"popup","width=480,height=380,menubar=yes,resizable=yes");
	}
	
	function httpIt(lnk) {
		var l = (lnk.toLowerCase().indexOf("http://") > -1) ? lnk : "http://"+lnk;
		return l;
	}
		
	
	function printLink() {
		if (!document.layers) {
			document.write("<a href=\"#\" onClick=\"window.print();\">Print <img src=\"/lib/suffixapp/tools/zoomsave/img/printIcon.gif\" width=\"16\" height=\"14\" alt=\"\" border=\"0\"></a>");
		}
	}
	
	// builds 50 state + CA prov. select options
	function buildStateSelect(st) {
		var selected = new String();
		var stateList = ["AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"];
		var o_stateList = ["AA","AE","AK","AL","AP","AR","AZ","CA","CO","CT","DC","DE","FL","GA","HI","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NY","NV","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VI","VT","WA","WI","WV","WY","AB","BC","MB","NB","NF","NT","NS","NU","ON","PE","QC","SK","YT","BH","OT"];
		document.write("<option value=\"\"></option>");
		for (x = 0; x < stateList.length; x++) {
			trueVal = new String(stateList[x]);
			if (trueVal == st) {
				document.write("<option value=\""+trueVal+"\" SELECTED>"+trueVal+"</option>");
			} else {
				document.write("<option value=\""+trueVal+"\">"+trueVal+"</option>");
			}
		}
	}

	function whatStyle(d) {
		if (document.layers) {
			//document.write("<link href=\"style_ns.css\" rel=\"stylesheet\">");
			document.write("<link href=\""+d+"style_ns.css\" rel=\"stylesheet\">");

		} else {
			//document.write("<link href=\"style.css\" rel=\"stylesheet\">");
			document.write("<link href=\""+d+"style.css\" rel=\"stylesheet\">");

		}
	}
	
	function mapDirCode(a,c,s,z,t){	
		var lk = (t == "m") ? "http://maps.yahoo.com/pmaps?addr=" + a + "&csz=" + c + "+" + s + "+" + z + "&country=us" : "http://maps.yahoo.com/dd?taddr=" + a + "&tcsz=" + c + "+" + s + "+" + z + "&tcountry=us";		window.open(lk,"searchResultMap","width=800,height=600,toolbar=0,location=0,menuBar=0,scrollBars=1,resizable=1,status=1");
		//return lk;		
	}
	
	function ck_search() {
		//alert("ck_search");
		var f = document.forms[0];
		//alert(f.state[f.state.selectedIndex].value);
		
		var cs = (charCheck(f.city,"notNull","",true) || charCheck(f.state,"notNull","",true)) ? true : false;
		var zr = (charCheck(f.zipcode,"notNull","",true) && charCheck(f.radius,"notNull","",true)) ? true : false;
		var e = charCheck(f.searchTerms,"notNull","",true);
		if (e) {
			if (!cs && !zr) {
				alert("You must specify either a city and state or a zip code and search radius before you begin your search for local businesses."); 
				return false;
			} else if (cs && zr) {
				alert("You may search on a city and/or state OR on a zip code and search radius.\nPlease edit your input and try again.");
				return false;
			} else if (cs || zr) {
				return true;
			}
		} else {
			alert("You must specify at least one keyword before you can perform a local business search.");
			return false;
		}
	}
	
	var alpha = /[^A-Za-z]/ig;
	var alphaNum =/[^\w \-]/ig;
	var num = /[^\d]/ig;
	var notNull = /[^\s]/ig;
	var URL = /(http:\/\/)?[\w\.-]+\.[A-Za-z\.]{2,}/ig;
	var dateForm = /\d{1,2}\/\d{1,2}\/[20]?[\d{2}][ ]?[\d:ampm ]?/ig;
	
	function charCheck(f,ty,m,e) {
		var e = (e || !e) ? e : true;
		if (e) {
			var f_type = f.type;
			var f_val = (f_type == "checkbox" || f_type == "select" || f_type == "select-one" || f_type == "radio") ? f[f.selectedIndex].value : f.value;

			if (ty == "alpha") {
				e = (f_val.search(alpha) == -1) ? true : false;
			} else if (ty == "alphaNum") {
				e = (f_val.search(alphaNum) == -1) ? true : false;
			} else if (ty == "num") {
				e = (f_val.search(num) == -1) ? true : false;
			} else if (ty == "notNull") {
				e = (f_val.search(notNull) == -1) ? false : true;
			} else if (ty ==  "URL") {
				e = (f_val.match(URL) == null) ? false : true;
			} else if (ty == "dateForm") {
				e = (f_val.match(dateForm) == null) ? false : true;
			}
			
			if (!e) {
				if (m != "") {
					var msg = (ty != "notNull") ? "The value you have entered for " + m + " is invalid.  Please re-enter this information." : "The " + m + " field is required.  Please enter this information before saving.";
					alert(msg);
				}			
				f.focus();
			}
			
		}
		return e;
	}
	
	function cleanForm(v, formName) {
		var f = GrabId (formName);
		var d = eval("GrabId('"+formName+"')." + v);
		if (d.value != "") {
			if (v == "city" || v == "state") {
				f.zipcode.value = "";
				f.radius.value = "";
			} else if (v == "zipcode" || v == "radius") {
				f.state.value = "";
				f.city.value = "";
					if (f.radius.value == "") {
						f.radius.value = "50";
					}
					if (f.zipcode.value != "") {
						f.zipcode.value = f.zipcode.value.replace(/^d/ig,"");
						f.zipcode.value = f.zipcode.value.substr(0,5);
					}
			}
		}
	}


// -->

