

 /*****************************************
 * saintForms.js
 *
 * All JavaScript functions needed for handling SAINT 7.0
 *
 * Author: Brian Stull except those w/ //v## tags.
 * Version: 1/29/09
 *
 *****************************************/



/* Globals *******************************/
var oldDiv = "div0";			// panel_tabs current div
var oldTab = "tab0";			// panel_tabs current tab
var oldGenDiv = "none";			// generic current div
var oldElems = new Array("","");// forgot what this is. oh no.
/*****************************************/



/** 
 * Handle movement on ip boxes.
 * user presses '.' means jump to next box.
 * should only be used onKeyUp event.
 */
function jumpOct(e, current, next)
{	var curVal = current.value;
	var key;

	if (e.keyCode) key = e.keyCode;
	else if (e.which) key = e.which;

	if (key == 190) /* '.' */        // <-- looks like a bat.
	{	if ( /\./.test(curVal) )	
		{	current.value = curVal.substr(0, curVal.indexOf('.'));
		}
		next.select();
	}
}

/**
 * Opens a popup window.
 *
 * @param url the window location
 * @param w the width of the window
 * @param h the height of the window
 * @param resizeable is the window resizeable?
 */
function openWindow(url,w,h,resizeable)
{	window.open(url,
		"poppedwin",
		"'location=0,status=0,scrollbars=0,width="+w+",height="+h+",resizable="+resizeable+"'");
}

/**
 * Deals with category select boxes for configuration pages.
 *
 * @param elem the new drop down menu to display.
 * @param menuType the new drop down menu's type (category or option)
 */
function cf_menu_action(elem,menuType,hc)
{

	if (menuType == 0)
		if (oldElems[1] != "")
			hide(oldElems[1]);

	if (oldElems[menuType] && oldElems[menuType] != "none")
		hide(oldElems[menuType]);

	if (elem != "none" )
		show(elem);
	else
		setElemHeight('cfg_item_frame'+hc+'', 0);

	oldElems[menuType] = elem;
}

/**
 * Displays the option selected from a configuration pages option select box.
 *
 * @param cfUrl the item to display (cf_item_... blah blah)
 */
function cf_option_disp(cfUrl,hc)
{
	if (cfUrl != "none")
	{
		window.frames['cfg_item_frame'+hc+''].location.href = 'not_supported.html';
		setElemHeight('cfg_item_frame'+hc+'', 275);
	}
	else
		setElemHeight('cfg_item_frame'+hc+'', 0);
}

/**
 * Panel_tabs div show/hide function
 *
 * @param divId the div to show.
 */
function swapDiv(divId)
{
	if (oldDiv != "none")
		hide(oldDiv);

	show(divId);
	oldDiv = divId;
}

/**
 * Panel_tabs tab show/hide function
 *
 * @param tabId the tab to show.
 */
function swapTab(tabId)
{
	if (oldTab != "none")
		document.getElementById(oldTab).className = 'tabOff';

	document.getElementById(tabId).className = 'tabOn';
	oldTab = tabId;
}

/**
 * Sets the current panel div and current panel tab.
 *
 * @param divNum the tab/div index to show.
 */
function setSelectedTab(divNum) {
	oldDiv = "div"+divNum;
	oldTab = "tab"+divNum;
}

/**
 * A generic div show/hide for use without panels.
 *
 * @param divID the div to show.
 */
function genericDivSwap(divID)
{
	if (oldGenDiv != "none")
		hide(oldGenDiv);
	
	if (divID != "none")
		show(divID);
	
	oldGenDiv = divID;
}

/**
 * Helper method to set an elements height.
 *
 * @param eid the element
 * @param nHeight the new height of the element.
 */
function setElemHeight(eid, nHeight)
{
	document.getElementById(eid).style.height = nHeight;
}

/**
 * Helper method to display a div.
 *
 * @param id the div to display.
 */
function show(id)
{
	if (id != null)
		document.getElementById(id).style.display = 'block';
}

/**
 * Helper method to hide a div.
 *
 * @param id the div to hide.
 */
function hide(id)
{
	if (id != null)
		document.getElementById(id).style.display = 'none';
}

/**
 * Sets the color of text in an element.
 *
 * @param id the element that the text is in.
 * @param color the color to set.
 */
function swap_text_color_by_id(id, color)
{
	if (id != null)
		document.getElementById(id).style.color = color;
}

/**
 * Same as above but specific to saint_run_form.pl
 *   -> should probably put this function in there.
 */
function swap_text_color_by_id_test_length(myid,myid2,chid)
{
	if (myid != null && myid2 != null && chid != null)
	{
		var chelem = document.getElementById(chid);
		if (myid.value.length > 0 || myid2.value.length > 0)
			chelem.style.color = 'green';
		else
			chelem.style.color = '#b41c2d';
	}
}

function flipall(arg)
{	if (arg.value==0) 
	{	show('auth_nocred');
	} else 
	{	hide('auth_nocred');
	}
}

function flipallres(arg) {
	if (arg.value==0) 
	{	show('auth_nocredres');
	} else
	{	hide('auth_nocredres');
	}
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


