$(function(){

    var text_alert_email = $('#email').attr("title");
    var text_alert_confirm_email = $('#confirm_email').attr("title");
    if($('#email').val() == ""){
        $('#email').val(text_alert_email);
    }
    if($('#confirm_email').val() == ""){
        $('#confirm_email').val(text_alert_confirm_email);
    }
    // remove instruction for keywords.
    $('#email').focus(function(){
        if($(this).val() == text_alert_email){
            $(this).val("");
        }
    }).blur(function(){
        if($(this).val() == ""){
            $(this).val(text_alert_email);
        }
    });
    $('#confirm_email').focus(function(){
        if($(this).val() == text_alert_confirm_email){
            $(this).val("");
        }
    }).blur(function(){
        if($(this).val() == ""){
            $(this).val(text_alert_confirm_email);
        }
    });
    $('.alert').submit(function(){
        if($('#email').val() == text_alert_email){
            $('#email').val("");
        }
        if($('#confirm_email').val() == text_alert_confirm_email){
            $('#confirm_email').val("");
        }
    });

    $('a.round_corner').corner("round 10px");

    var current;
    var next;
    var FF_block = "display: block;";
    var IE_block = "DISPLAY: block";
    if($("div#premier").attr("style") == FF_block || $("div#premier").attr("style") == IE_block){
        current = $("div#premier");
    }else{
        $("div#premier").hide();
        if($("div#deuxieme").attr("style") == FF_block || $("div#deuxieme").attr("style") == IE_block){
            current = $("div#deuxieme");
        }else{
            $("div#deuxieme").hide();
            if($("div#troisieme").attr("style") == FF_block || $("div#troisieme").attr("style") == IE_block){
                current = $("div#troisieme");
            }else{
                $("div#troisieme").hide();
                current = $("div#quatrieme");
            }
        }
    }

    $("div#navigation ul li a").click(function() {
        next = $("div"+$(this).attr("href"));
        current.fadeOut(700, function() {
            current = next;
            current.fadeIn(700);
            });
        return false;
    });


    $('form#inquiry').submit(function(){
            $('#notice').html('');
            var req = 'The following fields are required :';
            var send = true;

            if($('#author').val() == '') {
                req += ' - name';
                send = false;
            }
            if($('#email').val() == '') {
                req += ' - email';
                send = false;
            }
            if($('#phone').val() == '') {
                req += ' - phone';
                send = false;
            }
            if($('#disclaimer:checked').val() != 'yes') {
                req += ' - disclaimer';
                send = false;
            }
            req += '.';

            if (send == false) {
                $('#notice').html(req);
            } else {
                var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                var filter2=/^([0123456789 \.\-\(\)\+_]*)$/i
                if (filter.test($('#email').val())) {
                    if (filter2.test($('#phone').val())) {
                        $(this).ajaxSubmit(function(data) {
                                if (data.status == 'success') {
                                    $('#inquiry_form').html(data.message);
                                } else {
                                    $('#notice').html(data.message);
                                }
                        });
                    } else{
                        alert("Please input a valid phone number");
                    }
                } else{
                    alert("Please input a valid email address");
                }
            }

            // Prevent normal submit
            return false;
    });



    $('form#inquiryrf').submit(function(){
            $('#notice').html('');
            var req = 'The following fields are required :';
            var send = true;

            if($('#fullname').val() == '') {
                req += ' - fullname';
                send = false;
            }
            if($('#email').val() == '') {
                req += ' - email';
                send = false;
            }
             if($('#phone').val() == '') {
                req += ' - phone';
                send = false;
            }
            if($('#city').val() == '') {
                req += ' - city';
                send = false;
            }
            if($('#budget').val() == '') {
                req += ' - budget';
                send = false;
            }
            if($('#disclaimer:checked').val() != 'yes') {
                req += ' - disclaimer';
                send = false;
            }

            req += '.';

            if (send == false) {
                $('#notice').html(req);
            } else {
                var filter =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
                var filter2=/^([0123456789 \.\-\(\)\+_]*)$/i
                if (filter.test($('#email').val())) {
                    if (filter2.test($('#phone').val())) {
                        $(this).ajaxSubmit(function(data) {
                                var json = eval('(' + data + ')');
                                if (json.status == 'success') {
                                    $('#inquiry_form').html(json.message);
                                } else {
                                    $('#notice').html(json.message);
                                }
                        });
                    } else{
                        alert("Please input a valid phone number")
                    }
                } else{
                    alert("Please input a valid email address")
                }
            }

            // Prevent normal submit
            return false;
    });

});
