$(function() {
var duration = 500, arParent=[], baseURL;
/* events */
/* functions */
function setPageDisplay() {
/* fixing main area for IE */
if($.browser.msie) { /* IE special case to prevent IE8+'s characteristics */
var oWrapper = document.getElementById("wrapper");
oWrapper.style.setExpression("height",
"(document.compatMode=='CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight)-20");
var oMain = document.getElementById("main");
oMain.style.setExpression("height",
"(document.compatMode=='CSS1Compat' ? document.documentElement.clientHeight : document.body.clientHeight)-205");
}
$("#wrapper").fadeIn(1000); baseURL = "https://www.backoffice.berliansolusi.com/app/";
}
function setPageEvent() {
var getUrlVars = function(href) {
var vars = [], hash;
var hashes = href.slice(href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var showSubmenuPop = function(el,idx) {
if(!idx) idx=0;
if($("#menupop"+idx).get().length==0) {
$(document.body).append('
');
setTimeout(function() { showSubmenuPop(el,idx) },100);
} else {
var param = "href="+el.attr("href");
$.ajax({
type: "POST",
url: baseURL+"show_sub_menu",
data: param,
success: function(html){
if(html.indexOf("menulist")<0) {
window.alert(html); window.location.reload();
} else {
$("#menupop"+idx).html(html);
var offset = el.offset(),
mnuHeight = 0,
mnuLength = $("#menupop"+idx+" .menulist li").get().length,
mnuTop = 0;
$("#menupop"+idx+" .menulist li").each(function() {
if($(this).attr("class").indexOf("separator")>=0) mnuHeight+=5;
else mnuHeight+=parseInt($(this).css("line-height").replace("px",""));
});
if(idx==0) {
$("#menupop"+idx).css({
left: offset.left+"px",
top: offset.top+el.height()+6+"px",
height:mnuHeight+5+"px"
}).slideDown(0.5*duration);
} else {
mnuTop = offset.top-2;
if ($(window).height()<=(mnuTop+mnuHeight+5)) {
var rowHeight = parseInt($("#menupop"+idx+" .menulist li[class!='separator']").eq(0).css("line-height").replace("px",""));
mnuTop -= (mnuHeight-rowHeight);
}
$("#menupop"+idx).css({
left: offset.left+$("#menupop"+idx).width()-1+"px",
/*top: offset.top-2+"px",*/
top: mnuTop+"px",
height:mnuHeight+5+"px"
}).slideDown(0.5*duration);
}
$(window).resize(function(e){
for(var i=0; i<=arParent.length; i++) {
if(i==0) {
offset = $("#subheader .menuhorizontal li a[title]").offset();
$("#menupop"+i).css({
left: offset.left+"px",
top: offset.top+el.height()+6+"px"
});
} else {
$("#menupop"+(i-1)+" li a").each(function() {
if($(this).attr("title")==arParent[i-1]) {
offset = $(this).offset();
mnuTop = offset.top-2;
if ($(window).height()<=(mnuTop+mnuHeight+5)) {
var rowHeight = parseInt($("#menupop"+i+" .menulist li[class!='separator']").eq(0).css("line-height").replace("px",""));
mnuTop -= (mnuHeight-rowHeight);
}
$("#menupop"+i).css({
left: offset.left+$("#menupop"+(i-1)).width()-1+"px",
/*top: offset.top-2+"px"*/
top: mnuTop+"px",
});
return false;
}
});
}
}
}).click(function(e) {
var $target = $(e.target);
if($(e.target).is(":not(.menupop .menulist li a, #subheader .menuhorizontal li a)")) {
$("#subheader .menuhorizontal li a[title]").click();
}
});
menupopEvent();
}
},
error: function(html){ window.alert("Technical error..."); }
});
}
}
var menupopEvent = function() {
$(".menupop .menulist li a").unbind().click(function(e) {
e.preventDefault();
var sClass = $(this).attr("class"), idx;
if(sClass=="parent") {
idx=$(this).parent().parent().parent().parent().attr("id").replace("menupop","");
arParent[idx] = $(this).attr("title");
showSubmenuPop($(this),parseInt(idx)+1);
} else {
var title = $(this).attr("title"), href = $(this).attr('href'),
url = $(location).attr('href'), param;
var href1 = getUrlVars(href)[0],
href2 = getUrlVars(href)["key"], href3 = getUrlVars(href)["mnu"],
href4 = href.replace('?','');
param = "href="+href;
$.ajax({
url: baseURL+"check_menu",
type: "POST",
data: param,
success: function(response){
if($.trim(response)=='1')
window.location.replace(href);
else
window.alert('Under Construction...');
//window.alert('Not available for demo version...');
}
});
}
}).hover(function() {
var idx;
idx=$(this).parent().parent().parent().parent().attr("id").replace("menupop","");
for(var i=idx; i0) {
if(i==idx) {
if(arParent[i]!=$(this).attr("title")) {
$("#menupop"+(parseInt(i)+1)).hide();
arParent[i] = "";
}
} else {
$("#menupop"+(parseInt(i)+1)).hide();
arParent[i] = "";
}
}
}
});
}
if($("#loginfrm").get().length>0) {
$("#loginfrm .LoginUserID").focus(function() {
$(this).css({ background: "url(https://www.backoffice.berliansolusi.com/assets/img/bguseron.gif) left top no-repeat #FFF" });
}).blur(function() {
if($.trim($(this).val())=='') {
$(this).css({ background: "url(https://www.backoffice.berliansolusi.com/assets/img/bguseroff.gif) left top no-repeat #FFF" });
$(this).val('');
}
});
$("#loginfrm .LoginPassword").focus(function() {
$(this).css({ background: "url(https://www.backoffice.berliansolusi.com/assets/img/bgpwdon.gif) left top no-repeat #FFF" });
}).blur(function() {
if($.trim($(this).val())=='') {
$(this).css({ background: "url(https://www.backoffice.berliansolusi.com/assets/img/bgpwdoff.gif) left top no-repeat #FFF" });
$(this).val('');
}
});
$("#loginfrm .TextInput").keypress(function(e) { if(e.which==13) doLogin(); });
$("#loginfrm .Button").unbind().click(function(e) { doLogin(e) });
/* special actions */
$("#loginfrm .LoginUserID").val('');
$("#loginfrm .LoginPassword").val('');
}
if($("#search").is(":visible")) {
$("#search .SearchKeyword").focus(function() {
$(this).css({ background: "url(https://www.backoffice.berliansolusi.com/assets/img/bgsearchon.gif) left center no-repeat #FFF" });
})
.blur(function() {
if($.trim($(this).val())=='') {
$(this).val('')
.css({ background: "url(https://www.backoffice.berliansolusi.com/assets/img/bgsearchoff.gif) left center no-repeat #FFF" });
}
}).keyup(function(e) { if(e.which==13 && $.trim($(this).val())!='') doQuickSearch(); });
$("#search .SearchButton").click(function() {
if($("#search .SearchKeyword").val()=='')
window.alert('Masukkan kata kunci untuk pencarian!');
else
doQuickSearch();
});
}
$("#account .linksignout").click(function(e) {
e.preventDefault();
if(confirm('Anda yakin hendak keluar dari sistem?')) doLogout();
});
$("#account .linkchgpwd").click(function(e) {
e.preventDefault(); showFormChgPwd();
});
if($("#main .ButtonMain").get().length>0) {
$("#main .ButtonMain[name='GantiPassword']").click(function() { showFormChgPwd() });
$("#main .ButtonMain[name='SignOut']").click(function() {
if(confirm('Anda yakin hendak keluar dari sistem?')) doLogout();
});
}
/* menu events */
$("#menu .menuhorizontal li a[class='mnuon']").click(function(e) { e.preventDefault() });
$("#menu .menuhorizontal li a[class!='mnuon']").click(function(e) {
e.preventDefault();
var sClass, href = $(this).attr("href");
//if(href.indexOf("?")>=0) {
if(href.indexOf("#")<0) {
if($(this).attr("class") && $(this).attr("class").indexOf("parent")>=0) {
if(!$(this).attr("title")) {
$("#menu .menuhorizontal li a").each(function() {
sClass = $(this).attr("class");
sClass = $.trim(sClass.replace("clicked",""));
if(sClass=="") $(this).removeAttr("class");
else $(this).attr("class",sClass);
$(this).removeAttr("title");
});
$(".menupop").hide();
sClass = $(this).attr("class");
sClass += " clicked";
$(this).attr("class",$.trim(sClass)).attr("title",$(this).text());
showSubmenuPop($(this));
} else {
sClass = $(this).attr("class");
sClass = $.trim(sClass.replace("clicked",""));
if(sClass=="") $(this).removeAttr("class");
else $(this).attr("class",sClass);
$(this).removeAttr("title");
$(".menupop").hide();
}
} else {
var title = $(this).attr("title"), href = $(this).attr('href'),
url = $(location).attr('href'), param;
var href1 = getUrlVars(href)[0],
href2 = getUrlVars(href)["key"], href3 = getUrlVars(href)["mnu"],
href4 = href.replace('?','');
param = "href="+href;
$.ajax({
url: baseURL+"check_menu",
type: "POST",
data: param,
success: function(response){
if($.trim(response)=='1')
window.location.replace(href);
else
window.alert('Under Construction...');
//window.alert('Not available for demo version...');
}
});
}
} else {
$("#menu .menuhorizontal li a").each(function() {
sClass = $(this).attr("class");
sClass = $.trim(sClass.replace("clicked",""));
if(sClass=="") $(this).removeAttr("class");
else $(this).attr("class",sClass);
$(this).removeAttr("title");
});
$(".menupop").hide();
}
});
}
function doSearch(btn) {
if($("#perpusfrm .TextForm[name='Keyword']").val()==''
&& $("#perpusfrm .TextForm[name='Judul']").val()==''
&& $("#perpusfrm .TextForm[name='Pengarang']").val()==''
&& $("#perpusfrm .TextForm[name='Subjek']").val()==''
&& $("#perpusfrm .TextForm[name='ISBNISSN']").val()=='') {
window.alert('Masukkan Keyword!');
if(btn.attr("name")=="Search")
$("#perpusfrm .TextForm[name='Keyword']").focus();
else if(btn.attr("name")=="Search2")
$("#perpusfrm .TextForm[name='Judul']").focus();
} else {
$("#perpusfrm").submit();
}
}
function doLogout(e) {
$.ajax({
type: "POST",
url: baseURL+"logout_process",
success: function(response){ window.location.reload(); }
});
}
function doLogin(e) {
var param = '', $TextInput;
for(var i=$("#loginfrm .TextInput").get().length-1;i>=0;i--) {
$TextInput = $("#loginfrm .TextInput").eq(i);
if($.trim($TextInput.val())=='') {
if(e) {
window.alert('Isikan '+$TextInput.attr("title")+' Anda');
$TextInput.focus();
}
param = ''; return false;
} else {
param+= $TextInput.attr("name")+'='+escape($TextInput.val())+'&';
}
}
if(param!='') {
/*window.alert(param); */
$.ajax({
type: "POST",
url: baseURL+"login_process",
data: param,
beforeSend: function(){ showModal(true) },
/*complete: function(){ showModal(false) },*/
success: function(response){
if(response.indexOf("")>0) {
arRsp = response.split("");
if(arRsp[0]=='0') {
/* $("#loginfrm").hide(); */
/*window.location.reload();*/
var href = $(location).attr('href');
window.location.replace(href);
} else {
window.alert(arRsp[1]);
$("#loginfrm .TextInput").eq(parseInt(arRsp[2])).select();
showModal(false);
}
} else { window.alert(response); showModal(false) }
}, error: function() { window.alert('AJAX Error...'); showModal(false); }
});
}
}
function showFormChgPwd() {
showModal(true);
if($("#mainpop").get().length==0) {
$(document.body).append('');
setTimeout(function() { showFormChgPwd() },100);
} else {
var href = $(location).attr('href');
href= href.split("/")[href.split("/").length-1];
href= href.substr(0,href.indexOf("."));
$.ajax({
url:baseURL+"chg_pwd_form",
type:'POST',
success:function(response){
if(response.split("").length>1) {
arResponse = response.split("");
var width = $.trim(arResponse[0].replace('width:','')),
height = $.trim(arResponse[1].replace('height:','')),
html = arResponse[2];
$("#mainpop").html(html).css({
height:parseInt(height),
width:parseInt(width),
marginTop:parseInt(height)/-2,
marginLeft:parseInt(width)/-2
}).fadeIn(duration);
if($.browser.msie) { // IE special case
oMainForm = document.getElementById("mainpop");
oMainForm.style.setExpression("margin-top",
"(document.compatMode=='CSS1Compat' ? document.documentElement.scrollTop : document.body.scrollTop)-"+parseInt(height)/2
);
oMainForm.style.setExpression("marginLeft",
"(document.compatMode=='CSS1Compat' ? document.documentElement.scrollLeft : document.body.scrollLeft)-"+parseInt(width)/2
);
}
} else $("#mainpop").html(response).fadeIn(duration);
setFormEvent();
},
error:function(){ window.alert('AJAX Error in opening form...'); }
});
}
}
function setFormEvent() {
$("#mainpop input").unbind();
$("#mainpop .ButtonImage[name='Close']").click(function() { closeForm() });
$("#mainpop .TextForm").keypress(function(e) { if(e.which==13) changePwd(); });
$("#mainpop .ButtonPop[name='Save']").click(function(e) { changePwd(e) });
}
function closeForm() { showModal(false); $("#mainpop").hide().html(''); }
function changePwd(e) { //alert(e)
var param = '';
$("#mainpop .TextForm").each(function() {
if($.trim($(this).val())=='') {
if(e) { window.alert('Isikan '+$(this).attr("title")+' Anda'); }
$(this).focus();
param = ''; return false;
} else {
param+= $(this).attr("name")+'='+escape($(this).val())+'&';
}
});
if(param!=''
&& $("#mainpop .TextForm[name='PasswordBaru']").val()!=$("#mainpop .TextForm[name='PasswordBaru2']").val()) {
window.alert("Cek lagi Password Baru Anda");
$("#mainpop .TextForm[name='PasswordBaru2']").select();
param='';
}
if(param!='') {
$.ajax({
type: "POST",
url:baseURL+"chg_pwd",
data: param,
success: function(response){
if(response.indexOf("")>0) {
arRsp = response.split("");
window.alert(arRsp[1]);
if(arRsp[0]=='0') {
closeForm();
} else {
$("#mainpop .TextForm[name='PasswordLama']").select();
}
} else if(response.toLowerCase().indexOf("session habis")>=0) {
window.alert(response);
window.location.reload();
} else {
window.alert('Unknown error. Call the vendor!');
closeForm();
}
}, error: function() { window.alert('AJAX Error...') }
});
}
}
function showModal(state) {
if($("#mask").get().length==0) {
$(document.body).append('');
setTimeout(function() { showModal(state); },100);
} else {
if(!state) {
if($("#mask:animated").get().length>0) {
$("#mask:animated").stop().hide();
} else {
setTimeout(function() { $("#mask").fadeOut(duration); },100);
}
} else {
$("#mask:hidden").css({ backgroundColor: "#000", opacity: .5, filter: "alpha(opacity=50)" })
.fadeIn(duration).fadeTo(duration,0.75);
}
}
}
function doQuickSearch() {
$("#search .SearchForm .HiddenValue[name='Keyword']").val($("#search .SearchKeyword").val());
$("#search .SearchForm").submit();
}
function substrLeft(str,n){
if(n <= 0)
return "";
else if(n > String(str).length)
return str;
else
return String(str).substring(0,n);
}
function substrRight(str, n){
if (n <= 0)
return "";
else if (n > String(str).length)
return str;
else {
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}
function clearChar(str,chr) {
while(str.indexOf(chr)>=0)
str = str.replace(chr,"");
return str;
}
/* actions */
setPageDisplay();
setPageEvent();
});