/* 
  This file is copyrighted. You may not use any code nor information from file without written permission.
  Efoze.co.il site crew (2005) (c)
*/

function InRange(a,b,v) {
	if (b <= a+v && b >= a-v) return 1;
	return 0;
}

var steps=100;
function openDiv(divname, speed) {
	var i;
	var divobj = document.getElementById(divname);
	divobj.style.overflow = 'hidden';
//	alert(" openDiv("+divname+","+speed+"): divobjs.visibility:"+divobj.style.visibility+" parseInt(divobjs.height):"+parseInt(divobj.style.height)+" scrollHeight:"+divobj.scrollHeight+" inRange:"+InRange(parseInt(divobj.style.height),parseInt(divobj.scrollHeight),1)+' innerHTML:'+divobj.innerHTML);
	if (divobj.style.visibility == 'hidden' || (divobj.style.visibility == '' && divobj.className.lastIndexOf('clsHidden') != -1) || (parseInt(divobj.style.height) && !InRange(parseInt(divobj.style.height),parseInt(divobj.scrollHeight),5))) { // folded
		if (divobj.style.height == '') divobj.style.height = '0px';
		if (speed)
			for (i=parseInt(divobj.style.height)*steps/divobj.scrollHeight;i<steps;i++)
				setTimeout("chgCSSHeight('"+divname+"', '"+i/steps*divobj.scrollHeight+"px')", speed/steps*i);
		else
			chgCSSHeight(divname, divobj.scrollHeight+'px');
			
		return 1;
	}
	return 0;
}

function closeDiv(divname, speed) {
	var i;
	var divobj = document.getElementById(divname);
	divobj.style.overflow = 'hidden';
/*	parent.frames['mainFrame'].document.getElementById('debug').innerHTML = "closeDiv("+divname+","+speed+"): divobjs.visibility:"+divobj.style.visibility
	+ "\n<br/>" + parent.frames['mainFrame'].document.getElementById('debug').innerHTML;*/
	if (divobj.style.visibility != 'hidden' || (divobj.style.visibility == '' && divobj.className.lastIndexOf('clsHidden') == -1)) {
		if (speed)
			for (i=1;i<steps;i++)
				setTimeout("chgCSSHeight('"+divname+"', '"+(steps-i)/steps*divobj.scrollHeight+"px')", speed/steps*i);
		else
				chgCSSHeight(divname, '0px');
		return 1;
	}
	return 0;
}

function toggleDiv(divname, speed) {
	var divobj = document.getElementById(divname);
	if (openDiv(divname, speed)) 
		return 1;
	else {
		closeDiv(divname, speed);
		return 0;
	}
}

function chgCSSHeight(divname, newheight) {
	var divobjs = document.getElementById(divname).style;
	if (parseInt(newheight) == 0) {
		divobjs.visibility = 'hidden';
		divobjs.position = 'absolute';
		divobjs.height = '0px';
	} else {
		divobjs.visibility = 'visible';
		divobjs.position = 'static';
	}
	divobjs.height = newheight;
}

var imagesOnOut = new Array();

function prepareMouseEvents(btn) {
	var btnobj = document.getElementById(btn);
	var btnp1, btnp2;
	btnp1 = btnobj.src.substring(0,btnobj.src.length-4);
	btnp2 = btnobj.src.substring(btnobj.src.length-4);
	
	imagesOnOut[btn] = new Array(3);
	imagesOnOut[btn][0] = new Image; // normal
	imagesOnOut[btn][0].src = btnp1+''+btnp2;
	imagesOnOut[btn][1] = new Image; // over
	imagesOnOut[btn][1].src = btnp1+'_over'+btnp2;
	imagesOnOut[btn][2] = new Image; // down
	imagesOnOut[btn][2].src = btnp1+'_down'+btnp2;
	//the code above is used to preload the images

	btnobj.onmouseover = function () {
		this.src = imagesOnOut[this.id][1].src;
	}
	btnobj.onmousedown = function () {
		this.src = imagesOnOut[this.id][2].src;
	}
	btnobj.onmouseout = function () {
		this.src = imagesOnOut[this.id][0].src;
	}
	btnobj.onmouseup = btnobj.onmouseover;
}

var onLoad = new Array();
function jsOnLoad() {
	var i;
	for (i=0;i<onLoad.length;i++) {
		onLoad[i]();
	}
}
/*
var noParent=0;
onLoad.push(function (){
	if (noParent == 0) {
		if (parent.frames['mainFrame'] == undefined && !parent.document.getElementById('mainFrame')) { window.location = '/index.php'; }
	}
});
*/
function enterKeyTrap(that, ev) {
	if (ev.keyCode == 13)
		if (that.tagName == 'INPUT')
			that.form.submit();
		else
			that.submit();
}

function chgLocation(newloc, target) {
	if (!target) return 0;
	if (parent.frames[target])
		parent.frames[target].location = newloc;
	else if (parent.document.getElementById(target))
		parent.document.getElementById(target).window.location = newloc;
}

function openImageInWindow(loc) {
	window.open(loc, 'Image', 'width=820,height=620,resizable=no,scrollbars=no,toolbar=no,location=no,status=no,menubar=no');
}

function XBrowserAddHandler (target,eventName,handlerName) {  //from andy smith's blog
  if ( target.addEventListener ) { 
    target.addEventListener(eventName, function(e){target[handlerName](e);}, false);
  } else if ( target.attachEvent ) { 
    target.attachEvent("on" + eventName, function(e){target[handlerName](e);});
  } else { 
    var originalHandler = target["on" + eventName]; 
    if ( originalHandler ) { 
      target["on" + eventName] = function(e){originalHandler(e);target[handlerName](e);}; 
    } else { 
      target["on" + eventName] = target[handlerName]; 
    } 
  } 
}