<!--
var menuDir = "documents/menus";
var specialsDir = "documents/specials";
function turnBlack(menuLink) {
	document.getElementById(menuLink).style.color = '#000000';
}
function turnWhite(menuLink) {
	document.getElementById(menuLink).style.color = '#FFFFFF';
}
function turnRed(menuLink) {
	document.getElementById(menuLink).style.color = '#CC0033';
}
function turnOn(imgSwap) {
	document.getElementById(imgSwap).src = 'images/img'+imgSwap+'_On.jpg';
}
function turnOff(imgSwap) {
	document.getElementById(imgSwap).src = 'images/img'+imgSwap+'_Off.jpg';
}
function closeLogin(page) {
	window.opener.location.href = page;
	window.close();
}
function logout() {
	document.logout.submit();
}
function submitButton (frmName, btnName) {
	if (btnName == "All") {
		document.getElementById("deliv_yesno").value = "0";
	} else if (btnName == "Delivery") {
		document.getElementById("deliv_yesno").value = "1";
	}
	eval('document.' + frmName + '.submit();');
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
   {
   myfield.form.submit();
   return false;
   }
else
   return true;
}
function clearMe(formfield){
  if (formfield.defaultValue==formfield.value)
   formfield.value = ""
}

function popupMap(url){
	var newurl = url.replace(" ", "+");
	var popWin = window.open(newurl, "mapWindow", "width=1050,height=650,toolbar=no,directories=no,location=no,resizable=yes,dependent=no,scrollbars=yes");
	popWin.creator = self ;
	popWin.focus();	
	if (popWin.opener == null) {
		popWin.opener = window;
	}
}
function popupMenu(rid, filename, html){ //pdf is boolean.  1 if it's an html menu, 0 if it's a pdf menu 
	setMenuCookie(rid);
	if (html == 1) { //this is an html-based menu
		var newurl = "menu.php?rid="+rid;
	} else { //this is a pdf menu
		var newurl = menuDir + "/" + rid + "/" + filename;
	}
	var popWin = window.open(newurl, "menuWindow");
	popWin.creator = self ;
	popWin.focus();	
	if (popWin.opener == null) {
		popWin.opener = window;
	}
}
function popupSpecials(rid, filename){  
	setMenuCookie(rid);
	var newurl = specialsDir + "/" + rid + "/" + filename;
	var popWin = window.open(newurl, "specialsWindow");
	popWin.creator = self ;
	popWin.focus();	
	if (popWin.opener == null) {
		popWin.opener = window;
	}
}
function popupCoupon(url){
	var newurl = url;
	var popWin = window.open(newurl, "couponWindow", "width=1200,height=900,toolbar=no,directories=no,location=no,resizable=yes,dependent=no,scrollbars=yes");
	popWin.creator = self ;
	popWin.focus();	
	if (popWin.opener == null) {
		popWin.opener = window;
	}
}
function popupDelivery(url) {
	var newurl = url;
	var popWin = window.open(newurl, "deliveryWindow", "width=400,height=400,toolbar=no,directories=no,location=no,resizable=yes,dependent=no,scrollbars=no");
	popWin.creator = self ;
	popWin.focus();	
	if (popWin.opener == null) {
		popWin.opener = window;
	}
}
function setMenuCookie(rid) {
	strRecent = readCookie('stringRecent');
	if (strRecent) {
		arrRecent = strRecent.split(","); //turn string into array.
		for (i=0; i<arrRecent.length; i++) { //see if the rid is already in the array.
			if (arrRecent[i] == rid) { //if we've found the rid
				arrRecent.splice(i,1);//remove the i-th element
			}
		}
		arrRecent.unshift(rid); //add rid to beginning of string
		if (arrRecent.length > 10) {
			arrRecent.pop(); //removes the last element of the array.
		}
		strRecent = arrRecent.toString(); //convert array to string.
	} else {
		strRecent = rid + ''; //set it to the rid, and make sure it's a string
	}
	createCookie('stringRecent', strRecent, 365);
}
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//grab url parameter value with id="name".
function gup(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function menuDelete()
{
	document.getElementById("submittype").value = "menuDelete";
	document.restaurantEdit.submit();
}
function specialsDelete()
{
	document.getElementById("submittype").value = "specialsDelete";
	document.restaurantEdit.submit();
}
function couponDelete()
{
	document.getElementById("submittype").value = "couponDelete";
	document.restaurantEdit.submit();
}
function htmlDelete(filename)
{
	document.getElementById("submittype").value = "htmlDelete-"+filename;
	document.restaurantEdit.submit();
}
function confirmDelete()
{
	if (confirm("Are you sure you want to delete this restaurant?")) {
		return true; 
	} else {
		return false;
	}
}
function changePage(pageNum)
{
	alert('page num');
	document.getElementById("page").value = "pageNum";
	document.listing.submit();
}
function submitCuisine() {
	document.listing.submit();
}
function sortDelivery(delivery) {
	if (delivery == "asc") {
		document.listing.delivery.value = "desc";
	} else {
		document.listing.delivery.value = "asc";
	}
	document.listing.fullname.value = "";
	//document.listing.cuisine.value = "";
	document.listing.distance.value = "";
	document.listing.submit();
}
function sortFullname(fullname) {
	if (fullname == "asc") {
		document.listing.fullname.value = "desc";
	} else {
		document.listing.fullname.value = "asc";
	}
	//document.listing.delivery.value = "";
	//document.listing.cuisine.value = "";
	document.listing.distance.value = "";
	document.listing.submit();
}
function sortCuisine(cuisine) {
	if (cuisine == "asc") {
		//document.listing.cuisine.value = "desc";
	} else {
		//document.listing.cuisine.value = "asc";
	}
	//document.listing.delivery.value = "";
	document.listing.distance.value = "";
	document.listing.fullname.value = "";
	document.listing.submit();
}
function sortDistance(distance) {
	if (distance == "asc") {
		document.listing.distance.value = "desc";
	} else {
		document.listing.distance.value = "asc";
	}
	//document.listing.delivery.value = "";
	//document.listing.cuisine.value = "";
	document.listing.fullname.value = "";
	document.listing.submit();
}

function submitDistance() {
	document.listing.submit();
}

function redirectParent(url) {
	if (url == '') {
		url = window.opener.location.href;
	}
	window.opener.location.href = url;
	window.opener = null; // this is so that IE doesn't show the confirm close message
	self.close();
}

function couponSignin() {
	alert('You must first sign in or register to use this coupon.');
	//document.getElementById("username").focus();
	window.location.href = 'profile.php';
}
function focusSignIn() {
	//alert(document.getElementById("username").focus);
	document.getElementById("username").focus();
}

function delivHoursSame() {
	//if (document.getElementById("delivSame").checked == true) {
	document.getElementById("delivhours_mon").value = document.getElementById("hours_mon").value;
	document.getElementById("delivhours_tue").value = document.getElementById("hours_tue").value;
	document.getElementById("delivhours_wed").value = document.getElementById("hours_wed").value;
	document.getElementById("delivhours_thu").value = document.getElementById("hours_thu").value;
	document.getElementById("delivhours_fri").value = document.getElementById("hours_fri").value;
	document.getElementById("delivhours_sat").value = document.getElementById("hours_sat").value;
	document.getElementById("delivhours_sun").value = document.getElementById("hours_sun").value;
	document.getElementById("delivhours2_mon").value = document.getElementById("hours2_mon").value;
	document.getElementById("delivhours2_tue").value = document.getElementById("hours2_tue").value;
	document.getElementById("delivhours2_wed").value = document.getElementById("hours2_wed").value;
	document.getElementById("delivhours2_thu").value = document.getElementById("hours2_thu").value;
	document.getElementById("delivhours2_fri").value = document.getElementById("hours2_fri").value;
	document.getElementById("delivhours2_sat").value = document.getElementById("hours2_sat").value;
	document.getElementById("delivhours2_sun").value = document.getElementById("hours2_sun").value;
	
	
}




//Form submissions

function checkRegisterForm() {
	if (document.register.password.value.length < 1) {
		alert("Please enter a valid password.");
		document.register.password.select(); document.register.password.focus(); return false;
	}
	if (document.register.password.value != document.register.passwordagain.value) {
		alert("Passwords do not match.");
		document.register.password.select(); document.register.password.focus(); return false;
	}
	if (document.register.username.value.length < 1) {
		alert("Please enter a valid username.");
		document.register.username.select(); document.register.username.focus(); return false;
	}
	/*
	if (document.register.password.value.length < 1) {
		alert("Please enter a valid password.");
		document.register.password.select(); document.register.password.focus(); return false;
	}
	*/
	if (document.register.firstname.value.length < 1) {
		alert("Please enter a valid first name.");
		document.register.firstname.select(); document.register.firstname.focus(); return false;
	}
	if (document.register.lastname.value.length < 1) {
		alert("Please enter a valid last name.");
		document.register.lastname.select(); document.register.lastname.focus(); return false;
	}
	if (document.register.email.value.length < 1) {
		alert("Please enter a valid email address.");
		document.register.email.select(); document.register.email.focus(); return false;
	}
	if (document.register.address1.value.length < 1) {
		alert("Please enter a valid street address.");
		document.register.address1.select(); document.register.address1.focus(); return false;
	}
	if (document.register.city.value.length < 1) {
		alert("Please enter a valid city.");
		document.register.city.select(); document.register.city.focus(); return false;
	}
	if (document.register.state.value.length < 1) {
		alert("Please enter a valid state.");
		document.register.state.select(); document.register.state.focus(); return false;
	}
	if (document.register.zip.value.length < 1) {
		alert("Please enter a valid zip code.");
		document.register.zip.select(); document.register.zip.focus(); return false;
	}
}
function checkRestaurantForm() {
	//if (document.frmForm.Employees.value.length > 0) {
		/*
		if (isNaN(document.frmForm.Employees.value)) {
			alert("Please enter a number only.  No commas, periods or other non-numeric characters.");
			document.frmForm.Employees.select(); document.frmForm.Employees.focus(); return false;
		}
		*/
	//}
	if (document.restaurantEdit.fullname.value.length < 1) {
		alert("Please enter a valid first name.");
		document.restaurantEdit.fullname.select(); document.restaurantEdit.fullname.focus(); return false;
	}
	if (document.restaurantEdit.address1.value.length < 1) {
		alert("Please enter a valid street address.");
		document.restaurantEdit.address1.select(); document.restaurantEdit.address1.focus(); return false;
	}
	if (document.restaurantEdit.city.value.length < 1) {
		alert("Please enter a valid city.");
		document.restaurantEdit.city.select(); document.restaurantEdit.city.focus(); return false;
	}
	if (document.restaurantEdit.state.value.length < 1) {
		alert("Please enter a valid state.");
		document.restaurantEdit.state.select(); document.restaurantEdit.state.focus(); return false;
	}
	if (document.restaurantEdit.zip.value.length < 1) {
		alert("Please enter a valid zip code.");
		document.restaurantEdit.zip.select(); document.restaurantEdit.zip.focus(); return false;
	}
}
//Google maps stuff


var map = null;
var geocoder = null;

function submitLatLong(id, address) {
	initializeGeocoder();
	geocoder.getLatLng(
    address,
    function(point) {
			if (!point) {
        alert(address + " not found");
      } else {
				var blah = point + '';
				var latlong = blah.split(',');
				var lat = latlong[0];
				lat = lat.substring(1, lat.length);
				var long = latlong[1];
				long = long.substring(1, long.length - 1);
				document.frmLatLong.id.value = id;
				document.frmLatLong.rid.value = id;
				document.frmLatLong.lat.value = lat;
				document.frmLatLong.long.value = long;
				
			}
    }
  );
}
function submitAfterTime() {
	setTimeout('document.frmLatLong.submit();', 1000);
}

function initializeGeocoder() { //same as initializeMap, just without the map.
	if (GBrowserIsCompatible()) {
		geocoder = new GClientGeocoder();
	}
}


function initializeMap() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map_canvas"));
		//map.setCenter(new GLatLng(37.4419, -122.1419), 13);
		geocoder = new GClientGeocoder();
	}
}

function showAddress() {
	
	
	if (geocoder) {
		
		var address = gup('address');
		address = address.replace(/\+/g, " ");
		address = address.replace(/%20/g, " ");
		founddash = address.indexOf("-");
		fullname = address.substring(0, founddash);
		address = address.substring(founddash+1);
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert(address + " not found");
				} else {
					map.addControl(new GLargeMapControl());
					map.setCenter(point, 15);
					var marker = new GMarker(point);
					map.addOverlay(marker);
					address = address.replace(/, /, "<br>");
					marker.openInfoWindowHtml(fullname + "<br>" + address);
				}
			}
		);
		var addressOrig = gup('addressOrig');
		if (addressOrig) {
			addressOrig = addressOrig.replace(/\+/g, " ");
			addressOrig = addressOrig.replace(/%20/g, " ");
			if (addressOrig.length > 10) {
				geocoder.getLatLng(
					addressOrig,
					function(pointOrig) {
						if (!pointOrig) {
							alert(addressOrig + " not found");
						} else {
							var markerOrig = new GMarker(pointOrig);
							map.addOverlay(markerOrig);
							//markerOrig.openInfoWindowHtml(addressOrig);
						}
					}
				);
			}
		}
	}
}

//-->
