/*-------------------------------------------------------------
 * Name:    asria.js
 * Purpose: Site-wide Javascript utilities resource library
 * Author:  Brice Dunwoodie
 * Created: Feb-23-2001
 *
 * Last Modified: Feb-23-2001
 *
 * Author claims no copyrights on this material.
 *------------------------------------------------------------*/



/**************************************************************
 * Function:  goBack()
 * Purpose:   navigates back one page in history list
 * Accepts:   nothing
 * Returns:   nothing
 *
 **************************************************************/
function goBack() 
{
    if (history.length > 0) {
        history.back();
    }
}

/**************************************************************
 * Function:  selectMenu()
 * Purpose:   navigates to the "value" field in the specified
 *            HTML select menu
 * Accepts:   1) link target, 2) the select object reference,
 *            3) boolean - restore to index 0 ?
 * Returns:   nothing
 *
 **************************************************************/
function selectMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


/**************************************************************
 * Function:  validateEM()
 * Purpose:	  validates and email address format
 * Accepts:   a email address as a string
 * Returns:   0 or 1 accordingly
 *
 **************************************************************/
function validateEM(addr) {
    if (addr != null && addr != "") {
        a = addr.lastIndexOf("@");
        b = addr.lastIndexOf(".");
        c = addr.indexOf(":");
        d = addr.indexOf("/");
        e = addr.substring(0,a);
        f = e.indexOf("@");
        g = addr.substring(a+1,addr.length);
        h = g.indexOf("[");
        i = g.indexOf("]");
        j = g.indexOf("<");
        k = g.indexOf(">");
        l = addr.substring(a+1,b);
        m = addr.substring(b+1,addr.length);
        n = addr.substring(0,a);
        o = 0;
        if (a > b) {o++};
        if (c != -1) {o++};
        if (d != -1) {o++};
        if (f != -1) {o++};
        if (h != -1) {o++};
        if (i != -1) {o++};
        if (j != -1) {o++};
        if (k != -1) {o++};
        if (l.length < 3) {o++};
        if (m.length < 2) {o++};
        if (n.length < 1) {o++};
        if (o == 0) {
            return 1;
        }
        else {
            return 0;
        }
    }
    else {
        return 0;
    }
} //validateEM()


/**************************************************************
 * Function:  doDate()
 * Purpose: constructs a current date string
 * Returns: a formatted date string
 *
 **************************************************************/
function doDate()
{
	var theDate = new Date();
	var theDay = theDate.getDay();
	var theDayNum = theDate.getDate();
	var theMonth = theDate.getMonth();
	if (navigator.appName == "Netscape") {
	  var theYear = 1900 + theDate.getYear();
	} else if (navigator.appName == "Microsoft Internet Explorer") {
	  var theYear = theDate.getYear();
	} else {
	  var theYear = 1900 + theDate.getYear();
	}
	var dateString = "";
	
	// set month to a string
	if (theMonth == 0)
		theMonth = "January";
	else if (theMonth == 1)
		theMonth = "February";
	else if (theMonth == 2)
		theMonth = "March";
	else if (theMonth == 3)
		theMonth = "April";
	else if (theMonth == 4)
		theMonth = "May";
	else if (theMonth == 5)
		theMonth = "June";
	else if (theMonth == 6)
		theMonth = "July";
	else if (theMonth == 7)
		theMonth = "August";
	else if (theMonth == 8)
		theMonth = "September";
	else if (theMonth == 9)
		theMonth = "October";
	else if (theMonth == 10)
		theMonth = "November";
	else if (theMonth == 11)
		theMonth = "December";
		
	//set the day to a string
	if (theDay == 0)
		theDay = "Sunday";
	else if (theDay == 1)
		theDay = "Monday";
	else if (theDay == 2)
		theDay = "Tuesday";
	else if (theDay == 3)
		theDay = "Wednesday";
	else if (theDay == 4)
		theDay = "Thursday";
	else if (theDay == 5)
		theDay = "Friday";
	else if (theDay == 6)
		theDay = "Saturday";
		
	dateString = theDay + " " + theMonth + " " + theDayNum + ", " + theYear;
	return dateString;
}
