// JavaScript Document

function ClosePageOver(){
	document.getElementById("PageOver").style.zIndex = 1008;
	var eff = new Effect.Opacity('PageOver',
	{ to: 0.0, duration: 0.3 ,
	transition: Effect.Transitions.linear,
	afterFinish:function(){
		document.getElementById("PageOver").style.zIndex = -1;
		document.getElementById("PageOver").style.visibility = "visible";
		document.getElementById("PageOver").style.height = getPageSize()[1] + "px";
		document.getElementById("PageOver").style.width = "100%";
		dropdowns = document.getElementsByTagName("select");
		for(i=0;i<dropdowns.length;i++){
			elem = dropdowns[i];
			Element.extend(elem);
			elem.show();
		}
	}
	});

}

function OpenDialog(el){
	dropdowns = document.getElementsByTagName("select");
	for(i=0;i<dropdowns.length;i++){
		elem = dropdowns[i];
		Element.extend(elem);
		elem.hide();
	}
	opendropdowns = $(el).getElementsByTagName("select");
	for(i=0;i<opendropdowns.length;i++){
		elem = opendropdowns[i];
		elem.show();
	}

	
	document.getElementById("PageOver").style.zIndex = 10;
	var eff = new Effect.Opacity('PageOver',
	{ to: 0.8, duration:0.3,
	transition: Effect.Transitions.linear,
	afterFinish:function(obj){
		var elem = document.getElementById(el);
		Element.extend(elem);
		//Position.absolutize(elem);
		//elem.makePositioned();
		var hg = getWindowHeight();
		var wd = getWindowWidth();
		elem.style.position = "absolute";
		elem.style.zIndex = 1009;
		elem.style.display = "block";
		scrpos = getScrollXY();
		elem.style.left = String((wd / 2) - (parseInt(elem.getWidth()) / 2) + scrpos[0]) + "px";
		elem.style.top = String((hg / 2) - (parseInt(elem.getHeight()) / 2) + scrpos[1]) + "px";
		elem.style.visibility = "visible";
	}});
}

function CloseDialog(el){
	var elem = document.getElementById(el);
	elem.style.display = "none";
	elem.style.visibility = "hidden";
	elem.style.zIndex = -2;
	ClosePageOver();
}



function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

function ShowMenu(el,target){
	Element.extend(el);

	if(el.up().style.position != "absolute"){
		pos = Position.cumulativeOffset(el);
		tx = (pos[0] + el.getWidth() - 0) + "px";
		ty = pos[1] + "px";
	}else{
		tx = el.up().getWidth() + "px";
		hh = 0;
		hx = 0;
		while(el.previous(".MenuItem", hx) != undefined){
			hh += 20;
			hx += 1;
		}
		ty = hh + "px";
		//ty = getposOffset(el,"top");

		//alert(el.getHeight());
	}


	$(target).style.left = tx;
	$(target).style.top = ty;
	$(target).show();

}

function ShowMenu2(target){
	$(target).show();
}

function HideMenu(target){
	$(target).hide();
}

function ShowTooltip(event, source){
	
	ttSource = $(source);
		
	if($("IdeaToolTip") != null && $("IdeaToolTip").visible){
		tt = $("IdeaToolTip");
		css = tt.classNames();
		for(i=0;i<css.length;i++)
			tt.removeClassName(css[i]);
	}else{
		tt = document.createElement("div");
		Element.extend(tt);
		tt.id = "IdeaToolTip";
		tt.hide();
		document.body.appendChild(tt);
		Position.absolutize(tt);
	}
		
	tt.addClassName(ttSource.className);
	tt.update(ttSource.innerHTML);
	
	tt.setStyle({
		'width':ttSource.style.width,
		'height':ttSource.style.height,
		'display':'block',
		'z-index':1050
	});
	
	tt.style.left = (Event.pointerX(event) + 15)  + "px";
	tt.style.top = (Event.pointerY(event))  + "px";
	tt.makePositioned();
	tt.show();
}

function HideTooltip(){
	$('IdeaToolTip').hide();
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}
