var is_browser_ie = window.navigator.userAgent.indexOf ( "MSIE " ) > 0 ? true : false;

function modify_navbar_urls(inst_id, ishepstaff)
{
  // this fuctionality has been moved to page_load routines inte aspx.cs files
  return;
  
  modify_url("ctl00_institute_profile", "EditMainProfile.aspx?id="+inst_id);
  modify_url("ctl00_institute_admin_positions", "EditAdminPositions.aspx?id="+inst_id);
  
  if(ishepstaff == 'true' ){
    modify_url("ctl00_online_contact", "InstitutionContact.aspx?id="+inst_id);
    modify_url("ctl00_accreditations", "EditAccreditation.aspx?id="+inst_id);
  }
  else {
    modify_url("ctl00_view_accreditations", "ViewAccreditation.aspx?id="+inst_id);
  }
}
function modify_url(elt_id,new_url) {
  var nav = document.getElementById(elt_id);
  if(nav )
    nav.href = new_url
}

function getYearNow() {
  var d = new Date();
  return d.getFullYear();
} 
// modify the institution id in the GET URL in the layout navigation. This is needed when switching
// pages via the navbar at the top and the institution id cannot be stored in the session.
 function set_navbar_institution_id(id){
 }
 function GetValue(eid)
{
  var ctl = document.getElementById(eid);
  if(ctl) return ctl.value;
  return null;
}
// alert( "browser is IE: "+is_browser_ie);
   
    // hide list of elements with ids encoded as a string with , separator, e.g.
    //
	function hide_list(element_list){
	  //if(element_list == null )
	    //alert("element_list is null in hide_list");
	  if( element_list != null ) {
	    var e = element_list.split(",");
        for(i=0;i<e.length;i++)
          if(e[i] != null && e[i].length > 0 )
            hide(e[i]);
      }
    }
	function hide(html_element){
	  try {
      var obj = document.getElementById(html_element);
      if( obj != null )
        if(is_browser_ie )
          obj.style.display = "none";
        else
          obj.style.visibility = "collapse";
      }catch (ex) { alert(ex.message);}
    }
	function toggle_visibility_list(element_list){
	  if( element_list != null ) {
	    var e = element_list.split(",");
        for(i=0;i<e.length;i++)
          if(e[i] != null && e[i].length > 0 )
            toggle_visibility(e[i]);
      }
    }
	function toggle_visibility(html_element){
      var obj = document.getElementById(html_element);
      if(obj != null)
        if(is_browser_ie )
          obj.style.display = ( obj.style.display == "none" ) ? "block" : "none";
        else
          obj.style.visibility = ( obj.style.visibility == "collapse" ) ? "visible" : "collapse";
    }
    function edit_institution_in_new_window(page, id ) {
          var url=page+"?id="+id;
          // watch out. IE hates to see spaces in window's id
          var title = "EditInstitution";
          //alert('edit_institution_in_new_window:' +url+', title:'+title);
          try {
          window.open(url, title,
                "resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width=950,height=800");
          } catch (ex ) { alert(ex.message); }
        }
    function create_institution_in_new_window(  ) {
          var url="NewMainProfile.aspx";
          // watch out. IE hates to see spaces in window's id
          var title = "NewMainProfile";
          //alert('edit_institution_in_new_window:' +url+', title:'+title);
          try {
          window.open(url, title,
                "resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width=950,height=800");
          } catch (ex ) { alert(ex.message); }
        }


    function SelectAllCheckboxes(spanChk)
    {
        var oItem = spanChk.children;
        var theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
        xState=theBox.checked;
        elm=theBox.form.elements;
        for(i=0;i<elm.length;i++)
        if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
        {
        //elm[i].click();
        if(elm[i].checked!=xState)
        elm[i].click();
        //elm[i].checked=xState;
        }

    }
    function show_institution_in_list(sel) {
		var idx = sel.selectedIndex;
		var id = sel.options[idx].value;
        edit_institution_in_new_window('EditMainProfile.aspx',id);
	}

/* show count of characters in a text input field like <input>. 10px are subtracted from elt's width for the number display and
10px is added to width of elt's parent element */		
function show_char_count(elt) {
  var cc = elt.value.length; /* initial character count */
  var elt_id = jQuery(elt).attr('id');
  var span_id = 'cspan'+elt_id;
  /* if the char count span does not exist, create it */
  var span_elt = jQuery('#'+span_id);
  if( span_elt === undefined || span_elt === null || span_elt.length == 0 ){
    var elt_obj = jQuery('#'+elt_id);
    var elt_width = elt_obj.width();
    var elt_parent_width = elt_obj.parent().width();
    elt_obj.width(elt_width-20);
    elt_obj.after('<span style="color:red; font-size:75%;width:10px;text-align:left;" id="'+span_id+'">00</span>');
    elt_obj.parent().width(elt_parent_width+15);
  }
  var cc_str = ''+elt.value.length;
  if(elt.value.length < 10 ){
    cc_str = cc_str + '&nbsp;';
  }
  jQuery('#'+span_id).html(cc_str);
}