﻿function UrlEncode (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
    }

function Mil_Get_Cookie(check_name) {
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; 

    for (i = 0; i < a_all_cookies.length; i++) {

        a_temp_cookie = a_all_cookies[i].split('=');


        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');


        if (cookie_name == check_name) {
            b_cookie_found = true;

            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }

            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

function Mil_Set_Cookie(name, value, path, domain) {
    var expires_date = new Date();
    expires_date.setUTCHours(0,0,0,0);
    expires_date.setDate(expires_date.getDate()+1);
    document.cookie = name + "=" + escape(value) + ";expires=" + expires_date.toGMTString();
}
