function trim(s) 
{
	return s.replace(/^\s+|\s+$/g,'');
}


ieHover = function() {
	if (document.getElementById("sm-calendar")) {
		var ele = document.getElementById("sm-calendar").getElementsByTagName("td");
		for (i=0; i<ele.length; i++) {
			if (ele[i].className.indexOf('event-day') != -1) {
				
				ele[i].onmouseover=function() { 
					this.className += " iehover";
				}
				ele[i].onmouseout=function() {
					this.className = this.className.replace(" iehover", "");
				}
			}
		}
	}
}

/*
$(document).ready(function(){
 	for (var i=1; i <= 31; i++)
	{
		$("td#day_"+i+" a").hover(function() {
			$(this).next("div.event-wrapper").css('margin-top', '-50px');
		});
		$("td#day_"+i+" a").mouseout(function() {
			$(this).next("div.event-wrapper").css('margin-top', '-1000px');
		});
	}

	$('a.external').click(function(){ 
		window.open(this); return false;
	});
});*/	
	
function startGallery() {
	var myGallery = new gallery($('myGallery'), {
		timed: true,
		delay: 6000,
		slideInfoZoneOpacity: 0.8,
		showCarousel: false 
	});
}
window.addEvent('domready', startGallery);
window.addEvent('domready', ieHover);

function show_calendar(d)
{
	document.getElementById('calendar-box').innerHTML = "<div id='calendar-load'>Loading<br/><img src='img/icon/loading.gif' alt='Loading..' /></div>";
	var ajax; 
	try {
		ajax = new XMLHttpRequest();
	} catch (e){
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser broke!");
				return false;
			}
		}
	}
	ajax.open("GET", 'common/calendar.php?d=' + d, true);
	ajax.onreadystatechange = function() {
		if(ajax.readyState == 4){
			setTimeout(function() { update_calendar(ajax.responseText); }, 1000);
			ieHover();
		}
	}
	ajax.send(null); 	
}

function update_calendar(html)
{
	document.getElementById('calendar-box').innerHTML = html;
}

function char_count(obj)
{
	if (obj.value.length > 1000) {
		obj.value = obj.value.substr(0, 1000);	
		alert('You have exceeded the allowed character length');
	}
	
	var c = document.getElementById('char-count');
	c.innerHTML = "" + (1000 - obj.value.length);
}