//--------------------------------------------------------------------------
var isCookieEnabled = navigator.cookieEnabled;
//--------------------------------------------------------------------------
function getCookie( name ) {
	if( !isCookieEnabled ) return false;
  var start = document.cookie.indexOf( name + "=" );
  var len = start + name.length + 1;
  if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
    return null;
  }
  if ( start == -1 ) return null;
  var end = document.cookie.indexOf( ";", len );
  if ( end == -1 )
		end = document.cookie.length;
		return unescape( document.cookie.substring( len, end ) );
}
//--------------------------------------------------------------------------
function setCookie( name, value, expires, path, domain, secure ) {
	if( !isCookieEnabled ) return false;
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}

	if( value == 'now' ) value = today.setTime( today.getTime() );

	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) + ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}
//--------------------------------------------------------------------------
function deleteCookie( name, path, domain ) {
	if( !isCookieEnabled ) return false;
	if ( getCookie( name ) )
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
//--------------------------------------------------------------------------
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
	return false;
}
//--------------------------------------------------------------------------
function deleteLoginCookies(){
	//Deletting the evt. cookie which indicates the user logout
	deleteCookie( 'cookiesVar_loggedOut', '/' , SERVER_NAME );
	//deletting the previous cookies too
	deleteCookie( 'cookiesVar_debitorNo', '/' , SERVER_NAME );
	deleteCookie( 'cookiesVar_SomeThing', '/' , SERVER_NAME );
}
//--------------------------------------------------------------------------
function setLoginCookies( sessionid ){
	//Inserting coockie to indicate that the user is logged on
	setCookie( 'cookiesVar_loggedOn'    , '1'                     , 0.25, '/', SERVER_NAME , 0 );
	setCookie( 'cookiesVar_sessionid'   , sessionObj.sessionid    , 1   , '/', SERVER_NAME , 0 );
	setCookie( 'sessionid'              , sessionObj.sessionid    , 0.25, '/', SERVER_NAME , 0 );
	setCookie( 'cookiesVar_currencyCode', sessionObj.currency     , 0.25, '/', SERVER_NAME , 0 );
	setCookie( 'cookiesVar_currencyName', sessionObj.currencyName , 0.25, '/', SERVER_NAME , 0 );
	setCookie( 'cookiesVar_countryCode' , sessionObj.country      , 0.25, '/', SERVER_NAME , 0 );
	setCookie( 'cookiesVar_countryName' , sessionObj.countryName  , 0.25, '/', SERVER_NAME , 0 );
}
//--------------------------------------------------------------------------