
function SwapOut(IMGName, swap){
    switch(swap){
        case 1:
            document.images[IMGName].src=eval(IMGName+'Array[0].src');
            break;
        case 2:
            document.images[IMGName].src=eval(IMGName+'Array[1].src');
            break;
        case 3:
            document.images[IMGName].src=eval(IMGName+'Array[2].src');
    }
}

//check and uncheck are for checking/unchecking of specified checkbox array
function check(field)
{
  if (!(field.length > 1) ) {
	  if (!field.disabled == true) {
      field.checked = true;
    }
  }
  else {
	  for (i = 0; i < field.length; i++) {
	    if (!field[i].disabled == true) {
	      field[i].checked = true;
	    }
	  }
	}
}

function uncheck(field)
{	
  if (!(field.length > 1) ) {
	  if (!field.disabled == true) {
      field.checked = false;
    }
  }
  else {
	  for (i = 0; i < field.length; i++) {
	    if (!field[i].disabled == true) {
	      field[i].checked = false;
	    }
	  }
	}
}
  
function getCheckboxes(field) {
  var sReturn = "";
  if (!(field.length > 1)) {
    if(field.checked == true) {
      sReturn = field.value;
    }
  }
  else {
    for (var i = 0; i < field.length; i++) {
      if (field[i].checked == true) {
        sReturn += ((sReturn.length) ? "," : "") + field[i].value;
      }
    }
  }
  return sReturn;
}

// isChecked will return true if object contains a checked checkbox or radio button
function isChecked(inObj) {
    if (inObj==null)
      return true;
      
    if (inObj.length > 1) {
      for(var i=0;i<inObj.length;i++) {
        if (inObj[i].checked)
          return true;
      }
    } else {
       return (inObj.checked);
    }    
    return false;
}

function isObject(obj)
{
  var str = "";
  for (var i in obj) {
    str += obj[i] + "\n";
    break;
  }
  if (str.length > 0) {
    return true;
  }
  else {
    return false; 
  }
}
    
function isEmail(str) {
  var pos = str.indexOf('<');
  if (pos < 0) {
    if (str.search(/^\w+(('\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
      return true;
    } else {
      return false;
    }
  } else if (pos == 0) {
    if (str.search(/^< *\w+(('\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+ *>$/) != -1) {
      return true;
    } else {
      return false;
    }
  } else {
    if ( (trim(str.substring(0, pos)).search(/^[\w']+( [\w']+)*$/) != -1)  &&
      (str.substring(pos, str.length).search(/^< *\w+(('\w+)|(-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+ *>$/) != -1) ) {
      return true;
    } else {
      return false;
    }
  }
}
    
function checkToAddress(str) {
  var aTemp, fOK = true;
  str = str.replace(/,/g, ';');
  aTemp = str.split(';');
  for (var i = 0; i < aTemp.length; i++) {
    if (!isEmail(aTemp[i])) {
      alert("'" + aTemp[i] + "' does not appear to be a valid email address. Please correct and submit again!");
      fOK = false;
    }
  }

  if (fOK) {
    return aTemp.join(';');
  } else {
    return '';
  }
}

function openWin(pageIs,widthIs, heightIs, framename) {
  framename = framename ? framename : "popupmainframe"
	var winStr = "height=" + heightIs + ",width=" + widthIs + ",status=1,toolbar=0,resizable=1,scrollbars=yes"
	var newWin = window.open(pageIs,framename,winStr, false);
	newWin.focus();
}

function openWinWithMenu(pageIs,widthIs, heightIs, framename) {
  framename = framename ? framename : "popupmainframe"
	var winStr = "height=" + heightIs + ",width=" + widthIs + ",status=1,toolbar=0,resizable=1,scrollbars=yes,menubar=yes"
	var newWin = window.open(pageIs,framename,winStr, false);
	newWin.focus();
}

function downloadIt() {
  if (!document.execCommand) {
    alert("Your browser does not support the document.execCommand() feature (IE 4+ is required).\nClick File/Save As in the menu bar to download your selected documents.");
    return;
  }
  if (jdelivFormat == "html") {
    document.execCommand("SaveAs", true, ".htm"); }
  else {
    document.execCommand("SaveAs", true, ".txt"); }
}  
    
function trim(sStr) {
  return ltrim(rtrim(sStr));
}
    
function ltrim(sStr) {
  sStr = sStr.replace(/^\s+/g, "");
  return sStr;
}
    
function rtrim(sStr) {
  sStr = sStr.replace(/\s+$/g, "");
  return sStr;
}

function isEmpty(sStr) {
  if (sStr == null || trim(sStr).length == 0) {
    return true;
  }
  return false;  
}

function sidebartop (title, width) {
	var bgcolor='#00396B';
	var seccolor='#D7E0F2';
	var temptitle;
	temptitle = title.split(" ").join("&nbsp;");
	document.write ('<table cellSpacing="0" cellPadding="0" width='+width+' border=0>');
	document.write ('<TR>');
	document.write ('<TD width="1%" bgColor='+bgcolor+'><IMG src="/pagearch/NILS/graphics/sidetabbullet.gif" hspace=2></TD>');
	document.write ('<TD width="1%" class=sidenote bgColor='+bgcolor+' noWrap><FONT ');
	document.write (' color=white><B>' +temptitle+ '</B></FONT></TD>');
	document.write (' <td width=98% background="/pagearch/NILS/graphics/edge1.gif" valign="top"><img src="/pagearch/NILS/graphics/edge.gif"></td>');
	document.write ('</TR></TABLE>');
	document.write ('<TABLE cellSpacing=0 cellPadding=1 width='+width+' bgColor='+bgcolor+' border=0>');
	document.write ('<TR><TD>');
	document.write ('<TABLE cellSpacing=0 cellPadding=8 height=90 width="100%" bgColor="'+seccolor+'" border=0>');
	document.write ('<TR><TD class=sidenote>');
}

function sidebarbtm () {
	document.write ('</TD></TR></TABLE>');
	document.write ('</TD></TR></TABLE><p>');
}

function HTMLHeader(sTitle, sLogo) {
  var sReturn;
  sTitle = sTitle ? sTitle : "Page View";
  sLogo = sLogo ? "/PageArch/NILS/graphics/" + sLogo 
      : "/pagearch/NILS/graphics/INSourceWeb.gif";
  sReturn = '<html><head>\n' +
    '<link rel="stylesheet" type="text/css" href="/PageArch/NILS/styles/n1.css">\n' +
    '<title>' + sTitle + '</title>\n' +
    '</head><body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">\n' +
    '<table bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>\n' +
    '<table bgcolor="#E1E1E1" border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td width="100%" nowrap>&nbsp;</td>\n' +
    '<td width="100%" nowrap>&nbsp;</td>\n' +
    '</tr></table>\n' +
    '<table bgcolor="#FFFFFF" border="0" cellspacing="0" cellpadding="0" width="100%"><tr>\n' +
    '<td width="10px"><img src="/pagearch/NILS/graphics/1x1_pixel.gif" border="0" width="10px" height="91px"></td>\n' +
    '<td width="10px"><img src="' + sLogo + '" border="0""></td>\n' +
    '<td width="100%" align="right"><img src="/pagearch/NILS/graphics/1x1_pixel.gif" border="0" width="10px" height="91px"></td>\n' +
    '</tr></table>\n' +
    '<table bgcolor="#6699CC" border="0" width="100%" cellspacing="0" cellpadding="0"\n' +
    '<tr valign="middle" height="25px">\n' +
    '<td><span class="titlebar">' + sTitle + '</span></td>\n' +
    '</tr></table>\n' +
    '<table bgcolor="#FFFFFF" border="0" cellpadding="10" cellspacing="10" width="100%"><tr><td>\n'
  return(sReturn);
}
  
function HTMLFooter() {
  var sReturn;
  var today = new Date();
  var thisYear = today.getFullYear();
  sReturn = '</td></tr></table>\n' + 
    '<table bgcolor="#E1E1E1" border="0" cellpadding="0" cellspacing="0" width="100%"><tr>\n' +
    '<td class="copyright" nowrap>&nbsp;©' + thisYear + ', CCH INCORPORATED. All Rights Reserved.</td>\n' +
    '<td width="100%" nowrap>&nbsp;</td>\n' +
    '</tr><tr>\n' +
    '<td class="copyright" colspan="2">&nbsp;A WoltersKluwer Company</td>\n' +
    '</tr></table>\n' + 
    '</td></tr></table>\n';
  return(sReturn);  
}

function CloseWindowButton() {
  return('<p align="center"><input type="button" value="Close Window" onclick="self.close();" id=button1 name=button1></input></p>');
}

function UserNotesAdmin(page) {
  openWin(page, 750, 575);
}


function Cookie(document, name, hours, path, domain, secure) {
  this.$document = document;
  this.$name = name.toUpperCase();
  this.$expiration = (hours) ? new Date((new Date()).getTime() + hours*3600000) : null;
  this.$path = (path) ? path : null;
  this.$domain = (domain) ? domain : null;
  this.$secure = (secure) ? true : false;
}

Cookie.prototype.store = function() {
  var cookieval = "";
  for (var prop in this) {
    if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
      continue;
    if (cookieval != "") 
      cookieval += '&';
    cookieval += prop + ':' + escape(this[prop]);
  }
  var cookie = this.$name + '=' + cookieval;
  if (this.$expiration)
    cookie += '; expires=' + this.$expiration.toGMTString();
  if (this.$path)
    cookie += '; path=' + this.$path;
  if (this.$domain)
    cookie += '; domain=' + this.$domain;
  if (this.$secure)
    cookie += '; secure';
  this.$document.cookie = cookie;
}

Cookie.prototype.load = function() {
  
  var allcookies = this.$document.cookie;
  if (allcookies == "")
    return false;
  
  var start = allcookies.indexOf(this.$name + '=');
  if (start == -1)
    return false;
  start += this.$name.length + 1;
  var end = allcookies.indexOf(';', start);
  if (end == -1)
    end = allcookies.length;
  var cookieval = allcookies.substring(start, end);
  
  var a = cookieval.split('&');
  for (var i=0; i < a.length; i++)
    a[i] = a[i].split(':');
  
  for (var i=0; i < a.length; i++) {
    this[a[i][0]] = unescape(a[i][1]);
  }
  
  return true;
}

Cookie.prototype.remove = function() {
  var cookie;
  cookie = this.$name + '=';
  if (this.$path)
    cookie += '; path=' + this.$path;
  if (this.$domain)
    cookie += '; domain=' + this.$domain;
  cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
  
  this.$document.cookie = cookie;
}

function aLs(layerID) {
  var returnLayer; {
  returnLayer = eval("document.all." + layerID + ".style"); }
  return returnLayer;
}

function ChangeDisplay(ID) {
  if((aLs(ID).display == "")) {
    aLs(ID).display = "none"; }
  else { 
    aLs(ID).display= ""; } 
}

var clicks = 0;
function ChangeText(obj, originalText, clickText) {
  if(clicks == 0) {
  obj.innerHTML = clickText;
    clicks = 1; }
  else {
    obj.innerHTML = originalText;
    clicks = 0; }	
}

var bChanged=false;
function hasChanged() {
   if (bChanged == true)
    if(confirm("Save changes to this Criticism?\n\nOk to save changes\nCancel to remove changes")== true) {
      document.f1.submit();
    } 
   return true;
}


