//Author Ray Bayly
//Purpose Validation for form values on Author area
//Date Created 12/31/2003
// *************************************
// 
// Modified on 03/01/2005 - email vaidation function added . Simon Kapstan
// 

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */



/*
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}
*/

function checkEmail(str) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
return (true)
}
//alert("Invalid E-mail Address! Please re-enter.")
return (false)
}
//  End -->

function checkAddAuth(){

		  if (document.addauth.address1.value.length <= 0){
		   alert('You must enter an address.');
		   document.addauth.address1.focus();
		   return false;
		  }
		  /*
		  if (document.addauth.email.value.length <= 0){
		   alert('Email is required');
		   document.addauth.email.focus();
		   return false;
		  } */
		  
		  if (document.addauth.city.value.length <= 0){
		   alert('You must enter a city.');
		   document.addauth.city.focus();
		   return false;
		  }
		  
		  if(document.addauth.country.selectedIndex == 0){
			  alert('You Must enter an Country.');
			  document.addauth.country.focus();
			  return false;
		  }

		  if (document.addauth.country.value == '1' && document.addauth.zip_code.value.length <= 0){
		   alert('You must enter a Zip Code.');
		   document.addauth.zip_code.focus();
		   return false;
		  }
		  
		  if(document.addauth.affiliation.value.length <= 0){
			  alert('You Must enter an Affiliation.');
			  document.addauth.zip_code.focus();
			  return false;
		  }
		 
		  
		return true;
		  
}

	function deleteEntry(Name, URL) {
	if (confirm('Are you sure you want to delete ' + Name + '?')) {
		location.href = URL;
	}
}

function checkAddAuthor(){

if (document.addauth.firstname.value.length <= 0){
		   alert('You must enter an First Name.');
		   document.addauth.firstname.focus();
		   return false;
		  }
		  
if (document.addauth.lastname.value.length <= 0){
		   alert('You must enter an Last Name.');
		   document.addauth.lastname.focus();
		   return false;
		  }
if (document.addauth.email.value.length <= 0){
		   alert('You must enter an e-mail address.');
		   document.addauth.email.focus();
		   return false;
		  }
if (document.addauth.organization.value.length <= 0){
		   alert('You must enter an organization.');
		   document.addauth.organization.focus();
		   return false;
		  }
		  
if (checkEmail(document.addauth.email.value)==false){
		   alert("You've entered invalid email") ;
		   document.addauth.email.focus();
		   return false;
		   }
return true;
}

function checkNewDoc(){

	if(document.newsubmission.title.value.length <= 0){
		alert("You must fill out a title before you submit");
		document.newsubmission.title.focus();
		return false;
	}
	
	if(document.newsubmission.aabstract.value.length <= 0){
		alert("You must fill out the abstract before you submit (you may cut and paste it from your manuscript)");
		document.newsubmission.aabstract.focus();
		return false;
	}

	if(document.newsubmission.olcategory.value == '16' && !(document.newsubmission.feature_id.options[document.newsubmission.feature_id.selectedIndex].text.search('ECOC') > -1)) {
		alert("If submitting to ECOC, you must select both the ECOC Category and appropriate ECOC feature issue.");
		document.newsubmission.olcategory.focus();
		return false;
	}
	
	if(document.newsubmission.feature_id.options[document.newsubmission.feature_id.selectedIndex].text.search('ECOC') > -1 && !(document.newsubmission.olcategory.value == '16')) {
		alert("If submitting to ECOC, you must select both the ECOC Category and appropriate ECOC feature issue.");
		document.newsubmission.feature_id.focus();
		return false;
	}
	
	if(document.newsubmission.ocisagree.checked == false){
		alert("You must agree to choosing a primary OCIS code before submitting");
		document.newsubmission.category1.focus();
		return false;
	}
	
	if(document.newsubmission.category1.value.length <= 0){
		alert("You must fill out a Category and Keyword before you submit");
		document.newsubmission.category1.focus();
		return false;
	}
	
	if(document.newsubmission.keyword1.value.length <= 0){
		alert("You must fill out a Category and Keyword before you submit");
		document.newsubmission.ms_type.focus();
		return false;
	}
	
	if(document.newsubmission.category2.value.length <= 0){
		alert("You must fill out a Category and Keyword before you submit");
		document.newsubmission.category1.focus();
		return false;
	}
	
	if(document.newsubmission.keyword2.value.length <= 0){
		alert("You must fill out a Category and Keyword before you submit");
		document.newsubmission.ms_type.focus();
		return false;
	}
		
	if(document.newsubmission.reviewer_name_1.value.length <= 0 || document.newsubmission.reviewer_email_1.value.length <= 0){
		alert("You must fill out at least three reviewer suggestions (names and email) before you submit");
		document.newsubmission.reviewer_name_1.focus();
		return false;
	}

	if(document.newsubmission.reviewer_name_2.value.length <= 0 || document.newsubmission.reviewer_email_2.value.length <= 0){
		alert("You must fill out at least three reviewer suggestions (names and email) before you submit");
		document.newsubmission.reviewer_name_2.focus();
		return false;
	}

	if(document.newsubmission.reviewer_name_3.value.length <= 0 || document.newsubmission.reviewer_email_3.value.length <= 0){
		alert("You must fill out at least three reviewer suggestions (names and email) before you submit");
		document.newsubmission.reviewer_name_3.focus();
		return false;
	}

	for (var z=1; z<=10; z++) {
		thisfield = eval("document.newsubmission.reviewer_email_"+z);
		thisemail = thisfield.value;
		if (thisemail != '' && !checkEmailFormat(thisemail)) {
			alert("Reviewer suggestion email "+z+" is not a vaild email.  Please correct before proceeding.");
			thisfield.focus();
			return false;
		}
	}

	return true;
}


function checkEmailFormat(email){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email))
		return true;
	else
		return false;
}

// this script determines which email text to display
function getEmailText()
{
  var message0 = document.firstdecision.accepted.value;
  var message1 = document.firstdecision.rejected.value;
  var message2 = document.firstdecision.revise.value;
  var message3 = document.firstdecision.majorrevise.value;
  for (i=0; i<document.firstdecision.result.length; i++)
    if (document.firstdecision.result[i].checked == true)
	{
	  var decision = i;
	  i = 10;
    }
  var emailtext = eval("message" + decision);
  document.firstdecision.emailcomments.value = emailtext;
}
// this script retrieves reviewer comments and appends them to the email text
function getReviewerText()
{
  var emailtext = document.firstdecision.emailcomments.value;
  for (var i=1; i <= document.firstdecision.commentcount.value; i++)
  {
    var temptext = eval("document.forms[0].hidComment" + i + ".value");
	emailtext = emailtext + "\r\rReviewer " + i + " comments:\r\r" + unescape(temptext);
  }
  if (document.firstdecision.commentcount.value == 0)
    emailtext = emailtext + "No reviewer comments available.";
  document.firstdecision.emailcomments.value = emailtext;
}
// this script takes the value from the filename field and writes it to a hidden 
// form field so that it's value can be passed back to check for form errors
function getFileInfo()
{
	var name = document.firstdecision.filename.value;
	document.firstdecision.hideFileName.value = name;
}

function setFormColor(obj) {
	if (obj.value=='') {
		if ((document.all)||(document.getElementById)) {
			obj.className = 'form';
		}
	} else {
		if ((document.all)||(document.getElementById)) {
			obj.className = 'formSelected';
		}
	}
}	


