var viewNames = new Array('regionIndex','atozIndex');
document.currentView = viewNames[0];
function selectLeftWsTab(id) {
    for(var i = 0; i < 2; i++) {
        divId = 'leftnav_ws_tab_' + i;
        var div = document.getElementById(divId);
        if (!div) { continue; }
        if (divId == id) {
            div.style.border = 'solid #333366 1px';
            div.style.padding = '1px';
            setCookieValue(COOKIE_LEFTWSTAB,id);
            var iframe = document.getElementById('leftnav_ws');
            switchTab(viewNames[i]);
        } else {
            div.style.border = '0px';
            div.style.padding = '2px';
        }
    }
}
function getLeftWsTab(defaultTab)
{
    var val = getCookieValue(COOKIE_LEFTWSTAB);
    if (!val) { 
        val = defaultTab;
    }
    return val;
}
var printWin;
function doPrint()
{
    printWin = window.open('','printWin','width=600,height=400');
    var title = getSpanContent('title');
    printWin.document.writeln('<link href="print.css" rel="stylesheet" type="text/css">');
    printWin.document.writeln('<title>AncientScripts.com: ' + title + '</title>');
    printWin.document.writeln('<span class=title>');
    printWin.document.writeln(title);
    printWin.document.writeln('</span>');
    printWin.document.writeln('<span class="content">');
    printWin.document.writeln(getSpanContent('content'));
    printWin.document.writeln('</span>');
    printWin.document.close();
    setTimeout('realPrint()', 100);
}
function getSpanContent(name) {
    var span = document.getElementById(name);
    return span.innerHTML;
}
function realPrint() {
    if (printWin) {
        printWin.print();
        printWin.close();
        printWin = 0;
    }
}
function doSearch() {
}
function showFontSize() {
    scroll(0,0);
    var div = document.getElementById('font_size');
    div.style.visibility = 'visible';
}
function hideFontSize() {
    var div = document.getElementById('font_size');
    div.style.visibility = 'hidden';
}
function setFontSize(size) {
    var span = document.getElementById('content');
    if (span) {
        span.style.fontSize = size;
        setCookieValue('fontSize',size,false);
    }
}
function setDefaultFontSize() {
    var fontSize = getCookieValue('fontSize');
    if (fontSize) {
        setFontSize(fontSize);
    }
}

var onLoadHandlers = new Array();
function addOnLoadHandler(handler) {
	onLoadHandlers[onLoadHandlers.length] = handler;
}
function callOnLoadHandlers() {
	for(var i = 0; i < onLoadHandlers.length; i++) {
		onLoadHandlers[i]();
	}
}

var NUM_LOGOS = 6;
function randomLogo() {
	document.write("<img src=\"images/logo"+parseInt(Math.random()*NUM_LOGOS+1)+".gif\">");
}

var LEFT_ALIGN = 1;
var RIGHT_ALIGN = 2;

// implements something like printf
function Format(pattern) {
	this.fragments = new Array();
	var parts = pattern.split("%");
	var i = 1;
	while (i < parts.length) {
		var fragment = null;
		if (parts[i] == "") {
			// double %
			fragment = new FormatFragment(1, "%", LEFT_ALIGN);
		} else if (parts[i].charAt(0) == "-") {
			//parsePadding(parts[i].substring(
		} else if (parts[i].charAt(0) == "0") {
		
		} else {
		
		}
	}
	return this;
}

function parsePadding(token) {

}

function FormatFragment() {

}

function SlideShow(imageId,indexId,totalId) {
	this.pictures = new Array();
	this.imageId = imageId;
	this.indexId = indexId;
	this.totalId = totalId;
	this.index = 0;
	this.addPicture = function(url) {
		var image = new Image();
		image.src = url;
		this.pictures[this.pictures.length] = image;
	}
	this.getPictureCount = function() {
		return this.pictures.length;
	}
	this.gotoPictureAt = function(index) {
		this.index = index;
		var image = document.getElementById(this.imageId);
		if (image) {
			image.src = this.pictures[this.index].src;
			this.updateTextBlocks();
		}
	}
	this.gotoNextPicture = function() {
		this.gotoPictureAt((this.index + 1) % this.pictures.length);
	}
	this.gotoLastPicture = function() {
		var i = this.index - 1;
		if (i < 0) { 
			i += this.pictures.length; 
		}
		this.gotoPictureAt(i);
	}
	this.updateTextBlocks = function() {
		var indexBlock = document.getElementById(this.indexId);
		indexBlock.innerHTML = this.index + 1;
		var totalBlock = document.getElementById(this.totalId);
		totalBlock.innerHTML = this.pictures.length;
	}
	return this;
}

if (navigator.userAgent.indexOf("MSIE")) {
    document.writeln("<style>.u { font-family: Microsoft Sans Serif; }</style>");
}
var fc_pagename = document.title.substring(17);

