/*****************************************************************************
******************************************************************************

f_ookie.js

Written by Chris Harding and Joshua McKinney
© Copyright F1 Solutions Pty Ltd 2002

This file holds the cookie manipulation code used by some pages.

Production Version 2.0 - June 2007

******************************************************************************
*****************************************************************************/


/****************************************************************************/
/* Function: getCookie(name)
/* This function returns the value of the cookie specified by name.
/* If the cookie is not found it returns null.
/*
/* INPUTS : string
/* OUTPUTS: string/null
/****************************************************************************/
function getCookie(name) {
    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(unescape(document.cookie.substring(len,end)));
}
/****************************************************************************/
/* End Function
/****************************************************************************/


/****************************************************************************/
/* Function: setCookie(name,value)
/*
/* This function sets the cookie specified by name with the value value.
/* The expiry date is set one year into the future.
/*
/* INPUTS : string, string
/* OUTPUTS: none
/****************************************************************************/
function setCookie(name,value) {
	var today = new Date();
	var expiry = new Date(today.getTime() + 365 * 24*60*60*1000);
	var theCookie = name + "=" + escape(value) + ";expires=" + expiry.toGMTString();
	//theCookie += ";path=/";
	//alert(theCookie);
	document.cookie = theCookie;
}
/****************************************************************************/
/* End Function
/****************************************************************************/


/****************************************************************************/
/* Function: deleteCookieNamed(name)
/* This function deletes the cookie specified by name.
/* It does this by setting the expiry date in the past.
/*
/* INPUTS : string
/* OUTPUTS: none
/****************************************************************************/
function deleteCookieNamed(name) {
	var theCookie = name + "=;expires=Thu, 01-Jan-1900 00:00:01 GMT";
	document.cookie = theCookie;
}
/****************************************************************************/
/* End Function
/****************************************************************************/


/****************************************************************************/
/* Function: deleteCookie()
/* This function deletes all the cookies associated with the DGRR.
/*
/* INPUTS : none
/* OUTPUTS: none
/****************************************************************************/
function deleteCookie() {
	deleteCookieNamed("dgrrpremisedata");
	deleteCookieNamed("dgrrgoodsdata01");
	deleteCookieNamed("dgrrsortdata");
	deleteCookieNamed("dgrrnewpremise");
	deleteCookieNamed("ASPCLIENTDEBUG");
	// delete all cookies used in modifications (activeX replacement)
	deleteCookieNamed("ePremiseOccupier");
	deleteCookieNamed("dateTime");
	deleteCookieNamed("ePremiseABN");
	deleteCookieNamed("ePremiseAddress");
	deleteCookieNamed("ePremisePropertyLocation");	
	deleteCookieNamed("ePremiseContactPersonAndPhone1");
	deleteCookieNamed("ePremiseContactPersonAndPhone2");
	deleteCookieNamed("aTempPremises");
        deleteCookieList('aTempGood');
}
/****************************************************************************/
/* End Function
/****************************************************************************/

function deleteCookieList(key) {
        var index = 0;
        while (getCookie(key + index) != null) {
                deleteCookieNamed(key + index);
                index++;
        }    
}