/************************************
*                                  *
*      WhenIsGood JavaScript       *
*                                  *
************************************/

var millisInAMinute = 1000 * 60;
var millisInASlot = millisInAMinute * 15;
var millisInHalfAnHour = millisInASlot * 2;
var millisInAnHour = millisInASlot * 4;
var millisInADay = millisInAnHour * 24;

function byid(id) {
	return document.getElementById(id);
}

function toggleVisible(id) {
	if (visible(id)) {
		hide(id);
	}
	else {
		show(id);
	}
}

function visible(id) {
	if (document.layers) {
		return document.layers[id].visibility == '' || document.layers[id].visibility == 'show';
	}
	else if (document.all) {
		return document.all[id].style.visibility == '' || document.all[id].style.visibility == 'visible';
	}
	else if (document.getElementById) {
		return byid(id).style.visibility == '' || byid(id).style.visibility == 'visible';
	}
}

function hide(id) {
	if (document.layers) {
		document.layers[id].visibility = 'hide';
	}
	else if (document.all) {
		document.all[id].style.visibility = 'hidden';
	}
	else if (document.getElementById) {
		byid(id).style.visibility = 'hidden';
	}
}

function show(id) {
	if (document.layers) {
		document.layers[id].visibility = 'show';
	}
	else if (document.all) {
		document.all[id].style.visibility = 'visible';
	}
	else if (document.getElementById) {
		byid(id).style.visibility = 'visible';
	}
}

function togglePresent(id) {
	if (present(id)) {
		remove(id);
	}
	else {
		unremove(id);
	}
}

function present(id) {
	if (document.layers) {
		return document.layers[id].display == '' || document.layers[id].display == 'block';
	}
	else if (document.all) {
		return document.all[id].style.display == '' || document.all[id].style.display == 'block';
	}
	else if (document.getElementById) {
		return byid(id).style.display == '' || byid(id).style.display == 'block';
	}
}

function remove(id) {
	if (document.layers) {
		document.layers[id].display = 'none';
	}
	else if (document.all) {
		document.all[id].style.display = 'none';
	}
	else if (document.getElementById) {
		byid(id).style.display = 'none';
	}
}

function unremove(id) {
	if (document.layers) {
		document.layers[id].display = 'block';
	}
	else if (document.all) {
		document.all[id].style.display = 'block';
	}
	else if (document.getElementById) {
		byid(id).style.display = 'block';
	}
}

function pop(url, name) {
        mainPopUp = window.open(url, name, 'width=400,height=400,left=200,top=100,scrollbars=1,resizable=1');
        return false;
}

function deTag(string) {
	while (string.indexOf("<") > -1) {
		string = string.substring(0,string.indexOf("<")) + "&lt;" + string.substring(string.indexOf("<")+1);
	}
	while (string.indexOf(">") > -1) {
		string = string.substring(0,string.indexOf(">")) + "&gt;" + string.substring(string.indexOf(">")+1);
	}
	return string;
}

function mySlider() {
		// dig out the style used for the main grid
		var gridStyle = null;
		var gridDateStyle = null
		if (document.styleSheets) {
			var rules = null;
			if (document.styleSheets[0].cssRules)
				rules = document.styleSheets[0].cssRules
			else if (document.styleSheets[0].rules)
				rules = document.styleSheets[0].rules
			if (rules != null) {
				for (var i = 0; i < rules.length; i++) {
					if (rules[i].style.fontSize == '12px') {
						gridStyle = rules[i].style;
					}
					if (rules[i].style.fontSize == '16px') {
						gridDateStyle = rules[i].style;
					}
				}
			}
		}
		// build the slider
		var slider = new Slider(byid("slider"), byid("gridSize"));
		slider.setMinimum(6);
		slider.setMaximum(24);
		slider.setValue(14);
		slider.setUnitIncrement(2);
		slider.setBlockIncrement(2);
		slider.recalculate();
		gridStyle.fontSize = slider.getValue() + 'px';
		gridDateStyle.fontSize = (slider.getValue()+4) + 'px';
		slider.onchange = function () {
			gridStyle.fontSize = slider.getValue() + 'px';
			gridDateStyle.fontSize = (slider.getValue()+4) + 'px';
		};
		return slider;
}

function setSelect(id, val) {
	var sel = byid(id);
  	for(index = 0; index < sel.length; index++) {
   		if(sel[index].value == val) sel.selectedIndex = index;
	}
}

/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
	target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
	target.style.MozUserSelect="none"
else //All other route (ie: Opera)
	target.onmousedown=function(){return false}
target.style.cursor = "default"
}
