//
//	$Id: global_functions.js,v 1.10 2009/07/29 09:11:30 cvsco Exp $
//

function openWindow (url, params) {
	window.open (url, '', params);
}


function ws_open_centered_window (u, n, w, h, p) {
  lp = (screen.width) ? (screen.width - w) / 2 : 100;
  tp = (screen.height) ? (screen.height - h) / 2 : 100;
  return window.open (u, n, 'width='+w+',height='+h+',top='+tp+',left='+lp+','+p);
}


var tobj = 0;
var menutimer = 0;
var menuiv = 0;
var menublock = 0;
var mpos = -200;
var mmoving = 0;
var mTimeout = 8000;
var mSpeed = 20;
var initMPanePos = 0;
var maxMPansePos = 0;
var menupane = 0;
var menuholder = 0;
var menu_in_position = 0;
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

window.onscroll=function(){
	if (menupane) {
		dsoctop=document.all? iebody.scrollTop : pageYOffset
		if ((dsoctop + initMPanePos) < maxMPanePos) {
			menupane.style.marginTop = dsoctop + initMPanePos + "px";
			menuholder.style.top = dsoctop + "px";
		}
	}
	
	
};



function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

function screeninit() {
	var mblock = document.getElementById('cntNavigation');
	var hblock = document.getElementById('cntNavigationH');
	var contentblock = document.getElementById('cntContentHolder');
	if (contentblock.offsetHeight < 520) contentblock.style.height = "520px";
	try {
		mblock.style.left = contentblock.offsetLeft + "px";
		mblock.style.top = hblock.style.top = contentblock.offsetTop + "px";
		hblock.style.width = contentblock.offsetLeft + "px";
	} catch(e) {}

	var menublock = document.getElementById('cntMenu');
	menuholder = document.getElementById('menuholder');
	if (menublock) {
		menublock.style.height = contentblock.offsetHeight + "px";
		menupane = document.getElementById('menupane');
		var browserheight = (document.all) ? iebody.clientHeight : window.innerHeight;
		var h = ((browserheight - 50) > contentblock.offsetHeight) ?  contentblock.offsetHeight : browserheight - 50;
		initMPanePos = h - menuholder.offsetHeight - 76 ;
		maxMPanePos = contentblock.offsetHeight - menuholder.offsetHeight - 76;
		menupane.style.marginTop = initMPanePos + "px";
		hblock.style.height = mblock.offsetHeight + "px";
		try {
			if (shownav) {
				mblock.style.visibility = 'visible';
			}
		} catch(e) {}
		hblock.style.visibility = 'visible';
	}
	
}

function switch_menu() {
	var mblock = document.getElementById('cntNavigation');
	mblock.style.visibility = (mblock.style.visibility == "hidden") ? "visible" : "hidden";
}

function show_menu() {
	if (mmoving) return false;
	menublock = document.getElementById('cntMenu');
	mmoving = 1;
	menuiv = window.setInterval("slidein_menu()", mSpeed);
}

function hide_menu() {
	window.clearInterval(menuiv);
	menublock.style.position = 'relative';
	menublock.style.left = '0px';

	window.clearTimeout(menutimer);
	menuiv = window.setInterval("slideout_menu()", mSpeed);
	menu_in_position = 0;
}

function slidein_menu() {
	fac = (mpos < -30) ? 10 : 2; 
	mpos = mpos + fac;
	menublock.style.left = mpos + "px";
	if (mpos >= 0) {
		mpos = 0;
		menublock.style.left = "0px";
		window.clearInterval(menuiv);
		window.clearTimeout(menutimer);
		menutimer = window.setTimeout("hide_menu()", mTimeout);
		menu_in_position = 1;	
		var icon = document.getElementById('menupaneicon');
		if (icon) {
			icon.src = "/gfx/menubutton_c.gif";
		}
		menublock.style.position = 'static';
	}
}

function reset_mtimer() {
	window.clearTimeout(menutimer);
	menutimer = window.setTimeout("hide_menu()", mTimeout);	
}

function react_on_menu() {
	if (menu_in_position) {
		hide_menu();
	}
}



function slideout_menu() {
	fac = (mpos > -30) ? 4 : 10; 
	mpos = mpos -fac;
	menublock.style.left =  mpos + "px";
	if (mpos <= -200) {
		window.clearInterval(menuiv);
		window.clearTimeout(menutimer);
		menublock.style.left = "-200px";
		mpos=-200;
		mmoving = 0;
		var icon = document.getElementById('menupaneicon');
		if (icon) {
			icon.src = "/gfx/menubutton.gif";
		}
	}
}

var fieldcnt = new Array();
function newfield(fieldid, mode) {
	var row = document.getElementById('td' + fieldid);
	
	if (!row) return;
	if (!fieldcnt[fieldid]) fieldcnt[fieldid] = 0;
	if (fieldcnt[fieldid] == 2) return ;
	
	var nbr = document.createElement('BR');
	var nfield = document.createElement('INPUT');
	nfield.name = "txt_" + fieldid + "[]";
	switch (mode) {
	
	
		case 2:
			nfield.type = "file";
			nfield.className = "txtupload";
			break;

		default:
			nfield.type = "text";
			nfield.className = "txtinput";
			break;
			
	}

	row.appendChild(nbr);
	row.appendChild(nfield);
	fieldcnt[fieldid] ++;

}

function positionEmailFrame(url) {
	var ecnt = document.getElementById('cntEMailToFriend');
	var lcnt = document.getElementById('emailtofriendlink');
	var ifr = document.getElementById('ifEMailToFriend');
	ifr.src=url;
	ecnt.style.top = (lcnt.offsetTop - 425) + "px";
	ecnt.style.left = (lcnt.offsetLeft + 20) + "px";
	ecnt.style.display = 'block';
	
}

function hideEmailFrame() {
	var ecnt = document.getElementById('cntEMailToFriend');
	if (ecnt) ecnt.style.display = 'none';	
}
