// Thickbox for merchant applications
jQuery(document).ready(function() {
	var screenWidth = screen.availWidth;
	var screenHeight = screen.availHeight;
	var okScreenHeight = 960;
	if(screenHeight >= okScreenHeight) {
		jQuery("a.MerchantForm").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'overlayOpacity'		: 0.65,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500,
			'frameWidth'			: 650,
			'frameHeight'			: 600
		});
	}
	else {
		jQuery('a.MerchantForm').click(function() {
			var l = screenWidth/2-325;
			var t = screenHeight/2-250;
			window.open(this.href, 'merchantform', 'scrollbars=yes, width=650, height=500, left='+l+', top='+t);
			return false;
		});
	}

	// Thickbox for home page screenshots
	if(screenHeight >= okScreenHeight) {
		jQuery("a.HomeShot").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'overlayOpacity'		: 0.65,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500
		});
	}
	else {
		jQuery('a.HomeShot').click(function() {
			if(navigator.userAgent.indexOf('MSIE') >= 0) {
				var w = 780;
				var h = 570;
			}
			else {
				var w = 745;
				var h = 555;
			}
			var l = screenWidth/2-(w/2);
			var t = screenHeight/2-(h/2);
			window.open(this.href, 'homeshot', 'scrollbars=yes, width='+w+', height='+h+', left='+l+', top='+t);
			return false;
		});
	}

	// Thickbox for store designs
	if(screenHeight >= okScreenHeight) {
		jQuery("a.StoreTemplate").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'overlayOpacity'		: 0.65,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500
		});
	}
	else {
		jQuery('a.StoreTemplate').click(function() {
			if(navigator.userAgent.indexOf('MSIE') >= 0) {
				var w = 845;
				var h = 630;
			}
			else {
				var w = 835;
				var h = 615;
			}
			var l = screenWidth/2-(w/2);
			var t = screenHeight/2-(h/2);
			window.open(this.href, 'storetemplate', 'scrollbars=yes, width='+w+', height='+h+', left='+l+', top='+t);
			return false;
		});
	}

	// The tour video
		jQuery("a.VideoTour").fancybox({
			'zoomOpacity'			: true,
			'overlayShow'			: true,
			'overlayOpacity'		: 0.65,
			'zoomSpeedIn'			: 500,
			'zoomSpeedOut'			: 500,
			'frameWidth'			: 660,
			'frameHeight'			: 500
		});

		// The feature tour videos
			jQuery("a.VideoTourFeature").fancybox({
				'zoomOpacity'			: true,
				'overlayShow'			: true,
				'overlayOpacity'		: 0.65,
				'zoomSpeedIn'			: 500,
				'zoomSpeedOut'			: 500,
				'frameWidth'			: 660,
				'frameHeight'			: 530
			});

	// The trial form
	jQuery("a.FreeTrial").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: true,
		'overlayOpacity'		: 0.65,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500,
		'frameWidth'			: 660,
		'frameHeight'			: 470
	});

	// Getting started support videos
	jQuery("a.GettingStartedVideo").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: true,
		'overlayOpacity'		: 0.65,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500,
		'frameWidth'			: 860,
		'frameHeight'			: 700
	});

	// Merchant account form
	jQuery("a.MerchantForm").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: true,
		'overlayOpacity'		: 0.65,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500,
		'frameWidth'			: 450,
		'frameHeight'			: 350
	});

	// Support videos
	jQuery('a.SupportVideo').click(function() {
		if(navigator.userAgent.indexOf('MSIE') >= 0) {
			var w = 840;
			var h = 665;
		}
		else {
			var w = 820;
			var h = 660;
		}

		var l = screenWidth/2-(w/2);
		var t = screenHeight/2-(h/2);
		window.open(this.href, 'tourvideo', 'scrollbars=yes, width='+w+', height='+h+', left='+l+', top='+t);
		return false;
	});

	// KB articles
	jQuery('a.SupportKb').click(function() {
		var w = 650;
		var h = 550;
		var l = screenWidth/2-(w/2);
		var t = screenHeight/2-(h/2);
		window.open(this.href, 'supportkb', 'scrollbars=yes, width='+w+', height='+h+', left='+l+', top='+t);
		return false;
	});

	jQuery('#SupportBar .PopularSearches em a').click(function() {
		jQuery('#Query').val(jQuery(this).html());
		jQuery('#SearchForm').submit();
		return false;
	});

	jQuery('#SupportBar #Query').
		focus(function() {
			if(jQuery(this).data('custom') == undefined) {
				jQuery(this).data('oldValue', jQuery(this).val());
				jQuery(this).val('');
			}
		})
		.blur(function() {
			if(jQuery(this).val()) {
				jQuery(this).data('custom', 1);
			}
			else if(jQuery(this).data('oldValue')) {
				jQuery(this).val(jQuery(this).data('oldValue'));
			}
		})
	;

	// IE needs some Javascript to handle the menu mouse overs
	if(document.all) {
		jQuery('#Menu li').hover(function() {
			jQuery(this).addClass('Over');
		}, function() {
			jQuery(this).removeClass('Over');
		});
	}
	
	jQuery('#ecu_email').click(function() {
		if(jQuery(this).val() == 'Email Address') {
			jQuery(this).val('');
		}
	});

	jQuery('#EcuForm').submit(function() {
		if(jQuery('#ecu_email').val() == '' || jQuery('#ecu_email').val().indexOf('@') == -1 || jQuery('#ecu_email').val().indexOf('.') == -1) {
			alert('Please enter your email address.');
			jQuery('#ecu_email').focus().select();
			return false;
		}
		return true;
	});
});

function PlayVideo(url, width, height) {
	window.open(url, 'supportVideo', 'width='+width+', height='+height);
}


function PlayVideo(url, width, height) {
	window.open(url, 'supportVideo', 'width='+width+', height='+height);
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name) {
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
  return "";
}

