﻿/// <reference path="jquery-1.3.2-intellisense.js" />
//http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx

$(document).ready(function () {

    //force https
    //if (location.href.indexOf("http://localhost") == -1 && location.href.indexOf("https://") == -1) {
    //    location.href = location.href.replace("http://", "https://");
    //}

    $aksi = $('#aksi');
    $yuib = $('.yui-b');

    $yuib.corner();

    $('a#help').click(function(e) {
        return switchInterface();
    });

    $BCari = $('#BCari');
    $BCari.click(function() {
    	$BCari.attr("value", "Checking...");
    	$BCari.attr("disabled", "disabled");
    	$BCari.attr("class", "disabled");
        semakCukai();
    });

    $('#form').keypress(function (e) {
        if (e.which == 13) {
            $BCari.attr("value", "Checking...");
            $BCari.attr("disabled", "disabled");
            $BCari.attr("class", "disabled");
            semakCukai();
        }
    });


});


function laporProblem() {

    
    $emailTitle = $.trim($('#emailTitle').val());
    $emailAddress = $.trim($('#emailAddress').val());
    $emailContent = $.trim($('textarea[name="emailContent"]').val());

    if ($emailAddress == "" || $emailContent == "" || $emailTitle == "") {
        $("#feedback").effect("highlight", {}, 1500);
	$BLapor.attr("value", "Lapor Masalah/Tanya Soalan");
	$BLapor.removeAttr('disabled');
	$BLapor.removeAttr("class");  
    } else {
        $.ajax({
            type: "POST",
            url: "Contact.svc/MDKS",
            data: '{"emailTitle":"' + $emailTitle + '", "senderEmail":"' + $emailAddress + '", "emailText":"' + $emailContent + '"}',
            contentType: "application/json",            
            dataType: "json",
            success: function(data) {
                //console.log(data);
                if (data.d == "SENT") {  //email sent
                    $("#feedback").text("Masalah/Pertanyaan anda sudah dihantar kepada MDKS");
                    $("#feedback").css("color", "Green");
                    $("#feedback").effect("highlight", {}, 1500);
		    $BLapor.attr("value", "Laporan/Pertanyaan diterima.");
                } else {
                    $("#feedback").text("Gagal menghubungi MDKS, harap maaf. " + data.d);
                    $("#feedback").css("color", "Red");
                    $("#feedback").effect("highlight", {}, 1500);
		    $BLapor.attr("value", "Lapor Masalah/Tanya Soalan");
		    $BLapor.removeAttr('disabled');
		    $BLapor.removeAttr("class");    
                }                
            }
        });
    }

    

}

function semakCukai() {


    $noAkaun = $.trim($('#noAkaun').val());
    $fullName = $.trim($('#Nama').val());

    if ($noAkaun == "") $noAkaun = "null";
    if ($fullName == "") $fullName = "null";

    $.getJSON("Taksiran.svc/IsAccountExist/" + $noAkaun + "/" + $fullName,
            null,
            function(data) {
		$BCari.attr("value", "Semak Cukai");
		$BCari.removeAttr('disabled');
		$BCari.removeAttr('class');
                if (data.IsAccountExistResult.toString() != "NOTEXIST") {  //the account exist, display it
                    $('#noAkaun').val(data.IsAccountExistResult.toString());
                    document.forms[0].submit();
                } else {
                    $("#answers")
                        .text("Akaun tersebut tidak dijumpai, sila semak nombor akaun/nama atau laporkan kepada MDKS.")
                        .effect("highlight", {}, 1500);
					/*$("#answers")
						.text("Akaun tuan tidak mempunyai sebarang tunggakan, kami masih sedang menguji sistem untuk memaparkan transaksi terkini akaun tuan.")
						.effect("highlight", {}, 1500);*/
                }
            });

}

function switchInterface() {
	if ($aksi.is(":hidden")) {
		$aksi.load('problem.html', null, function() {
			$yuib.fadeOut("fast", function() {
				$aksi.fadeIn("fast");
			});						
		});		
	} else {
		$aksi.fadeOut("fast", function() {
			$yuib.fadeIn("fast");			
		});			
	}

	return false;	//return false will stop both default action (e.preventDefault) and event bubbling (e.stopPropagation)
}
