/*
// deprecated

function createMediumItem( data, mode ){
	var output = '';
	var id = data.id;
	var image = data.image + "?crop(140x140)";
	var name = data.title;
	var location = ucfirst( data.community.region_name ) + " - " + ucfirst( data.community.community );
	var url = data.url;
	var color = data.color;
	output += '<div class="avatar140 avatar align-left" id="item-' + id + '"><a href="'+url+'">';
	output += '		<div class="img-round-mid">';
	output += '			<div class="img-round-mask-mid"></div>';
	output += '      	<img src="' + image + '"></div>';
	output += '    </a>';
	output += '    <div class="color-bar round bg-' + color + '">';
	output += '      <div class="tt-up"></div>';
	output += '    <div class="color-bar-inner">' + name + '</div>';
	output += '      </div>';
	output += '  </div>';
	return output;
}

function showHelper() {
	$("#collapse").show();
	$("#expand").hide();
	setCookie("the_helper_cookie", "show"); 
}

function hideHelper() {
	$("#collapse").hide();
	$("#expand").show();
	setCookie("the_helper_cookie", "hide");
}

function openPopupUsingUrl(url) {
	$.fn.colorbox({href:url, iframe:true, width:900, height:500, open:true, opacity:0.8, transition:'elastic'});
}

// validate the registration form (deprecated?)
function registrationFormIsError(){
	$("input, select, textarea").each(function(){
		if( isDefined( $(this).attr("validation") ) ){
			$(this).trigger('blur');
		}
	});
	window.formError = false;
	$("input, select, textarea").each(function(){
		if( $(this).attr("errorState") == "1" ){
			window.formError = true;
		}else{
			//$(".form-tips").fadeIn();			
		}
	});

	if( window.formError ){
		$info = $('<div id="info-box-for-button">');
		//$info.html("Please check any error(s) before submitting the form."); // put the message on the container
		$info.html(""); // put the message on the container
		$info.fadeIn(); // show the infobox
		$info.attr("class", "info-box-error align-left");
		if( $("form #info-box-for-button").length == 0 ) $("form").append($info);
		else $("form #info-box-for-button").fadeIn();
		return true;
	}else{
		$("form #info-box-for-button").fadeOut();
		return false;	
	}	
}

*/

var ajaxWaitingImage = '<img src="/images/ajax-loader.gif" width="43" height="11" />';
var the_helper_cookie;

// check if an object is defined or not
function isDefined( variable ) {
    return (typeof(variable) == "undefined")?  false: true;
}

// redirection after x second
function timedRedirection(url, second) {
	var time = second * 1000;
	var t = setTimeout("location.href='" + url + "';", time);
}

// limit character from textarea or input (mainly for textarea)
function limitChars(textid, limit, infodiv) {
	var text = $('#'+textid).val(); 
	var textlength = text.length;
	if(textlength > limit) {
		$('#' + infodiv).html('You cannot write more then '+limit+' characters!');
		$('#'+textid).val(text.substr(0,limit));
		return false;
	} else {
		$('#' + infodiv).html('You have '+ (limit - textlength) +' characters left.');
		return true;
	}
}

// same as above function only dedicated for twitter comment
function limitCharacter(text, limit, infodiv, id) {
	var textlength = text.length;
	if(textlength > limit) {
		$('#' + infodiv).html('0');
		$('#twitter #comment-textarea-0').val( text.substr(0,limit) );
		return false;
	} else {
		$('#' + infodiv).html(''+ (limit - textlength) +'');
		return true;
	}
}

// substring a string
function limitChar(text, limit) {
	return text.substr(0,limit);
}

// limit a string based on number of words specified
function limitWord(string, limit){
	var str = "";
	var output = string.split(" ");
	for(var i=0; i<limit; i++){
		if( isDefined(output[i]) )
		str += output[i] + " ";
	}
	return trim(str);
}

// toggle visibility of a div (block)
function toggle(id) {
	var current = $("#" + id).css("display"); 
 	if( current == "block" ) {
  		$("#" + id).css("display", "none");
 	} else {
  		$("#" + id).css("display", "block");
 	}
}

/**
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
**/
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}


// Escapes single quote, double quotes and backslash characters in a string with backslashes  
// 
// version: 907.119
// discuss at: http://phpjs.org/functions/addslashes
// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   improved by: Ates Goral (http://magnetiq.com)
// +   improved by: marrtins
// +   improved by: Nate
// +   improved by: Onno Marsman
// +   input by: Denny Wardhana
// +   improved by: Brett Zamir (http://brett-zamir.me)
// *     example 1: addslashes("kevin's birthday");
// *     returns 1: 'kevin\'s birthday'
function addslashes( str ) { 
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\u0000/g, "\\0");
}

// cookie related function (to set)
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

// get cookie
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			
			if (c_end==-1) 	c_end=document.cookie.length;
			
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

// check if it's a proper email format
function isEmail(string) {
	var emailfilter = /^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	var result = emailfilter.test(string);
	return result;
}               

// check if it's just a alphanumeric
function isProper(string) {
   if (!string) return false;
   var iChars = "!\"$%^&*()+=`':;~#/?.>,<|\\/";
   for (var i = 0; i < string.length; i++) {
	  if (iChars.indexOf(string.charAt(i)) != -1)
		 return false;
   }
   return true;
} 

// capitalise first character
function ucfirst( str ) {
    str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1);
}

// get the form name (deprecated?)
function getForm(name) {
	var ajaxUrl = '/form/' + name;
	$.get(ajaxUrl, function(data) {
		return data;
	});		
}

// automatically move the focus to the top 
// using a nice movements
function scrollToTop( speed, id ) {
	
	if( isDefined(id) && id!=""){
		var top = $("#" + id).position().top;
	}else{
		var top = 0;	
	}
	
	if (!speed) speed = "slow";
	$("html, body").animate({scrollTop:top+"px"},speed);
}

// dynamically attaching google map script tag
function loadGoogleMapScript(){
  	var script = document.createElement("script");
  	script.type = "text/javascript";
  	script.src = "http://maps.google.com/maps?file=api&v=2.x&key=" + GOOGLE_MAP_API + "&async=2";
	document.body.appendChild(script);

	var script2 = document.createElement("script");
  	script2.type = "text/javascript";
  	script2.src = "http://gmaps-utility-library.googlecode.com/svn/trunk/markermanager/1.1/src/markermanager_packed.js";
	document.body.appendChild(script2);	
}

// Returns part of a string  
// 
// version: 908.406
// discuss at: http://phpjs.org/functions/substr
// +     original by: Martijn Wieringa
// +     bugfixed by: T.Wild
// +      tweaked by: Onno Marsman
// *       example 1: substr('abcdef', 0, -1);
// *       returns 1: 'abcde'
// *       example 2: substr(2, 0, -6);
// *       returns 2: ''
function substr (f_string, f_start, f_length) {
    f_string += '';

    if (f_start < 0) {
        f_start += f_string.length;
    }

    if (f_length == undefined) {
        f_length = f_string.length;
    } else if (f_length < 0){
        f_length += f_string.length;
    } else {
        f_length += f_start;
    }

    if (f_length < f_start) {
        f_length = f_start;
    }

    return f_string.substring(f_start, f_length);
}

// search string within an array
function searchArray(array, string, wholeStringMode){
	if( isDefined( wholeStringMode ) && wholeStringMode == true){
		for(var i=0; i<array.length; i++){
			if(array[i]==string) return true;	
		}
		return false;
	}else{
		str = array.toString();
		if(str.indexOf(string)!=-1) return true;
		else return false;
	}
}

// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   improved by: Ates Goral (http://magnetiq.com)
// +      fixed by: Mick@el
// +   improved by: marrtins
// +   bugfixed by: Onno Marsman
// +   improved by: rezna
// +   input by: Rick Waldron
// +   reimplemented by: Brett Zamir (http://brett-zamir.me)
// *     example 1: stripslashes('Kevin\'s code');
// *     returns 1: "Kevin's code"
// *     example 2: stripslashes('Kevin\\\'s code');
// *     returns 2: "Kevin\'s code"
// strip slashes on a string
function stripslashes (str) {
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

// render date from 3 dropdown box
function renderDate(prefixId, destinationId){
	var strdate = "";
	
	if( $("#" + prefixId + "dd").val() != "" && $("#" + prefixId + "mm").val() != "" && $("#" + prefixId + "yyyy").val() != "" )
	strdate = $("#" + prefixId + "dd").val() + "/" + $("#" + prefixId + "mm").val() + "/" + $("#" + prefixId + "yyyy").val();
	
	$("#" + destinationId ).val(strdate);
}

// render date from 3 dropdown box
function renderOptionDate(prefixId, destinationId){
	var d = $("#" + destinationId).val();
	dArray = d.split("/");
	$("#" + prefixId + "dd").val( dArray[0] );
	$("#" + prefixId + "mm").val( dArray[1] );
	$("#" + prefixId + "yyyy").val( dArray[2] );
	
}

// render date from database format
function renderDateFromDb(prefixId, dateStr){
	var d = dateStr;
	dArray = d.split("-");
	$("#" + prefixId + "dd").val( dArray[2] );
	$("#" + prefixId + "mm").val( dArray[1] );
	$("#" + prefixId + "yyyy").val( dArray[0] );
}

// returns a select box of all joined community
function getJoinedCommunity( containerId, selectedValue ) {
	if( !isDefined(selectedValue) ) selectedValue = "";
	$.get("/json-data/joined-community.json", function(data) {
		response = eval("(" + data + ")");
		var output = "";
		output += "<option value=''>Please select</option>";			
		for( var i=0; i<response.data.length; i++) {
			if( typeof(response.data[i].id) != "undefined") {
				output += "<option ";
				output += "value='" + response.data[i].community_id + "'";
				if( selectedValue == response.data[i].community_id ) output += " selected='selected'";
				output += ">";
				output += ucfirst( response.data[i].community );
				output += "</option>";
			}
		}
		$("#" + containerId).html( output );
	});
}

// return owned business in dropdown format
function getOwnedBusiness(containerId, selectedValue) {
	if( !isDefined(selectedValue) ) selectedValue = "";
	$.get("/json-data/my-business.json", function(data) {
		response = eval("(" + data + ")");
		var output = "";
		output += "<option value=''>Please select</option>";			
		for( var i=0; i<response.data.length; i++) {
			if( typeof(response.data[i].id) != "undefined") {
				output += "<option ";
				output += "value='" + response.data[i].id + "'";
				if( selectedValue == response.data[i].id ) output += " selected='selected'";
				output += ">";
				output += ucfirst( response.data[i].title );
				output += "</option>";
			}
		}
		$("#" + containerId).html( output );
	});
}

// if list of options have an url attribute, then this function
// will attach the event to do redirection when something's been chosen
function redirectUrlFromDropDown(id){
	var val = $("#" + id).val();
	$.each($("#" + id + ">option"), function(){
		if( isDefined($(this).attr("url")) ){
			if( $(this).val() == val) location.href = $(this).attr("url");
		}
	});
}

// create dropdown of crountry list
function generateDropDownCountry( noNextButton, id ){
	$.get('/json-data/list-country.json', function(data){
		if( isDefined(id) ) var output = "<select id='" + id + "' >";
		else var output = "<select id='country'>";
		output += "<option></option>"
		countryJson = eval("(" + data + ")");
		for(var i=0; i<countryJson.length; i++){
			if( countryJson[i].id == "253" )
				output += "<option value='" + countryJson[i].id + "' selected='selected'>" + countryJson[i].country + "</option>";
			else
				output += "<option value='" + countryJson[i].id + "'>" + countryJson[i].country + "</option>";
		}
		output += '</select>';
		if( !isDefined(noNextButton) || noNextButton!=true)
		output += '<br /><input onclick="displayCommunity( $(\'#country\').val() );" value="Next" class="next-button" type="button" />';
		$("#country-select").html( output );
		showPanel(1);
	});
}

// Uppercase the first character of every word in a string  
// 
// version: 909.322
// discuss at: http://phpjs.org/functions/ucwords
// +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// +   improved by: Waldo Malqui Silva
// +   bugfixed by: Onno Marsman
// *     example 1: ucwords('kevin van zonneveld');
// *     returns 1: 'Kevin Van Zonneveld'
// *     example 2: ucwords('HELLO WORLD');
// *     returns 2: 'HELLO WORLD'
function ucwords (str) {
    return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase( ); } );
}

// Searches the array for a given value and returns the corresponding key if successful  
// 
// version: 909.322
// discuss at: http://phpjs.org/functions/array_search
// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +      input by: Brett Zamir (http://brett-zamir.me)
// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
// *     returns 1: 'surname'
function array_search (needle, haystack, argStrict) {
    var strict = !!argStrict;
    var key = '';

    for (key in haystack) {
        if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
            return key;
        }
    }

    return false;
}

// replacing space with dash
function dash( input ){
	input = input.toLowerCase();
	input = input.replace(/ /, "-");
	return input;	
}

// debug something
function debug( text ){
	try{
		console.log(text);
	}catch(e){
		alert(text);	
	}
}

// made the width of bgImage bigger than it should be. (deprecated?)
function setSize() {
	w = $(window).width();
	h = $(window).height();
	
	$('#bgImage').css("width",10*w+'px'); 
	if (h>600) { $('#black-bg').css("height",h+'px'); }

	r = w/h;
	if (r > ratio) {
		slideWidth = w;
		slideHeight = w/ratio;
	} else {
		slideHeight = h;
		slideWidth = h*ratio;
	}
		
	$("#container img").attr("width",slideWidth);
	$("#container img").attr("height",slideHeight);
		
	$('#container').css("margin-left",-slideWidth/2);
	$('#container').css("margin-top",-slideHeight/2);
		
	$('#bgImage').css("margin-left",-(page-1)*slideWidth);
	
}

// deprecated (this will change the background of the site)
function changeBackground(file){
	if(!isDefined(file) && getCookie("background")!=""){
		$("#loading").toggle();
		$image = $("<img />");
		$image.attr("src", "/images/profile/" + getCookie("background"));
		$image.css("height", $(window).height());
		$image.css("width", $(window).width());		
		$('#bgImage').text($image);
		var html = "<img src='/images/profile/" + getCookie("background") + "' />";
		$('#bgImage').html(html);			
		$("#loading").toggle();
	}else{
		$("#loading").toggle();
		$image = $("<img />");
		$image.attr("src", "/images/profile/" + file);
		$image.css("height", $(window).height());
		$image.css("width", $(window).width());		
		$('#bgImage').html($image);
		$("#loading").toggle();
		setCookie("background", file);
	}
}

// this will change the image on the gallery with the label
function changeImageOnGallery( src, label ){
	$("#main-gallery-image").attr("src", "/images/loading-heart.gif");
	setTimeout(function(){
		$("#main-gallery-image").attr("src", src);
		$("#main-gallery-image").show();
		$("#main-gallery-label").html(label);	
	},1000);
}

// will create thumbnail of images for favourite page
function createImageBlock( data, size ){
	var output = "";
	if( size == 20 ) output += '<div class="align-left pointer" onclick="changeImageOnGallery(\''+data.image+'?crop(300x300)\', \'' + addslashes(data.label) + '\');">';
	else output += '<div class="align-left">';	
		output += '<input type="hidden" value="' + data.id + '" name="ids[]" />';
		output += '<img src="' + data.image + '?crop(' + size + 'x' + size + ')" width="'+size+'" height="'+size+'" style="margin-right:3px; margin-bottom:3px;" />';
	output += '</div>';
	return output;
}

// will initialise the gallery
function initGallery( id ){
	var url = '/json-data/business-gallery.json?id=' + id;
	$.get(url, function(data){
		json = eval("(" + data + ")");
		data = json.data;
		var output = "";
		if( data.length>0 ){
			// show big image
			output += '<div style="height:300px; width:300px;">';
			output += '<div class="img-round-mask-big"></div>';
			output += '<img src="' + data[0].image + '?crop(300x300)" id="main-gallery-image" /><br />';
			output += '</div>';
			output += '<div class="bg-cream round">';
				output += '<div class="tt-up"></div>';
				output += '<div class="overflow padding15">';
					output += '<div style="padding-top:0px; padding-bottom:5px;" id="main-gallery-label">';				
						output += data[0].label;
					output += '</div>';					
					output += '<div class="clear"></div>';
					output += '<div id="thumbnail">';
						for(var i=0; i<data.length; i++){
							if( isDefined(data[i].image)){
								output += createImageBlock(data[i], 20);						
							}
						}
					output += '</div>';					
				output += '</div>';
			output += '</div>';
			$("#images").html(output);
		}else{
			output += '<div class="img-round-mask-big"></div>';
			output += '<img src="/images/default_business_big.png?crop(300x300)" width="300" height="300" /><br />';
			$("#images").html(output);
		}
	});	
}

// create thumbnail of video that is stored on the table/db
function createVideoBlock( data, size ){
	var output = "";
	output += '<div class="align-left pointer" onclick="changeVideoOnGallery(\''+data.video+'\', \'' + addslashes(data.label) + '\');" style="margin-bottom:5px; margin-right:5px;">';
		output += '<img src="' + data.thumbnail + '" width="50" height="38" />';
	output += '</div>';
	
	return output;
}

// change the video when thumbnail is clicked
function changeVideoOnGallery( src, label ){
	output = '<div id="v-c">';
		output += '<object width="440" height="273"><param name="movie" value="'+src+'&rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+ src +'&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="440" height="273"></embed></object>';
	output += '</div>';
	$("#video").html(output);		
}

// initialise video gallery on favourite detail page
function initVideoGallery( id ){
	var url = '/json-data/business-video-gallery.json?id=' + id;
	$.get(url, function(data){
		json = eval("(" + data + ")");
		data = json.data;
		var output = "";
		if( data.length>0 ){
			if( data.length > 1 ){
				for(var i=0; i<data.length; i++){
					if( isDefined(data[i].video)){
						output += createVideoBlock(data[i], 20);						
					}
				}
				$("#video-thumbnail").html(output);
			}
			changeVideoOnGallery(data[0].video, '');							
			$("#video-container").fadeIn();
			
		}
	});	
}
/* ********************************************************************************************************* */
function attachRolloverForAvatar(){
	/*
	$(".avatar").mousemove(function(e){
		$rollover = $(this).find(".tooltip");
		$rollover.css("left", e.pageX);
		$rollover.css("top", e.pageY-35);				
	});
	$(".avatar").hover(
		function(e){
			$rollover = $(this).find(".tooltip");
			$rollover.css("left", e.pageX);
			$rollover.css("top", e.pageY-35);				
			$rollover.show();
		},
		function(){
			$rollover = $(this).find(".tooltip");	
			$rollover.hide();
		}
	);
	*/
}

// attach the top arrow for action box 
function setTopArrow() {
	/* calculate the position of cream top arrow */
	//var w1 = $("#action-box-trigger-actived .back").width();
	var w2 = $("#action-box-trigger-actived .current-trigger").width();
	/* 20px(container padding-left) + 8px (a margin-left) + w1 + 30px (space dash space) + w2 - w2/2 - 20/2 (half arrow width) = 48 + w1 + w2/2 */
	var arrow_margin_left =  ( (w2/2)) + 'px';
	$('#action-box-popup .tt-up').css('margin-left', arrow_margin_left);
}

// validate email address
function isRFC822ValidEmail(sEmail) {

  var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
  var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
  var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
  var sQuotedPair = '\\x5c[\\x00-\\x7f]';
  var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
  var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
  var sDomain_ref = sAtom;
  var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
  var sWord = '(' + sAtom + '|' + sQuotedString + ')';
  var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
  var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
  var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
  var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
  
  var reValidEmail = new RegExp(sValidEmail);
  
  if (reValidEmail.test(sEmail)) {
    return true;
  }
  
  return false;
}

// showing error on infobox if something wrong happen or not validated
function showInfoOrErrorOnInfoBox(msg, color, obj) {
	var html = '<div style="width:280px;" class="overflow"><div class="align-right"><div class="tt-up" style="margin-right:20px;"></div></div></div>' + msg;
	
	$info = $("#info-" + $(obj).attr("name"));	
	
	//$(".info-box:not([errorState=1])").hide();
	
	$info
		.hide()
		.removeClass("bg-"+memberColor).removeClass("bg-grey")
		.addClass("bg-" + color)
		.html( html )
		.css({"margin-top":"-15px", "margin-bottom":"10px", "width":($(obj).width()-10)+"px"})
		.fadeIn(500);
}

// validate each form elements based on the rules (attribute called validation)
// supplied. This function will be called on the actionbox's form
function validationForm (obj, e) {
	
	var i=0;
	$info = $("#info-" + $(obj).attr("name"));
	//if ( $(obj).attr("validation").length<1) alert( "#info-" + $(obj).attr("name") );
	var value = $(obj).val();
	var rules = $(obj).attr("validation").split("},{");
	var objType = $(obj).attr("type");
	
	if( !isDefined( $(obj).attr("errorState") ) )
	$(obj).attr("errorState", "0");
	
	while(isDefined(rules[i])) {
		
		// process the rules on the validation tag
		var text = rules[i];		
		text = rtrim(ltrim(text, "{"), "}");			
		rule = text.split("]:[");
		regexp 	= rule[0].substr(1); /* value: info | empty | email */
		message = rule[1].substr(0, rule[1].length-1);

		if (e == 'focus') {
			if( regexp == "info" ) {
				showInfoOrErrorOnInfoBox(message,'grey', obj);
			}
		} else if (e == 'blur') {	
			if( regexp == "empty" ) {
				if(objType=="checkbox"){
					if( $(obj).attr("checked") == false ){
						showInfoOrErrorOnInfoBox(message, memberColor, obj);
						$(obj).attr("errorState", "1");
					}else{
						$info.hide();
					}
				}else{			
					if(value == "" || isDefined(value)==false) {
						showInfoOrErrorOnInfoBox(message, memberColor, obj);
						$(obj).attr("errorState", "1");
					}else{
						$info.hide();
					}
				}				
			} else if( regexp == "checkExistingUserName" ) {
				username = trim( value );
				if( username != "" ){
					var regex = /^[0-9a-z-A-Z-_]+$/;
					if( $(obj).attr("existingUsername") == value ){
					}else{
						if( !regex.test(username) ){
							showInfoOrErrorOnInfoBox("Your username may only contain letters A-Z, numbers 0-9 and no spaces.", memberColor, obj);
						}else{
							var url = "/json-data/validate.json?b=username&data=" + username;
							var o = obj;
							$.get(url, function(data){
								response = eval("(" + data + ")");
								if( response.status == 0 ){
									showInfoOrErrorOnInfoBox(message, memberColor, o);
									$(o).attr("errorState", "1");
								}
							});
						}
					}
				}
			} else if( regexp == "checkExistingEmail" ) {
				email = trim( value );
				if( email != "" ){
					var regex = /^[0-9a-z-A-Z-_]+$/;
					if( $(obj).attr("existingEmail") == value ){
					}else{
						if( isRFC822ValidEmail(value) == false ){
							showInfoOrErrorOnInfoBox("Please enter a valid email address", memberColor, obj);
						}else{
							var url = "/json-data/validate.json?b=email&data=" + email;
							var o = obj;
							$.get(url, function(data){
								response = eval("(" + data + ")");
								if( response.status == 0 ){
									showInfoOrErrorOnInfoBox(message, memberColor, o);
									$(o).attr("errorState", "1");	
								}
							});
						}
					}
				}
			} else if( regexp == "mismatchPassword" ){
				var inputId = $(obj).attr("id");
				inputId = inputId.substring(0, inputId.length-1);	
				if( value != $("#" + inputId).val() ){
					showInfoOrErrorOnInfoBox(message, memberColor, obj);
					$(obj).attr("errorState", "1");
				}else{
					$info.hide();
				}
			} else if( regexp == "email" ) {
				if(value !="" && isRFC822ValidEmail(value)==false) {
					showInfoOrErrorOnInfoBox(message,memberColor, obj);
					$(obj).attr("errorState", "1");
				}else{
					$info.hide();
				}
			} else {
				$info.hide();
			}
		}
		i++;
	}
}

// start the validation of the form
function formIsError(){
	window.formError = false;
	
	$("#action-box-form-container input, #action-box-form-container select, #action-box-form-container textarea").each(function(){
		if( isDefined( $(this).attr("validation") ) ){
			$(this).trigger('blur');
		}
	});
	
	// check if there's an error on the fields
	$("#action-box-form-container input, #action-box-form-container select, #action-box-form-container textarea").each(function(){
		if( isDefined( $(this).attr("errorState") ) ){
			if( $(this).attr("errorState") == "1" ){
				window.formError = true;
				resetLockedButton();
			}
		}
	});
	
	if( window.formError ){
		$("form #info-box-for-button").fadeIn();
		resetLockedButton();
		return true;
	}else{
		$("form #info-box-for-button").fadeOut();
		return false;	
	}
}

// used for community/country.html
function createSmallItem( data, mode ){
	var output = '';
	var id = data.id;
	var image = data.image + "?crop(48x48)";
	var name = data.title;
	var location = ucfirst( data.community.region_name ) + " - " + ucfirst( data.community.community );
	var url = data.url;
	var color = data.color;
	
	return data.avatar;
}

// get the object of flash movie
function getFlashMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

// add market to the map from javascript to flash
function addMarkerToMap(flash, str) {
	getFlashMovie(flash).sendToActionscript(str);
}

// helper function for JSON.stringify
function replacer(key, value) {
	if (typeof value === 'number' && !isFinite(value)) {
		return String(value);
	}
	return value;
}

// hichlight the marker from javascript to flash
function highlightMarker(flash, id){
	getFlashMovie(flash).sendToActionscript_2(id);
}

// create promotion/event list - used on display all 
// promotion/event page
function createPromotionEventList(data, color){
	var output = "";
	var tmp = data.start_date;
	tmp = tmp.split(" ");
	day = tmp[0];
	month = tmp[1].toUpperCase();
	output += '<div class="overflow">';
		output += '<div class="align-left">';
			//output += '<img src="/images/assets/feed-action/feed_event_'+ color+'.png?resize(48x48)" />';						
			if(data.object_type == "event" )
				output += '<div style="width:48px; height:48px; background-image: url(\'/images/assets/event/event_listing_'+ color+'.png?resize(48x48)\'); background-repeat:no-repeat; font-size:24px; font-weight:bold; padding-left:7px; padding-top:5px; color:white;">' + day + '<div class="font-12" style="margin-top:-2px;">' + month + '</div></div>';				
			else if( data.object_type == "promotion" )
				output += '<img src="/images/assets/promotion/promotion_listing_'+ color+'.png?resize(48x48)" />';
		output += '</div>';
		output += '<div class="align-left bg-cream round" style="width:400px; margin-bottom:10px; margin-left:-7px;">';
			output += '<div class="tt-left"></div>';		
			output += '<div class="padding5">';
				output += '<strong><a href="' + data.link + '">' + data.title + '</a></strong>';
				output += '<div style="margin-top:3px;">Date: ' + data.start_date + ' - ' + data.end_date + '</div>';
				if( isDefined(data.business) )
					output += '<div>Community: ' + ucwords( data.business.community.community ) + '</div>';				
				else
					output += '<div>Community: ' + ucwords( data.community.community ) + '</div>';
			output += '</div>';			
		output += '</div>';
	output += '</div>';
	output += '<div class="clear"></div>';
	return output;
}

// create a notice (notice has a different style)
function createNotice(data){
	var output = "";
	output += '<div class="notices round bg-cream" style="height:140px;">';
		output += '<img class="notice-clip" src="/images/notices.png" />';
		output += '<div class="padding10">';
			//output += '<strong><a onclick="getNoticeDetail(' + data.id + ')">' + data.title + '</a></strong>';
			output += '<strong><a href="' + data.link + '">' + data.title + '</a></strong>';			
			output += '<div>' + limitWord(data.description, 15) + '</div>';				
		output += '</div>';
	output += '</div>';
	return output;
}

// this will embed a inline confirmation box to the first h3 on the #content div
function showConfirmationBox( message, color, timeout ){
	var output = "";
	if( isDefined(timeout) ) id = "timed-confirmation-box";
	else id = "fixed-confirmation-box";
	
	if( !isDefined(color) || color=="" ) color = window.localColor;
	
	output += '<div id="' + id + '" class="round hidden bg-' + color + '">';
		output += '<div class="padding10">' + message + '</div>';
	output += '</div>';
	
	$("#content h3:first").before(output);
	$("#" + id).fadeIn();
	if( isDefined(timeout) ){
		setTimeout(function(){
			$("#timed-confirmation-box").remove();
		}, timeout);
	}
	return output;
}

// deprecated
function showConfirmationBoxForInbox( message, color, timeout, container ){
	var output = "";
	if( isDefined(timeout) ) id = "timed-confirmation-box";
	else id = "fixed-confirmation-box";
	
	if( !isDefined(color) || color=="" ) color = window.localColor;
	
	output += '<div style="margin:10px;" id="' + id + '" class="round hidden bg-' + color + '">';
		output += '<div class="padding10">' + message + '</div>';
	output += '</div>';
	
	$(container).before(output);
	$("#" + id).fadeIn();
	if( isDefined(timeout) ){
		setTimeout(function(){
			$("#timed-confirmation-box").remove();
		}, timeout);
	}
	return output;
}

// deprecated
function processFavorite(id){
	if(confirm("Are you sure about this?")){
		$.get('/json-data/process-favorite.json', {"businessId":id}, function(data){
			response = eval("(" + data + ")");
			showConfirmationBox( response.message, "", "3000");
			return false;
		});
	}
}		

// deprecated
function showSummaryBlock(id){
	if( id == "summary-community" ){
		$("#summary-favorite-container").hide();				
		$("#summary-community-container").fadeIn();
	}else{
		$("#summary-community-container").hide();
		$("#summary-favorite-container").fadeIn();				
	}
	$(".summary-btn-trigger").removeClass("active");
	$("#" + id).addClass("active");
}

// create content of summary block
function createSummaryBlockList( data ){
	var output = "";
	var color = "";
	type = data.object_type;
	if(type == "general"){
		type = "notice";
		size = "13x24";
	}else if( type == "promotion" || type == "event" ){
		size = "18x18"			
	}else{
		size = "19x10";
	}
	if( data.business_id != "" && data.business_id != "0" ){
		color = data.business.color;
		label = "" + ucwords(data.business.title);
	}
	if( data.community_id != "" && data.community_id != "0" ){
		color = data.community.color;
		label = "" + ucwords(data.community.community);
	}
	var truncated = false;
	if(data.title.length>32){
		truncated = true;	
	}
	
	var vTitle = (data.title.length>32)?data.title.substr(0, 32) + "...":data.title;
	output += '<div class="overflow right-listing" ' + ((truncated)?'name="' + data.title + '"':'') + ' style="border-bottom:1px dotted #333; padding-top:3px; padding-bottom:3px;">';
		output += '<div class="align-left" style="width:23px; text-align:center;">';				
			if( type == "event"){
				var tmp = data.start_date.split(" ");
				output += createEventIcon(new Array(tmp[0],tmp[1]), color, color, true, data.link);
			}else{
				output += '<img src="/images/assets/feed-action/feed_' + type + '_' + color + '.png?resize(' + size + ')" />';
			}
		output += '</div>';
		output += '<div class="align-left padding10' + color + '" style="margin-left:10px; width:245px;">';					
			output += '<a href="' + data.link + '" class="' + color + ' font-14">' + vTitle + '</a>';
			output += '<div style="margin-top:-2px; *margin-top:0px;"><a href="' + data.link + '" class="font-10 dark-grey bold uppercase">' + label + '</a></div>';
		output += '</div>';
	output += '</div>';
	output += '<div class="clear"></div>';
	return output;
}

// approve friend request using ajax
function approveFriendRequest(memberId){
	$.post("/json-data/approve-friend-request.json", {"id":memberId}, function(data){
		response = eval("(" + data + ")");
		$("#approval-container").html(response.message);
		return false;
	});
}

// approve team member using ajax
function approveTeamMember(businessId){
	$.post("/json-data/approve-team-member-request.json", {"id":businessId}, function(data){
		response = eval("(" + data + ")");
		$("#approval-container").html(response.message);
		// ActionBox.prototype.close( response, false, function(){ $("#other").html(""); } );
		return false;
	});
}

// deprecated
function deleteMessage(id){
	cb.create('Are you sure you want to delete this message - by doing this, you will not be able to get it back! ','/json-data/delete-message.json?id=' + id );
	$("#item-" + id).hide();
}

// function is used for a step-by-step panel on the form, this will 
// hide all panel and only display defined panel number
function showPanel( number ){
	$("#loading").show();
	$(".steps").hide();
	$("#step" + number).show();
	$("#loading").hide();
}

// only for favourite form
function showPanelFavourite(number){
	$("#loading").show();
	$(".stepFavourite").hide();
	$("#stepFavourite" + number).fadeIn(100, function(){
		$("#loading").hide();
	});
}


// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com
// Created by: John G. Wang | http://www.csua.berkeley.edu/~jgwang/
function checkCapsLock( e, divId ) {
	var myKeyCode=0;
	var myShiftKey=false;
	var myMsg='Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

	// Internet Explorer 4+
	if ( document.all ) {
		myKeyCode=e.keyCode;
		myShiftKey=e.shiftKey;

	// Netscape 4
	} else if ( document.layers ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	// Netscape 6
	} else if ( document.getElementById ) {
		myKeyCode=e.which;
		myShiftKey=( myKeyCode == 16 ) ? true : false;

	}

	// Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
	if ( ( myKeyCode >= 65 && myKeyCode <= 90 ) && !myShiftKey ) {
		$("#" + divId).show();
	// Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
	} else if ( ( myKeyCode >= 97 && myKeyCode <= 122 ) && myShiftKey ) {
		$("#" + divId).show();
	}else{
		$("#" + divId).hide();	
	}
}

// http://kevin.vanzonneveld.net
// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   improved by: Gabriel Paderni
// +   improved by: Philip Peterson
// +   improved by: Simon Willison (http://simonwillison.net)
// +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// +   bugfixed by: Anton Ongson
// +      input by: Onno Marsman
// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +    tweaked by: Onno Marsman
// +      input by: Brett Zamir (http://brett-zamir.me)
// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   input by: Oleg Eremeev
// +   improved by: Brett Zamir (http://brett-zamir.me)
// +   bugfixed by: Oleg Eremeev
// %          note 1: The count parameter must be passed as a string in order
// %          note 1:  to find a global variable in which the result will be given
// *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
// *     returns 1: 'Kevin.van.Zonneveld'
// *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
// *     returns 2: 'hemmo, mars'
function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}

// create a link out of a text that looks like a link
function linkify(text){
    if (text) {
        text = text.replace(
            /((https?\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
            function(url){
                var full_url = url;
                if (!full_url.match('^https?:\/\/')) {
                    full_url = 'http://' + full_url;
                }
                return '<a href="' + full_url + '" target="_blank">' + url + '</a>';
            }
        );
    }
    return text;
}

// disable a submit button to prevent double submission
jQuery.fn.lockSubmit = function(options) {
	// default text to change submit button too
	var settings = jQuery.extend({
		submitText: null,
		onAddCSS: null,
		onClickCSS: null
	}, options);

	// add CSS to this button
	if(settings.onAddCSS) {	this.addClass(settings.onAddCSS); }

	return this.click(function(e) {		

		// Hide current submit and insert a dummy submit which is disabled. The reason for doing this and not just disabling the normal submit, 
		// is that in some browsers the disabled submit will stop the form being submited at all.
		targetselect = jQuery(this);

		targetselect.hide();
		
		// new buttons value
		if(settings.submitText) { var newValue = settings.submitText; } else { var newValue = jQuery(this).val(); }

		// insert hidden field with name and value of submit
		targetselect.after("<input id='dummySubmit' disabled='disabled' type='submit' name='"+jQuery(this).attr("name")+"DUMMY' style='height:25px;' value='"+newValue+"'>");

		// add onClick CSS
		if(settings.onClickCSS) {
			jQuery("#dummySubmit").addClass(settings.onClickCSS);
		}

		return true;
	});
};

// resetting the locked submit button
jQuery.fn.lockSubmitReset = function() {
	this.show();
	jQuery("#dummySubmit").remove();
};

// resetting the locked submit button
function resetLockedButton(){
	$("#action-box-form-container-content .disabled-after-click").lockSubmitReset();
}

// remove the lastline on the listing (the hr line)
function removeLastLineOnRightListing(){
	$(".arrow-box ").each(function(){
		if( $(this).find(".right-listing").length > 0 )
			$(this).find(".right-listing:last").css({"margin-bottom":"-1px", "border-bottom":"0px"});
		else
			$(this).parent(".right-listing-container").hide();
	});	
}

// perform translation on all container that have .translate
function translateAll(){
	/*
	try{
		google.setOnLoadCallback(translateAll);
	}catch(e){  }
	$("#loading").show();

	// offer on the fly translation
	$(".translate").each(function(){
		var object = $(this);
		var text = object.text();
		try{
			google.language.detect(text, function(result) {
				if( !result.error && result.language!="en") {
					//var object = object;
					text = text.replace('<br>','<br />');
					try{
						google.language.translate(text, result.language, "en", function(result) {
							if (result.translation) {
								window.translateCount++;
								originalText = text;
								text = result.translation;
								text = text.replace('\n','<br />');
								object.attr('name', result.translation);
								output = text;
								object.attr("name", '<div style="width:300px;"><strong>Google translation:</strong><br />' + output + '.</div>');
								object.tipTip({maxWidth: "auto", edgeOffset: 2});
							}
						});
					}catch(e){}
				}
			});
		}catch(e){}
	});	
	$("#loading").hide();
	*/
}

// logging out the facebook
function fbLogout(){
	try{
		FB.Connect.logout(function(){location.href=HTTP_SERVER});
	}catch(err){
		
	}
}

// this is used for favourite tab page when you click heart on the right
// will revoke this function and change the color to something else if you
// change the color of that particular favourite.
function processFavourite( id, color ){
	$("#indicator-for-" + id).fadeOut(300);
	$.post('/json-data/process-favorite.json', {"memberId":window.loggedMember.id, "businessId":id}, function(data){
		response = eval("(" + data + ")");
		
		
		$("#indicator-for-" + id).attr("onmouseout", "");
		$("#indicator-for-" + id).attr("onmouseover", "");

		if( response.message.search('added') == -1 ){
			// remove
			$("#indicator-for-" + id).attr("name", "Add");						
			$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_heartadd_grey.png");						
		//	$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_heartadd_" + color + ".png");				
		
		}else{
			// add
			$("#indicator-for-" + id).attr("name", "Remove");						
			$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_heart_" + color + ".png");				
		}
		
		if( color != response.data.color ){
			var newColor = response.data.color;
			
			if( newColor == "orange" || newColor == "yellow" ){
				$("#list-item-container-" + id ).removeClass("bg-cream").addClass("bg-" + newColor);
				$("#list-item-title-" + id ).removeClass(color).addClass("darkgrey");
				$("#list-item-f-" + id ).attr("src", '/images/assets/title/title_person_darkgrey.png?resize(10)');
				if( response.message.search('added') == -1 ){
					// remove
					$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_heart_grey.png");				
				}else{
					// added
					//$("#indicator-for-" + id).attr("src", "/images/assets/indicator/tick_darkgrey.png?resize(10)");
					$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_heartadd_grey.png");
					
				}
				$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_colour_fave_grey.png");
				
				
				$("#list-item-creator-" + id ).removeClass(color).removeClass("red").removeClass("turqouise").removeClass("blue").removeClass("green").removeClass("pink").removeClass("brown").removeClass("purple").removeClass("orange").removeClass("yellow").removeClass("xxx").addClass("darkgrey");
				$("#list-item-category-" + id ).removeClass('light-grey').addClass("darkgrey");
				$("#list-item-community-" + id ).removeClass('light-grey').addClass("darkgrey");	
				$("#list-item-c-" + id ).removeClass('light-grey').addClass("darkgrey");	
				$("#list-item-d-" + id ).removeClass('light-grey').addClass("darkgrey");	
				$("#list-item-meta-" + id ).removeClass('light-grey').addClass("darkgrey");						
			}else{
			
				$("#list-item-container-" + id ).removeClass("bg-cream").addClass("bg-" + newColor);
				$("#list-item-title-" + id ).removeClass(color).addClass("white");
				$("#list-item-f-" + id ).attr("src", '/images/assets/title/title_person_white.png?resize(10)');
				if( response.message.search('added') == -1 ){
					// remove
					$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_heartadd_grey.png");				
				}else{
					// added
					$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_colour_fave_white.png");
				}
				$("#indicator-for-" + id).attr("src", "/images/assets/feed-action/feed_colour_fave_white.png");
				
				$("#list-item-creator-" + id ).removeClass(color).removeClass("red").removeClass("turqouise").removeClass("blue").removeClass("green").removeClass("pink").removeClass("brown").removeClass("purple").removeClass("orange").removeClass("yellow").removeClass("xxx").addClass("white");
				$("#list-item-category-" + id ).removeClass('light-grey').addClass("white");
				$("#list-item-community-" + id ).removeClass('light-grey').addClass("white");	
				$("#list-item-c-" + id ).removeClass('light-grey').addClass("white");	
				$("#list-item-d-" + id ).removeClass('light-grey').addClass("white");	
				$("#list-item-meta-" + id ).removeClass('light-grey').addClass("white");		
			}
		
		// if member didn't change the color
		}
		
		$("#indicator-for-" + id).fadeIn(300);
		
		// check if ipad in campaign
		if( id == 2725 ){
			window.ab.create('referral', new Array(2725, 4));
		}
	
		attachStyle();
		return false;
	});	
}

// alias for avatarAlign
function alignAvatar(numPerLine, container){
	avatarAlign(numPerLine, container);
}

function avatarAlign(numPerLine, container) {
	if( !isDefined(numPerLine) ) var numPerLine = 5;
	if( !isDefined(container) ) var container = '.widget';

	var numOfAvatar=1;
	$(container + " .avatar").each(function(){
		if( numOfAvatar%numPerLine==0){
			$(this).addClass("last-col");
			$(this).after('<div class="clear"></div>');
		}
		numOfAvatar++;
	});
}

function createItemList(id, radioButton, imageSrc, title, smallText, description, tooltip, categoryIsEnabled, color, width, draggable){
	var output = "";
	if( isDefined(color) ) titleColor = color;
	else titleColor = "darkgrey";

	if( isDefined(width) ){
		if( width == 330 ){
			width = width;
			detailWidth = 250;
		}else{
			width = width;
			detailWidth = width-80;
		}
	}else{
		width = 440;
		detailWidth = 360;
	}
	if( isDefined( draggable ) && draggable == true )
	cursor = "move";
	else
	cursor = "pointer";

	output = '<div class="margin0 font14 overflow  all-item" id="item-' + id + '" style="margin:0px; width:' + width + 'px; cursor: ' + cursor + '; " name="' + tooltip + '">';
		//output += '<div style="height:10px;"></div>';
		output += '<div class="margin0 overflow align-left list-image" style="margin-right:5px;">';
			output += radioButton;
			output += '<img src="' + imageSrc + '?crop(20x20)" />';
		output += '</div>';
		output += '<div class="align-left margin0" style="width:' + detailWidth + 'px;">';
			output += '<div class="margin0">';
				output += '<label for="item-' + id + '">';			
					output += '<div class="margin0 ' + titleColor + ' item-title" >' + ucwords(title) + '</div>';
					output += '<div class="margin0 light-grey">';
						if( smallText!="" ){
							output += '<div class="uppercase font-10 bold">' + ucwords(smallText) + '</div>';
							output += '<div style="height:10px;"></div>';
						}
						if( description!="" ){
							output += '<div class="font-14 not-bold" style="line-height:16px;">' + ucwords(description) + '</div>';
							output += '<div style="height:10px;"></div>';							
						}
					output += '</div>';
					output += '<div class="margin0 categoryContainer" id="categoryFor' + id + '"></div>';
				output += '</label>';
			output += '</div>';
		output += '</div>';
	output += '<div class="hr margin0 padding0" style="height:1px;"></div>';
	output += '</div>';
	//output += '</div>';
	return output;
}	

function createEventIcon( date, staticColor, rolloverColor, smallMode, url ){
	var output = "";
	
	if( staticColor == "" ){
		staticColor = "grey";	
	}
	
	if( isDefined( smallMode ) && smallMode == true ){
		output += '<div style="margin-left:0px; width:24px; height:24px;" class="bg-'+staticColor+' round" onclick="location.href=\'' + url + '\'">';
			output += '<div class="white bold capitalize" style="text-align:center; width:24px; padding-top:3px; font-size:8px;">' + date[1] + '</div>';			
			output += '<div class="white bold" style="width:24px; text-align:center; padding-top:0px; font-size:12px;">' + date[0] + '</div>';			
		output += '</div>';
	}else{
		output += '<div style="margin-left:10px; width:28px; height:28px; margin-bottom:4px;" class="bg-' + staticColor + ' round ' + ((url!="")?"pointer":"") + '" onclick="location.href=\'' + url + '\'" onmouseover="$(this).removeClass(\'bg-' + staticColor + '\'); $(this).addClass(\'bg-' + rolloverColor + '\'); " onmouseout="$(this).removeClass(\'bg-' + rolloverColor + '\'); $(this).addClass(\'bg-' + staticColor + '\'); ">';
			output += '<div class="white capitalize" style="padding-top:2px; font-size:9px;">' + date[1] + '</div>';			
			output += '<div class="white bold" style="padding-top:0px; font-size:16px;">' + date[0] + '</div>';			
		output += '</div>';
	}
	
	
	
	return output;
}