var signup = null;
var _isInternational = false;
		
window.addEvent('domready', function() {
	signup = new fValidator('signup_form'); 

	$('signup_form').addEvent('submit', function(e) {
		new Event(e).stop();
		
		var isMail = jQuery('#dm_mail').attr('checked');
				
		if(!$('over_13').checked) {
			alert("You must be over 13 years of age to request an informational packet");
			return;
		}	
			
		if(signup.isValid) {
		
			if(_isInternational)
				alert("Given that International Ship times are long (i.e. several weeks), packets can get lost in customs or experience other delays, we are making available to you an electronic version of our investor relations packet. In the event you would like us to mail you a physical packet, please send an email to dallas@zionoil.com requesting such.");
		
			this.send({
				onComplete: function(res) {
					$('signup_form').reset();
					tb_show('Signup Successful', '/free_offer/thanks.php?height=500&width=600&dm=' + (isMail ? 'm' : 'd'), null);
					jQuery('#TB_closeWindowButton').unbind('click').click(function() {
						window.location.href = '/';
						return false;
					});
				}
			});
		}
	});
});


jQuery(document).ready(function($) {
	initCountry();
	
	$('#countrySelect').change(function() {
		var country = $(this).val();
		switch(country)
		{
			case 'US':
			case 'CA':
				_isInternational = false;
				$('.delivery_method, .delivery_method_label').show();
				break;
			default:
				_isInternational = true;
				$('.delivery_method, .delivery_method_label').hide();
				$('#dm_download').attr('checked', true);
				break;
		}
		
		$('#dm_download').attr('checked', true);
	});
	
	var referral_source = getParameterByName('rs');
	if(referral_source != null && referral_source.length > 0) {
		$rsSelect = $('select[name="referral_source"]');
		
		switch(referral_source) {
			case 'wnd':
				$rsSelect.val('World Net Daily');
				break;
			case 'oii':
				$rsSelect.val('Oil In Israel');
				break;
		}
		
		$('.referral_source, .referral_source_header, .specific_source, .specific_source_header').hide();
	}
});

function getParameterByName(name) {
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.href);
	if (results == null)
		return "";
	else
		return results[1];
}
