function settingResettingCookie(cookieName,cookieValue,currentCookie){
/*-------------------------------------
Description:
sets the cookie if it hasnt been set but also will only set if its not the same.

Author: JL
Dependencies:
	jquery.cookie lib
Updates:
@Parameters: cookieName = name of the cookie
@Parameters: cookieValue = new cookie value to set if not present
@Parameters: currentCookie = current cookie value
-------------------------------------*/
	//chk if cookie present
	if($j.cookie(cookieName) == null && cookieValue != null){
		$j.cookie(cookieName,cookieValue);
	}
	//chk if cookie the same, if not then replace with this cookieValue
	else if ($j.cookie(cookieName) != currentCookie && cookieValue != null){
		$j.cookie(cookieName,cookieValue);
	}
	
}

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];
}

function addTrackingToDeepLink(className,trackingVarName,trackingCode,noTrackValue,dcsDelimiter,dcsTracker){
	/*-------------------------------------
	Description: 
	Adds the tracking code to all links of "className"

	Author: JL
	Updates: 
	Dependencies: 
	   jq.cookie
	-------------------------------------*/	
		//check if any GET params exist
		var debug = 0;
		var paramChar; //either '?' or '&'
		if (debug){alert($j(className).attr('href'))};
		
		if (trackingCode === null){
			trackingCode = noTrackValue;
		}
		if (dcsTracker === null){
			dcsTracker = 'noDcsTrk'
		}

		$j(className).each(function(){
			if (debug){alert($j(this).attr('href'))};
			
			//chk if there's existing params
			if (String($j(this).attr('href')).indexOf('?') > 1){
				paramChar = '&';
			}
			//else there's no parameters 
			else{
				paramChar = '?';
			}
		
			if(debug){ alert($j(this).attr("href")+paramChar+trackingVarName+"="+trackingCode) };
		
			//change all the URLs 
			$j(this).attr("href",$j(this).attr("href")+paramChar+trackingVarName+"="+trackingCode+dcsDelimiter+dcsTracker)
		});

	}

function routePlanForMap(from,to){
/*-------------------------------------
Description:
preps the parameters ready for the map page

Author: JL Oct 09
Dependencies:
jquery.cookie
Updates:
@Parameters: string from 
@Parameters: string to
-------------------------------------*/
	//convert to url safe string
	from = Url.encode(from);
	to = Url.encode(to);
	
	var redirectString = 'http://' + document.domain + '/map.php?depart=' + from + '&to=' + to;
	
	window.location = redirectString;
}

function showOnMapLocation(locationSearch){
	/**
	 * Description:
		 Forwards the request to the map.php with the location
	 * Author: JL
	 * Changelog: 
	 * 	Rev1
	 * @param String locationSearch
	 * @return none
	 */

		var forwardLocation = 'http://'+document.domain+'/map.php?locSearch='+locationSearch;
		window.location = forwardLocation;			 
	}

/********************************************************************/
$j(document).ready(function() {
	var trackingCodeParam= 'A8ID';
	var DcStormCookie = '_#clkid';
	
    //chk if need to set cookie a8id, see if in url params.
	if(GetParameterFromURL(trackingCodeParam)){
		$j.cookie(trackingCodeParam,GetParameterFromURL(trackingCodeParam))	   
	}
	
	addTrackingToDeepLink($j('.trackingArea'), "LID", $j.cookie(trackingCodeParam),'a08_preminn','~~',$j.cookie(DcStormCookie));	
	addTrackingToDeepLink($j('.banner'), "LID", $j.cookie(trackingCodeParam),'a08_preminn','~~',$j.cookie(DcStormCookie));
	
	//clear fields when user clicks in the text field
	$j('input').bind('click',function(e){
		   $j(this).val('');
	});
});