var trk ={
    defaultCookie : '',//local

    init : function(defaultCookie){ //public call//
    /*-------------------------------------
    Description:
    Init function to setup the tracking stuff
    Author: JL Jan 10
    -------------------------------------*/
        this.defaultCookie = defaultCookie;

        if(!this._allModulesIn()){
            //not all modules present
            return false;
        }

        if(this._GetParameterFromURL("A8ID")){
             //set the PPC tracking code cookie at the root level
            $.cookie('A8ID',trk._GetParameterFromURL("A8ID"),{path: '/'})
        }

        if(!$.cookie('a8.referer')){//if referrer not set
            $.cookie('a8.referer',document.referrer,{path: '/'});
        }
        return true;
    },
    _allModulesIn : function(){
        //chk if jquery present
        if (!jQuery) {
           // use google cdn
           //   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
           alert('Jquery not loaded!!! - Fix this before putting live');
           return false;
        }
        if(!jQuery.cookie){
            alert('jquey cookie plugin not installed - Add it or fix the reference');
            return false;
        }
        return true
    },

    _GetParameterFromURL : function(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];
    }
}

function returnDocument() {
    var file_name = document.location.href;
    var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
    return file_name.substring(file_name.lastIndexOf("/")+1, end);
}

/************************************* */

/*-------------------------------------
Description:
The code to get floating calendar stuff

Author: JL Aug '09
Dependencies: jquery.js, jq.cookie.js
Updates:
-------------------------------------*/
$(document).ready(function() {
    /*****
     * event binding ere
     */
    $('#brandSelect').change(function(){
        //alert($(this).val());
        $('#brandFrm').submit();
    })


    /*******
     * other stuff here
     */
    if(returnDocument() == 'vodafone-simonly-deals-b.html' && $.cookie('A8afVars[A8ID]')
			&& !$.cookie('fwd')){
        //alternative page traffic
        var newTrk = $.cookie('A8afVars[A8ID]') + '_b'
		var end = window.location.href.indexOf('?');
		var newLoc = window.location.href.substring(0,end);
		var fwdLoc = newLoc +'?A8ID=' + newTrk;

		$.cookie('fwd','true')
		window.location.href = fwdLoc;
    }
    //payasyougo.php
    trk.init('a08_voda_payg');
});

