//
// Hide e-mail addresses
//
// Sune.Karlsson@hhs.se 2003-04-25

function Obfuscate( b, a ) {
  
  document.write( '<a href="mailto:' + a + '&#64;' + b + '">' + a + '&#64;' + b + '</a>' );
  
}


//
// Simple form validation for S-WoPEc/S-WoBA forms
//
// Sune.Karlsson@hhs.se 2001-11-09
//

function MsgAndFocus( msg, formelement ) {

alert( msg );
eval( formelement + ".focus()" );

}

function CheckLogin(lform) {

if ( lform.s.selectedIndex <= 0 ) {
  alert('You must choose a series');
  lform.s.focus();
  return false;
  }

var coordinator = false;
var author = false;
var wpnum = false;
for ( var i = 0; i < lform.length; i++ ) {
  if ( lform.elements[i].name == 'wpcp' ) {
    coordinator = true;
    }
  if ( lform.elements[i].name == 'p' ) {
    author = true;
    }
  if ( lform.elements[i].name == 'n' ) {
    wpnum = true;
    }
  }
  
if ( author && coordinator ) {
  if ( lform.wpcp.value=="" && lform.p.value=="" ) {
    alert('You must supply a author or coordinator password');
    return false;
    }
  if ( lform.wpcp.value!=="" && lform.p.value!=="" ) {
    alert('You can not supply both author and coordinator passwords');
    return false;
    }
  }
else
if ( author ) {
  if ( lform.p.value=="" ) {
    alert('You must supply a password');
    lform.p.focus();
    return false;
    }
  }
else 
if ( coordinator ) {
  if ( lform.wpcp.value=="" ) {
    alert('You must supply a password');
    lform.wpcp.focus();
    return false;
    }
  }
if ( wpnum ) {
  if ( lform.n.value=="" ) {
    alert('You must supply a Working Paper number');
    lform.n.focus();
    return false;
    }
  }

}

//------------------------

function CheckConfirmPaper(button) {

if ( button.form.c.value == "" ) {
  alert('You must supply a code for the paper' );
  button.form.c.focus();
  return false;
  }

if ( button.name == 'C_accept' ) {
  if ( button.form.n.value == "" ) {
    alert('You must supply a number for the paper when adding it to the series' );
    button.form.n.focus();
    return false;
    }
  }
if ( button.name == 'C_reject' ) {
  if ( button.form.n.value !== "" ) {
    if ( confirm('You have given a number for the paper and you are rejecting it.\nDo you really want to REJECT the paper?' ) ) {
      return true;
      }
    else {
      button.form.n.focus();
      return false;
      }
    }
  }
}

//--------------------------

function SFPF(item) {

var cmd = "document.PaperForm." + item + ".focus()";
eval( cmd );

}

//--------------------------

function CheckPaperForm(button) {

var pf = button.form;

if ( pf.title.value == "" ) {
  alert( 'The Title is missing' );
  pf.title.focus();
  return false;
  }

if ( ( pf.F_Namn1.value == "" ) || ( pf.L_Namn1.value == "" ) ) {
  alert( 'First or last name missing for first author' );
  if ( pf.F_Namn1.value == "" ) {
    pf.F_Namn1.focus();
    }
  else {
    pf.L_Namn1.focus();
    }
  return false;
  }

var emailseen = false;
for ( var i = 1; i <= pf.OldNumAuth.value; i++ ) {
  var em = eval( "pf.Email" + i + ".value" );
  if ( em ) {
    emailseen = true;
    }
  }
for ( var i = 1; i <= pf.OldNumAuth.value; i++ ) {
  var fn = eval( "pf.F_Namn" + i + ".value" );
  var ln = eval( "pf.L_Namn" + i + ".value" );
  var em = eval( "pf.Email" + i + ".value" );
  if ( fn !== "" || ln !== "" || em !== "" ) {
    if ( fn == "" ) {
      alert( 'First name missing for author' );
      eval( "pf.F_Namn" + i + ".focus()" );
      return false;
      }
    if ( ln == "" ) {
      alert( 'Last name missing for author' );
      eval( "pf.L_Namn" + i + ".focus()" );
      return false;
      }
    if ( ( em == "" ) && ( !pf.noemail.checked && !emailseen ) ) {
      alert( "E-mail required for at least one author unless the 'No author has an email address' box is checked" );
      eval( "pf.Email" + i + ".focus()" );
      return false;
      }
    }
  }

if ( pf.abstrakt.value == "" && ( !pf.NoAbs.checked || pf.NoKey.value == "false" ) ) {
  alert( 'The Abstract is missing' );
  pf.abstrakt.focus();
  return false;
  }

if ( pf.key.value == "" && ( !pf.NoKey.checked || pf.NoKey.value == "false" ) ) {
  alert( 'No Keywords supplied' );
  pf.key.focus();
  return false;
  }

if ( pf.Jel.value == "" && !( pf.NoJel.checked || pf.NoJel.value == "true" ) ) {
  alert( 'No JEL-codes supplied' );
  pf.Jel.focus();
  return false;
  }

if ( pf.sid.value == "" ) {
  alert( 'The number of pages is missing' );
  pf.sid.focus();
  return false;
  }

if ( pf.date.value == "" ) {
  alert( 'The date is missing' );
  pf.date.focus();
  return false;
  }
  
if ( pf.wpcp.value !== "" && pf.n.value == "" ) {
  alert( 'The Working Paper number is missing' );
  pf.n.focus();
  return false;
  }

if ( pf.wpcp.value == "" && pf.n.value !== "" && pf.Updating.value == "" ) {
  alert( 'A Coordinator Password is required when specifying the Working Paper number' );
  pf.wpcp.focus();
  return false;
  }

if ( pf.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  pf.myemail.focus();
  return false;
  }

if ( pf.Updating.value !== "" ) {
  if ( !pf.revising[0].checked && !pf.revising[1].checked ) {
    alert( "Specify if this is a revised version or correcting the WP data" );
    pf.revising[0].focus();
    return false;
    }
  if ( pf.revising[0].checked && pf.revised.value == "" ) {
    alert( "Revision Date is missing" );
    pf.revised.focus();
    return false;
    }
  if ( pf.revising[1].checked && pf.revised.value !== "" ) {
    alert( "Revision date is ignored when correcting the bibliographic data" );
    pf.revised.focus();
    return false;
    }
  }

}

//--------------------------

function CheckArticleForm(button) {

var af = button.form;

if ( af.A_title.value == "" ) {
  alert( 'The Title is missing' );
  af.A_title.focus();
  return false;
  }

if ( ( af.A_F_Namn1.value == "" ) || ( af.A_L_Namn1.value == "" ) ) {
  alert( 'First or last name missing for first author' );
  if ( af.A_F_Namn1.value == "" )  {
    af.A_F_Namn1.focus();
    }
  else {
    af.A_L_Namn1.focus();
    }
  return false;
  }

for ( var i = 1; i <= af.A_OldNumAuth.value; i++ ) {
  var fn = eval( "af.A_F_Namn" + i + ".value" );
  var ln = eval( "af.A_L_Namn" + i + ".value" );
  if ( fn !== "" || ln !== "" ) {
    if ( fn == "" ) {
      alert( 'First name missing for author' );
      eval( "af.A_F_Namn" + i + ".focus()" );
      return false;
      }
    if ( ln == "" ) {
      alert( 'Last name missing for author' );
      eval( "af.A_L_Namn" + i + ".focus()" );
      return false;
      }
    }
  }

if ( af.A_journal.value == "" ) {
  alert( "The journal name is required" );
  af.A_journal.focus();
  return false
  }
  
if ( !af.A_status[0].checked && !af.A_status[1].checked ) {
  alert( "Specify if the article is published or forthcoming" );
  af.A_status[0].focus();
  return false
  }

if ( af.A_status[1].checked ) {
  if ( af.A_year.value == "" ) {
    alert( "The year is required for published articles" );
    af.A_year.focus();
    return false;
    }
  if ( af.A_pages.value == "" && !af.A_Nopages.checked ) {
    alert( "The pages are required for published articles" );
    af.A_pages.focus();
    return false;
    }
  }
  
if ( af.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  af.myemail.focus();
  return false;
  }

}

//--------------------------

function CheckBookForm(button) {

var bf = button.form;

if ( bf.B_title.value == "" ) {
  alert( 'The Title is missing' );
  bf.B_title.focus();
  return false;
  }

if ( ( bf.B_F_Namn1.value == "" ) || ( bf.B_L_Namn1.value == "" ) ) {
  alert( 'First or last name missing for first author' );
  if ( bf.B_F_Namn1.value == "" ) {
    bf.B_F_Namn1.focus();
    }
  else {
    bf.B_L_Namn1.focus();
    }
  return false;
  }

for ( var i = 1; i <= bf.B_OldNumAuth.value; i++ ) {
  var fn = eval( "bf.B_F_Namn" + i + ".value" );
  var ln = eval( "bf.B_L_Namn" + i + ".value" );
  if ( fn !== "" || ln !== "" ) {
    if ( fn == "" ) {
      alert( 'First name missing for author' );
      eval( "bf.B_F_Namn" + i + ".focus()" );
      return false;
      }
    if ( ln == "" ) {
      alert( 'Last name missing for author' );
      eval( "bf.B_L_Namn" + i + ".focus()" );
      return false;
      }
    }
  }

if ( bf.B_publisher.value == "" ) {
  alert( "The publisher is required" );
  bf.B_publisher.focus();
  return false
  }
  
if ( !bf.B_status[0].checked && !bf.B_status[1].checked ) {
  alert( "Specify if the book is published or forthcoming" );
  bf.B_status[0].focus();
  return false
  }

if ( bf.B_status[1].checked ) {
  if ( bf.B_year.value == "" ) {
    alert( "The year is required for published books" );
    bf.B_year.focus();
    return false;
    }
  }
  
if ( bf.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  bf.myemail.focus();
  return false;
  }

}

//--------------------------

function CheckChapterForm(button) {

var cf = button.form;

if ( cf.C_title.value == "" ) {
  alert( 'The Title is missing' );
  cf.C_title.focus();
  return false;
  }

if ( ( cf.C_F_Namn1.value == "" ) || ( cf.C_L_Namn1.value == "" ) ) {
  alert( 'First or last name missing for first author' );
  if ( cf.C_F_Namn1.value == "" ) {
    cf.C_F_Namn1.focus();
    }
  else {
    cf.C_L_Namn1.focus();
    }
  return false;
  }

for ( var i = 1; i <= cf.C_OldNumAuth.value; i++ ) {
  var fn = eval( "cf.C_F_Namn" + i + ".value" );
  var ln = eval( "cf.C_L_Namn" + i + ".value" );
  if ( fn !== "" || ln !== "" ) {
    if ( fn == "" ) {
      alert( 'First name missing for author' );
      eval( "cf.C_F_Namn" + i + ".focus()" );
      return false;
      }
    if ( ln == "" ) {
      alert( 'Last name missing for author' );
      eval( "cf.C_L_Namn" + i + ".focus()" );
      return false;
      }
    }
  }

if ( ( cf.C_E_F_Namn1.value == "" ) || ( cf.C_E_L_Namn1.value == "" ) ) {
  alert( 'First or last name missing for first Editor' );
  if ( cf.C_E_F_Namn1.value == "" ) {
    cf.C_E_F_Namn1.focus();
    }
  else {
    cf.C_E_L_Namn1.focus();
    }
  return false;
  }

for ( var i = 1; i <= cf.C_OldNumEds.value; i++ ) {
  var fn = eval( "cf.C_E_F_Namn" + i + ".value" );
  var ln = eval( "cf.C_E_L_Namn" + i + ".value" );
  if ( fn !== "" || ln !== "" ) {
    if ( fn == "" ) {
      alert( 'First name missing for Editor' );
      eval( "cf.C_E_F_Namn" + i + ".focus()" );
      return false;
      }
    if ( ln == "" ) {
      alert( 'Last name missing for Editor' );
      eval( "cf.C_E_L_Namn" + i + ".focus()" );
      return false;
      }
    }
  }

if ( cf.C_B_title.value == "" ) {
  alert( "The volume name is required" );
  cf.C_B_title.focus();
  return false
  }

if ( cf.C_publisher.value == "" && cf.C_sponsor.value == "" ) {
  alert( "The publisher or sponsor is required" );
  cf.C_publisher.focus();
  return false
  }
  
if ( !cf.C_status[0].checked && !cf.C_status[1].checked ) {
  alert( "Specify if the article is published or forthcoming" );
  cf.C_status[0].focus();
  return false
  }

if ( cf.C_status[1].checked ) {
  if ( cf.C_year.value == "" ) {
    alert( "The year is required for published chapters" );
    cf.C_year.focus();
    return false;
    }
  if ( cf.C_pages.value == "" && cf.C_chapter.value == "" ) {
    alert( "The pages or chapter is required for published chapters" );
    cf.C_pages.focus();
    return false;
    }
  }
  
if ( cf.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  cf.myemail.focus();
  return false;
  }

}

//--------------------------

function CheckHTTPForm(button) {

var hf = button.form;

if ( hf.wpfile1.value == "" && hf.exfile1.value == "" ) {
  alert( "No files to upload!" );
  hf.wpfile1.focus();
  return false;
  }

for ( var i = 1; i <= hf.numwp.value; i++ ) {
  var f = eval( "hf.wpfile" + i + ".value" );
  var d = eval( "hf.wpdesc" + i + ".value" );
  var t = eval( "hf.wptype" + i + ".value" );
  if ( f !== "" ) {
    if ( d == "" ) {
      alert( "Description missing for WP file " + i );
      eval( "hf.wpdesc" + i + ".focus()" );
      return false;
      }
    if ( t == "" ) {
      alert( "Type missing for WP file " + i );
      eval( "hf.wptype" + i + ".focus()" );
      return false;
      }
    }
  }
for ( var i = 1; i <= hf.numex.value; i++ ) {
  var f = eval( "hf.exfile" + i + ".value" );
  var d = eval( "hf.exdesc" + i + ".value" );
  var t = eval( "hf.extype" + i + ".value" );
  if ( f !== "" ) {
    if ( d == "" ) {
      alert( "Description missing for additional file " + i );
      eval( "hf.exdesc" + i + ".focus()" );
      return false;
      }
    if ( t == "" ) {
      alert( "Type missing for additional file " + i );
      eval( "hf.extype" + i + ".focus()" );
      return false;
      }
    }
  }
  
  
if ( hf.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  hf.myemail.focus();
  return false;
  }

}

//--------------------------

function CheckOSForm(button) {

var of = button.form;

if ( of.wpfile1.value == "" && of.exfile1.value == "" ) {
  alert( "No files to upload!" );
  of.wpfile1.focus();
  return false;
  }

for ( var i = 1; i <= of.numwp.value; i++ ) {
  var f = eval( "of.wpfile" + i + ".value" );
  var d = eval( "of.wpdesc" + i + ".value" );
  var t = eval( "of.wpFormat" + i + ".selectedIndex" );
  var n = eval( "of.wpFormat" + i + ".length" ) - 1;
  var o = eval( "of.wpO_Format" + i + ".value" );
  if ( f !== "" ) {
    if ( d == "" ) {
      alert( "Description missing for WP file " + i );
      eval( "of.wpdesc" + i + ".focus()" );
      return false;
      }
    if ( t == 0 || ( t == n && o == "" ) ) {
      alert( "Type missing for WP file " + i );
      eval( "of.wpFormat" + i + ".focus()" );
      return false;
      }
    if ( o !== "" && t !== n ) {
      alert( "Type specified both in select list and text box" );
      eval( "of.wpFormat" + i + ".focus()" );
      return false;
      }
    }
  }
for ( var i = 1; i <= of.numex.value; i++ ) {
  var f = eval( "of.exfile" + i + ".value" );
  var d = eval( "of.exdesc" + i + ".value" );
  var t = eval( "of.exFormat" + i + ".selectedIndex" );
  var n = eval( "of.exFormat" + i + ".length" ) - 1;
  var o = eval( "of.exO_Format" + i + ".value" );
  if ( f !== "" ) {
    if ( d == "" ) {
      alert( "Description missing for Additional file " + i );
      eval( "of.exdesc" + i + ".focus()" );
      return false;
      }
    if ( t == 0 || ( t == n && o == "" ) ) {
      alert( "Type missing for Additional file " + i );
      eval( "of.exFormat" + i + ".focus()" );
      return false;
      }
    if ( o !== "" && t !== n ) {
      alert( "Type specified both in select list and text box" );
      eval( "of.exFormat" + i + ".focus()" );
      return false;
      }
    }
  }
  
  
if ( of.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  of.myemail.focus();
  return false;
  }

}

//---------------------

function CheckEmail(button) {

if ( button.form.myemail.value == "" ) {
  alert( 'Your e-mail is missing' );
  button.form.myemail.focus();
  return false;
  }

}
