String.prototype.trim = function()

{return this.replace(/(^\s*)|(\s*$)/g, "");}

//***JS File To Validate Character and Number  created by Basil 2004-10-11***
function validateCharNum(Val)
{
	var tmp ;
	re = /^[A-Za-z0-9]+$/;
	tmp= re.test(Val) ;
	return tmp;

}  

//*** Added by B.S. on 9/10/2003 - customized Number Checker...
function checkValidNumber(val,arrMiscValid)
{
var arrValid = new Array(0,1,2,3,4,5,6,7,8,9)
var charsOK = arrValid.join('') + (arrMiscValid ? arrMiscValid.join('') : '')
for(i=0;i<val.length;i++)
	{
	if(charsOK.indexOf(val.charAt(i)) == -1)
		{
		return val.charAt(i)	//*** Return the offending character
		}
	}

return ""	//*** If All is good return a blank string
}


function checkZip(val)
{
//parent.frames["frameSocContent"].document.getElementById("frameZipCheck").src = 'includes/zipCheck.aspx?zip=' + val + '&noCache=' + escape(Date()); 
getObjectById('frameZipCheck').src = 'includes/zipCheck.aspx?zip=' + val + '&noCache=' + escape(Date());
}

//###
function isWhitespace (s)
{
	var i;
    // Is s empty?
    if (isEmpty(s)) return true;
    // Search through string's characters one by one until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}


function dropDownMenu(elementName)  {
	var myindex=elementName.options[elementName.selectedIndex].value;
	if (myindex=="") {
	return true;
	}
	else {
	return false;
	   }
}
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function invalidAreaCode (sAreaCode)
{
	if ( // Check if all the numbers in area code are the same. ie. check if 777
		(sAreaCode.charAt(0) == sAreaCode.charAt(1)) &&	(sAreaCode.charAt(1) == sAreaCode.charAt(2))
		)
	{
		return true;
	}
	else if ( //phone can't prefix with "0" or "1"
		(sAreaCode.charAt(0) == "0") || (sAreaCode.charAt(0) == "1")
		)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function invalidAddress(sAddress)
{
// Address can't have "#, P, p, R, r" these as the first character Added by D.K. 2003-04-07
	if ((sAddress.charAt(0) == "#") || (sAddress.charAt(0).toUpperCase() == "P") || (sAddress.charAt(0).toUpperCase() == "R"))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function isInteger (s){   
	var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);
    // Search through string's characters one by one until we find a non-numeric character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

function emailCheck (emailStr) {


/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
//var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/i;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|aero|coop|info|jobs|mobi|museum|name|travel|ca|pr|vi|gu|as|us|tv|mp|us)$/i;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

//Add verify for email like lisa@chuckgg.homeip.net     Bruce
/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */
//var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;


/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
//var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var domainPat=new RegExp("^" + word + "(\\." + word +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
/* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */
//alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username 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;
   }
}
// See if "user" is valid 
if (user.match(userPat)==null) {
// user is not valid
//alert("The username doesn't seem to be valid.");
return false;
}
/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */
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("Destination IP address is invalid!");
return false;
   }
}
return true;
}
// Domain is symbolic name.  Check if it's valid.
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.");
//alert("domArr[i]");
return false;
   }
}
/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

/*
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
*/
if (checkTLD && domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
// Make sure there's a host name preceding the domain.
if (len<2) {
//if (len<=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("This address is missing a hostname!");
return false;
}

	///Bruce
//alert(EmailDomain(emailStr));
var k=len;
for (i=0;i<len;i++) {

if(EmailDomain(emailStr))
{
  return true;
}
else
{
  if(k>2)
	{
      // alert("Domain >1");
       var domainnew=domArr[i+1];
       for (t=i+2;t<len ;t++ )
       {
           domainnew+="."+domArr[t];
		   
       }
      // alert("New domain"+domainnew);
	   
	   emailStr =user+"@"+domainnew;
	  // alert("k New emailStr "+ emailStr);
     }
	  k=k-1;
  }
}
if(!EmailDomain(emailStr))
{
//alert("Old emailStr " + emailStr);
//alert("EmailDomain failed");
 return false;
}

 ///


// If we've gotten this far, everything's valid!
return true;
}

////Bruce
function EmailDomain(emailvalue)
{
	this.CreateHTTPObject = function()
	{        
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				xmlhttp = false;
			}
		}
	    
		if (!xmlhttp && typeof XMLHttpRequest!='undefined')
		{
			try
			{
				xmlhttp = new XMLHttpRequest();
			}
			catch (e)
			{
				xmlhttp=false;
			}
		}
	    
		if (!xmlhttp && window.createRequest)
		{
			try
			{
				xmlhttp = window.createRequest();
			}
			catch (e)
			{
				xmlhttp=false;
			}
		}        
		return xmlhttp;
	}
	//this.CurrentTimes=0;
	//this.URL = "http://localhost/Bullseye.PublicSite.ValidateTelNOViaWTN.Pages/ValidatePage.aspx";
	this.URL="MXLookUp.aspx";
	
//	this.Check=function(emailvalue)
//	{
//		var result = '0';
		
		
	//	this.CurrentTimes++;
	    //alert( this.CurrentTimes );
	    var xmlhttp = this.CreateHTTPObject();
	    if (xmlhttp)
	    {
	       var s= this.URL + "?email=" + emailvalue;
	       xmlhttp.open("GET", s, false);
           xmlhttp.send(null);
		   //if(xmlHttp.readyState == 4)
		   {
			    var responseValue=xmlhttp.responseText;

				
			    
			    if(responseValue=="True"||responseValue=="true")
			   {
				
				return true;				
			   }

				else
					return false;
				
							
		   }
	    }
	    	
//	}
}
////For 10996 check

function PostStringFor10996(urlvalue)
{
	this.CreateHTTPObject = function()
	{        
		try
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				xmlhttp = false;
			}
		}
	    
		if (!xmlhttp && typeof XMLHttpRequest!='undefined')
		{
			try
			{
				xmlhttp = new XMLHttpRequest();
			}
			catch (e)
			{
				xmlhttp=false;
			}
		}
	    
		if (!xmlhttp && window.createRequest)
		{
			try
			{
				xmlhttp = window.createRequest();
			}
			catch (e)
			{
				xmlhttp=false;
			}
		}        
		return xmlhttp;
	}
	//this.CurrentTimes=0;
	//this.URL = "http://localhost/Bullseye.PublicSite.ValidateTelNOViaWTN.Pages/ValidatePage.aspx";
//	this.URL="http://scww07.silvercarrot.com/Rjr10996Check/Rjr10996Check.aspx?";
    this.URL="Rjr10996Check.aspx?";
	
//	this.Check=function(urlvalue)
//	{
//		var result = '0';
		
		
	//	this.CurrentTimes++;
	    //alert( this.CurrentTimes );
	    var xmlhttp = this.CreateHTTPObject();
	    if (xmlhttp)
	    {
	       var s= this.URL + urlvalue;
	       xmlhttp.open("GET", s, false);
           xmlhttp.send(null);
		   //if(xmlHttp.readyState == 4)
		   {
			    var responseValue=xmlhttp.responseText;

               
				
			    
			    if(responseValue.substr(0,3)=="yes")
			   {
                              
				return responseValue.substr(0,3);				
			   }

				else
				{	return responseValue;
                                             
                                }
				// 
				    
				
							
		   }
	    }
	    	
//	}
}
////Bruce
function JSTrim(str) 
{ 
        var i = 0;
        var j = str.length - 1;        
        while(str.charAt(i) == ' ') i++; 
        while(str.charAt(j) == ' ') j--; 
        j++; 
        if(j==0 && i==str.length) 
		{ 
            str = ''; 
            return str; 
		} 
        else 
        { 
			return str.substring(i,j); 
        } 
} 

function prePopTestFormData(oForm)
{
	//### Prepopulate the form for SilverCarrot's test user (Kardz). Added by D.K. on 2003-04-08
	var oForm = document.vForm;
	var stateVal;

	if (QueryString("testMe") == 1)
	{	
		oForm.namefirst.value = 'Kardz'	
		oForm.namelast.value = 'User'	
		oForm.email.value = 'kardz@silvercarrot.com'	
		oForm.address1.value = '132 west 36th street'	
		//oForm.city.value = 'New York'	
		//oForm.state.options[36].selected = true //select NY	
		//oForm.state.value='New York' //select NY	
		oForm.zip.value = '10018'	
		checkZip('10018');
		oForm.country.value = 'USA'
		oForm.phone1.value = '212'
		oForm.phone2.value = '999'
		oForm.phone3.value = '5555'
		oForm.gender[0].checked = true
		oForm.birth_day.options[4].selected = true
		oForm.birth_month.options[11].selected = true
		oForm.age.options[30].selected = true
	}
		if(QueryString('namefirst')) oForm.namefirst.value = unescape(QueryString('namefirst'))
		if(QueryString('namelast')) oForm.namelast.value = unescape(QueryString("namelast"))	
		if(QueryString('email')) oForm.email.value = unescape(QueryString("email"))	
		if(QueryString('address1')) oForm.address1.value = unescape(QueryString("address1"))
		if(QueryString('address2'))
		{
			oForm.address2.value = unescape(QueryString("address2"));
		}
		else
		{
			oForm.address2.value = "";
		}

		if(QueryString('zip')) 
			{		
			oForm.zip.value = unescape(QueryString("zip"))	
			checkZip(oForm.zip.value);  //***Check zip and grab city/state values based on zip
			}

		if(QueryString('phone_tot')) 
			{
			oForm.phone1.value = unescape(QueryString("phone_tot")).substr(0,3)
			oForm.phone2.value = unescape(QueryString("phone_tot")).substr(3,3)
			oForm.phone3.value = unescape(QueryString("phone_tot")).substr(6,4)
			}
		
		if(QueryString('gender')) 
		{	
			if (unescape(QueryString("gender")).toUpperCase() == "M")
			{
				oForm.gender[0].checked = true;
			}
			else{
				oForm.gender[1].checked = true;
			}
		}
		
		if(QueryString('birth_day')) oForm.birth_day.options[QueryString("birth_day")].selected = true
		if(QueryString('birth_month')) oForm.birth_month.options[QueryString("birth_month")].selected = true
		if(QueryString('birth_year')) 
			{	
			if (oForm.age.options[QueryString("birth_year") - 1899])
				{
				oForm.age.options[QueryString("birth_year") - 1899].selected = true
				}
			}
}	
function stateFullToAbbrev(stateFull)
{
	var AbbState;
	switch(stateFull) {
		case "Alabama" :
			AbbState = "AL";
			break;
		case "Alaska" : 
			AbbState = "AK";
			break;
		case "Arkansas" :
			AbbState = "AR";
			break;
		case "Arizona" :
			AbbState = "AZ"; 
			break;
		case "California" :
			AbbState = "CA"; 
			break;
		case "Colorado":
			AbbState = "CO";
			break;
		case "Connecticut":
			AbbState = "CT"; 
			break;
		case "Canal Zone":
			AbbState = "CZ";   
			break;
		case "District Of Columbia":
			AbbState = "DC";  
			break;	
		case "Delaware":
			AbbState = "DE";  
			break;	
		case "Florida":
			AbbState = "FL";  
			break;	
		case "Georgia":
			AbbState = "GA";  
			break;
		case "Guam":
			AbbState = "GU";   
			break;
		case "Hawaii":
			AbbState = "HI";  
			break;
		case "Iowa":
			AbbState = "IA";   
			break;
		case "Idaho":
			AbbState = "ID";   
			break;
		case "Illinois":
			AbbState = "IL";   
			break;
		case "Indiana":
			AbbState = "IN";   
			break;
		case "Kansas":
			AbbState = "KS";   
			break;
		case "Kentucky":
			AbbState = "KY";   
			break;
		case "Louisiana":
			AbbState = "LA";   
			break;
		case "Massachusetts":
			AbbState = "MA"; 
			break;	
		case "Maryland":
			AbbState = "MD";   
			break;
		case "Maine":
			AbbState = "ME";  
			break;
		case "Michigan":
			AbbState = "MI"; 
			break;
		case "Minnesota":
			AbbState = "MN"; 
			break;	
		case "Missouri":
			AbbState = "MO";  
			break;
		case "Mississippi":
			AbbState = "MS";  
			break;
		case "Montana":
			AbbState = "MT";  
			break;
		case "North Carolina":
			AbbState = "NC"; 
			break;	
		case "North Dakota":
			AbbState = "ND";  
			break;	
		case "Nebraska":
			AbbState = "NE"; 
			break;
		case "New Hampshire":
			AbbState = "NH";
			break;	
		case "New Jersey":
			AbbState = "NJ"; 
			break;	
		case "New Mexico":
			AbbState = "NM";  
			break;
		case "Nevada":
			AbbState = "NV";  
			break;
		case "New York":
			AbbState = "NY";  
			break;
		case "Ohio":
			AbbState = "OH"; 
			break;
		case "Oklahoma":
			AbbState = "OK";  
			break;
		case "Oregon":
			AbbState = "OR";  
			break;
		case "Pennsylvania":
			AbbState = "PA";
			break;	
		case "Puerto Rico":
			AbbState = "PR";  
			break;	
		case "Rhode Island":
			AbbState = "RI"; 
			break;	
		case "South Carolina":
			AbbState = "SC";  
			break;
		case "South Dakota":
			AbbState = "SD"; 
			break;
		case "Tennessee":
			AbbState = "TN";  
			break;
		case "Texas":
			AbbState = "TX";  
			break;
		case "Utah":
			AbbState = "UT";  
			break;
		case "Virginia":
			AbbState = "VA"; 
			break;
		case "Virgin Island":
			AbbState = "VI"; 
			break;	
		case "Vermont":
			AbbState = "VT";  
			break;
		case "Washington":
			AbbState = "WA";  
			break;
		case "Wisconsin":
			AbbState = "WI"; 
			break;
		case "West Virginia":
			AbbState = "WV";  
			break;
		case "Wyoming":
			AbbState = "WY";  
			break;
		}
		return AbbState;

}
function stateAbbrevToFull(stateAbb) {
	var fullState;
	switch(stateAbb) {
		case "AL" :
			fullState = "Alabama";
			break;
		case "AK" : 
			fullState = "Alaska";
			break;
		case "AR" :
			fullState = "Arkansas";
			break;
		case "AZ" :
			fullState = "Arizona"; 
			break;
		case "CA" :
			fullState = "California"; 
			break;
		case "CO":
			fullState = "Colorado";
			break;
		case "CT":
			fullState = "Connecticut"; 
			break;
		case "CZ":
			fullState = "Canal Zone";   
			break;
		case "DC":
			fullState = "District Of Columbia";  
			break;	
		case "DE":
			fullState = "Delaware";  
			break;	
		case "FL":
			fullState = "Florida";  
			break;	
		case "GA":
			fullState = "Georgia";  
			break;
		case "GU":
			fullState = "Guam";   
			break;
		case "HI":
			fullState = "Hawaii";  
			break;
		case "IA":
			fullState = "Iowa";   
			break;
		case "ID":
			fullState = "Idaho";   
			break;
		case "IL":
			fullState = "Illinois";   
			break;
		case "IN":
			fullState = "Indiana";   
			break;
		case "KS":
			fullState = "Kansas";   
			break;
		case "KY":
			fullState = "Kentucky";   
			break;
		case "LA":
			fullState = "Louisiana";   
			break;
		case "MA":
			fullState = "Massachusetts"; 
			break;	
		case "MD":
			fullState = "Maryland";   
			break;
		case "ME":
			fullState = "Maine";  
			break;
		case "MI":
			fullState = "Michigan"; 
			break;
		case "MN":
			fullState = "Minnesota"; 
			break;	
		case "MO":
			fullState = "Missouri";  
			break;
		case "MS":
			fullState = "Mississippi";  
			break;
		case "MT":
			fullState = "Montana";  
			break;
		case "NC":
			fullState = "North Carolina"; 
			break;	
		case "ND":
			fullState = "North Dakota";  
			break;	
		case "NE":
			fullState = "Nebraska"; 
			break;
		case "NH":
			fullState = "New Hampshire";
			break;	
		case "NJ":
			fullState = "New Jersey"; 
			break;	
		case "NM":
			fullState = "New Mexico";  
			break;
		case "NV":
			fullState = "Nevada";  
			break;
		case "NY":
			fullState = "New York";  
			break;
		case "OH":
			fullState = "Ohio"; 
			break;
		case "OK":
			fullState = "Oklahoma";  
			break;
		case "OR":
			fullState = "Oregon";  
			break;
		case "PA":
			fullState = "Pennsylvania";
			break;	
		case "PR":
			fullState = "Puerto Rico";  
			break;	
		case "RI":
			fullState = "Rhode Island"; 
			break;	
		case "SC":
			fullState = "South Carolina";  
			break;
		case "SD":
			fullState = "South Dakota"; 
			break;
		case "TN":
			fullState = "Tennessee";  
			break;
		case "TX":
			fullState = "Texas";  
			break;
		case "UT":
			fullState = "Utah";  
			break;
		case "VA":
			fullState = "Virginia"; 
			break;
		case "VI":
			fullState = "Virgin Island"; 
			break;	
		case "VT":
			fullState = "Vermont";  
			break;
		case "WA":
			fullState = "Washington";  
			break;
		case "WI":
			fullState = "Wisconsin"; 
			break;
		case "WV":
			fullState = "West Virginia";  
			break;
		case "WY":
			fullState = "Wyoming";  
			break;
		}
		return fullState;
}


