
function switchback( id, src )
{
    document.getElementById( id ).src = src;
}
function toggleDiv(name){
// 	if( fromstr == "" )
// 	fromstr = "-";
// 	if( tostr == "" )
// 	tostr = "-";
    element = ( name + "div" );
//     var href = document.getElementById(element + "href");
     if(document.getElementById(element).style.display == 'none')
     {
       document.getElementById(element).style.display = 'block';
       document.getElementById( "lessspan" + name ).style.display = 'block';
       document.getElementById( "morespan" + name ).style.display = 'none';
//       href.innerHTML = fromstr;
     }
     else if(document.getElementById(element).style.display == 'block')
     {
       document.getElementById(element).style.display = 'none';
       document.getElementById( "lessspan" + name ).style.display = 'none';
       document.getElementById( "morespan" + name ).style.display = 'block';
//       href.innerHTML = tostr;
     }
}
function toggleDivOther(element){
     if(document.getElementById(element).style.display == 'none')
     {
       document.getElementById(element).style.display = 'block';
     }
     else if(document.getElementById(element).style.display == 'block')
     {
       document.getElementById(element).style.display = 'none';
     }
}
//-->
function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;
  return e;
}
function swapValues(field, val) {
	var e = document.forms[0].eval(field);
	
	if (e.type == 'text') {
		var oldval = e.value;
		e.value = val;
	} else if (e.type == 'select-one') {
		var oldval = e.options[e.selectedIndex].text;
		for(i = 0; i < e.options.length; i++) {
			if (e.options[i].value == val) {
				e.selectedIndex = i;
				break;
			}
		}
		//e.value = val;
	}
	
	var temp_field = 'deltas_' + field;
	document.forms[0].eval(temp_field).value = 1;
		
	var n = xGetElementById(field);
	//n.innerHTML = "previous value = <a style='font-weight: bold;' title='Click to Replace' href='javascript:swapValues(\"" + field + "\", \"" + oldval + "\")'>" + oldval + "</a>";
	n.innerHTML = "<span style='color: green;'>Update approved.</span> Previous value = <b>" + oldval + "</b> (to unapprove, reload)";
	
}


function getSelectedRadio(buttonGroup) {
    // returns the array number of the selected radio button or -1 if no button is selected
    if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	for (var i=0; i<buttonGroup.length; i++) {
	    if (buttonGroup[i].checked) {
		            return i
	    }
	}
    } else {
	if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
    }
    // if we get to this point, no radio button is selected
    return -1;
} // Ends the "getSelectedRadio" function

function selectRadio(buttonGroup, value) {
    // returns the array number of the selected radio button or -1 if no button is selected
    if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	for (var i=0; i<buttonGroup.length; i++) {
	    if (buttonGroup[i].value == value) {
		buttonGroup[i].checked = true;
	    }
	    else
		{
		    buttonGroup[i].checked = false;
		}
	}
    } else {
	if (buttonGroup.value == value) { buttonGroup.checked = true; } // if the one button is checked, return zero
    }
    // if we get to this point, no radio button is selected
    //    return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
    // returns the value of the selected radio button or "" if no button is selected
    var i = getSelectedRadio(buttonGroup);
    if (i == -1) {
	return "";
    } else {
	if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
	    return buttonGroup[i].value;
	} else { // The button group is just the one button, and it is checked
	    return buttonGroup.value;
	}
    }
} // Ends the "getSelectedRadioValue" function
function getSelectedPulldownValue(buttonGroup) {
    return buttonGroup.options[buttonGroup.selectedIndex].value;
} 
function selectAll( id, val )
{
    frm = document.forms["itemform"];
    for( i = 0; i < frm.elements.length; i++ )
    {
        if( frm.elements[i].id == id )
            frm.elements[i].checked = val;
    }
}

function selectAllLike( id, val )
{
    frm = document.forms["itemform"];
    for( i = 0; i < frm.elements.length; i++ )
    {
        if( frm.elements[i].id.indexOf( id ) == 0 )
            frm.elements[i].checked = val;
    }
}

/***********************************************
* Pop-it menu- 
Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
/*
var defaultMenuWidth="150px" //set default menu width.


////No need to edit beyond here

var ie5=document.all && !window.opera
var ns6=document.getElementById

if (ie5||ns6)
document.write('<div id="popitmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event)"></div>')

function iecompattest(){
return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}

function showmenu(e, which, optWidth){
if (!document.all&&!document.getElementById)
return
clearhidemenu()
menuobj=ie5? document.all.popitmenu : document.getElementById("popitmenu")
if( !menuobj )
	return;
if( typeof( menuobj ) == "undefined" )
	return;
menuobj.innerHTML=which
menuobj.style.width=(typeof optWidth!="undefined")? optWidth : defaultMenuWidth
menuobj.contentwidth=menuobj.offsetWidth
menuobj.contentheight=menuobj.offsetHeight
eventX=ie5? event.clientX : e.clientX
eventY=ie5? event.clientY : e.clientY
//Find out how close the mouse is to the corner of the window
var rightedge=ie5? iecompattest().clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX-menuobj.contentwidth+"px" : window.pageXOffset+eventX-menuobj.contentwidth+"px"
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=ie5? iecompattest().scrollLeft+eventX+"px" : window.pageXOffset+eventX+"px"
//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.style.top=ie5? iecompattest().scrollTop+eventY-menuobj.contentheight+"px" : window.pageYOffset+eventY-menuobj.contentheight+"px"
else
menuobj.style.top=ie5? iecompattest().scrollTop+event.clientY+"px" : window.pageYOffset+eventY+"px"
menuobj.style.visibility="visible"
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.style.visibility="hidden"
}

function dynamichide(e){
if( !menuobj )
	return;
if( typeof( menuobj ) == "undefined" )
	return;
if (ie5&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

if (ie5||ns6)
document.onclick=hidemenu

*/

function checkField( field, name )
{
//        alert( field.options );
  if( !field.options )
  {
//alert( "in " );
	if( field.value == "" )
    {
        fillInError( field.name, name + " is required." );
        return false;
    }
    else
    {
        fillInError( field.name, "" );
        return true;
    }
  }
  else
  {
//	alert( "in2" );
      if( field.options[field.selectedIndex].value == "" )
      {
          fillInError( field.name, name + " is required." );
          return false;
      }
      else
      {
          fillInError( field.name, "" );
          return true;
      }
  }
}

function fillInError( elename, error )
{
    var ele = document.getElementById( "err_" + elename );
    if( !ele )
        alert( "err_" + elename );
	else
        ele.innerHTML = "<font color='red'>" + error + "</font>";
	if( document.getElementById( "messagediv" ) )
	{
		document.getElementById( "messagediv" ).innerHTML = "";
	}
}

function submitSearchForm()
{
	form = self.document.forms['searchform'];
    form.doit.value=1;
    form.submit();
}

function isValidEmail(email, required) {
    if (required==undefined) {   // if not specified, assume it's required 
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid 
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character 
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @ 
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character 
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid 
        return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character 
        return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
function isInteger (s)
{
    var i;

    if (isEmpty(s))
        if (isInteger.arguments.length == 1) return 0;
        else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    return true;
}
function isEmpty(s)
{
    return ((s == null) || (s.length == 0))
        }

function isDigit (c)
{
    return ((c >= "0") && (c <= "9"))
        }

function isDecimal(str)
{
    mystring = str;
    if (mystring.match(/^\d+\.\d{2}$/ ) ) {
        return true;
    }
    else
    {
        return false;
    }
}
