///////////////////////////////////////////
// MAIN FUNCTIONS AREA
///////////////////////////////////////////
//<![CDATA[

/*
object_type - logo,footer...
object_id - id logo,id footer...
*/

function art_click()
{
	var tmp_val = $('#art_active').val();
	
	if (tmp_val)
	{
		$('#'+tmp_val).removeClass('art_click');
			}
	
	/*if (this.id==tmp_val)
	{
		$('#art_active').val(0);
	}
	else
	{*/
				$('#'+this.id).addClass('art_click');
		
		$('#art_active').val(this.id);
		$('#selected_article_div_id').val(this.id);
	//}
}

function art_mouseover()
{
	var tmp_val = $('#art_active').val();
	//alert(this.id);
	if (this.id!=tmp_val)
	{
		//alert(this.id);
		$('#'+this.id).addClass('art_click');
	}
}

function art_mouseout()
{
	var tmp_val = $('#art_active').val();
	if (this.id!=tmp_val)
	{
		$('#'+this.id).removeClass('art_click');
	}
}

function art_save()
{
	//var tmp_val = $('#art_active').val();
	//alert('save '+tmp_val);
	$('#mslide_a_save').click();
}

function art_edit()
{
	//var tmp_val = $('#art_active').val();
	//alert('save '+tmp_val);
	$('#mslide_a_new2').click();
}

function art_delete()
{
	$('#mslide_a_delete').click();
	//var tmp_val = $('#art_active').val();
	//if (confirm('Do you really want to delete this article?')) alert('1');
	//alert('delete '+tmp_val);
}

function art_new()
{
	//var tmp_val = $('#art_active').val();
	//alert('new '+tmp_val);
	$('#mslide_a_new').click();
}

function art_move_up()
{
	//var tmp_val = $('#art_active').val();
	//alert('Moving up!');
	$('#mslide_a_up').click();
	$('#art_toolbar').removeClass('art_toolbar_show');
	//var offset = $('#'+this.id).offset();
	//$('#art_toolbar').css('top',offset.top-38).css('left',offset.left);
}

function art_move_down()
{
	//alert('Moving down!');
	//var tmp_val = $('#art_active').val();
	//alert('move_down '+tmp_val);
	$('#mslide_a_down').click();
	$('#art_toolbar').removeClass('art_toolbar_show');
}

function saveArea(param1,param2,param3)
{
	var par = "module=newmenu&action=save";
	par += "&param1="+param1;
	par += "&param2="+param2;
	par += "&param3="+param3;
	
	//alert('Saving area with params: '+par);
	
	$.ajax(
	{
		type: "POST",
		url: "index.php",
		data: par,
		beforeSend: function() {},
		success: function(html)
		{
			//alert('Output html: '+html);
			
			if (param2!=undefined){
				//alert('Evaling in area: '+param2);
				eval(param2);
			} else {
				//alert('Refreshing...');
				ns_click('refresh');
			}
		}
	});
}

function jdc_hgray_iframe_hide()
{
	if (window.parent.document.getElementById('jdc_hgray_status')!=null)
	{
		//window.parent.document.getElementById('showModalDialogDivPageBackgroundLogin').style.display = 'none';
		window.parent.document.getElementById('jdc_hgray_status').click();
	} else {
		parent.document.location='../index.php';
	}
}

function jdc_hgray_hide()
{
	$('#jdc_hgray').hide();
	$('#jdc_hgray_screen').hide();
}

function jdc_hgray_show()
{
	var scroll_top = $(document).scrollTop();
 	var scroll_left = $(document).scrollLeft();
 	var win_width = $(window).width();
	var win_height = $(window).height();
	jdc_hgray_screen_pos(scroll_top,scroll_left,win_width,win_height);

	$('#jdc_hgray_screen').show();
	$('#jdc_hgray').css('opacity','0');
	$('#jdc_hgray').show().animate({ opacity: 0.8}, 1000 );
}

function jdc_hgray_size(width,height)
{
	$('#jdc_hgray').width(width);
	$('#jdc_hgray').height(height);
}

function jdc_hgray_screen_pos(top,left,width,height)
{
	owidth = $('#jdc_hgray_screen').width();
	oheight = $('#jdc_hgray_screen').height();
	posx = (width-owidth)/2;
	posy = (height-oheight)/2;
	posx = (posx>0 ? posx : 0);
	posy = (posy>0 ? posy : 0);
	$('#jdc_hgray_screen').css('top',top+posy);
	$('#jdc_hgray_screen').css('left',left+posx);
}

$(document).ready(function ()
{
	var scroll_top = $(document).scrollTop();
 	var scroll_left = $(document).scrollLeft();
 	
 	var win_width = $(window).width();
	var win_height = $(window).height();
	var doc_width = $(document).width();
	var doc_height = $(document).height();
	
	width = (win_width>doc_width ? win_width : doc_width);
	height = (win_height>doc_height ? win_height : doc_height);
		
	jdc_hgray_size(width,height);
	jdc_hgray_screen_pos(scroll_top,scroll_left,win_width,win_height);
});

$(window).resize(function()
{
  var scroll_top = $(document).scrollTop();
 	var scroll_left = $(document).scrollLeft();
 	
 	var win_width = $(window).width();
	var win_height = $(window).height();
	var doc_width = $(document).width();
	var doc_height = $(document).height();
	
	width = (win_width>doc_width ? win_width : doc_width);
	height = (win_height>doc_height ? win_height : doc_height);
	
  jdc_hgray_size(width,height);
});

$(window).scroll(function () {
	var scroll_top = $(document).scrollTop();
 	$('#top_left_1').height(scroll_top);
});


function really_over(src) {
  if (!window.event) return true;
  var event = window.event;
  var from = event.fromElement;
  var to = event.toElement;
  return ( to == src || src.contains(to) ) && !src.contains(from) && src != from;
}

function really_out(src) {
  if (!window.event) return true;
  var event = window.event;
  var from = event.fromElement;
  var to = event.toElement;
  return (src == from || src.contains(from)) && !src.contains(to) && src != to;
}






function jdc_edit_article(object_type,object_id,article_id)
{
	//alert(object_type+'-'+object_id+'-'+article_id);
	document.forms.article_edit_form.action+='aid='+article_id+'&';
	document.forms.article_edit_form.object_type.value=object_type;
	document.forms.article_edit_form.object_id.value=object_id;
	document.forms.article_edit_form.article_to_edit.value=article_id;
	//document.forms.article_edit_form.article_to_edit_group.value=article_group;
	document.forms.article_edit_form.submit();
}



function findY(obj)
{
	curleft = 0;
	if (obj.offsetParent)
	{
		do { curleft += obj.offsetLeft; }
		while (obj = obj.offsetParent);
		return curleft;
	}
	else if(obj.x)
	{
		curleft+=obj.x;
		return curleft;
	}
}

function findX(obj)
{
	curtop = 0;
	if (obj.offsetParent)
	{
		do { curtop += obj.offsetTop; }
		while (obj = obj.offsetParent);
		return curtop;
	}
	else if(obj.y)
	{
		curtop+=obj.y;
		return curtop;
	}
}




// GLOBAL VARIABLE TO IDENTIFY BROWSER
var browser = navigator.userAgent.toLowerCase();
var isIE = false, isFirefox = false, isOpera = false, isSafari2 = false, isSafari3 = false;
if (browser.indexOf("msie 6")!=-1) var isIE6 = true;
if (browser.indexOf("msie")!=-1) var isIE = true;
else if (browser.indexOf("firefox")!=-1) var isFirefox = true;
else if (browser.indexOf("opera")!=-1) var isOpera = true;
else if (browser.indexOf("safari")!=-1)
	{
	// Safari 3 works as Firefox
	if (browser.indexOf("version/3.")!=-1)
		{
		isSafari3 = true;
		isFirefox = true;
		}
	else
		isSafari2 = true;
	}
//alert("MSIE:"+isIE+" Firefox:"+isFirefox+" Opera:"+isOpera+" Safari:"+isSafari2);



// Variable to store logo image for changing it on category selection if image_change is defined
//var logo_image_name='Max';

//Function to pause executing
function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}
//End pause


function set_preview_from_new_menu (forig,fdest,object_type,object_id) {
	if (forig=="more_align_new_menu") {
		if (document.getElementById(forig).value=="none") {
			document.forms[object_type+"_"+object_id+"_articles_form"].type.value="article";
		} else {
			document.forms[object_type+"_"+object_id+"_articles_form"].type.value="larticle";
			document.getElementById(fdest).value = document.getElementById(forig).value;
		}
	}
	else
	{
	
		document.getElementById(fdest).value = document.getElementById(forig).value;	
		//alert(document.getElementById(fdest).value);
	}
}

function admin_logout()
{
//isIE5; // !!!
// Set the dialog window options
    var window_width = 500;
    var window_height = 400;
    var Center = "center=yes; ";
    var Scrollbars = "scroll=no; ";
    //var sElem = event.srcElement ? event.srcElement : event.target;
    var Help = "help=no; ";
    var Status = "status=no; ";
    var Resize = "resizable=no; ";
    var Height = "dialogHeight=" + window_height + "px; ";
    var Width = "dialogWidth=" + window_width + "px; ";
    //var posLeft = sElem.offsetLeft + sElem.offsetWidth + window.screenLeft;
    var posLeft = screen.width/2 - window_width/2;
    //var posTop = sElem.offsetTop + sElem.offsetHeight + window.screenTop;
    var posTop = screen.height/2 - window_height/2;
    var Left = "dialogLeft=" + posLeft + "px; ";
    var Top = "dialogTop=" + posTop + "px; ";
    var unadorned = "yes";
// Compile the option string
    var ParamStr = Top + Left + Height + Width + Center + Scrollbars + Help + Status + Resize + unadorned;
// Call the dialog and wait for results
//   result = window.open("logout.html", "_blank", "statusbar=no; heigth=200; width=200;");
	//if (isIE)
	if (1==2)
		{
	    result = window.showModalDialog("admin/logout.php?site=kval", window , ParamStr);
		if (result != null)
		    {
		    document.getElementById("logoutform_yes").submit();
		    }
    	}
    else
	    {
	    //modalDivLogout(1);
	    var attribs = new Array();
	    attribs['width'] = 500;
	    attribs['height'] = 400;
	    showModalDialogDiv("admin/logout.php?site=kval",attribs,0);
	    }
return;
}



function admin_login()
{
//isIE5; // !!!
// Set the dialog window options
    var window_width = 540;
    var window_height = 400;
    var Center = "center=yes; ";
    var Scrollbars = "scroll=no; ";
    //var sElem = event.srcElement ? event.srcElement : event.target;
    var Help = "help=no; ";
    var Status = "status=no; ";
    var Resize = "resizable=no; ";
    var Height = "dialogHeight=" + window_height + "px; ";
    var Width = "dialogWidth=" + window_width + "px; ";
    //var posLeft = sElem.offsetLeft + sElem.offsetWidth + window.screenLeft;
    var posLeft = screen.width/2 - window_width/2;
    //var posTop = sElem.offsetTop + sElem.offsetHeight + window.screenTop;
    var posTop = screen.height/2 - window_height/2;
    var Left = "dialogLeft=" + posLeft + "px; ";
    var Top = "dialogTop=" + posTop + "px; ";
    var unadorned = "yes";
// Compile the option string
    var ParamStr = Top + Left + Height + Width + Center + Scrollbars + Help + Status + Resize + unadorned;
// Call the dialog and wait for results
//   result = window.open("logout.html", "_blank", "statusbar=no; heigth=200; width=200;");
	//if (isIE)
	if (1==2)
		{
	    result = window.showModalDialog("admin/index.php?site=kval", window , ParamStr);
		if (result != null)
		    {
		    document.getElementById("logoutform_yes").submit();
		    }
    	}
    else
	    {
	    //modalDivLogout(1);
	    var attribs = new Array();
	    attribs['width'] = 580;
	    attribs['height'] = 500;
	    showModalDialogDivLogin("admin/index.php?site=kval",attribs,0);
	    }
return;
}




function toggle_help_section(){
(document.getElementById("help_section").style.display=='') ? document.getElementById("help_section").style.display='none':document.getElementById("help_section").style.display='';
}





// Multiple function load on window.onload
var windowOnloadFunctionList = new Array();
// Adding function to window.onload list
function addToWindowOnloadFunctionList(function_name)
{
windowOnloadFunctionList[windowOnloadFunctionList.length] = function_name;
}

// Running window.load list
function runWindowOnloadFunctionList()
{
//alert(windowOnloadFunctionList.length + ' functions to run on window.onload!');
for (var i=0; i<windowOnloadFunctionList.length; i++)
	{
	//alert(windowOnloadFunctionList[i]);
	//eval(windowOnloadFunctionList[i]);
	// setTimeout is more secured - if error happens in any function it will continue
	if (!document.getElementById("m0g1_button") && !document.getElementById("m0g10_button")) {
	setTimeout(windowOnloadFunctionList[i],100);}
	}
}








var global_text_id = '';



// BLANK FUNCTINO FOR A HREF TO WORK PROPERLY, because "#" makes page go to top
function menu_click()
{
return;
}

function click()
{}




function directory_click(menu_id, category_id)
{
hide_first_level_menu_categories(menu_id);
var AnchorFieldObj = document.getElementById('m'+menu_id+'g'+category_id+'_button');
// Remove category id from expand list, so click() will always expand it, not hide/show
var expand_id="m"+menu_id+"g"+category_id+";";
var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
expand_list.value=expand_list.value.replace(expand_id,"");
// click() method in Mozilla browsers enables fixMozillaClickMethod();
AnchorFieldObj.click();
}





/*

function getElementTopPositionByObject(object)
{
var top_offset = object.style.posTop;
if (!top_offset)
{
top_offset = object.style.top;
}
if (!top_offset)
{
var top_node = document.body;
var cur_node;
//var cur_node = document.all[elem_id];
var cur_node = object;
top_offset=0;
while (cur_node != top_node)
	{
	top_offset += cur_node.offsetTop;
	if (cur_node.scrollTop) top_offset -= cur_node.scrollTop;
	cur_node = cur_node.offsetParent;
	}
//alert(top_offset+'-'+i);
}
//alert(top_offset);
return top_offset;
}


function getElementLeftPositionByObject(object)
{
var left_offset = object.style.posLeft;
if (!left_offset)
{
left_offset = object.style.left;
}
if (!left_offset)
{
var top_node = document.body;
var cur_node;
//var cur_node = document.all[elem_id];
var cur_node = object;
left_offset=0;
while (cur_node != top_node)
	{
	left_offset += cur_node.offsetLeft;
	cur_node = cur_node.offsetParent;
	}
}
//alert(left_offset);
return left_offset;
}






function showHoverMenuCategory(group_id, hover_flag, horizontal_flag, null_level)
{
//alert(group_id);
//document.all['output_debug'].value += 'showHoverMenuCategory('+group_id+','+category_object+')';
//category_object.menu_status == 'show' ? category_object.menu_status == '' : category_object.menu_status == 'show';
//if (category_object.menu_status == 'show')
showgroup(group_id,1, hover_flag, horizontal_flag, null_level);
//global_hover_menu_show_flag = 1;
}
*/







function showgroup(id, thisNode, hover_flag, horizontal_flag, null_level, page_has_directory_object)
{
// null_level - identifies if current category is a null level category subcategory.

//if (id == 'm0g0p0' && page_has_directory_object) return;
var parent_id = id.substring(0,id.indexOf("g")+1)+id.substring(id.indexOf("p")+1,id.length)
//alert(parent_id);

var menu_width = document.getElementById('object_cell_menu4db_0').style.width;
var menu_width_new = document.getElementById('menu0_main_table').offsetWidth;
// Was in non "loose.dtd" doctype
menu_width = parseInt(menu_width, 10)+parseInt(document.getElementById('object_cell_menu4db_0').style.paddingLeft, 10)+parseInt(document.getElementById('object_cell_menu4db_0').style.paddingRight, 10);
//menu_width = parseInt(menu_width, 10);
var first_level_categories_step = menu_width / global_first_level_categories_count;
// Rounding to lowest
first_level_categories_step = first_level_categories_step - first_level_categories_step%1;
//alert(first_level_categories_step);

var item;
var a = 0;
item = id.substring(0,id.indexOf('p')) + "i" + a;
if (document.getElementById(item))
{
//for (var a=0;a<i;a++)

while (document.getElementById(item))
     {
	 // Cell address
     item = id.substring(0,id.indexOf('p')) + "i" + a;
     x = document.getElementById(item);
          if (x)
          {
          if (x.style.display == '')
              {
              x.style.display = 'none';
              if ((isSafari2 && thisNode.id.indexOf('g0')==-1)) { x.parentNode.parentNode.style.marginTop = 0; }
              }
          else
              {
              // If not first level category
              if (id.indexOf('g0')<0)
	              	{
	              	if (!horizontal_flag)
		              	{
						//PAVELs
		              	x.style.marginLeft = menu_width_new-10 + "px";
		              	// SAFARI BUG
		              	x.style.marginTop = -20 + a * 20 + a * menu_category_spacing + (menu_category_spacing!="0" ? 0 : -3);						
		              	x.style.height = 22; // was 25
		              	}
		            else
			            {
			            // Set indent only for not first level categories
			            x.style.marginLeft = (isIE ? 120: 100) * !null_level + "px";
						//alert(x.style.marginLeft);
			            // SAFARI BUG !!!
			           	if (isSafari2) { x.style.pixelTop = null_level * 20 + a * (20 + parseInt(menu_category_spacing,10)); /*document.getElementById('m0g0i4').style.marginTop = -10;*/ }
			           		else x.style.marginTop = (!null_level * (isIE ? -23 : -20)) + a * 20 + a * menu_category_spacing + "px";
						//alert(x.style.marginTop);
			            x.style.height = 20 + "px";
			            }
	              	x.style.width = 150+"px";
	              	// In FF and Safari inner <td> inherits width of containing text. Fixed with JS.
	              	if (!isIE)
	              		x.cells[0].style.width = 150+"px";
	              	if (isSafari2)
	              		{
		              	// CLIENT LEFT, TOP. for DIV and TBODY inside for check.
		              	var div = x.parentNode.parentNode.parentNode;
		              	var tab = x.parentNode.parentNode;
		              	var tbody = x.parentNode;
		              	var header_tab = tbody.rows[0].cells[0].children[0];
		              	tab.style.marginTop = -10;
		              	}
		      		}
	          else // First level categories
		      		{
		          	x.style.marginLeft = a * first_level_categories_step + (x.style.marginLeft ? parseInt(x.style.marginLeft,10) : 0) +"px";
		          	x.style.height = 20 + "px";
		          	}
				x.style.display = '';
				x.style.zIndex = 2;
				}
          }
     a++;
     }

// Do this only in normal expand mode (not hover+dropdown)
if (!hover_flag)
{
var menu_id = id.substring(id.indexOf("m")+1,id.indexOf("g"));
var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
//alert(expand_list.value);
var expand_id=id+";";
if (expand_list.value.indexOf(expand_id)!=-1)
    expand_list.value=expand_list.value.replace(expand_id,"");
else expand_list.value+=expand_id;
//alert(expand_id+' to '+expand_list.value);


// Change plus/minus image for this group
x = document.getElementById(id+"_plus_img");
if (x)
	{
	image=x.src
	image=image.substring(image.lastIndexOf("/")+1,image.lastIndexOf("."));
	if (image=="plus")
	    x.src="pictures/default/system/minus.gif";
	else
	    x.src="pictures/default/system/plus.gif";
	}

}

} // End of - if (i)
return;
}

///////////////////////////////////////////////

function changeGalleryIcon(img,dir)
{
document.getElementById('choose_icon'+dir).style.backgroundRepeat="no-repeat";
document.getElementById('choose_icon'+dir).style.backgroundPosition="5% 50%";
document.getElementById('choose_icon'+dir).style.backgroundImage="url("+img+")";

}
 
function setGalleryValues(id,type) 
{
	switch(type)
	{
	case 'checkbox':
	  if (document.getElementById(id).checked) {
	  	document.getElementById(id).checked=false;
	  } else {
	  	document.getElementById(id).checked=true;
	  }
	  break;  
	case 'text':
	  document.getElementById(id).value = document.getElementById(id+'_new_menu').value;
	  break;   
	case 'radio':
	  document.getElementById(id).checked=true;
	  break;    
	}
}

function changeVideo(video_file,article_id)
{
	var so = new SWFObject("RolloverPlayer.swf?path="+video_file+"&buffersize=4&startauto=false&redirect=", "player", "340", "220", "8", "#ffffff");
	so.write("flashcontent_"+article_id);
}


function expandIngress(id) {
	if (document.getElementById('ingress_'+id+'_ingress_div').style.display == 'none') {
		document.getElementById('ingress_'+id+'_ingress_div').style.display = '';
		document.getElementById('onliner_'+id+'_oneliner_img').src = 'pictures/default/new/oneliner_minus.gif';
	} else {
		document.getElementById('ingress_'+id+'_ingress_div').style.display = 'none';
		document.getElementById('onliner_'+id+'_oneliner_img').src = 'pictures/default/new/oneliner_plus.gif';

	}

}


function loopThroughDivs() {
	var allDivs = document.getElementsByTagName("div");


	var len = allDivs.length;
	
	for(var x=0;x<len;x++){
		var singleDiv = allDivs[x].id;
		if ((singleDiv.substring(0,9)=='art_g0div' || singleDiv.substring(0,9)=='ads_g0div') && document.getElementById('selected_article_div_id').value!=singleDiv) {document.getElementById(singleDiv).style.border='1px solid transparent';}
	}

}

function psEnabled(obj)
{
	if (obj.checked) 
	{
		document.getElementById('buy_enabled').checked=true;
		if (document.getElementById('ps1')) document.getElementById('ps1').style.display="";
		if (document.getElementById('ps2')) document.getElementById('ps2').style.display="";
		if (document.getElementById('ps3')) document.getElementById('ps3').style.display="";
		if (document.getElementById('ps4')) document.getElementById('ps4').style.display="";
	} 
	else 
	{
		document.getElementById('buy_enabled').checked=false;
		if (document.getElementById('ps1')) document.getElementById('ps1').style.display="none";
		if (document.getElementById('ps2')) document.getElementById('ps2').style.display="none";
		if (document.getElementById('ps3')) document.getElementById('ps3').style.display="none";
		if (document.getElementById('ps4')) document.getElementById('ps4').style.display="none";
	}

}

function editIframeShow () {
	if (document.getElementById('frame_edit_div')) document.getElementById('frame_edit_div').style.display="";
}
function editIframeHide () {
	if (document.getElementById('frame_edit_div')) document.getElementById('frame_edit_div').style.display="none";
}
function move_group(cell_id,direction)
{
	//alert(cell_id+'-'+direction);

	var a=document.getElementById(cell_id+"_pos").value;
	if (direction=='down') a++; // use a because "+" symbol concatinates strings 1+1 !=2, but =11
	else a--;
	//alert(direction);
	var div_num=cell_id.substring(0,(cell_id.indexOf("g")+1))+document.getElementById(cell_id+"_groupid").value+'div'+document.getElementById(cell_id+"_pos").value;
	var div_num_under=div_num.substring(0,(div_num.indexOf("v")+1))+a;

	var i=0;
	var cell_find=cell_id.substring(0,(cell_id.indexOf("i")+1));
	//alert("cell_id:"+cell_id+";div_num:"+div_num+";div_num_under:"+div_num_under+";cell_find:"+cell_find);
	while(document.getElementById(cell_find+i+"_pos"))
	{
	//alert(cell_find+i+"_pos");
	//alert(document.getElementById(cell_find+i+"_pos").value+" ?= "+a);
	if (document.getElementById(cell_find+i+"_pos").value==a)
	if (document.getElementById(cell_find+i+"_groupid").value==document.getElementById(cell_id+"_groupid").value)
		{
		cell_find+=i;
		break;
		}
	i++;
	}

	//alert("Cell from: "+cell_id+"\nCell to: "+cell_find+"\nDiv from: "+div_num+"\nDiv to: "+div_num_under);

	//if (document.getElementById(div_num_under) && document.getElementById(cell_find))
	if (document.getElementById(cell_id+"_pos") && document.getElementById(cell_find+"_pos"))
		{

		var temp = '';
		var parent_0 = document.getElementById(div_num);
		var parent_1 = document.getElementById(div_num_under);
		//alert(div_num+'-'+document.getElementById(div_num));
		// In Firefox <div> has #text on both sides of content
		var content_0 = parent_0.childNodes[0];
		var content_1 = parent_1.childNodes[0];

		temp = document.getElementById(cell_id+"_pos").value;
		// U Safari v sledujushej strochke na document.getElementById(cell_find+"_pos").value HUJNJA!
		document.getElementById(cell_id+"_pos").value = document.getElementById(cell_find+"_pos").value;
		document.getElementById(cell_find+"_pos").value = temp;
		
		temp = document.getElementById(cell_id+"_start_new_row").value;
		document.getElementById(cell_id+"_start_new_row").value = document.getElementById(cell_find+"_start_new_row").value;
		document.getElementById(cell_find+"_start_new_row").value = temp;


		// FOR VEIW_ALL_ARTICLES
		if (document.getElementById(cell_id+"_pos_real"))
		  {
		  temp=document.getElementById(cell_id+"_pos_real").value;
		  document.getElementById(cell_id+"_pos_real").value=document.getElementById(cell_find+"_pos_real").value;
		  document.getElementById(cell_find+"_pos_real").value=temp;
		  }

		// Swap categories visually
		var next = content_0.nextSibling;
		parent_1.insertBefore(content_0,content_1);
		parent_0.insertBefore(content_1,next);
		}
	//return 1;
}







// Viewing all articles of selected group throught form submiting
function all_articles_view(menu_id, group_nr, parent_id, hover_flag)
{
	if (document.getElementById("menu_"+menu_id+"_default_show_plus").value==0 && !hover_flag)
	{
		var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
		var expand_id="m"+menu_id+"g"+group_nr+'p'+parent_id+";";
		if (expand_list.value.indexOf(expand_id)==-1)
		{
			expand_list.value+=expand_id;
			cleanExpandList(menu_id, group_nr, parent_id);
		}
		else expand_list.value=expand_list.value.replace(expand_id,"");
	}
	
	if (!hover_flag) expandCategoriesByList(menu_id);
	
	document.getElementById("menu_"+menu_id+"_view_all_articles_for_group").value=group_nr;
	
	var action = document.getElementById("menu_"+menu_id+"_main_form").action;
	// Safari starts refreshing the page all the time
	if (action.indexOf('?cid=')>=0) action = action.substring(0,action.indexOf('?cid'));
	document.getElementById("menu_"+menu_id+"_main_form").action = action+"?site=kval&change_base=site&cid="+group_nr+"&mid="+menu_id;

	// Change logo image if name was given by selecting a category
	if (document.getElementById('logo_image'))
	if (document.getElementById('change_logo_image').value)
	{
		var new_logo_path = 'http://www.kvalsvik.no\/'+picture_directory +'/'+ document.getElementById('change_logo_image').value;
		//document.getElementById('logo_image').src = new_logo_path;
		document.getElementById('logo_image').setAttribute('src',new_logo_path);
		// FIX for IE6
		if (isIE6) setTimeout("document.getElementById('logo_image').setAttribute('src','"+new_logo_path+"');", 500);
	}
	else document.getElementById('logo_image').src=logo_image_name;
	
	
	// Change background image if name was given by selecting a category
	var background_image;
	var background_target;
	// Determine if use requested background image or general for page
	background_image = (document.getElementById('change_background_image').value ? "url("+picture_directory +"/"+ document.getElementById('change_background_image').value+")" : background_image = "url("+picture_directory +"/"+ background_image_name+")");
	// Determine background of what object to change (body in normal mode OR "page frame" in admin mode)
	background_target = document.getElementById('page_frame_in_design') ? document.getElementById('page_frame_in_design') : document.getElementById("main_body");
	if (background_image)
	{
	background_target.style.backgroundImage = background_image;
	// FIX for IE6
	if (isIE6) setTimeout((document.getElementById('page_frame_in_design') ? "document.getElementById('page_frame_in_design')" : 'document.getElementById("main_body")')+'.style.backgroundImage = "'+background_image+'"', 500);
	}
	//alert(document.body.background);
	
	
	document.forms["menu_"+menu_id+"_main_form"].submit();
	// FIX for IE5
		
	// Empty value of 'change_logo_image' for categories with no image (form is not refreshed in web mode)
	document.getElementById('change_logo_image').value = '';
	document.getElementById('change_background_image').value = '';
}




// Set all categories' events to normal category's events (unset "current category" style)




function html_page_view(menu_id, group_nr, parent_id)
{
//if (!document.all["menu_"+menu_id+"_config"] && document.all["menu_"+menu_id+"_default_show_plus"].value==0)
//     document.all["m"+menu_id+"g"+group_nr+"_expanded"].value=(document.all["m"+menu_id+"g"+group_nr+"_expanded"].value) ? 0 : 1;
if (document.getElementById["menu_"+menu_id+"_default_show_plus"].value==0)
    {
    //document.all["m"+menu_id+"g"+group_nr+"_expanded"].value=(document.all["m"+menu_id+"g"+group_nr+"_expanded"].value) ? 0 : 1;
    var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
    var expand_id="m"+menu_id+"g"+group_nr+"p"+parent_id+";";
    if (expand_list.value.indexOf(expand_id)==-1)
        expand_list.value+=expand_id;
    }
document.getElementById["menu_"+menu_id+"_view_html_page_for_group"].value=group_nr;
document.getElementById["menu_"+menu_id+"_main_form"].submit();
}






function menu_submit(tablename, type)
{
alert("Under Construction");
}




function add_subgroup(menu_id, group_id, parent_id)
{
// Open folder where new subgroup will be created
//document.all["m"+menu_id+"g"+group_id+"_expanded"].value = 1;
//document.all["new_subgroup_header"].value=subgroup_header; // Written on place by $words
//document.all.new_subgroup_form.menu_0_selected_article_form.value=group_id;
document.getElementById("new_subgroup_group_id").value=group_id;
document.getElementById("new_subgroup_menu_id").value=menu_id;
    var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
    var expand_id="m"+menu_id+"g"+group_id+'p'+parent_id+";";
    if (expand_list.value.indexOf(expand_id)==-1)
        expand_list.value+=expand_id;
// Copy of expand list to be sent with "" form when creating a subcategory and expanding parent category
//var new_expand_list = document.forms["new_subgroup_form"].elements("menu_"+menu_id+"_cat_expand_list");
var new_expand_list = document.forms["new_subgroup_form"].elements["menu_0_cat_expand_list"];
new_expand_list.value = expand_list.value;
document.getElementById("menu_"+menu_id+"_cat_expand_list").value = expand_list.value;
document.getElementById("new_subgroup_form").submit();
}





function cleanExpandList(menu_id, group_id, parent_id)
{
var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
//alert(menu_id+'-'+group_nr+'-'+expand_list.value);
var category_full_id = getCategoryFullId(menu_id, group_id);
var live_list = category_full_id + ';';
var parent_id = category_full_id.substring(category_full_id.indexOf('p')+1);
var save_dead_cycle = 0;
while (parent_id != '0' && parent_id != 0 && save_dead_cycle<1000)
	{
	//alert("Full id: "+category_full_id+' Parent: '+parent_id);
	category_full_id = getCategoryFullId(menu_id, parent_id);
	live_list += category_full_id + ';';
	parent_id = category_full_id.substring(category_full_id.indexOf('p')+1);
	save_dead_cycle++;
	}
expand_list.value = live_list;
// Debug show if no success
//if (save_dead_cycle>=1000) alert("Dead");
//alert('List: '+live_list);
}





function getCategoryFullId(menu_id, group_id)
{
var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
var category_half_id = 'm'+menu_id+'g'+group_id+'p';
var full_id = expand_list.value.substring(expand_list.value.indexOf(category_half_id));
full_id = full_id.substring(0,full_id.indexOf(';'));
return full_id;
}



function expandOneCategoryByList(menu_id,category_id)
{
document.getElementById("menu_"+menu_id+"_cat_expand_list").value = "m"+menu_id+"g"+category_id+"p0;";
expandCategoriesByList(menu_id);
}



function expandCategoriesByList(menu_id)
{
var expand_list = document.getElementById("menu_"+menu_id+"_cat_expand_list");
//alert(expand_list.value);
var categories = expand_list.value.split(';');
var tr_rows = document.getElementsByTagName('TR');
var cateory_item_id, processed = 0;
//alert(tr_rows.length);

for (var i=0; i<categories.length; i++)
	{
	categories[i] = categories[i].substring(0,categories[i].indexOf('p'));
	}
//*
var i = 0, g = 0;
for (var j=0; j<tr_rows.length; j++)
	{
	while (categories[i] && !processed && tr_rows[j].id)
		{
		if ((tr_rows[j].id.indexOf(categories[i]+'i') == 0 || tr_rows[j].id.indexOf('m'+menu_id+'g0i')==0) && tr_rows[j].id.indexOf('_icons')==-1)
			{
			// Chechk if cell is not a first level category, so the subcategory choice whould not display it in normal mode
			if (!(tr_rows[j].id.indexOf('m'+menu_id+'g0i')==0 && (document.getElementById('menu_'+menu_id+'_directory_0') || document.getElementById('menu_'+menu_id+'_directory_1') && document.getElementById('menu_'+menu_id+'_directory_2'))))
				{
				//alert(tr_rows[j].id);
				tr_rows[j].style.display = '';
				}
			processed = 1;
			}
		else if (tr_rows[j].id.indexOf('m'+menu_id+'g')==0)
			{
			tr_rows[j].style.display = 'none';
			}
		i++;
		}
	processed = 0;
	i = 0;
	}
}




function delete_subfolder(menu_id, group_id)
{
document.getElementById("menu_"+menu_id+"_rem_group_"+group_id).value=1;
document.getElementById("menu_"+menu_id+"_main_form").submit();
}









function showModalDialogDiv(url, attribs, values)
{
document.getElementById('showModalDialogDivPage').style.display = '';
document.getElementById('showModalDialogDivPageBackground').style.display = '';
document.getElementById('showModalDialogDivPage').style.height = document.body.scrollHeight;
document.getElementById('showModalDialogDivPageBackground').style.height = document.getElementsByTagName('html')[0].scrollHeight+'px';
document.getElementById('showModalDialogDivIframe').src = url;
if (attribs['height']) document.getElementById('showModalDialogDivWindow').style.height = attribs['height']+'px';
if (attribs['width']) document.getElementById('showModalDialogDivWindow').style.width = attribs['width']+'px';
if (attribs['top']) document.getElementById('showModalDialogDivWindow').style.merginTop = attribs['top']+'px';
if (attribs['left']) document.getElementById('showModalDialogDivWindow').style.marginLeft = attribs['left']+'px';
if (attribs['right']) document.getElementById('showModalDialogDivWindow').style.marginRight = attribs['right']+'px';
if (attribs['bottom']) document.getElementById('showModalDialogDivWindow').style.marginBottom = attribs['bottom']+'px';
if (attribs['close']) document.getElementById('showModalDialogDivCloseButton').style.display = '';
//document.all['showModalDialogDivIframe'].dialogArguments = values;
}

function showModalDialogDivLogin(url, attribs, values)
{
document.getElementById('showModalDialogDivPage').style.display = '';
document.getElementById('showModalDialogDivPageBackgroundLogin').style.display = '';
document.getElementById('showModalDialogDivPage').style.height = document.body.scrollHeight;
document.getElementById('showModalDialogDivPageBackgroundLogin').style.height = document.getElementsByTagName('html')[0].scrollHeight+'px';
document.getElementById('showModalDialogDivIframe').src = url;
if (attribs['height']) document.getElementById('showModalDialogDivWindow').style.height = attribs['height']+'px';
if (attribs['width']) document.getElementById('showModalDialogDivWindow').style.width = attribs['width']+'px';
if (attribs['top']) document.getElementById('showModalDialogDivWindow').style.merginTop = attribs['top']+'px';
if (attribs['left']) document.getElementById('showModalDialogDivWindow').style.marginLeft = attribs['left']+'px';
if (attribs['right']) document.getElementById('showModalDialogDivWindow').style.marginRight = attribs['right']+'px';
if (attribs['bottom']) document.getElementById('showModalDialogDivWindow').style.marginBottom = attribs['bottom']+'px';
if (attribs['close']) document.getElementById('showModalDialogDivCloseButton').style.display = '';
//document.all['showModalDialogDivIframe'].dialogArguments = values;
}


function showModalDialogDivClose()
{
document.getElementById('showModalDialogDivPage').style.display = 'none';
document.getElementById('showModalDialogDivPageBackground').style.display = 'none';
document.getElementById('showModalDialogDivPageBackgroundLogin').style.display = 'none';
document.getElementById('showModalDialogDivCloseButton').style.display = 'none';
}






// Opens a Dialg window for group settings changing
function group_advanced_settings(menu_id, categ_id, cell_id)
{
//isIE5;
// Set the dialog window options

//alert(user+menu_id+categ_id+cell_id);
/*
    var params = new Array(1);
    params["type"] = document.all[cell_id+"_type"].value;
    params["group_type"] = document.all[cell_id+"_group_type"].value;
    params["icon"] = document.all[cell_id+"_icon"].value;
    params["font_type"] = document.all[cell_id+"_font_type"].value;
    params["font_color"] = document.all[cell_id+"_font_color"].value;
    params["bgcolor"] = document.all[cell_id+"_bgcolor"].value;

    params["default_group_type"] = document.all['menu_'+menu_id+"_default_group_type"].value;
    params["default_icon"] = document.all['menu_'+menu_id+"_default_icon"].value;
    params["default_font_type"] = document.all['menu_'+menu_id+"_default_font_type"].value;
    params["default_font_color"] = document.all['menu_'+menu_id+"_default_font_color"].value;
    params["default_bgcolor"] = document.all['menu_'+menu_id+"_default_bgcolor"].value;
    params["default_hovercolor"] = document.all['menu_'+menu_id+"_default_hovercolor"].value;
    params["default_show_plus"] = document.all['menu_'+menu_id+"_default_show_plus"].value;
    params["default_menu_nowrap"] = document.all['menu_'+menu_id+"_default_menu_nowrap"].value;

    var window_width = 380;
    var window_height = 540;
    var posLeft = screen.width/2 - window_width/2;
    var posTop = screen.height/2 - window_height/2;
    var ParamStr = "dialogLeft:"+posLeft+"px; dialogTop:"+posTop+"px; dialogWidth:"+window_width+"px; dialogHeight:"+window_height+"px; resizable:no; help:no;";
// Call the dialog and wait for results
    result = window.showModalDialog("group_adv_set.php", params, ParamStr);
*/
    var window_width = 380;
    var window_height = 600;
    var posLeft = screen.width/2 - window_width/2;
    var posTop = screen.height/2 - window_height/2;
    var ParamStr = "dialogLeft:"+posLeft+"px; dialogTop:"+posTop+"px; dialogWidth:"+window_width+"px; dialogHeight:"+window_height+"px; resizable:no; help:no; status: no;";
// Call the dialog and wait for results
	var params = 0;

/*	if (isIE)
		{
    	result = window.showModalDialog("group_adv_set.php?menu_id="+menu_id+"&categ_id="+categ_id, params, ParamStr);
		}
	else
		{*/
		var attribs = new Array();
		attribs['height'] = 600;
		showModalDialogDiv("group_adv_set_iframe.php?menu_id="+menu_id+"&categ_id="+categ_id,attribs,0);
		//}
	/*
if (result != null)
    {
    document.all[cell_id+"_type"].value=result["type"];
    document.all[cell_id+"_group_type"].value=result["group_type"];
    document.all[cell_id+"_icon"].value=result["icon"];
    document.all[cell_id+"_font_type"].value=result["font_type"];
    document.all[cell_id+"_font_color"].value=result["font_color"];
    document.all[cell_id+"_bgcolor"].value=result["bgcolor"];

    document.all['menu_'+menu_id+"_default_group_type"].value=result["default_group_type"];
    document.all['menu_'+menu_id+"_default_icon"].value=result["default_icon"];
    document.all['menu_'+menu_id+"_default_font_type"].value=result["default_font_type"];
    document.all['menu_'+menu_id+"_default_font_color"].value=result["default_font_color"];
    document.all['menu_'+menu_id+"_default_bgcolor"].value=result["default_bgcolor"];
    document.all['menu_'+menu_id+"_default_hovercolor"].value=result["default_hovercolor"];

    if (!result["default_show_plus"])
         document.all['menu_'+menu_id+"_default_show_plus"].value=0;
    else document.all['menu_'+menu_id+"_default_show_plus"].value=1;
    if (!result["default_menu_nowrap"])
         document.all['menu_'+menu_id+"_default_menu_nowrap"].value=0;
    else document.all['menu_'+menu_id+"_default_menu_nowrap"].value=1;
    //alert(document.all['menu_'+menu_id+"_default_show_plus"].value);
    if (result["default_icon_file"])
        {
        document.all["menu_"+menu_id+"_default_icon_file"].value=result["default_icon_file"];
        var short_file,filename;
        short_file=result["default_icon_file"];
        filename=short_file.substring(short_file.lastIndexOf("\\")+1,short_file.lenght);
        //alert(filename);
        document.all["menu_"+menu_id+"_default_icon"].value=filename;
        }
    if (result["icon_file"])
        {
        document.all["menu_"+menu_id+"_icon_file"]=result["default_icon_file"];
        var short_file,filename;
        short_file=result["icon_file"];
        filename=short_file.substring(short_file.lastIndexOf("\\")+1,short_file.lenght);
        //alert(filename);
        document.all["menu_"+menu_id+"_default_icon"].value=filename;
        }
    }
*/
return;
}





function check_group_for_article(menu_id,group_id)
{
//alert(document.all["article_cat_m"+menu_id+"g"+group_id+"_copy"].checked);
if (!document.getElementById("article_cat_m"+menu_id+"g"+group_id+"_copy").checked)
    {
    document.getElementById("article_cat_m"+menu_id+"g"+group_id+"_copy").checked=0;
    if (document.getElementById("article_cat_m"+menu_id+"g"+group_id))
        document.getElementById("article_cat_m"+menu_id+"g"+group_id).checked=0;
    }
else
    {
    document.getElementById("article_cat_m"+menu_id+"g"+group_id+"_copy").checked=1;
    if (document.getElementById("article_cat_m"+menu_id+"g"+group_id))
        document.getElementById("article_cat_m"+menu_id+"g"+group_id).checked=1;
    }

}





function start_check_group_for_article(menu_id)
{
	var checkboxes = document.getElementsByTagName('input');
	for(var i=0; i < checkboxes.length; i++){
		//alert("article_cat_m"+menu_id+"g"+group_id);
		//alert(document.all["article_cat_m"+menu_id+"g"+group_id]);
		if (checkboxes[i].id.indexOf("article_cat_m"+menu_id+"g")!=-1 && checkboxes[i].id.indexOf("_copy")==-1)
		if (checkboxes[i].checked)
			{
			document.getElementById(checkboxes[i].id+"_copy").checked=1;
			//alert('Checked');
			}
	}
}




// Open a popup window to change the object's settings refresh it in db, close it and refresh the main page
function object_setting(user,type,id)
{
//alert("User-"+user+" Type-"+type+" Id-"+id+" Width-"+width+" Height-"+height+" Bgcolor-"+backgroundcolor+" Bgimage-"+backgroundimage);
var params = new Array(1);
    params["user"] = user;
    params["type"] = type;
    params["id"] = id;

    var window_width = 300;
    var window_height = 550;
    var posLeft = screen.width/2 - window_width/2;
    var posTop = screen.height/2 - window_height/2;
    var ParamStr = "dialogLeft:"+posLeft+"px; dialogTop:"+posTop+"px; dialogWidth:"+window_width+"px; dialogHeight:"+window_height+"px; center: yes; help: No; resizable: no; status: no;";
// Call the dialog and wait for results
/*	if (isIE)
    	result = window.showModalDialog("object_settings.php?user="+user+"&type="+type+"&id="+id, params, ParamStr);
    else
    	{*/
    	var attribs = new Array();
    	attribs['height'] = 440;
    	attribs['close'] = 1;
    	showModalDialogDiv("object_settings.php?user="+user+"&type="+type+"&id="+id, attribs, params);
    	//}
if (result != null)
    {
    //window.location="index.php";
    //alert(result["backgroundimage"]);

    var width = result["width"] - result["left_indent"] - result["right_indent"];
    document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.width=result["width"];
    document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.height=result["height"];
    document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundColor=result["backgroundcolor"];
    document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundImage='url(pictures/default/users/kval/'+result["backgroundimage"].toLowerCase()+')';
    //alert(result["background_repeat"]);
    if (result["background_repeat"]=="0")
        document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundRepeat="no-repeat";
    else
        document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundRepeat="repeat";

    //alert(result["backgroundimage"]+'-'+result["backgroundimage"].toUpperCase());
    if (result["backgroundimage"]==result["backgroundimage"].toUpperCase())
        document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundPosition="left top";
    else if (result["backgroundimage"]==result["backgroundimage"].toLowerCase())
        document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundPosition="left bottom";
    else
    	document.getElementById("object_cell_"+result["type"]+'_'+result["id"]).style.backgroundPosition="left center";

    }
}





// TEX EDITOR CALLING FUNCTION FOR ALL PREPARED FIELDS
function text_editor(text_id)
{
if (isIE)
{
/*
var params = Array();
params["sys_path"] = "editor";
params["mode"] = "textarea";
params["width"] = "100%";
params["height"] = "200";
params["lng"] = "eng";
params["title"] = "InteliEditor";
params["value"] = document.all[text_id+"_div"].innerHTML;
params["text_style"]=document.all[text_id+"_div"].currentStyle;
params["page_bgcolor"]=document.all.page_frame_in_design.currentStyle.backgroundColor;
//params["page_bgcolor"]=document.all[text_id].currentStyle.backgroundColor;

    var window_width = 700;
    var window_height = 630;
    var posLeft = screen.width/2 - window_width/2;
    var posTop = screen.height/2 - window_height/2;
    var ParamStr = "dialogLeft:"+posLeft+"px; dialogTop:"+posTop+"px; dialogWidth:"+window_width+"px; dialogHeight:"+window_height+"px; center: Yes; help: No; resizable: No; status: No;";

// Call the dialog and wait for results
result = window.showModalDialog("text_editor.php", params, ParamStr);
if (result)
if (result!=document.all[text_id].value)
    {
    document.all[text_id].value=result;
    document.all[text_id+"_div"].innerHTML = result;
    }
*/

var value = document.getElementById(text_id).value;

// Inheriting text style
var iframe_id = text_id; // Save time :)
global_text_id = text_id;
// document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.innerHTML = '"+document.all[text_id].value+"';
//var do_later ="document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontFamily = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontFamily; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontSize = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontSize; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.color = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).color; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontWeight = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontWeight; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontStyle = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontStyle; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.textDecoration = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).textDecoration; document.getElementById('showModalDialogDivIframe').contentWindow.setTimeout('var text_id = \\'"+text_id+"\\';',10);";
var do_later = "document.getElementById('showModalDialogDivIframe').contentWindow.setTimeout('var text_id = \\'"+text_id+"\\';',10);";

var params = Array();
params["text_id"] = text_id;

var window_width = 700;
var window_height = 630;
var posLeft = screen.width/2 - window_width/2;
var posTop = screen.height/2 - window_height/2;
var ParamStr = "dialogLeft:"+posLeft+"px; dialogTop:"+posTop+"px; dialogWidth:"+window_width+"px; dialogHeight:"+window_height+"px; center: Yes; help: No; resizable: No; status: No;";
result = window.showModalDialog("text_editor_FF.htm", params, ParamStr);
if (result)
if (result!=document.getElementById(text_id).value)
    {
    document.getElementById(text_id).value=result;
    document.getElementById(text_id+"_div").innerHTML = result;
    }
}
// IF NOT IE
else
{
var attribs = new Array();
attribs['width'] = 700;
attribs['height'] = 400;
attribs['close'] = 1;
var value = document.getElementById(text_id).value;

// Inheriting text style
var iframe_id = text_id; // Save time :)
global_text_id = text_id;
// document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.innerHTML = '"+document.all[text_id].value+"';
//var do_later ="document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontFamily = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontFamily; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontSize = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontSize; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.color = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).color; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontWeight = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontWeight; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.fontStyle = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).fontStyle; document.getElementById('showModalDialogDivIframe').contentWindow.document.getElementById('edit').contentWindow.document.body.style.textDecoration = document.defaultView.getComputedStyle(document.all['"+iframe_id+"_div'],null).textDecoration; document.getElementById('showModalDialogDivIframe').contentWindow.setTimeout('var text_id = \\'"+text_id+"\\';',10);";
var do_later = "document.getElementById('showModalDialogDivIframe').contentWindow.setTimeout('var text_id = \\'"+text_id+"\\';',10);";
if (isIE) do_later = "document.getElementById('showModalDialogDivIframe').document.setTimeout('var text_id = \\'"+text_id+"\\';',10);";
//alert(do_later);
if (!isIE) setTimeout(do_later,5000);

//.contentWindow.document.body.innerHTML = value;
showModalDialogDiv("text_editor_FF.htm", attribs, 0);
}
//alert(result);
return;
}





// CHANGING LANGUAGE FOR TRANSLATION
function change_language(lang)
{
	document.forms.lang_form.lang.value=lang;
	document.forms.lang_form.submit();
}



function flashObject(swf, div_id, width, height, version, background_color)
{
if (!document.getElementById(div_id).object_activated)
	{
	var so = new SWFObject(swf, div_id+"_swf", width, height, version, background_color);
	so.write(div_id);
	id2 = div_id.replace(/_div/,"");
	//alert("object_"+id2+"_form");
	var onfocus_id = document.getElementById(div_id).getAttribute("onfocus_id");
	if (onfocus_id != '')
		{
		onfocus_id = onfocus_id.split("_");
		//document.getElementById(div_id+"_swf").onfocus = function () { document.getElementById("object_"+onfocus_id+"_form").submit(); };
		document.getElementById(div_id+"_swf").onfocus = function () { object_config_mode(event,onfocus_id[0], onfocus_id[1]); };
		}
	// Flag that this object was activated and doesn't need it again on main section refresh - otherwise blinks
	document.getElementById(div_id).object_activated = 1;
	}
}


function detectFlashObjects()
{
//var flashObjects = document.all.tags('object');
var flashObjects = document.getElementsByTagName('object');
for (var i=0; i<flashObjects.length; i++)
	{
	div_id = flashObjects[i].id.replace(/_swf/,'');
	swf_src = document.getElementById(div_id).swf_src;
	flashObject(swf_src, div_id, '100%', '100%', 7, '');
	}
}






















///////////////////////////////////////////
// ARTICLE FUNCTIONS AREA
///////////////////////////////////////////

function check()
{
alert(document.getElementById("editor_Field").value);
return;
}

function sumbit_extra_doc_new_menu()
{
document.getElementById("extra_doc_new_menu_form").submit();
alert(document.forms['forma_new_menu'].article_extra_doc_new_menu.value);
return true;
}


// This function checks if there is any checked category for new article
function sumbit_article(object_type,object_id)
{

	var is_checked=0;

	// Do this check only if edited article was called from MAIN section
	// Because in logo, footer and advert there is no need
	var type = document.getElementById('type').value;
	if (object_type=="main" && type!='comment')
	{
	var checkboxes = document.getElementsByTagName('input');
	for(var i=0; i < checkboxes.length; i++)
		 {
		 if (checkboxes[i].id.indexOf("article_cat_m")!=-1 && checkboxes[i].id.indexOf("_copy")==-1 && checkboxes[i].checked)
		  is_checked=1;
		 }
	}
	else {
		if (type=='comment') createCommentHeading();
		is_checked=1;
	}



	if (is_checked){
		// If Article Active mode is 2 (Active in period) check the dates
		if (document.getElementById("article_active_js").value==2){
			 // If New articel "Start" = Today, If "article_to_save"!=0 - mode Edit Article
			 if (check_active_period_date("start") || document.getElementById("article_to_save").value!=0){
				 if (check_active_period_date("finish")){
					//CHECK IF THIS PRODUCT ID ALREADY EXISTS
					if (document.getElementById('article_product_id')){
						 if (document.getElementById('article_product_id').value && document.getElementById('article_product_id').value!=document.getElementById('article_product_id_old').value){
							document.getElementById('article_shop_id_check_iframe').src = 'shop_check_id.php?id=' + document.getElementById('article_product_id').value + '&object=' + object_type + "_" + object_id + "_articles_form";
						} else {
							document.getElementById(object_type+"_"+object_id+"_articles_form").submit();
						}
					} else {
						document.getElementById(object_type+"_"+object_id+"_articles_form").submit();
					}
				} else {alert("Active period finish date can\'t be in past!");}
			} else {alert("Active period start date can\'t be in past!");}
		// If article_active_js!=2 - Article Mode is Active or Deactivated, article is submited without dates checking
		} else {
		 //CHECK IF THIS PRODUCT ID ALREADY EXISTS
		 if (document.getElementById('article_product_id')){
				if (document.getElementById('article_product_id').value && document.getElementById('article_product_id').value!=document.getElementById('article_product_id_old').value){
					document.getElementById('article_shop_id_check_iframe').src = 'shop_check_id.php?id=' + document.getElementById('article_product_id').value + '&object=' + object_type + "_" + object_id + "_articles_form";
				} else {
				document.getElementById(object_type+"_"+object_id+"_articles_form").submit();
				}
			} else {
				document.getElementById(object_type+"_"+object_id+"_articles_form").submit();
			}
		}
	} else {
		alert("Check any of category for new article!");
		return false;
	}
	

}






// This func. submits a form to delete an article
function delete_article(object_type,object_id,article_id)
{
	//alert('Deleting: '+object_type+' '+object_id+' '+article_id);
	
	
	$("#article_delete_form input[name='object_type']").val(object_type);
	$("#article_delete_form input[name='object_id']").val(object_id);
	$("#article_delete_form input[name='article_to_delete']").val(article_id);
	//alert('Deleting: '+object_type+' '+object_id+' '+article_id);
	$("#article_delete_form").submit();
}



function custom_picture_width_toggle()
{
if (document.getElementById("article_picture_width").value=="custom")
    document.getElementById("article_picture_width_custom").style.display="";
else
    document.getElementById("article_picture_width_custom").style.display="none";
}



// This function checks if article active period date is not in the past
function check_active_period_date(id)
{
current_date = new Date();
current_month = current_date.getMonth();
current_month = current_month + 1;
current_day = current_date.getDate();
current_year = current_date.getYear();

if (document.getElementById("active_"+id+"_date_year").value>=current_year)
    {
    if (document.getElementById("active_"+id+"_date_year").value==current_year)
        {
        if (document.getElementById("active_"+id+"_date_month").value>=current_month)
            {
            if (document.getElementById("active_"+id+"_date_month").value==current_month)
                {
                if (document.getElementById("active_"+id+"_date_day").value>=current_day)
                    return 1;
                else return 0;
                }
            else return 1;
            }
        else return 0;
        }
    else return 1;
    }
else return 0;
}

function set_active_start_date_to_current()
{
current_date = new Date();
current_month = current_date.getMonth();
current_month = current_month + 1;
current_day = current_date.getDate();
current_year = current_date.getYear();

// Set Start date to current (minimum logical)
document.getElementById("active_start_date_year").value=current_year;
document.getElementById("active_start_date_month").value=current_month;
document.getElementById("active_start_date_day").value=current_day;

// Set Finish date to current (minimum logical), doing user job
document.getElementById("active_finish_date_year").value=current_year;
document.getElementById("active_finish_date_month").value=current_month;
document.getElementById("active_finish_date_day").value=current_day;
}


// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj) {
		alert(radioObj);
		return;
		}
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		alert(radioObj.value);
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}



// UNFINISHED - there are tree article_active elements
function toggle_period_dates(active_value)
{
document.getElementById("article_active_js").value=active_value;
}

// Previews the article picture (works only for uploaded pictures)
function preview_article_picture()
{
if (document.getElementById("article_picture").value!='none.gif')
    var picture_path = "versions/ver/users/kval/"+document.getElementById("article_picture").value;
else var picture_path = "versions/ver/users/kval/"+'../../default/system/none.gif';
// Local file usage is disabled by modern browsers for security reasons
//if (document.getElementById("article_new_picture").value) picture_path = document.getElementById("article_new_picture").value;
// Safari - onload doesn't work if path is the same (when changing only width in preview)
//!!! THIS LINE "KILLS" SESSION ON SERVER - because it calls "http://justdoubleclick.com" and $_SESSION['user'] takes default ("root" or "folkeweb") name
//!!! document.getElementById("article_picture_preview").src='';
if (document.getElementById("article_picture_preview").getAttribute('src')!=picture_path)
	{
	document.getElementById("article_picture_preview").removeAttribute('src');
	document.getElementById("article_picture_preview").src=picture_path;
	}
document.getElementById("article_picture_text_preview").innerHTML=(isSafari2 ? document.getElementById("picture_text").innerText : document.getElementById("picture_text").value);
// Resize image
preview_article_picture_resize(document.getElementById("article_picture_preview"));
}





// Finishs picture preview on picture load complete!
function preview_article_picture_resize(image)
{
var width = document.getElementById("article_picture_width").value;
if (width=="custom")
    width = document.getElementById('article_picture_width_custom').value;
if (parseInt(width))
    {
    image.width=width;
    image.removeAttribute('height');
    }
}


function more_extra_doc_field()
{
alert(document.getElementById("article_extra_document_0").value);
}


// TOGGLES BUTTON SECTION IN ARTICLE EDIT VIEW
function toggle_article_buttons_sections(section_id)
{
if (section_id!=undefined){
	// If Safari copy text from Iframes to textareas (otherwise it's (new) is lost when iframe is not on screen)
	if (isSafari2) checkTextFields();
	//var sections = new Array("index","picture","document","period","template","email","position","banner","iframe","gallery","product","latest","event");
	var sections = new Array("index","period","template","picture","document","position","email","iframe","gallery","product","latest","blog","event");
	var full_id="article_"+section_id+"_section";

	for (var i=0; i<sections.length; i++)
		 {
		 full_id="article_"+sections[i]+"_section";
		 tab_id="article_"+sections[i]+"_tab";
		 if (document.getElementById(tab_id))
			 {
			 document.getElementById(full_id).style.display="none";
			 document.getElementById(tab_id).style.fontWeight="normal";
			 }
		 }

	full_id="article_"+section_id+"_section";
	tab_id="article_"+section_id+"_tab";
	//alert(full_id);
	document.getElementById(full_id).style.display="";

	//alert(full_id);
	//$('#'+full_id).show();|

	if (document.getElementById(tab_id)) {
		document.getElementById(tab_id).style.fontWeight="bold";
	}
}
}





function read_more(menu_id,group_id,article_id)
{
//alert(menu_id+'-'+group_id+'-'+article_id);
document.getElementById("menu_"+menu_id+"_selected_article_menuid").value=menu_id;
document.getElementById("menu_"+menu_id+"_selected_article_groupid").value=group_id;
document.getElementById("menu_"+menu_id+"_selected_article").value=article_id;
//alert(document.all["menu_"+menu_id+"_selected_article_groupid"].value);
document.getElementById("menu_"+menu_id+"_selected_article_form").submit();
// Delay due to innerHTML fill in
setTimeout('formatCommentInput();',1000);
//alert("Menu:"+document.all["menu_"+menu_id+"_selected_article_menuid"].value+" Group:"+document.all["menu_"+menu_id+"_selected_article_groupid"].value+" Article:"+article_id);
}

function toggle_section_new(section_id) {

/*if (document.getElementById(type+'_section_new').style.display=='none') 
	{document.getElementById(type+'_section_new').style.display='block';} 
else 
	{document.getElementById(type+'_section_new').style.display='none';}*/

// If Safari copy text from Iframes to textareas (otherwise it's (new) is lost when iframe is not on screen)
if (isSafari2) checkTextFields();
//var sections = new Array("index","picture","document","period","template","email","position","banner","iframe","gallery","product","latest","event");
var sections = new Array("product","attachment","period","gallery","iframe","latest");
var full_id=section_id+"_section_new";

for (var i=0; i<sections.length; i++)
     {
     full_id=sections[i]+"_section_new";	 
     if (document.getElementById(full_id))
	     {		 
	     	if (full_id != section_id+"_section_new")
			{
				document.getElementById(full_id).style.display="none";
			}
	     }
     }

var full_id=section_id+"_section_new";

if (document.getElementById(full_id).style.display == "none") 
{
	document.getElementById(full_id).style.display="";
	//alert("Otkrili!");
}
else
{
	document.getElementById(full_id).style.display="none";
	//alert("Zakrili!");
}

}


function toggle_type_new(type,flag)
{
	if (type!='oneliner' && type!='seminar' && type!='product')
	{
		$('#article_heading_tr').hide();
	}
	else
	{
		$('#article_heading_tr').show();

		if (type=='oneliner') {
			$('#seminar_table').hide();
		}
		if (type=='seminar') {
			$('#seminar_table').hide();
		}
		if (type=='product') {
			$('#seminar_table').hide();
		}
	}
	
	if (type=='video') {
		$('#article_video_tr').show();
	}else{
		$('#article_video_tr').hide();
	}

	
	if (type=='basket') {
		$('#article_iframe_url_new_menu').val('shop_index.php');
		$('#article_iframe_url').val('shop_index.php');
	}
	
	var sections = new Array("product","attachment","period","gallery","iframe","latest","table","regform","bmecat","responce","timestamp","adress","calendar","document","note","email","appointment","oneliner","seminar","video","basket");
	var sectionsByRoles = new Array();
	sectionsByRoles["article"] = new Array("attachment","period","responce","timestamp","adress");
	sectionsByRoles["product"] = new Array("attachment","period","product","responce","adress");
	sectionsByRoles["gallery"] = new Array("gallery","period","responce","adress");
	sectionsByRoles["iframe"] = new Array("iframe","period","adress");
	sectionsByRoles["latest_news"] = new Array("latest","period","adress");
	sectionsByRoles["table"] = new Array("table","period","adress");
	sectionsByRoles["regform"] = new Array("regform","period","adress");
	sectionsByRoles["bmecat"] = new Array("bmecat","period","adress");
	sectionsByRoles["calendar"] = new Array("adress","calendar");
	sectionsByRoles["document"] = new Array("adress");
	sectionsByRoles["note"] = new Array("adress");
	sectionsByRoles["email"] = new Array("adress");
	sectionsByRoles["appointment"] = new Array("adress");
	
	sectionsByRoles["oneliner"] = new Array("attachment","period","responce","timestamp","adress","product");
	sectionsByRoles["seminar"] = new Array("attachment","period","responce","timestamp","adress","product");
	
	sectionsByRoles["video"] = new Array("video");
	
	sectionsByRoles["basket"] = new Array("period");

	for (var i=0; i<sections.length; i++)
	{
		full_tab_id=sections[i]+"_section_new";
		full_section_id=sections[i]+"_button_new";
		
		$('#'+full_tab_id).hide();
		$('#'+full_section_id).hide();
		
	}
	
	if (flag=="1"){
		$('#type').val('larticle');
	}else if (type=='basket') {
		$('#type').val('iframe');
	} else {
		$('#type').val(type);
	}

	if (type!="logo" && type!="footer" )
	{
		for (i=0; i<sectionsByRoles[type].length;i++)
		{
			$('#'+sectionsByRoles[type][i]+"_button_new").show();
		}
	}
}



// SWITCHING ON ONLY TABS FOR GIVEN ROLE (ARTICLE OR BANNER)
function toggle_type_flag(type)
{
//                          0        1        2         3          4          5        6        7         8         9        10       11	12
var sections = new Array("index","period","template","picture","document","position","email","iframe","gallery","product","latest","blog","event","video");
var sectionsByRoles = new Array();
sectionsByRoles["article"] = new Array("index","period","template","picture","document","email","product","event");
sectionsByRoles["larticle"] = sectionsByRoles["article"];
sectionsByRoles["logo"] = new Array("picture");
sectionsByRoles["banner"] = new Array("period","document","email","iframe","event");
sectionsByRoles["footer"] = new Array("index","template","picture","event");
sectionsByRoles["iframe"] = new Array("iframe");
sectionsByRoles["gallery"] = new Array("index","gallery");
sectionsByRoles["latest_news"] = new Array("index","latest");
sectionsByRoles["latest_products"] = new Array("index","latest");
sectionsByRoles["oneliner"] = new Array();
sectionsByRoles["product"] = new Array();
sectionsByRoles["blog"] = new Array("index","period","template","picture","document","email","blog","event");
sectionsByRoles["video"] = new Array("index","period","template","picture","document","email","blog","event");
for (var i=0; i<sections.length; i++)
     {
     full_tab_id="article_"+sections[i]+"_section_button";
     full_section_id="article_"+sections[i]+"_section";
     tab_text_id="article_"+sections[i]+"_tab";
     //alert(full_section_id+'-'+full_tab_id);
     if (document.getElementById(full_tab_id))
	     {
	     document.getElementById(full_tab_id).style.display="none";
	     document.getElementById(full_section_id).style.display="none";
	     //alert(document.all[full_section_id]+"-"+full_section_id);
	     document.getElementById(tab_text_id).style.fontWeight="normal";
	     document.getElementById("article_"+sections[i]+"_section_button").className="article_edit_middle_tab";
	     }
     }

document.getElementById("type").value=type;
//alert(type);

for (i=0; i<sectionsByRoles[type].length;i++)
	{
	if (document.getElementById("article_"+sectionsByRoles[type][i]+"_section_button"))
		document.getElementById("article_"+sectionsByRoles[type][i]+"_section_button").style.display="";
	}
if (document.getElementById("article_"+sectionsByRoles[type][0]+"_section_button")) {
	document.getElementById("article_"+sectionsByRoles[type][0]+"_section_button").className="article_edit_first_tab";
}
if (document.getElementById("article_"+sectionsByRoles[type][sectionsByRoles[type].length-1]+"_section_button")) {
	document.getElementById("article_"+sectionsByRoles[type][sectionsByRoles[type].length-1]+"_section_button").className="article_edit_last_tab";
}
toggle_article_buttons_sections(sectionsByRoles[type][0]);
}





function edit_article(object_type,object_id,article_id,article_group)
{
	document.forms.article_edit_form.action+='aid='+article_id+'&';
	document.forms.article_edit_form.object_type.value=object_type;
	document.forms.article_edit_form.object_id.value=object_id;
	document.forms.article_edit_form.article_to_edit.value=article_id;
	document.forms.article_edit_form.article_to_edit_group.value=article_group;
	//return false;
	//alert('aa');
	document.forms.article_edit_form.submit();
}

function toggle_article_larticle(object_type,object_id,role_id)
{
	if (role_id=="article")
    {
    document.forms[object_type+"_"+object_id+"_articles_form"].type.value="article";
    document.getElementById("article_more_text").style.display='none';
    checkTextFields();
    }
else
    {
    document.forms[object_type+"_"+object_id+"_articles_form"].type.value="larticle";
    document.getElementById("article_more_text").style.display='';
    setTimeout("initContenteditableIframe('text');",1000);
    }
}


function testik()
{
alert('ok');
}

// GALLERY FUNCTION TO LIST THE GALLERY (PREV/NEXT)
function gallery_change_image(gallery_id, direction)
{
	var current_image_id = $("#gallery_"+gallery_id+"_current_image_id").val();
	current_image_id = current_image_id * 1;
	var new_image_id = current_image_id + direction;
	if (new_image_id<0) return 0;

	if ($("#gallery_"+gallery_id+"_image_"+new_image_id).length>0){
		gallery_seek_to_image(gallery_id,new_image_id);
	} else {
		return 0;
	}
	

}


// GALLERY FUNCTION THAT DISPLAYS IMAGE AFTER SLIGHT DELAY (BUGFIX)
function gallery_set_image(image_id,image_src)
{
	$("#"+image_id).attr('src',image_src);
}


// GALLERY FUNCTION THAT SEEKS PREVIEW IMAGE TO THE ONE SELECTED FROM THE LIST
function gallery_seek_to_image(gallery_id,image_id)
{

	var new_image_path = $("#gallery_"+gallery_id+"_image_"+image_id).attr('full');
	$("#gallery_"+gallery_id+"_current_image_id").val(image_id);
	//setTimeout("gallery_set_image('gallery_"+gallery_id+"_preview_image','"+new_image_path+"')",1000);
	gallery_set_image("gallery_"+gallery_id+"_preview_image",new_image_path);
	//document.getElementById("gallery_"+gallery_id+"_preview_image_comment").innerHTML = document.getElementById(").innerHTML;
	//$("#gallery_"+gallery_id+"_preview_image_comment").html('aaaaaaaaaaaa');
	$("#gallery_"+gallery_id+"_preview_image_comment").html($("#gallery_"+gallery_id+"_image_"+image_id+"_comment").html());
}



// GALLERY FUNCTION THAT OPEN A POPUP WITH ORIGINAL IMAGE (800x600)
function gallery_open_original_image(image_src, image_com)
{
window.open("gallery_open_image.php?image_src="+image_src+"&image_com="+image_com);
}






// FUNCTIONS FOR FIREFOX TO MAKE EMULATION OF "CONTENTEDITABLE"

function initContenteditableIframe(iframe_id)
{
// Hiding one of objects for direct text editing (for IE or FireFox&Opera)
if (isIE)
	document.getElementById(iframe_id+'_iframe_section').style.display = 'none';
else
	{
	// Check if IFRAME is already initialized
	if (document.getElementById(iframe_id+'_iframe').contentWindow.document.designMode == 'on')
		return;

	// Define if IFRAME is visible on screen. If not then stop execution
	try
		{
		document.getElementById(iframe_id+'_iframe').contentWindow.document.designMode = 'on';
		}
	catch(err)
		{
		//alert("Iframe '"+iframe_id+"' not visible. Error: "+err.description);
		return;
		}

	// Make DIV visible for Mozilla to see it's style and content
	document.getElementById(iframe_id+'_div').style.display = '';
	// Setting text styles to global text settings' styles (can't give class, because it is remote iframe)
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.style.fontFamily = document.defaultView.getComputedStyle(document.getElementById(iframe_id+'_div'),null).fontFamily;
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.style.fontSize = document.defaultView.getComputedStyle(document.getElementById(iframe_id+'_div'),null).fontSize;
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.style.color = document.defaultView.getComputedStyle(document.getElementById(iframe_id+'_div'),null).color;
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.style.fontWeight = document.defaultView.getComputedStyle(document.getElementById(iframe_id+'_div'),null).fontWeight;
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.style.fontStyle = document.defaultView.getComputedStyle(document.getElementById(iframe_id+'_div'),null).fontStyle;
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.style.textDecoration = document.defaultView.getComputedStyle(document.getElementById(iframe_id+'_div'),null).textDecoration;
	document.getElementById(iframe_id+'_iframe').contentWindow.document.body.innerHTML = document.getElementById(iframe_id+'_div').innerHTML;

	document.getElementById(iframe_id+'_div').style.display = 'none';

	if (iframe_id=='heading')
		document.getElementById(iframe_id+'_iframe').contentDocument.addEventListener('blur',getIframeContentHeading,false);
	else if (iframe_id=='ingress')
		document.getElementById(iframe_id+'_iframe').contentDocument.addEventListener('blur',getIframeContentIngress,false);
	else if (iframe_id=='text')
		document.getElementById(iframe_id+'_iframe').contentDocument.addEventListener('blur',getIframeContentText,false);
	else if (iframe_id=='picture_text')
		document.getElementById(iframe_id+'_iframe').contentDocument.addEventListener('blur',getIframeContentPictureText,false);
	}
}

function getIframeContentHeading()
{
getIframeContent("heading");
}

function getIframeContentIngress()
{
getIframeContent("ingress");
}

function getIframeContentText()
{
getIframeContent("text");
}

function getIframeContentPictureText()
{
getIframeContent("picture_text");
}

function getIframeContent(text_id)
{
document.getElementById(text_id).value = document.getElementById(text_id+'_iframe').contentWindow.document.body.innerHTML;
document.getElementById(text_id+'_div').style.display = '';
document.getElementById(text_id+'_div').innerHTML = document.getElementById(text_id+'_iframe').contentWindow.document.body.innerHTML;
document.getElementById(text_id+'_div').style.display = 'none';
}





// BUY PRODUCT
function buy_product(product_id, product_name, price, units, article_id, article_text_id, in_stock)
{
	//alert("Buy prod! - "+product_id+' '+product_name);
	$("#buy_product_form input[name='prod_id']").val(product_id);
	$("#buy_product_form input[name='prod_price']").val(price);
	$("#buy_product_form input[name='prod_name']").val(product_name);
	$("#buy_product_form input[name='prod_ammount']").val((parseInt(units,10) ? parseInt(units,10) : 1));
	$("#buy_product_form input[name='prod_article_id']").val(article_id);
	$("#buy_product_form input[name='prod_in_stock']").val(in_stock);
	
	$("#buy_product_form textarea[name='prod_article_text']").val($('#ingress_'+article_text_id+'_ingress_div').html());
	//alert($('#ingress_'+article_text_id+'_ingress_div').html());
	
	//alert($("#buy_product_form textarea[name='prod_article_text']").val());

	//alert(article_text_id+'_article_text');
	//document.forms['buy_product_form'].prod_article_text.value = document.getElementById(article_text_id).outerHTML;
	//document.forms['buy_product_form'].prod_article_text.value = document.forms['buy_product_form'].prod_article_text.value.replace('id='+article_text_id,'');
	//document.forms['buy_product_form'].prod_article_text.value = document.forms['buy_product_form'].prod_article_text.value.replace('id='+article_text_id+'_buy','style="display:none;"');
	//alert(document.forms['buy_product_form'].prod_article_text.value);
	$("#buy_product_form").submit();
	//alert('Da');
}






var copynum=0;
function changeMain(div_name,src,get_param1,get_param2,get_param3,get_param4,get_param5) {
	
	var xwidth=$("#"+div_name).width();
	var xheight=$("#"+div_name).height();
	var offset=$("#"+div_name).offset();
	var xleft=offset.left;
	var xtop=offset.top;

	
	//$("#"+div_name).attr('disabled','true');
	//div_loading=$("#main_page_loader").clone(true).insertAfter("#main_page_loader");
	
	
	
	copynum++;
	if (copynum>9) copynum=1;
	
	var div_loading="#main_page_loader"+copynum;

	
	if ($(div_loading).is()==true){
	
		//$(div_loading).fadeTo(0, 0);
		
		//alert('width: '+xwidth+'; xheight: '+xheight+'; xleft: '+xleft+'; xtop: '+xtop);
		
		$(div_loading).css("position","absolute");
		$(div_loading).css("border","0px none");
		$(div_loading).css("display","block");
		$(div_loading).css("z-index","5000");
		

		$(div_loading).css("margin-top",$("#"+div_name).css("margin-top"));
		$(div_loading).css("margin-right",$("#"+div_name).css("margin-right"));
		$(div_loading).css("margin-bottom",$("#"+div_name).css("margin-bottom"));
		$(div_loading).css("margin-left",$("#"+div_name).css("margin-left"));
		
		$(div_loading).css("padding-top",$("#"+div_name).css("padding-top"));
		$(div_loading).css("padding-right",$("#"+div_name).css("padding-right"));
		$(div_loading).css("padding-bottom",$("#"+div_name).css("padding-bottom"));
		$(div_loading).css("padding-left",$("#"+div_name).css("padding-left"));
		
		$(div_loading).css("border-top",$("#"+div_name).css("border-top"));
		$(div_loading).css("border-right",$("#"+div_name).css("border-right"));
		$(div_loading).css("border-bottom",$("#"+div_name).css("border-bottom"));
		$(div_loading).css("border-left",$("#"+div_name).css("border-left"));
		
		
		
		$(div_loading).width(xwidth);
		$(div_loading).height(xheight);	
		$(div_loading).css("top",xtop);
		$(div_loading).css("left",xleft);
		

		
		
		
		$(div_loading).fadeTo("fast", 0.60);
	
	}
	//alert(div_loading);
	//putting empty in variable, if not defined
	//if (lasturl==undefined)	lasturl='{$lasturl}';
	
	if (src==undefined)	src='';
	if (get_param1==undefined)	get_param1='';
	if (get_param2==undefined)	get_param2='';
	if (get_param3==undefined)	get_param3='';
	if (get_param4==undefined)	get_param4='';
	if (get_param5==undefined)	get_param5='';
	
	//$("#"+div_name).hide(); 
	if (src!=''){
		var content_show = $(this).attr("title"); //retrieve title of link so we can compare with php file 
		
		$.ajax({
			method: "get",
			url: src,
			//data: "ajax=true&go="+get_go+"&get_param1="+get_param1+"&get_param2="+get_param2+"&get_param3="+get_param3+"&get_param4="+get_param4+"&get_param5="+get_param5+"&lasturl="+lasturl,
			cache: false,
			beforeSend: function(){
				if ($(div_loading).is()==true){
				$(div_loading).show();
				}
			}, //show loading just when link is clicked 
			complete: function(){
				if ($(div_loading).is()==true){
				$(div_loading).hide();
				}
			}, //stop showing loading when the process is complete 
			success: function(html){ //so, if data is retrieved, store it in html 
				$("#"+div_name).show(); //animation 
				
				//$(div_loading).remove();
				if ($(div_loading).is()==true){
					$(div_loading).hide();
				}
				$("#"+div_name).html(html);
				//show the html inside .content div 
				//$("#"+div_name).removeAttr("disabled").focus();
			}
		}); //close $.ajax( 
		//alert(1);
	} else {
		if ($(div_loading).is()==true){
			$(div_loading).fadeOut("slow");
		}
	}
	
}



// Function to emulate AJAX concept
function get_iframe(frame_id)
{
	//alert(frame_id);
	var src=$('#'+frame_id).attr('src');
	
	
	
	if (src!=undefined && src!=''){
		//if (src!='shop_index.php') alert(src);
		//alert($('#'+frame_id).contents().find('body').html());
		$('#'+frame_id+'_div').html($('#'+frame_id).contents().find('body').html());
		//changeMain(frame_id+'_div',src);
	}
}









// Fix for Firefox to work with swapNode
function swapNodes(item1,item2)
{
var itemtmp = item1.cloneNode(1);
var parent = item1.parentNode;
var parent2 = item2.parentNode;
item2 = parent2.replaceChild(itemtmp,item2);
parent.replaceChild(item2,item1);
parent2.replaceChild(item1,itemtmp);
itemtmp = null;
}



function toggle_object(object_id) {
document.getElementById(object_id).style.display = (document.getElementById(object_id).style.display==''?'none':'');
//document.getElementById(object_id).style.display == 'none' ? document.getElementById(object_id).style.display = 'block': document.getElementById(object_id).style.display = 'none';
}




// Show hidden Xtender screen elements that are used to help IE understand complex colspan and rowspan tables
function toggle_object_titles()
{
var cells = document.getElementsByTagName('DIV');
var show_titles = 0;
for (var i = 0; i<cells.length; i++)
	{
	// Show each objects title
	if (cells[i].id.indexOf("object_cell_title_") != -1)
		{
		cells[i].style.display = (cells[i].style.display=='' ? 'none' : '');
		show_titles = (cells[i].style.display=='' ? 1 : 0);
		}
	}

var cells = document.getElementsByTagName('TD');
for (var i = 0; i<cells.length; i++)
	{
	// Show each objects border
	var re = new RegExp("object_cell_[a-z]+_[0-9]+");
	if (cells[i].id.match(re))
		{
		cells[i].style.border = (show_titles ? '3px solid red' : '0px solid red');
		cells[i].style.borderStyle = 'solid';
		}
	}
}



// in the beginning -
var picture_directory = "versions/ver/users/kval";
var logo_image_name;
var background_image_name = "background.jpg";
/* VOT GOVNO! V IE eta funkcija ne vizivaets'a pri onclick="change_logo_image('logo','background'); all_articles_view(0,3,0,0);"
function change_logo_image(logo_imagename, background_imagename)
{
// Put image_name value to a form for submiting category change request
if (logo_imagename) document.getElementById('change_logo_image').value=logo_imagename;
if (background_imagename) document.getElementById('change_background_image').value=background_imagename;
}
*/

function changeLogoImage(logo_imagename, background_imagename)
{
// Put image_name value to a form for submiting category change request
if (logo_imagename) document.getElementById('change_logo_image').value=logo_imagename;
if (background_imagename) document.getElementById('change_background_image').value=background_imagename;
}








var todayDateColor = 'yellow';
var eventDateColor = 'salmon';
var eventArticleDateColor = 'lightgreen';

var multiselect_calendar;







// Function to fix IE problem of incorrectly expanding <table> cells
function correct_ie_table_height()
{
	// Disabled because of errorous functionality
	return;
	//
	
//alertDebug("correct_ie_table_height");
// Do nothing for Firefox - he is perfect enought
if (window.navigator.appName.indexOf('Microsoft')==-1) return;

var main_cell_id = "object_cell_main_0";
//var main_height = document.getElementById(main_cell_id).clientHeight;
var main_height = parseInt(document.getElementById(main_cell_id).clientHeight,10);
var main_rowspan = document.getElementById(main_cell_id).rowSpan;
var main_row = document.getElementById(main_cell_id).parentNode;
var main_row_index = main_row.sectionRowIndex;
var current_row = null;
var cell = null;
var c_index = 0;
// Array to calculate knows heights of cells
var heights = new Array (10);
for (var i=0; i < heights.length; i++)
	heights[i] = new Array (10);

if (!found_cell)
// Go by rows (top-to-bottom)
for (var rows=0; rows < main_rowspan; rows++)
	{
	current_row = main_row.parentNode.rows(main_row_index+rows);
	for (var cells=0; cells < current_row.cells.length; cells++)
		{
		cell = current_row.cells(cells);
		// Set height to 0 (false) for cells under current if rowspan was given
		if (cell.rowSpan)
			for (var l=1; l<cell.rowSpan; l++)
			// !!! SET IT TO SAME HEIGHT VALUE AS CELL WITH THIS ROWSPAN
				heights[rows+l][cells] = 0;
		c_index = 0;
		// Find first free cell (depends on rowspans)
		while(typeof(heights[rows][c_index])!="undefined")
			{
			c_index++;
			}
		if (cell.style.height!="")
			{
			heights[rows][c_index] = parseInt(cell.style.height,10)+parseInt(cell.style.paddingTop,10)+parseInt(cell.style.paddingBottom,10);
			//heights[rows][c_index] = parseInt(cell.currentStyle.height,10)-parseInt(cell.currentStyle.paddingTop,10)-parseInt(cell.currentStyle.paddingBottom,10);
			}
		else if (cell.id!="main")
			{
			var found_cell = cell;
			var found_cell_cellIndex = c_index;
			//alertDebug("Found cell: "+found_cell.id+"<br>Found cell Index:"+found_cell_cellIndex);
			// Unset height for this cell, because it affects Main section clientHeight
			found_cell.removeAttribute('height');
			// Recalculate Main section clientHeight
			//main_height = parseInt(document.getElementById(main_cell_id).clientHeight,10)+parseInt(document.getElementById(main_cell_id).style.paddingTop,10)+parseInt(document.getElementById(main_cell_id).style.paddingBottom,10);
			main_height = parseInt(document.getElementById(main_cell_id).clientHeight,10);
			}
		}
	}

// Set cells "height" where "style.height" is not set
if (found_cell)
	{
	var height_sum = 0;
	for (var rows=0; rows < main_rowspan; rows++)
		{
		//if (heights[rows[found_cell_cellIndex]])
		if (heights[rows][found_cell_cellIndex])
			height_sum += heights[rows][found_cell_cellIndex];
		}
	found_cell.height = (main_height-height_sum-parseInt(found_cell.style.paddingTop,10)-parseInt(found_cell.style.paddingBottom,10))+"px";
	//alert(found_cell.id+'-'+found_cell.height);
	}
/*
var content = '';
for (var k = 0; k<heights.length; k++)
	{
	for (var l = 0; l<heights[k].length; l++)
		{
		typeof(heights[k][l])=='undefined' ? content += "-\t" : content += heights[k][l]+"\t";
		}
	content += "\n";
	}
//alert(content+"\nFound height: main_height("+main_height+")-height_sum("+height_sum+")=found_height("+found_cell.height+")");
*/
}



// Copies content of ContentEditable div tag to a textarea
function copy_contenteditable(text_id)
{
var text_div = document.getElementById(text_id+'_div');
if (!isIE)
{
// Specialy for Safari 2 determine if iframe is on screen for copying
try
	{
	var text_iframe = document.getElementById(text_id+'_iframe').contentWindow.document.body;
	}
catch (err)
	{
	return;
	}
document.getElementById(text_id+'_div').innerHTML = text_iframe.innerHTML;
}
document.getElementById(text_id).value = text_div.style.display=='' ? text_div.innerHTML : text_iframe.innerHTML;
// Safari 2 fix: it can't see object if it's display:none and .value is accessible only by .innerText
if (isSafari2)
	{
	document.getElementById(text_id).style.display = "inline";
	document.getElementById(text_id).innerText = text_div.style.display=='' ? text_div.innerHTML : text_iframe.innerHTML;
	document.getElementById(text_id).style.display = "none";
	}
}


// Function to ckeck if HTML mode was on (turn off) and copy all text fields to textarea
function checkTextFields()
{
/*var text_fields = new Array('heading','text','ingress','picture_text');
for (var i = 0; i<text_fields.length; i++)
	{
	if (isIE && document.getElementById(text_fields[i]+"_div").style.fontFamily == 'Courier New, Source')
		{
		reditor_current_div_field = text_fields[i]+"_div";
		toggleRasamaxEditorSourceCode();
		if (isIE) document.getElementById(text_fields[i]+"_div").blur();
		}
	// In isIE case content os copied onbeforedeactivate
	if (isSafari2 || isSafari3)
		copy_contenteditable(text_fields[i]);
	}
*/
return true;
}


function fixButtonTagInSafari()
{
if (!isSafari2 && !isSafari3) return;
var buttons = document.getElementsByTagName('BUTTON');
for (var i=0; i<buttons.length; i++)
	{
	buttons[i].style.paddingLeft = 0;
	}
}


function printVersion(article_id)
{
window.open('print.php?sid='+document.getElementById('php_session_id').value+'&aid='+article_id);
}


function alertDebug(debug_string)
{
document.getElementById('alertDebugWindow').innerHTML += debug_string+'<br>';
}


function object_config_mode(event,object_type, object_id)
{
var parents = '';
var parNode;
var curNode = (isFirefox && !isSafari3 ? event.originalTarget : event.srcElement);
var clear = 1;
while (curNode != document.body)
	{
	parNode = curNode.parentNode;
	parents += ' < '+parNode.id;
	curNode = parNode;
	if (parNode.id=='shop_basket_div') clear = 0;
	}
//alert('SrcElement '+event.srcElement.tagName + ' Parents\' ids:' + parents);
// If no exception was met
if (clear)
	{
	document.getElementById("config_mode_for").value = object_type+'_'+object_id;
	document.forms["object_config_mode_form"].submit();
	}
}



// Function that makes click() method for <A> elements come true
function fixMozillaClickMethod()
{
var anchors = document.getElementsByTagName('A');
var a;
for (var i=0; i<anchors.length; i++)
	{
	a = anchors[i];
	if (a && typeof(a.click) == 'undefined') {
	    a.click = function() {
	        var result = true;
	        if (a.onclick) result = a.onclick();
	        if (typeof(result) == 'undefined' || result) {
	            //eval(a.href);
	            this.onclick();
	        }
	    }
	}
	}
}



function formatCommentInput()
{
//document.getElementById("ingress").style.height = 100+"px";
//tinyMCEinit("ingress", "simple_top","article_text");
}

function createCommentHeading()
{
document.getElementById('heading').value = document.getElementById('comment_owner').value+'(<a href="mailto:'+document.getElementById('comment_owner_email').value+'">@</a>)';
}

function deleteComment(id)
{
if (confirm('Delete comment?'))
	{
	ajax('delete_article.php','aid='+id+'&at=comment',removeCommentFromScreen);
	}
}

function removeCommentFromScreen(id)
{
id = id + '_comment_body';
var elem = document.getElementById(id);
var parent = document.getElementById(id).parentNode;
parent.removeChild(elem);
}


function ajax(url, vars, callbackFunction){
        var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
        request.open("POST", url, true);
        request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        request.onreadystatechange = function(){
                if (request.readyState == 4 && request.status == 200) {
                        if (request.responseText){
                        		//alert(request.responseText);
                                callbackFunction(request.responseText);
                                // Run <script> from response
								var re = /<script.*?>(.*?)<\//igm;
								var match;
								while (match = re.exec(request.responseText))
									{
									eval(match[1]);
									}
                        }
                }
        };
        request.send(vars);
}

function ajax_object_setting(user,type,id,mode)
{
	var add_param = "";
	var add_param2 = "iframe1";
	if (mode == "edit") add_param = "&mode=edit";
	else if (mode == "menu4db") add_param2 = "iframe12";
	var string = '<iframe id="object_settings_iframe" name="object_settings_iframe" class="'+add_param2+'" frameborder="0" scrolling="no"  src="object_settings_iframe_new.php?user='+user+'&type='+type+'&id='+id+add_param+'"></iframe>';
	document.getElementById("object_settings_div").innerHTML = string;
}
function ajax_advanced_setting(menu_id,categ_id)
{
	var string = '<iframe name="advanced_settings_iframe" class="iframe2" frameborder="0" scrolling="no" src="group_adv_set_iframe.php?menu_id='+menu_id+'&categ_id='+categ_id+'"></iframe>';
document.getElementById("advanced_settings_div").innerHTML = string;
}

function show_hide_new_row () {
	if (document.getElementById("start_new_row").checked)
	{
		document.getElementById("a_to_row").style.display = 'block';
		document.getElementById("start_new_row_2").checked = true;
	}
	else
	{
		document.getElementById("a_to_row").style.display = 'none';
		document.getElementById("start_new_row_2").checked = false;
	}
}

