function addEvent(obj, eventType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(eventType, fn, useCapture);
		return true;
	} else {
		if (obj.attachEvent) {
			var r = obj.attachEvent("on"+eventType, fn);
			return r;
		}
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var a = document.getElementsByTagName("a");
	for (var i = 0; i < a.length; i++) {
		var link = a[i];
		if (link.getAttribute("href") && link.getAttribute("rel") == "external") {
			link.target = "_blank";
		}
	}
}
addEvent(window, "load", externalLinks);

function productFinder(f) {
	if (!document.getElementById) return;
	var bakery        = new Array("Endload", "Topload", "VFFS", "Wraparound");
	var confectionery = new Array("Endload", "Topload", "VFFS");
	var contract      = new Array("Endload", "Topload", "VFFS", "Wraparound");
	var dairy         = new Array("Endload", "Trolley Loaders", "VFFS", "Wraparound");
	var frozen        = new Array("Endload", "Topload", "VFFS", "Wraparound");
	var nonfood       = new Array("Endload", "Topload", "VFFS", "Wraparound");
	var snackfood     = new Array("Display Card Loader", "VFFS");

	var opt = eval(f[f.selectedIndex].value);
	var searchProduct = document.getElementById("search-product");
	searchProduct.length = 0;
	searchProduct.options[0] = new Option("Select Product Type...", "");

	for (var i = 0, j = 1; i < opt.length; i++, j++) {
		searchProduct.options[j] = new Option(opt[i], opt[i].toLowerCase().replace(/[^A-z]g/, ""));
	}
}

function validateContactForm(f) {
	var errors = new Array();
	if (isEmpty(f.elements["items[First_Name]"].value)) {
		errors.push("First name missing");
	}
	
	if (isEmpty(f.elements["items[Last_Name]"].value)) {
		errors.push("Last name missing");
	}
	
	if (isEmpty(f.elements["items[Phone]"].value)) {
		errors.push("Phone number missing");
	}
	
	if (isEmpty(f.elements["email"].value)) {
		errors.push("Email missing");
	} else if (!isValidEmail(f.elements["email"].value)) {
		errors.push("Email must be valid (format: username@example.com)");
	}
	
	return !errorAlert(errors);
}


function videoPopup(videofile) {
   var w = window.open("/products/video/player.aspx?video=" + videofile, "video", "height=410,width=370,scrollbars=0,resizable=0");
///products/video/player.aspx?video=
	}
	
	
	// Functions related to display of the flash splash page
	
	/* Cookie plugin usage:
	$.cookie('the_cookie'); // get cookie
	$.cookie('the_cookie', 'the_value'); // set cookie. No expiry date makes it a 'session' cookie
	$.cookie('the_cookie', 'the_value', { expires: 7 }); // set cookie with an expiration date seven days in the future
	$.cookie('the_cookie', null); // delete cookie
	*/
	
	// Check to see if the cookie is setActive
	/*
	if (!$.cookie('kliksplash')) {
		//$.cookie('kliksplash', '1'); // expires when session ends
		$.cookie('kliksplash', '1', { expires: 7 });
		location.href='splash';
	}
	*/
	
	
