function checkDLnumFromState(){
	if(document.getElementById("dlswitch").value==false){
		DLState=document.getElementById("drivers_state").value.toUpperCase();
		if(DLState == 'TX'){
			if(document.getElementById("idnumber").value.length != 8){
				alert("Please enter an 8 digit drivers license number.state");
				document.getElementById("idnumber").focus();
			}
		}
	} else {
		document.getElementById("dlswitch").value=false;
	}
}
function checkDLnumFromNumber(){
	DLState=document.getElementById("drivers_state").value.toUpperCase();
	if(DLState == 'TX'){
		if(document.getElementById("idnumber").value.length != 8){
			document.getElementById("dlswitch").value=true;
			alert("Please enter an 8 digit drivers license number.number");
			document.getElementById("idnumber").focus();
		}
	}
}
function checkValues(){
	if(document.notary.last_name.value.trim()==''){
		alert('Please enter last name.');
		document.notary.last_name.focus();
		return;
	}
	if(document.notary.first_name.value.trim()==''){
		alert('Please enter first name.');
		document.notary.first_name.focus();
		return;
	}
	if(document.notary.address1.value.trim()==''){
		alert('Please enter street address.');
		document.notary.address1.focus();
		return;
	}
	if(document.notary.city.value.trim()==''){
		alert('Please enter city name.');
		document.notary.city.focus();
		return;
	}
	if(document.notary.zip.value.trim()==''){
		alert('Please enter zip code.');
		document.notary.zip.focus();
		return;
	}
	if(document.notary.this_county.value.trim()==''){
		alert('Please enter residence county.');
		document.notary.this_county.focus();
		return;
	}
	if(document.notary.idnumber.value.trim()==''){
		alert('Please enter a Drivers License or Identification No.');
		document.notary.idnumber.focus();
		return;
	}
	if(document.notary.idnumber.value.trim()=='NONE'){
		alert('Please enter a valid Drivers License or Identification No.');
		document.notary.idnumber.focus();
		return;
	}
	if(document.notary.drivers_state.value.trim()=='TX' && document.notary.idnumber.value.length!=8) {
		alert('Please enter a valid Drivers License or Identification No.');
		document.notary.idnumber.focus();
		return;
	}
	if(document.notary.drivers_state.value.trim()==''){
		alert('Please enter the Issuing State.');
		document.notary.drivers_state.focus();
		return;
	}
	admin=document.notary.admin.value;
	if((document.notary.email.value.trim()=='')&&(admin!=1)){
		alert('Please enter your Email Address.');
		document.notary.email.focus();
		return;
	}
// check the social security no
	var $ss1 = document.notary.ss1.value.trim();
	var $ss2 = document.notary.ss2.value.trim();
	var $ss3 = document.notary.ss3.value.trim();
	if( isNaN($ss1) || isNaN($ss2) || isNaN($ss3)){
		alert('Please enter a correct Social Security No.');
		document.notary.ss1.focus();
		return;
	}
	if($ss1.length != 3){
		alert('Please enter a correct Social Security No.');
		document.notary.ss1.focus();
		return;
	}
	if($ss2.length != 2){
		alert('Please enter a correct Social Security No.');
		document.notary.ss2.focus();
		return;
	}
	if($ss3.length != 4){
		alert('Please enter a correct Social Security No.');
		document.notary.ss3.focus();
		return;
	}
// check the date of birth
	var $month = document.notary.birthmonth.value.trim();
	var $day = document.notary.birthday.value.trim();
	var $year = document.notary.birthyear.value.trim();
	if( isNaN($month) || isNaN($day) || isNaN($year)){
		alert('Please enter a correct Date of Birth.');
		document.notary.birthmonth.focus();
		return;
	}
	if($month.length != 2){
		alert('Please enter a correct Date of Birth.');
		document.notary.birthmonth.focus();
		return;
	}
	if($day.length != 2){
		alert('Please enter a correct Date of Birth.');
		document.notary.birthday.focus();
		return;
	}
	if($year.length != 4){
		alert('Please enter a correct Date of Birth.');
		document.notary.birthyear.focus();
		return;
	}
// if renewal, check expiration date
	if(document.notary.renewalyes.checked==false && document.notary.renewalno.checked==false){
			alert('Please select if this is a Renewal.');
			document.notary.renewalyes.focus();
			return;
	}
	if(document.notary.renewalyes.checked==true){
		document.notary.renewal_ans.value=true;
		var $month = document.notary.expmonth.value.trim();
		var $day = document.notary.expday.value.trim();
		var $year = document.notary.expyear.value.trim();
		if( isNaN($month) || isNaN($day) || isNaN($year)){
			alert('Please enter a correct Expiration Date.');
			document.notary.expmonth.focus();
			return;
		}
		if($month.length != 2){
			alert('Please enter a correct Expiration Date.');
			document.notary.expmonth.focus();
			return;
		}
		if($day.length != 2){
			alert('Please enter a correct Expiration Date.');
			document.notary.expday.focus();
			return;
		}
		if($year.length != 4){
			alert('Please enter a correct Expiration Date.');
			document.notary.expyear.focus();
			return;
		}
	} else {
		document.notary.expmonth.value='';
		document.notary.expday.value='';
		document.notary.expyear.value='';
	}
// check answers about being guilty of a crime
	$guilty = document.notary.guilty.checked;
	$notguilty = document.notary.notguilty.checked;
	$notcrime = document.notary.notcrime.checked;
	if($guilty==false && $notguilty==false && $notcrime==false){
		alert('Please answer the Statements Relating to Qualifications.');
		document.notary.guilty.focus();
		return;
	}
// check e and o answers
	decline=document.notary.decline_eando.checked;
	if (decline==false){
		ans1=document.notary.amt1.checked;
		ans2=document.notary.amt2.checked;
		ans3=document.notary.amt3.checked;
		ans4=document.notary.amt4.checked;
		if(ans1==false && ans2==false && ans3==false && ans4==false){
			alert('Please select a Limit of Liability.');
			document.notary.amt1.focus();
			return
		}
		q1no=document.notary.q1no.checked;
		q1yes=document.notary.q1yes.checked;
		q2no=document.notary.q2no.checked;
		q2yes=document.notary.q2yes.checked;
		if(q1no==false && q1yes==false){
			alert("Please answer the questions in Applicant's Statement section.");
			document.notary.q1no.focus();
			return;
		}
		if(q2no==false && q2yes==false){
			alert("Please answer the questions in Applicant's Statement section.");
			document.notary.q2no.focus();
			return;
		}
		if(ans1==true){
			coverage = '$5,000';
			premium = 2500;
		}
		if(ans2==true){
			coverage = '$10,000';
			premium = 4000;
		}
		if(ans3==true){
			coverage = '$15,000'
			premium = 5000;
		}
		if(ans4==true){
			coverage = '$25,000'
			premium = 6000;
		}
		document.notary.coverage.value=coverage;
		document.notary.premium.value=premium;
		document.notary.eando_amount.value=premium;
	} else {
		coverage = '$0'
		premium = 00;
	}
// no errors, continue to next page
//	document.notary.action = 'ordersupplies.php';
//	document.notary.action = 'https://www.texasnotaryonline.com/ordersupplies.php';
	var foo = window.location.pathname;
	var slashPosition = foo.lastIndexOf("/");
	var folder = foo.substring(0,slashPosition);
	var oldURL = window.location.hostname + folder;
	var newURL = "https://" + oldURL + '/ordersupplies.php';
	document.notary.action = newURL;
	document.notary.submit();
}
function SetDefault(ctrl,msg){
	if(ctrl.value==''){
		ctrl.value = msg;
		$csstxt = 'color:#999999';
		ctrl.style.cssText = $csstxt;
		ctrl.setAttribute('style',$csstxt);
	}
}
function toggleRenewal(ctrl){
	if(ctrl==document.notary.renewalyes){
		if(ctrl.checked==true){
			document.notary.renewalno.checked=false;
		}
	}
	if(ctrl==document.notary.renewalno){
		if (ctrl.checked==true){
			document.notary.renewalyes.checked=false;
		}
	}
}
function toggleGuilt(ctrl){
	if(ctrl==document.notary.guilty){
		if(ctrl.checked==true){
			document.notary.notguilty.checked=false;
			document.notary.notcrime.checked=false;
		}
	}
	if(ctrl==document.notary.notguilty){
		if (ctrl.checked==true){
			document.notary.guilty.checked=false;
			document.notary.notcrime.checked=false;
		}
	}
	if(ctrl==document.notary.notcrime){
		if (ctrl.checked==true){
			document.notary.guilty.checked=false;
			document.notary.notguilty.checked=false;
		}
	}
}
function toggleLimits(clickCtrl){
	var ctrl1 = document.notary.amt1;
	var ctrl2 = document.notary.amt2;
	var ctrl3 = document.notary.amt3;
	var ctrl4 = document.notary.amt4;
	var ctrl5 = document.notary.decline_eando;
	var clickCtrlChecked = clickCtrl.checked;
	if(clickCtrlChecked){
		if(clickCtrl == ctrl1){
			ctrl2.checked=false;
			ctrl3.checked=false;
			ctrl4.checked=false;
			ctrl5.checked=false;
		}
		if(clickCtrl == ctrl2){
			ctrl1.checked=false;
			ctrl3.checked=false;
			ctrl4.checked=false;
			ctrl5.checked=false;
		}
		if(clickCtrl == ctrl3){
			ctrl2.checked=false;
			ctrl1.checked=false;
			ctrl4.checked=false;
			ctrl5.checked=false;
		}
		if(clickCtrl == ctrl4){
			ctrl2.checked=false;
			ctrl3.checked=false;
			ctrl1.checked=false;
			ctrl5.checked=false;
		}
	}
}
function eando_decline(){
	var declineChecked = document.notary.decline_eando.checked;
	if (declineChecked){
		document.notary.amt1.checked=false;
		document.notary.amt2.checked=false;
		document.notary.amt3.checked=false;
		document.notary.amt4.checked=false;
	}
}
function toggleAnswer(clickCtrl,yesCtrl,noCtrl){
	var clickCtrlChecked = clickCtrl.checked;
	var yesAnswer=yesCtrl.checked;
	var noAnswer=noCtrl.checked;
	if (yesAnswer){
		if (noCtrl == clickCtrl){	
			noCtrl.checked = true;
			yesCtrl.checked = false;
		}
	}
	if (noAnswer){
		if (yesCtrl == clickCtrl){	
			noCtrl.checked = false;
			yesCtrl.checked = true;
		}
	}
}
var zChar = new Array(' ', '(', ')', '-', '.');
var maxphonelength = 13;
var phonevalue1;
var phonevalue2;
var cursorposition;

function ParseForNumber1(object){
phonevalue1 = ParseChar(object.value, zChar);
}
function ParseForNumber2(object){
phonevalue2 = ParseChar(object.value, zChar);
}

function backspacerUP(object,e) { 
if(e){ 
e = e 
} else {
e = window.event 
} 
if(e.which){ 
var keycode = e.which 
} else {
var keycode = e.keyCode 
}

ParseForNumber1(object)

if(keycode >= 48){
ValidatePhone(object)
}
}

function backspacerDOWN(object,e) { 
if(e){ 
e = e 
} else {
e = window.event 
} 
if(e.which){ 
var keycode = e.which 
} else {
var keycode = e.keyCode 
}
ParseForNumber2(object)
} 

function GetCursorPosition(){

var t1 = phonevalue1;
var t2 = phonevalue2;
var bool = false
for (i=0; i<t1.length; i++)
{
if (t1.substring(i,1) != t2.substring(i,1)) {
if(!bool) {
cursorposition=i
bool=true
}
}
}
}

function ValidatePhone(object){

var p = phonevalue1

p = p.replace(/[^\d]*/gi,"")

if (p.length < 3) {
object.value=p
} else if(p.length==3){
pp=p;
d4=p.indexOf('(')
d5=p.indexOf(')')
if(d4==-1){
pp="("+pp;
}
if(d5==-1){
pp=pp+")";
}
object.value = pp;
} else if(p.length>3 && p.length < 7){
p ="(" + p; 
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

object.value = pp; 

} else if(p.length >= 7){
p ="(" + p; 
l30=p.length;
p30=p.substring(0,4);
p30=p30+")"

p31=p.substring(4,l30);
pp=p30+p31;

l40 = pp.length;
p40 = pp.substring(0,8);
p40 = p40 + "-"

p41 = pp.substring(8,l40);
ppp = p40 + p41;

object.value = ppp.substring(0, maxphonelength);
}

GetCursorPosition()

if(cursorposition >= 0){
if (cursorposition == 0) {
cursorposition = 2
} else if (cursorposition <= 2) {
cursorposition = cursorposition + 1
} else if (cursorposition <= 5) {
cursorposition = cursorposition + 2
} else if (cursorposition == 6) {
cursorposition = cursorposition + 2
} else if (cursorposition == 7) {
cursorposition = cursorposition + 4
e1=object.value.indexOf(')')
e2=object.value.indexOf('-')
if (e1>-1 && e2>-1){
if (e2-e1 == 4) {
cursorposition = cursorposition - 1
}
}
} else if (cursorposition < 11) {
cursorposition = cursorposition + 3
} else if (cursorposition == 11) {
cursorposition = cursorposition + 1
} else if (cursorposition >= 12) {
cursorposition = cursorposition
}

var txtRange = object.createTextRange();
txtRange.moveStart( "character", cursorposition);
txtRange.moveEnd( "character", cursorposition - object.value.length);
txtRange.select();
}

}

function ParseChar(sStr, sChar)
{
if (sChar.length == null) 
{
zChar = new Array(sChar);
}
else zChar = sChar;

for (i=0; i<zChar.length; i++)
{
sNewStr = "";

var iStart = 0;
var iEnd = sStr.indexOf(sChar[i]);

while (iEnd != -1)
{
sNewStr += sStr.substring(iStart, iEnd);
iStart = iEnd + 1;
iEnd = sStr.indexOf(sChar[i], iStart);
}
sNewStr += sStr.substring(sStr.lastIndexOf(sChar[i]) + 1, sStr.length);

sStr = sNewStr;
}

return sNewStr;
}
function movess1(){
	var $ss1 = document.notary.ss1.value.trim();
	$len = $ss1.length;
	if($len==3){
		document.notary.ss2.focus();
	}
}
function movess2(){
	var $ss1 = document.notary.ss2.value.trim();
	$len = $ss1.length;
	if($len==2){
		document.notary.ss3.focus();
	}
}
function movess3(ctrl){
	var $ss1 = document.notary.ss3.value.trim();
	$len = $ss1.length;
	if($len==4){
		document.notary.address1.focus();
	}
}
function movebmonth(){
	var $bmonth = document.notary.birthmonth.value.trim();
	$len = $bmonth.length;
	if ($len==2){
		document.notary.birthday.focus();
	}
}
function movebday(){
	var $bday = document.notary.birthday.value.trim();
	$len = $bday.length;
	if ($len==2){
		document.notary.birthyear.focus();
	}
}
function movebyear(){
	var $byear = document.notary.birthyear.value.trim();
	$len = $byear.length;
	if ($len==4){
		document.notary.idnumber.focus();
	}
}
function moveemonth(){
	var $emonth = document.notary.expmonth.value.trim();
	$len = $emonth.length;
	if ($len==2){
		document.notary.expday.focus();
	}
}
function moveeday(){
	var $eday = document.notary.expday.value.trim();
	$len = $eday.length;
	if ($len==2){
		document.notary.expyear.focus();
	}
}
function moveeyear(){
	var $eyear = document.notary.expyear.value.trim();
	$len = $eyear.length;
	if ($len==4){
		document.notary.guilty.focus();
	}
}
function setFocus(ctrl){
	if(ctrl.value=='mm' || ctrl.value=='dd' || ctrl.value=='yyyy'){
		ctrl.value='';
		$csstxt = 'color:#000000';
		ctrl.style.cssText = $csstxt;
		ctrl.setAttribute('style',$csstxt);
	}
}
