/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var oTable;

$(document).ready(function(){

    var currentYear = (new Date).getFullYear();
    $("#footer").text("Copyright, "+currentYear+" REALTY INTERNATIONAL ASSOCIATES PTE LTD");

    $("#contact_form").dialog({
        autoOpen: false,
        height: 500,
        width: 400,
        modal: true,
        buttons: {
            Send: function() {
                if(My_Validation_Contact_Us()){
                    $.ajax({
                        type: "POST",
                        url: "servlet_contact_us",
                        dataType:"json",
                        data:$("#form_contact").serialize(),
                        success:function(){
                        },
                        error:function (xhr, ajaxOptions, thrownError){
                            alert("xhr.status: "+xhr.status+"<br />thrownError: "+thrownError+"<br />ajaxOptions: "+ajaxOptions);
                        }
                    });
                    $(this).dialog('close');
                }
            },
            Cancel: function() {
                $(this).dialog('close');
            }
        }
    });

    $("#menu_home").click(function(){
        $("#div_contain").load("home.jsp", function(){
            $('#slider').nivoSlider();
        });
    });

    $("#menu_home").click();

    $("#menu_valuation").click(function(){
        $("#div_contain").load("valuation.jsp");
    });

    $("#menu_project_management").click(function(){
        $("#div_contain").load("project_management.jsp", function(){
            $('#slider').nivoSlider();
        });
    });

    $("#menu_home_warranty_plan").click(function(){
        $("#div_contain").load("home_warranty_plan.jsp", function(){
            $('#faq').makeFAQ();
        });
    });

    $("#menu_water_proofing").click(function(){
        $("#div_contain").load("water_proofing.jsp");
    });

    $("#menu_contact_us").click(function(){
        $("#div_contain").load("contact.jsp");
    });

    $("#menu_estate_management").click(function(){
        $("#div_contain").load("estate_management.jsp", function(){
            $.ajax({
                type: "POST",
                url: "servlet_estate_management_list",
                dataType:"json",
                success:function(response){
                    $("#div_property").text("");
                    $.each(response, function(){
                        $("#div_property").append("<a href='#' onclick=\"Property('"+this.project+"');\">"+this.project+"</a><br/>");
                    });
                },
                error:function (xhr, ajaxOptions, thrownError){
                    alert("xhr.status: "+xhr.status+"<br />thrownError: "+thrownError+"<br />ajaxOptions: "+ajaxOptions);
                }
            });
        });
    });
    
});

function Property(prop)
{
    $("#div_contain").load("estate_detail.jsp", function(){

        var temp = prop.ReplaceAllString(" ", "%20");

        $.ajax({
            type: "POST",
            url: "servlet_estate_management_form",
            dataType:"json",
            data:"property="+prop,
            success:function(response){
                $("#div_form").text("");
                $.each(response, function(){
                    $("#div_form").append("<a href='#' onclick=\"File('"+prop+"', '"+this.file+"');\">"+this.file+"</a><br/>");
                });
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert("xhr.status: "+xhr.status+"<br />thrownError: "+thrownError+"<br />ajaxOptions: "+ajaxOptions);
            }
        });

        $.ajax({
            type: "POST",
            url: "servlet_estate_management_image_list",
            dataType:"json",
            data:"property="+prop,
            success:function(response){
                $("#slider").text("");
                $.each(response, function(){
                    $("#slider").append("<img src='estate_management_images/"+temp+"/"+this.image+"' alt='' />");
                });
                $('#slider').nivoSlider();
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert("xhr.status: "+xhr.status+"<br />thrownError: "+thrownError+"<br />ajaxOptions: "+ajaxOptions);
            }
        });

        $("#div_description").load("estate_management_details/"+temp+".txt");

        $("#property_header").text(prop);
    });
}

function File(prop, file)
{
    window.open("estate_management_form/"+prop+"/"+file);
}

function My_Validation_Contact_Us()
{
    var result = true;
    result = result & $("#text_subject").CheckEmpty();
    result = result & $("#text_name").CheckEmpty();
    result = result & $("#text_email").CheckEmail();
    result = result & $("#text_tel").CheckEmpty();
    result = result & $("#text_message").CheckEmpty();
    return result;
}
