//Browser compatability
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}
function opensubset(url,rows) {
	if (url) top.subset.document.location.href = url;
	if (!rows) rows = '50%,50%';
	top.document.getElementById('mainset').rows = rows;
}
function closesubset() {
	top.document.getElementById('mainset').rows = "*,0";
}
function closeoptions() {
	top.document.getElementById('actionset').rows = "*,0";
	top.options.document.location.href = 'blank.htm';
	//top.actions.document.body.scroll = 'no';
}
function openoptions() {
	top.document.getElementById('actionset').rows = "50%,50%";
	//top.actions.document.body.scroll = 'auto';
}
function openaddset(url,cols) {
	if (url) top.addset.document.location.href = url;
	if (!cols) cols = '50%,50%';
	top.document.getElementById('serviceset').cols = cols;
}
function closeaddset() {
	top.document.getElementById('serviceset').cols = "*,0";
}
function blankall(main) {
	if (main) top.main.document.location.href = 'blank.htm';
	top.options.document.location.href = 'blank.htm';
	top.subset.document.location.href = 'blank.htm';
	top.addset.document.location.href = 'blank.htm';
	closeoptions();
}
function help(page) {
	if (page==undefined) page = '';
	else page = 'page.php?page='+page;
	var win = window.open('http://help.worshiporganizer.com/'+page,'wohelp','left=100,top=50,height=400,width=700,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=yes');
	//var win = window.open('http://www.worshiporganizer.com/help/'+page,'wohelp','left=100,top=50,height=400,width=700,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=yes');
	win.focus();
}
function currentpage() {
	var script = document.location.href.split('/');
	script = script[3];
	if (script.indexOf('?')>=0) script = script.substring(0,script.indexOf('?'));
	return script;
}
// Tabs
function tabClick(id) {
	for (i=0; i<tabdivs.length; i++) {
		if (i==id) {
			tabdivs[i].style.display = '';
			tabcells[i].className = 'tabSelected';
		}
		else {
			tabdivs[i].style.display = 'none';
			tabcells[i].className = 'tabUnselected';
		}
	}
	tabselected = id;
	SetCookie('tab-'+currentpage(),id);
}
var tabdivs = new Array();
var tabcells = new Array();
var tabselected = 0;
function collecttabs(notab) {
	for (j=0; j<2; j++) {
		if (j==0) tags = document.getElementsByTagName('TD');
		else tags = document.getElementsByTagName('TABLE');
		for (i=0; i<tags.length; i++) {
			el = tags[i];
			if (el.id=='tabcell') {
				el.onclick = new Function('tabClick('+tabcells.length+')');
				tabcells[tabcells.length] = el;
			} else if (el.id=='tabdiv') {
				tabdivs[tabdivs.length] = el;
			}
		}
	}
	var curpg = currentpage();
	if (GetCookie('tab-'+curpg)!='' && GetCookie('tab-'+curpg)<tabcells.length && notab==undefined) tabClick(GetCookie('tab-'+curpg));
	else tabClick(0);
}
function printwin(url) {
	window.open(url,'','top=50,left=50,height=500,width=700,location=0,resizable=1,menubar=1,toolbar=1,status=0,scrollbars=1');
}
function SetCookie(cookieName,cookieValue) {
	//Supports deleting
	if (cookieValue=='') {
		var expire = new Date();
		expire.setTime(expire.getTime() - 3600000*24*7);
		document.cookie = cookieName+"=;expires="+expire.toGMTString();
	}
	else document.cookie = cookieName+"="+escape(cookieValue);
}
function GetCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return "";
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length;
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
function Dec2Hex(Decimal) {
	var hexChars = "0123456789ABCDEF";
	var a = Decimal % 16;
	var b = (Decimal - a)/16;
	return "" + hexChars.charAt(b) + hexChars.charAt(a);
}
function colorval (color) {
	if (color=='') return color;
	else if (color.length==7) return color.toUpperCase();
	else {
		var re = new RegExp (' ', 'gi') ;
		var ca = color.replace(re,'').split(',');
		ca[0] = Dec2Hex(ca[0].substring(4));
		ca[1] = Dec2Hex(ca[1]);
		ca[2] = Dec2Hex(ca[2].substring(0,ca[2].length-1));
		return '#'+ca[0]+ca[1]+ca[2];
	}
}
function dotip(id,text) {
	var te = document.getElementById(id);
	if (te!=null) te.title = text;
}
function email(name,email,subject) {
	window.open('email.php?name='+escape(name)+'&email='+escape(email)+'&subject='+escape(subject),'','top=50,left=50,height=350,width=400,location=0,resizable=1,menubar=0,toolbar=0,status=0,scrollbars=0');
}
function download() {
	window.document.location.href = window.document.location.href + '&downloadrpt=1';
}