// Script handles the submit form event for text boxes

function checkEnter(e){ //e is event object passed from function invocation
var characterCode;

if(e && e.which){ //if which property of event object is supported (NN4)
e = e;
characterCode = e.which; //character code is contained in NN4's which property
}
else{
e = event;
characterCode = e.keyCode; //character code is contained in IE's keyCode property
}

if(characterCode == 13){ //if ascii 13 (if enter key)
document.forms[0].submit() //submit the form
return false 
}
else{
return true 
}

}





function addObjective(){
	theTotal = 0;
var NewObj= window.prompt('NEW COURSE OBJECTIVE:','');
if (!NewObj){

alert('Course objective can not be null.');

}else{




if (NewObj==null ) 
{ alert('Course objective can not be null.'); }
else{
theTotal=theTotal+1;

document.getElementById("obj").innerHTML=document.getElementById("obj").innerHTML+'<input type=\"text\" value=\"'+NewObj+'\" name=\"pObjective\" size=\"65\"><br>'; 

}}

}



function activefield(field){
field.style.background="#FAF9E7";
return true;
}

function inactivefield(field){
field.style.background="#FFFFFF";
return true;
}





  function validRequired(formField,fieldLabel)
{
  var result = true;
  
  if (formField.value == "")
  {
    alert('Please ' + fieldLabel +'.');
    formField.focus();
    result = false;
  }
  
  return result;
}

function isEmailAddr(email)
{
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
  result = true;
  }

  return result;
}
  
  
  
  function validEmail(formField,fieldLabel,required, theLabel)
{
  var result = true;
  
  if (required && !validRequired(formField,fieldLabel))
    result = false;

  if (result && ((formField.value.length < 3) || !isEmailAddr(formField.value)) )
  {
    alert(theLabel);
    formField.focus();
    result = false;
  }
   
  return result;

}
  
  
  
  function validPassword(PasswordField,ConfirmPassword)
{
  var result = true;
  
  if (PasswordField.value != ConfirmPassword.value)
  {
    alert('Passwords do not match!.');
	PasswordField.value="";
	ConfirmPassword.value="";
    PasswordField.focus();
    result = false;
  }
  
  return result;
}  
  
   function validLength(formField,fieldLabel)
{
  var result = true;
  
 if (formField.value.length > 20  ||  formField.value.length < 8 )
  {
    alert(fieldLabel + ' must be between 8-20 alphanumeric characters.');
	formField.value="";
	formField.focus();
    result = false;
  }
  
  return result;
}  
  
  
  
 function checkSubscription (theForm) {
   var result = true;
 
 
 if (theForm.pSubscription.value == 6 ){
 
 
 	if (theForm.pFacility.value == "N/A" || theForm.pKeyCode.value==""){ 

 alert('You must select your facility name and enter the key code provided '+
 ' to register for an ' +
 'institutional subscription.  If you have forgotten your '+
 'key code, you will need to contact your institutional POC or AFIP technical'+
 ' support for the key code. '+
 'If your facility is not listed, you will have to contact AFIP technical support. ');
  result = false;
   theForm.pFacilityType.focus();
  }
 }
 
 
 if (result==true){
  theForm.button.disabled=true;
}
 
 
 return result;
 }
  
  

  
function ArchiveNavigation(theCourse)
{

document.EduForm.pCourse.value=theCourse;
document.EduForm.submit();
return false;
}
  
function NavigateCourse(theCourse) {
document.course.pCourse.value=theCourse;
document.course.submit();
return false;
} 
  
function CourseNavigation(thePage)
{

document.CourseForm.pPage.value=thePage;
document.CourseForm.submit();
return false;
}

function EduNavigation(theAction)
{

document.EduForm.pAction.value=theAction;
document.EduForm.submit();
return false;
}
  
  function validateNewAccount(theForm)
{
	
   // Start ------->
 if (!validRequired(theForm.pFname,'enter your First Name'))
    return false; 
 if (!validRequired(theForm.pLname,'enter your Last Name'))
    return false;  
if (!validRequired(theForm.pAddress,'enter your Home Address'))
    return false;  
if (!validRequired(theForm.pCity,'enter your City'))
    return false;  	
if (!validRequired(theForm.pCountry,'select your City'))
    return false;  		
if (!validRequired(theForm.pZip,'your Zip Code'))
    return false;  		
if (!validRequired(theForm.pPhone,'your Phone Number'))
    return false;  	
 	
	
	
  theForm.button.disabled=true;
	
    // <--------- End


  return true;
}



function DeactivateBtn(theForm)
{
	
   // Start ------->
theForm.button.disabled=true;
  return true;
 // <--------- End

}



function validatePaymentForm_old(theForm) //validatePaymentForm
{
	
   // Start ------->
 if (!validRequired(theForm.FNAME,' enter the first name on the card'))
    return false; 
 if (!validRequired(theForm.LNAME,' enter the last name on the card'))
    return false;  	
 if (!validRequired(theForm.ACCT,' enter the card account number'))
    return false; 	
 if (!validRequired(theForm.exp_mm,' enter the card expiration month'))
    return false; 
 if (!validRequired(theForm.exp_yyyy,' enter the card expiration year'))
    return false;   
 
	
    // <--------- End

theForm.PaymentNetV2.disabled=true;
  return true;
}



function validateNewAnswer(theForm)
{
	
   // Start ------->
 if (!validRequired(theForm.pAnswer,'The case diagnosis '))
    return false; 
 	
 	
	
	  
 
	
    // <--------- End

theForm.button.disabled=true;
  return true;
}


function validateNewAccountMil(theForm)
{
	
   // Start ------->
 if (!validRequired(theForm.pRank,'select your military rank/branch'))
    return false; 
if (!validRequired(theForm.pComponent,'select your military component'))
    return false; 
if (!validRequired(theForm.pFacName,'enter your facility name'))
    return false; 		
if (!validRequired(theForm.pFacAddress,'enter your facility address'))
    return false; 		
if (!validRequired(theForm.pWorkPhone,'enter your military phone'))
    return false; 		
if (!validEmail(theForm.pEmail,'','', 'Please enter a complete military email address: yourname@yourdomain.mil.  This email will be verified.'))
    return false; 	
if (!validRequired(theForm.pLogin,'create your Login ID'))
    return false; 	
if (!validLength(theForm.pLogin, 'Your Login ID'))
    return false; 	
if (!validRequired(theForm.pPassword,'create your password'))
    return false; 	
if (!validLength(theForm.pPassword, 'Your password'))
    return false; 	
if (!validRequired(theForm.pConfirmPassword,'confirm your pPassword'))
    return false; 		
if (!validPassword(theForm.pPassword,theForm.pConfirmPassword))
    return false; 		
	
				
    // <--------- End

  theForm.button.disabled=true;
  return true;

  
}



function validateKeyCodeReg(theForm)
{
 // Start ------->

if (!validRequired(theForm.pKeyCode,'enter your course key code.'))
    return false;   
 // <--------- End
  return true;
	theForm.button.disabled=true;
}



function openWin(url,windowname){
var w = 480, h = 340;
if (document.all || document.layers) {
   /* the following is only available after onLoad */
   w = screen.availWidth;
   h = screen.availHeight;
}
var popW = 800, popH = 600;
var leftPos = (w-popW)/2, topPos = (h-popH)/2;
window.open(url,windowname,'width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos+',resizable, scrollbars=yes');
}

  
 function wholeslide(url) 
{
openWin(url,'Wholeslide'); 
return true;}


function page(url,title){
openWin(url,'Page');
}

function fascicles(url){

openWin(url,'Myfascicle');
}


function tables(url){
openWin(url,'Table');
}

function reference(url)
{
openWin(url,'reference');}

function figures(url)
{
openWin(url,'figures');}

  

function validateNewAccountCiv(theForm)
{
	
   // Start ------->
if (!validEmail(theForm.pEmail,'','', 'Please enter a complete email address: yourname@yourdomain.com.  This email will be verified.'))
    return false;   
if (!validRequired(theForm.pLogin,'create your Login ID'))
    return false; 	
if (!validLength(theForm.pLogin, 'Your Login ID'))
    return false; 	
if (!validRequired(theForm.pPassword,'create your password'))
    return false; 	
if (!validLength(theForm.pPassword, 'Your password'))
    return false; 	
if (!validRequired(theForm.pConfirmPassword,'confirm your pPassword'))
    return false; 		
if (!validPassword(theForm.pPassword,theForm.pConfirmPassword))
    return false; 		
	
				
    // <--------- End
	theForm.button.disabled=true;
  return true;
  
}


function validateNewAccountGov(theForm)
{
	
   // Start ------->
if (!validRequired(theForm.pWorkPhone,'enter your work phone'))
    return false; 		
if (!validEmail(theForm.pEmail,'','', 'Please enter a complete government email address: yourname@yourdomain.gov.  This email will be verified.'))
    return false;    
if (!validRequired(theForm.pLogin,'create your Login ID'))
    return false; 	
if (!validLength(theForm.pLogin, 'Your Login ID'))
    return false; 	
if (!validRequired(theForm.pPassword,'create your password'))
    return false; 	
if (!validLength(theForm.pPassword, 'Your password'))
    return false; 	
if (!validRequired(theForm.pConfirmPassword,'confirm your pPassword'))
    return false; 		
if (!validPassword(theForm.pPassword,theForm.pConfirmPassword))
    return false; 		
	
				
    // <--------- End
  theForm.button.disabled=true;	
  return true;
}

function disable_button(){
submit_button.disabled=true;	
return true;
}



function validateNewAccountAFIP(theForm)
{
	
   // Start ------->
if (!validRequired(theForm.pAFIPdept,'select your AFIP department'))
    return false; 	   
if (!validRequired(theForm.pWorkPhone,'enter your AFIP phone'))
    return false; 		
if (!validEmail(theForm.pEmail,'','', 'Please enter a complete AFIP email address: yourname@afip.osd.mil.  This email will be verified.'))
    return false;    
if (!validRequired(theForm.pLogin,'create your Login ID'))
    return false; 	
if (!validLength(theForm.pLogin, 'Your Login ID'))
    return false; 	
if (!validRequired(theForm.pPassword,'create your password'))
    return false; 	
if (!validLength(theForm.pPassword, 'Your password'))
    return false; 	
if (!validRequired(theForm.pConfirmPassword,'confirm your pPassword'))
    return false; 		
if (!validPassword(theForm.pPassword,theForm.pConfirmPassword))
    return false; 		
	
	  theForm.button.disabled=true;			
    // <--------- End
  return true;
}



function validateActivateAccount(theForm)
{
	
   // Start ------->
	
if (!validEmail(theForm.pEmail,'','','Please enter the email address that you used to create your account.'))
    return false;    
if (!validRequired(theForm.pLogin,'enter your Login ID'))
    return false; 	
	
	  theForm.button.disabled=true;			
    // <--------- End
  return true;
}

function validateLogin (theForm)
{
	
   // Start ------->
	
if (!validRequired(theForm.pLogin,'enter your Login ID'))
    return false; 	 
if (!validRequired(theForm.pPassword,'enter your Password'))
    return false; 		  
	  theForm.button.disabled=true;			
    // <--------- End
  return true;
}

function validateRecoverPass(theForm)
{
	
   // Start ------->
	
if (!validEmail(theForm.pEmail,'','','Please enter the email address that you used to create your account.'))
    return false;    
	  theForm.button.disabled=true;			
    // <--------- End
  return true;
}
	
function Checkall(form){ 


 for (var i = 0; i < form.pDept.length; i++){ 

 form.pDept[i].checked=form.pCheckAll.checked;
 
 } 

 form.pDept.checked=form.pCheckAll.checked;
} 










function ResetSearchForm(theAction)
{
	this.UserSearch.pAction.value=theAction;
	this.UserSearch.submit();
return true;	
	}


// New scripts added 03202006

// Function used to check course admin form 
// for multiple selections.


function checkformultiples(form,field){
thefield = eval(form+"."+field);
theForm = eval(form);
theForm.pAdminAction.value='Grade Course';
found = 0 ; 

if (thefield.checked==true)
{
theForm.submit();
return true;
	
}else{

for (i=0; i < theForm.elements(field).length; i++){

if (theForm.elements(field)[i].checked){

found = found+1;
 }
}

if (found >1 || found == 0  ){
alert('Please select one conference.');
return false;

}else{
	
	theForm.submit();
return true;
}}

}


function movefacilities(){
fromList = eval('formcourseadmin.pFacility');
toList = eval('formcourseadmin.pFacilityReport');

for (i=0; i < fromList.options.length;i++){
 var current = fromList.options[i];

if (current.selected){
	txt = current.text;
	val = current.value;
toList.options[toList.length] = new Option(txt,val);
fromList.options[i] = null;

}

}


}

function removefacilities(){



for (i=0; i < formcourseadmin.pFacilityReport.options.length + 1;i++){
 var current = formcourseadmin.pFacilityReport.options[i];
 
formcourseadmin.pFacilityReport.options[i] = null;


}


}


function selectall(){



for (i=0; i < formcourseadmin.pFacilityReport.options.length;i++){
 var current = formcourseadmin.pFacilityReport.options[i];
 
formcourseadmin.pFacilityReport.options[i].selected = true;

}


}


function validate_report(theForm){
l_flag = false;
if (formcourseadmin.pPage.checked){
l_flag = true;

}else{


for (i=0; i < formcourseadmin.elements('pPage').length; i++){
if (formcourseadmin.elements('pPage')[i].checked){
l_flag = true;
}
}
}

if (l_flag == true){
formcourseadmin.pAdminAction.value='Generate Facility Report';
theForm.disabled=true;
theForm.value='Please wait...';
formcourseadmin.submit();

}else{
alert('You must select at least one conference for reporting.');

}
return l_flag;
}


