// JavaScript Document
var previousField = '';
var sep = '*~';
var subSep = '|';

function subNav(id) {
	for(var i = 1; i <= 9; i++) {
		var setStyle = 'hidden';
		if(i == id)
			setStyle = 'visible';
		document.getElementById('nav' + i).style.visibility = setStyle;
	}
}

function ajaxLoader(url,id) {
  if (document.getElementById) {
    var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
  }
  if (x) {
    x.onreadystatechange = function() {
      if (x.readyState == 4 && x.status == 200) {
				el = document.getElementById(id);
				if(id == 'maincol_content_print')
					el.innerHTML += x.responseText;
				else if(id == 'bookform') {
					setDay(x.responseText.split(sep), true);
				}
				else
					el.innerHTML = x.responseText;
      }
    }
    x.open("GET", url + '&r=' + rdm(), true);
    x.send(null);
  }
}

function rdm() {
	return Math.floor(Math.random()*100000001);
}

function showDetails(pid, tid, div, field) {
	if(div == undefined || div == '') {
		div = 'maincol_content';
		
		if(previousField != field && previousField != '') {
			previousField.style.color = '';
			previousField.style.backgroundImage = 'url("_i/mc_nav_bg_link.png")';
		}
		field.style.color = '#333333';
		field.style.backgroundImage = 'url("_i/mc_nav_bg_link_over.gif")';
		previousField = field;
	}
	ajaxLoader('_ssi/page_details.php?p=' + pid + '&t=' + tid, div);
}

function showDetailsGoogle(pid, tid, div, field) {
	if(div == undefined || div == '') {
		div = 'maincol_content';
		
		if(previousField != field && previousField != '') {
			previousField.style.color = '';
			previousField.style.backgroundImage = 'url("_i/mc_nav_bg_link.png")';
		}
		field.style.color = '#333333';
		field.style.backgroundImage = 'url("_i/mc_nav_bg_link_over.gif")';
		previousField = field;
	}
	ajaxLoader('_ssi/page_details_google.php?p=' + pid + '&t=' + tid, div);
}

function getURL(url) {
	if(url != undefined)
		var setURL = url.toString();
	else
		var setURL = window.location.href;
	var setRet = '';
	if(setURL.indexOf('/') > -1) {
		setRet = setURL.substr(setURL.lastIndexOf('/')+1);
		if(setRet.indexOf('?') > -1)
			setRet = setRet.substr(0, setRet.indexOf('?'));
	}
	return setRet;
}

function activeNav() {
	var current = getURL();
	if(current == '')
		current = 'index.php';
	var count = 1;
	var mainNum = 0;
	
	do {
		var selected = document.getElementById('nav' + count);
		if(selected != null) {
			var nav = selected.getElementsByTagName('li');
			for(var i = 0; i < nav.length; i++) {
				var href = nav[i].getElementsByTagName('a');
				if(href[0] != undefined) {
					if(getURL(href[0].toString()) == current) {
						selected.style.visibility = 'visible';
						href[0].style.fontWeight = 'bold';
						mainNum = count;
					}
				}
			}
			count++;
		}
	}
	while(selected != null);
	

	var main = document.getElementById('navMain');
	var nav = main.getElementsByTagName('li');
	for(var i = 0; i < nav.length; i++) {
		if(mainNum > 0) {
			if(mainNum-1 == i) {
				nav[i].style.backgroundImage = 'url("_i/nav_background_white-grey_over.gif")';
				nav[i].style.color = '#FFFFFF';
			}
		}
		else {
			if(nav[i].onclick != null) {
				var temp = nav[i].onclick.toString();
				if(temp.indexOf(current) > -1) {
					nav[i].style.backgroundImage = 'url("_i/nav_background_white-grey_over.gif")';
					nav[i].style.color = '#FFFFFF';
				}
			}
		}
	}
}

function addOption(selectbox, text, value) {
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}

function removeAllOptions(selectbox) {
	var i;
	for(i = selectbox.options.length-1; i >= 0; i--) {
		selectbox.remove(i);
	}
}

function popupHide() {
	Effect.Fade('popup', { duration: 0.5 });
	Effect.Fade('popupBox', { duration: 0.5 });
}

function popupShow() {
	Effect.Appear('popup', { duration: 0.5 });
	Effect.Appear('popupBox', { duration: 0.5 });
}