function check_login()
{
  if(document.login.username.value=="")
  {
    alert("Please enter your username.");
    return false;
  }
  if(document.login.password.value=="")
  {
    alert("Please enter your password.");
    return false;
  }
  return true;
}
function check_event_form(multiple_institutes)
{
  if(multiple_institutes==1)
  {
    if(document.event_form.institute_id.selectedIndex==0)
    {
      alert("Please select the Institute.");
      return false;
    }
  }
  if(document.event_form.title.value=="")
  {
    alert("Please enter Event Title.");
    return false;
  }
  if(document.event_form.event_type_id.selectedIndex==0 && document.event_form.new_event_type.value=="")
  {
    alert("Please select or enter an event type.");
    return false;
  }
  if(document.event_form.start_year.selectedIndex==0 || document.event_form.start_month.selectedIndex==0 || document.event_form.start_date.selectedIndex==0)
  {
    alert("Please enter correct start date information.");
    return false;
  }
  if(document.event_form.end_year.selectedIndex==0 || document.event_form.end_month.selectedIndex==0 || document.event_form.end_date.selectedIndex==0)
  {
    alert("Please enter correct end date information.");
    return false;
  }
  return true;
}
var institute=0;
function change_institute()
{
  if(document.event_form.institute_id.selectedIndex>=1)
  {
    institute=document.event_form.institute_id.options[selectedIndex].value;
  }  
}
function display_table(method)
{
  if (method==1)
  {
    window.location="?module=1";
  }
  else if (method==2)
  {
    window.location="?module=1&method=1";
  }
}
function display_schema_dtd(method)
{
  if(method==1)
  {
    obj=document.getElementById('xml_schema_dtd');   
    obj.innerHTML="<b>XML Schema</b><br>";
    obj.innerHTML+="&lt;?xml version=\"1.0\"?&gt;<BR>";
    obj.innerHTML+="&lt;xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"&gt;<BR>";
    obj.innerHTML+="&lt;xs:element name=\"nsfevent\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&lt;xs:complexType&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"event\" minOccurs=\"1\" maxOccurs=\"100\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:complexType&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:sequence&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"institute\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:simpleType&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:restriction base=\"xs:string\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"AIM\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"IAS\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"IMA\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"IPAM\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"MBI\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"MSRI\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:enumeration value=\"SAMPI\"&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xs:restriction&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:simpleType&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xs:element&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"title\" type=\"xs:string\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"event_type\" type=\"xs:string\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"parent_event_id\" type=\"xs:integer\" default=\"0\" minOccurs=\"0\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"start_date\" type=\"xs:date\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"end_date\" type=\"xs:date\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"event_url\" type=\"xs:string\" minOccurs=\"0\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"description\" type=\"xs:string\" minOccurs=\"0\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;xs:element name=\"keywords\" type=\"xs:string\" minOccurs=\"0\"/&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xs:sequence&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xs:complexType&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;&lt;/xs:element&gt;<BR>";
    obj.innerHTML+="&nbsp;&nbsp;&lt;/xs:complexType&gt;<BR>";
    obj.innerHTML+="&lt;/xs:element&gt;<BR>";
    obj.innerHTML+="&lt;/xs:schema&gt;<BR>";
    

    
  }
  else if(method==2)  
  {
    obj=document.getElementById('xml_schema_dtd');
    
    obj.innerHTML="<b>XML DTD</b><BR>";
    obj.innerHTML+="&lt;!ELEMENT nsfevent (event)*&gt;<br>";
    obj.innerHTML+="&lt;!ELEMENT event (institute,title,event_type,parent_event_id?,start_date,end_date,event_url?,description?,keywords?)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT institute (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT title (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT event_type (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT parent_event_id (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT start_date (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT end_date (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT event_url (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT description (#PCDATA)&gt;<BR>";
    obj.innerHTML+="&lt;!ELEMENT keywords (#PCDATA)&gt;<BR>";    
  }
}
function manage_user_form_submit()
{  
  if(document.manage_user_form.user_id.selectedIndex==0)
  {
    window.location='?module=3';
  }
  else
  {
    document.manage_user_form.submit();
  }
}
function manage_event_types_submit()
{  
  if(document.manage_event_types.institute_id.selectedIndex==0)
  {
    window.location='?module=4';
  }
  else
  {
    document.manage_event_types.submit();
  }
}
function check_password_form()
{
  if(document.change_password_form.new_password.value=='' || document.change_password_form.confirm_password.value=='')
  {
    alert("Please enter your new password and confirm it.");
    return false;
  }
  if(document.change_password_form.new_password.value != document.change_password_form.confirm_password.value)
  {
    alert("Your new password is not the same with the confirmed password.");
    return false;
  }
  return true;
}
function switch_children(id)
{
  objid="children_"+id;
  obj=document.getElementById(objid);
  
  
  if(obj.style.display=="none")
  {
    obj.style.display="inline";
    document.getElementById("parent_switch_"+id).innerHTML="<a style='background-color:#fff;color:#000;text-decoration:none;font-weight:bold;font-size:16px;' href='javascript:switch_children("+id+");'><img src='../images/minus.gif' border='0' alt='Drop Down' width='14' height='14'></a>&nbsp;";
  }
  else if(obj.style.display=="inline")
  {
    obj.style.display="none";
    document.getElementById("parent_switch_"+id).innerHTML="<a style='background-color:#fff;color:#000;text-decoration:none;font-weight:bold;font-size:16px;' href='javascript:switch_children("+id+");'><img src='../images/plus.gif' border='0' alt='Drop Down' width='14' height='14'></a>&nbsp;";
  }
}

function manage_user_checkform(button_action,multiple_institutes) //action=1=>add new,action=2=>save changes
{
  if(button_action==2)
  {
    if(document.manage_user_form.user_id.selectedIndex==0)
    {
      alert("Please select user.");
      return false;
    }
  }
  
  if(document.manage_user_form.new_username.value=="")
  {
    alert("Please enter username.");
    return false;
  }
  if(document.manage_user_form.new_password.value=="")
  {
    alert("Please enter password.");
    return false;
  }
  if(multiple_institutes==1)
  {    
    if(document.manage_user_form.new_institute_id.selectedIndex==0)
    {
      alert("Please select Institute.");
      return false;
    }
  }    
  return true;
}
function manage_event_types_checkform(button_action,multiple_institutes) //action=1=>add new,action=2=>save changes
{  
  if(multiple_institutes==1)
  {
    if(document.manage_event_types.institute_id.selectedIndex==0)
    {
      alert("Please choose institute.");
      return false;
    }
  }
  if(button_action==3)
  {
    if(document.manage_event_types.event_type_id.selectedIndex==0)
    {
      alert("Please select event type.");
      return false;
    }
    else 
      return confirm("Do you really want to delete this event type?");
  }
  if(button_action==2)
  {
    if(document.manage_event_types.event_type_id.selectedIndex==0)
    {
      alert("Please select event type.");
      return false;
    }
    if(document.manage_event_types.event_type_id.options[document.manage_event_types.event_type_id.selectedIndex].text==trim(document.manage_event_types.new_event_type_name.value))
    {
      return false;
    }        
  }
    
  if(trim(document.manage_event_types.new_event_type_name.value)=="")
  {
    alert("Please enter event type name.");
    return false;
  }
}
function LTrim( value ) {
  
  var re = /\s*((\S+\s*)*)/;
  return value.replace(re, "$1");
  
}

// Removes ending whitespaces
function RTrim( value ) {
  
  var re = /((\s*\S+)*)\s*/;
  return value.replace(re, "$1");
  
}

// Removes leading and ending whitespaces
function trim( value ) {
  
  return LTrim(RTrim(value));
  
}
