﻿$(function()
{
    // Date Picker
	$("#txtReservationDate").datePicker({createButton:false, horizontalOffset:-180, startDate:'01/01/2000'}).bind('click',
		function()
		{
			$(this).dpDisplay(this);
			return false;
		});
});

function SendService()
{
    // Resseting all
    $("#txtFirstName").css("backgroundColor", "");
    $("#txtTelephone1").css("backgroundColor", "");
    $("#txtTelephone2").css("backgroundColor", "");
    $("#txtFax").css("backgroundColor", "");
    $("#txtEmail").css("backgroundColor", "");
    $("#txtReservationDate").css("backgroundColor", "");
    
    var isValid = new Boolean(true);
 
    // Validating form   
    if (!$("#txtFirstName").validate("^.+$"))
    {
        $("#txtFirstName").blink();
        isValid = false;
    }
    if (!$("#txtTelephone1").validate("(\\d{2,3}-\\d{7})|(\\d{9,10})"))
    {
        $("#txtTelephone1").blink();
        isValid = false;
    }
    if (!$("#txtTelephone2").validate("(\\d{2,3}-\\d{7})|(\\d{9,10})*"))
    {
        $("#txtTelephone2").blink();
        isValid = false;
    }
    if (!$("#txtFax").validate("(\\d{2,3}-\\d{7})|(\\d{9,10})*"))
    {
        $("#txtFax").blink();
        isValid = false;
    }
    if (!$("#txtEmail").validate("\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))
    {
        $("#txtEmail").blink();
        isValid = false;
    }
    if (!$("#txtReservationDate").validate("(^((((0?[1-9]|[12]\\d|3[01])[\\.\\-\\/](0?[13578]|1[02])[\\.\\-\\/]((1[6-9]|[2-9]\\d)?\\d{2}))|((0?[1-9]|[12]\\d|30)[\\.\\-\\/](0?[13456789]|1[012])[\\.\\-\\/]((1[6-9]|[2-9]\\d)?\\d{2}))|((0?[1-9]|1\\d|2[0-8])[\\.\\-\\/]0?2[\\.\\-\\/]((1[6-9]|[2-9]\\d)?\\d{2}))|(29[\\.\\-\\/]0?2[\\.\\-\\/]((1[6-9]|[2-9]\\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\\d)?\\d{2}))|((0[1-9]|[12]\\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\\d)?\\d{2}))|((0[1-9]|1\\d|2[0-8])02((1[6-9]|[2-9]\\d)?\\d{2}))|(2902((1[6-9]|[2-9]\\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$)*"))
    {
        $("#txtReservationDate").blink();
        isValid = false;
    }
        
    // If valid, sending the form by AJAX to the server, and saying tnx
    if (isValid)
    {
        ShowBackground();
        
        $("#sendBtn").attr("href", "#");
        $("#sendBtn").attr("disabled", "disabled");
            
        AJAX.CustomerService($("#txtCustomerName").val(), $("#txtFirstName").val(), $("#txtLastName").val(), $("#txtAddress").val(), $("#txtTelephone1").val(), $("#txtTelephone2").val(), $("#txtFax").val(), $("#txtEmail").val(), $("#txtBoughtInStore").val(), $("#txtReservationNumber").val(), $("#txtReservationDate").val(), $("#txtFreeText").val(), SendService_Callback);
    }
}

function SendService_Callback(res)
{
    ShowPopUp(res.value);
}
