/////////////////////////////
function runExample(page)
/////////////////////////////
{
	if (location.protocol != 'http:' && location.protocol != 'https:')
		httpMsg('Sample applications')
	else
		selectPage('samples/' + page)
}

/////////////////////////////
function runSample(e)
/////////////////////////////
{
	var sampleType 
	if (document.getElementById("serverSampleTable") != null)
		sampleType = (document.getElementById("serverSampleTable").style.display == "none") ? "Client" : "Server"
	else
		sampleType = ""

	selectPage('samples/' + e.getAttribute("url") + "?title=" + escape( e.getAttribute("description") ) + "&sampletype=" + sampleType)
}

/////////////////////////////
function selectPage(page, tab)
/////////////////////////////
{
	switch ( page )
	{
		case "install.hta":
			window.open( "install.hta?installdir=" + installPath + "&tab=" + tab );
			break;
		case "language.hta":
			window.open( "language.hta?installdir=" + installPath );
			break;
		case "designer/designer.aspx":
			if ( document.all )
				location.href = page;
			else
				alert("Internet Explorer is required for the Designer application")
			break;
		default:
			location.href = page;
			break;
	}
}

/////////////////////////////
function selectSample(i)
/////////////////////////////
{
	var e = document.getElementById("sampleList");

	if ( typeof(i) != "number" )
		i = e.selectedIndex;
	else
	{
		i = e.selectedIndex + i;
		if ( i == e.options.length || i < 0)
			return
	}
	
	var title = e.options[ i ].text.replace(/\d{1,}\. /,"");

	var url = e.options[ i ].value + '?title=' + escape(title)
	selectPage( url)
}

/////////////////////////////
function httpMsg(app)
/////////////////////////////
{
	alert( 'Menu must be running under the http protocol to launch ' + app + '. \n\n i.e. http://servername/dbnetcombo/docs/index.htm')
}

/////////////////////////////
function connectionTest()
/////////////////////////////
{
	location.href = 'common/util/connection_test.aspx'
}

/////////////////////////////
function selectTab(tab)
/////////////////////////////
{
	if ( tab.className == "selectedTab" )
		return;

	document.getElementById("sample").style.display = ( tab.id == "sourceTab" ) ? "none" : ""
	document.getElementById("source").style.display = ( tab.id == "sourceTab" ) ? "" : "none"

	document.getElementById("sampleTab").className = ( tab.id == "sourceTab" ) ? "tab" : "selectedTab"
	document.getElementById("sourceTab").className = ( tab.id == "sourceTab" ) ? "selectedTab" : "tab"
}

/////////////////////////////
function selectMenuTab(tab)
/////////////////////////////
{
	if ( tab.className == "selectedTab" )
		return;
	if (document.getElementById("serverSampleTable") == null)
		return;

	setCookie("selectedMenuTab", tab.id, 30)
	
	document.getElementById("clientSampleTable").style.display = ( tab.id == "serverTab" ) ? "none" : ""
	document.getElementById("serverSampleTable").style.display = ( tab.id == "serverTab" ) ? "" : "none"

	document.getElementById("clientTab").className = ( tab.id == "serverTab" ) ? "menuTab" : "selectedMenuTab"
	document.getElementById("serverTab").className = ( tab.id == "serverTab" ) ? "selectedMenuTab" : "menuTab"
}


window.onload = windowLoad
window.onresize = resizeScroller


/////////////////////////////
function windowLoad()
/////////////////////////////
{
	getMenuTabCookie()
	resizeScroller()
}

/////////////////////////////
function getMenuTabCookie()
/////////////////////////////
{
	if (document.getElementById("serverSampleTable") == null)
		return;
	var c = getCookie("selectedMenuTab")
	if ( (c != null) && (c != "") )
		selectMenuTab( document.getElementById(c) )
	else
		selectMenuTab( document.getElementById("clientTab") )
}


/////////////////////////////
function resizeScroller()
/////////////////////////////
{
	scrollerResize("clientSampleTableScroller")
	scrollerResize("serverSampleTableScroller")
}

/////////////////////////////
function scrollerResize(id)
/////////////////////////////
{
	if ( ! document.getElementById( id ) )
		return;

	var e = document.getElementById( id )
	var y 
	if ( document.all )
		y = document.body.offsetHeight;
	else
		y = window.innerHeight;

	e.style.height = y - 200;
}

//////////////////////////////////////////////////////////////////////////////////////////////
function setCookie(name, value, expires, path, domain, secure)
//////////////////////////////////////////////////////////////////////////////////////////////
{
	var now = new Date()
	var days = 1000 * 60 * 60 * 24

    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + new Date( now.valueOf() + ( expires * days) ).toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

//////////////////////////////////////////////////////////////////////////////////////////////
function getCookie(name)
//////////////////////////////////////////////////////////////////////////////////////////////
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}