﻿// JScript File

String.prototype.startsWith = function (s) {
	return (this.substring(0, s.length) == s);
};

$(
	function()
	{
		// hide the video
		$('#video-container').css( { visibility: 'hidden' } );
		
		// show a modal dialog to collect contact information
		var dlg = $('#contact-form').dialog({ modal: true, closeOnEscape: false, width: 400 });
		dlg.parent().appendTo($('form:first'));
		
		// disable the ability to close the dialog in the title bar
		$('.ui-dialog-titlebar-close').hide();
		
		// if the form needs to be pre-populated, do so
		if (/(&|\?)email=/.test(location.search))
		{
			var pairs = location.search.substring(1, location.search.length).split('&');
			for (var i = 0; i < pairs.length; i++)
			{
				if (pairs[i].startsWith('firstName='))
					$('#' + gFirstNameElementId).val(pairs.substring(10));
					
				if (pairs[i].startsWith('lastName='))
					$('#' + gLastNameElementId).val(pairs.substring(9));
				
				if (pairs[i].startsWith('email='))
					$('#' + gEmailElementId).val(pairs.substring(6));
				
				if (pairs[i].startsWith('zip='))
					$('#' + gZipCodeElementId).val(pairs.substring(4));
			}
			
			$('#contact-form p:first-child').html('Please confirm your information before viewing this video.');
		}
		
//		$.closeDialog = function() {
//			$('#contact-form').dialog('close');
//			$('#video-container').css( { visibility: 'visible' } );
//		};
	}
);