


function doOnLoad() {

	// tell a friend link
	tell_a_friend_link();


	// load hover images
	loadRolloverImages();

	// preload images


}


function doPostBodyLoad() {
	init_menus();

	//if(window._set_page_title) {
	//	var el = document.getElementById('pHeading');
	//	if(el) el.innerHTML = window._set_page_title;
	//}

	//if(window._set_page_subtitle) {
	//	var el = document.getElementById('pSubheading');
	//	if(el) el.innerHTML = window._set_page_subtitle;
	//}

	if(window._set_page_title == "About Us") {
		var el = document.getElementById('pHeading');
		if(el) el.innerHTML = '<p><a href="/about.html" style="color:#6D250C; text-decoration:none;">About Us</a></p><p><a href="/about-then_and_now.html" style="color:#6D250C; text-decoration:none;">Napoli Pizzeria Then &amp; Now</a></p><p><a href="/about-staff.html" style="color:#6D250C; text-decoration:none;">Ownership & Staff</a></p>';
	}
	if(window._set_page_title == "Party Size Orders") {
		var el = document.getElementById('pHeading');
		if(el) el.innerHTML = '<p><a href="/party_orders.html" style="color:#6D250C; text-decoration:none;">Party Size Orders</a></p><p><a href="/group-pricing.html" style="color:#6D250C; text-decoration:none;">Sample Menus & Pricing</a></p>';
	}
	if(window._set_page_title == "Our Menu" || window._set_page_subtitle == "Sample Menus & Pricing") {
		var el = document.getElementById('pHeading');
		if(el) el.innerHTML = '<p style="padding-top:66px;"><img src="/assets/images/side-garlic-olive-oil-ravio.jpg" alt="Garlic Olive Oil Ravioli" width="150" height="200" style="border:1px solid #E57743"><br><br><br><br><br><br><br><br><br><br><img src="/assets/images/side-lasagna.jpg" alt="Lasagna" width="150" height="200" style="border:1px solid #E57743"><br><br><br><br><br><br><br><br><br><br><img src="/assets/images/side-tortolini.jpg" alt="Tortolini" width="150" height="200" style="border:1px solid #E57743"><br><br><br><br><br><br><br><br><br><br><img src="/assets/images/side-veggie-pizza.jpg" alt="Tortolini" width="150" height="113" style="border:1px solid #E57743"></p>';
	}	
	if(window._set_page_title == "Questions & Answers") {
		var el = document.getElementById('pHeading');
		if(el) el.innerHTML = '<p style="padding-top:66px;"><img src="/assets/images/side-outside.jpg" alt="Napoli Pizza" width="150" height="200" style="border:1px solid #E57743"><br><br></p>';
	}	
	var imgPostit = document.getElementById('imgPostit');
	if(imgPostit) {
		var setpostop = parseInt(imgPostit.getAttribute('setpostop'));
		imgPostit.style.top = ( getTop(imgPostit) + setpostop ) + 'px';

		var setposleft = parseInt(imgPostit.getAttribute('setposleft'));
		//imgPostit.style.left = ( getLeft(imgPostit) + setposleft ) + 'px';

		imgPostit.style.visibility = 'visible';
	}
}




function init_menus() {

	window._menus = new Array();

	var divlist = document.getElementsByTagName('div');
	for(var i=0; i<divlist.length; ++i) {
		if(divlist[i].className == 'submenu') {
			window._menus[divlist[i].id] = new MainMenu(divlist[i]);
		}
	}


	var alist = document.getElementsByTagName('a');
	for(var i=0; i<alist.length; ++i) {
		if(alist[i].getAttribute('showmenu')) {

			if(alist[i].getAttribute('showmenu') == 'none') {
				alist[i].onmouseover = function() {
					hide_all_menus();
				}
			}
			else {
				alist[i].onmouseover = function() {
					window._menus[this.getAttribute('showmenu')].show_menu(this);
				}
				alist[i].onmouseout = function() {
					window._menus[this.getAttribute('showmenu')].start_hide_menu(this);
				}
			}
		}
	}

	for(var i in window._menus) {
		window._menus[i].init();
	}
}

function MainMenu(div) {
	this.div = div;
	this.id = div.id;
	this.timer;


	this.init = function() {
		var tdlist = this.div.getElementsByTagName('td');
		for(var n=0; n<tdlist.length; ++n) {

			tdlist[n].setAttribute('menuid', this.id);

			tdlist[n].onclick = function() {
				document.location = this.childNodes[0].href;
			}

			tdlist[n].onmouseover = function() {
				var menuid = this.getAttribute('menuid');
				window._menus[menuid].menu_item_over(this);
			}

			tdlist[n].onmouseout = function() {
				var menuid = this.getAttribute('menuid');
				window._menus[menuid].menu_item_out(this);
			}
		}

	}

	this.show_menu = function(a) {
		hide_all_menus();
	
		this.div.style.left = getLeft(a) + 'px';
		this.div.style.top = ( getTop(a) + a.offsetHeight + 0 ) + 'px';
		this.div.style.visibility='visible';
		this.clear_menu_timer();
	}


	this.start_hide_menu = function() {
		var timeout = 1000;

		this.clear_menu_timer();
		this.timer = setTimeout("window._menus['"+this.id+"'].do_hide_menu();", timeout);
	}

	this.do_hide_menu = function() {
		this.div.style.visibility = 'hidden';

	}

	this.clear_menu_timer = function() {
		clearTimeout(this.timer);
	}

	this.menu_item_over = function(that) {
		this.clear_menu_timer();
		that.className = 'hover';
	}

	this.menu_item_out = function(that) {

		that.className = '';


		// start hiding the menu 
		this.start_hide_menu();


	}

}

function hide_all_menus() {
	for(var k in window._menus) {
		window._menus[k].do_hide_menu();
	}
}















function loadRolloverImages() {

	var allimgs = document.getElementsByTagName('img');
	for(var i=0; i<allimgs.length; ++i) {
		if(allimgs[i].getAttribute('hoversrc')) {
			_loadRolloverImage(allimgs[i]);
		}
	}

	var allinputs = document.getElementsByTagName('input');
	for(var i=0; i<allinputs.length; ++i) {
		if(allinputs[i].getAttribute('hoversrc')) {
			_loadRolloverImage(allinputs[i]);
		}
	}

}

function _loadRolloverImage(img) {
	preloadImage(img.getAttribute('hoversrc'));

	img.onmouseover = function() {
		var src = this.getAttribute('src');
		if(src) {
			this.setAttribute('__src_orig', src);
			this.setAttribute('__filter_orig', this.style.filter);

			if(this.style.filter && navigator.userAgent.toUpperCase().indexOf('MSIE') >= 0) {
				this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.getAttribute('hoversrc')+"', sizingMethod='scale')";
			} else {
				this.setAttribute('src', this.getAttribute('hoversrc'));
			}
		}
	};
	img.onmouseout = function() {
		var src = this.getAttribute('__src_orig');
		if(src) {
			if(this.style.filter && navigator.userAgent.toUpperCase().indexOf('MSIE') >= 0) {
				this.style.filter = this.getAttribute('__filter_orig');
			} else {
				this.setAttribute('src', src);
			}
		}
	};

}

function preloadImage(href) {
	if(!window.preloadImageList) window.preloadImageList = new Array();
	var i = window.preloadImageList.length;

	window.preloadImageList[i] = new Image();
	window.preloadImageList[i].src = href;
}


function popupWin(that, w, h, options) {
	if(!w) w = 500;
	if(!h) h = 500;

	var x = (screen.availWidth - w) / 2;
	var y = (screen.availHeight - h) / 2;

	if(!options) options = '';

	var optslist = new Array();
	optslist[optslist.length] = 'width='+w;
	optslist[optslist.length] = 'height='+h;
	optslist[optslist.length] = 'scrollbars=auto';
	optslist[optslist.length] = 'resizable=yes';
	optslist[optslist.length] = 'left='+x;
	optslist[optslist.length] = 'top='+y;

	var bits = options.split(/,/);
	for(var i=0; i<bits.length; ++i) {
		var b = bits[i].split(/=/);
		optslist[optslist.length] = b[0] + '=' + b[1];
	}
	var optionstring = optslist.join(',');



	var href;
	if(that.href) href = that.href;
	else href = that;

	var win = window.open(that.href, 'popwin', optionstring);

	win.resizeTo(w, h);
	win.focus();

	return false;
}

function getLeft(obj) {
	return (obj.offsetParent==null ? obj.offsetLeft : obj.offsetLeft + getLeft(obj.offsetParent));
}
function getTop(obj) {
	return (obj.offsetParent==null ? obj.offsetTop : obj.offsetTop + getTop(obj.offsetParent));
}

// error class
function Errors() {
	this.errors = new Array();

	this.add = function(msg) {
		this.errors[this.errors.length] = msg;
	}
	this.alert = function() {
		if(!this.errors.length) return false;

		var msg = 'The following error(s) have occurred:\n\n';

		for(var i=0; i<this.errors.length; ++i) {
			msg += '*  ' + this.errors[i];
			if(i < this.errors.length - 1) msg += '\n\n';
		}

		alert(msg);
		return true;
	}
}

function validate_email(email) {
	if(email.length <= 5) return false;
	if(email.indexOf('@', 0) == -1) return false;
	return true;
}

function validate_newsletter(f) {
	var e = new Errors();
	if(!validate_email(f.email.value)) e.add("Sorry, Invalid Email Address!");

	return e.alert() ? false : true;
}


function tell_a_friend_link() {
	var a = document.getElementById('tell_a_friend_link');
	if(!a) return;

	//var title = document.title.substr(0, document.title.indexOf(' - '));
	var title = document.title;

	if(a.href.indexOf('?') > -1) a.href += '&';
	else a.href += '?';
	a.href += 'page_title=' + escape(title);
}



//// Print image 
function makepage(src)
{

  return "<html>\n" +
    "<head>\n" +
    "<title>Temporary Printing Window</title>\n" +
    "<script>\n" +
    "function step1() {\n" +
    "  setTimeout('step2()', 10);\n" +
    "}\n" +
    "function step2() {\n" +
    "  window.print();\n" +
    "  window.close();\n" +
    "}\n" +
    "</scr" + "ipt>\n" +
    "</head>\n" +
    "<body onLoad='step1()'>\n" +
    "<img src='" + src + "'/>\n" +
    "</body>\n" +
    "</html>\n";
}

function printme(evt)
{
  if (!evt) {
    // Old IE
    evt = window.event;
  }    
  var image = evt.target;
  if (!image) {
    // Old IE
    image = window.event.srcElement;
  }
  src = image.src;
  link = "about:blank";
  var pw = window.open(link, "_new");
  pw.document.open();
  pw.document.write(makepage(src));
  pw.document.close();
}


