function Get_Cookie(check_name) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; 

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
var today = new Date();
today.setTime( today.getTime() );
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
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" : "" );
}
	
/**
 * JavaScript code to detect available availability of a 
 * particular font in a browser using JavaScript and CSS. 
 * 
 * Author : Lalit Patel
 * Website: http://www.lalit.org/lab/jsoncookies
 * License: Creative Commons Attribution-ShareAlike 2.5
 *          http://creativecommons.org/licenses/by-sa/2.5/
 * Version: 0.15 
 *          changed comparision font to serif from sans-serif, 
 *          as in FF3.0 font of child element didn't fallback 
 *          to parent element if the font is missing.
 * Updated: 09 July 2009 10:52pm
 * 
 */

/**
 * Actual function that does all the work. Returns an array with all the info.
 * This test will fail for the font set as the default serif font.
 * 
 * Usage: d = new Detector();
 *        d.test('font_name');
 */
var Detector = function(){
	var h = document.getElementsByTagName("BODY")[0];
	var d = document.createElement("DIV");
	var s = document.createElement("SPAN");
	d.appendChild(s);
	d.style.fontFamily = "sans";			//font for the parent element DIV.
	s.style.fontFamily = "sans";			//serif font used as a comparator.
	s.style.fontSize   = "72px";			//we test using 72px font size, we may use any size. I guess larger the better.
	s.innerHTML        = "mmmmmmmmmmlil";		//we use m or w because these two characters take up the maximum width. And we use a L so that the same matching fonts can get separated
	h.appendChild(d);
	var defaultWidth   = s.offsetWidth;		//now we have the defaultWidth
	var defaultHeight  = s.offsetHeight;	//and the defaultHeight, we compare other fonts with these.
	h.removeChild(d);
	/* test
	 * params:
	 * font - name of the font you wish to detect
	 * return: 
	 * f[0] - Input font name.
	 * f[1] - Computed width.
	 * f[2] - Computed height.
	 * f[3] - Detected? (true/false).
	 */
	function debug(font) {
		h.appendChild(d);
		var f = [];
		f[0] = s.style.fontFamily = font;	// Name of the font
		f[1] = s.offsetWidth;				// Width
		f[2] = s.offsetHeight;				// Height
		h.removeChild(d);
		font = font.toLowerCase();
		if (font == "serif") {
			f[3] = true;	// to set arial and sans-serif true
		} else {
			f[3] = (f[1] != defaultWidth || f[2] != defaultHeight);	// Detected?
		}
		return f;
	}
	function test(font){
		f = debug(font);
		return f[3];
	}
	this.detailedTest = debug;
	this.test = test;	
}

// Font test
function ft(f) {return d.test(f)?'1':'0';}
var xfont = Get_Cookie('x-font')
if (xfont != 'test') {
 if (xfont != 'sans-serif' && xfont != 'serif' && xfont != 'default') {
  Set_Cookie('x-font', 'test', 90, '/');
 } 
} else {
var d = new Detector();
var p = '';
p += ft('Courier New');
p += ft('Arial');
p += ft('Verdana');
p += ft('Times New Roman');
p += ft('Trebuchet MS');
p += ft('Impact');
p += ft('Comic Sans MS');
p += ft('Georgia');
p += ft('Andale Mono');
p += ft('Arial Black');
p += ft('Tahoma');
p += ft('Microsoft Sans Serif');
p += ft('Lucida Console');
p += ft('Lucida Sans Unicode');
p += ft('Palatino Linotype');
p += ft('Franklin Gothic Medium');
p += ft('Calibri');
p += ft('Candara');
p += ft('consolas');
p += ft('Constantia');
p += ft('Cambria');
p += ft('Segoe UI');
p += ft('Segoe Print');
p += ft('Segoe Script');
p += ft('Segoe Media Center');
p += ft('Arial Narrow');
p += ft('Century Gothic');
p += ft('Garamond');
p += ft('Bookman Old Style');
p += ft('Book Antiqua');
p += ft('Copperplate Gothic Light');
p += ft('Monotype Corsiva');
p += ft('Papyrus');
p += ft('Century');
p += ft('Haettenschweiler');
p += ft('OCR A Extended');
p += ft('Gill Sans MT');
p += ft('Arial Rounded MT Bold');
p += ft('Bell MT');
p += ft('Bodoni MT');
p += ft('Helvetica');
p += ft('Myriad Pro');
p += ft('Minion Pro');
p += ft('DejaVu Sans');
p += ft('DejaVu Serif');
p += ft('Bitstream Vera Sans');
document.write('<img src="http://misc.maly.cz/font.php?f='+p+'" alt="">');
Set_Cookie('x-font', 'default', 90, '/');
}