// JavaScript Document
//------------------------------------------------------------------------------------------------
var Tabx = { cur:0 };

function initabx( classname ) {
 var tabs = [], divs = [], texts = [], f, g, h, i = 0, j = 0, k, o,
  d = document, a = d.getElementsByTagName('h3'),
  b = d.createElement('div'), c = d.createElement('a'),
  n = function(h) { while((h = h.nextSibling)) {
   if( /div/i.test( h.tagName ) || '' ) { return h; }
   return null; }
  },
  y = function() { return false; },
  z=function(e) { e = e || window.event || {}; var t;
   if( e.keyCode===37 &&
    ( ( t = this.previousSibling ) || ( t = this.parentNode.lastChild ) )
    || e.keyCode===39 &&
    ( ( t = this.nextSibling ) || ( t = this.parentNode.firstChild ) ) ) {
     if( /a/i.test( t.tagName ) ) { t.focus(); e.returnValue = false; }
     return false;
   }
  };
 c.className = 'tab0'; c.hideFocus = true;
 while( i < a.length ) { h = a[i];
   if( new RegExp( '\\b' + classname + '\\b' ).test( h.className ) &&
    ( g = n(h) ) ) {
     k = h.firstChild && h.firstChild.nodeValue;
     o = c.cloneNode(true); o.href = '?' + ( j + 1 );
     o.appendChild( d.createTextNode( k || c || 'Tabx' ) );
     o.onfocus = new Function( 'return doTabx(' + j + ')' );
     o.onclick = y;
     o.onkeydown = z;
     g.className = 'slab0'; h.className = 'slab0';
     b.appendChild(o); tabs[j] = o; divs[j] = g; texts[j] = k;
     if(!f) { f = h; } j++;
   }
   i++;
 }
 f.parentNode.insertBefore( b, f );
 Tabx.tabs = tabs; Tabx.divs = divs; Tabx.texts = texts; i = 0;
 if( window.location.search ) {
  j = parseInt( window.location.search.substring(1) ) - 1;
  if( tabs[j] ) { i = j; }
 }
 doTabx(i);
}

function doTabx(i) {
  Tabx.tabs[Tabx.cur].className = 'tab0';
  Tabx.divs[Tabx.cur].className = 'slab0';
  Tabx.cur=i;
  Tabx.tabs[i].className = 'tab1';
  Tabx.divs[i].className = 'slab1x';
  return false;
}




// Driving Record Validation
//------------------------------------------------------------------------------------------------
var errMsg1 = "You must fill in all the required details in the Previous Residence Section";
var errMsg2 = "You must fill in all the required details in the Driving Experience Section";
var errMsg3 = "You must fill in all the required details in the Previous Driver License Section";
var errMsg4 = "You must fill in all the required details in the Accident Record Section";
var errMsg5 = "You must fill in all the required details in the Road Violation Section";
var errMsg6 = "You must fill in all the required details in the Previous Employer Section";

var aForm;
var n;

function checkForm(obj)
{
	return SSNValidate(obj.ssn)
		&& validateForm(obj)
		&& checkFormR(obj)		//residence check
		&& checkFormX(obj)		//driving experience check
		&& checkFormL(obj)		//license check
		&& checkFormA(obj)		//accident check
		&& checkFormV(obj)		//violations check
		&& checkFormE(obj);		//employment check
}

function isFormOLAFilled(obj)
{
	return SSNValidate(obj.ssn)
		&& validateFormOLA(document.forms.Form0)
		&& checkFormR(document.forms.Form0) //residence check
		&& checkFormX(document.forms.Form0) //driving experience check
		&& checkFormL(document.forms.Form0) //license check
		&& checkFormA(document.forms.Form0) //accident check
		&& checkFormV(document.forms.Form0) //violations check
		&& checkFormE(document.forms.Form0); //employment check
}

function checkFormOLA(obj)
{
	if(!isFormOLAFilled(obj))
		return false;
	alert('You will be contacted by one of our managers closest to your location.');
	return true;
}

//Form4 validation check
function checkFormFour(obj)
{
	return checkFormR(obj)	//residence check
		&& checkFormX(obj)	//driving experience check
		&& checkFormL(obj)	//license check
		&& checkFormA(obj)	//accident check
		&& checkFormV(obj)	//violations check
		&& checkFormE(obj);	//employment check
}

function checkFormZero(obj)
{
	return SSNValidate(obj.ssn)
		&& validateForm(obj);
}

//checking accidents record
function checkFormA(obj)
{ 
	aForm = obj.name;
	var thisForm = eval("document.forms."+aForm);
	//alert(aForm);
	if ((!thisForm.accNone.checked) && ( eval("thisForm.accDate0.value")==""))
	{
		thisForm.accDate0.style.background = "#FF6666";
		thisForm.accDate0.focus();
		alert (errMsg4);	
		return false;		
	}
	else
	{
		for (i = 0; i < 3 ; i++)
		{
			objElem = eval("thisForm.accDate" + i);		
			if (!objElem.value == "")
			{
				objD = eval("thisForm.accDescr" + i);
				if (objD.value == "")
				{
					alert (errMsg4);
					objD.style.background = "#FF6666";
	  				objD.focus();
					return false;
				}
				//else
				objChk = eval("thisForm.accAvoid" + i );
				val = getRadioValue(objChk);
				if (val == "")
				{
					alert (errMsg4);
					objChk[0].style.background = "#FF6666";
					objChk[1].style.background = "#FF6666";
	  				objChk[0].focus();
					return false;
				}
			}	
		} //end for
	}
	return true;
}//end method


//check Violations Record
function checkFormV(obj)
{ 
	aForm = obj.name;
	var thisForm = eval("document.forms."+aForm);
	//alert(aForm);
	if ((!thisForm.rvNone.checked) && ( eval("thisForm.rvDate0.value")==""))
	{
		alert (errMsg5);
		inDate = eval("thisForm.rvDate0.value");
		thisForm.rvDate0.style.background = "#FF6666";
		thisForm.rvDate0.focus();
		return false;	
	}
	else 
	{
		for (i = 0; i < 3 ; i++)
		{
			l = eval("thisForm.rvLoc" + i + ".value");
			inDate = eval("thisForm.rvDate" + i +".value");
				if (inDate > "") 
				{		
					objE1 = eval("thisForm.rvLoc" + i );
					objE2 = eval("thisForm.rvV" + i );
					objE3 = eval("thisForm.rvP" + i);
										
					if (objE1.value=="")
					{
						alert (errMsg5);
						objE1.style.background = "#FF6666";
						objE1.focus();
						return false;
					}
					if (objE2.value=="")
					{
						alert (errMsg5);
						objE2.style.background = "#FF6666";
						objE2.focus();
						return false;
					}
					if (objE3.value=="")
					{
						alert (errMsg5);
						objE3.style.background = "#FF6666";
						objE3.focus();
						return false;
					}
				}// end if
		}// end for
	} //end else if	
	return true;
} //end method
	

// Previous Address Validation
function checkFormR(obj)
{ 
	aForm = obj.name;
	var thisForm = eval("document.forms."+aForm);
	//alert("FormR: " + aForm);


	if ((!thisForm.prevNone.checked) && ( eval("thisForm.prevStreet1.value")==""))
	{
		alert (errMsg1);
		//inVal = eval("thisForm.prevStreet1.value");
		thisForm.prevStreet1.style.background = "#FF6666";
		thisForm.prevStreet1.focus();
		return false;	
	}
	else 
	{			
		for (i = 1; i < 5 ; i++)
		{
			inVal = eval("thisForm.prevStreet" + i +".value");
			if (inVal > "") 
			{		
				objE1 = eval("thisForm.prevCity" + i );
				objE2 = eval("thisForm.prevState" + i );
				objE3 = eval("thisForm.prevZip" + i);
				objE4 = eval("thisForm.prevPh" + i);
				objE5 = eval("thisForm.prevLngth" + i);
											
				if (objE1.value=="")
				{
					alert (errMsg1);
					objE1.style.background = "#FF6666";
					objE1.focus();
					return false;
				}
				if (objE2.value=="")
				{
					alert (errMsg1);
					objE2.style.background = "#FF6666";
					objE2.focus();
					return false;
				}
				if (objE3.value=="")
				{
					alert (errMsg1);
					objE3.style.background = "#FF6666";
					objE3.focus();
					return false;
				}
				if (objE4.value=="")
				{
					alert (errMsg1);
					objE4.style.background = "#FF6666";
					objE4.focus();
					return false;
				}
				if (objE5.value=="")
				{
					alert (errMsg1);
					objE5.style.background = "#FF6666";
					objE5.focus();
					return false;
				}
			}// end if
		}// end for
	} //end else
	return true;
} //end method


//checking driving Xperience
function checkFormX(obj)
{ 
	aForm = obj.name;
	var thisForm = eval("document.forms."+aForm);
	//alert('driving experience ' + aForm);
	
	if ( eval("thisForm.eqpType1.value")==""){
		alert (errMsg2);
		thisForm.eqpType1.style.background = "#FF6666";
		thisForm.eqpType1.focus();
		return false;	
	}
	inVal = eval("thisForm.eqpType1.value");
	if (inVal > "") {		
		objE1 = eval("thisForm.eqpDate1");
		objE2 = eval("thisForm.eqpMiles1");
										
		if (objE1.value==""){
			alert (errMsg2);
			objE1.style.background = "#FF6666";
			objE1.focus();
			return false;
		}
			
		if (objE2.value==""){
			alert (errMsg2);
			objE2.style.background = "#FF6666";
			objE2.focus();
			return false;
		}
	}			
	return true;
} //end method


//checking previous License record
function checkFormL(obj)
{ 
	aForm = obj.name;
	var thisForm = eval("document.forms."+aForm);
	//alert("licence " + aForm);
	if ((!thisForm.licNone.checked) && ( eval("thisForm.licstate1.value")=="selected"))
	{
		alert (errMsg3);
		thisForm.licstate1.style.background = "#FF6666";
		thisForm.licstate1.focus();
		return false;	
	}
	else 
	{	
		for (i = 1; i < 4 ; i++)
		{
			inVal = eval("thisForm.licstate" + i +".value");
			if (inVal != "selected") 
			{		
				objE1 = eval("thisForm.licNum" + i );
				objE2 = eval("thisForm.licClass" + i );
				objE3 = eval("thisForm.licExp" + i);
										
				if (objE1.value=="")
				{
					alert (errMsg3);
					objE1.style.background = "#FF6666";
					objE1.focus();
					return false;
				}
				if (objE2.value=="")
				{
					alert (errMsg3);
					objE2.style.background = "#FF6666";
					objE2.focus();
					return false;
				}
				if (objE3.value=="")
				{
					alert (errMsg3);
					objE3.style.background = "#FF6666";
					objE3.focus();
					return false;
				}
			}// end if
		}// end for
	} //end else
	return true;
} //end method


//checking previous Employment record
function checkFormE(obj)
{ 
	aForm = obj.name;
	var thisForm = eval("document.forms."+aForm);
	//alert(aForm);
	//No more checkbox allowed
	//if ((!thisForm.erNone.checked) && ( eval("thisForm.erName1.value")=="")){
	//alert(eval("thisForm.erName1.value"));	
	if (eval("thisForm.erName1.value")=="")
	{
		alert (errMsg6);
		thisForm.erName1.style.background = "#FF6666";
		thisForm.erName1.focus();
		return false;	
	}
	else 
	{			
		for (i = 1; i < 4 ; i++)
		{
		
			inVal = eval("thisForm.erName" + i +".value");
			var objE = new Array();
		
			if (inVal > "") 
			{		
				objE[1] = eval("thisForm.erAddr" + i );
				objE[2]= eval("thisForm.erPos" + i );
				objE[3] = eval("thisForm.erDateFrom" + i);
				objE[4] = eval("thisForm.erDateTo" + i);
				objE[5] = eval("thisForm.erPhone" + i);
				//objE6 = eval("thisForm.erContact" + i);
				for (i = 1; i < objE.length; i++)
				{
					v = eval("objE[i]");
					if ( v.value == "")
					{
						alert (errMsg6);
						v.style.background = "#FF6666";
						v.focus();
						return false;
					}
				} //inner for	
			}// end if
		}// end for
	} //end else if
	return true;
} //end method
//-----------------------------------------------------------------
function validateFormOLA(obj)
{
	
    var objF = obj;	
	
	if (obj)
	{
		formname=obj.name;
		x=eval("document.forms."+formname);
	}
	
	var x=document.forms.Form0;

	for (var e = 0; e < 12; ++e)
	{
		if(e==1){}
		else
		{
			if ( (x[e].value =="") ) 
			{
				//alert(x[e].name + " indice " + e);
				x[e].style.background = "#FF6666";
				alert ("You must complete ALL fields except indicated otherwise ");
				x[e].focus();
				return false;
			}
		}	
	} //for
	
	if (x.DOBSelectMonth.value == "00")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.DOBSelectMonth.style.background = "#FF6666";
		x.DOBSelectMonth.focus();
		return false;
	}
	if (x.DOBSelectDay.value == "0")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.DOBSelectDay.style.background = "#FF6666";
		x.DOBSelectDay.focus();
		return false;
	}
	if (x.DOBSelectYear.value == "0000")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.DOBSelectYear.style.background = "#FF6666";
		x.DOBSelectYear.focus();
		return false;
	}
	if (x.dlicense.value == "")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.dlicense.style.background = "#FF6666";
		x.dlicense.focus();
		return false;
	}
	if (x.dlclass.value == "")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.dlclass.style.background = "#FF6666";
		x.dlclass.focus();
		return false;
	}
	if (x.dlstate.value == "select")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.dlstate.style.background = "#FF6666";
		x.dlstate.focus();
		return false;
	}
	if (x.expSelectMonth.value == "00")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.expSelectMonth.style.background = "#FF6666";
		x.expSelectMonth.focus();
		return false;
	}
	if (x.expSelectDay.value == "0")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.expSelectDay.style.background = "#FF6666";
		x.expSelectDay.focus();
		return false;
	}
	if (x.expSelectYear.value == "0000")
	{
		alert ("You must complete ALL fields except indicated otherwise");
		x.expSelectYear.style.background = "#FF6666";
		x.expSelectYear.focus();
		return false;
	}
	if (x.ee_gender.value == "select")
	{
		alert ("You must complete ALL fields except indicated otherwise ");
		x.ee_gender.style.background = "#FF6666";
		x.ee_gender.focus();
		return false;
	}
	return true;
}
// END DIRVING VALIDATION SECTION
//------------------------------------------------------------------------------------------------
