var	Options="location=no";
	Options+=",toolbar=no";
	Options+=",menubar=no";
	Options+=",status=no";
	Options+=",scrollbars=no";
	Options+=",resizable=no";
	Options+=",top=65";
	Options+=",left=95";
	Options+=",width=420";
	Options+=",height=150";

function openfieldsearch(sendto)
{

window.open(sendto, "blank",Options);
}


function handleEnter (field, event) {
var uagent = window.navigator.userAgent.toLowerCase();
var ab=0;      
    
   if((uagent.indexOf('netscape') != -1) || (uagent.indexOf('opera') != -1)){
      var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
        if (keyCode == 13) {
            var i;
            for (i = 0; i < field.form.elements.length; i++)
                if (field == field.form.elements[i])
                break;
                i = (i + 1) % field.form.elements.length;
                field.form.elements[i].focus();
                ab=1;
        }   
    }
    
    if((uagent.indexOf('msie') != -1) || (uagent.indexOf('opera') != -1)){
        if (window.event.keyCode == 13){
        window.event.keyCode = 0;
        ab=1;
        }
    }

    if (ab == 1){
        alert("Enter key is disabled, please click on the image to submit information");
        return false;
    }else{
        return true;
    }
    
}


function chkforsplchars(){
            
            var srchstr = document.forms.frm1.searchfield.value;
            //var strsrch = srchstr.toLowerCase(); 
            
            if((srchstr.indexOf("&") >-1) || (srchstr.indexOf("*") >-1) || (srchstr.indexOf("#") >-1) || (srchstr.indexOf("@") >-1) || 
            (srchstr.indexOf("~") >-1) || (srchstr.indexOf("(") >-1) || (srchstr.indexOf(")") >-1) || (srchstr.indexOf("!") >-1) || 
            (srchstr.indexOf("%") >-1) || (srchstr.indexOf("^") >-1) || (srchstr.indexOf("-") >-1) || (srchstr.indexOf("_") >-1) || 
            (srchstr.indexOf("+") >-1) || (srchstr.indexOf("=") >-1) || (srchstr.indexOf("`") >-1) ||
            (srchstr.indexOf(":") >-1) || (srchstr.indexOf(";") >-1) || (srchstr.indexOf("\"") >-1) || (srchstr.indexOf("'") >-1) ||
            (srchstr.indexOf("<") >-1) || (srchstr.indexOf(",") >-1) || (srchstr.indexOf(">") >-1) || (srchstr.indexOf(".") >-1) ||
            (srchstr.indexOf("?") >-1) || (srchstr.indexOf("/") >-1) ){
            alert("Special characters like ~`!@#$%$%^&*()_-+=  is  not allowed to search.");  
            document.forms.frm1.searchfield.value ="";
            document.forms.frm1.searchfield.focus();
            return false;
            }else{
            document.forms.frm1.submit();            
            }
            
            
        }

function PUBTOCQuery(num,val){

    var qry =  document.srchform.queryText.value;
    var sc =  document.srchform.scope.value;
    if(qry.length < 1){
    	  alert("Please enter search criteria.");
    	  return false;
    }
    if(sc.length > 1){
    qry = "(" + qry + " <in> " + sc + ")";
    }
    qry = qry + " <and> (" + num + " <in> " +  val + ")"; 
    document.srchform.queryText.value = qry;
}

function HistorySearch()
{
    var vals="";
    var sc = document.history.op.value; 
    j=document.history.chklist.length; 
        
    for (i=0; i<j; i++) {
	    if(document.history.chklist[i].checked){
	        if(vals.length > 1){
	            vals = vals + "<" + sc + ">" + document.history.chklist[i].value
	        }
	        else{
	            vals = document.history.chklist[i].value
	        }
	    }
    }
    document.history.queryText.value = vals;
    alert(vals);

}

function ValidateBasicQry(){
    
    document.bsearch.queryblock.value="";
    
    var qr1 = document.bsearch.query1.value;
    var qr2 = document.bsearch.query2.value;
    var qr3 = document.bsearch.query3.value;
    
    if(qr1.length < 1 && ( qr2.length > 1 || qr3.length > 1) ) {
        alert("Please Enter search term in searchbox properly.");
    }
    if(qr2.length < 1 && qr3.length > 1) {
	    alert("Please Enter search term in searchbox properly.");
    }
        
}

function removeBasicText(){
        document.bsearch.query1.value="";
        document.bsearch.query2.value="";
        document.bsearch.query3.value="";
}

function BuildSrchQuery(YY){
    
    var queryText;
    
    var qry1 = document.bsearch.query1.value;
    var len1 = qry1.length;
            
    var qry2 = document.bsearch.query2.value;
    var len2 = qry2.length;
            
    var qry3 = document.bsearch.query3.value;
    var len3 = qry3.length;
    
    var sc1 = document.bsearch.scope1.value;
    var sc2 = document.bsearch.scope2.value;
    var sc3 = document.bsearch.scope3.value;
    
    var op1 = document.bsearch.op1.value;
    var op2 = document.bsearch.op2.value;

    var p1 = document.bsearch.py1.value;
    var p2 = document.bsearch.py2.value;
    	    
    var queryText = document.bsearch.queryblock.value;
    queryText = queryText.toLowerCase();
    if(queryText.length > 0){
    	var nLoc = queryText.indexOf("<in>");
    	var containLoc = queryText.indexOf("<contains>");
    	if(nLoc==-1 && containLoc == -1 ){
    	  queryText = "(("+ queryText +")<in>metadata)";
    	}
    	document.bsearch.reqloc.value = "adv";
    	
    }

    if( len1 > 0 || len2 > 0 || len3 > 0) {
       
        if(sc1.length > 0 && qry1.length > 0){
            qry1 = " ( " + qry1 + "<in>" + sc1 + " ) ";
        }
        
        if(sc2.length > 0 && qry2.length > 0){
            qry2 = " ( " + qry2 + "<in>" + sc2 + " ) ";
        }
        
        if(sc3.length > 0 && qry3.length > 0){
            qry3 = " ( " + qry3 + "<in>" + sc3 + " ) ";
        }
	
		
        
        if(len1 > 0 && len2 < 1 && len3 < 1){
         
          queryText = qry1;
        }
        
        if(len1 > 0 && len2 > 0 && len3 < 1){
          queryText = qry1 + "<" + op1 +">" + qry2;
        }
        
        if(len1 > 0 && len2 > 0 && len3 > 0){
          queryText = qry1 + "<" + op1 +">" + qry2 + "<" + op2 + ">" +qry3;
        }
    
    }
    queryText=fixsrchquote(queryText);
    
    
    if(p1 == '1950' && p2 == YY && queryText.length > 0){
	    queryText = queryText;
    }else{
        queryText = "(" + queryText +") <and> (pyr >= "+ p1 + " <and> pyr <= " + p2 + ")";
    }
  	
    document.bsearch.queryText.value = queryText.toLowerCase();    
    
    if(document.bsearch.coll1.checked ==true) {
	    document.bsearch.coll6.value = "preprint";  
    }
    if(document.bsearch.coll1.checked ==false) {
	    document.bsearch.coll6.value = "";
    }
   
}

 function activate(radioAction) {

    if (radioAction=='activate')
    {
    
    document.bsearch.coll1.disabled=false;
    document.bsearch.coll2.disabled=false;
    document.bsearch.coll3.disabled=false;
    document.bsearch.coll4.disabled=false;
    document.bsearch.coll5.disabled=false;
    document.bsearch.coll1.checked=true;
    document.bsearch.coll2.checked=true;
    document.bsearch.coll3.checked=true;
    document.bsearch.coll4.checked=true;
    document.bsearch.coll5.checked=true;
    }
    else
    {
    document.bsearch.coll1.disabled=true;
    document.bsearch.coll2.disabled=true;
    document.bsearch.coll3.disabled=true;
    document.bsearch.coll4.disabled=true;
    document.bsearch.coll5.disabled=true;
    document.bsearch.coll1.checked=false;
    document.bsearch.coll2.checked=false;
    document.bsearch.coll3.checked=false;
    document.bsearch.coll4.checked=false;
    document.bsearch.coll5.checked=false;
    }
}

function go_back() {
    history.length=0;
}

function SearchwithinSearch() {
	var qry = document.search.queryText.value;
	qry = qry.toLowerCase();
	var inLoc = qry.indexOf("<in>");
	var containLoc = qry.indexOf("<contains>");
	if(qry.length > 1 && inLoc== -1 && containLoc == -1){
	    qry = "(" + document.search.queryText.value + "<IN>metadata)";
    	}
	if(document.search.chkresult.checked == true) {
	    document.search.chkresult.value="true";
	    qry = "(" + document.search.oldqrytext.value + "<AND>" + qry.toLowerCase() + ")";
	}
	qry=fixsrchquote(qry);
        document.search.queryText.value = qry;
}

function SelectTOC() {
    var vals="";
    j=document.viewtoc.checkbox.length; 
    for (i=0; i<j; i++) {
	    if(document.viewtoc.checkbox[i].checked) vals = vals + document.viewtoc.checkbox[i].value
    }
    alert(vals);
}

function locateurl() {
  var loc_url;
  loc_url = document.location.toString();
  loc_url = loc_url + "&LPChangeStyle=xplorePrint";       
  return loc_url;
}

function locatequery() {
   if(!document.Search.query1.value) {
      alert("Please enter Search text");
	  return false;
    } else {
      var qstr = "((" + document.Search.query1.value + ")and("+document.Search.puNumber.value +"<in>punumber))";
	  document.Search.queryText.value = qstr;
	  return true; 
    }
}

function fixsrchquote(oldstr) {
	
	if(oldstr.length < 1){
		nocriteria="Enter one or more keywords";	
		alert("Enter one or more keywords");
		return nocriteria;
	}
	
	nLoc = 0;
   	nStart = 0;
    	var  tempstr;
	tempstr = '"';
	nLoc = oldstr.indexOf(tempstr, nStart);
	sTemp = "";

	while(nLoc != -1) {
		sTemp += oldstr.substring(nStart, nLoc);
		sTemp += "~~";
		nStart = nLoc+1;
		nLoc = oldstr.indexOf(tempstr, nStart);
	}
	sTemp += oldstr.substring(nStart, oldstr.length);
	oldstr = sTemp;
	
	nLoc = 0;
	nStart = 0;
	tempstr = "'";
	nLoc = oldstr.indexOf(tempstr, nStart);
	sTemp = "";
	while(nLoc != -1) {
		sTemp += oldstr.substring(nStart, nLoc);
		sTemp += "~~";
		nStart = nLoc+1;
		nLoc = oldstr.indexOf(tempstr, nStart);
	}
	sTemp += oldstr.substring(nStart, oldstr.length);
	
	return sTemp;
}

function removedash(d) {
	nLoc = 0;
    nStart = 0;
    var  tempstr;
	tempstr = '_';
	nLoc = d.indexOf(tempstr,nStart);
	sTemp = "";
	while(nLoc != -1) {
		sTemp += d.substring(nStart,nLoc);
		sTemp += " ";
		nStart = nLoc+1;
		nLoc = d.indexOf(tempstr,nStart);
	}
    sTemp += d.substring(nStart,d.length);

	return sTemp;
}

function removespace(s) {
	strp = new String();
	strp1 = new String();
	strp = s;
	strp1 = s;
    chp = " ";
    nStart=0; 
	var pos = strp.lastIndexOf(chp);
    if (pos >= 0) {
 	    strp = strp.substring(nStart,pos) + "%20";
	    nStart = pos + 1;
	    strp += strp1.substring(nStart, strp1.length);
	}
	return strp;
}

function fixperiod(s) {
	nLoc = 0;
    nStart = 0;
	nLoc = s.indexOf(".",nStart);
	sTemp = "";
	while(nLoc != -1)
	{
		sTemp += s.substring(nStart,nLoc);
		sTemp += ".%20";
		nStart = nLoc +1;
		nLoc = s.indexOf(".",nStart);
	}
	sTemp += s.substring(nStart,s.length);
	return sTemp;
}

function messagepage() {
      alert( "Information is not available at this time.");
}

var	strWinOptions="location=no";
	strWinOptions+=",titlebar=no";
	strWinOptions+=",toolbar=no";
	strWinOptions+=",menubar=no";
	strWinOptions+=",status=no";
	strWinOptions+=",scrollbars=yes";
	strWinOptions+=",resizable=no";
	strWinOptions+=",top=0";
	strWinOptions+=",left=0";
	strWinOptions+=",width=620";
	strWinOptions+=",height=530";
	
function loadwindow(strUrl) {
	window.open(strUrl,"_blank",strWinOptions);
}

function loademail(strUrl) {
	window.open(strUrl,"_blank",strWinOptions);
}

var	strHelpOptions="location=no";
	strHelpOptions+=",toolbar=no";
	strHelpOptions+=",menubar=no";
	strHelpOptions+=",status=no";
	strHelpOptions+=",scrollbars=yes";
	strHelpOptions+=",resizable=yes";
	strHelpOptions+=",top=0";
	strHelpOptions+=",left=0";
	strHelpOptions+=",width=320";
	strHelpOptions+=",height=400";

function loadhelp(strUrl) {
	window.open(strUrl, "Help", strHelpOptions);
}

var	strfOptions="location=yes";
	strfOptions+=",toolbar=yes";
	strfOptions+=",menubar=yes";
	strfOptions+=",status=yes";
	strfOptions+=",scrollbars=yes";
	strfOptions+=",resizable=yes";
	strfOptions+=",top=50";
	strfOptions+=",left=50";
	strfOptions+=",width=650";
	strfOptions+=",height=650";

function loadfback(fUrl) {
	window.open(fUrl, "blank", strfOptions);
}

function getAccess (name) {
    var mtcookie = document.cookie; 
    var cname = name + "=";
    var clen = mtcookie.length;
    var cbegin = 0;
    while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
        if (mtcookie.substring(cbegin, vbegin) == cname) { 
            var vend = mtcookie.indexOf (";", vbegin);
            if (vend == -1) vend = clen;
            return unescape(mtcookie.substring(vbegin, vend));
        }
        cbegin = mtcookie.indexOf(" ", cbegin) + 1;
        if (cbegin == 0) break;
    }
    return;
}

function openurl(sendto)
{
//alert(sendto);  
    
window.open(sendto, "blank", strfOptions);
}


var	strmmOptions="location=no";
	strmmOptions+=",toolbar=no";
	strmmOptions+=",menubar=no";
	strmmOptions+=",status=no";
	strmmOptions+=",scrollbars=yes";
	strmmOptions+=",resizable=yes";
	strmmOptions+=",top=0";
	strmmOptions+=",left=0";
	strmmOptions+=",width=550";
	strmmOptions+=",height=550";

function mmfiles(strUrl) {
	window.open(strUrl, "Multimedia", strmmOptions);
}

// Script to validate the abstract e-mail form
function isEmailformfilled() {
    var from = document.emailform.emailfrom.value;
    var to = document.emailform.emailto.value;
    var fname = document.emailform.fullname.value;
    
    if ((fname == null) || (fname.length < 1)) {
        alert("You must enter your name to continue!");
        document.emailform.fullname.focus();
        return false;
    }
    if ((from == null) || (from.length < 1)) {
		alert("You must enter your E-MAIL to continue!");
    	document.emailform.emailfrom.focus();        
    	return false;
	}
	else if ((from.indexOf("@") == -1) || (from.indexOf(".") == -1)) {
        alert("Incorrect email address. Please re-enter");
        document.emailform.emailfrom.focus();        
        return false;
	}
	if ((to == null) || (to.length < 1)) {
		alert("You must enter recipients E-MAIL to continue!");
    	document.emailform.emailto.focus();        
    	return false;
	}
	else if ((to.indexOf("@") == -1) || (to.indexOf(".") == -1)) {
        alert("Incorrect email address. Please re-enter");
        document.emailform.emailto.focus();        
        return false;
	}
}

// For searchresult.jsp
function isoneselected(f) {
    for (var i = 0; i < f.length; i++) {
        var c = f.elements[i];
        if (c.name == "chklist") {
            if (c.checked) {
                return true;
            }
        }
    }
    alert("Please select atleast one article to proceed!");
    return false;
}

// For advsearch.jsp
function isvalidsearch(f,yr) {
    var q1 = "true";
    var q2 = "true";
    for (var i = 0; i < f.length; i++) {
        var c = f.elements[i];
        if (c.name == "query1") {
            if ((c.value == null) || (c.value == "") || isblank(c.value)) {
                q1 = "false";
            }
        } 
        if (c.name == "queryblock") {
            if ((c.value == null) || (c.value == "") || isblank(c.value)) {
                q2 = "false";
            }
        }
    }
    if ((q1 == "false") && (q2 == "false")) {
    alert("Please enter atleast one search criteria!");
    return false;
    }
    BuildSrchQuery(yr);
    return true;
}

function isblank(s) {
    for (var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) {
            return false;
        }
    }
    return true;
}
function myOpenWindow(winURL, winName, winFeatures, winObj) {
if (winObj != null) {
// the window has already been created, but did the user close it?
// if so, then reopen it. Otherwise make it the active window.
if (!winObj.closed) {
winObj.focus();
}
// otherwise fall through to the code below to re-open the window
}

// if we get here, then the window hasn't been created yet, or it
// was closed by the user.
theWin = window.open(winURL, winName, winFeatures);
theWin.blur()
theWin.focus()
}