/**
 * Page containing common script for JS
 */

/**
 * Function to get add to favourite link
 */
/*9function funcPrintAddToFavouties(country)
{
	if (window.external) 
	{ 
		document.write("<a href=\"javascript:funcAddBookmark('" + country + "');\">Add to Favourites</a>");   
	} 
	else if (window.sidebar)
	{ 
		document.write("<a href=\"javascript:funcAddBookmark('" + country + "');\">Bookmark Page</a>");  
	} 
	else if (window.opera && window.print) 
	{ 
		document.write("<a href=\"javascript:funcAddBookmark('" + country + "');\">Add Bookmark</a>"); 
	} 	
}*/
 
 /**
  * Function to add the URL to the bookmarks
  */
/*function funcCreateBookmarkLink(country) 
{ 
	var title 	= "Mobility Index";   
	var url 	= "http://www.mobilityindex.com/" + country;  
	
	if (window.sidebar)
	{
		window.sidebar.addPanel(title, url,"");	
	} 
	else if( window.external ) 
	{ 
		window.external.AddFavorite( url, title); 
	}	
	else if(window.opera && window.print) 
	{
		return true; 
	} 
} */

/** 
 * Function to add to favourites
 */
function funcAddBookmark(url, title)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print) // opera
	{ 
		var elem = document.createElement('a');
		elem.setAttribute('href', url);
		elem.setAttribute('title', title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}

/**
 * Method to resize font size
 */
var count=0;
// default font size in percent
function resizeText(process)
{	
	currentSize = getCookie("FontSize");
	
	fontSizeToSet = processFontSize(parseInt(currentSize), process);
	setCookie("FontSize", fontSizeToSet);
	fontSizeToSet = (fontSizeToSet.toString()) + "%";
	$("body").css("font-size", fontSizeToSet);
	
	return false;
}

/**
 * Function to process font size
 */
function processFontSize(currentSize, process) 
{	
	var defaultFontSize = 100;
	
	var increment   = 10;
	switch(process)
	{	
		case 0:
			fontSizeRet = currentSize - increment;
		break;
		case 1: 
			fontSizeRet = currentSize + increment;
		break;
		case 2:
			fontSizeRet = defaultFontSize;
		break; 
	}
	
	return fontSizeRet;
}

$(document).ready(
	function()
	{	
		if(getCookie("FontSize") == null || getCookie("FontSize") == "")
		{	
			setCookie("FontSize", 100);
		}
		else
		{	
		//	alert(getCookie("FontSize"));
			$("body").css("font-size", (getCookie("FontSize").toString()) + "%");
		}
	}
);


/**
 * Function to set a cookie
 */
function setCookie ( name, value, expYear, expMonth, expDay, path, domain, secure )
{
	var cookieString = name + "=" + escape ( value );
	
	if ( expYear )
	{
		var expires = new Date ( expYear, expMonth, expDay );
		cookieString += "; expires=" + expires.toGMTString();
	}
	
	if ( path )
		cookieString += "; path=" + escape ( path );
	
	if ( domain )
		cookieString += "; domain=" + escape ( domain );
	
	if ( secure )
		cookieString += "; secure";
	
	document.cookie = cookieString;
}

/**
 * Function to delete cookie variable
 */
function deleteCookie ( cookieName )
{
	  var cookie_date = new Date ( );  // current date & time
	  cookie_date.setTime ( cookie_date.getTime() - 1 );
	  document.cookie = cookieName += "=; expires=" + cookie_date.toGMTString();
}

/**
 * Function to get a value of a cookie variable
 */
function getCookie ( cookieName )
{
	var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' );
	
	if ( results )
		return ( unescape ( results[2] ) );
	else
		return null;
}
function setTheme(colorCodeID)
{
	if(colorCodeID > 0)
	{
		setCookie("colorCodeID", colorCodeID);
		window.location.reload();
	}
	else
	{
		deleteCookie("colorCodeID");
	}
}