/**************************************
 *
 * 		MAIN JS File
 *		
 *		Holds js-functions used
 *		around all pages
 *
 **************************************/

		function getXMLHTTP() { //function to return the xml http object
			var xmlhttp=false;	
			try{
				xmlhttp=new XMLHttpRequest();
			}
			catch(e)	{		
				try{			
					xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e){
					try{
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
					}
					catch(e1){
						xmlhttp=false;
					}
				}
			}
				
			return xmlhttp;
		}
		
		function show_comments(id) {		
			var strURL="ajax_comments.php?survey_id="+id+"&action=show";
			var req = getXMLHTTP();
			if (req) {
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {			
				  divid="survey_"+id;			
							document.getElementById(divid).innerHTML=req.responseText;						
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}		
		}
		
		function hide_comments(id) {		
			var strURL="ajax_comments.php?survey_id="+id+"&action=hide";
			var req = getXMLHTTP();
			if (req) {
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {			
				  divid="survey_"+id;			
							document.getElementById(divid).innerHTML=req.responseText;						
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}		
		}					
		
		function add_comment(id) {	
		var strURL="ajax_comments.php?survey_id="+id+"&action=add";
			var req = getXMLHTTP();
			if (req) {
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {			
		   			        divid="survey_"+id;			
							document.getElementById(divid).innerHTML=req.responseText;
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}		
		}				
					
		function save_comment(id,text) {	
    var strSingleLineText = text.replace(new RegExp( "\\n", "g" ), "<br>");		
		var strURL="ajax_comments.php?survey_id="+id+"&action=save&text="+strSingleLineText;
			var req = getXMLHTTP();
			if (req) {
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						// only if "OK"
						if (req.status == 200) {			
		   			        divid="survey_"+id;			
							document.getElementById(divid).innerHTML=req.responseText;
						} else {
							alert("There was a problem while using XMLHTTP:\n" + req.statusText);
						}
					}				
				}			
				req.open("GET", strURL, true);
				req.send(null);
			}		
		}				
					
		
		function popSelectUser(type, varname){
			var SelectPicWindow = window.open('index.php?sec=friendselector&popupMode=1&insert_field='+varname+'&type='+type,'popup','location=0,status=0,scrollbars=1,resizable=1,width=525,height=600');
		}
		
		function checkBoxFlip(item_prefix, items_csv) {
			var items = items_csv.split(',');
			for(var i=0; i<items.length; i++){
				the_item = document.getElementById(item_prefix+items[i]);
				if(the_item!=null){
					if(the_item.type=='checkbox') {
						the_item.checked=!the_item.checked;
					}
				}
			}
		}
		
		function selectUser(select_pk, insert_field){
			window.opener.document.getElementById(insert_field).value = select_pk;
			window.opener.document.getElementById(insert_field+'_usr_card').innerHTML = $('user_card_'+select_pk).innerHTML;
			window.close();
		}
		function selectUserMultiSingle(select_pk, insert_field){
			var currentList=window.opener.document.getElementById(insert_field).value;
			var currentListArray = currentList.split(',');
			selectUserMultiSingle2(select_pk, insert_field, currentListArray);
			window.close();
		}
		
		function selectUserMulti(item_prefix, items_csv, insert_field) {
			var items = items_csv.split(',');
			var currentList=window.opener.document.getElementById(insert_field).value;
			var currentListArray = currentList.split(',');
			for(var i=0; i<items.length; i++){
				the_item = document.getElementById(item_prefix+items[i]);
				if(the_item!=null){
					if(the_item.type=='checkbox') {
						if(the_item.checked){
							selectUserMultiSingle2(''+items[i], insert_field, currentListArray);
						}
					}
				}
			}
			window.close();
		}
		
		function selectUserMultiSingle2(select_pk, insert_field, currentListArray){
			if(!isNaN(select_pk) && !in_array(select_pk, currentListArray, false)){
				if(window.opener.document.getElementById(insert_field).value!='') window.opener.document.getElementById(insert_field).value += ',';
				window.opener.document.getElementById(insert_field).value += ''+select_pk;
				var insertBox = window.opener.document.getElementById(insert_field+'_usr_card_template').innerHTML;
				insertBox = str_replace('{pk}', select_pk, insertBox);
				insertBox = str_replace('{usr_card_tmpl}', $('user_card_'+select_pk).innerHTML, insertBox);
				window.opener.document.getElementById(insert_field+'_usr_card').innerHTML += insertBox;
			}
		}
		
		function toggleSlide(objname, savestatus){
			var slider = eval(objname+'Slider');
			slider.toggle(); //toggle the slider up and down.
			var isOpen = slider.open;
			if(savestatus) saveCustomPanelStatus(objname, isOpen);
		}
		
		//called when user collapses/expands panel
		function savePanelStatus(par1){
			var panel = eval(par1);
			Spry.Utils.loadURL("GET", "ajax_panel_save.php?id="+par1+"&sta="+panel.isOpen(), true);
		}
		
		//called when user collapses/expands panel
		function saveCustomPanelStatus(par1, sta){
			Spry.Utils.loadURL("GET", "ajax_panel_save.php?id="+par1+"&sta="+sta, true);
		}
		
		function panelMouseOver(panel_num, subhead){
			/*
			var panel_head_left = document.getElementById('panel_'+panel_num+'_head_left');
			var panel_head_mid = document.getElementById('panel_'+panel_num+'_head_mid');
			var panel_head_right = document.getElementById('panel_'+panel_num+'_head_right');
			panel_head_left.className = 'panel_head_left_1'+subhead;
			panel_head_mid.className = 'panel_head_mid_1'+subhead;
			panel_head_right.className = 'panel_head_right_1'+subhead;
			*/
		}
		
		function panelMouseOut(panel_num, subhead){
			/*
			var panel_head_left = document.getElementById('panel_'+panel_num+'_head_left');
			var panel_head_mid = document.getElementById('panel_'+panel_num+'_head_mid');
			var panel_head_right = document.getElementById('panel_'+panel_num+'_head_right');
			panel_head_left.className = 'panel_head_left_0'+subhead;
			panel_head_mid.className = 'panel_head_mid_0'+subhead;
			panel_head_right.className = 'panel_head_right_0'+subhead;
			*/
		}
		
		function setClass(item_id, nu_class){
			var the_item = document.getElementById(item_id);
			the_item.className = nu_class;
		}
		
		var tmm_last_pos=7;
		var tmm_active_pos=-1;
		var tmm_active_class='';
		var tmm_inactive_class='';
		function tmmFocus(focusOn){
			if(tmm_last_pos>0 && tmm_active_class!='' && tmm_inactive_class!=''){
				for(var i=0; i<=tmm_last_pos; i++){
					if(focusOn==i){
						$('mm_item_id_'+i).removeClass(tmm_inactive_class);
						$('mm_item_id_'+i).addClass(tmm_active_class);
					}else{
						$('mm_item_id_'+i).removeClass(tmm_active_class);
						$('mm_item_id_'+i).addClass(tmm_inactive_class);
					}
					//submenu
					if(focusOn==i){
						$('perm_sb_'+i).setStyle('display', 'block');
					}else{
						$('perm_sb_'+i).setStyle('display', 'none');	//if($('perm_sb_'+i).getStyle('display')!='none') 
					}
				}
			}
		}
		
		//used for main login-form
		function clearLoginDefault(el) {
			if (el.defaultValue==el.value){
				el.value = "";
				hideDiv('login_pwd_lbl','login_pwd', false);	//remove pwd-lable so it can focus with tabulator
			}
		}
		//used for main login-form
		function clearDefault(el) {
			if (el.defaultValue==el.value) el.value = ""
		}
		//used for main login-form
		function hideDiv(whichLayer, focusItem, doFocus) {
			var elem, focusElem, vis;
			if( document.getElementById )
				elem = document.getElementById( whichLayer );
			else if( document.all )
				  elem = document.all[whichLayer];
			else if( document.layers )
				elem = document.layers[whichLayer];
			
			if( document.getElementById )
				focusElem = document.getElementById( focusItem );
			else if( document.all )
				  focusElem = document.all[focusItem];
			else if( document.layers )
				focusElem = document.layers[focusItem];
			
			vis = elem.style;
			if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
				vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
			vis.display = (vis.display==''||vis.display=='block')?'none':'block';
			
			vis = focusElem.style;
			if(vis.display==''&&focusElem.offsetWidth!=undefined&&focusElem.offsetHeight!=undefined)
				vis.display = (focusElem.offsetWidth!=0&&focusElem.offsetHeight!=0)?'block':'none';
			vis.display = (vis.display==''||vis.display=='block')?'none':'block';
			
			if(doFocus) focusElem.focus();
		}
		
		function writeToDiv(text,id){
			if (document.getElementById)
			{
				x = document.getElementById(id);
				x.innerHTML = '';
				x.innerHTML = text;
			}
			else if (document.all)
			{
				x = document.all[id];
				x.innerHTML = text;
			}
			else if (document.layers)
			{
				x = document.layers[id];
				text2 = '' + text + '';
				x.document.open();
				x.document.write(text2);
				x.document.close();
			}
		}
		
		function reloadCaptchaDiv(baseUrl) {
			var now = new Date();
			var nuSrc = baseUrl+'&time=' + now.getTime();
			document.getElementById('captcha_img').src = nuSrc;
		}
		
		
		function popSelectPic(type, insert_field, insert_size){
			var SelectPicWindow = window.open('index.php?sec=gallery&sub1=pictures&popupMode=1&mode=select&insert_field='+insert_field+'&insert_size='+insert_size+'&type='+type,'popup','location=0,status=0,scrollbars=1,resizable=1,width=765,height=600');
		}
		
		/*
		 * function called in popup-image-selector
		 */
		function selectImage(imgName){
			//set preview-image
			window.opener.document.getElementById(preview_img).src = pictureDir+insert_size+'/'+imgName+'.'+pictureResampleExtension;
			window.opener.document.getElementById(insert_field).value=imgName;
			window.close();
		}
		
		function unsetPic(previewPic, resetPic, fieldName){
			document.getElementById(previewPic).src = resetPic;
			document.getElementById(fieldName).value='';
		}
		
		function fileBrowserCallBack(field_name, url, type, win) {
			if(type=='image') popSelectPic('tinymce', field_name, 'wide');
			// This is where you insert your custom filebrowser logic
			//alert("Filebrowser callback: field_name: " + field_name + ", url: " + url + ", type: " + type);
	
			// Insert new URL, this would normaly be done in a popup
			//win.document.forms[0].elements[field_name].value = "someurl.htm";
		}
		
		
		
		function replyTo(title){
			document.getElementById('CO_Title').value="RE: "+title;
		}
		
		function setDivContent(divID, nuContent){
			$(divID).setHTML(nuContent);
		}
		
		var myRatingFx1=null;
		var ratingRequest=null;
		function rateBlogPost(itemid, value, ratingdiv, altTxt){
			var myRatingFx1 = new Fx.Style(ratingdiv, 'opacity');
			myRatingFx1.start(1,0).chain(function(){
				var myAjax = new Ajax("ajax_rating_save.php?id="+itemid+"&value="+value, {method: 'get', update: $(ratingdiv+'_disp')});
				myAjax.request();
				$(ratingdiv+'_btns').setHTML(altTxt);
				myRatingFx1.start(0,1);
			});
			
			
			//Spry.Utils.updateContent(ratingdiv+'_disp', "ajax_rating_save.php?id="+itemid+"&value="+value, myRatingFx1.start(0,1));
			//var myRatingFx2 = new Fx.Style(ratingdiv2, 'opacity');
			//myRatingFx2 = eval(ratingdiv2+'Fx');
			/*
			myRatingFx1.start(1,0).chain(function(){
				ratingRequest = Spry.Utils.loadURL("GET", "ajax_rating_save.php?id="+itemid+"&value="+value, true, rateBlogPostReturn(ratingdiv));
				//+returnValue.xhRequest.responseText
				$(ratingdiv+'_btns').setHTML(altTxt);
			});*/
		}
		function rateBlogPostReturn(ratingdiv){
			//ratingRequest.xhRequest.responseText
			//$(ratingdiv+'_disp').setHTML('x');
			myRatingFx1.start(0,1);
		}
		
		function setFriendGroup(itemid, value){
			var myAjax = new Ajax("ajax_frgroup_save.php?id="+itemid+"&value="+value, {method: 'get'});
			myAjax.request();
		}
		
		function setFanclubModerator(itemid, value){
			var myAjax = new Ajax("ajax_fcmoderator_save.php?id="+itemid+"&value="+value, {method: 'get', update: $('debug')});
			myAjax.request();
		}
		
		var comment_form_FX=null;
		var comment_editor_FX_array=new Array();
		//var comment_currently_editing_FX=null;
		var comment_currently_editing=0;
		function switchEditComment1(commentID){
			/*****************
			 * HIDE CURRENT FORM
			 *****************/
				if(comment_currently_editing!=0){
					//slide out currently edditing-form
					//$('edit_comment_'+comment_currently_editing).setHTML('');
					//var commentEditorSlider = new Fx.Slide('edit_comment_'+comment_currently_editing, {duration: 500});
					comment_editor_FX_array[comment_currently_editing].toggle();
				}else{
					//slide out original 'add comment'-form
					if(comment_form_FX==null) comment_form_FX = new Fx.Slide('comment_form', {duration: 500});
					comment_form_FX.toggle();
				}
			
			/*****************
			 * SHOW NU FORM
			 *****************/
				if(comment_currently_editing==commentID){
					//toggled current item
					//now show original comment-form
					comment_form_FX.toggle();
					comment_currently_editing=0;
				}else if(comment_editor_FX_array[commentID]!=null){
					//current item form already exists
					comment_editor_FX_array[commentID].toggle();
					comment_currently_editing=commentID;
				}else{
					//init current item form
					//copy form-html into comment-edit-div
					$('edit_comment_'+commentID).setHTML($('comment_form').innerHTML);
					$('CO_Title').value=$('comment_title_'+commentID).innerHTML;
					$('CO_Text').value=$('comment_body_'+commentID).innerHTML;
					$('comment_editing').value=commentID;
					comment_currently_editing=commentID;
					var comment_currently_editing_FX = new Fx.Slide('edit_comment_'+commentID, {duration: 500});
					comment_editor_FX_array[commentID]=comment_currently_editing_FX;
					comment_currently_editing_FX.hide();
					comment_currently_editing_FX.toggle();
				}
			
		}
		
		var comment_current_form_div=null;
		var comment_current_form_fx=null;
		var comment_form_html='';
		function switchEditComment2(commentID){
			if(comment_current_form_fx==null){
				//this is the first time the function is called
				comment_current_form_div = 'comment_form';
				comment_form_html=$('comment_form').innerHTML;
				comment_current_form_fx = new Fx.Slide(comment_current_form_div, {duration: 500});
			}
			//var current_form_html=$(comment_current_form_div).innerHTML;
			//slideOut current form
			comment_current_form_fx.slideOut().chain(function(){
				//copy current form to new place
				$('edit_comment_'+commentID).setHTML(comment_form_html);
				
				//slideIn new form
				comment_current_form_fx = new Fx.Slide('edit_comment_'+commentID, {duration: 500});
				comment_current_form_fx.hide();
				comment_current_form_fx.slideIn().chain(function(){
					//empty current form
					//$(comment_current_form_div).setHTML('');
					$('CO_Title').value=$('comment_title_'+commentID).innerHTML;
					$('CO_Text')=$('comment_body_'+commentID).innerHTML;
					$('comment_editing').value=commentID;
					comment_current_form_div='edit_comment_'+commentID;
				});
			});
		}
		
		var comment_edit_form = 0;
		var comment_form_open = true;
		function switchEditComment(commentID){
			if(commentID!=comment_edit_form){
				eval('comment_edit_'+comment_edit_form+'_slider').toggle();
				eval('comment_edit_'+commentID+'_slider').toggle();
				comment_edit_form=commentID;
			}else{
				var comment_prev_form_fx = eval('comment_edit_'+comment_edit_form+'_slider');
				comment_prev_form_fx.toggle();
				var comment_current_form_fx = eval('comment_edit_'+0+'_slider');
				comment_current_form_fx.toggle();
				comment_edit_form=0;
			}
			/*
			if(comment_current_form_fx==null){
				//this is the first time the function is called
				comment_current_form_div = 'comment_form';
				//comment_form_html=$('comment_form').innerHTML;
				comment_current_form_fx = new Fx.Slide(comment_current_form_div, {duration: 500});
			}
			//var current_form_html=$(comment_current_form_div).innerHTML;
			//slideOut current form
			comment_current_form_fx.toggle().chain(function(){
				//copy current form to new place
				//slideIn new form
				comment_current_form_fx = eval('comment_edit_'+commentID+'_slider');
				comment_current_form_fx.toggle();
			});*/
		}
		
		function prevPage(pagerID){
			the_url = eval(pagerID+"_url");
			the_page = eval(pagerID+"_page");
			the_pages = eval(pagerID+"_num_of_pages");
			next_page = the_page-1;
			if((next_page>=1)&&(next_page<=the_pages)){
				eval(pagerID+"_page = "+next_page);
				new Ajax(the_url+"?page="+next_page, {method: 'get', update: $(pagerID), evalScripts: 'true'}).request();
				if(next_page==1){
					/*
					$(pagerID+'_pager_1_prev').className='uc_heavy_0';
					$(pagerID+'_pager_2_prev').className='uc_heavy_0';
					*/
					$(pagerID+'_pager_prev').setStyle('display', 'none');
				}
				if(next_page<the_pages){
					/*
					$(pagerID+'_pager_1_next').className='uc_heavy_1';
					$(pagerID+'_pager_2_next').className='uc_heavy_1';
					*/
					$(pagerID+'_pager_next').setStyle('display', 'block');
				}
			}
		}
		
		function nextPage(pagerID){
			the_url = eval(pagerID+"_url");
			the_page = eval(pagerID+"_page");
			the_pages = eval(pagerID+"_num_of_pages");
			next_page = the_page+1;
			
			if((next_page>=1)&&(next_page<=the_pages)){
				eval(pagerID+"_page = "+next_page);
				new Ajax(the_url+"?page="+next_page, {method: 'get', update: $(pagerID), evalScripts: 'true'}).request();
				if(next_page>1){
					/*
					$(pagerID+'_pager_1_prev').className='uc_heavy_1';
					$(pagerID+'_pager_2_prev').className='uc_heavy_1';
					*/
					$(pagerID+'_pager_prev').setStyle('display', 'block');
				}
				if(next_page==the_pages){
					/*
					$(pagerID+'_pager_1_next').className='uc_heavy_0';
					$(pagerID+'_pager_2_next').className='uc_heavy_0';
					*/
					$(pagerID+'_pager_next').setStyle('display', 'none');
				}
			}
		}
		
		function usrCardInit(cardID, isOpen){
			if(isOpen){
				$('usr_card_collapsed_'+cardID).setStyle('display', 'none');
			}else{
				$('usr_card_expanded_'+cardID).setStyle('display', 'none');
			}
		}
		
		function usrCardToggle(cardID, usrID, type){
			if($('usr_card_expanded_'+cardID).getStyle('display')=='none'){
				$('usr_card_expanded_'+cardID).setStyle('display', 'block');
				$('usr_card_collapsed_'+cardID).setStyle('display', 'none');
			}else{
				$('usr_card_expanded_'+cardID).setStyle('display', 'none');
				$('usr_card_collapsed_'+cardID).setStyle('display', 'block');
			}
			Spry.Utils.loadURL("GET", "ajax_usrcard_save.php?id="+usrID+"&type="+type+"&sta="+($('usr_card_expanded_'+cardID).getStyle('display')=='block'), true);
		}
		
		var nugget_interval=null;
		
		function js_track_nugget(){
		/*	nugget_interval=setInterval('js_track_nugget_interval()', 100);*/
		}
		
		var alerted=false;
		
		function js_track_nugget_interval(){	
		/*	if ('function' == typeof 'atrk_get_uid'){ 
				clearInterval(nugget_interval);
				var myAjax=new Ajax("ajax_nugget.php?verify="+atrk_get_uid(), {method: 'get'});
				myAjax.request();
			}
		  try {
				clearInterval(nugget_interval);
				new Ajax("ajax_nugget.php?verify="+atrk_get_uid(), {method: 'get'}).request();
				//if(!alerted) alert(1);
			} catch (e) {
				//if(!alerted) alert(2);
				// do nothing	
			}
			alerted=true;
			*/
		}
		
	/************************************
	 * USER SELECTION FUNCTIONS
	 ************************************/			
		
		function popSelectUser(type, varname){
			var SelectPicWindow = window.open('index.php?sec=friendselector&popupMode=1&insert_field='+varname+'&type='+type,'popup','location=0,status=0,scrollbars=1,resizable=1,width=525,height=600');
		}
		
		function unsetUser(varname){
			//unset user-card
			$(varname+'_usr_card').setHTML('');
			document.getElementById(varname).value='0';
		}
		
		function selectUser(select_pk, insert_field){
			window.opener.document.getElementById(insert_field).value = select_pk;
			window.opener.document.getElementById(insert_field+'_usr_card').innerHTML = $('user_card_'+select_pk).innerHTML;
			window.close();
		}
		
		function selectUserMultiSingle(select_pk, insert_field){
			var currentList=window.opener.document.getElementById(insert_field).value;
			var currentListArray = currentList.split(',');
			selectUserMultiSingle2(select_pk, insert_field, currentListArray);
			window.close();
		}
		
		function selectUserMultiSingle2(select_pk, insert_field, currentListArray){
			if(!isNaN(select_pk) && !in_array(select_pk, currentListArray, false)){
				if(window.opener.document.getElementById(insert_field).value!='') window.opener.document.getElementById(insert_field).value += ',';
				window.opener.document.getElementById(insert_field).value += ''+select_pk;
				var insertBox = window.opener.document.getElementById(insert_field+'_usr_card_template').innerHTML;
				insertBox = str_replace('{pk}', select_pk, insertBox);
				insertBox = str_replace('{usr_card_tmpl}', $('user_card_'+select_pk).innerHTML, insertBox);
				window.opener.document.getElementById(insert_field+'_usr_card').innerHTML += insertBox;
			}
		}
		
		function selectUserMulti(item_prefix, items_csv, insert_field) {
			var items = items_csv.split(',');
			var currentList=window.opener.document.getElementById(insert_field).value;
			var currentListArray = currentList.split(',');
			for(var i=0; i<items.length; i++){
				the_item = document.getElementById(item_prefix+items[i]);
				if(the_item!=null){
					if(the_item.type=='checkbox') {
						if(the_item.checked){
							selectUserMultiSingle2(''+items[i], insert_field, currentListArray);
						}
					}
				}
			}
			window.close();
		}
		
		function removeUserCard(select_pk, insert_field){
			var currentList=document.getElementById(insert_field).value;
			var currentListArray = currentList.split(',');
			var cleanList = '';
			strict=false;
			for(var i=0; i<currentListArray.length; i++){
				if (currentListArray[i] != select_pk) {
					if(cleanList!='') cleanList += ',';
					cleanList += ''+currentListArray[i];
				}
			}
			document.getElementById(insert_field).value = cleanList;
			$(insert_field+'_usr_card_'+select_pk).remove();
		}	
		
		
		/************************************
	 * TEAM SELECTION FUNCTIONS
	 ************************************/			
		
		function popSelectTeam(varname){
			var SelectPicWindow = window.open('index.php?sec=team&popupMode=1&insert_field='+varname,'popup','location=0,status=0,scrollbars=1,resizable=1,width=755,height=600');
		}
		
		function unsetTeam(varname, default_label){
			//unset user-card
			$(varname+'_team_label').setHTML(default_label);
			document.getElementById(varname).value='0';
		}
		
		function selectTeam(select_pk, insert_field){
			window.opener.document.getElementById(insert_field).value = select_pk;
			window.opener.document.getElementById(insert_field+'_team_label').innerHTML = $('team_label_'+select_pk).innerHTML;
			window.close();
		}
		
	/************************************
	 * MISC AJAX FUNCTIONS
	 ************************************/	
		
		//get word from the dictionary
		function ajaxDic(varname, uselan, update_element){
			var myAjax = new Ajax("ajax_dic.php?var="+varname+"&uselan="+uselan, {method: 'get', onComplete: function(response_text){ document.getElementById(update_element).value=response_text; }});
			myAjax.request();
		}
		
		var message_reload_timeout=null;
		//save message-inbox auto-reload-setting
		function setMessageAutoReload(value){
			saveSetting("pm_auto", 1, (value==1));
			if(value==0){
				if(message_reload_timeout!=null) clearTimeout(message_reload_timeout);
			}else{
				message_reload_timeout = setTimeout('loadMessageInbox()', 180000);
			}
		}
		
		function saveSetting(settingType, settingID, settingStatus){
			new Ajax("ajax_save_setting.php?id="+settingID+"&type="+settingType+"&sta="+settingStatus, {method: 'get'}).request();
		}
		
		//var myRatingFx1=null;
		//var ratingRequest=null;
		
		//save blog post rating
		function rateBlogPost(itemid, value, ratingdiv, altTxt){
			$(ratingdiv+'_text_'+itemid).setHTML("");
			$(ratingdiv+'_btns_'+itemid).setHTML(altTxt);
			var myAjax = new Ajax("ajax_rating_save.php?id="+itemid+"&value="+value, {method: 'get', update: $(ratingdiv+'_'+itemid)});
			myAjax.request();
		}
		/*
		function rateBlogPostReturn(ratingdiv){
			myRatingFx1.start(0,1);
		}
		*/
		
		
	
	/************************************
	 * AJAX PAGING FUNCTIONS
	 ************************************/	
	
		function prevPage(pagerID){
			the_page = eval(pagerID+"_page");
			next_page = the_page-1;
			loadPage(pagerID, next_page);
		}
		
		function nextPage(pagerID){
			the_page = eval(pagerID+"_page");
			next_page = the_page+1;
			loadPage(pagerID, next_page);
		}
		
		function loadPage(pagerID, next_page){
			the_url = eval(pagerID+"_url");
			the_page = eval(pagerID+"_page");
			the_pages = eval(pagerID+"_num_of_pages");
			if((next_page>=1)&&(next_page<=the_pages)){
				if($(pagerID+'_page_link_'+the_page+'_Top')!=null) $(pagerID+'_page_link_'+the_page+'_Top').removeClass('page_link_1');
				if($(pagerID+'_page_link_'+the_page+'_Bot')!=null) $(pagerID+'_page_link_'+the_page+'_Bot').removeClass('page_link_1');
				eval(pagerID+"_page = "+next_page);
				$(pagerID).setHTML('<div style="height:'+$(pagerID).offsetHeight+'px; text-align:center;"><img src="img/loading.gif" height="20" width="60" /></div>');
				new Ajax(the_url+"&page="+next_page, {method: 'get', update: $(pagerID), evalScripts: 'true'}).request();	//, evalScripts: 'true'
				if($(pagerID+'_page_link_'+next_page+'_Top')!=null) $(pagerID+'_page_link_'+next_page+'_Top').addClass('page_link_1');
				if($(pagerID+'_page_link_'+next_page+'_Bot')!=null) $(pagerID+'_page_link_'+next_page+'_Bot').addClass('page_link_1');
				//show-hide pager buttons
				if(next_page==1 && $(pagerID+'_pager_prev_Top')!=null && $(pagerID+'_pager_prev_Top').getStyle('display')!='none') $(pagerID+'_pager_prev_Top').setStyle('display', 'none');
				if(next_page==1 && $(pagerID+'_pager_prev_Bot')!=null && $(pagerID+'_pager_prev_Bot').getStyle('display')!='none') $(pagerID+'_pager_prev_Bot').setStyle('display', 'none');
				if(next_page>1 && $(pagerID+'_pager_prev_Top')!=null && $(pagerID+'_pager_prev_Top').getStyle('display')!='block') $(pagerID+'_pager_prev_Top').setStyle('display', 'block');
				if(next_page>1 && $(pagerID+'_pager_prev_Bot')!=null && $(pagerID+'_pager_prev_Bot').getStyle('display')!='block') $(pagerID+'_pager_prev_Bot').setStyle('display', 'block');
				if(next_page==the_pages && $(pagerID+'_pager_next_Top')!=null && $(pagerID+'_pager_next_Top').getStyle('display')!='none') $(pagerID+'_pager_next_Top').setStyle('display', 'none');
				if(next_page==the_pages && $(pagerID+'_pager_next_Bot')!=null && $(pagerID+'_pager_next_Bot').getStyle('display')!='none') $(pagerID+'_pager_next_Bot').setStyle('display', 'none');
				if(next_page<the_pages && $(pagerID+'_pager_next_Top')!=null && $(pagerID+'_pager_next_Top').getStyle('display')!='block') $(pagerID+'_pager_next_Top').setStyle('display', 'block');
				if(next_page<the_pages && $(pagerID+'_pager_next_Bot')!=null && $(pagerID+'_pager_next_Bot').getStyle('display')!='block') $(pagerID+'_pager_next_Bot').setStyle('display', 'block');
			}
		}
		
	
	/************************************
	 * AJAX MESSAGE INBOX
	 ************************************/		
		
		var messageInboxValue = -1;
		function loadMessageInbox(){
			$('sb_message').setHTML('<div style="clear:both; height:21px; text-align:center;"><img src="img/loading.gif" height="20" width="60" /></div>');	//'+$('sb_message').offsetHeight+'
			//var theUrl="ajax_index.php?sec=sbmessage&activesec='.activesec.'messageInboxValue="+messageInboxValue+generateTimeParam();
			var theUrl=ajax_inbox_url+generateTimeParam();
			new Ajax(theUrl, {method: 'get', update: $('sb_message'), evalScripts: 'true'}).request();	//, evalScripts: 'true'
		}
		
	
	/************************************
	 * BORDER SELECT
	 * ... clickable items with a border
	 * around the selected item...
	 * set border for the clicked,
	 * unset border for the previous
	 ************************************/
		
		function selectionBorder(varName, idPrefix, nuValue){
			//var prev_active_item = eval(idPrefix+document.getElementById(varName+"").value);
			if(document.getElementById(idPrefix+""+document.getElementById(varName+"").value)!=null){
				$(idPrefix+""+document.getElementById(varName+"").value).removeClass('form_select_item_border_1');
				$(idPrefix+""+document.getElementById(varName+"").value).addClass('form_select_item_border_0');
			}
			document.getElementById(varName+"").value = nuValue;
			if(document.getElementById(idPrefix+""+nuValue)!=null){
				$(idPrefix+""+nuValue).removeClass('form_select_item_border_0');
				$(idPrefix+""+nuValue).addClass('form_select_item_border_1');
			}
		}
		
	/************************************
	 * 
	 * COMMENT FORM FUNCTIONS
	 * (deprecated and not in use anymore)
	 * 
	 ************************************/			
		
		var comment_form_FX=null;
		var comment_editor_FX_array=new Array();
		//var comment_currently_editing_FX=null;
		var comment_currently_editing=0;
		function switchEditComment1(commentID){
			/*****************
			 * HIDE CURRENT FORM
			 *****************/
				if(comment_currently_editing!=0){
					//slide out currently edditing-form
					//$('edit_comment_'+comment_currently_editing).setHTML('');
					//var commentEditorSlider = new Fx.Slide('edit_comment_'+comment_currently_editing, {duration: 500});
					comment_editor_FX_array[comment_currently_editing].toggle();
				}else{
					//slide out original 'add comment'-form
					if(comment_form_FX==null) comment_form_FX = new Fx.Slide('comment_form', {duration: 500});
					comment_form_FX.toggle();
				}
			
			/*****************
			 * SHOW NU FORM
			 *****************/
				if(comment_currently_editing==commentID){
					//toggled current item
					//now show original comment-form
					comment_form_FX.toggle();
					comment_currently_editing=0;
				}else if(comment_editor_FX_array[commentID]!=null){
					//current item form already exists
					comment_editor_FX_array[commentID].toggle();
					comment_currently_editing=commentID;
				}else{
					//init current item form
					//copy form-html into comment-edit-div
					$('edit_comment_'+commentID).setHTML($('comment_form').innerHTML);
					$('CO_Title').value=$('comment_title_'+commentID).innerHTML;
					$('CO_Text').value=$('comment_body_'+commentID).innerHTML;
					$('comment_editing').value=commentID;
					comment_currently_editing=commentID;
					var comment_currently_editing_FX = new Fx.Slide('edit_comment_'+commentID, {duration: 500});
					comment_editor_FX_array[commentID]=comment_currently_editing_FX;
					comment_currently_editing_FX.hide();
					comment_currently_editing_FX.toggle();
				}
			
		}
		
		var comment_current_form_div=null;
		var comment_current_form_fx=null;
		var comment_form_html='';
		function switchEditComment2(commentID){
			if(comment_current_form_fx==null){
				//this is the first time the function is called
				comment_current_form_div = 'comment_form';
				comment_form_html=$('comment_form').innerHTML;
				comment_current_form_fx = new Fx.Slide(comment_current_form_div, {duration: 500});
			}
			//var current_form_html=$(comment_current_form_div).innerHTML;
			//slideOut current form
			comment_current_form_fx.slideOut().chain(function(){
				//copy current form to new place
				$('edit_comment_'+commentID).setHTML(comment_form_html);
				
				//slideIn new form
				comment_current_form_fx = new Fx.Slide('edit_comment_'+commentID, {duration: 500});
				comment_current_form_fx.hide();
				comment_current_form_fx.slideIn().chain(function(){
					//empty current form
					//$(comment_current_form_div).setHTML('');
					$('CO_Title').value=$('comment_title_'+commentID).innerHTML;
					$('CO_Text')=$('comment_body_'+commentID).innerHTML;
					$('comment_editing').value=commentID;
					comment_current_form_div='edit_comment_'+commentID;
				});
			});
		}
		
		var comment_edit_form = 0;
		var comment_form_open = true;
		function switchEditComment(commentID){
			if(commentID!=comment_edit_form){
				eval('comment_edit_'+comment_edit_form+'_slider').toggle();
				eval('comment_edit_'+commentID+'_slider').toggle();
				comment_edit_form=commentID;
			}else{
				var comment_prev_form_fx = eval('comment_edit_'+comment_edit_form+'_slider');
				comment_prev_form_fx.toggle();
				var comment_current_form_fx = eval('comment_edit_'+0+'_slider');
				comment_current_form_fx.toggle();
				comment_edit_form=0;
			}
		}
	
	/************************************
	 * CHECKBOX invert current selection
	 ************************************/		
	
		function checkBoxFlip(item_prefix, items_csv) {
			var items = items_csv.split(',');
			for(var i=0; i<items.length; i++){
				the_item = document.getElementById(item_prefix+items[i]);
				if(the_item!=null){
					if(the_item.type=='checkbox') {
						the_item.checked=!the_item.checked;
					}
				}
			}
		}
		
		function in_array(needle, haystack, strict) {
			var found = false, key, strict = !!strict;
			for (key in haystack) {
				if ((strict && haystack[key] === needle) || (!strict && haystack[key] == needle)) {
					found = true;
					break;
				}
			}
			return found;
		}
		
		function str_replace(search, replace, subject) {
			var f = search, r = replace, s = subject;
			var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
			while(j = 0, i--){
				while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f);
			}
			return sa ? s : s[0];
		}
		
		function is_array( mixed_var ) {
			return ( mixed_var instanceof Array );
		}
		
		/*
		function removeElement(parentDiv, childDiv){
			if (childDiv == parentDiv) {
				alert("The parent div cannot be removed.");
			} else if (document.getElementById(childDiv)) {     
				var child = document.getElementById(childDiv);
				var parent = document.getElementById(parentDiv);
				parent.removeChild(child);
			} else {
				alert("Child div has already been removed or does not exist.");
				return false;
			}
		}*/
		
		var preload_image_array = new Array();
		
		function preloadImages(){
			for (i=0; i < preload_image_array.length; i++) {
				var theImage = new Image();
				theImage.src = preload_image_array[i];
			}
		}
		
