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 invert_chk(id) {
	var chk = document.getElementById(id);
	chk.checked = !chk.checked;
}


// GET X COORDINATE
function getRealLeft(id) { 
	var el = document.getElementById(id);
	if (el) { 
		xPos = el.offsetLeft;
		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 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';
	}
}


// -------- 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;
	}
}

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++) {
		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;
	}
}


// Profile view gallery mouse handlers
function gallerythumbOver(id) {
	document.getElementById(id).className='mouover';
	var i;
	var lastaround = arguments.length;
	if (lastaround > 3) lastaround = 3;
	for (i=1; i<lastaround; i++) {
		if (arguments[i]!='') document.getElementById(arguments[i]).className='mouoveraround';
	}
	
	if ((arguments.length > 3) && arguments[3])
		document.getElementById('tableProfileImageThumbs').style.left = (parseInt(document.getElementById('tableProfileImageThumbs').style.left)-20)+'px';
}

function gallerythumbOut(id) {
	document.getElementById(id).className='';
	var i;
	var lastaround = arguments.length;
	if (lastaround > 3) lastaround = 3;
	for (i=1; i<lastaround; i++) {
		if (arguments[i]!='') document.getElementById(arguments[i]).className='';
	}
	
	if ((arguments.length > 3) && arguments[3])
		document.getElementById('tableProfileImageThumbs').style.left = (parseInt(document.getElementById('tableProfileImageThumbs').style.left)+20)+'px';
}


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';
}





