//***********************************************
function emailCheck (emailStr) 
	{
		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 you have entered is not valid, please check @ and .'s")
		return false
		}
		
		var user=matchArray[1]
		var domain=matchArray[2]
		
		if (user.match(userPat)==null) {
		   alert("The email address you have entered is not valid, please check the first part of it")
		return false
		}
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
		   // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        alert("The email address you have entered is not valid, please check Destination IP")
			    return false
		    }
		   }
		   return true
		}
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
		alert("The email address you have entered is not valid, please check the domain name")
		   return false
		}
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
		   domArr[domArr.length-1].length>6) {
		   alert("The email address you have entered is not valid,\nthe last part of the address must not have more than a six-letter domain")
		   return false
		}
		if (len<2) {
		  var errStr="The email address you have entered is not valid, this address is missing a hostname!"
		  alert(errStr)
		  return false
		}
	return true;
	}
	//***********************************************
	function SendToFriend (strSubject,strLink){
		//alert(strLink);
		document.location.href='mailto:?Subject='+ escape(strSubject) + '&body=' + escape(strLink);
	}
	//***********************************************
	function makeWindow (upload,x,y) {
      window.open(upload,"upload","height="+ y +",width="+ x +",toolbar=no,scrollbars=yes,resizable=1,left=200,top=300")
	}
	//***********************************************
	function IsValidPhone(sText)
	{
	   var ValidChars = "0123456789- ";
	   var IsValidChar=true;
	   var Char;
	   for (i = 0; i < sText.length && IsValidChar == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsValidChar = false;
	         }
	      }
	   return IsValidChar;
	   }
	   
	//***********************************************
	function IsValidPassword(sText)
	{
	   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	   var IsValidChar=true;
	   var Char;
	   for (i = 0; i < sText.length && IsValidChar == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsValidChar = false;
	         }
	      }
	   return IsValidChar;
	   }
//***********************************************
	function IsValidChars(sText)
	{
	   var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. ";
	   var IsValidChar=true;
	   var Char;
	   for (i = 0; i < sText.length && IsValidChar == true; i++) 
	      { 
	      Char = sText.charAt(i); 
	      if (ValidChars.indexOf(Char) == -1) 
	         {
	         IsValidChar = false;
	         }
	      }
	   return IsValidChar;
	   }
//***********************************************
	   function CountWords (this_field, show_word_count, show_char_count) {
			if (show_word_count == null) {
			show_word_count = true;
		}
		
		if (show_char_count == null) {
			show_char_count = false;
		}
		
		var char_count = this_field.value.length;
		var fullStr = this_field.value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length -1;
		if (fullStr.length <2) {
			word_count = 0;
		}
		if (word_count == 1) {
			wordOrWords = " word";
		}
		else {
			wordOrWords = " words";
		}
		if (char_count == 1) {
			charOrChars = " character";
		} else {
			charOrChars = " characters";
		}
		if (show_word_count & show_char_count) {
			alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
		}
		else {
			if (show_word_count) {
				//alert ("Word Count:  " + word_count + wordOrWords);
		}
		else {
			if (show_char_count) {
				alert ("Character Count:  " + char_count + charOrChars);
		      }
		   }
		}
		return word_count;
		}
//***********************************************