var iex		= (document.all);
var nav		= (document.layers);
var old 	= (navigator.appName=="Netscape" && !document.layers && !document.getElementById);
var n_6 	= (window.sidebar);

String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
} // -------------------------------------------------------------------------------------------

function truncateForm( form ) {
	for( i = 0 ; i < form.length ; i++ )
	{
	    if( form.elements[i].type == 'text' || form.elements[i].type == 'textarea' )
			form.elements[i].value = form.elements[i].value.trim();
	};
} // -------------------------------------------------------------------------------------------


var popup_id 	= "popup";
var c_popup		= -1;
var last_obj	= 0;
var overpopup 	= 0;
var defcolor 	= "";

function show_popup(e,obj,id) {
	
	if (id==c_popup) return true;//hidepopup();

	if (arguments.length==4) {
		if (defcolor=='') defcolor = document.getElementById(popup_id).style.background;
		document.getElementById(popup_id).style.background = arguments[3];
		document.getElementById(popup_id).style.border = "";
	} else {
		if (defcolor!='') document.getElementById(popup_id).style.background = defcolor;
	}
	
	c_popup = id;
	var x = y = 0;
	var tag = obj;
	while (tag) { 
		y+=tag.offsetTop;
		x+=tag.offsetLeft;
		tag=tag.offsetParent; 
	} 
	
	if (!iex) {
		x=e.pageX;
		y=e.pageY;
	} else {
		x=e.x;
		y=e.y + document.body.scrollTop; 
	} 
    


	var popup = document.getElementById(popup_id);
	y += 16;

	
	if (x+popups[id][1]+50 > document.body.clientWidth) {
		x = document.body.clientWidth - popups[id][1] - 60;
	}

	popup.innerHTML = '<table width=100% height=100% cellpadding=0 cellspacing=0><tr valign=top><td width=100%>'+popups[id][0]+'</td><td style="padding-left:5px;"><a onclick="hidepopup(); return false;" href=#><img src=./images/close.jpg width=15 height=15></a></td></tr></table>';
	popup.style.top = y+'px';
	popup.style.left = x+'px';
	popup.style.width = popups[id][1];
	//popup.style.height = popups[id][2];
	popup.style.visibility = "visible";

	//alert(1);
	
	//var aaa = document.getElementsByTagName("body")[0];
	//aaa.focus();

	obj.blur();
	last_obj = obj;

	//overpopup = 1;
	
	e.cancelBubble=true;

	return true;
}

function hidepopup() {

	//sub_hidepopup();

	if (last_obj!=0) {
		last_obj.blur();
	}
	var popup = document.getElementById(popup_id);
	popup.style.visibility = "hidden";
	c_popup = -1;
	last_obj= 0;
	overpopup = 0;
	return true;
}

function openWin(x,title,wid,hei) {

  	myWin= open(x, "_blank", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width="+wid+",height="+hei);
  	
	var hWnd = myWin; 
	var nLeftPos, nTopPos; 
	var nWidth = wid;
	var nHeight = hei;
 
    nLeftPos = Math.round(screen.availWidth/2) - Math.round(nWidth/2); 
    nTopPos  = Math.round(screen.availHeight/2) - Math.round(nHeight/2); 
	
	//hWnd.moveTo(nLeftPos,nTopPos);
}



var sub_popup_id 	= "sub_popup";
var sub_c_popup		= -1;
var sub_last_obj	= 0;
var sub_overpopup 	= 0;



function sub_hidepopup() {
	if (sub_last_obj!=0) {
		sub_last_obj.blur();
	}
	var sub_popup = document.getElementById(sub_popup_id);
	sub_popup.style.visibility = "hidden";
	sub_c_popup = -1;
	sub_last_obj= 0;
	sub_overpopup = 0;
	return true;
}

var curEvtn = '';
var curPhoto = 0;
var evntPhoto, evntText;

function _el(id) {
	return document.getElementById(id);
}

function createEvntPlace() {
	evntPhoto = document.createElement('IMG');
	evntText  = document.createElement('SPAN');
	_el('phHolder').appendChild(evntPhoto);
	_el('phHolder').appendChild(evntText);
}

function showEvntPhoto(d) {

	curPhoto += d;
	if (curPhoto>=evnts[curEvtn].length) {
		curPhoto = 0;
	}
	if (curPhoto<0) {
		curPhoto = evnts[curEvtn].length-1;
	}
	
	_el('phHolder').removeChild(evntPhoto);
	_el('phHolder').removeChild(evntText);

	createEvntPlace();

	evntPhoto.src = evnts[curEvtn][curPhoto]['url'];
	evntText.innerHTML = evnts[curEvtn][curPhoto]['text'];

	_el('curPhoto').innerHTML = (curPhoto+1)+' of '+evnts[curEvtn].length;	
}

function showEvnt(id) {
	if (curEvtn!='') {
		_el(curEvtn+'-link').className = '';
	} else {
		createEvntPlace();
	}
	curEvtn = id;
	_el(curEvtn+'-link').className = 'selEvnt';
	curPhoto = 0;
	showEvntPhoto(0);
}

