function emailCheck (emailStr) {

var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("The email address is incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("The email address contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
if (user.match(userPat)==null) {
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
/*alert('Your sample email will now be sent to the specified email address.');*/
return true;
}




function Left(str, n){
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0,n);
}
function Right(str, n){
	if (n <= 0)
	   return "";
	else if (n > String(str).length)
	   return str;
	else {
	   var iLen = String(str).length;
	   return String(str).substring(iLen, iLen - n);
	}
}





/*
	Revised to support looking for multiple class names,
	no matter in which order they're applied to the element
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
// ---
// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}
// ---
/*
	Examples of how to call the function:
	
	To get all a elements in the document with a "info-links" class:
    getElementsByClassName(document, "a", "info-links");
    
	To get all div elements within the element named "container", with a "col" and a "left" class:
    getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]);
*/
// ---

function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete this?")) 
	{
	document.location = delUrl
	return true;
	}
  else
  	{
    return false;
    }
}


function isNumeric(vTestValue)
{
	// put the TEST value into a string object variable
	var sField = new String((vTestValue));
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}

function isDefined(variable)
{
return (!(!( variable||false )))
}

function ListFind(list, value)
{
  var i = 0;
  var delimiter = ',';
  var returnValue = -1;
  var _tempArray = new Array();
  if(ListFind.arguments.length == 3)
    delimiter = ListFind.arguments[2];
  _tempArray = list.split(delimiter);
  for(i = 0; i < _tempArray.length; i++)
  {
    if(_tempArray[i] == value)
    {
      returnValue = i;
      break;
    }
  }
  return returnValue;
}

function ListFindNoCase(list, value)
{
  var i = 0;
  var delimiter = ',';
  var returnValue = -1;
  var _tempArray = new Array();
  if(ListFindNoCase.arguments.length == 3)
    delimiter = ListFindNoCase.arguments[2].toLowerCase();
  list = list.toLowerCase();
  value = value.toLowerCase();
  _tempArray = list.split(delimiter);
  for(i = 0; i < _tempArray.length; i++)
  {
    if(_tempArray[i] == value)
    {
      returnValue = i;
      break;
    }
  }
  return returnValue;
}

function ListLast(list)
{
  var delimiter = ',';
  var returnValue = '';
  var _tempArray = new Array();
  if(ListLast.arguments.length == 2) delimiter = ListLast.arguments[1].toLowerCase();
  _tempArray = list.split(delimiter);
  if(_tempArray.length)
    returnValue = _tempArray[_tempArray.length - 1];
  else
    returnValue = list;
  return returnValue;
}

function trim(s){
return s.replace(/^\s*(.*?)\s*$/,"$1")
}

function shDiv(prop,id)
{
	document.getElementById(id).style.display = prop;
}

function detectOS()
{
	var OSName="Unknown OS";
	if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
	if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
	if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
	if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
	
	return OSName;
}

function detectBrowser()
{
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	var bName = (browser+" "+version);
	
	return bName;
}

function imageFileUploadValidation(theFile)
{
var theFile = theFile;
var ext = Right(theFile.toLowerCase(), 4);
var errorMessage = '';

if (theFile != '')
	{
		theFile = theFile.replace( /"/g, '' );

		var theFileName = ListLast(theFile,'\\');
		theFileName = ListLast(theFileName,'/');
		
		//alert(theFileName);
		if (theFileName.length >= 50)
			{errorMessage = errorMessage + "Please upload a file with a name smaller than 50 characters\n";}
		if (ext != '.gif' && ext != '.jpg' && ext != 'jpeg')
			{errorMessage = errorMessage + "Please upload a GIF or a JPG image file\n";}
		
		return errorMessage;
	}
}

function csvFileUploadValidation(theFile)
{
var theFile = theFile;
var ext = Right(theFile.toLowerCase(), 4);
var errorMessage = '';

if (theFile != '')
	{
		theFile = theFile.replace( /"/g, '' );

		var theFileName = ListLast(theFile,'\\');
		theFileName = ListLast(theFileName,'/');
		
		//alert(theFileName);
		if (theFileName.length >= 50)
			{errorMessage = errorMessage + "Please upload a CSV with a name smaller than 50 characters\n";}
		if (ext != '.csv')
			{errorMessage = errorMessage + "Invalid file!\nPlease upload a CSV (Comma seperated value) file, with 5 fields 'First Name','Last Name','E-mail Address','Company','Company Main Phone'\n";}
		
		return errorMessage;
	}
}



/*
function imageFileUploadValidation(theFile)
{
var theFile = theFile;
var ext = Right(theFile, 4);
var errorMessage = '';

if (theFile != '')
	{
		switch(detectBrowser())
		{
			case 'Netscape 5':
			 	var theFileName = theFile;
			break; 
			   
			default:
				if (detectOS() == "Windows")
				{	var FilePathDelimiter = theFile.lastIndexOf('\\');}
				else
				{	var FilePathDelimiter = theFile.lastIndexOf('/');}

			    if (FilePathDelimiter != -1)
			    {	var firstpos = (FilePathDelimiter + 1)
					var lastpos = theFile.length
					var theFileName=theFile.substring(firstpos,lastpos)}
		}

		if (theFileName.length >= 50)
			{errorMessage = errorMessage + "Please upload a file with a name smaller than 50 characters\n";}
		if (ext != '.gif' && ext != '.GIF' && ext != '.JPG' && ext != '.jpg' && ext != 'jpeg' && ext != 'JPEG')
			{errorMessage = errorMessage + "Please upload a GIF or a JPG image file\n";}
		
		return errorMessage;
			
	}
}*/
