/* 
 * js file used in the homepage
 *
 */

function GetParameterFromURL(name){
    /*-------------------------------------
    Description:
    Extracts a parameter from the url. eg xyz.com/test.php?msg=hello
    GetParameterFromURL('msg') will get 'hello'
    Author: http://www.netlobo.com/url_query_string_javascript.html
    Dependencies:
    Updates:
    @Parameters: name = name of the parameter to extract
    -------------------------------------*/
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }

    var home = {
        //this is the starting search string - we use this to try figure out if the user has randomly hit the search button without putting in a search term
        searchString : '',
        textPromptMsg : 'Please enter a search in London here',
        alertMsg : 'Please enter a search term in the text search box to search'
    }

    $(document).ready(function(){
        if(GetParameterFromURL('A8ID')){
            // if A8ID is set in the URL set value into cookie
            $.cookie('A8ID',GetParameterFromURL("A8ID"),{path: '/', expires: 120});
        }
        home.searchString = $('#srchString').val();

        //binding events
            //to search form
        $('#frmSearch').submit(function(){
            if($('#srchString').val() == home.searchString || $('#srchString').val() == ''){
                $('#srchString').val(home.textPromptMsg).css('color','red');
                return false;
            }
            else if($('#srchString').val() == home.textPromptMsg ){
                $('#srchString').val(home.textPromptMsg).css('color','red');
                alert(home.alertMsg);
                return false;
            }
            else{
                return true;
            }
        })

            //to text search box
       $('#srchString').focus(function(){
           $(this).css('color','#444444');
       })


    })
