function ActionConfirm(message){
	return confirm(message);
}


function DisplayImageField(){
	$('ImageFileInput').style.display = '';
	$('EditLinksTr').style.display = 'none';
}


function submitSelect(news_id, url){
	selform = document.getElementById('UpdateItem');
	selform.action = url;
	document.getElementById('ItemId').value = news_id;
	selform.submit();
}



function AddItem(tableId, formId){
	$(tableId).style.display = 'none';
	$(formId).style.display = 'block';
}



function AddNews(){
		if (document.getElementById) { // DOM3 = IE5, NS6
			table = document.getElementById('TableGrid');
			addnews = document.getElementById('AddNews');
//			AddNewsTable = document.getElementById('desc_en_tbl');
			table.style.display = 'none';
			table.style.height = 0;
			addnews.style.display = 'block';
//			AddNewsTable.style.width = '500px';
//			AddNewsTable.style.height = '300px';
		}
		else {
			if (document.layers) { // Netscape 4
				document.TableGrid.display = 'none';
			}
			else { // IE 4
				document.all.TableGrid.style.display = 'none';
			}
		}
}

function ShowData(which, label_link){
	divToShow = document.getElementById(which);
	divToShow.style.display = 'block';
	setSelectedLink(label_link);
//	alert('hggg');
}



function ShowCultureData(inputDiv, textareaDiv, label_link){
	$(inputDiv).style.display = 'block';
	$(textareaDiv).style.display = 'block';
	setSelectedLink(label_link);	
}



function ShowDescriptionData(tableId, label_link){
	$(tableId).style.display = 'block';
}


function setSelectedLink(obj){
	obj.className = 'aselected';
}

function ShowDoc(){
	docLink = document.getElementById('DocLink');
	doc = document.getElementById('doc_form');
	IsDocInput = document.getElementById('is_doc');
	doc.style.display = 'block';
	docLink.style.display = 'none';
	IsDocInput.value = '1';
}



function voteOver(obj, starUrl, StarEmptyUrl, divId)
{
	var parentObj = obj.parentNode;
	var imgsrc = starUrl;
	for (i=0; i<parentObj.childNodes.length; i++)
	{
		if (parentObj.childNodes[i].tagName == 'IMG')
		{
			parentObj.childNodes[i].src = imgsrc;
			if (parentObj.childNodes[i].getAttribute("name") == obj.getAttribute("name"))
			{
				imgsrc = StarEmptyUrl;
			}
		}
	}
	$('hidden_'+divId).value = obj.getAttribute("name").substring(4);
}

function voteClick(obj, url, divId)
{
//	alert('111111111');
//	$('hidden_'+divId).value = obj.getAttribute("name").substring(4);
//	new Ajax.Updater(divId, url, {asynchronous:true, evalScripts:false}); 
	
}


function ChangeStatus(obj, url, divId){
	statusId = obj.options[obj.selectedIndex].value;
	new Ajax.Updater(divId, url+'/status_id/'+statusId, {asynchronous:true, evalScripts:false}); 
}




function ChangeUserTeam(obj_select, url, divId){
	teamId = obj_select.options[obj_select.selectedIndex].value;
	new Ajax.Updater(divId, url+'/team_id/'+teamId, {asynchronous:true, evalScripts:false}); 
}



function WizardFormAdd(DivAppendFor, lastIndex, DivToUpdate, DivToAppend, url){
	new Ajax.Updater(DivToUpdate, 
					 url+'/next_id/'+lastIndex, 
					 {asynchronous:true, 
					 evalScripts:true, 
					 onComplete:function(request, json){ $(DivAppendFor).appendChild($(DivToAppend+'_'+lastIndex)); }});; 
	
}



function DeletePromo(ParentDiv, ChildDiv){
	$(ParentDiv).removeChild($(ChildDiv));
}






function myFileBrowser (field_name, url, type, win) {

     alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing

    /* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
       the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
       These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */

    var cmsURL = window.location.toString();    // script URL - use an absolute path!
    if (cmsURL.indexOf("?") < 0) {
        //add the type as the only query parameter
        cmsURL = cmsURL + "?type=" + type;
    }
    else {
        //add the type as an additional query parameter
        // (PHP session ID is now included if there is one at all)
        cmsURL = cmsURL + "&type=" + type;
    }

    tinyMCE.activeEditor.windowManager.open({
        file : cmsURL,
        title : 'My File Browser',
        width : 420,  // Your dimensions may differ - toy around with them!
        height : 400,
        resizable : "yes",
        inline : "yes",  // This parameter only has an effect if you use the inlinepopups plugin!
        close_previous : "no"
    }, {
        window : win,
        input : field_name
    });
    return false;
  }
  
  
  
   
  function initForum2GroupGrid(groups, rows_data, tableId){
//		alert(rows_data.length);
		for (var i=0; i<rows_data.length; i++) {
//			AddForum2GroupRow(groups, i, tableId);
			
			
			newTr = document.createElement('tr');
			newTr.setAttribute('id', 'grouptr'+i);
			newTd1 = document.createElement('td');
			selectGroup = document.createElement('select');
			selectGroup.setAttribute('name', 'group[' + i + ']');
			selectGroup.style.width = '200px';
			for (var gr=0; gr<groups.length; gr++){
				newOption = document.createElement('option');
				OptionText = document.createTextNode(groups[gr]['text']);
				newOption.appendChild(OptionText);
				newOption.setAttribute('value', groups[gr]['value']);
				if (groups[gr]['value'] == rows_data[i]['group']){
					newOption.setAttribute('selected', 'selected');
				}
				selectGroup.appendChild(newOption);
			}
			newTd1.appendChild(selectGroup);
			newTr.appendChild(newTd1);
			
			newTd2 = document.createElement('td');
			newTd2.setAttribute('class', 'centered');
			newCheckbox1 = document.createElement('input');
			newCheckbox1.setAttribute('type', 'checkbox');
			newCheckbox1.setAttribute('name', 'read['+ i +']');
			newCheckbox1.setAttribute('value', 'y');
			if (rows_data[i]['read'] == 'y'){
				newCheckbox1.setAttribute('checked', 'checked');
			}
			newTd2.appendChild(newCheckbox1);
			newTr.appendChild(newTd2);
			
			newTd3 = document.createElement('td');
			newTd3.setAttribute('class', 'centered');
			newCheckbox2 = document.createElement('input');
			newCheckbox2.setAttribute('type', 'checkbox');
			newCheckbox2.setAttribute('name', 'write['+ i +']');
			newCheckbox2.setAttribute('value', 'y');
			if (rows_data[i]['write'] == 'y'){
				newCheckbox2.setAttribute('checked', 'checked');
			}
			newTd3.appendChild(newCheckbox2);
			newTr.appendChild(newTd3);
			
			newTd4 = document.createElement('td');
			newTd4.setAttribute('class', 'centered');
			deleteText = document.createTextNode('X');
			ahref = document.createElement('a');
			ahref.href="#";	
			ahref.setAttribute('onclick', "deleteForum2groupTr('" + "grouptr" + i + "', '" + tableId + "'); return false;")
			ahref.appendChild(deleteText);
			newTd4.appendChild(ahref);
			newTr.appendChild(newTd4);
		
			$(tableId + 'Tbody').appendChild(newTr);
		}
	}
		
		
		
   function AddForum2GroupRow(groups, lastId, tableId){
		newTr = document.createElement('tr');
		newTr.setAttribute('id', 'grouptr'+lastId);
		newTd1 = document.createElement('td');
		selectGroup = document.createElement('select');
		selectGroup.setAttribute('name', 'group[' + lastId + ']');
		selectGroup.style.width = '200px';
		for (var gr=0; gr<groups.length; gr++){
			newOption = document.createElement('option');
			OptionText = document.createTextNode(groups[gr]['text']);
			newOption.appendChild(OptionText);
			newOption.setAttribute('value', groups[gr]['value']);
			selectGroup.appendChild(newOption);
		}
		newTd1.appendChild(selectGroup);
		newTr.appendChild(newTd1);
		
		newTd2 = document.createElement('td');
		newTd2.setAttribute('class', 'centered');
		newCheckbox1 = document.createElement('input');		
		newCheckbox1.setAttribute('type', 'checkbox');
		newCheckbox1.setAttribute('name', 'read['+ lastId +']');
		newCheckbox1.setAttribute('checked', 'checked');
		newCheckbox1.setAttribute('value', 'y');
		newTd2.appendChild(newCheckbox1);
		newTr.appendChild(newTd2);
		
		newTd3 = document.createElement('td');
		newTd3.setAttribute('class', 'centered');
		newCheckbox2 = document.createElement('input');
		newCheckbox2.setAttribute('type', 'checkbox');
		newCheckbox2.setAttribute('name', 'write['+ lastId +']');
		newCheckbox2.setAttribute('checked', 'checked');
		newCheckbox2.setAttribute('value', 'y');
		newTd3.appendChild(newCheckbox2);
		newTr.appendChild(newTd3);
		
		newTd4 = document.createElement('td');
		newTd4.setAttribute('class', 'centered');
		deleteText = document.createTextNode('X');
		ahref = document.createElement('a');
		ahref.href="#";
		ahref.setAttribute('onclick', "deleteForum2groupTr('" + "grouptr" + lastId + "', '" + tableId + "'); return false;")
		ahref.appendChild(deleteText);
		newTd4.appendChild(ahref);
		newTr.appendChild(newTd4);
	
		$(tableId + 'Tbody').appendChild(newTr);
	}
	
	
	function getLastIdFroum2group(){
		i = 0;
		while($('grouptr' + i) != null){
			i++;
		}
		return i;
	}
	
	
	function deleteForum2groupTr(trId, tableId){
		$(tableId + 'Tbody').removeChild($(trId));
	}
	
	
	function moveUserOrGroup(primarySelectId, targetSelect){
		primary = $(primarySelectId);
		target = $(targetSelect);
		if (primary.selectedIndex >= 0){
			option = primary.options[primary.selectedIndex];
			optionToAppend = primary.options[primary.selectedIndex];
			primary.removeChild(option);
			target.appendChild(optionToAppend);
		}
	}
	
	
	
	
	function moveAllUsersOrGroup(primarySelectId, targetSelect){
		primary = $(primarySelectId);
		target = $(targetSelect);
		optionsP = primary.childNodes;
//		alert(optionsP.length);
		while (optionsP.length > 0){
			for (var i=0; i<optionsP.length; i++){
				option = optionsP[i];
				optionToAppend = optionsP[i];
				primary.removeChild(option);
				target.appendChild(optionToAppend);
			}
//			alert('1111');
		}
//		alert(target.childNodes.length);
//		primary.innerHTML = '';		
	}
	
	
	
		
	function moveUserOrGroupBack(primarySelectId, targetSelect){
		primary = $(primarySelectId);
		target = $(targetSelect);
		if (target.selectedIndex >= 0){
			option = target.options[target.selectedIndex];
			optionToAppend = target.options[target.selectedIndex];
			target.removeChild(option);
			primary.appendChild(optionToAppend);		
		}
	}
	
	
	function hideForum2GroupTable(obj, forum2groupTableId){
		if (obj.checked == true){
			$(forum2groupTableId).style.display = 'none';
		}else{
			$(forum2groupTableId).style.display = '';
		}
	}
	
	
	function getAllOptionsFromSelect(selectId, hiddenfield)
	{
		var options = $(selectId).options;
		var newInput = document.getElementById(hiddenfield);
		newInput.value = '';
		for (var i=0; i<options.length; i++){
			newInput.value += ','+options[i].value;
		}
	}
	
	
	
	function getLastId(serialId){
		i = 0;
		while($(serialId + i) != null){
			i++;
		}
		return i;
	}
	
	
	function AddFileInput(name, lastId, divIdToAppend, serialId){
		newDiv = document.createElement('div');
		newDiv.setAttribute('id', 'inputDiv'+lastId);
		newInput = document.createElement('input');
		newInput.setAttribute('name', name + lastId);
		
		newInput.setAttribute('type', 'file');
		newInput.setAttribute('size', '80px');
		newInput.setAttribute('id', 'input'+lastId);
		$(divIdToAppend).appendChild(newInput);
		
		removeText = document.createTextNode('remove');
		attachText = document.createTextNode('Attach new');
		ahref = document.createElement('a');
		ahref.href="#";			
		ahref.setAttribute('onclick', "removeFileInput('inputDiv" + lastId + "', '"+divIdToAppend+"'); return false;")
		ahref.setAttribute('id', ' remove' + lastId);
		ahref.appendChild(removeText);
		
//		ahrefAdd = document.createElement('a');
//		ahrefAdd.href="#";		
//		ahrefAdd.setAttribute('onclick', 'AddFileInput("'+ name + '", getLastId('+ serialId +'), "'+divIdToAppend+'", "'+ serialId +'")')
//		ahrefAdd.setAttribute('id', 'attach' + lastId);
//		ahrefAdd.appendChild(attachText);
		
		newDiv.appendChild(newInput);
		newDiv.appendChild(ahref);
		
		$(divIdToAppend).appendChild(newDiv);
	}
	
	
	
	function removeFileInput(divId, divIdParent){
		$(divIdParent).removeChild($(divId));
	}
	
	
	
	function getDocumentForIframe(target) {
		if (target == undefined)
			return document;
		else if (target.contentDocument)
			return target.contentDocument;
		else if (target.contentWindow)
			return target.contentWindow.document;
		else if (target.document)
			return target.document;
		else
			throw 'unable to get document object';
	}
	
	
//	
//	function setHeightForTranslationDiv(table, divId){
//		$(divId).style.height = table.offsetHeight;
//	}
