// Promotions class
/// <reference path="global.js">
/// <reference path="classes/jquery-vsdoc.js">

var Promotions;
if (!Promotions) Promotions = {};

// Initializes the find product form
Promotions.initFindRebateForm = function() {
	var form = $id("frmFindRebate");
	if (form) {
		// Set change event for location drop-down box
		form.rdept.onchange = function() { form.submit(); }
		// Set submit event for form
		form.onsubmit = function() {
			if (form.rdept.value == '') {
				alert('Please select a department.');
				return false;
			} else return true;
		}
	}
}

// Initialize the change flyer form
Promotions.initChangeFlyerForm = function() {
	var topform = $id("frmChangeFlyer");
	if (topform) {
		topform.fid.onchange = function() {
			topform.p.value = "1";
			topform.submit();
		}
		topform.p.onchange = function() { topform.submit(); }
	}
	var bottomform = $id("frmChangeFlyerBottom");
	if (bottomform) {
		bottomform.p.onchange = function() { bottomform.submit(); }
	}
}

// Initializes events in the register promo form
Promotions.initRegisterPromoForm = function () {
	var cbNewsletter = $id("cbNewsletter");
	if (cbNewsletter) cbNewsletter.onclick = FormValidation.checkNewsletterCheckboxes;
}

Promotions.viewFlyer = function(id) {
	var popup = window.open('flyer_detail.aspx?fid=' + id,'FlyerViewer','width=800,height=650,resizable=yes,scrollbars=yes');
	if (window.focus) {
		popup.focus();
		if (popup != null) return false;
	}
}

Promotions.selectFlyer = function() {
	if (window.opener) {
		window.opener.location.href = '/promotions/';
		window.close();
	} else location.href = '/promotions/';
}

// OnLoad directive for this class
Promotions.onLoad = function() {
	if ($id("frmFindRebate")) Promotions.initFindRebateForm();
	if ($id("frmChangeFlyer")) Promotions.initChangeFlyerForm();
	if ($id("frmRegisterPromo")) Promotions.initRegisterPromoForm();
}

if (window.addEventListener) window.addEventListener("load", Promotions.onLoad, false);
else if (window.attachEvent) window.attachEvent("onload", Promotions.onLoad);
