var arrAttr = null;
var oldLoc = null;

function PoolAddressChanges() {
    if(oldLoc != document.location.href) {
        LoadRequestString();
        oldLoc = document.location.href;
        if(arrAttr.length > 1) {
            var reqStr = getHashString();
            //UpdateLocationAddress(reqStr);
            DoPostBack("", getPostbackAction(), "CMSService.php");
        }
    }
    setTimeout('PoolAddressChanges()', 300);
}

function UpdateLocationAttributes(newAtt) {
    LoadRequestString();
    var att = toHashString(newAtt);

    if(navigator.appVersion.indexOf("4.0 (compatible; MSIE 6.0;") == -1)
        document.location.href = arrAttr[0] + att;
    oldLoc = arrAttr[0] + att;
}

function UpdateLocationAddress(newLoc) {
    oldLoc = newLoc;
    document.location.href = newLoc;
}

function LoadRequestString() {
    var DocLoc = document.location.href;

    DocLoc = DocLoc.replace(/\&/g, "#");
    DocLoc = DocLoc.replace(/\?/g, "#");

    var arrSplitLoc = DocLoc.split("#");
    var arrLen = arrSplitLoc.length;

    arrAttr = new Array();
    for(var i=0; i<arrLen; i++) {
        arrAttr[i] = arrSplitLoc[i];
    }
}

function getRequestString() {
    var reqStr = "";
    if(arrAttr != null) {
        var attLen = arrAttr.length;

        for(var i=1; i<attLen; i++) {
            if(i == 1)
                reqStr = "?";

            reqStr += arrAttr[i];
            if(i < attLen-1)
                reqStr += "&";
        }
    }

    return reqStr;
}

function getHashString() {
    var reqStr = "";
    if(arrAttr != null) {
        var attLen = arrAttr.length;
        for(var i=0; i<attLen; i++) {
            if(i > 0)
                reqStr += "#";
            reqStr += arrAttr[i];
        }
    }

    return reqStr;
}

function getPostbackAction() {
    var reqStr = "";
    if(arrAttr != null) {
        var attLen = arrAttr.length;

        for(var i=1; i<attLen; i++) {
            if(i > 1)
                reqStr += "&";
            reqStr += arrAttr[i];
        }
    }

    return reqStr;
}

window.onload = function() {
    loadedTitle = document.getElementById("TitleMetaTag").content;
    if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.indexOf("4.0 (compatible; MSIE 6.0;") != -1) {
	} else {
		if(parent == self) {
			oldLoc = document.location.href;
			LoadRequestString();
			if(arrAttr.length > 1) {
				var reqStr = getHashString();
				//UpdateLocationAddress(reqStr);
				//alert(reqStr);
				//alert(getPostbackAction());
				DoPostBack("", getPostbackAction(), "CMSService.php");
			} else {
				var Att = document.getElementById("AddressAttributes");
				//alert(Att.innerHTML);

				UpdateLocationAttributes(Att.innerHTML);
			}
			PoolAddressChanges();
		}

		if(navigator.appName == "Microsoft Internet Explorer" || navigator.appName.indexOf("Safari") != -1) {
			if(parent == self) {
				LoadRequestString();

				if(!historyFrame) {
					historyFrame = document.createElement("IFRAME");
					historyFrame.setAttribute("ID", "Ime");
					historyFrame.setAttribute("style", "position:absolute;top:-1000;left:-1000;display:none !important;");
					historyFrame.setAttribute("src", "historyFrame.php" + getRequestString() + "&title=" + document.title);
					
					historyFrame.setAttribute("WIDTH", "0");
					historyFrame.setAttribute("HEIGHT", "0");

					historyFrame.style.position = "absolute";
					historyFrame.style.left = -1000;
					historyFrame.style.top = -1000;
					document.body.appendChild(historyFrame);

				}
				historyCache[getRequestString() + "&title=" + document.title] = getPostbackAction();
				historyFrame.contentWindow.location.href = "historyFrame.php" + getRequestString() + "&title=" + document.title;
			}
		}
	}
}

function historyFrameOnLoad() {
    var loc = historyFrame.contentWindow.location.href;
    var pos = loc.indexOf("?", 0);
    var rs = loc.substr(pos);

    if(rs != getRequestString() + "&title=" + document.title) {
        DoPostBack('', historyCache[rs], 'CMSService.php');
    }
}
