

Ext.onReady(function(){

  Ext.get('mb9').on('click', function(){
    
    if(document.form.firstName.value == "")
    {
       Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please enter your first name',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }  
    else if(document.form.lastName.value == "")
    {
       Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please enter your last name',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    else if(document.form.title.value == "")
    {
    	Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please enter your title in your organization',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    else if(document.form.organization.value == "")
    {
        Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please the organization you belong to',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    else if(document.form.department.value == "")
    {
    	Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please the department you belong to',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    else if(document.form.email.value == "")
    {
    	Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please enter a valid email address',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    else if(document.form.pwd.value == "")
    {
       Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please enter a valid password',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    else if(document.form.pwd.value != document.form.pwd2.value)
    {
       Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'The passwords you have entered do not match',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
    }
    
    else
    { 
      var test = validateEmail(document.form.pwd.value);
      if(!test)
      {
       Ext.MessageBox.show({
           title: 'Incomplete Form Submission',
           msg: 'Please register with an academic/non-profit email address',
           buttons: Ext.MessageBox.OK,
           animEl: 'mb9',
           icon: Ext.MessageBox.ERROR
       });
      }
      else
      {
      	document.form.submit(); 
      }
    }
  });

});


function validateEmail(str)
{

  var allowedExtensions = new Array(".org",".edu",".com",".net");
  var extension = form.email.value;
  indexAt = extension.indexOf('@');
  
  if(!(extension.indexOf('@') > 0))
  {
  	return false;
  }
  
  /* 
  afterAt = extension.substr(indexAt+1, extension.length-indexAt);

  for (i=0;i<allowedExtensions.length;i++)
  {
   var index=afterAt.lastIndexOf(allowedExtensions[i]);
    if(index != -1)
    {
      c = afterAt.charAt(index + allowedExtensions[i].length);
      if (c=="" || c == ".")
      {
        return true;
      }
      return false;
    }
  }
  */
  return true;
 }
 
function deleteConfirm(url)
{
	var yes = confirm("Do you wish to delete this concept?");
    if(yes){
    	location.href = url;
    }
	
}

function searchQuery()
{
    document.form.keywordType.value = 'concept';
	document.form.submit();
}

function searchGeneQuery()
{
    document.form.keywordType.value = 'geneConcept';
	document.form.submit();
}

