﻿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 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 stripHTML(str){
    var re = /(<([^>]+)>)/gi;
    str = str.replace(re, "");
    return str;
}