function absolute(value)
{
    if (value < 0) return -value;
    return value;
}
function popupwnd(url, targ, width, height, centerwnd){
 var param = 'width='+width + ',height='+height + ',toolbar=no,location=no,scrollbars=yes,menubar=no,status=no,resizable=yes';
 if (centerwnd && !(navigator.userAgent.indexOf('Opera')>=0)){
     param += ",left=" + ((screen.width - width)/2) + ",top=" + ((screen.height-height)/2);
 } else {
     if (centerwnd){         
         param += ",left=" + ((screen.width - width)/2) + ",top=" + (absolute(window.innerHeight-height)/2);
     }
 } 
 var popupWin = window.open(url, targ, param);
 popupWin.focus();
}

function ifdisabled(v, someid)
{
   someobj = document.getElementById(someid);
   if(v.checked)
	someobj.disabled=false;
   else
	someobj.disabled=true;		
}
var current = '';
var menu_timer = null;
var menu_hide_timeout = 100;
var menu_show_timeout = 105;
function switch_sub_menu(id, show){
 if(menu_timer){ window.clearTimeout(menu_timer); }
 if(current.length>0 && show){
  tmp = document.getElementById(current);
  if(tmp){
   if(current == id){
    tmp.style.visibility = 'visible';
   }else{
    tmp.style.visibility = 'hidden';
    current = '';
   }
  }
 }
 if(!document.getElementById(id)){ return; }
 current = id;
 menu_timer = show?
 	window.setTimeout("set_visibility('"+id+"', true)", menu_show_timeout):
	window.setTimeout("set_visibility('"+id+"', false)", menu_hide_timeout);
}
function set_visibility(id, show){
 document.getElementById(id).style.visibility = show?'visible':'hidden';
 if(!show && current==id){ current = ''; }
}

function openURL(){
  var url=document.getElementById('url').value;
  if(url!='http://' && url!='') {
      //popupwnd(url, targ, width, height, centerwnd)
  	var win = window.open(url,'','toolbar=yes,location=yes,scrollbars=yes,menubar=yes,status=yes,resizable=yes');
  	win.focus();
  }
}
function previewImg(src, filename, path) {
	document.images['preview_img'].src = src;
	document.images['preview_img'].alt = filename;
	document.getElementById("filename").innerHTML = filename;
	document.getElementById("selected_image_popup").value = path + filename;
	document.getElementById("button").style.visibility = 'visible';
}
function insertImg(_par_num) {
	window.opener.document.getElementById('selected_image' + _par_num).value = document.getElementById("selected_image_popup").value;
	window.opener.document.getElementById('is_image_selected' + _par_num).value = 1;
	window.close();    	
}
function clearImg(_par_num) {
	 document.getElementById("selected_image" + _par_num).value = '';
	 document.getElementById("is_image_selected" + _par_num).value = 0;
}

function displayTab(tabToDisplayName, tabToHideName){
    document.getElementById(tabToDisplayName).style.visibility = 'visible';
    document.getElementById(tabToHideName).style.visibility = 'hidden';
    document.getElementById(tabToDisplayName+'_menu').style.background = '#FFFFFF';
    document.getElementById(tabToHideName+'_menu').style.background = '#FFFFCC';
}
function select_onclick_handler(id){
    var element = document.getElementById(id);
    if (element.selectedIndex != -1)     
    eval("element.form."+ id +"_single.value =  element.options[element.selectedIndex].text");
}

function chimg(i) {
    if (i != ""){
	   document.images['random_image'].src = i;
    }
}
function change_language(url){
	if(confirm('Do you want to save the changes made on the current page?')){
		document.getElementById('redirect').value = url;
		document.getElementById('redirect').form.submit();
    } else
    {
    	window.location.href = url;
    }
}
function insertDir(path) {
	window.opener.document.getElementById('selected_dir').value = path;
	window.close();    	
}
function CheckAll(field, val) {
    var i = 1;
    while (obj = document.getElementById(field+'_'+i)) {
       obj.checked = val;
       i++;
    }
}