﻿var SiteHelper = {
	initialize: function () {
		var self = this;
		
		$('#customer_service').click(function (e) { self.openCs(e) });
		$('#fp_help').click(function (e) { self.openHelp(e) });
		$('#email_friend').click(function (e) { self.openEmail(e) });
	},

	exitSite: function (from, destination, windowName, options, goesto, pid, sSite) {
		while (destination.indexOf('+') != -1)
			destination = destination.replace('+', 'FPSMBplusFPSMB');
	
		if (destination.indexOf("golink.asp") != -1)
			newWindow = window.open(destination + '&FPFrom=' + from, windowName, options);
		else
			newWindow = window.open('/' + sSite + '/leaving.asp?FPDest=' + escape(destination) + '&FPFrom=' + escape(from) + '&goto=' + escape(goesto) + '&pid=' + pid, windowName, options);
	},
	
	openEmail: function (e) {
		e.preventDefault();
		window.open(this.href, 'emailWindow', 'left=150,top=50,screenX=200,screenY=100,resizable=yes,scrollbars=yes,toolbar=no,width=500,height=560');
	},
	
	openHelp : function (e) {
		e.preventDefault();
		window.open(this.href, 'fphelp', 'left=5,top=10,screenX=100,screenY=100,resizable=yes,location=yes,scrollbars=yes,toolbar=yes,menubar=yes,width=790,height=470');
	},

	openCs : function (e) {
		e.preventDefault();
	
		thisHref = $('#customer_service').attr('href');
		thisSite = thisHref.match(/(\w{1,})(?=\/default)/g)[0];
		this.exitSite('/'+thisSite+'/default.asp?', thisHref, 'MATTELCR', 'left=5,top=10,screenX=100,screenY=100,resizable=yes,location=yes,scrollbars=yes,toolbar=yes,menubar=yes,width=790,height=470', 'Customer Service', '-1', thisSite);
	},
	
	validateSearch: function (default_text, options) {
		var defaults = {
			error_tooltip: true
		};
		
		var opts = $.extend({}, defaults, options);
		
		$('#search input[name=\'keyword\']').focus(function () {
			var $this = $(this);
			if ($.trim($this.val()) == default_text) {
				$this.val('');
			}
		});
		
		$('#search').submit(function () {
			var $form = $(this);
			var $keyword = $('input[name=\'keyword\']', $form);
			if ($.trim($keyword.val()) != default_text && $keyword.val() != '') {
				return true;
			} else {
				$keyword.focus();
				if (opts.error_tooltip) {
					$.getUniqueScript('/pages/v6/script/jquery/jquery.fp.plugin.tooltip.js', function () {
						$form.tooltip('Search word(s) or item #', { name: 'search', corner: true });
					});
				}
				return false;
			}
		});
	}
}

$(document).ready(function () {
	SiteHelper.initialize();
});