
$(document).ready(function () {

    var currentColorScheme = "white";

    $("#browse_options").click(function(){
        if (currentColorScheme == "white") {
            changeBackground("orange"); 
        } else if (currentColorScheme == "orange") {
            changeBackground("orangered");
                $("#information_row").css('color', "white");
                $("#information_row a").css('color', "yellow");
        } else {
            changeBackground("white"); 
            $("#information_row").css('color', "black");
                $("#information_row a").css('color', "red");
        }
    });

    function changeBackground(color) {
        $("#information_row").css('background-color', color);
        currentColorScheme = color;           
    }

    $("#property_city").change(function(){
        var city = $(this).val();
        var built = $("#built").val();
        if (built == 'no') {
            var propUrl = 'http://'+document.domain+'/property/u'+city;
        } else {
            var propUrl = 'http://'+document.domain+'/property/'+city;
        }
        $.ajax({
          url: propUrl,
          success: function(data) {
            $('#property_table').html(data);
          },
          error: function(xmlRequest, textStatus, errorThrown) {
            $('#property_table').html('No property at the moment..');
          }
        });
    });

    $("#list_navigation").click(function(){
        /*
        var city = $(this).val();
        var propUrl = 'http://phpdebian/tn/appian/property/'+city;
        $.ajax({
          url: propUrl,
          success: function(data) {
            $('#property_table').html(data);
          }
        });
        */        
    });

    var city = $("#property_table").html();
    var propUrl = 'http://'+document.domain+'/property/'+city;
    if (city != null) {
        $.ajax({
          url: propUrl,
          success: function(data) {
            $('#property_table').html(data);
          }
        });
    }
    $('.submenu_item').mouseover(function(){
        $(this).css('height', '50px');
        $(this).css('background', '#A80000');
        $(this).css('cursor', 'pointer');

            $(this).find('a').css('font-size', '17px');
            $(this).find('a').css('color', '#CC99CC');
    });
    $('.submenu_item').mouseout(function(){
        $(this).css('height', '20px');
        var bgurl = 'url(http://'+document.domain+'/images/synced.jpg)';
        $(this).css('background', bgurl);
        var tid = $(this).attr('id');
        if (tid != 'submenu_header') {
            $(this).find('a').css('font-size', '12px');
        }
        $(this).find('a').css('color', 'black');
    });
    $('.submenu_item').click(function(){
        var urlto = $(this).find('a').attr('href');
        window.location.replace(urlto);
     });
    
    $('#career_form').submit(function() {
        var a_name = $('#applicant_name').val();
        var a_email = $('#applicant_email').val();
        var a_telephone = $('#application_telephone').val();
        var a_resume = $('#applicant_resume').val();

        if ( a_name == '') {
            $("#form_message").html("Name is required.");
            return false;
        } else if (a_telephone =='') {
            $("#form_message").html("Telephone is required.");
            return false;
        } else if (a_email=='') {
            $("#form_message").html("E-mail is required.");
            return false;
        } else if (a_resume == '') {
            $("#form_message").html("Resume is required.");
            return false;
        }

        var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
        if (emailPattern.test(a_email)) {
            return true;
        } else {
            $("#form_message").html("Please specify a valid e-mail");
            return false;
        }
    });

    jQuery(document.body).imageZoom();

    $('#search_button').click(function(){
        var query = $('#search_text').val();
        window.location.replace('http://'+document.domain+'/search?query='+query);
    });

    $('#search_text').keypress(function(e){
        if(e.keyCode == 13) {
            var query = $('#search_text').val();
            window.location.replace('http://'+document.domain+'/search?query='+query);
        }
    });
    
});



