$(document).ready(function(){
	$.ajaxSetup({
		error:function(x,e){
			if(x.status==0){
			alert('You are offline!!\n Please Check Your Network.');
			}else if(x.status==404){
			alert('Requested URL not found.');
			}else if(x.status==500){
			alert('Internel Server Error.');
			}else if(e=='parsererror'){
			alert('Error.\nParsing JSON Request failed.');
			}else if(e=='timeout'){
			alert('Request Time out.');
			}else {
			alert('Unknow Error.\n'+x.responseText);
			}
		}
	});

	$('#dialogSubscribe').dialog( {
		autoOpen:false,
		modal:true,
		resizable: false,
		width: 450
	});

	$('#subscribe').click(function(){		
		$('#resultSubscribe').html("");
		$("#formSubscribe").show();
		$('#dialogSubscribe').dialog('open');
		return false;
	});

});

function submitComment() {
	$('#resultComment').html("");
	$.post(
		'/ajax/submit-comment.php',
		$("form#formComment").serialize(),
		function(response){
			$('#resultComment').html(response['message']);
			if(response['result']==true) {
				$("#formComment").hide();
			}
		},
		"json"
	);
}

function subscribe() {
	$('#resultSubscribe').html("");
	$.post(
		'/ajax/subscribe.php',
		$("form#formSubscribe").serialize(),
		function(response){
			$('#resultSubscribe').html(response['message']);
			if(response['result']==true) {
				$("#formSubscribe").hide();
			}
		},
		"json"
	);
}
