//Javascript functions for JCSE
//document variables
var commentwindow;
var newcommentwindow;
var helpwin;
var commentmode=1;      //0 = inline, 1 = window, 2 = for printing
var lastpara=-1;        //last paragraph number
var dirRoot='/';
var jrnl_domain='www.jcse.org';
var jrnl_root='http://'+jrnl_domain+'/';
var CorrosionHome="corrosiontest.its.manchester.ac.uk/";
var pubYear='2001';     //should be in paper include - from paper database
var dynInc=1;	        //1 for Dynamic include files, 0 for static
var commentPara=1;	//the current paragraph number for a comment
var maxVol=11;		//maximum volume number
var lgi=false;

//display links to other volumes
function linkVol(n) {
var i;
for (i=1;i<=maxVol;i++) {
    if (i!=n) {
        document.write('<A HREF="'+jrnl_root+'view_vol.php?vol='+i+'">Volume '+i+'</A> ');
		}
	else {
        document.write('Volume '+i+' ');
		}
	if (i!=maxVol) {
		document.write('| ');
        }
    }
}

//display a mailto: link to Bob Cottis
function mailtobob() {
  document.write('<a href="mailto:bob.cottis@manchester.ac.uk">Bob Cottis</a>')
}

//display a mailto: link to JCSE Admin
function mailtoadmin() {
  document.write('<a href="mailto:Admin@jcse.org">JCSE Administration</a>')
}

//display a mailto: link to the Editor
function mailtoeditor() {
  document.write('<a href="mailto:Editor@jcse.org">Editor</a>')
}

//display a general mailto link with the email address as the displayed text
function mailto2(a,b) {
  document.write('<a href="mailto:'+a+'@'+b+'">'+a+'@'+b+'</a>')
}

//display a general mailto link
function mailto(a,b,c) {
  document.write('<a href="mailto:'+a+'@'+b+'">'+c+'</a>')
}

//display a cross reference to an endnote
function crossref(n) {
  document.write('<a href="#_edn' + n + '">' + n + '</a>')
}

//display a reference definition number
function defref(n) {
  document.write('<a name="_edn' + n + '">' + n + '</a>. ')
}

//display the message '(click for a larger image)' if not a print mode
function ifscreenclick() {
  ifscreen(' (click for a larger image)')
}

//display text for the specified commentmode only
function ifmode(c,t) { //c is required commentmode, t is text
  if (commentmode==c) {
    document.write(t)
  }
}

//display text for all commentmodes except that specified
function ifnotmode(c,t) { //c is excluded commentmode, t is text
  if (commentmode!=c) {
    document.write(t)
  }
}

//display text for screen display modes only
function ifscreen(t) { //t is text
  if ((commentmode==0)||(commentmode==1)) {
    document.write(t)
  }
}

//display text for print modes only
function ifprint(t) { //t is text
  if ((commentmode==2)||(commentmode==3)) {
    document.write(t)
  }
}

//display a standard footer
function footer() {
comment(9999);
switch (commentmode) {
  case 2:
  case 3:
    document.write('<HR><P>This paper has been printed from the Journal of Corrosion Science and Engineering, ');
    document.write('the online journal for corrosion and its control, ISSN 1466-8858. Freely available on ' + jrnl_root + '. ');
    document.write('Comments can be added to papers on the online version.</P>');
    document.write('<P>© ' + pubYear + ' University of Manchester, Corrosion and Protection Centre.</P>');
    break;
  case 0:
  case 1:
    document.write('<hr>');
    notify();
    document.write('<p>Send Mail to the <a href="mailto:Editor@jcse.org">Editor (Editor@jcse.org)</a></p>');
    document.write('<p><a href="'+jrnl_root+'">Journal of Corrosion Science and Engineering Home Page</a><br>');
    document.write('<a href="http://' + CorrosionHome + 'default.htm">Corrosion Information Server</a><br>');
    document.write('Center for Electrochemical Science and Engineering, University of Virginia (JCSE ');
    document.write('Mirror Site - currently being redeveloped)</p>');
    break;
  }
}

//display a standard footer for pages without comments
function footernc() {
switch (commentmode) {
  case 2:
  case 3:
    document.write('<HR><P>This paper has been printed from the Journal of Corrosion Science and Engineering, ');
    document.write('the online journal for corrosion and its control, ISSN 1466-8858. Freely available on ' + jrnl_root + '. ');
    document.write('Comments can be added to papers on the online version.</P>');
    document.write('<P>© ' + pubYear + ' University of Manchester, Corrosion and Protection Centre.</P>');
    break;
  case 0:
  case 1:
    document.write('<hr>');
    document.write('<p>Send Mail to the <a href="mailto:Editor@jcse.org">Editor (Editor@jcse.org)</a></p>');
    document.write('<p><a href="'+jrnl_root+'">Journal of Corrosion Science and Engineering Home Page</A><br>');
    document.write('<a href="http://' + CorrosionHome + 'default.htm">Corrosion Information Server</a><br>');
    document.write('Center for Electrochemical Science and Engineering, University of Virginia (JCSE ');
    document.write('Mirror Site - currently being redeveloped)</p>');
    break;
  }
}

//display a standard footer for 'non-paper' pages
function show_ftr() {
    document.write('<hr>');
    document.write('<p>Send Mail to the <a href="mailto:Editor@jcse.org">Editor (Editor@jcse.org)</a></p>');
    document.write('<p><a href="'+jrnl_root+'">Journal of Corrosion Science and Engineering Home Page</A><br>');
    document.write('<a href="http://' + CorrosionHome + 'default.htm">Corrosion Information Server</a><br>');
    document.write('Center for Electrochemical Science and Engineering, University of Virginia (JCSE ');
    document.write('Mirror Site - currently being redeveloped)</p>');
}

//get commentmode from querystring
function getcommentmode() {
var str=location.search;
if (str.search('commentmode=0')!=-1) {commentmode=0};
if (str.search('commentmode=1')!=-1) {commentmode=1};
if (str.search('commentmode=2')!=-1) {commentmode=2};
if (str.search('commentmode=3')!=-1) {commentmode=3};
switch (commentmode) {
  case 2:		//print
    document.write('<link rel="stylesheet" type="text/css" href="'+ jrnl_root +'config/jrnl_web_print.css">');
    break;
  case 3:		//special print for JDS papers
    document.write('<link rel="stylesheet" type="text/css" href="'+ jrnl_root +'config/jrnl_web_printjds.css">');
    break;
  case 1:
  case 0:
    document.write('<link rel="stylesheet" type="text/css" href="' + jrnl_root + 'config/jrnl_web.css">');
  }
}


//**********************************************
//Display JCSE logo and random advert in a table
function writeheader() {
var r;
switch (commentmode) {
  case 2:		//print
    //for now don't print adverts
    document.write('<a href="/default.php"><img border="0" src="/images/jrnl_logo.gif" ');
    document.write('alt="JCSE Logo" width="600" height="42"></A><BR><font size="2">ISSN 1466-8858</font><BR>');
    break;
  case 3:		//special print for JDS papers
    //for now don't print adverts
    document.write('<a href="/default.php"><img border="0" src="/images/jrnl_logo.gif" ');
    document.write('alt="JCSE Logo" width="600" height="42"></A><br /><font size="2">ISSN 1466-8858</font><br />');
    break;
  case 1:
  case 0:
    //r=Math.round(Math.random()*ad.length-0.5);
    //document.write('<table border="0" cellspacing="1" cellpadding="0">');
    //document.write('<table border="0" cellspacing="1" cellpadding="0">');
    //document.write('<tr><td><a href="' + jrnl_root + 'Default.htm"><img border="0" src="');
    //document.write(jrnl_root+'images/jcselogo_left.gif" alt="JCSE Logo, click for home page" width="337" height="84"></A>');
    document.write('<a href="/default.php"><img border="0" src="/images/jrnl_logo.gif" alt="JCSE Logo, click for home page" width="1200" height="84"></A>');
    //document.write('</td><td><a href="'+ad[r].l+'">');
    //document.write('<img border="0" src="'+ jrnl_root +'ads/ad'+ad[r].i+'.'+ad[r].t);
    //document.write('" alt="'+ad[r].alt+'" width="'+ad[r].w+'" height="84"></A></td>');
    //document.write('<td><img border="0" src="'+jrnl_root+'ipix-2.php?ad='+ad[r].i);
    //document.write('&pg='+location.href+'"></td>');
    document.write('<br /><font size="2">ISSN 1466-8858</font><br />');
    
  }
}


//**********************************************
//write the navigation buttons to the child frame or window
function writenav(wn,ix) {
var cnext, cnextthrd, cnextpara, cprev, cprevthrd, cprevpara, i;
//wn.write("writenav called with ix=",ix,"<br>");
//first get navigation pointers
cnext = cnextthrd = cnextpara = cprev = cprevthrd = cprevpara = -1;
for(i = ix+1; (i<c.length) && (cnextpara==-1); i++) {
  if ((cnext==-1) && (c[i].s==c[ix].s) && (c[i].p==c[ix].p)) {cnext=i};
  if ((cnextthrd==-1) && (c[i].s!=c[ix].s) && (c[i].p==c[ix].p)) {cnextthrd=i};
  if ((cnextpara==-1) && (c[i].p!=c[ix].p)) {cnextpara=i};
  //wn.write("i=",i," ix=",ix," cnextpara=", cnextpara,"<br>");
  }
for(i = 0; (i<ix) && (cprev==-1); i++) {
  if ((cprev==-1) && (c[i].s==c[ix].s) && (c[i].p==c[ix].p)) {cprev=i}
  if ((cprevthrd==-1) && (c[i].s!=c[ix].s) && (c[i].p==c[ix].p)) {cprevthrd=i}
  if ((cprevpara==-1) && (c[i].p!=c[ix].p)) {cprevpara=i}
  //wn.write("i=",i," ix=",ix," cprevpara=", cprevpara,"<br>");
  }
//wn.write(ix," ",cprevpara, " ", cprevthrd, " ", cprev, " ", cnext, " ", cnextthrd, " ", cnextpara);
if (cprevpara>-1) {
  wn.write('<a href="javascript:window.opener.windowcomment('+cprevpara+')"><img border="0" src="' + jrnl_root + 'images/jrnl_prev_para.gif" alt="Go to previous paragraph with a comment"></a>');
  } else {
  wn.write('<img border="0" src="'+ jrnl_root +'images/jrnl_prev_para_dim.gif" >');
  }
if (cprevthrd>-1) {
  wn.write('<a href="javascript:window.opener.windowcomment('+cprevthrd+')"><img border="0" src="' + jrnl_root + 'images/jrnl_prev_thrd.gif" alt="Go to previous comment thread in this paragraph" ></a>');
  } else {
  wn.write('<img border="0" src="' + jrnl_root + 'images/jrnl_prev_thrd_dim.gif" >');
  }
if (cprev>-1) {
  wn.write('<a href="javascript:window.opener.windowcomment('+cprev+')"><img border="0" src="' + jrnl_root + 'images/jrnl_prev.gif" alt="Go to previous comment in this thread" ></a>');
  } else {
  wn.write('<img border="0" src="' + jrnl_root + 'images/jrnl_prev_dim.gif" >');
  }
if (cnext>-1) {
  wn.write('<a href="javascript:window.opener.windowcomment('+cnext+')"><img border="0" src="' + jrnl_root + 'images/jrnl_next.gif" alt="Go to next comment in this thread" ></a>');
  } else {
  wn.write('<img border="0" src="' + jrnl_root + 'images/jrnl_next_dim.gif" >');
  }
if (cnextthrd>-1) {
  wn.write('<a href="javascript:window.opener.windowcomment('+cnextthrd+')"><img border="0" src="' + jrnl_root + 'images/jrnl_next_thrd.gif" alt="Go to next comment thread in this paragraph" ></a>');
  } else {
  wn.write('<img border="0" src="' + jrnl_root + 'images/jrnl_next_thrd_dim.gif" >');
  }
if (cnextpara>-1) {
  wn.write('<a href="javascript:window.opener.windowcomment('+cnextpara+')"><img border="0" src="' + jrnl_root + 'images/jrnl_next_para.gif" alt="Go to next paragraph with a comment" ></a>');
  } else {
  wn.write('<img border="0" src="' + jrnl_root + 'images/jrnl_next_para_dim.gif" >');
  }
wn.write('<a href="'+jrnl_root+'add_comment.php?mode=a&papid='+papid+'&par='+c[ix].p+'&sub='+c[ix].s+'"><img border="0" src="' + jrnl_root + 'images/jrnl_new_comment.gif" alt="Add a new comment"></a>');
}

//**********************************************
//open a new comment window
function newcomment(para) {
if ((newcommentwindow == null) || newcommentwindow.closed) {
  //window doesn't exist or is closed - open it
  newcommentwindow = window.open("","newcommentwindow","width=640,height=480,resizable=yes,scrollbars=yes");
  }
//now load add comment page
newcommentwindow.location=""+jrnl_root+"add_comment.php?vol="+vol+"&pap="+pap+"&par="+para+"&papid="+papid+"&mode=a";
}

//**********************************************
//open a help window
function helpwindow() {
if ((helpwin == null) || helpwin.closed) {
  //window doesn't exist or is closed - open it
  helpwin = window.open("","helpwin","width=640,height=480,resizable=yes,scrollbars=yes");
  }
//now load add comment page
helpwin.location=""+jrnl_root+"help.php";
}

//*********************************************
//Display a Notify link (and give other options for page display)
function notify() {
switch (commentmode) {
  case 0:
    if (lgi) {
		document.write('<A HREF="'+jrnl_root+'notify.php?papid='+papid+'" onClick="popup = window.open("'+jrnl_root+
			'notify.php?papid='+papid+'", "Add/Remove Watch", "height=450,width=300,scrollbars=yes,resizable=yes"); return false">Watch this paper for new comments</A>')
		}
	else
		{
		document.write("Please note that as you are not currently logged-in, you will not be able to add yourself ");
		document.write("to the watch list to watch for new comments, or to make comments on the paper. Please ");
		document.write('<a href="/jrnl_login.php">Login</a> if you wish to do either of these.<br>');
		}
    document.write(' | <A HREF="'+jrnl_root+'volume'+vol+'/paper'+pap+'/v'+vol+'p'+pap+'.php?commentmode=1">Display comments in window</A>')
    document.write(' | <A HREF="'+jrnl_root+'volume'+vol+'/paper'+pap+'/v'+vol+'p'+pap+'.php?commentmode=2">Display for printing</A>')
    document.write(' | <A HREF="javascript: helpwindow();">Help</A><BR>');
    break;
  case 1:
    if (lgi) {
		document.write('<A HREF="'+jrnl_root+'notify.php?papid='+papid+'" onClick="popup = window.open("'+jrnl_root+
			'notify.php?papid='+papid+'", "Add/Remove Watch", "height=450,width=300,scrollbars=yes,resizable=yes"); return false">Watch this paper for new comments</A>')
		}
	else
		{
		document.write("Please note that as you are not currently logged-in, you will not be able to add yourself ");
		document.write("to the watch list to watch for new comments, or to make comments on the paper. Please ");
		document.write('<a href="/jrnl_login.php">Login</a> if you wish to do either of these.<br>');
		document.write('Watch this paper for new comments')
		}
    document.write(' | <A HREF="'+jrnl_root+'volume'+vol+'/paper'+pap+'/v'+vol+'p'+pap+'.php?commentmode=0">Display comments inline</A>')
    document.write(' | <A HREF="'+jrnl_root+'volume'+vol+'/paper'+pap+'/v'+vol+'p'+pap+'.php?commentmode=2">Display for printing</A>')
    document.write(' | <A HREF="javascript: helpwindow();">Help</A><BR>');
    break;
  }
}

//*********************************************
//Display a Notify link for a Preprint
function notifyPreprint() {
switch (commentmode) {
  case 0:
    document.write('<A HREF="'+jrnl_root+'notify.php?papid='+papid+'&mode=a">Watch this paper for new comments</A>')
    document.write(' | <A HREF="javascript: helpwindow();">Help</A><BR>');
    break;
  case 1:
    document.write('<A HREF="'+jrnl_root+'notify.php?papid='+papid+'&mode=a">Watch this paper for new comments</A>')
    document.write(' | <A HREF="javascript: helpwindow();">Help</A><BR>');
    break;
  }
}

//**********************************************
//Display inline code for comment, or display comment inline
function comment() {
var i;
var para; // was a parameter passed to the function

//check for a parameter
if (arguments.length>0) {
    para = arguments[0];
    }
else {
    para = commentPara;
    commentPara++;
    }
//document.write("<P>Testing, Para="+para+"; commentmode="+commentmode+"</p>");
switch(commentmode) {

  case 0:		//inline
    //just display the comments for the PREVIOUS paragraph
    for(i=0;i < c.length;i++) {
      //document.write("displaying comment " +i+ "for paragraph " + lastpara);
      if (c[i].p==lastpara) {commenttable(document,i)}
      //document.write("END");
      } 
    lastpara=para;
    break;
  case 1:       //window
    //display the relevant icon in the left margin
    var idx=-1;
    for(i=0;i < c.length;i++) {
      if (c[i].p==para) {
        idx=i;
        break;
        }
      }
    if (para!=9999) { //don't diplay end marker
      if (idx>-1) {
        //there are comments on this paragraph
        document.write("<a href='Javascript:windowcomment("+idx+")' name ='BK"+para+"'>")
        document.write('<img border="0" src="'+jrnl_root+'images/comment1.gif" class=icon></a>\n')
        }
      else {
          //there are no comments on this paragraph
		  //don't show icon unless logged_in
		  if (lgi) {
          	document.write("<a href='Javascript:newcomment("+para+")' name ='BK"+para+"'>")
          	document.write('<img border="0" src="'+jrnl_root+'images/comment2.gif" class=icon></a>\n')
		  }
        }
      }
    break;
  case 2:		//print - do nothing for now
  case 3:
    break;
  }
}

//**********************************************
//Write comment display table
function commenttable(wn, i) {
//wn.write('|0|');
wn.write('<table border="1" width="90%"><tr><td width="100%" colspan="3"><b>Comment Subject:</b> ');
//wn.write('|1|');
wn.write(c[i].s+'</td></tr><tr><td width="45%"><b>Author:</b> '+c[i].a+'</td>');
//wn.write('|2|');
wn.write('<td width="45%"><b>Date:</b> '+c[i].d+'</td>');
wn.write('<td><A HREF="'+jrnl_root+'/add_comment.php?mode=a&papid='+papid+'&par='+c[i].p+'&sub='+c[i].s+'">Add</A></td>');
wn.write('</tr><tr><td width="100%" colspan="3">'+c[i].t+'</td></tr></table>');
//wn.write('|3|');
}

//**********************************************
//Display comment in separate window
function windowcomment(index) {
if ((commentwindow == null) || commentwindow.closed) {
  //window doesn't exist or is closed - open it
  commentwindow = window.open("","commentwindow","width=640,height=480,resizable=yes,scrollbars=yes");
  }
//first clear any existing text
commentwindow.document.open();
commentwindow.focus();
//then write next comment text
//first the style sheet
commentwindow.document.write('<html><head><link rel="stylesheet" type="text/css" href="'+jrnl_root+'config/jrnl_web.css"></head><body>');
commentwindow.document.write('<h3>Comment on Volume'+vol+', Paper '+pap+', Para '+c[index].p+'</h3>');
//then the navigation buttons
commentwindow.document.write('<p>');
writenav(commentwindow.document, index);
//then the comment table
commenttable(commentwindow.document,index);
//and move main window to bookmark
location=location.pathname+"#BK"+c[index].p+location.search;
commentwindow.document.write('</body></html>');
commentwindow.document.close();
return;
}

//**********************************************
//Display comment in frame
function FrameComment(index) {

}

//**********************************************
//Convert date in form "dd/mm/yy" to "dd Month yyyy"
function dateToLongFormat (d) {
var dArray;
dArray=d.split('/') //chop up the string into three parts
if (dArray[0].indexOf('0')==0) {
  dArray[0]=dArray[0].slice(1); //remove the leading zero
  }
switch (dArray[1]) {
  case '01' : dArray[1]='January'; break;
  case '02' : dArray[1]='February'; break;
  case '03' : dArray[1]='March'; break;
  case '04' : dArray[1]='April'; break;
  case '05' : dArray[1]='May'; break;
  case '06' : dArray[1]='June'; break;
  case '07' : dArray[1]='July'; break;
  case '08' : dArray[1]='August'; break;
  case '09' : dArray[1]='September'; break;
  case '10' : dArray[1]='October'; break;
  case '11' : dArray[1]='November'; break;
  case '12' : dArray[1]='December'; break;
  }
dArray[2] = '20'+dArray[2]; //!!!!!!! This will give an error in 2100!!!!!!!!!!
return(dArray);
}

function google_ad() {
document.write("<!-- SiteSearch Google -->");
document.write('<form method="get" action="http://www.google.co.uk/custom" target="_top">');
document.write('<table border="0" bgcolor="#ffffcc">');
document.write('<tr><td nowrap="nowrap" valign="top" align="left" height="32">');

document.write('</td>');
document.write('<td nowrap="nowrap">');
document.write('<input type="hidden" name="domains" value="'+jrnl_domain+'"></input>');
document.write('<input type="text" name="q" size="31" maxlength="255" value=""></input>');
document.write('<input type="submit" name="sa" value="Google Search"></input>');
document.write('</td></tr>');
document.write('<tr>');
document.write('<td>&nbsp;</td>');
document.write('<td nowrap="nowrap">');
document.write('<table>');
document.write('<tr>');
document.write('<td>');
document.write('<input type="radio" name="sitesearch" value="" checked="checked"></input>');
document.write('<font size="-1" color="#000000">Web</font>');
document.write('</td>');
document.write('<td>');
document.write('<input type="radio" name="sitesearch" value="'+jrnl_domain+'"></input>');
document.write('<font size="-1" color="#000000">'+jrnl_domain+'</font>');
document.write('</td>');
document.write('</tr>');
document.write('</table>');
document.write('<input type="hidden" name="client" value="pub-0421257259150762"></input>');
document.write('<input type="hidden" name="forid" value="1"></input>');
document.write('<input type="hidden" name="ie" value="ISO-8859-1"></input>');
document.write('<input type="hidden" name="oe" value="ISO-8859-1"></input>');
document.write('<input type="hidden" name="cof" value="GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"></input>');
document.write('<input type="hidden" name="hl" value="en"></input>');
document.write('</td></tr></table>');
document.write('</form>');
document.write('<!-- SiteSearch Google -->');
google_ad_client = "pub-0421257259150762";
google_alternate_ad_url = jrnl_root+"google_adsense_script.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "FF4500";
google_color_bg = "FFEBCD";
google_color_link = "DE7008";
google_color_url = "E0AD12";
google_color_text = "8B4513";
}