function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// adds/removes/swaps a class name in an object's className attribute. 
// a = action, o = the object, c1 = the first class name, c2= the second class name
function removeClassName(a,o,c1,c2) {
	switch (a){
		case 'swap':
			o.className=!jscss('check',o,c1)?o.className.replace(c2,c1):o.className.replace(c1,c2);
		break;
		case 'add':
			if(!jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
		break;
		case 'remove':
			var rep=o.className.match(' '+c1)?' '+c1:c1;
			o.className=o.className.replace(rep,'');
		break;
		case 'check':
			return new RegExp('\\b'+c1+'\\b').test(o.className)
		break;
	}
}


function togglediv(d) {
	var c = document.getElementById(d);
	if (c.style.display=='none') {
		c.style.display = 'block';
	} else {
		c.style.display = 'none';
	}
}

function focusWindow(w) {
	w.focus();
}

function invert_all_chk(form_id, field_prefix) {
	for (i=0; i<document.forms[form_id].elements.length; i++) {
		if (document.forms[form_id].elements[i].name.indexOf(field_prefix) == 0) 
			document.forms[form_id].elements[i].checked=!document.forms[form_id].elements[i].checked;
	}
}

function invert_all_chk_byid(field_prefix) {
	var inputs = document.getElementsByTagName("input");
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].id.indexOf(field_prefix) == 0)
			inputs[i].checked=!inputs[i].checked;
	}
}

function change_all_chk_byidprefix(field_prefix, fstate) {
	var inputs = document.getElementsByTagName("input");
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].id.indexOf(field_prefix) == 0)
			inputs[i].checked = fstate;
	}
}

function invert_one_chk_byid(id) {
	var o = document.getElementById(id);
	o.checked = !o.checked;
}


function getRealLeft(id) {
	var el = document.getElementById(id);
	var ol = el.offsetLeft;
	while ((el = el.offsetParent) != null) {
		ol += el.offsetLeft;
		if (el.clientLeft) ol += el.clientLeft;
	}
	return ol;
}
function getRealTop1(id) {
	var el = document.getElementById(id);
	var ol = el.offsetTop;
	while ((el = el.offsetParent) != null) {
		ol += el.offsetTop;
		if (el.scrollTop && el != document.body) ol -= el.scrollTop;
	}
	return ol;
}

// GET X COORDINATE
/*function getRealLeft(id) {
	var el = document.getElementById(id);
	if (el) { 
		var xPos = el.offsetLeft;
		var tempEl = el.offsetParent;
		while (tempEl != null) {
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		} 
		return xPos;
	} else {
		return 0;
	}
}
*/
// GET Y COORDINATE
function getRealTop(id) {
	var el = document.getElementById(id);
	if (el) { 
		yPos = el.offsetTop;
		tempEl = el.offsetParent;
		while (tempEl != null) {
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return (yPos+1);
	} else {
		return 0;
	}
}


// get the index page Y scroll offset
function GetIndexYOffset() {
	var x,y;
	if (parent.window.pageYOffset) // all except Explorer
	{
		x = parent.window.pageXOffset;
		y = parent.window.pageYOffset;
	}
	else if (parent.window.document.documentElement && parent.window.document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = parent.window.document.documentElement.scrollLeft;
		y = parent.window.document.documentElement.scrollTop;
	}
	else if (parent.window.document.body) // all other Explorers
	{
		x = parent.window.document.body.scrollLeft;
		y = parent.window.document.body.scrollTop;
	}
	return y;
}

// get the client inner height of the browser
function GetPageClientHeight() {
	var x,y;
	if (parent.window.innerHeight) // all except Explorer
	{
		x = parent.window.innerWidth;
		y = parent.window.innerHeight;
	}
	else if (parent.window.document.documentElement && parent.window.document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = parent.window.document.documentElement.clientWidth;
		y = parent.window.document.documentElement.clientHeight;
	}
	else if (parent.window.document.body) // other Explorers
	{
		x = parent.window.document.body.clientWidth;
		y = parent.window.document.body.clientHeight;
	}
	return y;
}

// get the client inner width of the browser
function GetPageClientWidth() {
	var x,y;
	if (parent.window.innerHeight) // all except Explorer
	{
		x = parent.window.innerWidth;
		y = parent.window.innerHeight;
	}
	else if (parent.window.document.documentElement && parent.window.document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = parent.window.document.documentElement.clientWidth;
		y = parent.window.document.documentElement.clientHeight;
	}
	else if (parent.window.document.body) // other Explorers
	{
		x = parent.window.document.body.clientWidth;
		y = parent.window.document.body.clientHeight;
	}
	return x;
}

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;
}

function GetPageYSize() {
	var pagesize = GetPageSize();
	return pagesize[1];
}


function toggledivonoff(d, state) {
	var c = document.getElementById(d);
	if (state) {
		c.style.display = 'block';
	} else {
		c.style.display = 'none';
	}
}

function showhidediv(d, state) {
	var c = document.getElementById(d);
	if (state) {
		c.style.display = 'block';
	} else {
		c.style.display = 'none';
	}
}

function showhidedivobj(o, state) {
	if (state) {
		o.style.display = 'block';
	} else {
		o.style.display = 'none';
	}
}


// -------- functions needed for table module
function change_all_chk(form_id, field_prefix, fstate) {
	for (i=0; i<document.forms[form_id].elements.length; i++) {
		if (document.forms[form_id].elements[i].name.indexOf(field_prefix) == 0) document.forms[form_id].elements[i].checked=fstate;
	}
}

// deselects all checkboxes of given prefix, except the one that was clicked
function chk_single_byprefix(prefix, e) {
	if (!e) var e = window.event;   // IE
	var target;
	if (e.target) target = e.target;
	else if (e.srcElement) target = e.srcElement;
	
	var inputs = document.getElementsByTagName("input");
	var i;
	for (i=0; i<inputs.length; i++) {
		if (inputs[i].name.indexOf(prefix) == 0) inputs[i].checked = false;
	}
	target.checked = true;
}

function togglefilterdiv(m) {
	var imgid = 'imgFilter_'+m;
	var divid = 'divFilter_'+m;
	var divref = document.getElementById(divid);
	
	var imx = getRealLeft(imgid);
	var imy = getRealTop(imgid);
	
	divref.style.left = imx-640+'px';
	divref.style.top = imy+12+'px';

	togglediv(divid);
	return false;
}

// Adds a row to a filter table
function addRowDOMFilter(tableID) { 
// pass every cell content as a futher arg
  var table = document.getElementById(tableID);
  if (arguments.length > 1) {
	var row = table.insertRow(table.rows.length);
	if (document.getElementById) {
	  for (var i = 1; i < arguments.length; i++) {
		var cell = row.insertCell(i - 1);
		if (i == 1) cell.style.textAlign = 'right';
		
		cell.innerHTML = arguments[i];
	  }  // for
	}
  }
}

// removes a row from a table with id
function removeRowFromTable(tableID, rowNum)
{
	var tbl = document.getElementById(tableID);
	tbl.deleteRow(rowNum);   // zero based
//  var lastRow = tbl.rows.length;
}

// removes a row from a filter table
function removeRowFromFilterTable(moduleID, rowID)
{
	var tbl = document.getElementById('tableFilter_'+moduleID);
	var k = 0;
	// search for the element
	for (i=0; i<document.forms['form_filtering_'+moduleID].elements.length; i++) {
		c = document.forms['form_filtering_'+moduleID].elements[i];
		if ( c.id.indexOf('lstFilterFields_'+moduleID) != -1 ) {   // increment row number only for a row in filter table
			k++;
		}
		if ( c.id.indexOf('btnRemoveCondition_'+moduleID+'_'+rowID) != -1 ) {   // found
			tbl.deleteRow(k);
		}
	}
}
// --------- end of functions needed for table module

function SetChkOn(chk) {
	document.getElementById(chk).checked = true;
}



//var divNoticeBoxesRemovable = new Array();   // holds notice boxes ids to be auto removed by tab switches

// a third argument of true indicates that no status boxes should be removed (e.g. called by page loading or so)
function TabSwitch(d,n) {
	var IDbuttons = "TabButton_";
	var IDcontents = "divTabContents_";
	var i;
	for (i=1; i<=n; i++) {
		if (document.getElementById(IDcontents+i)) {
			showhidediv(IDcontents+i, false);
			document.getElementById(IDbuttons+i).className = '';
			document.getElementById(IDbuttons+i).blur();
		}
	}
	if (d>0) {   // pass 0 to d for no active button
		showhidediv(IDcontents+d, true);
		document.getElementById(IDbuttons+d).className = 'act';
	}
	
//	if ( !((arguments.length > 2) && (arguments[2]==true)) ) {
//		for (i=0; i<divNoticeBoxesRemovable.length; i++) {
//			showhidediv(divNoticeBoxesRemovable[i], false);
//		}
//	}

}


function showprofilewritemessage() {
	tabSwitch(0,4);
	showhidediv('divWriteMessage', true);
}
function showprofilerecommendform() {
	tabSwitch(0,4);
	showhidediv('divRecommendForm', true);
}
function tabSwitchProfile(d,n) {
	showhidediv('divWriteMessage', false);
	showhidediv('divRecommendForm', false);
	tabSwitch(d,n);
}

function add_select_option(selectid, stext, svalue) {
	var o = document.getElementById(selectid);
	var sellen = o.options.length;
	var newOption = new Option(stext, svalue);
	var saveInd = o.selectedIndex;
	o.options[sellen] = newOption;
	o.selectedIndex = saveInd;
}

function copyMultipleSelectOptions(lstSrc, lstDst) {
	var elsrc = document.getElementById(lstSrc);
	var eldst = document.getElementById(lstDst);
	
	for (i = 0; i < elsrc.length; i++) {
		if ( elsrc.options[i].selected ) {
			// check if option already added
			var exists = false;
			for (j = 0; j < eldst.length; j++) {
				if (eldst.options[j].value == elsrc.options[i].value) exists = true;
			}
			if (!exists) add_select_option(lstDst, elsrc.options[i].text, elsrc.options[i].value);
		}
	}
}

function removeMultipleSelectOptions(lst) {
	var el = document.getElementById(lst);
	for (i = el.length-1; i >= 0; i--) {
		if (el.options[i].selected) el.options[i] = null;
	}
}

function removeMultipleSelectOptionsWithCallback(lst,c) {
	var el = document.getElementById(lst);
	for (i = el.length-1; i >= 0; i--) {
		if (el.options[i].selected) {
			c(el.options[i].value);
			el.options[i] = null;
		}
	}
}

function emptySelectOptions(lst) {
	var el = document.getElementById(lst);
	for (i = el.length-1; i >= 0; i--) {
		el.options[i] = null;
	}
}

function listSelectAll(listid) {
	var el = document.getElementById(listid);
	for (i = 0; i < el.length; i++) {
		el.options[i].selected = true;
	}
}

// ------ BROWSER DETECTION OBJECT
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();




function galleryshowimg(url) {
	document.getElementById('imgProfileBigger').src=url;
	document.getElementById('aProfileBigger').href=url.replace(/_thumb2/,'');
}

function contactsaboutchange() {
	var ind = document.getElementById('lstAbout').selectedIndex;
	document.getElementById('spanAboutOther').style.visibility = (ind==3)?'visible':'hidden';
}



function HideSelects() {
	var i;
	var selects = document.getElementsByTagName("select");
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility = "hidden";
	}
}
function ShowSelects() {
	var i;
	var selects = document.getElementsByTagName("select");
	for (i=0; i<selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
}

function ShowCoverDiv() {
	var obj = document.getElementById('divPageCover');
	var pagesizes = GetPageSize();
	//obj.style.width = pagesizes[2]+'px';
	obj.style.height = pagesizes[1]+'px';
	HideSelects();
	obj.style.display = 'block';
}
function HideCoverDiv() {
	var obj = document.getElementById('divPageCover');
	ShowSelects();
	obj.style.display = 'none';
}


// escape autocomplete for form fields
var autocomplete_entries_to_disable;
function disable_autocomplete_tmout(f) {
	var i;
	for (i=0; i<f.length; i++) {
		document.getElementById(f[i]).value = '';
	}
}
function disable_autocomplete(f) {
	autocomplete_entries_to_disable = f;
	window.setTimeout("disable_autocomplete_tmout(autocomplete_entries_to_disable)", 200);
}


function showlogincallout(m) {
	showhidediv('divHomeLoginCallout', true);
	document.getElementById('divHomeLoginCallout').innerHTML = m;
	var callout_left = Math.round(GetPageClientWidth() / 2 - 174);
	if (BrowserDetect.browser == 'Explorer') callout_left += 8;
	document.getElementById('divHomeLoginCallout').style.left = callout_left + 'px';
	//document.getElementById('divHomeLoginCallout').style.left = getRealLeft('tableMain') + 322 + 'px';//imgSuperTopSpacer
}





/* -------------------- Textarea manipulation routines ---------------------- */
function setSelectionRange(input, selectionStart, selectionEnd) {
  if (input.setSelectionRange) {
	input.focus();
	input.setSelectionRange(selectionStart, selectionEnd);
  }
  else if (input.createTextRange) {
	var range = input.createTextRange();
	range.collapse(true);
	range.moveEnd('character', selectionEnd);
	range.moveStart('character', selectionStart);
	range.select();
  }
}

function setCaretToEnd (input) {
	setSelectionRange(input, input.value.length, input.value.length);
}

function setCaretToBegin (input) {
	setSelectionRange(input, 0, 0);
}

function setCaretToPos (input, pos) {
	setSelectionRange(input, pos, pos);
}

// Inserts a text into a textarea at the cursor, or in place of a selection
// tagSymbolsOffset - number of symbols added to selection, needed to move caret to end of selection+tags
function insertAtCursor(myField, myValue, tagSymbolsOffset) {
  //IE support
  if (document.selection) 
  {
	myField.focus();
	sel = document.selection.createRange();
	sel.text = myValue;
	sel.scrollIntoView();
	sel.select();
	sel.collapse(false);
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') 
  {
	var startPos = myField.selectionStart;
	var endPos = myField.selectionEnd;
	myField.value = myField.value.substring(0, startPos)
				  + myValue 
				  + myField.value.substring(endPos, myField.value.length);
	setCaretToPos(myField, endPos + tagSymbolsOffset);
  } 
  else 
  {
	myField.value += myValue;
	setCaretToEnd(myField);
  }
}

function getSel(myfield) {
	if (document.selection) {
		return document.selection.createRange().text; 
	}
	else if (myfield.selectionEnd) {
		startPos = 0; endPos = 0;
		startPos = myfield.selectionStart;
		endPos = myfield.selectionEnd;
		if (startPos != endPos) {
			fldtext = myfield.value;
			return fldtext.substr(startPos, endPos-startPos);
		} else {
			return '';
		}
	}
	else {
		return;
	};
}

function taReplaceSelection(f,t) {
	var s = getSel(f);
	s = t;
	insertAtCursor(f, s, s.length);
}

function InsertEmoticon(fldid,t) {
	var fld = document.getElementById(fldid);
	taReplaceSelection(fld, t);
	fld.focus();
}

/* ------------------------------------------------------------------------------------- */







// ---------------------------- cookies management -------------------------------
function writeCookie(name,value,days,path) {
	var expires = "";
	var cpath = "; path=/";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	if (path) {
		cpath = "; path=" + path;
	}
	document.cookie = name + "=" + value + expires + cpath;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for (var i=0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return false;
}

function deleteCookie(name) {
	createCookie(name,"",-1);
}
// ----------------------------------------------------------------------







// ----------------------------- functions to show/hide the map --------------------------
var map_visible = false;
var map_height = 0;
var map_effect_running = false;   // avoid another click to get in the way of the running effect

function init_hide_map() {
	hidingMap();
}

function hidingMap() {
	var omap = document.getElementById('divMap');
	if (map_height > 0) {
		map_height -= 50;
		if (map_height < 0) map_height = 0;
		omap.style.height = map_height + 'px';
		document.getElementById('imgMap').style.height = map_height + 'px';
		//omap.style.marginTop = -(701-map_height) + 'px';
		window.setTimeout("hidingMap()", 15);
	} else {
		omap.style.display = 'none';
		omap.style.height = '0px';
		map_visible = false;
		map_effect_running = false;
	}
}
function showingMap() {
	var omap = document.getElementById('divMap');
	if (map_height < 701) {
		map_height += 50;
		if (map_height > 701) map_height = 701;
		omap.style.height = map_height + 'px';
		document.getElementById('imgMap').style.height = map_height + 'px';
		//omap.style.marginTop = -(701-map_height) + 'px';
		window.setTimeout("showingMap()", 15);
	} else {
		omap.style.height = '701px';
		//omap.style.marginTop = '0px';
		map_visible = true;
		map_effect_running = false;
	}
}

function ShowHideMap() {
	if (map_effect_running) return;
	
	map_effect_running = true;
	if (map_visible) {
		hidingMap();
	} else {
		var omap = document.getElementById('divMap');
		omap.style.display = 'block';
		showingMap();
	}
}
// ------------------------------------------------------------------------------















