/* ********************************************************************************
 * Channel 6 misc. client-side code
 * ---------------------------------
 * (c) ch-6.co.uk, 2002-2005
 * ---------------------------------
 * Last modified:	2005-03-21: rememberDetails(), loginRemember() added.
 * ********************************************************************************/

/**********************************************************************************/
/* deleteItem()                                                                   */
/* DB function                                                                    */
/**********************************************************************************/
function deleteItem(oForm, sItem, sURL) {
	if (confirm('Are you sure you wish to delete this ' + sItem + '?')) {
		oForm.Action.value = 'Delete';
		oForm.action = sURL;
		oForm.submit();
	} else {
		return false;
	}
}

/**********************************************************************************/
/* rememberDetails()                                                              */
/* Login function                                                                 */
/* Depends: ch-6_cookie-lib.js [setCookie()]                                      */
/**********************************************************************************/
function rememberDetails(sLogin, sPassword) {
	var dExpiry = new Date();
	var sValue = sLogin + '_' + sPassword + '#';
	dExpiry.setTime(dExpiry.getTime() + (60 * 24 * 60 * 60 * 1000));	// 60 days (60 * (24 hours * 60 minutes * 60 seconds * 1000 milliseconds))
	setCookie('Login', sValue, dExpiry);
	return true;
}

/**********************************************************************************/
/* loginRemember()                                                                */
/* Login function                                                                 */
/* Depends: ch-6_cookie-lib.js [getCookie()]                                      */
/**********************************************************************************/
function loginRemember(oForm) {
	var sCookie = getCookie('Login');
	if (sCookie) {
		var iUnderscorePos = sCookie.lastIndexOf('_');
		var iHashPos = sCookie.lastIndexOf('#');
		if (iUnderscorePos > -1 && iHashPos > -1) {
			var sEmail = sCookie.substr(0, iUnderscorePos);
			var sPassword = sCookie.substr(iUnderscorePos+1, iHashPos-(iUnderscorePos+1));
			oForm.email.value = sEmail;
			oForm.password.value = sPassword;
			oForm.remember_me.checked = true;
		}
	}
}

/**********************************************************************************/
/* submitCounter()                                                                */
/* Ensures that forms don't get submitted more than once.                         */
/* Used on "confirm.asp", etc                                                     */
/**********************************************************************************/
var submitcount = 0;
// SUBMIT COUNT FUNCTION:
function submitCounter(sText) {
	if (submitcount++ == 0) {
		return true;
	} else {
		alert(sText);
		return false;
	}
}

/**********************************************************************************/
/* addEvent()                                                                     */
/* Cross-platform (IE, Gecko, KHTML, Opera) addEvent function                     */
/* http://www.scottandrew.com/weblog/articles/cbs-events                          */
/* ...via...                                                                      */
/* http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html        */
/* Allows an event to be *added* to existing events, instead of replacing any     */
/* existing events                                                                */
/**********************************************************************************/
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}


