/*
# Written by Robb Garrioch, Copyright © 2001-2009
# functions checkBrowser() & openWin()
# written by Danny Goodman & the Project Cool guy respectively.
*/



function dostuff()
{
    checkBrowser()
}



function checkBrowser()
{
    var b = navigator.appName
    if (b == "Netscape")
        this.b = "ns"
    else if (b == "Microsoft Internet Explorer")
        this.b = "ie"
    else
        this.b = b
    this.v = parseInt(navigator.appVersion)
    this.ns =  (this.b == "ns" && this.v >= 4)
    this.ns3 = (this.b == "ns" && this.v < 4)    
    this.ns4 = (this.b == "ns" && this.v == 4)
    this.ns5 = (this.b == "ns" && this.v == 5)

    this.ie =  (this.b == "ie" && this.v >= 4)
    this.ie3 = (this.b == "ie" && this.v < 4)   // might not be relavent

    this.ie4 = (navigator.userAgent.indexOf('MSIE 4') > 0)
    this.ie5 = (navigator.userAgent.indexOf('MSIE 5') > 0)    
    this.ie6 = (navigator.userAgent.indexOf('MSIE 6') > 0)    
    this.ie7 = (navigator.userAgent.indexOf('MSIE 7') > 0)    
    this.ie8 = (navigator.userAgent.indexOf('MSIE 8') > 0)    
    if(this.ie5 || this.ie6 || this.ns5 || this.ie7 || this.ie8)
        this.dom = (this.ie5 || this.ie6 || this.ie7 || this.ie8 || this.ns5)
    this.min = (this.ns || this.ie) // do we have the minimum browser specs
}
is = new checkBrowser();            // Browser object instance required for CSS layer fixes


function gohref(url)
{
    window.location = url
}




function setbgcolor(id, color)
{
    if(is.ns4)
    {
        document.layers[id].document.bgColor = color
    }
    else if(is.ie4)
    {
        document.all[id].style.backgroundColor = color
    }
    else if(is.dom)
    {
        str = "document.getElementById('" + id + "').style.backgroundColor = '" + color + "'"
        eval(str)
    }
}







function menu(arrname, opt)
{
    if(opt == 'in')
    {
        if(isstateone(arrname))		// if state is one then roll menu in
        {
            rollmenu(arrname, 'in')
            clearstate(arrname)
        }
    }
    else if(opt == 'out')
    {
        rollmenu(arrname, 'out')
        setstate(arrname)
    }
    else if(opt == 'dual')
    {
        if(isstateone(arrname))	// if state is one then roll menu in
        {
            rollmenu(arrname, 'in')
            clearstate(arrname)
        }
        else			// is state is zero then roll menu out
        {
            rollmenu(arrname, 'out')
            setstate(arrname)
        }
    }
}

function isstateone(arrname)
{
    var str2 = "tempstate = " + arrname + "state"
    eval(str2)
    if(tempstate == 1)
        return true
    else
        return false    
}

function setstate(arrname)
{
    var str
    str = arrname + "state = 1"
    eval(str)
}

function clearstate(arrname)
{
    var str
    str = arrname + "state = 0"
    eval(str)
}



// opt can be 'out', 'in'
function rollmenu(arrname, opt)
{
    var str

    var temparr = new Array()
    str = "temparr = " + arrname
    eval(str)

    for(var t = 0; t < temparr.length; t++)
    {
        if(opt == "out")
        {
            showlayer(temparr[t])
        }
        if(opt == "in")
        {
            hidelayer(temparr[t])
        }
    }
}

function unrollall()
{
    //window.status = ""
    for(var b = (allarr.length - 1); b >= 0; b--)
    {
        if(isstateone(allarr[b]))
        {
            rollmenu(allarr[b], 'in')
            clearstate(allarr[b])
        }
    }
}

function unrollchildren(currarrname)
{
    for(var b = (allarr.length - 1); b >= 0; b--)
    {
        if(allarr[b] == currarrname)
            return
        if(isstateone(allarr[b]))
        {
            rollmenu(allarr[b], 'in')
            clearstate(allarr[b])
        }
    }
}




function getstyleobj(id)
{
    if(document.getElementById && document.getElementById(id))
    {
	return document.getElementById(id).style;
    }
    else if (document.all && document.all(id))
    {  
 	return document.all(id).style;
    } 
    else if (document.layers && document.layers[id])
    { 
 	return document.layers[id];
    }
    else
 	return false;
}



function showlayer(id)
{
    var idobj = getstyleobj(id);

    if(idobj)
    {
        idobj.visibility = 'visible';
        return true;
    }
    else
        return false;
}



function hidelayer(id)
{
    var idobj = getstyleobj(id);

    if(idobj)
    {
        idobj.visibility = 'hidden';
        return true;
    }
    else
        return false;
}


function display(id)
{
    var idobj = getstyleobj(id);

    if(idobj)
    {
        idobj.display = 'block';
        return true;
    }
    else
        return false;
}


function displaynone(id)
{
    var idobj = getstyleobj(id);

    if(idobj)
    {
        idobj.display = 'none';
        return true;
    }
    else
        return false;
}


function open_portfoliowindow(page)
{
    var width, height, center, top, left, args

    scrwidth = (document.all) ? document.body.offsetWidth : window.innerWidth
    scrheight = (document.all) ? document.body.offsetHeight : window.innerHeight

    width = scrwidth - 40
    height = scrheight - 10

    center = 1
    top = 0
    left = 0
    if((parseInt(navigator.appVersion) >= 4 ) && (center))
    {
        left = (screen.width - width) / 2;
        top = (screen.height - height) / 2;
    }

    args = "width=" + width + "," + 
           "height=" + height + "," +
           "top=" + top +"," +
           "left=" + left + "," +
           "toolbar=1," +
           "location=1," +
           "directories=0," +
           "status=0," +
           "menubar=1," +
           "scrollbars=1," +
           "resizable=1"

    var winObj = window.open(page, 'popup', args);
    winObj.focus()
}



function open_window(page, name, width, height, top, left, center)
{
    var args
    if((parseInt(navigator.appVersion) >= 4 ) && (center != "no"))
    {
        if((center == "yes") || (center == "left"))
            left = (screen.width - width) / 2;
        if((center == "yes") || (center == "top"))
            top = (screen.height - height) / 2;
    }
    args = "width=" + width + "," + 
           "height=" + height + "," +
           "top=" + top +"," +
           "left=" + left + "," +
           "toolbar=0," +
           "location=0," +
           "directories=0," +
           "status=0," +
           "menubar=0," +
           "scrollbars=1," +
           "resizable=1"

    var winobj = window.open(page, name, args);
    winobj.focus()
}


function isvalidateemail(email)
{
    if (email.length < 7 ||
    email.indexOf(" ") != -1 ||
    email.indexOf("@.") != -1 ||
    email.indexOf("-.") != -1 ||
    email.indexOf("_.") != -1 ||
    email.indexOf("..") != -1 ||
    email.indexOf("._") != -1 ||
    email.indexOf(".-") != -1 ||
    email.indexOf(".@") != -1 ||
    email.indexOf("@-") != -1 ||
    email.indexOf("@_") != -1 ||
    email.indexOf("@") != email.lastIndexOf("@") ||
    email.indexOf("@") == -1 ||
    email.indexOf(".") == -1 ||
    (email.length - (email.lastIndexOf(".") + 1)) < 2)
        return false;
    else
        return true;
}







// The credits below were as found.
// I tried to find the original owner but to no avail.
// Credits:
// "whole credits are devoted to orignal author"
var gototoptype = -1;
var gototopinterval = 0;

function goto_top_timer() {
    var y = (gototoptype == 1) ? document.documentElement.scrollTop : document.body.scrollTop;

    var moveby = 15; // set this to control scroll seed. minimum is fast

    y -= Math.ceil(y * moveby / 100);
    if (y < 0)
        y = 0;

    if (gototoptype == 1)
        document.documentElement.scrollTop = y;
    else
        document.body.scrollTop = y;

    if (y == 0) {
        clearInterval(gototopinterval);
        gototopinterval = 0;
    }
}

function goto_top()
{
    if (gototopinterval == 0)
    {
        if (document.documentElement && document.documentElement.scrollTop)
            gototoptype = 1;
        else if (document.body && document.body.scrollTop)
            gototoptype = 2;
        else
            gototoptype = 0;

        if (gototoptype > 0)
            gototopinterval = setInterval('goto_top_timer()', 25);
    }
}



dostuff();
