/**
 * muntilan package
 * 
 * @author donna iwan setiawan
 * @version 1 
 * copyright - (c) 2007 - 2010 donna iwan setiawan
 * license - GPL version 3 or any later version <http://www.gnu.org/licenses/gpl-3.0.txt>
 */
doi.muntilan={input:{},list:{},search:{},header:{},_qLabel:"q",session:{timer:null,time:3600},_ajax_timeout:60000,btoa:function(i){var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var e=[];var h=0;while(h<i.length){var m=i.charCodeAt(h++);var l=i.charCodeAt(h++);var k=i.charCodeAt(h++);var a=(m<<16)+((l||0)<<8)+(k||0);var g=(a&(63<<18))>>18;var f=(a&(63<<12))>>12;var d=isNaN(l)?64:(a&(63<<6))>>6;var b=isNaN(k)?64:(a&63);e[e.length]=j.charAt(g);e[e.length]=j.charAt(f);e[e.length]=j.charAt(d);e[e.length]=j.charAt(b)}return e.join("")},atob:function(i){var j="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var g={strlen:(i.length%4!=0),chars:new RegExp("[^"+j+"]").test(i),equals:(/=/.test(i)&&(/=[^=]/.test(i)||/={3}/.test(i)))};if(g.strlen||g.chars||g.equals){throw new Error("Invalid base64 data")}var n=[];var h=0;while(h<i.length){var f=j.indexOf(i.charAt(h++));var e=j.indexOf(i.charAt(h++));var d=j.indexOf(i.charAt(h++));var b=j.indexOf(i.charAt(h++));var a=(f<<18)+(e<<12)+((d&63)<<6)+(b&63);var m=(a&(255<<16))>>16;var l=(d==64)?-1:(a&(255<<8))>>8;var k=(b==64)?-1:(a&255);n[n.length]=String.fromCharCode(m);if(l>=0){n[n.length]=String.fromCharCode(l)}if(k>=0){n[n.length]=String.fromCharCode(k)}}return n.join("")}};doi.muntilan.refresh=function(){var b=new doi.dom.request(unescape(window.location.pathname));b.remove(["_ajax","_modal"]);b.remove(["_ajax","_modalbox"]);var a=b.toString();if(window.location.reload){window.location.reload(false)}else{if(window.location.replace){window.location.replace(a)}else{window.location.href=a}}};doi.muntilan.modalBox=function(){var a=null;if(doi.widget.modalBox2&&doi.widget.modalBox2.visible()){a=doi.widget.modalBox2}else{if(doi.widget.modalBox1&&doi.widget.modalBox1.visible()){a=doi.widget.modalBox1}else{if(doi.widget.modalBox&&doi.widget.modalBox.visible()){a=doi.widget.modalBox}}}return a};doi.muntilan.header.insert=function(a){var b=doi.muntilan.modalBox();if(b){b.show(a)}else{location.href=a}};doi.muntilan.list.del=function(d,b,a){var g=doi.dom.$("tag:input;type=checkbox;id="+b);var h=[];for(var e=0;e<g.length;e++){if(g[e].checked){h.push(g[e].value)}else{if(g[e].value==a){h.push(a)}}}var f;if(h.length>0){f=b+"="+doi.muntilan.btoa(h.join("|"))}else{f=b+"="+doi.muntilan.btoa(a)}doi.widget.modalBox.show({url:d,method:"post",data:f});return false};doi.muntilan.list.link_onclick=function(a,c){var b=doi.widget.instance.get("muntilan-tab-id");if(b){b.tabFocus(0)}doi.widget.loaderBox.show({show:doi.muntilan.list.refresh,hide:function(){}},{url:a+"&_ajax=list",ids:c})};doi.muntilan.list.action=function(a){var c=doi.muntilan.modalBox();if(c){c.show(a)}else{if(location.href==a){var b=doi.widget.instance.get("muntilan-tab-id");if(b){b.tabFocus(1)}}else{location.href=a}}return false};doi.muntilan.input.cancel=function(a){var b=doi.muntilan.modalBox();if(b){if(!b.back()){b.hide()}}else{location.href=a}};doi.muntilan.input.submit=function(b,a){var c=doi.muntilan.modalBox();if(c){if(!a){return true}if(a=="ajax"){doi.ajax.request("post",b.action,{success:function(d){c.show({url:d.responseText,type:"html"})},failure:function(d){alert("Last Action Failed.")},data:b,timeout:doi.muntilan._ajax_timeout});return false}else{return doi.iAjax.submit(b,{success:function(d){c.show({url:d,type:"html"})}})}}else{return true}};doi.muntilan.list.sortable=function(c){if(sorttable){var b=doi.dom.get("class:sortable",c);if(b){for(var a in b){if(b.hasOwnProperty(a)){sorttable.makeSortable(b[a])}}}}};doi.muntilan.list.refresh=function(data){var url=data.url;var listId=data.ids.listId;var inputId=data.ids.inputId;doi.ajax.request("get",url,{timeout:doi.muntilan._ajax_timeout,success:function(req){var content=false;var modalBox=doi.muntilan.modalBox();if(modalBox){content=modalBox.element("content")}var listElm=doi.dom.$("#"+listId,content);var inputElm=doi.dom.$("#"+inputId,content);var tmpContainer=document.createElement("div");tmpContainer.innerHTML=req.responseText;var listTagElms=doi.dom.$("tag:div;title=doilist",tmpContainer);var inputTagElms=doi.dom.$("tag:div;title=doiinput",tmpContainer);var lastVisitTagElms=doi.dom.$("tag:div;title=doilastvisit",tmpContainer);if(lastVisitTagElms){if(lastVisitTagElms[0].childNodes&&lastVisitTagElms[0].childNodes[0]&&lastVisitTagElms[0].childNodes[0].nodeName=="SCRIPT"){eval(lastVisitTagElms[0].childNodes[0].innerHTML)}else{doi.dom.execScript(lastVisitTagElms[0])}}if(listElm){var height=listElm.offsetHeight;var divx=document.createElement("div");if(listTagElms&&listTagElms[0]){divx.innerHTML=listTagElms[0].innerHTML}var timer=false;var opacity=10;if(!timer){timer=window.setInterval(function(){opacity--;doi.dom.style(listElm,"opacity:"+opacity);if(opacity<=0){window.clearInterval(timer);opacity=0;if(divx.childNodes[0]&&divx.childNodes[0].id==listId){var parent=listElm.parentNode;var newListElm=divx.childNodes[0];parent.replaceChild(newListElm,listElm);listElm=newListElm;doi.dom.style(listElm,"opacity:0")}else{listElm.innerHTML=req.responseText}timer=window.setInterval(function(){opacity++;doi.dom.style(listElm,"opacity:"+opacity);if(opacity>=10){window.clearInterval(timer);timer=false;doi.widget.render();doi.dom.execScript(listElm);var modalbox=doi.muntilan.modalBox();if(modalbox){modalbox.resize()}doi.muntilan.list.sortable(listElm);doi.widget.loaderBox.hide()}},10)}},10)}}if(inputElm&&inputTagElms){var height=inputElm.offsetHeight;var div=document.createElement("div");if(inputTagElms&&inputTagElms[0]){div.innerHTML=inputTagElms[0].innerHTML}if(div.childNodes[0]&&div.childNodes[0].id==inputId){var input=div.childNodes[0].innerHTML}else{var input=div.innerHTML}if(input=="false"){return}var timer2=false;var opacity2=10;if(!timer2){timer2=window.setInterval(function(){opacity2--;doi.dom.style(inputElm,"opacity:"+opacity2);if(opacity2<=0){window.clearInterval(timer2);opacity2=0;if(div.childNodes[0]&&div.childNodes[0].id==inputId){var parent=inputElm.parentNode;var newInputElm=div.childNodes[0];parent.replaceChild(newInputElm,inputElm);inputElm=newInputElm;doi.dom.style(inputElm,"opacity:0")}else{inputElm.innerHTML=div.innerHTML}timer2=window.setInterval(function(){opacity2++;doi.dom.style(inputElm,"opacity:"+opacity2);if(opacity2>=10){window.clearInterval(timer2);timer2=false;doi.widget.render();doi.dom.execScript(inputElm);var modalbox=doi.muntilan.modalBox();if(modalbox){modalbox.resize()}doi.widget.loaderBox.hide()}},10)}},10)}}else{doi.widget.loaderBox.hide()}},failure:function(req){alert("Last Action Failed.")}})};doi.muntilan.list.refreshx=function(data){var url=data.url;var listId=data.ids.listId;var inputId=data.ids.inputId;doi.ajax.request("get",url,{timeout:doi.muntilan._ajax_timeout,success:function(req){var content=false;var modalBox=doi.muntilan.modalBox();if(modalBox){content=modalBox.element("content")}var listElm=doi.dom.$("#"+listId,content);var inputElm=doi.dom.$("#"+inputId,content);var tmpContainer=document.createElement("div");tmpContainer.innerHTML=req.responseText;var listTagElms=doi.dom.$("tag:div;title=doilist",tmpContainer);var inputTagElms=doi.dom.$("tag:div;title=doiinput",tmpContainer);var lastVisitTagElms=doi.dom.$("tag:div;title=doilastvisit",tmpContainer);if(lastVisitTagElms){if(lastVisitTagElms[0].childNodes&&lastVisitTagElms[0].childNodes[0]&&lastVisitTagElms[0].childNodes[0].nodeName=="SCRIPT"){eval(lastVisitTagElms[0].childNodes[0].innerHTML)}else{doi.dom.execScript(lastVisitTagElms[0])}}if(listElm){var height=listElm.offsetHeight;doi.effect.blindUp(listElm,{from:height,to:"0",stop:function(){var div=document.createElement("div");if(listTagElms&&listTagElms[0]){div.innerHTML=listTagElms[0].innerHTML}if(div.childNodes[0]&&div.childNodes[0].id==listId){var parent=listElm.parentNode;var newListElm=div.childNodes[0];parent.replaceChild(newListElm,listElm);listElm=newListElm;doi.dom.style(listElm,{display:"none",height:"1px"})}else{listElm.innerHTML=req.responseText}doi.widget.render();doi.dom.execScript(listElm);doi.effect.blindDown(listElm,{from:"0",to:listElm.scrollHeight,stop:function(){var modalbox=doi.muntilan.modalBox();if(modalbox){modalbox.resize()}doi.muntilan.list.sortable(listElm);doi.widget.loaderBox.hide()}})}})}if(inputElm&&inputTagElms){var height=inputElm.offsetHeight;var div=document.createElement("div");if(inputTagElms&&inputTagElms[0]){div.innerHTML=inputTagElms[0].innerHTML}if(div.childNodes[0]&&div.childNodes[0].id==inputId){var input=div.childNodes[0].innerHTML}else{var input=div.innerHTML}if(input=="false"){return}doi.effect.blindUp(inputElm,{from:height,to:"0",stop:function(){if(div.childNodes[0]&&div.childNodes[0].id==inputId){var parent=inputElm.parentNode;var newInputElm=div.childNodes[0];parent.replaceChild(newInputElm,inputElm);inputElm=newInputElm;doi.dom.style(inputElm,{display:"none",height:"1px"})}else{inputElm.innerHTML=div.innerHTML}doi.widget.render();doi.dom.execScript(inputElm);doi.effect.blindDown(inputElm,{from:"0",to:inputElm.scrollHeight,stop:function(){var modalbox=doi.muntilan.modalBox();if(modalbox){modalbox.resize()}doi.dom.style(inputElm,{height:"auto"});doi.widget.loaderBox.hide()}})}})}else{doi.widget.loaderBox.hide()}},failure:function(req){alert("Last Action Failed.")}})};doi.muntilan.list.input_visibility=function(e,c){var b=false;var a=doi.muntilan.modalBox();if(a){b=a.element("content")}var d=doi.dom.$("#"+e,b);if(d){if(c){doi.dom.style(d,{visibility:"visible",display:"block"})}else{doi.dom.style(d,{visibility:"hidden",display:"none"})}}};doi.muntilan.search.clear=function(f,e,a,c){for(var b=0;b<e.length;b++){var h=e.elements[b];if(h.type!="hidden"&&h.name!="submit"&&h.name!="clearSubmit"){if(h.options){h.selectedIndex=0}else{h.value=""}}}var d=new doi.dom.request(a);var g=doi.muntilan.modalBox();if(g&&(d.get("_modal")||d.get("_modalbox"))){g.show(a);return false}else{if(doi.muntilan.list.link_onclick){doi.muntilan.list.link_onclick(a,c);return false}else{e.action=a;return true}}};doi.muntilan.search.submit=function(b,f,c,a){if(!c){var c=f.action;for(var h=0;h<f.length;h++){var d=f[h].name;if(d.charAt(0)=="q"){if(d==doi.muntilan._qLabel){f[h].value=1}else{var g=/^q(.*)(\-dd|\-mm|\-yy|\-hh|\-ii|\-ss)$/;if(g.test(d)){continue}}c+="&"+f[h].name+"="+f[h].value}}}var j=new doi.dom.request(c);var e=doi.muntilan.modalBox();if(e&&(j.get("_modal")||j.get("_modalbox"))){e.show(c);return false}else{if(doi.muntilan.list.link_onclick){doi.muntilan.list.link_onclick(c,a);return false}else{f.action=c;return true}}};doi.muntilan.session.run=function(d){d=doi.dom.parseInt(d);if(d==0){d=doi.muntilan.session.time}else{doi.muntilan.session.time=d}var b=Math.floor(d/60);d*=1000;var a=0;var c=60000;window.clearInterval(doi.muntilan.session.timer);doi.muntilan.session.timer=window.setInterval(function(){a+=c;if(a>=d){window.clearInterval(doi.muntilan.session.timer);var e=location.href;var f="<center>You have been idle for over "+b+" minute(s).<br/>";f+="Your session might be over.<br/>";f+="Please, review your last work by clicking outside this box or<br/>";f+='click <a href="'+e+'" onclick="doi.muntilan.refresh(this.href);return false;">here</a> to log in again.';f+="</center>";doi.widget.modalBox2.show({url:f,type:"html"})}},c)};doi.muntilan.session.executeLastVisitDateFromAjax=function(responseText){var div=document.createElement(div);div.innerHTML=responseText;var lastVisitTagElms=doi.dom.$("tag:div;title=doilastvisit",div);if(lastVisitTagElms){if(lastVisitTagElms[0].childNodes&&lastVisitTagElms[0].childNodes[0]&&lastVisitTagElms[0].childNodes[0].nodeName=="SCRIPT"){eval(lastVisitTagElms[0].childNodes[0].innerHTML)}else{doi.dom.execScript(lastVisitTagElms[0])}}};doi.muntilan.session.setLastVisitDate=function(b){var a=doi.dom.$("#muntilan-last-visit-id");doi.muntilan.session.run();if(a){a.innerHTML=b}};
