/**
 * --------------------------------------------------------------------------------
 * @desc NameSpace is the root javascript object for this library, and serves primarily as a namespace.
 * 
 * usage: if you define a new section/namespace, include it here and put the full implementation details later in the file.
 *  
 * --------------------------------------------------------------------------------
 */

website = {
    version: 1,
    constant: {},       // store universal constants here, including html, text, numerics, etc.
    fn: {},             // global shortcuts to hi-value functions.
    util: {},           // general purpose utility functions:
    widget: {},         // self-contained widgets: eg, colour picker, etc.
    module: {           // self-contained modules, these correspond to modules/components in the application
        navigation:{},       // All admin module code should go here, can also have sub name spaces.
        mlrs:{}
    }
    
};

website.module.navigation.displaySubItems = function(){
  $(this).find('ul').show('fast');  
};
website.module.navigation.hideSubItems = function(){
    $(this).find('ul').hide('fast');  
};

website.module.mlrs.stylePropertyDetailTable = function(row, backgroundColor){
    
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child('+row+')').css('background-color',backgroundColor);
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child('+row+')').find('td').attr('ALIGN','LEFT');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child('+row+')').find('td:nth-child(1)').attr('style','width:115px; padding-left:40px;');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child('+row+')').find('td:nth-child(3)').attr('style','width:115px;');
    $('#mlsr_main_image_div').parent().parent().parent().parent().parent().parent().parent().parent().find('tr:nth-child('+row+')').find('td:nth-child(4)').attr('style','padding-right:40px;');
};

website.fn.popupCalculator = function() {
    newwindow=window.open('/index/mortgage-Calculator','name','height=500,width=680');
    if (window.focus) {
        newwindow.focus();
    }
    return false;
}

website.module.mlrs.checkMlrsForm = function(formObj){
    var returnValue = true;
    var message = '';
    if ($('#ws_quicksearch_region').val() == '-1'){
        returnValue = false;
        message = "- Please choose the region for the quick search.";
    }
    
    if (parseInt($('#ws_quicksearch_mnprc').val()) > parseInt($('#ws_quicksearch_mxprc').val())){
        returnValue = false;
        if (!returnValue){
            message += "\n\n- Price from cannot be more than the maximum price.\n\nPlease adjust your search parameters."
        } else {
            message = "- Price from cannot be more than the maximum price.\n\nPlease adjust your search parameters.";
        }
   
    }
    
    if (!returnValue){
        message = "The quick search could not be submitted:\n\n" + message;
        alert (message);
    }
    
    return returnValue;
    
}

website.fn.subscribeValidate = function(){
    var returnValue = true;
    if ($('#hm_links_sidebar_subscribe_email').val() == ''){
        returnValue = false;
        alert('Please enter an email address for the newsletter, and press the arrow to submit.');
    }
    
    return returnValue;
}

website.fn.contactMeCheck = function(){
    var returnValue = true;
    
    $('#ws_submit_results').html('');
    $('#ws_submit_results').hide();
    
    if ($('#ws_contact_email_input').val() == ''){
        returnValue = false;
        $('#ws_submit_results').html('<Br>Please enter your email address');
    }
    if ($('#ws_contact_comment_input').val() == ''){
        returnValue = false;
        $('#ws_submit_results').html($('#ws_submit_results').html() + '<Br>Please enter your message (you do want to tell me something no?)');
    }
    
    if (!returnValue){
        $('#ws_submit_results').show('slow');
    }
    return returnValue
}

website.fn.submitMortgageCalculator = function (){
    if(library.fn.validateForm()){
        calculateMortgage();
    }
};

