// --- CLIENTCHECK ---

function getClient() {
  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase()
  var apv=navigator.appVersion.toLowerCase()
  this.major = parseInt(navigator.appVersion)
  this.minor = parseFloat(navigator.appVersion)
  // browserversion
  this.opera = (agt.indexOf('opera')!=-1);
  this.ns  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)))
  this.ns4 = (this.ns && (this.minor >= 4.03) && (this.major < 5))
  this.ns6 = (this.ns && (this.major == 5) || this.opera)
  this.gecko = (this.ns && (this.major >= 5))
  this.ie   = (agt.indexOf("msie") != -1)
  this.ie4  = (this.ie && (this.major == 3))
  this.ie45 = (agt.indexOf('msie 4.5') != -1);
  this.ie5  = (this.ie && (this.major == 4))
  // platform
  this.mac = (apv.indexOf("macintosh")>0);
  this.win = (apv.indexOf("win")>0);	
  // compatible browsers
  this.ie4comp = ((this.ie4 && !this.mac) || this.ie45 || this.ie5)
  this.ns4comp = (this.ns4);
  this.ns6comp = (this.gecko || this.ns6);
  this.comp = (this.ie4comp || this.ns4comp || this.ns6comp);
  return (this)
}

var is = new getClient();

function printURL() {
	var header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Printable version</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
	header += '<link rel="stylesheet" href="/css/default.css" type="text/css"><style>body {background: none; background-color: #ffffff; padding: 10px;}</style></head>';
	header += '<body onLoad="window.print();">';
	header += '<table align="center"><tr><td width="100%" align="left">';
	var footer = '</td></tr></table></body></html>';

	var strInner = document.body.innerHTML;
	var startPos = strInner.lastIndexOf("<!-- print_start -->");	
	var endPos = strInner.lastIndexOf("<!-- print_end -->");
	strInner = strInner.substring(startPos+20, endPos);
		
	if (strInner.lastIndexOf("<!-- print_pause_on -->") > -1){
		var str1 = "<!-- print_pause_on -->";
		var str2 = "<!-- print_pause_off -->";
		startPos = strInner.lastIndexOf(str1);	
		endPos = strInner.lastIndexOf(str2);
		if (endPos > startPos){
			leftStr = strInner.substring(0, startPos);
			rightStr = strInner.substring(endPos + str2.length, strInner.length);
			strInner =	 leftStr + rightStr;
		}
	}
	var xwin = window.open("/code/printable.php", "PrintVersion", "menubar=yes, scrollbars=yes, resizable=yes, width=625, toolbar=yes, statubar=no");
	xwin.document.write(header+strInner+footer);
}

function isPPC() {
	if (navigator.appVersion.indexOf("PPC") != -1) return true;
	else return false;
}

function sendPage(mailHeadline){
	if(!isPPC()) {
		window.location="mailto:\?subject\=" + mailHeadline + "&body=" + mailHeadline + ": " + window.location;
	}else { 
		window.location="mailto:\?body=" + mailHeadline + ": " + window.location;
	}
}

function openGalleryImage (url2, url3, caption, obj) {
	if (caption == ""){
		caption = "Reiyukai Canada";
	}
	var temp = '<div id="image_popup"><img src="'+url2+'" id="loaded_image" cursor: hand; "onClick="closeGalleryImage()"></div>';	
	if (url3 != "") {
		temp += '<div id="large"><a href='+url3+' target="_blank">Download Hi Resolution Image</a></div>';
	}
	//window.open('<img src="'+url2+'" id="loaded_image" onload="alert();">', 'DescriptiveWindowName', 'resizable=no,scrollbars=yes,status=no');
	document.getElementById('all').innerHTML = temp;
	document.getElementById('caption').innerHTML = caption;
	setupDiv (document.getElementById("big_image"), 250, curMouseY, url2);
}

function closeGalleryImage () {
	document.getElementById("big_image").style.display = "none";
}

var curMouseX = 0;
var curMouseY = 0;

var close = new Image();
close.src = "/images/basic/close.gif";


if (is.ns4comp) document.captureEvents(Event.MOUSEMOVE)

document.onmousedown = getMouseXY;

function getMouseXY(e) {
	curMouseY = getMousePageTop(e);
	if (curMouseY < 0){
		  curMouseY = 0
	}
	return true;
}

function setupDiv (elt, x, y, image) { 
	y = y - 250;
	if (y<150){ 
		y=150;
	}
	if (is.ns4comp) {
		elt.moveTo(x, y);  
		//alert ("1");
	} else if (is.ie4comp) {
		elt.style.pixelLeft = x;
		elt.style.pixelTop  = y;
		//alert (document.documentElement.scrollTop);
		//alert ("2");
	} else if (is.ns6comp) {
		elt.style.left = x + "px";
		elt.style.top  = y + "px";
		// alert (x + " | " + elt.style.left);
	}
	elt.style.display = "block";
	loadImage = function () {
		document.getElementById('loaded_image').src = image;
		//alert(image)
	}
	setTimeout("loadImage()", 100);
	
}

/*if (document.documentElement && !document.documentElement.scrollTop)
// IE6 +4.01 but no scrolling going on
else if (document.documentElement && document.documentElement.scrollTop)
// IE6 +4.01 and user has scrolled
else if (document.body && document.body.scrollTop)
// IE5 or DTD 3.2
*/

// ---MOUSE EVENT PROPERTIES ---


function getMousePageLeft(e) 
{ if (is.ns4comp) return(e.pageX);
  else if (is.ie4comp) return(event.clientX + document.documentElement.scrollLeft);
  else if (is.ns6comp) return(e.pageX);
}

function getMousePageTop(e) 
{ if (is.ns4comp) return(e.pageY);
  else if (is.ie4comp) return(event.clientY + document.documentElement.scrollTop);
  else if (is.ns6comp) return(e.pageY);
}