﻿var _pnlMain = "ctl00_CPHMain_";

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
 
function stripHTML(str){
    var re = /(<([^>]+)>)/gi;
    str = str.replace(re, "");
    return str;
}

function converStrToParam (str) {
    var temp = stripHTML(str);
    temp = temp.toLowerCase().replace(/([.])/g,'');
    temp = temp.replace(/([ ])/g,'.');
    var result = '';
    var isDot = false;
    
    for (var i=0;i<temp.length;i++) {
        if ((temp.charAt(i) >= 'a' && temp.charAt(i) <= 'z') || (temp.charAt(i) >= '0' && temp.charAt(i) <= '9') || (temp.charAt(i) == '.')) {
            if (temp.charAt(i) == '.') {
                if (isDot == false) {
                    result = result + temp.charAt(i);
                }   
            } else {
                result = result + temp.charAt(i);
            }
            
            if (temp.charAt(i) == '.') {
                isDot = true;
            } else {
                isDot = false;
            }
        }
    }
    if (result.charAt(result.length - 1) == '.') {
        result = left(result, result.length - 1);
    }
    return result;
}

function MyURLDecode (clearString) {
    var output = '';
    var huruf = new Array(" ", "\"", "#", "$", "%", "&", "+", ",", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "`", "{", "|", "}", "~", String.fromCharCode(13), String.fromCharCode(10));            
    var hurufEncode = new Array("%20", "%22", "%23", "%24", "%25", "%26", "%2b", "%2c", "%2f", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f", "%40", "%5b", "%5c", "%5d", "%5e", "%60", "%7b", "%7c", "%7d", "%7e", "%0d", "%0a");
            
    for (var j = 0; j < hurufEncode.length; j++) {
        while(clearString.indexOf(hurufEncode[j]) > -1)
            clearString = clearString.replace(hurufEncode[j], huruf[j]);
    }
    output = clearString;
    return output;
}

function MyURLEncode (clearString) {
    var output = '';
    
    var hurufEncode = new Array(" ", "\"", "#", "$", "&", "+", ",", "/", ":", ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "`", "{", "|", "}", "~", String.fromCharCode(13), String.fromCharCode(10));            
    var huruf = new Array("%20", "%22", "%23", "%24", "%26", "%2b", "%2c", "%2f", "%3a", "%3b", "%3c", "%3d", "%3e", "%3f", "%40", "%5b", "%5c", "%5d", "%5e", "%60", "%7b", "%7c", "%7d", "%7e", "%0d", "%0a");

    for (var j = 0; j < hurufEncode.length; j++) {
        while(clearString.indexOf(hurufEncode[j]) > -1)
            clearString = clearString.replace(hurufEncode[j], huruf[j]);
    }
    output = clearString;
    return output;
}  



function isNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;

    for (i = 0; i < sText.length && IsNumber == true; i++) { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//function showIndicator() {    
//    document.getElementById("waitIndicatorDiv").style.display='';
//}

//function hideIndicator() {    
//    document.getElementById("waitIndicatorDiv").style.display='none';
//}

   
function showNotification() {    
     document.getElementById("divNotification").style.display='';
}

function toNumeric(o) {
    if(/[^0-9]/.test(o.value)){
        o.value=o.value.replace(/([^0-9])/g,"");
    }
}

function toNumericVar(o) {
    if(/[^0-9.^0-9]/.test(o.value)){
        o.value=o.value.replace(/([^0-9.^0-9])/g,"");
    }
}
function emailValidation(addr) {
    var emailReg = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    var regex = new RegExp(emailReg);
    return regex.test(addr);
}

function dateValidation(date) {
    var dateReg = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    var regex = new RegExp(dateReg);
    return regex.test(date);
}

function left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function getMonthName (n) {


    switch(n){
        case "1":
          return "Jan";
          break;  
        case "2":
          return "Feb";
          break; 
        case "3":
          return "Mar";
          break;  
        case "4":
          return "Apr";
          break; 
        case "5":
          return "Mei";
          break;  
        case "6":
          return "Jun";
          break; 
        case "7":
          return "Jul";
          break;  
        case "8":
          return "Aug";
          break;
        case "9":
          return "Sep";
          break;  
        case "10":
          return "Okt";
          break; 
        case "11":
          return "Nov";
          break;  
        case "12":
          return "Des";
          break;   
    }
    switch(n){
        case 1:
          return "Jan";
          break;  
        case 2:
          return "Feb";
          break; 
        case 3:
          return "Mar";
          break;  
        case 4:
          return "Apr";
          break; 
        case 5:
          return "Mei";
          break;  
        case 6:
          return "Jun";
          break; 
        case 7:
          return "Jul";
          break;  
        case 8:
          return "Aug";
          break;
        case 9:
          return "Sep";
          break;  
        case 10:
          return "Okt";
          break; 
        case 11:
          return "Nov";
          break;  
        case 12:
          return "Des";
          break;   
    }
}

function charFilter(o) {
    if(/[-@&~=*|\[\]{}\"'`#\^]/.test(o.value)){
        o.value=o.value.replace(/([-@&~=*|\[\]{}\"'`#\^])/g,"");
    }
}

function charFilterSpace(o) {
    if(/ /.test(o.value)){
        o.value=o.value.replace(/ /g,"");
    }
}

function charFilterAlphaNum(o){
    if(/[^0-9A-Za-z ]/.test(o.value)){
        o.value=o.value.replace(/([^0-9A-Za-z ])/g,"");
    }
}

function countLengthTextArea(o,d,maxL){
	var n = o.value.length;
    var result = "";
    
    if (n <= maxL){
        try {
            d.innerHTML = (maxL - n) + " karakter tersedia";
        } catch(e) {
            d.innerText = (maxL - n) + " karakter tersedia";
        }
    } else {
        o.value = o.value.substring(0,maxL);
    }
}

function countLengthTextAreaSTF(o,d,maxL){
	var n = o.value.length;
    var result = "";
    
    if (n <= maxL){
        try {
            d.innerHTML = (maxL - n) + " Karakter";
        } catch(e) {
            d.innerText = (maxL - n) + " Karakter";
        }
    } else {
        o.value = o.value.substring(0,maxL);
    }
}


function bindWhatHot() {
    
    var moduleCode = '';
    switch(document.getElementById('selWH').value) {
        case "1" : moduleCode = '001'; break; //Artikel
        case "2" : moduleCode = '004'; break; //Tools
        case "3" : moduleCode = '002'; break; //Berita
        case "4" : moduleCode = '003'; break; //Blog Red
    }
    
    document.getElementById('divNewContent').innerHTML = "<div style=\"text-align:center; margin-top:10px;\"><img border=\"0\" src=\"" + _rootPath + "themes/default/images/indicatorOrangeBgTrans.gif\" /></div>";
    WCFGeneral.JSON_getContentTitleByDate(moduleCode, "all", 3, bindWhatHotOnComplete, bindWhatHotOnError);
}

function bindWhatHotOnComplete(result) {
    result = eval(result);
    //alert(result);
    var temp = '';
    var link = '';
    var linkM = '';
    for (var i = 0; i < result.length  ; i++) {
        //alert(MyURLDecode(result[i].subModuleName));
        switch(result[i].moduleCode) {
            case "001": link = _rootPath + "artikel/" + MyURLDecode(result[i].entityCategoryName) + "/" + MyURLDecode(result[i].subModuleName).replace(/([ ])/g,'+') + "/" + converStrToParam(MyURLDecode(result[i].title)) + "/" + result[i].moduleCode + "/" + result[i].subModuleCode + "/" + result[i].articleRef + "/2"; 
                        linkM = _rootPath + "artikel/2";
                        break;
            case "004": link = _rootPath + "support/file.content/" + _entityCode + "/" + result[i].moduleCode + "/" + result[i].subModuleCode + "/" + result[i].articleRef + "/1"; 
                        linkM = _rootPath + "tools/2";
                        break;
            case "002": link = _rootPath + "berita.ayahbunda/" + MyURLDecode(result[i].subModuleName).replace(/([ ])/g,'+') + "/" + converStrToParam(MyURLDecode(result[i].title)) + "/" + result[i].moduleCode + "/" + result[i].subModuleCode + "/" + result[i].articleRef + "/all/0/1";
                        linkM = _rootPath + "berita.ayahbunda";
                        break;
            case "003": link = _rootPath + "blog.redaksi/" + converStrToParam(MyURLDecode(result[i].title)) + "/" + result[i].subModuleCode + "/" + result[i].articleRef + "/3";
                        linkM = _rootPath + "blog.redaksi";
                        break;
        }    
        temp = temp + "<div class=\"leftMenu\"><a href=\"" + link + "\">" + MyURLDecode(result[i].title) + "</a></div>";
    }
    temp = temp + "<div style=\"text-align: right; margin-top:5px;\"><a href=\"" + linkM + "\" class=\"detil\">&raquo; more</a></div>";
    document.getElementById('divNewContent').innerHTML = temp;
}

function bindWhatHotOnError(result) {
    //alert(result.get_message()); 
    //alert('error getting data, pls refresh the browser ...');
}

// banner //

function iBH(BC) {
    try {
        WCFGeneral.JSON_insertTrBannerReportHover(BC);
    } catch(e) {}
}

// end banner //


