/******************************************************************************
 WEBANKO: Web Application NKO
-------------------------------------------------------------------------------

 webanko.js: Código JS para Webanko

 + 2007-03-11: Porte y modernización del código de SWAS

-------------------------------------------------------------------------------
 by TXiNo (J. Fernando Moyano) - txino@evolus.net
******************************************************************************/

function wbnk_open(p,w,h) {
 if (!w) w=720;
 if (!h) h=600;
 var winname="window_"+p;
 winname=winname.replace(/\.|\//g,'_');
 nw=window.open("/wbnk.php?"+p,winname,"scrollbars=yes,width="+w+", height="+h);
 nw.focus();
}

function wbnk_open_template(t,w,h) {
 if (!w) w=720;
 if (!h) h=600;
 var winname="window_"+t;
 winname=winname.replace(/\.|\//g,'_');
 nw=window.open('',winname,"scrollbars=yes,width="+w+", height="+h);
 with(document.swal_form) {
  target=winname;
  var taux=template.value;
  template.value=t;
  submit();
  target="";
  template.value=taux;
 }
 nw.focus();
}

function wbnk_ajax_template(t,params,id,myform,cb) {
 return ajax_load_post("/wbnk.php?template="+t+'&'+params,id,myform,cb);
}

function wbnk_open_admin(t,w,h) {
 if (!w) w=720;
 if (!h) h=600;
 var winname="window_"+t;
 winname=winname.replace(/\.|\//g,'_');
 nw=window.open('',winname,"scrollbars=yes,width="+w+", height="+h);
 with(document.swal_form) {
  target=winname;
  if (t.match(/admin\/autoform\.swal/)) {
   var params=t.split(':');
   t=params[0];
   tables.value=params[1];
   keys.value=params[2];
   rows.value=params[3];
   indexes.value=params[4];
  } else {
   tables.value=keys.value=rows.value=indexes.value="";
  }
  template.value=t;
  submode.value="";
  section_id.value="";
  condition.value="";
  submit();
  target="";
 }
 nw.focus();
}


/*
function wbnk_open_admin(t,w,h) {
  if (!w) w=700;
  if (!h) h=600;
  var afp="";
  if (t.match(/admin\/autoform\.swal/)) {
   var params=t.split(':');
   t=params[0];
   afp="&tables="+params[1]+"&keys="+params[2]+"&rows="+params[3];
  }
  u="/wbnk.php?template="+t+"&submode=&section_id=&condition="+afp;

  var winname="window_"+t;
  winname=winname.replace(/\.|\//g,'_');
  window.open(u,winname,"scrollbars=yes,width="+w+", height="+h);
}
*/

/*----------------------------------------------*/

function wbnk_login(f) {
 with(document.wbnk_form) {
  user_name.value=f.user_name.value;
  user_passwd.value=f.user_passwd.value;
  submit();
 }
}

function wbnk_logout(sid) {
 with(document.wbnk_form) {
  user_name.value="logout";
  user_passwd.value="logout";
  if (sid) { 
   section_id.value=sid;
   body.value='';
  } 
  submit();
 }
}

function wbnk_set_locale(loc) {
 with (document.wbnk_form) {
  locale.value=loc;
  submit();
 }
}

function wbnk_edit_mode(em) {
 with (document.wbnk_form) {
  edit_mode.value=em;
  submit();
 }
}

function wbnk_set_body(src) {
 with (document.wbnk_form) {
  body_steps.value=0;
  if (src==body.value) return;
  _body.value=body.value;
  body.value=src;
 }
}

function wbnk_back() {
 var steps=document.wbnk_form.body_steps.value;
 if (steps>0) steps=-steps;
 else steps=-1;
 history.go(steps);
}

function wbnk_back_body(default_body) {
 with (document.wbnk_form) {
  if (_body.value) {
   body.value=_body.value;
   _body.value='';
  } else if (default_body) body.value=default_body;
  submit();
 }
}

function wbnk_load_body(src) {
 with (document.wbnk_form) {
  wbnk_set_body(src);
  section_id.value="";
  content_id.value="";
  submit();
 }
}

function wbnk_load_section(sid,src) {
 with (document.wbnk_form) {
  if (sid) section_id.value=sid;
  if (!src) src="";
  wbnk_set_body(src);
  content_id.value="";
  submit();
 }
}

function wbnk_load_content(cid) {
 with (document.wbnk_form) {
  wbnk_set_body("wtmbrg/full.swal");
  content_id.value=cid;
  submit();
 }
}


function wbnk_popup_show(did,u,f) {
 if (!did) did="wbnk_popup";
 if (u) ajax_load_post(u,did,f);
 set_display(did,"block");
 $("#layout").css("opacity","0.3");
}

function wbnk_popup_hide(did) {
 if (!did) did="wbnk_popup";
 set_display(did,"none");
 $("#layout").css("opacity","1.0");
}

/* Admin: ----------------------------------------------*/

function wbnk_open_admin_section(sid) {
 with (document.swal_form) {
  if (sid) condition.value="sections.id='"+sid+"'";
  else condition.value="";
  submode.value="UPDATE";
 }
 wbnk_open_template("admin/sections_form.swal");
}

function wbnk_open_admin_contents(sid) {
 with (document.swal_form) {
  if (sid) condition.value="contents.section_id='"+sid+"'";
  else condition.value="";
  submode.value='';
 }
 wbnk_open_template("admin/contents_form.swal");
}

function wbnk_open_admin_content(cid) {
 with (document.swal_form) {
  if (cid) condition.value="contents.id='"+cid+"'";
  else condition.value="";
  submode.value="UPDATE";
 }
 wbnk_open_template("admin/contents_form.swal");
}

function wbnk_delete_content(cid) {
 if (!confirm("¿Estás seguro de que deseas eliminar el contenido?")) return;
 with (document.wbnk_form) {
  command.value="WTMBRG_DELETE_CONTENT";
  content_id.value=cid;
  submit();
 }
}

function wbnk_block_select_content_dialog(bid,pos,os,cid,fid) {
 with(document.swal_form) {
  block_i.value=bid;
  block_pos.value=pos;
  block_offset.value=os;
  content_id.value=cid;
  format_id.value=fid;
 }
 wbnk_open_template("wtmbrg/select_content_dialog.swal",640,200);
}

function wbnk_block_select_content(bid,pos,os,cid,fid) {
 with(document.wbnk_form) {
  command.value="WTMBRG_BLOCK_SET_CONTENT";
  block_i.value=bid;
  block_pos.value=pos;
  block_offset.value=os;
  content_id.value=cid;
  format_id.value=fid;
  submit();
 }
}

function wbnk_block_void_content(bid,pos) {
 if (!confirm("¿Estás seguro de que deseas quitar el contenido?")) return;
 with(document.wbnk_form) {
  command.value="WTMBRG_BLOCK_VOID_CONTENT";
  block_i.value=bid;
  block_pos.value=pos;
  submit();
 }
}

function wbnk_block_void(bid) {
 if (!confirm("¿Estás seguro de que deseas vaciar el bloque?")) return;
 with(document.wbnk_form) {
  command.value="WTMBRG_BLOCK_VOID";
  block_i.value=bid;
  submit();
 }
}

//*****************************************************************************
