// Copyright Textic Ltd. 2004. Unauthorised use is prohibited
// Change these depending on the installation site
ckDomain = '';//null for localhost
ckPath = '/';
ckExpiry = 0;//days
csspath='/css/';
despath='/design72/';
//csspath='/textic/rachel/css/';
//despath='/textic/design3/';

var clickmessage="Copyright Textic Ltd. 2005. Unauthorised use is prohibited";

function disableclick(e) {
    if (document.all) {
        if (event.button==2||event.button==3) {
                alert(clickmessage);
            return false;
            }
        }
    else if (document.layers) {
        if (e.which == 3) {
            alert(clickmessage);
        return false;
        }
    }
    else if (document.getElementById){
        if (e.which==3){
            alert(clickmessage)
        return false
        }
    }
}

function resetall() {
    // Clear all cookies and reload
	deleteCookie('font', ckPath, ckDomain);
	deleteCookie('face', ckPath, ckDomain);
	deleteCookie('contrast', ckPath, ckDomain);
	deleteCookie('design', ckPath, ckDomain);
    window.location.reload();
}



/*
if (document.all)
    document.onmousedown=disableclick
else if (document.getElementById)
    document.onmouseup=disableclick
*/

function setStyle(attrib, value, clear) {
    // Clear the cookie setting, revert to the default style for this attribute
    if (clear) {
        deleteCookie(attrib, ckPath, ckDomain);
    } else {
        setCookie(attrib, value, ckExpiry, ckPath, ckDomain);
    }
    window.location.reload();
}

// Cookie code from: http://www.netspade.com/articles/javascript/cookies.xml
function setCookie(name, value, expires, path, domain, secure)
{

    if (expires) {
        var expireDate = new Date();
        expireDate.setTime(expireDate.getTime() + 3600000*24*expires);
    }
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expireDate.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));
}

function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function setchoice(cobj,cvalue){
//set choice for dropdown
for (var i=0;i<cobj.options.length;i++){
if(cobj.options[i].value==cvalue) {
cobj.selectedIndex=i;break;
}
}
}

function setchoices(){
//set dropdown choices
setchoice(document.getElementById('toolbar').sizeselect,fontc);
setchoice(document.getElementById('toolbar').faceselect,facec);
setchoice(document.getElementById('toolbar').colourselect,contrastc);
setchoice(document.getElementById('toolbar').designselect,designc);
if (facec=='textichotplus' || facec=='texticcoolplus') vowels(facec);
}

// This final code writes the selector for the correct CSS sheets into the header of the page
fontc=getCookie('font');
contrastc=getCookie('contrast');
facec=getCookie('face');
designc=getCookie('design');

if (designc) {
    document.write('<link rel="stylesheet" type="text/css" href="'+despath+designc+'.css" />\n');
} else { }

if (fontc) {
    document.write('<link rel="stylesheet" type="text/css" href="'+csspath+fontc+'.css" />\n');
} else { }

if (contrastc) {
    document.write('<link rel="stylesheet" type="text/css" href="'+csspath+contrastc+'.css" />\n');
} else { }

if (facec) {
    document.write('<link rel="stylesheet" type="text/css" href="'+csspath+facec+'.css" />\n');
} else { }

function cookies(){
document.write('<input type="hidden" name="setfont" value="'+fontc+'">');
document.write('<input type="hidden" name="setcontrast" value="'+contrastc+'">');
document.write('<input type="hidden" name="setface" value="'+facec+'">');
}

function vowels(color){
html=document.getElementById('content').innerHTML;
l=html.length;
out='';tag=false;vowel=false;entity=false;
for (i=0;i<l;i++) {
c=html.charAt(i);
if (c=='<') {
tag=true;
if (vowel) {
c='</span>'+c;vowel=false;
}
}
else if (c=='>') tag=false;
else if (!tag){
if (c=='&') entity=true;
else if (c==';') entity=false;
if ('aeiou'.indexOf(c)>=0 && !entity){
if (!vowel) {
c='<span class="v">'+c;vowel=true;
}
}
else{
if (vowel) {
c='</span>'+c;vowel=false;
}
}
}
out+=c;
}
document.getElementById('content').innerHTML=out;
}