function isBotBootValid(c){
	var d = $('#botBootInput').val();
	if (d == c) {
		$('#frm').attr('action','process.php');
		return true;
	}
	return false;	
}

function subscribe(lang){
	var dialog = $('#dialog1').overlay({
		oneInstance: false, 
		api: true,
		expose: { 
			color: '#333', 
			loadSpeed: 200, 
			opacity: 0.9
		}, 		 
		closeOnClick: true,
		closeOnEsc: true
	});
	var dialog_result = $('#dialog1_result').overlay({
		oneInstance: false, 
		api: true,
		expose: { 
			color: '#333', 
			loadSpeed: 200, 
			opacity: 0.9
		}, 		 
		closeOnClick: true,
		closeOnEsc: true
	});
	
	var triggers = $('.modalInput').click(function(e){									
		var a = Math.ceil(Math.random() * 10);
		var b = Math.ceil(Math.random() * 10);       
		captcha = a + b;
		
		var htmlCaptcha='<label for="botBootInput" id="lblBotBootInput"></label><br/>';
		htmlCaptcha+='<input type="text" size="2" maxlength="2" class="text" id="botBootInput" name="botBootInput"/>';
		htmlCaptcha+='<input type="hidden" name="ajax" value="1"/>';
		$('#captcha').html(htmlCaptcha);
		
		var link = this.href;
		lang = (this.href.substring(7,9) != '' ? this.href.substring(7,9) : 'en');
		setLabelLang(lang);

		$('#lblBotBootInput').html(labels.lblHowMuchIs);
		$('#lblBotBootInput').html($('#lblBotBootInput').html() +' '+ a +' + '+ b +'?');
		
		dialog.load();		
		return e.preventDefault(); 
	});
	
	$('#btnFrmSubmit').click(function(e){		
		if (isBotBootValid(captcha)) {
			$.ajax({  
				type: "POST",  
				url: $('#frm').attr('action'),  
				data: $('#frm').serialize(),
				dataType: "json",
				cache: true,
				success: function(json){			
					dialog.close();
					if (json.response.code == 200) {
						dialog_result.load();
						e.preventDefault();
					}
				},
				failure: function(json){
					//alert('failure: ' + json);
				}
			});		
		}									  
		return e.preventDefault(); 
	});
	
	$('#btnFrmCancel').click(function(e){
		return e.preventDefault(); 								  
	});
	$('#btnResClose').click(function(e){
		dialog_result.close();
		return e.preventDefault(); 
	});
}
