// *************************************************************
// START SPLASH VALIDATION
// *************************************************************

var i =1;

function sendmail(){
	document.form1.action="sendmail.jsp";
	document.form1.submit();
}

function IsNumeric(numCheck)
{
   var ValidNums = "0123456789";
   var IsNumber = true;
   var Char = "";

 
   for (var q = 0; q < numCheck.length && IsNumber == true; q++) 
      { 
      Char = numCheck.charAt(q); 
      if (ValidNums.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}
function validate(ln)
{

	var lang = 'english';

	if (document.form1.lang.value != "" || document.form1.lang != null)
	{
		lang = document.form1.lang.value;
	}


if (i==3)
{

document.form1.action = "../Email/EmailErrorPage.jsp?callingPage="+document.URL+"";
document.form1.submit();
}

	//check length of certificate
	var result = true;
	//JR: Added 0238 - Feb-21-07
	var storenum = "0001|0007|0009|0012|0013|0014|0016|0018|0019|0020|0023|0025|0027|0032|0033|0034|0035|0036|0037|0040|0041|0044|0045|0046|0047|0048|0051|0053|0054|0055|0056|0057|0062|0064|0067|0068|0072|0074|0087|0096|0099|0102|0103|0107|0112|0116|0117|0128|0131|0132|0135|0143|0144|0145|0154|0155|0156|0157|0159|0160|0161|0162|0164|0168|0170|0172|0176|0191|0193|0196|0201|0205|0206|0208|0211|0212|0214|0215|0216|0217|0218|0220|0221|0222|0224|0225|0226|0227|0228|0229|0230|0231|0232|0233|0234|0235|0236|0238|0239|0100|0240|0241|0237|0247|0242";
	var storenumx = "0236";
	var certcode = document.form1.tf_code.value;
	var store = certcode.substr(0,4);
	var time = certcode.substr(4,2);
	var month = certcode.substr(6,2);
	var day = certcode.substr(8,2);
	var year = certcode.substr(10,1); 

	if (((certcode.length == 15 ) && (IsNumeric(certcode) == true)) && (storenumx.indexOf(store) != -1))

	{
		result = false;
		if (lang == "french" || lang =="fr")

		document.form1.action = "custsurvey2fr.jsp?store="+ store +"";

		else document.form1.action = "custsurvey2.jsp?store="+ store +"";

		document.form1.submit();

	}

	else if (certcode.length != 15 )
	{	
                if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid survey code,  please check the code on your receipt and try again.");
		result = false;
                i+=1;	
	}
	else if (IsNumeric(certcode) == false)
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid survey code,  please check the code on your receipt and try again.");
		result = false;
                i+=1;
	}
	else if (storenum.indexOf(store) == -1) 
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid survey code,  please check the code on your receipt and try again.");
		result = false;
                i+=1;
	}
	else if (time < 0 || time > 23) 
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid survey code,  please check the code on your receipt and try again.");
		result = false;
                i+=1;
	}
	else if (month < 1 || month > 12) 
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid survey code,  please check the code on your receipt and try again.");
		result = false;
                i+=1;
	}
	else if (day < 1 || day > 31) 
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid survey code,  please check the code on your receipt and try again.");
		result = false;
                i+=1;
	}

	
	if(result)
	{
		document.form1.action = "xmlloader.jsp?certcode="+ certcode +"";
		document.form1.submit();
	}


}

// *************************************************************
// START SECOND SPLASH VALIDATION
// *************************************************************
function getQueryVariable(variable) { 
	var query = window.location.search.substring(1); 
	var vars = query.split("&"); 
	for (var i=0;i<vars.length;i++) 
	{ 
		var pair = vars[i].split("="); 
		if (pair[0] == variable) 
		{ 
		return pair[1]; 
		} 
	} 
	alert('Query Variable ' + variable + ' not found'); 
} 


function validatex(ln)
{

	var lang = 'english';

	if (document.form2.lang.value != "" || document.form2.lang != null)
	{
		lang = document.form2.lang.value;
	}


	if (i>3)
	{
	document.form2.action = "../Email/EmailErrorPage.jsp?callingPage="+document.URL+"";
	document.form2.submit();
	}

	var result = true;

	var store = getQueryVariable("store") ;

	//alert(store);

	var check = document.form2.check.value;

	var hour = document.form2.hour.value;

	var Minute = document.form2.minute.value;

	var getDate = new Date();

	var day = getDate.getDate();

	var month = getDate.getMonth()+1;

	var year = getDate.getFullYear();

	visitMonth = (document.form2.month.selectedIndex+1) + '';

	visitDay = (document.form2.day.selectedIndex+1) + '';

	visitYear = document.form2.year.value;

	var year1= visitYear.substr(3,1);

	if (visitMonth.length == 1)
	{
		visitMonth 	= "0" + visitMonth ;
	}

	if (visitDay.length == 1)
	{
		visitDay	= "0" + visitDay;
	}

	if (hour.length == 1)
	{
		hour	= "0" + hour;
	}

	 

	if (check.length != 4)
	{	
                if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("1.	Désolé, ce numéro de transaction n’est pas valide, veuillez vérifier le numéro sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid check number, please check the number on your receipt and try again.");
		result = false;
                i+=1;	
	}
	else if (IsNumeric(check) == false)
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("1.	Désolé, ce numéro de transaction n’est pas valide, veuillez vérifier le numéro sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid check number, please check the number on your receipt and try again.");
		result = false;
                i+=1;
	}
	
	if(visitYear == year)
		{
			if (parseInt(visitMonth,10) > month)
			{
				if (i!=3)
				if (lang == "french" || lang =="fr")
					alert ("2.	Désolé, cette date n’est pas valide, veuillez vérifier la date sur votre facture et essayer encore.");
				else
					alert("Sorry, that does not appear to be a valid date, please check the date on your receipt and try again.");
				result = false;
				i+=1;
			}
			/* else if (parseInt(visitMonth,10) < month && parseInt(visitDay,10) < day)
			{
				if (i!=3)
				if (lang == "french" || lang =="fr")
					alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
				else
					alert("Sorry, that does not appear to be a valid date, please check the date on your receipt and try again.");
				result = false;
                		i+=1;
			}
			else if (parseInt(visitMonth,10) == 1 && parseInt(visitDay,10) < day && parseInt(visitYear) == 2008)
			{
				if (i!=3)
				if (lang == "french" || lang =="fr")
					alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
				else
					alert("Sorry, that does not appear to be a valid date, please check the date on your receipt and try again.");
				result = false;
                		i+=1;
			}*/
			else if (parseInt(visitMonth,10) == month && parseInt(visitDay,10) > day)
			{
				if (i!=3)
				if (lang == "french" || lang =="fr")
					alert ("Désolé, cette heure n’est pas valide, veuillez vérifier l’heure sur votre facture et essayer encore.");
				else
					alert("Sorry, that does not appear to be a valid date, please check the date on your receipt and try again.");
				result = false;
                		i+=1;
			}

		}
		else if(visitYear == year-1)
		{		
			if (parseInt(visitMonth,10) < 12)
			{
				if (i!=3)
				if (lang == "french" || lang =="fr")
					alert ("Désolé, cette heure n’est pas valide, veuillez vérifier l’heure sur votre facture et essayer encore.");
				else
					alert("Sorry, that does not appear to be a valid date, please check the date on your receipt and try again.");
				result = false;
                		i+=1;
			}

		}


	if (hour < 0 || hour > 23) 
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid time, please check the time on your receipt and try again.");
		result = false;
                i+=1;
	}
	else if (Minute < 0 || Minute > 60) 
	{
		if (i!=3)
		if (lang == "french" || lang =="fr")
			alert ("Désolé, ce code d’enregistrement n’est pas valide, veuillez vérifier le code sur votre facture et essayer encore.");
		else
			alert("Sorry, that does not appear to be a valid time, please check the time on your receipt and try again.");
		result = false;
                i+=1;
	}

	
	if(result)
	{
		document.form2.action = "xmlloader.jsp?certcode="+store+hour+visitMonth+visitDay+year1+check;
		document.form2.submit();
	}


}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
   	{
   		validate();
   		return false;
   	}
	else
   		return true;
}

function MM_callJS(jsStr) { //v2.0
  return eval(jsStr)
}




function addZeros(s_code)
{
	if(s_code.substr(0,1) == '#')
		s_code = s_code.substr(1,s_code.length - 1);
	if(s_code.length == 1)
		return s_code = "000" + s_code;
	else if(s_code.length == 2)
		return s_code = "00" + s_code;
	else if(s_code.length == 3)
		return s_code = "0" + s_code;
	else
		return s_code;
}



function removeNL(s)
{
	var r = "";

	for (i=0; i < s.length; i++)
	{
		if (s.charAt(i) != '-')
			r += s.charAt(i);
    	}
	return r;
}

// *************************************************************
// END SPLASH VALIDATION
// *************************************************************


function next()
{
        if (checkform())
        {
		document.form1.direction.value = "NEXT";
		document.form1.submit();
        }
}

function finish()
{
        if (checkform())
        {
		document.form1.direction.value = "FINISH";
		document.form1.submit();
        }
}

function getTextArray(f, grpName)
{
	var grp, rad, r = 0, sum =0;
	var lang = 'english';

	if (document.form1.lang.value != "" || document.form1.lang != null)
	{
		lang = document.form1.lang.value;
	}

	grp = (typeof grpName == 'string') ? document.form1[grpName] : grpName;
	while (rad = grp[r++])
	{ 
		if (rad.value > 0) 
    			sum = sum + parseInt(rad.value);
	}
	return sum;
}

function sumTextArray(f, grpName)
{
	var grp, rad, r = 0, sum =0;
	var lang = 'english';

	if (document.form1.lang.value != "" || document.form1.lang != null)
	{
		lang = document.form1.lang.value;
	}

	grp = (typeof grpName == 'string') ? document.form1[grpName] : grpName;

	if (grp.length > 0)
	{
		while (rad = grp[r++])
		{ 
			if (!IsNumeric(rad.value))
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre");
				else
					alert("Please enter a numeric value");

				return false;
			}

			if (rad.value > 0) 
				sum = sum + parseInt(rad.value);
		}
	}
	else
	{
		sum = grp.value;

		if (!IsNumeric(sum))
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			return false;
		}
	}

	document.form1.SumTotalTextCombo.value = sum; 
}


function checkform()
{
	var lang = 'english';

	//date validation to deny future dates MM
	if (document.form1.DATE != null)
	{
		var result = true;
		var message = "";
		var userDate = document.form1.DATE.value;
		var strYear = userDate.substring(0,4);
		var strMonth = userDate.substring(5,7);
		var strDay = userDate.substring(8,10);

	
		if (strMonth.length < 2)
		{
			strMonth = "0"+ strMonth;
		}
		if (strDay.length < 2)
		{
			strDay = "0"+ strDay;
		}
		


		var now = new Date();	

		var currentYear = now.getFullYear();
		var currentMonth = now.getMonth() + 1;
		var currentDay = now.getDate();	



		//date validation MM
		if((strDay > currentDay && strDay < 31 && strMonth == currentMonth && strMonth < 13 && strYear == currentYear) || (strMonth > currentMonth && strMonth < 13 && strYear == currentYear) || (strYear > currentYear)) 
		{
			if (strDay < 1 || strDay > 31) 
			{
				message += "Day must be between 1 and 31.\n";
			}
			else if (strMonth < 1 || strMonth > 12 ) 
				{ 
					message += "Month must be between 1 and 12.\n";
				}
			else
				{
					message += "You have entered a date from the future.\nPlease select the correct date of your visit.\n";
				}
			
				
			alert(message);	
			return false;
		

		}
		else 
		{
			return true;
		}

	}
	if (document.form1.lang.value != "" || document.form1.lang != null)
	{
		lang = document.form1.lang.value;
	}

	// Check to see how many boxes are checked for REST_CHOICE.

	var ichecked = "";

	if (document.form1.REST_CHOICE != null){

		for (var icnt = 0;icnt<(document.form1.REST_CHOICE.length-1);icnt++)
		{
			if (document.form1.REST_CHOICE[document.form1.REST_CHOICE.length-1].checked == true && document.form1.REST_CHOICE[icnt].checked == true)
			{
				ichecked = true;
			}
		}

		if(ichecked == true)
		{
			if(lang == 'french')
			{
				alert("Si vous avez choisi « Aucun » ne choisissez pas autre option.");
				return false;
			}
			else
			{
				alert("If you have selected ''None'' then please do not select any other option.");
				return false;
			}
		}
	}

	// Check to see how many boxes are checked for VISIT_WITH.

	var ichecked2 = "";

	if (document.form1.VISIT_WITH != null){

		for (var icnt2 = 0;icnt2<(document.form1.VISIT_WITH.length-3);icnt2++)
		{
			if (document.form1.VISIT_WITH[5].checked == true && (document.form1.VISIT_WITH[icnt2].checked == true || document.form1.VISIT_WITH[6].checked == true || document.form1.VISIT_WITH[document.form1.VISIT_WITH.length-1].checked == true))
			{
				ichecked2 = true;
			}
			if (document.form1.VISIT_WITH[6].checked == true && (document.form1.VISIT_WITH[icnt2].checked == true || document.form1.VISIT_WITH[5].checked == true || document.form1.VISIT_WITH[document.form1.VISIT_WITH.length-1].checked == true))
			{
				ichecked2 = true;
			}
			if (document.form1.VISIT_WITH[document.form1.VISIT_WITH.length-1].checked == true && (document.form1.VISIT_WITH[icnt2].checked == true|| document.form1.VISIT_WITH[4].checked == true ||document.form1.VISIT_WITH[5].checked == true || document.form1.VISIT_WITH[6].checked == true))
			{
				ichecked2 = true;
			}
		}


		if(ichecked2 == true)
		{
			if(lang == 'french')
			{
				alert("La sélection que vous avez choisi est invalide, veuillez choisir autre option.");
				return false;
			}
			else
			{
				alert("The selection you have made is invalid, please choose another option.");
				return false;
			}
		}
	}


	//TOMBSTONE VALIDATION

//TOMBSTONE VALIDATION

	if (document.form1.FirstName !=null)
	{
		//var valid = isAlpha(document.form1.FirstName.value);
		var valid = true;

		if(hasNumbers(document.form1.FirstName.value))
			valid = false;

		if (document.form1.FirstName.value == "" || valid == false)
		{
			//alert("saadi" + lang);
			if (lang == 'french')
				alert ("Veuillez entrer votre prénom.");
			else
				alert ("Please enter a valid First Name.");

			document.form1.FirstName.focus();
			return false;
		}
	}

	if (document.form1.LastName !=null)
	{
		//var valid = isAlpha(document.form1.LastName.value);
		var valid = true;


		if(hasNumbers(document.form1.LastName.value))
			valid = false;

		if (document.form1.LastName.value == "" || valid == false)
		{
			if (lang == 'french')
				alert ("Veuillez entrer votre nom de famille.");
			else
				alert ("Please enter a valid Last Name.");

			document.form1.LastName.focus();
			return false;
		}
	}









	
	if (document.form1.VISIT_FFREST != null)
	{
		var valid = true;
		var vFF_check = document.form1.VISIT_FFREST.value;

		if (IsNumeric_nd(vFF_check))
		{
			if (vFF_check < 0 || vFF_check > 90)
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre entre 0 et 90");
				else
					alert("Please enter in a number between 0 and 90");
				
				document.form1.VISIT_FFREST.focus();			
				return false;
			}
		}
		else
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			document.form1.VISIT_FFREST.focus();			
			return false;
		}
	}

	if (document.form1.VISIT_CDREST != null)
	{
		var valid = true;
		var vCD_check = document.form1.VISIT_CDREST.value;

		if (IsNumeric_nd(vCD_check))
		{
			if (vCD_check < 0 || vCD_check > 90)
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre entre 0 et 90");
				else
					alert("Please enter in a number between 0 and 90");
				
				document.form1.VISIT_CDREST.focus();			
				return false;
			}
		}
		else
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			document.form1.VISIT_CDREST.focus();			
			return false;
		}
	}

	if (document.form1.VISIT_FDREST != null)
	{
		var valid = true;
		var vFD_check = document.form1.VISIT_FDREST.value;

		if (IsNumeric_nd(vFD_check))
		{
			if (vFD_check < 0 || vFD_check > 90)
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre entre 0 et 90");
				else
					alert("Please enter in a number between 0 and 90");
				
				document.form1.VISIT_FDREST.focus();			
				return false;
			}
		}
		else
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			document.form1.VISIT_FDREST.focus();			
			return false;
		}
	}

	if (document.form1.VISIT_BAR != null)
	{
		var valid = true;
		var vBAR_check = document.form1.VISIT_BAR.value;

		if (IsNumeric_nd(vBAR_check))
		{
			if (vBAR_check < 0 || vBAR_check > 90)
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre entre 0 et 90");
				else
					alert("Please enter in a number between 0 and 90");
				
				document.form1.VISIT_BAR.focus();			
				return false;
			}
		}
		else
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			document.form1.VISIT_BAR.focus();			
			return false;
		}
	}

	if (document.form1.VISIT_REST != null)
	{
		var valid = true;
		var vREST_check = document.form1.VISIT_REST.value;

		if (IsNumeric_nd(vREST_check))
		{
			if (vREST_check < 1 || vREST_check > 90)
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre entre 1 et 90");
				else
					alert("Please enter in a number between 1 and 90");
				
				document.form1.VISIT_REST.focus();			
				return false;
			}
		}
		else
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			document.form1.VISIT_REST.focus();			
			return false;
		}
	}

	if (document.form1.PURCHASE_GROCERY != null)
	{
		var valid = true;
		var pg_check = document.form1.PURCHASE_GROCERY.value;

		if (IsNumeric_nd(pg_check))
		{
			if (pg_check < 0 || pg_check > 90)
			{
				if(lang == 'french')
					alert("Veuillez entrer un chiffre entre 0 et 90");
				else
					alert("Please enter in a number between 0 and 90");
				
				document.form1.PURCHASE_GROCERY.focus();			
				return false;
			}
		}
		else
		{
			if(lang == 'french')
				alert("Veuillez entrer un chiffre");
			else
				alert("Please enter a numeric value");

			document.form1.PURCHASE_GROCERY.focus();			
			return false;
		}
	}
	if (document.form1.TelephoneNumber !=null || document.form1.TelephoneAreaCode !=null)
	{
		var areacode = document.form1.TelephoneAreaCode.value;
		var areacode2 = replaceChars(areacode);
		var phoneno = document.form1.TelephoneNumber.value;
		var phoneno2 = phoneno;

		if (areacode.length != 3 || IsNumeric(areacode) == false)
		{
			if (lang == 'french' || lang=='fr')
				alert ("Veuillez entrer votre indicatif régional.");
			else if(lang == "spanish")
				alert ("Entre por favor un válido código de área.");
			else
				alert ("Please enter a valid Area Code.");

			document.form1.TelephoneAreaCode.focus();
			return false;
		}
		else if(phoneno2.length != 7 || IsNumeric(phoneno2) == false)
		{
			if (lang == 'french' || lang=='fr')
				alert ("Veuillez entrer un numéro de téléphone valide sous le format 5551234");
			else if(lang == "spanish")
				alert ("Ingrese por favor un número de teléfono válido en el formato siguiente: 5551234");
			else
				alert ("Please enter a valid telephone number in the following format: 5551234");

			document.form1.TelephoneNumber.focus();
			return false;
		}
	}

	if (document.form1.TelephoneExtension !=null)
	{
		var telext = document.form1.TelephoneExtension.value;
		var telext2 = replaceChars(telext);
		var valid = IsNumeric(telext2);

		if (valid == false)
		{
			alert ("Please enter a valid Telephone Extension.");
			document.form1.LastName.focus();
			return false;
		}
		else
		{
			document.form1.TelephoneExtension.value = telext2;
		}
	}

	return true;
}

function emailValidate(emailaddress)
{	
	var checkTLD=0; 
	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=emailaddress.match(emailPat);

	if (matchArray==null)
	{ 
		//alert("The Email Address Is Invalid"); 
		return false; 
	}

	var user=matchArray[1]; 
	var domain=matchArray[2]; 

	for (i=0; i<user.length; i++)
	{ 
		if (user.charCodeAt(i)>127)
		{ 
			//alert("The 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; 
		}
	}

	if (user.match(userPat)==null)
	{ 
		//alert("The Username Is Invalid."); 
		return false; 
	} 

	var IPArray=domain.match(ipDomainPat); 

	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{ 
			if (IPArray[i]>255)
			{ 
				//alert("The 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 Is Invalid."); 
			return false; 
		} 
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		//alert("The Domain Name Extension Is Invalid"); 
		return false; 
	} 

	if (len<2)
	{ 
		//alert("The Address Is Missing A Hostname."); 
		return false; 
	}
}


function replaceChars(entry)
{
	//out = "()+-x"; // replace this
	var add = ""; // with this
	var temp = "" + entry; // temporary holder
	var i = 0;
	var out2 = new Array(5);
	out2[0] = "(" ;
	out2[1] = ")" ;
	out2[2] = "+" ;
	out2[3] = "-" ;
	out2[4] = "x" ;

	for (i = 0; i < out2.length; i++)
	{
		var out = out2[i];
		while (temp.indexOf(out)>-1)
		{
			pos= temp.indexOf(out);
			temp = "" + (temp.substring(0, pos) + add + 
			temp.substring((pos + out.length), temp.length));
		}
	}
	//alert(temp);
	return temp;
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}
function IsNumeric_nd(sText_nd)
{
	var ValidChars_nd = "0123456789";
	var IsNumber_nd=true;
	var Char_nd;

	for (q = 0; q < sText_nd.length && IsNumber_nd == true; q++) 
	{ 
		Char_nd = sText_nd.charAt(q); 
		if (ValidChars_nd.indexOf(Char_nd) == -1) 
		{
			IsNumber_nd = false;
		}
	}
	return IsNumber_nd;
}

var letters="abcdefghijklmnopqrstuvwxyz";
var LETTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

function isAlpha(c)
{
	// is c a String or a character?
	if(c.length>1)
	{
		for(j=0;j<c.length;j++)
		{
			// call isAlpha recursively for each character
			alpha=isAlpha(c.substring(j,j+1));

			if(!alpha)
				return alpha;
		}
		return alpha;
	}
	else
	{
		// if c is alpha return true
		if(letters.indexOf(c)>=0 || LETTERS.indexOf(c)>=0)
			return true;
		return false;
	}
}

function hasNumbers(text)
{
	for(k=0;k<text.length;k++)
	{
		noNum = isNaN(text.substring(k,k+1));

		if(text.substring(k,k+1) == " ")
			noNum = true;

		if(!noNum)
		{
			return true;
			k = text.length;
		}
	}
}

function checkbay(src)
{
	//code for parsing the bay hbc card number
	var cd = "";

	if(src.length==9)
	{
		cd = src;
	}
	else
	{
		return false;
	}

	//now that we have a code, check it
	//first, eliminate codes that start with digits less than 6
	var nums = new Array(9);

	for(x=0;x<9;x++)
	{
		nums[x] = cd.charAt(x);		
	}

	if(nums[0]<6)
	{
		return false;
	}

	var checksum = 0;
	var checkcalc = 0;

	for(x = 0;x<8;x++)
	{
		checksum = (checksum ) + (nums[x] * (x+1));
	}

	var stringchecksum = checksum + "";
	var sumlastdigit = stringchecksum.substring(stringchecksum.length-1);
	var lastcheck = 10 - sumlastdigit;

	if(lastcheck==10)
		lastcheck = 0;
	if(nums[8]==lastcheck)
	{
		return true;
	}
	else
	{
		return false;
	}

}
