// ga.shared.js

/*
 * functions: 
 * @$,showJsDebugx,setElementValue,submitForm,logout
 * setHeaderText,showHideDiv,ebug,basename
 */
		
//submitForm
//
// assumes form has a _form_action input field
//
// if arg[1] provided, display that as confirmation text, and only proceed upon accept
//
function submitForm( action ) {
	if (arguments.length > 1) {
		if (!confirm(arguments[1]) ) {
			return false;
		} 
	}
	document.frmMain._form_action.value = action; 
	document.frmMain.submit(); 
}
		

// setField
//
// sets specified formfield f with value
// f must be a reference to a form field
//
// would be nice if field doesnt exist, this function created it
//
function setField( f, fieldval ) {
	try {
		f.value = fieldval;
	} catch(e) {
		alert('setField: error - ' + e.toString());
	}
}


//$ function
//
// shorthand for returning element with passed in ID
//
function $() {
   var elements = new Array();

   for (var i = 0; i < arguments.length; i++) {
      var element = arguments[i];
      if (typeof element == 'string')
         element = document.getElementById(element);

      if (arguments.length == 1) 
         return element;

      elements.push(element);
   }

   return elements;
}

function showJsDebug( s ) {
	if (e= document.getElementById('js_debug')) {
		//alert ("debug:" + s);
		e.innerHTML = s;
	}
}

function setElementValue( ename, val) {
	if (e=document.getElementById(ename)) {
		e.innerHTML=val;
	}
}


function logout() {
	submitForm( document.frmMain, ACTION_LOGOUT, 'Are you sure you want to log out?' );  
}
		

//setHeaderText
//
// sets text for header text in top area of screen
//
function setHeaderText( text_left, text_mid, text_right ) {
	var m;

	if ("" != text_left ) {
		m = document.getElementById("t_left");
		m.innerHTML = '&nbsp;' + text_left;
	}

	if ("" != text_mid ) {
		m = document.getElementById("t_middle");
		m.innerHTML = text_mid;
	}

	if ("" != text_right ) {
		m = document.getElementById("t_right");
		m.innerHTML = text_right + '&nbsp;';
	}
	
}


function showHideDiv(id, bShow) {
	var tShow = (bShow?'block':'none');
	var e;
	
	if (document.getElementById) {
		// this is the way the standards work
////		var style2 = document.getElementById(id).style;
////		style2.display = tShow;
		e = document.getElementById(id);
		if (e != null ) e.style.display = tShow;
	}
	else if (document.all) {
		// this is the way old msie versions work
////		var style2 = document.all[id].style;
////		style2.display = tShow;
		e = document.all[id];
		if (e != null ) e.style.display = tShow;

} else if (document.layers) {
		// this is the way nn4 works
		var style2 = document.layers[id].style;
		style2.display = tShow;
	}
}

// debug area can be displayed and hidden
// toggle with: ebug(!bShowDebug);
//
// assumes there is an element 'debug' that contains the debug info
// assumes there is an element 'debug_showhide'

var bShowDebug;

function showDebug( bShow ){
	if (!document.getElementById('debug')) {
		alert ('cannot find debug object');
		return;
	}
	var t;
	if (bShow) {
		showHideDiv( 'debug', true );
		t = 'hide debug';
	} else {
		showHideDiv( 'debug', false );
		t = 'show debug';
	}
	bShowDebug = bShow;
	
	// change the text on the button
	var e = document.getElementById("debug_showhide_button");
	if (e != null) e.innerHTML = t;

	return false; // to stop href from activating
}

var basename = function(path)
{
	var filename = path.split('/');
	if (filename.length == 1) {
			var filename = path.split("\\");    
	}
	filename = filename[filename.length-1];
	filename = filename.replace(/(.*)(\..*)/, "$1"); // strip out suffix
	return filename;
}



function makelink( name, domain, desc, pre, post ) {
    if ( pre != null && pre != "" )
        document.write( pre );
    
    document.write( '<a href="mailto:' );
    document.write( name + '&#64;' );
    document.write( domain + '">' );
    
    if ( desc != null && desc != "" )
        document.write( desc )
    else
        document.write( name + '&#64;' + domain );
    
    document.write( '</a>' );
    
    if ( post != null && post != "" )
        document.write( post );
}

function newImage( path ) {
	var i = new Image();
	i.src = path;
	return i;
}

function show_popup(name,url,w,h) {
    new_window = window.open(url, name, 'height =' + h + ', width =' + w + ', resizable');
}

///////////////////////////////////////////

		

