﻿/* Link opens to new browser window using rel="external" */
function externalLinks() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("href") &&
anchor.getAttribute("rel") == "external")
anchor.target = "_blank";
}
}
window.onload = externalLinks;
/* Pulldown menu */
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
/* Search */
function checkQuery() {
  var queryFld = document.keyword.query
  if (queryFld.value == "") {
    alert ("Please enter a query")
    queryFld.focus()
  return(false)
  }
  return(true)
}
function checkName() {
  var nameFld = document.ccso.NAME
  if (nameFld.value == "") {
    alert ("Please enter a name")
    nameFld.focus()
    return(false)
  }
  return(true)
}
function convertString( temp ) {
  var newString = "";
  var i=0;
  for( i=0; i < temp.length; i++ ) {
    if( temp.charAt(i) != " " ) {
      newString += temp.charAt(i);
    }
    else {
      newString += "+";
    }
  }
  return newString;
}
function startSearch() {
//vcu via Google
if( document.keyword.searchnav[0].checked ) {
 if( checkQuery() ) {
  var header = "http://www.vcu.edu/search/search.php?";
  var options = "&cx=011427294941142349901%3Aisqthw0ltmc&cof=FORID%3A11&sa.x=0";
  var searchVal = "q=" + convertString(document.keyword.query.value);
  eval( "location = " + "\"" + header + searchVal + options + "\"");
  }
 }
//people
if( document.keyword.searchnav[1].checked ) {
  if( checkQuery() ) {
    var header = "http://phonebook.vcu.edu?";
    options = "TYPE=All";
    searchVal = "&NAME=" + convertString(document.keyword.query.value);
    eval( "location = " + "\"" + header + options + searchVal + "\"" );
  }
}
//searchSearch
}
function setVCURadio(ip){
        if (ip.indexOf("128.172.")<0) {
                document.keyword.searchnav[0].checked = true;
        } else {
                document.keyword.searchnav[1].checked = true;
        }
}
function cleartextbox()
{
if (document.keyword.query.value == "Search")
document.keyword.query.value = "";
}
/* 
Login validation::
Login returns true if the string is a valid email address 
*/
function isValidEmail(str)
{
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
/* Returns true if the string is all numeric */
function isNumeric(sText)
{
    var validChars = "1234567890";
    var isNumber=true;
    sText = sText.toString();
    for (i = 0; i < sText.length && isNumber == true; i++) {
        if ((validChars.indexOf(sText.charAt(i)) == -1)) {
            isNumber = false;
        }
    }
    return isNumber;
}
function doLoginValidation() {
    if(isValidEmail(document.loginForm.ssousername.value)) {
       alert('The ID that you entered does not meet the criteria for your VCUeID. Please read the information located directly below the Login portlet to find your eID.');
       document.loginForm.ssousername.focus();
       return false;
    } else if (isNumeric(document.loginForm.ssousername.value)) {
       alert('The ID that you entered does not meet the criteria for your VCUeID. Please read the information located directly below the Login portlet to find your eID.');
       document.loginForm.ssousername.focus();
       return false;
    }
    return true;
}
function handleLoginSubmit() {
    if (!doLoginValidation()) {
        return false;
    }
    if (document.loginForm.site2pstoretoken.value == "") {
        var hw = parent.frames.s2pFrame.window;
        var hd = hw.document;
        var s2p = hd.forms.freshTokenForm.site2pstoretoken.value;
        document.loginForm.site2pstoretoken.value = s2p;
    }
    return true;
}
function submitOnEnter(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        if (handleLoginSubmit()) {
            document.loginForm.submit();
        }
        return false;
    }
    return true;
}