var index = 0;
var quotes = ["&ldquo;...I am a private tennis coach working with pro level tennis players on the WTA/ITF tours. I use Tennis Trakker Pro to chart my players' matches and find the app very easy to use. It is an invaluable tool for coaches and players that are serious about their game...&rdquo;<br/><br/>Mark Gellard - PTR Certified Tennis Coach<br/>Currently working with Melinda Czink<br/>Worked with M. Hingis, V. Williams, B. Mattek-Sands<br/><br/><a href='http://www.markgellard.com' target='_blank'><strong>http://www.markgellard.com</strong></a><br/><br/>", "&ldquo;...I downloaded Tennis Trakker Pro charting software on both my iPhone and iPad and was completely satisfied with how easy I am able to record matches and provide instant stats to my players. It is by far one of the best tennis apps I have used. Any coach who charts matches would find this to be one of the best charting systems on the market. It has changed the way I view matches.....&rdquo;<br/><br/>Paul Tobin - Head Coach, Saint Francis Univ.<br/>Men's and Women's Tennis<br/>USTA High Performance Coach<br/>USPTA P-1 Professional, PTR Professional<br/><br/>", "&ldquo;..I've been using Tennis Trakker Pro to chart and analyze all of my matches this season. This app gives me even more detailed statistical information than ESPN or The Tennis Channel provides for professional matches. It's convenient and user-friendly. Simply amazing!...&rdquo;<br/><br/>Vincent Nguyen - UCSD Team Captain<br/>Athletic Director's Honor Roll<br/>Team's Leadership Award<br/><br/>","&ldquo;...the website adds a lot to the iPhone App!!! I lost my iphone that had so many matches on it and there was nothing I could do to get those backed-up. I appreciate now that they are on-line in my account...&rdquo;<br/><br/>&ldquo;...I like the upload feature of Tennis Trakker. What a difference it makes to be able to see my son's progress over many matches....&rdquo;<br/><br/>&ldquo;I love the graphs and my wife loves ScoreTrakker! I share the match data with my son’s coach to help focus his practice sessions. And my wife gets to follow the match score even when she can’t come with us!...&rdquo;<br/><br/>", "&ldquo;...I made some money by tracking players at their tournaments and emailing them their match stats from Tennis Trakker!...&rdquo;<br/><br/>"];

function display_quotes(){
    var length = quotes.length;
    if (index > (length -1))
	index = 0;

    var q = quotes[index];
    $("div#quotecontent").html(q);
    index++;
}

function enable_ctrl(ctrl_id_list){
    var length = ctrl_id_list.length;
    for (var i=0; i < length; i++) {
        $("#"+ctrl_id_list[i]).removeAttr("disabled");
    }
}

function disable_ctrl(ctrl_id_list){
    var length = ctrl_id_list.length;
    for (var i=0; i < length; i++) {
        $("#"+ctrl_id_list[i]).attr("disabled","disabled");
    }
}

function add_select_option(ctrl_id, item_value, item_name, selected){
    var jqctrl_id = "#"+ctrl_id;
    var opt = document.createElement('option');
    opt.value = item_value;
    opt.selected=selected;
    opt.appendChild(document.createTextNode(item_name));
    $(jqctrl_id).append(opt);
}

function days_between(date1, date2) {
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)
}

function scoreboard_init(){
    // this is a hack to get NiftyCube to work nicely on
    // various browser. Some how, the height of the container that
    // houses the 4 scoreboards changes between browsers so I have to 
    // dynamically set the height based on the browser.
    switch (BrowserDetect.browser) {
    case 'Safari':
	// 610px for 13px font
	$("#scorecontent").height('544px');
	break;
    case 'Firefox':
	// 596px for 13px font
	$("#scorecontent").height('564px');
	break;
    case 'Explorer':
	// 640px for 13px font
	$("#scorecontent").height('608px');
	break;
    default:
	$("#scorecontent").height('594px');
	break;
    }
}

/*
 * Date Format 1.2.3
 * (c) 2007-2009 Steven Levithan <stevenlevithan.com>
 * MIT license
 *
 * Includes enhancements by Scott Trenda <scott.trenda.net>
 * and Kris Kowal <cixar.com/~kris.kowal/>
 *
 * Accepts a date, a mask, or a date and a mask.
 * Returns a formatted version of the given date.
 * The date defaults to the current date/time.
 * The mask defaults to dateFormat.masks.default.
 * http://blog.stevenlevithan.com/archives/date-time-format
 */

var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};


var BrowserDetect = {
    init: function () {
	this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
	this.version = this.searchVersion(navigator.userAgent)
	    || this.searchVersion(navigator.appVersion)
	    || "an unknown version";
	this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
	for (var i=0;i<data.length;i++)	{
	    var dataString = data[i].string;
	    var dataProp = data[i].prop;
	    this.versionSearchString = data[i].versionSearch || data[i].identity;
	    if (dataString) {
		if (dataString.indexOf(data[i].subString) != -1)
		    return data[i].identity;
	    }
	    else if (dataProp)
		return data[i].identity;
	}
    },
    searchVersion: function (dataString) {
	var index = dataString.indexOf(this.versionSearchString);
	if (index == -1) return;
	return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
    },
    dataBrowser: [
	{
	    string: navigator.userAgent,
	    subString: "Chrome",
	    identity: "Chrome"
	},
	{ 	string: navigator.userAgent,
		subString: "OmniWeb",
		versionSearch: "OmniWeb/",
		identity: "OmniWeb"
	},
	{
	    string: navigator.vendor,
	    subString: "Apple",
	    identity: "Safari",
	    versionSearch: "Version"
	},
	{
	    prop: window.opera,
	    identity: "Opera"
	},
	{
	    string: navigator.vendor,
	    subString: "iCab",
	    identity: "iCab"
	},
	{
	    string: navigator.vendor,
	    subString: "KDE",
	    identity: "Konqueror"
	},
	{
	    string: navigator.userAgent,
	    subString: "Firefox",
	    identity: "Firefox"
	},
	{
	    string: navigator.vendor,
	    subString: "Camino",
	    identity: "Camino"
	},
	{		// for newer Netscapes (6+)
	    string: navigator.userAgent,
	    subString: "Netscape",
	    identity: "Netscape"
	},
	{
	    string: navigator.userAgent,
	    subString: "MSIE",
	    identity: "Explorer",
	    versionSearch: "MSIE"
	},
	{
	    string: navigator.userAgent,
	    subString: "Gecko",
	    identity: "Mozilla",
	    versionSearch: "rv"
	},
	{ 		// for older Netscapes (4-)
	    string: navigator.userAgent,
	    subString: "Mozilla",
	    identity: "Netscape",
	    versionSearch: "Mozilla"
	}
    ],
    dataOS : [
	{
	    string: navigator.platform,
	    subString: "Win",
	    identity: "Windows"
	},
	{
	    string: navigator.platform,
	    subString: "Mac",
	    identity: "Mac"
	},
	{
	    string: navigator.userAgent,
	    subString: "iPhone",
	    identity: "iPhone/iPod"
	},
	{
	    string: navigator.platform,
	    subString: "Linux",
	    identity: "Linux"
	}
    ]
    
};
BrowserDetect.init();
