

function checkCount( form, name ) {
  count = 0;
  var i, e = form.elements;
  for( i = 0; i < e.length; i++ )
    if( e[i].name == name )
      if ( e[i].checked )
        count++;
  return count;
}


function checkAll( form, name, check ) {
  var i, e = form.elements;
  for( i = 0; i < e.length; i++ )
    if( e[i].name == name )
      e[i].checked = check
}


function selectAll( form, name, check ) {
  var list = form.elements[name];
  for ( var i = 0; i < list.options.length; i++ )
    list.options[i].selected = check;
}

function viewWindow( name, url, w, h ) {
  var win = null;
  // window features: toolbar, location, directories, status, menubar
  //   scrollbars, resizable, width, height
  win = window.open( url, name, 'resizable=yes,scrollbars=yes,width=' + w + ',height=' + h);
  if (win != null) {
    if (win.opener == null) {
      win.opener = self;
    }
//    win.location.href = url;
    win.name = name;
    win.focus();
  }

}

function printWindow( name, url, w, h ) {
  var win = null;

  win = window.open( 'about:blank', '', 'resizable=yes,scrollbars=yes,width=' + w + ',height=' + h);
  if (win != null) {
    if (win.opener == null) {
      win.opener = self;
    }

    with( win.document ) {
      write('<html><head><title>Print Preview</title></head>');
      write('<frameset frameborder="0" border="0" rows="30,*">');
      //write('<frame name="nav_bar" src="about:blank" scrolling="no">');
      write('<frame name="nav_bar" src="/assets/htmled/print_nav.html" scrolling="no">');
      write('<frame name="project" src="' + url + '" scrolling="yes">');
      write('</frameset>');
      write('</html>');
    }

/*
    with( win.nav_bar.document ) {
      write('<html><head><title>Print Preview</title></head>');
      write('<body>');
      write('<div align="right"><a href="javascript:parent.project.focus();parent.project.print();" class="action" title="Print this page">Print&nbsp;<img src="/images/icons/print.gif" border="0" align="absmiddle"></a>&nbsp;|&nbsp;<a href="javascript:parent.close();" class="action" title="Close this window">Close&nbsp;<img src="/images/icons/close.gif" border="0" align="absmiddle"></a></div>');
      write('</body>');
      write('</html>');
    }
*/

    win.name = name;
    win.focus();
  }

}

//============= SUPPORT EMAIL ======================

var support_window;
function email_support() {
  win = window.open( '/ltforms/support?view=basic' + '&referer=' + escape(document.location), 'Support', 'resizable=yes,scrollbars=yes,width=525,height=655');
  if (win != null) {
    if (win.opener == null) { win.opener = self; }
    support_window = win;
    support_window.focus();
  }
}

//============= FORM VERIFICATION ===================

function verifyNotBlank( elem, msg ) {
  if ( isEmpty( elem.value ) ) {
    alert( msg );
    elem.focus();
    return false;
  }
  return true;
}

function isEmpty( s ) {
  return ((s == null) || (s == "") || isWhiteSpace( s ));
}

function isWhiteSpace( s ) {
  for ( var i = 0; i < s.length; i++ ) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
  return true;
}

//============= ROW HIGHLIGHTING ===================

  function checkAllToggle( form, name, check ) {
    var i, e = form.elements;
    for( i = 0; i < e.length; i++ )
      if( e[i].name == name ) {
        e[i].checked = check
        if (check) {
          Highlight(e[i]);
        }
        else {
          Unhighlight(e[i]);
        }
      }
  }

  function Toggle(e) {
    if (e.checked) {
      Highlight(e);
    }
    else {
      Unhighlight(e);
    }
  }

  function Highlight(e) {

    var r = null;
    var r = getParent(e);

    if (r) {
      if (r.className == "tint_on") {
        r.className = "tint_on_chk";
      }
      else if (r.className == "tint_off") {
        r.className = "tint_off_chk";
      }
      else if (r.className == "list_item_tint_on") {
        r.className = "list_item_tint_on_chk";
      }
      else if (r.className == "list_item_tint_off") {
        r.className = "list_item_tint_off_chk";
      }
    }
  }

  function Unhighlight(e) {
    var r = null;
    var r = getParent(e);

    if (r) {
      if (r.className == "tint_on_chk") {
        r.className = "tint_on";
      }
      else if (r.className == "tint_off_chk") {
        r.className = "tint_off";
      }
      else if (r.className == "list_item_tint_on_chk") {
        r.className = "list_item_tint_on";
      }
      else if (r.className == "list_item_tint_off_chk") {
        r.className = "list_item_tint_off";
      }
    }
  }

  function getParent(e) {
    if (e.parentNode) {
      if (e.parentNode.tagName == 'TR') {
        return e.parentNode;
      }
      else {
        return getParent(e.parentNode);
      }
    }
    else if (e.parentElement) {
      if (e.parentElement.tagName == 'TR') {
        return e.parentElement;
      }
      else {
        return getParent(e.parentElement);
      }
    }
    else {
      return;
    }
  }


//============= UnitedStreaming Link ===================

// define a javascript function for handling submission of the hidden form
function view_ustreaming(urlDestination, formName) {
  
	var form;
	if( formName ){
		form = document.getElementById(formName);
	}else{
		form = document.ustreaming;
	}

	if ( form ) {
    // default the urlDestination argument if it has not been passed
    urlDestination = urlDestination == void 0 ? '' : urlDestination;

    // update the urlDesintation form field with the value passed to this function
    form.urlDestination.value = urlDestination;

    // submit the hidden form
    form.submit();
  }
}
 

//============= Cookies ===================

function getCookie(name) {
  var cookie = document.cookie.split("; ");
  for (var i = 0; i < cookie.length; i++) {
    var crumb = cookie[i].split("=");
    if (name == crumb[0]) 
      return unescape(crumb[1]);
  }
  return null;
}

//============= DHTML tree nodes ===================

function nodeLoad(elemId) {
  parent.document.getElementById(elemId).innerHTML = document.body.innerHTML;
}


function toggleVisibility(elemId) {
  elemStyle = document.getElementById(elemId).style;
  if (elemStyle.display == '') {
    elemStyle.visibility = 'hidden';
    elemStyle.display = 'none';
  }
  else {
    elemStyle.visibility = 'visible';
    elemStyle.display = '';
  }
}

function setStatus(str) {
  if (str == null) str = '';
  window.status = str;
  return true;
}

function adjustTextArea(elem, delta, min, max) {
  if (elem && delta) {
    if (min <= 0) min = 10;
    if (max <= min) max = min + 400;
    h = parseInt(elem.style.height) + delta;
    if (h < min) h = min;
    if (h > max) h = max;
    elem.style.height = h + 'px';
  }
}
