function pop_up(id, width, height, toolbar){
  if(id == "" || id == null) {
    return;
  }       
  if (width == "" || width == null || height == "" || height == null) {
    width = 800;
    height = 600;
  }
  if(toolbar=="") toolbar="no";
  wx = (screen.width-width)/2;
  wy = (screen.height-height)/2;
  wnd=window.open(id,"_blank", "width="+width+",height="+height+",status=no,resizable=1,scrollbars=1,toolbar="+toolbar+",menubar=no, left="+wx+",top="+wy);
}
function close_self(){
  if(window.opener){
    window.opener.location.reload();    
  }
  window.close();
}
function close_control(location){
  if(window.opener){
    window.opener.location=location;    
  }
  window.close();
}

opened=1;
function down(){
  if(opened){
    document.all['toolbal'].style.left=document.all['toolbal'].clientWidth-50;
    opened=0;
  }else{
    document.all['toolbal'].style.left=0;
    opened=1;
  }
}
function CheckContent(form){
  try{
    for(i=0;i<document.forms.length;i++){
      elements=document.forms[i].elements;
      j=0;
      while(elements[j]){
        try{
          updateRTE(elements[j].name);
          place=document.getElementById('placeholder_for_'+elements[j].name);
          elements[j].name
          place.value=elements[j].value;
          
        }catch(e){
        }
        j++;
      }
    }
    return true;
  }catch(e){
    alert(e.message);
    return false;
  } 
}
function AskModal(Quest){
  return confirm (Quest);
}
/*Cookie*/
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if(begin == -1) {
    begin = dc.indexOf(prefix);
    if(begin != 0)
      return null;
  }else 
    begin += 2;

  var end = document.cookie.indexOf(";", begin);
  if (end == -1)end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*ORDERING*/
function move_up(obj){
  try{       
    prev=obj.parentNode.previousSibling;
    curr=obj.parentNode;
    if(prev){
      for(i=0;i<curr.childNodes.length-2;i++){
        val=curr.childNodes.item(i).innerText;
        curr.childNodes.item(i).innerText=prev.childNodes.item(i).innerText;
        prev.childNodes.item(i).innerText=val;
      }
    }
  }catch(e){
    alert(e.message);
  }   
}
function move_down(obj){
  try{
    next=obj.parentNode.nextSibling;
    curr=obj.parentNode;
    if(next){
      for(i=0;i<curr.childNodes.length-2;i++){
        val=curr.childNodes.item(i).innerText;
        curr.childNodes.item(i).innerText=next.childNodes.item(i).innerText;
        next.childNodes.item(i).innerText=val;
      }
    }
  }catch(e){
    alert(e.message);
  }   
}

function get_ordering(form){
  text="";
  try{
    order=1;
    for(i=0;i<document.all.length;i++){
       if(document.all.item(i).className=="grape_ordering_id"){
         text=text+document.all.item(i).innerText+"="+order+++";";
       }
    }     
    document.all['order_list'].value=text;
    return true;
  }catch(e){
    alert(e.message);
    return false;
  }   
}

function object_move_to(id){
  try{
    document.forms["move"].move_to.value=id;
    document.forms["move"].submit();
  }catch(e){
    alert(e.message);
  }   
}

function ret_selected(element){
  url="";
  title="";
  form=element.form;
  try{
    elements=form.elements;
    for(i=0;i<elements.length;i++){
      if(elements[i].checked){
        url=elements[i].value;
        title=elements.elements[url].value;
      }
    }
    if(url!=""){
      window.opener.navigator_call_back(url,title);
      window.close();
    }else{
      alert("No page selected!");
      return false;
    }
  }catch(e){
    alert(e.message);
  }
}

function navigator_call_back(url,title){
  try{
    form=window.document.forms[0];
    form["url"].value=url;
    form["navigator_but"].value=title;
  }catch(e){
    alert(e.message);
  }
}
function switch_system(){
  if(document.all.system.style.display==""||document.all.system.style.display=="none"){
    document.all.system.style.display="block";
  }else{
    document.all.system.style.display="none";
  }
}
