//------------------------Cookie
//-------------------------------------------------------
function showCookie() {
    var cookie_str = document.cookie.toString();
    var cArr = cookie_str.split(/\|/);
    alert(unescape(cookie_str))
}

//-------------------------------------------------------
// function return site host name
function get_host_name() {
 	var host_url = '';
 	var url_str = String(document.location);
 	var pattern1 = /http:\/\/w{0,3}\.?([\w|-|.]*\.\w{2,4})\//;
 	var host_array = url_str.match(pattern1);
 	if(host_array[1])	host_url = host_array[1];
 	//alert(host_url);
 	return host_url;
}
//var domain_site = get_host_name();
var domain = "."+get_host_name();
//var domain = ".creditrapid.design.md";

//-------------------------------------------------------
//function setCookie(cookie_name,cookie_value,expiredays)
function setCookie(name,value,expiredate)
{
    //var domain=".somehost.md"; //- this variable may set by get_host_name() function
    var path="/";

    var exdate=new Date();
    exdate.setHours(exdate.getHours()+expiredate);
    //exdate.setDate(exdate.getDate()+expiredate);

	//alert(exdate)
    var vcookie="";
    vcookie+= ''+name+'=' + escape(value.toString());
    //vcookie+='|data=' + escape(data.toString());

    vcookie+=((expiredate==null) ? "" : ";expires="+exdate.toGMTString());
    vcookie+=((path) ? "; path=" + path : "");
    vcookie+=((domain) ? "; domain=" + domain : "");
    //vcookie+=((secure) ? "; secure" : "");

    document.cookie=vcookie;
    //alert(vcookie)
}

//-------------------------------------------------------
//function return cookie value by name
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
