//<![CDATA[
function verify_status( state, msg_confirm, msg_alert ) { //v1.0 by caridy
  if (state == '_UNPUBLISHED_DOCUMENT')
	return confirm (msg_confirm);
  else if (state == '_PUBLISHED_DOCUMENT') {
	alert (msg_alert);
    return false;
  }
  else if (state == '_ARCHIVED_DOCUMENT')
	return confirm (msg_confirm);
  return confirm (msg_confirm);
}

function display_Advanced_Search() { //v1.0 by caridy
  document.forms['PredefinedSearchForm'].style.display = 'none';
  document.forms['AdvSearchForm'].style.display 	   = 'block';
  return false;
}
function display_Predefined_Search() { //v1.0 by caridy
  document.forms['PredefinedSearchForm'].style.display = 'block';
  document.forms['AdvSearchForm'].style.display 	   = 'none';
  return false;
}

function Switch_Panels_Search() { //v1.0 by caridy
  document.forms['PredefinedSearchForm'].style.display     = 'block';
  document.forms['AdvSearchForm'].style.display 	   = 'none';
  return false;
}
function switch_Panels( id1, id2 ) { //v1.0 by caridy
  var obj1 = findObj ( id1 );
  var obj2 = findObj ( id2 );
  if (obj1)
    obj1.style.display = 'none';
  if (obj1)
    obj2.style.display = 'block';
  return false;
}
function goToURL() { //v3.0
  var i;
  var args=goToURL.arguments;
  for (i=0; i < (args.length-1); i+=2) {
    eval(args[i]+".location='"+ args[i+1]+"'");
  }
}
function goToExternalURL( url ) { //v3.0
  if (url != '')
    window.open(url, '','' );
}

var popUpWin = 0;
function popUpWindow(URLStr, left, top, width, height, style)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin',
                          'toolbar=no,'+
                          'location=no,'+
                          'directories=no,'+
                          'status=no,'+
                          'menubar=no,'+
                          'scrollbar=yes,'+
                          'resizable=yes,'+
                          'copyhistory=yes,'+
                          'width='+width+','+
                          'height='+height+','+
                          'left='+left+','+
                          'top='+top+','+
                          'screenX='+left+','+
                          'screenY='+top+ '' +
                           style  );

}


function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
  	if(!document.forms[FormName])
		return ;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return ;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
    return ;
}

function ManageCheckBoxes(FormName, FieldName, CheckBoxID) { // Scripted by Ronny
   	if(!document.forms[FormName])
		return ;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return ;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = ! objCheckBoxes.checked;
	else {
        var objCheckBox = document.getElementById(CheckBoxID);
        if (objCheckBox==null) alert ('Error. No such ID ' + CheckBoxID);

        if (! objCheckBox.checked) {
          // uncheck all its dependents
          var str;
          var prefix;
          var len = CheckBoxID.length;
		  for(var i = 0; i < countCheckBoxes; i++)  {
		    str = objCheckBoxes[i].id;
		    prefix = str.substr(0, len);
		    if ((str != CheckBoxID)&&(prefix == CheckBoxID))
		      // CheckBoxID is a prefix of objCheckBoxes[i].id
		      objCheckBoxes[i].checked = false;
		  }
        }
        else  {
          // check all its parents
          var pos;
          var str = CheckBoxID;
          while(str.length > 0) {
               objCheckBox = document.getElementById(str);
               if (objCheckBox)
                  objCheckBox.checked = true;
               pos = str.lastIndexOf(',');
               str = str.substring(0,pos);
          }

        }

    }

}

function AtLeastOnceCheckBox(FormName, FieldName ) {
  	if(!document.forms[FormName])
		return false;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return false;

	var countCheckBoxes = objCheckBoxes.length;

	if(!countCheckBoxes)
		return objCheckBoxes.checked;
	else {
    	for (var i=0; i < countCheckBoxes; i++) {
	      if (objCheckBoxes[i].checked)  {
                return true;
	      }
	   }
    }
    return false;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm.substr(1)+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;

  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);

  return foundObj;
}


function showHideLayers()
{
  var i, visStr, obj, args = showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
      }
      obj.display = visStr;
    }
  }
  return false;
}

// JS Calendar
var calendar = null; // remember the calendar object so that we reuse
// it and avoid creating another

// This function gets called when an end-user clicks on some date
function selected(cal, date) {
	cal.sel.value = date; // just update the value of the input field
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks the "Close" (X) button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
	cal.hide();			// hide the calendar

	// don't check mousedown on document anymore (used to be able to hide the
	// calendar when someone clicks outside it, see the     s function).
	Calendar.removeEvent(document, "mousedown", checkCalendar);
}

// This gets called when the user presses a mouse button anywhere in the
// document, if the calendar is shown.  If the click was outside the open
// calendar this function closes it.
function checkCalendar(ev) {
	var el = Calendar.is_ie ? Calendar.getElement(ev) : Calendar.getTargetElement(ev);
	for (; el != null; el = el.parentNode)
	// FIXME: allow end-user to click some link without closing the
	// calendar.  Good to see real-time stylesheet change :)
	if (el == calendar.element || el.tagName == "A") break;
	if (el == null) {
		// calls closeHandler which should hide the calendar.
		calendar.callCloseHandler(); Calendar.stopEvent(ev);
	}
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id) {
	var el = document.getElementById(id);
	if (calendar != null) {
		// we already have one created, so just update it.
		calendar.hide();		// hide the existing calendar
		calendar.parseDate(el.value); // set it to a new date
	} else {
		// first-time call, create the calendar
		var cal = new Calendar(true, null, selected, closeHandler);
		calendar = cal;		// remember the calendar in the global
		cal.setRange(1900, 2070);	// min/max year allowed
		calendar.create();		// create a popup calendar
	}
	calendar.sel = el;		// inform it about the input field in use
	calendar.showAtElement(el);	// show the calendar next to the input field

	// catch mousedown on the document
	Calendar.addEvent(document, "mousedown", checkCalendar);
	return false;
}
function switch_fieldset( anch, fs_id, id ) { //v1.0 by caridy

  var obj_container = findObj ( fs_id );
  for (var i = 0; i < obj_container.childNodes.length; i++) {
    if (obj_container.childNodes[i].nodeName == 'DIV') {
		obj_container.childNodes[i].style.display = 'none';
	} else if (obj_container.childNodes[i].nodeName == 'LEGEND') {
	    for (var j = 0; j < obj_container.childNodes[i].childNodes.length; j++) {
		   if (obj_container.childNodes[i].childNodes[j].nodeName == 'A')
		     obj_container.childNodes[i].childNodes[j].className = 'lclose';
			 }
	}
  }		
  var obj1 = findObj ( id );
  if (obj1)
    obj1.style.display = 'block';
  anch.className = 'lopen';
  return false;
}
function navigate( url ) {
	document.location.href = url;
}
//]]>