/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/*
 * Login helper
 * http://etraction.co.nz/
 *
 * Copyright (c) 2009 Mark Haussmann
 * Dual licensed under the MIT and GPL licenses.
 *
 * Date: 2009-09-19 17:34:21 -0500 (Thu, 19 Sep 2009)
 */
 
// alters the logins so that they have labels as text in the boxes.
// password field alternates between a password box and a text box.
$(document).ready(function () {
	(function loginLabels() {
		var uname = document.getElementById('SZUsername');
		var pword = document.getElementById('SZPassword');
		uname.onblur = function () { 
			if (this.value == '') { this.value = 'Username'; }
		}
		uname.onfocus = function () {
			if (this.value == 'Username') { this.value = ''; }
		}
		pword.onblur = function () { 
			if (this.value == '') { this.value = 'Password'; this.type="text" }
		}
		pword.onfocus = function () {
			if (this.value == 'Password') { this.value = ''; this.type="password" }
		}
		if (pword.value == 'Password') { pword.type="text" }
	}) ();

	// secure zones are stored in a cookie for users that are logged in
	// they are retrieved once per session from the e360 server on login
	(function setSecureZones() {
		// get cookie
		var myZoneID = $.cookie('optimalsports_securezoneid');
		
		if (myZoneID == null) {
			return false;
		}
		
		$('.hasSecureZoneId a').each(function () {
			$(this).attr('href', $(this).attr('href').replace('[secure_zone_id]', myZoneID));
		});
	}) ();
});
	
window.setSecureZoneCookie = function (id) {
	if (id != null) {
		$.cookie('optimalsports_securezoneid', id);
	}
}



