/*
'--------------------------------------------------------------------
' common.js: Common validation functions
'
' (c) 2003 Literate texhnology Company.  All Rights Reserved.
'
'--------------------------------------------------------------------
*/

function gotFocus (fld)
{
        fld.select();
}

function isAlphaNumeric (c)
{
      return (  (c >= 'a' && c <= 'z') ||
                (c >= 'A' && c <= 'Z') ||
                (c >= '0' && c <= '9'));
}

function validEmailCharacter (c)
{
        var validChars = "-_.@";
        if (isAlphaNumeric(c) || (validChars.indexOf (c) >= 0))
                return true;
        return false;
}

function validName (str)
{
        // Name fields should contain alpha numeric fields with the special
        // characters used in an email address
        if (str.length == 0)
                return false;
        for (i = 0; i < str.length; i++) {
                if (!validEmailCharacter (str.charAt(i)))
                        return false;
        }
        return true;
}

function verifyEmailString (str)
{
	var i, j;

	// Make sure contains an at-sign
	i = str.indexOf ("@", 0);
	if (i == -1) {	
		return "Email address must contain an @";
	}
	
	// Make sure contains only one at-sign
	j = str.indexOf ("@", i+1);
	if (j > -1) {	
		return "Email address cannot contain more than one @";
	}
	
	// Make sure contains a period after the at-sign
	j = str.indexOf(".", i);
	if (j == -1) {	
		return "Email address must contain a period after the @";
	}

	// Make sure period is not last character
	if (j + 2 > str.length){	
		return "Email address cannot end with a period";
	}
        
        // Make sure there are only valid characters
        for (i = 0; i < str.length; i++) {
                if (!validEmailCharacter(str.charAt(i))) {
                        return "Email address cannot contain the character: " + str.charAt(i);
                }
        }
        return "";        
}

function verifyEmail (fld)
{
	var i, j;
	var str = fld.value;
        var strError = verifyEmailString (str);
        
        if (strError.length > 0) {
                alert (strError);
		fld.focus();
		return false;
	}
        
	return true;	
}

function Is() {
 var agent = navigator.userAgent.toLowerCase();
 this.major = parseInt(navigator.appVersion);
 this.minor = parseFloat(navigator.appVersion);
 this.ns = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
 this.ns2 = (this.ns && (this.major == 2));
 this.ns3 = (this.ns && (this.major == 3));
 this.ns4 = (this.ns && (this.major == 4));
 this.ns5 = (this.ns && (this.major > 4));
 this.ns6 = (this.ns && (agent.indexOf('netscape6')!=-1) );
 this.ns7 = (this.ns && (agent.indexOf('netscape/7')!=-1) );
 this.ns7pr = (this.ns && (agent.indexOf('netscape/7.0b1')!=-1) );
 this.ns71 = (this.ns && (agent.indexOf('netscape/7.1')!=-1) );
 this.ie = (agent.indexOf("msie") != -1);
 this.ie3 = (this.ie && (this.major == 2));
 this.ie4 = (this.ie && (this.major >= 4));
 this.ie5 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") != -1));
 this.ie55 = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
 this.ie6 = (this.ie && (agent.indexOf("msie 6.0")!=-1));
 this.op3 = (agent.indexOf("opera") != -1);
 this.pc  = (agent.indexOf("win") != -1);
 this.mac = (agent.indexOf("mac")!=-1); // Mac detect
 this.moz = ( this.ns && (agent.indexOf("netscape/") == -1) );
 if (this.moz) this.ns = 0;

}

var is = new Is()

function getFileExt (fn)
{
        return fn.substring(fn.lastIndexOf ("."), fn.length)        
}

function strTrim(s) {
	//Match spaces at beginning and end of text and replace
	//with null strings
	return s.replace(/^\s+/,'').replace(/\s+$/,'');
}

function go (where)
{
	document.f.action = where;
	document.f.submit ();
}
