﻿function GetUrlBase() {
	var result = window.location.toString().replace("http://","");
	result = result.substr(0,result.indexOf("/"));
	return result;
}


function removeHTMLTags(text)
{
 	return text.replace(/<\/?[^>]+(>|$)/g, "");
}

// =======================================================================================
// WORK WITH COOKIES
// =======================================================================================

var MyCookie = {
    Write:function(name,value,days) {
        var D = new Date();
        D.setTime(D.getTime()+86400000*days)
        document.cookie = escape(name)+"="+escape(value)+
            ((days == null)?"":(";expires="+D.toGMTString())) + ";path=/"
        return (this.Read(name) == value);
    },
    Read:function(name) {
        var EN=escape(name)
        var F=' '+document.cookie+';', S=F.indexOf(' '+EN);
        return S==-1 ? null : unescape(     F.substring(EN=S+EN.length+2,F.indexOf(';',EN))    );
    }
}

// =======================================================================================
// MESSAGE BOX
// =======================================================================================

function MessageBox(parentObjectId, messageHTML, buttonsHTML, closeButtonText)
{
    var parentObject = document.getElementById(parentObjectId);
    parentObject.style.display = "block";
    parentObject.style.margin = (-parentObject.offsetHeight).toString() +"px 0 0 0";
    
    var htmlContent = 
    "<div id=\"messageBoxObjectCloseButtonHTML\">"+
    "    <a href=\"javascript:HideMessageBox('"+ parentObjectId +"');\">"+ closeButtonText +"</a>"+
    "</div>"+
    "<div id=\"messageBoxObjectMessageHTML\">"+ messageHTML +"</div>"+
    "<div id=\"messageBoxObjectButtonsHTML\">"+ buttonsHTML +"</div>";
    
    if (document.getElementById("messageBoxObject") == null)
        parentObject.innerHTML += ("<div id=\"messageBoxObject\"></div>");
 
    if (document.getElementById("messageBoxObjectWindow") == null)
        parentObject.innerHTML += ("<div id=\"messageBoxObjectWindow\"></div>");
 
    var windowObj = document.getElementById("messageBoxObjectWindow");
    var backObj = document.getElementById("messageBoxObject");
    
    windowObj.innerHTML = htmlContent;
    
    backObj.style.display = "block";
    windowObj.style.display = "block";
    
    backObj.style.height = "100%";
    windowObj.style.left = Math.round((backObj.offsetWidth - windowObj.offsetWidth) / 2) +"px";
    windowObj.style.top = Math.round((backObj.offsetHeight - windowObj.offsetHeight) / 2) +"px";
    windowObj.style.zIndex="999999999";
    if (Math.round((backObj.offsetHeight - windowObj.offsetHeight) / 2) < 0)
        windowObj.style.top = "230px";
    backObj.style.height = document.getElementById("page").offsetHeight +"px";
    
}

function HideMessageBox(parentObjectId) {
    var windowObj = document.getElementById("messageBoxObjectWindow");
    var backObj = document.getElementById("messageBoxObject");
    var parentObject = document.getElementById(parentObjectId);
    windowObj.style.display = "none";
    backObj.style.display = "none";
    parentObject.style.display = "none";
}