var last_qstring;

Event.observe(window,"load", function() {
	$$(".default").invoke("observe","focus", function(ev) {
		el = ev.element();
		if (el.value == el.defaultValue)
			el.value = "";
	});
	$$(".default").invoke("observe","blur", function(ev) {
		el = ev.element();
		if (el.value == "")
			el.value = el.defaultValue;
	});	
	$$("#bottle_search").invoke("observe","submit", function(ev) {
		ev.stop();
		reSearch();
	});
	$$("#bottle_search").invoke("observe","reset", function(ev) {
		setTimeout('reSearch();',500);
	});
	
	$$("#login_form").invoke("observe","submit", function(ev) {
		ev.stop();
		new Ajax.Updater("login_form","http://www2.berryplastics.com/modules/users/_ajax-login.php?email=" + escape($("email").value) + "&password=" + escape($("password").value));
	});
});

function reSearch() {
	qstring = "http://www2.berryplastics.com/modules/bottles/search.php?keywords=" + escape($("bottle_search").down("input").value) + "&";
	$$("#bottle_search select").each(function(el) {
		if (el.value)
			qstring = qstring + el.name + "=" + escape(el.value) + "&";
	});
	last_qstring = qstring;
	new Ajax.Updater("bottle_results",qstring);
}

function swapPage(page) {
	new Ajax.Updater("bottle_results",last_qstring + "page=" + page);
}

function popUp(id) {
	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	if (isIE6)
		features = 'location=0,statusbar=0,scrollbars=1,menubar=0,width=750,height=630';
	else
		features = 'location=0,statusbar=0,scrollbars=1,menubar=0,width=750,height=600';
	target = '_blank';
	var theWindow = window.open("http://www2.berryplastics.com/modules/bottles/view-bottle.php?id=" + id, target, features);
	theWindow.focus();
}

function popWindow(url) {
	isIE6 = /msie|MSIE 6/.test(navigator.userAgent);
	if (isIE6)
		features = 'location=0,statusbar=0,scrollbars=1,menubar=0,width=750,height=630';
	else
		features = 'location=0,statusbar=0,scrollbars=1,menubar=0,width=750,height=600';
	target = '_blank';
	var theWindow = window.open("http://www2.berryplastics.com/" + url, target, features);
	theWindow.focus();
}