
var isNS6

isNS6 = Boolean(document.getElementById && Boolean(!document.all));

function flashRowOff(obj, colorOff,dateValue) {
	obj.style.background = colorOff;
	var trEls = document.insetCal.document.getElementsByTagName('td');
	for (var i = 0;i<trEls.length;i++) 	{
			if (trEls[i].value==dateValue)  	{
				trEls[i].style.backgroundColor  = lastColor;
				return;
			}
	}
}

function flashRowOn(obj,dateValue) {
	var trEls
	obj.style.background = '#FFFFAA'
	
	if (isNS6)
		trEls	= document.getElementById('insetCal').contentDocument.getElementsByTagName('td');
	else
		trEls	= document.insetCal.document.getElementsByTagName('td');
	try {
	for (var i = 0;i<trEls.length;i++) 	{
		if (trEls[i].value==dateValue)  	{
			lastColor = trEls[i].style.backgroundColor;
			trEls[i].style.backgroundColor = '#FFFFAA';
			return;
		}
	}
	} catch(e) { alert(e + '\n' + isNS6); }
}

function trim(s) {
 var r=/\b(.*)\b/.exec(s);
 return (r==null)?"":r[1];
}


function goSearch() {

try {
	var result  = 0;
	if (arguments.length==2) {
		document.calendarSearch.calYear.value = arguments[0];
		document.calendarSearch.calMonth.value = arguments[1];
	 }

	if (document.getElementById('AllBox') && document.getElementById('AllBox').checked) 
	{
		document.getElementById('Category').value = 0;	
		result  = 0;
	}
	else
	{
		var els = document.getElementsByTagName("input")
		
		for (var i = 0;i<els.length;i++) {
			var elGuy = els[i];
			if ((els[i].type == 'checkbox') && (elGuy.checked))
				result += parseInt(elGuy.value);
		}
		
		document.getElementById('Category').value = result;	
	}
	
	document.cookie = "mcwEvents=" + result.toString() + ExpiresString();
	
	if (trim(document.calendarSearch.textfield.value) != '' && document.calendarSearch.textfield.value != 'Keyword Search'){
	   document.calendarSearch.keyword.value= trim(document.calendarSearch.textfield.value);
	}

    if (document.calendarSearch.keyword.value != ''){
      document.calendarSearch.timeSpan.value = '';
    }

	document.calendarSearch.submit();
	} catch (e) {alert(e.description) 	}

	function ExpiresString() {
		var dateObj = new Date();
		dateObj.setFullYear(dateObj.getFullYear()+1);
		return ("; expires="+dateObj.toGMTString())
	}

}

function getDay() {

try {
    document.calendarSearch.calDay.value = 1
    document.calendarSearch.timeSpan.value ="day"
    document.calendarSearch.submit();

	} catch (e) {alert(e.description) 	}

	function ExpiresString() {
		var dateObj = new Date();
		dateObj.setFullYear(dateObj.getFullYear()+1);
		return ("; expires="+dateObj.toGMTString())
	}

}

function getWeek() {

try {
    if(document.calendarSearch.timeSpan.value =="month"){ 
      document.calendarSearch.calDay.value = 1
    }
    document.calendarSearch.timeSpan.value ="week"
    document.calendarSearch.submit();

	} catch (e) {alert(e.description) 	}

	function ExpiresString() {
		var dateObj = new Date();
		dateObj.setFullYear(dateObj.getFullYear()+1);
		return ("; expires="+dateObj.toGMTString())
	}

}

function getMonth() {

try {
    document.calendarSearch.timeSpan.value ="month"
    document.calendarSearch.submit();

	} catch (e) {alert(e.description) 	}

	function ExpiresString() {
		var dateObj = new Date();
		dateObj.setFullYear(dateObj.getFullYear()+1);
		return ("; expires="+dateObj.toGMTString())
	}

}


function getEventsCookieData(cookieName) {
	var cookies = String(document.cookie).split(';');
	for (var crumb in cookies) 	{
		var arr =  cookies[crumb].split(/=/);
		if (arr.length==2) {
			if (arr[0]==cookieName)
				return unescape(arr[1]);
		}
	}
	return 0;
}

function AllisClicked(objThis) {

	if (objThis.checked) 
	{
		var els = document.calendarSearch.elements
		for (var i = 0;i<els.length;i++) {
			if ((els[i].type == 'checkbox') && !(objThis===els[i]))
				els[i].checked = false;
		}
	}
/*	else
	{
		var els = document.calendarSearch.elements
		for (var i = 0;i<els.length;i++) {
			if ((els[i].type == 'checkbox') && !(objThis === els[i]))
				els[i].checked = true;
		}
	} */
}

function OthersAreClicked(objThis) {
	if (objThis.checked) 
		document.getElementById('AllBox').checked = false;
}





var ContentHeight = 0;
var ClientWindowHeight = 0;
var TargetOffset = 0;
var ScrollOffset = 0;
var MaxScrollLength = 0;

var timerID = null;
var Container, contentArea


function findScrollToObject(sWorking) {

	var el = document.getElementById('tr' + sWorking)
	if (!el) 
		return false;
	ScrollStop()

	var ScrollTo =	(parseInt(contentArea.style.top) + parseInt(el.offsetTop))- ClientWindowHeight;
	if (ScrollTo < 0 )
		{
		GoToScrollUp(25,-(parseInt(el.offsetTop)));
		}
	if (ScrollTo > 0  )
		{
		GoToScrollDown(-25,-(ScrollTo+80));
		}
}


function GoToScrollDown(speed,goToY){
// on click on calendar
	if (parseInt(contentArea.style.top) < MaxScrollLength){ 
		ScrollStop();
		return false	
	}

	if (parseInt(contentArea.style.top) < goToY)  
		{
		ScrollStop();
		}
	else
		{
        contentArea.style.top = parseInt(contentArea.style.top) + speed + "px";
       	timerID = setTimeout("GoToScrollDown("+speed+","+goToY+")",20)
		}
				
}

function GoToScrollUp(speed,goToY){
// on click on calendar
	if (parseInt(contentArea.style.top) > 0) 
		{
		ScrollStop();
		contentArea.style.top = "0px";		
		}
              
	if (parseInt(contentArea.style.top) > goToY) 
		{
		ScrollStop();
		}
	else
		{
        contentArea.style.top = (parseInt(contentArea.style.top) + speed) + "px";
       	timerID = setTimeout("GoToScrollUp("+speed+","+goToY+")",20)
		}
}

function ScrollerUp(speed){

		if (parseInt(contentArea.style.top) > 0) 
			{
				ScrollStop();
				contentArea.style.top = "0px";
			}
		else
			{
				if ((parseInt(contentArea.style.top) + speed) > 0)
					contentArea.style.top = "0px";
				else
					contentArea.style.top = parseInt(contentArea.style.top) + speed + "px";
			}

		timerID = setTimeout("ScrollerUp("+speed+")",10)

}
function ScrollerDown(speed){
// on mouseover on arrow

	if (parseInt(contentArea.style.top) < MaxScrollLength)
		{ 
			ScrollStop();
			return false	
		}
	else
		{
			contentArea.style.top = parseInt(contentArea.style.top) - speed + "px";
		}

   	timerID = setTimeout("ScrollerDown("+speed+")",20)
}
	
function ScrollStop(){
	if(document.getElementById){
		if (timerID!=null) {
			clearTimeout(timerID);
			timerID = null;
		}
	}
}
