$(document).ready(function() {
	all_funcs();
	send();
	feedback();
});

function all_funcs()
{
	/*$("#formwrap").draggable({
		revert: 'invalid'
	});*/
		
	$("#dc").click(function (event) {
		event.preventDefault();
		$("#overlay").css("display","block");
		$("#doc_fac").css("display","block");
	});
	$("#pcm").click(function (event) {
		event.preventDefault();
		$("#overlay").css("display","block");
		$("#cash_man").css("display","block");
	});
	
	$("#os").click(function (event) {
		event.preventDefault();
		$("#overlay").css("display","block");
		$("#other_services").css("display","block");
	});
	
	$(".msg_box").click(function () {
		$("#doc_fac").css("display","none");
		$("#cash_man").css("display","none");
		$("#other_services").css("display","none");
		$("#msgwrap").css("display","block");
	});
	
	$(".s3sliderImage a").click(function () {
		$fill_text = $(this).attr("title");
		$("#overlay").css("display","block");
		$("#formwrap").css("display","block");
		
		$("#label").html("Item:");
		$("#item").attr("readOnly",true);
		$("#item").val($fill_text);
	});
	
	$("#buy_cash").click(function () {
		$("#overlay").css("display","block");
		$("#cash_gift").css("display","none");
		$("#formwrap").css("display","block");
		
		$("#label").html("Cash amount:");
		$("#item").attr("readOnly",false);
	});
	
	$("#buy_items").click(function () {
		$("#overlay").css("display","block");
		$("#non_cash_gift").css("display","none");
		$("#formwrap").css("display","block");
		
		$("#label").html("Indicate your item:");
		$("#item").attr("readOnly",false);
	});
	
	$(".close_icon").click(function () {
		$("#overlay").css("display","none");
		$("#formwrap").css("display","none");
		$("#msgwrap").css("display","none");
		
		$("#cash_gift").css("display","none");
		$("#non_cash_gift").css("display","none");
		$("#doc_fac").css("display","none");
		$("#cash_man").css("display","none");
		$("#other_services").css("display","none");
		
		$("#item").val("");
		$("#send_to_name").val("");
		$("#send_to_no").val("");
		
		$("#label").html("Item:");
		$("#item").attr("readOnly",true);
	});
	
	$("#cg").click(function (event) {
		event.preventDefault();
		$("#overlay").css("display","block");
		$("#cash_gift").css("display","block");
	});
	$("#ncg").click(function (event) {
		event.preventDefault();
		$("#overlay").css("display","block");
		$("#non_cash_gift").css("display","block");
	});
}

function feedback()
{
	$("#msgForm").submit(
		function (event) {
			event.preventDefault();
			// collect form data
			$your_name = $("#fullname").val();
			$email = $("#email").val();
			$country = $("#country").val();
			$phone_no = $("#pri_phone").val();
			$msg = $("#msg").val();
			//call ajax to send
			$.post('ajax/feedback.php', {name: $your_name, email: $email, country: $country, phone_no: $phone_no, msg: $msg}, function(data) {
				if(data == 1)
				{
					// display success message
					alert("Message sent sucessfully!!");
					// hide dialog
					$("#overlay").css("display","none");
					$("#msgwrap").css("display","none");
				}
				else
					alert(data);
			});
		}
	);
}

function send()
{
	$("#sendForm").submit(
		function (event) {
			event.preventDefault();
			// collect form data
			$your_name = $("#fullname").val();
			$email = $("#email").val();
			$country = $("#country").val();
			$phone_no = $("#pri_phone").val();
			$alt_no = $("#sec_phone").val();
			$item = $("#item").val();
			$send_to_name = $("#send_to_name").val();
			$send_to_no = $("#send_to_no").val();
			$send_to_alt_no = $("#send_to_alt_no").val();
			$msg = $("#msg").val();
			//call ajax to send
			$.post('ajax/send.php', {name: $your_name, email: $email, country: $country, phone_no: $phone_no, alt_no: $alt_no, item: $item, send_to_name: $send_to_name, send_to_no: $send_to_no, send_to_alt_no: $send_to_alt_no, msg: $msg}, function(data) {
				if(data == 1)
				{
					// display success message
					alert("Message sent sucessfully!!\r\nWe will contact you by phone");
					// hide dialog
					$("#overlay").css("display","none");
					$("#formwrap").css("display","none");
					// clear change values
					$("#item").val("");
					$("#send_to_name").val("");
					$("#send_to_no").val("");
				}
				else
					alert(data);
			});
		}
	);
}
