// OSC javascript code lib

function browser_fix()
{
	//alert(1);
}

//testing function
function menu_trace()
{
	trace = "Main Cookie:\t"+document.cookie;
	trace += "\nkbase_nav:\t"+readCookie('KBASE_NAV');
	trace += "\nosc_nav:\t"+readCookie('OSC_NAV');
	trace += "\nadmin_nav:\t"+readCookie('ADMIN_NAV');
	alert(trace);
}

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=/";
}

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;
}

function toggle_byclass(c) 
{
	var show = function(r) {
		target = r; 
		if (target.style.display == "none") { target.style.display = ""; } else { target.style.display = "none"; }
	
	}; $$('.'+c).each(show);

}

function toggle_kbase(nav_name, row)
{
	var kbase_nav = readCookie('KBASE_NAV');
	
	if(kbase_nav == "showing")
	{
		show_hideDisplay(nav_name, 'hide');
		row.style.backgroundColor = '#FFFFFF';
		createCookie('KBASE_NAV','hidden',0)
	}
	
	if(kbase_nav == "hidden")
	{
		show_hideDisplay(nav_name, 'show');
		row.style.backgroundColor = '#EFFBFF';
		createCookie('KBASE_NAV','showing',0)
	}
}

function toggle_fav(nav_name, row)
{
	var fav_nav = readCookie('FAV_NAV');
	
	if(fav_nav == "showing")
	{
		show_hideDisplay(nav_name, 'hide');
		row.style.backgroundColor = '#FFFFFF';
		createCookie('FAV_NAV','hidden',0)
	}
	
	if(fav_nav == "hidden")
	{
		show_hideDisplay(nav_name, 'show');
		row.style.backgroundColor = '#EFFBFF';
		createCookie('FAV_NAV','showing',0)
	}
}

function toggle_osc(nav_name, row)
{
	var osc_nav = readCookie('OSC_NAV');
	
	if(osc_nav == "showing")
	{
		show_hideDisplay(nav_name, 'hide');
		row.style.backgroundColor = '#FFFFFF';
		createCookie('OSC_NAV','hidden',0)
	}
	
	if(osc_nav == "hidden")
	{
		show_hideDisplay(nav_name, 'show');
		row.style.backgroundColor = '#EFFBFF';
		createCookie('OSC_NAV','showing',0)
	}
}

function toggle_support(nav_name, row)
{
	var support_nav = readCookie('SUPPORT_NAV');
	
	if(support_nav == "showing")
	{
		show_hideDisplay(nav_name, 'hide');
		row.style.backgroundColor = '#FFFFFF';
		createCookie('SUPPORT_NAV','hidden',0)
	}
	
	if(support_nav == "hidden")
	{
		show_hideDisplay(nav_name, 'show');
		row.style.backgroundColor = '#EFFBFF';
		createCookie('SUPPORT_NAV','showing',0)
	}
}

function toggle_admin(nav_name, row)
{
	var admin_nav = readCookie('ADMIN_NAV');
	
	if(admin_nav == "showing")
	{
		show_hideDisplay(nav_name, 'hide');
		row.style.backgroundColor = '#FFFFFF';
		createCookie('ADMIN_NAV','hidden',0)
	}
	
	if(admin_nav == "hidden")
	{
		show_hideDisplay(nav_name, 'show');
		row.style.backgroundColor = '#EFFBFF';
		createCookie('ADMIN_NAV','showing',0)
	}
}

function show_hide(id, action)
{
	if(document.all && !document.getElementById)
	{
		if(action == "show")
			document.all[id].style.visibility = 'visible';
		
		if(action == "hide")
			document.all[id].style.visibility = 'hidden';
		return true;	
	}
	
	if(document.layers && !document.getElementById)
	{
		if(action == "show")
			document.layers[id].visibility = 'show';
			
		if(action == "hide")
			document.layers[id].visibility = 'hide';
		return true;
	}
	
	if(document.getElementById)
	{
		if(action == "show")
			document.getElementById(id).style.visibility = 'visible';
			
		if(action == "hide")
			document.getElementById(id).style.visibility = 'hidden';
		return true;
	}
	
	alert("PLEASE UPGRADE YOUR BROWSER.");
	return false;
}

function show_hideDisplay(id, action)
{	
	if(document.all && !document.getElementById)
	{
		if(action == "show")
			document.all[id].style.display = 'block';
		
		if(action == "hide")
			document.all[id].style.display = 'none';
		return true;	
	}
	
	if(document.layers && !document.getElementById)
	{
		if(action == "show")
			document.layers[id].display = 'block';
			
		if(action == "hide")
			document.layers[id].display = 'none';
		return true;
	}
	
	if(document.getElementById)
	{
		if(action == "show")
			document.getElementById(id).style.display = 'block';
			
		if(action == "hide")
			document.getElementById(id).style.display = 'none';
		return true;
	}
	
	alert("PLEASE UPGRADE YOUR BROWSER.");
	return false;
}

function move_top(id, pix)
{
	if(document.all && !document.getElementById)
	{
		document.all[id].style.top = pix;
		return true;	
	}
	
	if(document.layers && !document.getElementById)
	{
		document.layers[id].top = pix;
		return true;
	}
	
	if(document.getElementById)
	{
		document.getElementById(id).style.top = pix;
		return true;
	}
	
	alert("PLEASE UPGRADE YOUR BROWSER.");
	return false;
}

//javascript:newWindow('')
function newWindow(image,w,h) 
{
	imageWindow = window.open(image, 'imageWin'+Math.random()*1000, 'width='+w+',height='+h+',scrollbars=yes,resize=yes');
	imageWindow.focus();
}

//prints out all form[] in new window
function show_formVars(formName)
{
	varWin = window.open('', 'varWin', 'toolbar=yes,width=600,height=550,scrollbars=yes,resize=yes');
	
	varWin.document.write("<html><title>From Name: "+formName.name+"</title>");
	for (var i = 0; i < formName.elements.length; i++)
	{
       	formField_obj = formName.elements[i];	
		varWin.document.write("&lt;cfparam name=\"form."+formField_obj.name+"\" default=\"N / A\"&gt;<br>\n"); 
	}
	varWin.document.write("</body></html>");
	varWin.document.close();
}

function set_action(list)
{
	var app_path = "http://library.cpmc.columbia.edu/ic/oscAdmin_kbase/";
	
	if(list.value == "main")
		document.osc_show.action = app_path+"err_tool.cfm";
	if(list.value == "software")
		document.osc_show.action = app_path+"show/show_software.cfm";
	if(list.value == "hardware")
		document.osc_show.action = app_path+"show/show_hardware.cfm";
	if(list.value == "firewallin")
		document.osc_show.action = app_path+"show/show_firewallin.cfm";
	if(list.value == "firewallout")
		document.osc_show.action = app_path+"show/show_firewallout.cfm";
	if(list.value == "ntpatch")
		document.osc_show.action = app_path+"show/show_ntpatch.cfm";
	if(list.value == "ipnew")
		document.osc_show.action = app_path+"show/show_ipnew.cfm";
	if(list.value == "ipupdate")
		document.osc_show.action = app_path+"show/show_ipupdate.cfm";
	if(list.value == "dns")
		document.osc_show.action = app_path+"show/show_dns.cfm";
	if(list.value == "bandwith")
		document.osc_show.action = app_path+"show/show_bandwith.cfm";
	if(list.value == "corptime")
		document.osc_show.action = app_path+"show/show_corptime.cfm";
	if(list.value == "netid")
		document.osc_show.action = app_path+"show/show_netid.cfm";
	if(list.value == "uni")
		document.osc_show.action = app_path+"show/show_uni.cfm";
	if(list.value == "saswin")
		document.osc_show.action = app_path+"show/show_sasw.cfm";
	if(list.value == "sasunix")
		document.osc_show.action = app_path+"show/show_sasu.cfm";
	if(list.value == "spss")
		document.osc_show.action = app_path+"show/show_spss.cfm";	
}

function update_outage(formName)
{
	document.p_outage.elements["id"].value = formName.elements["id"].value;
	document.p_outage.elements["outage"].value = formName.elements["outage"].value;
	document.p_outage.elements["level"].value = formName.elements["level"].value;
	document.p_outage.elements["description"].value = formName.elements["description"].value;
	document.p_outage.elements["submit"].value = "Update";
	show_hideDisplay("newrec", "show");
}

var tinyMCEmode = true;
function toogleEditorMode(sEditorID) {
    try {
        if(tinyMCEmode) {
            tinyMCE.removeMCEControl(tinyMCE.getEditorId(sEditorID));
            tinyMCEmode = false;
        } else {
            tinyMCE.addMCEControl(document.getElementById(sEditorID), sEditorID);
            tinyMCEmode = true;
        }
    } catch(e) {
        //error handling
    }
}