window.onload = function() {
    Element.hide('wireResults');
    Element.hide('circuitRequirements');
    $$('.tooltip').each(function(tooltip){Element.hide(tooltip)});
    hide_disclaimer_if_accepted();
    tipsHidden = readCookie('tipsHidden') || 0;
    if(tipsHidden != 0) { turn_off_help(); }
    else { turn_on_help(); }
    Element.hide('change_my_entries');
    setTopMenuHovers();
}

function col_light (e) {
    if (!e) e =  window.event;
    var obj = e.srcElement || e.target;
    var tname = (obj.nodeType == 1) ? obj.tagName.toLowerCase() : '';

    while(tname != "table" && tname !="td"){
            obj= obj.parentNode || obj.parentElement;
            tname = obj.tagName.toLowerCase();
    }

    if (tname == "td") {
        var newClass;

        switch (e.type) {
        case 'mouseout':
            newClass = '';
            break;
        case 'mouseover':
            newClass = 'hlt';
            break;
        }
        var cellIdx = getCellIndex(obj);

        obj= obj.parentNode || obj.parentElement; //row
        obj= obj.parentNode || obj.parentElement; //tbody

        for (var i = 0; i < obj.rows.length; i++) {
            obj.rows[i].cells[cellIdx].className = newClass;
        }
    }
}//end col_light

function getCellIndex(cell) {

    var rtrn = cell.cellIndex || 0;
    if (rtrn == 0) {
        do{
            if (cell.nodeType == 1) rtrn++;
            cell = cell.previousSibling;
        } while (cell);
        rtrn--;
    }
    return rtrn;
}//eof getCellIndex

function getRowIndex(row) {
    var rtrn = row.sectionRowIndex || 0;
    if (rtrn == 0) {
        do{
            row = row.previousSibling;
        } while (row, rtrn++);
        --rtrn;
    }
    return rtrn;
}//eof getRowIndex



function row_light(e) {
    e = e || event;
    var obj = e.target || e.srcElement;
    
    var tname = (obj.nodeType == 1) ? obj.tagName.toLowerCase() : '';
    
    while (tname != 'tr' && tname != 'table') {
        obj = obj.parentNode || obj.parentElement;
        tname = obj.tagName.toLowerCase();
    }

    if (tname == 'tr') {
        switch (e.type) {
        case 'mouseover':
            obj.className = 'hlt';
            break;
        case 'mouseout':
            obj.className = "";
                break;
        }
    }
}



function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
} // eof createCookie

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
} // eof readCookie

function eraseCookie(name) {
	createCookie(name,"",-1);
} // eof eraseCookie

                

function show_tip(thisTip) {
    thisTip = thisTip || "default_help";
    tipsHidden = readCookie('tipsHidden') || 0;
    if(tipsHidden != 1) {
        $$('.tooltip').each(function(tooltip){Element.hide(tooltip)});
        $$('.for_'+thisTip).each(function(tooltip){Element.show(tooltip)});
    }
} // eof show_tip

function turn_off_help() {
    createCookie('tipsHidden', 1, 30);
    $$('.tooltip').each(function(tooltip){Element.hide(tooltip)});
    $$('#hide_help').each(function(element){Element.hide(element)});
    $$('#show_help').each(function(element){Element.show(element)});
} // eof turn_off_help

function turn_on_help() {
    createCookie('tipsHidden', 0, 30);
    $$('#show_help').each(function(element){Element.hide(element)});
    $$('#hide_help').each(function(element){Element.show(element)});
    show_tip("default_help");
} // eof turn_on_help

function accept_disclaimer() {
    createCookie('tipsHidden', 0, 30);
    createCookie('disclaimerAccepted2', 1, 90);
    hide_disclaimer_if_accepted();
} // eof accept_disclaimer

function hide_disclaimer_if_accepted() {
    accepted = readCookie('disclaimerAccepted2') || 0;
    if (accepted == 1) {
        Element.hide('disclaimer');
        Element.show('disclaimer_show');
        Element.hide('disclaimer_acceptance');
        Element.show('forms_container');
    }
    else { Element.hide('disclaimer_show');
        Element.hide('forms_container');
    }
} // eof hide_disclaimer_if_accepted

function show_disclaimer() {
    Element.show('disclaimer');
    Element.hide('disclaimer_show');
    Element.show('disclaimer_acceptance');
}

function show_for_changes() {
    $$('#circuitProtectionTableDiv').each(function(element){Element.hide(element)});
    $$('#circuitRequirements').each(function(element){Element.hide(element)});
    $$('#wireResults').each(function(element){Element.hide(element)});
    
    Element.show('ffcp');
    Element.show('ffwt');
}

function show_only_fuses() {
    $$('.Fuse').each(function(element){Element.show(element)});
    $$('.Breaker').each(function(element){Element.hide(element)});
}

function show_only_cbs() {
    $$('.Fuse').each(function(element){Element.hide(element)});
    $$('.Breaker').each(function(element){Element.show(element)});
}

function show_fuses_and_cbs() {
    $$('.Fuse').each(function(element){Element.show(element)});
    $$('.Breaker').each(function(element){Element.show(element)});
}

function setTopMenuHovers(){
    $$('#topmenu img.with_hover').each(function(element){
        element.onmouseover = function(element) {
            var osrc=this.src;
            this.src = osrc.replace(/_unsel\.png/g,"_highlight.png");
        }
        element.onmouseout = function(element) {
            var osrc=this.src;
            this.src = osrc.replace(/_highlight\.png/g,"_unsel.png");
        }
    });
}