
function SetText( object, text )
{
    if( isIE )
    {
        object.innerText = text;
    }
    else
    {
        object.textContent = text;
    }
}

function CreateLabel( parent, label, button )
{
    var id      = label[0];
    var text    = label[1];
    var x       = label[2];
    var y       = label[3];
    var link    = label[4];
    
    var label;
	var label2;
    var css = button ? "button" : "label";

    if( isIE )
    {
        var tag = "<div";
	    if( button )
	    {
	        tag += " onclick=\"" + link + "\"";
	    }
	    else
	    {
	        tag += " onclick=\"NewMap(" + link + ");\"";
	    }
        tag += ">";

        label = document.createElement( tag );
	    label2 = document.createElement( "<div>" );
    }
    else
    {
        label = document.createElement( "div" );
	    label2 = document.createElement( "div" );

	    if( button )
	    {
	        label.setAttribute( "onclick", link );
	    }
	    else
	    {
	        label.setAttribute( "onclick", "NewMap(" + link + ");" );
	    }
    }


	//var tag = "<div id=\"" + id + "\" class=\"" + css + "\" unselectable=\"on\" style=\"left: " + x + "px; top: " + y + "px;\""
    label.id = id;
    label.className = css;
    label.UNSELECTABLE = "on";
    label.style.left = x + "px";
    label.style.top = y + "px";

	//var tag2 = "<div class=\"" + css + "2\" unselectable=\"on\"></div>";
    label2.className = css + "2";
    label2.UNSELECTABLE = "on";
	SetText( label2, text );

	parent.appendChild( label );
	label.appendChild( label2 );
}

function Show( obj, show )
{
    obj.style.visibility = show ? "visible" : "hidden";
}

function ShowBlock( obj, show )
{
    obj.style.display = show ? "block" : "none";
}


// Create a cookie with the specified name and value.
// The cookie expires after 30 days.
function SetCookie(sName, sValue)
{
    date = new Date();
    date.setTime( date.getTime()+(30*24*60*60*1000) );
    document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}

function SetMemCookie(sName, sValue)
{
    document.cookie = sName + "=" + escape(sValue);
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0]) 
            return unescape(aCrumb[1]);
    }

    // a cookie with the requested name does not exist
    return null;
}

function ReadParam()
{
    return srchString = unescape( location.search.substr(1, location.search.length) );
}

function GetScrollSize()
{
    // Get scroll size
    mapObj.style.width = "80px";
    mapObj.style.height = "80px";
    vertScroll = scrollObj.offsetWidth - scrollObj.clientWidth;
    horizScroll = scrollObj.offsetHeight - scrollObj.clientHeight;
    mapObj.style.width = "auto";
    mapObj.style.height = "auto";

    // Firefox bug?
    if( vertScroll == 0 )
    {
        vertScroll = horizScroll;
    }
}

function GetScrollPos()
{
    // Get scroll positions
    scrollObj.scrollLeft = GetCookie( "scrollLeft" );
    scrollObj.scrollTop = GetCookie( "scrollTop" );
}	

function SetScrollPos()
{
    // Store scroll positions
    SetCookie( "scrollLeft", scrollObj.scrollLeft );
    SetCookie( "scrollTop", scrollObj.scrollTop );
}

function ResizeMap()
{
    var clientHeight = isIE ? document.documentElement.clientHeight : window.innerHeight;
    var maxWidth = document.body.clientWidth - 24;
    var maxHeight = clientHeight - titleObj.offsetHeight - panelObj.offsetHeight - 4;
    var mapWidth = mapObj.offsetWidth;
    var mapHeight = mapObj.offsetHeight;

    var width = 0;
    var height = 0;

    //alert( maxWidth + " " + maxHeight + " " + mapWidth + " " + mapHeight );
    //alert( clientHeight );
    //alert( panelObj.offsetHeight );
    
    // Need horizontal bar?
    if( mapWidth > maxWidth )
    {
        width = maxWidth;

        // Need vertical scroll bar?
        if( mapHeight > maxHeight - horizScroll )
        {
            height = maxHeight;
        }
        else
        {
            height = mapHeight + horizScroll;
        }
    }
    // Need vertical bar?
    else if( mapHeight > maxHeight )
    {
        height = maxHeight;

        // Need horizontal scroll bar?
        if( mapWidth > maxWidth - vertScroll )
        {
            width = maxWidth;
        }
        else
        {
            width = mapWidth + vertScroll;
        }
    }
    else
    {
        width = mapWidth;
        height = mapHeight;
    }

    // Set scroll size
    scrollObj.style.width = width + "px";
    scrollObj.style.height = height + "px";

    // Set frame size
    frameObj.style.width = width + "px";
    frameObj.style.height = height + "px";
}

function ResetFrame()
{
    Show( e("logo"), false );
    Show( frameObj, false );

    scrollObj.scrollLeft = 0;
    scrollObj.scrollTop = 0;
    frameObj.style.width = "0px";
    frameObj.style.height = "0px";
    mapObj.style.width = "0px";
    mapObj.style.height = "0px";

	ShowBlock( e("loading"), true );
    //alert("a");
}


