// JavaScript Document

var theTip = new Array();
theTip[0] = 'images/tips/1.png'
theTip[1] = 'images/tips/2.png'
theTip[2] = 'images/tips/3.png'
theTip[3] = 'images/tips/4.png'
theTip[4] = 'images/tips/5.png'

var theTestimonial = new Array();
theTestimonial[0] = 'images/testimonials/1.png'
theTestimonial[1] = 'images/testimonials/2.png'
theTestimonial[2] = 'images/testimonials/3.png'

var j = 0
var p = theTip.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theTip[i]
}

var l = 0;
var m = theTestimonial.length;
var preBuffer2 = new Array()
for(n = 0; n < m; n++){
	preBuffer2[n] = new Image()
	preBuffer2[n].src = theTestimonial[n]
}

var whichImage = Math.round(Math.random()*(p-1));
var whichImage2 = Math.round(Math.random()*(m-1));
var whichImage3 = whichImage + 1;

if(whichImage === 4) {
	whichImage3 = 0;
}

function pickImages(){
	document.getElementById('testimonials').src = ''+theTestimonial[whichImage2]+'';
	document.getElementById('tips1').src = ''+theTip[whichImage]+'';
	document.getElementById('tips2').src = ''+theTip[whichImage3]+'';
}

function checkType() {
	var selectedInsurance = document.getElementById("insuranceSelector");
	var selectedValue = selectedInsurance.options[selectedInsurance.selectedIndex].text;
	if(selectedValue === 'Auto Insurance') {
		document.getElementById('auto-form').style.display = "block";
		document.getElementById('busines-form').style.display = "none";
		document.getElementById('auto-1').style.display = "block";
		document.getElementById('auto-2').style.display = "none";
		document.getElementById('auto-3').style.display = "none";
		document.getElementById('auto-4').style.display = "none";
	} else if(selectedValue === 'Business Insurance') {
		document.getElementById('auto-form').style.display = "none";
		document.getElementById('busines-form').style.display = "block";
		document.getElementById('bus-1').style.display = "block";
		document.getElementById('bus-2').style.display = "none";
		document.getElementById('bus-3').style.display = "none";
		document.getElementById('bus-4').style.display = "none";
		document.getElementById('bus-5').style.display = "none";
	} else {
		document.getElementById('auto-form').style.display = "none";
		document.getElementById('busines-form').style.display = "none";
	}
}

var pageToChange;
var valToPass;

function nextPage(obj) {
	valToPass = ''+ obj.name + '';
	if(valToPass === 'auto-1-name') {
		pageToChange = 'auto-1';
	} else if(valToPass === 'auto-2-name') {
		pageToChange = 'auto-2';
	} else if(valToPass === 'auto-3-name') {
		pageToChange = 'auto-3';
	} else if(valToPass === 'auto-4-name') {
		pageToChange = 'auto-4';
	} else if(valToPass === 'bus-1-name') {
		pageToChange = 'bus-1';
	} else if(valToPass === 'bus-2-name') {
		pageToChange = 'bus-2';
	} else if(valToPass === 'bus-3-name') {
		pageToChange = 'bus-3';
	} else if(valToPass === 'bus-4-name') {
		pageToChange = 'bus-4';
	} else if(valToPass === 'bus-5-name') {
		pageToChange = 'bus-5';
	}

	checkValidation(valToPass);
}

function prevPage(obj) {
	valToPass = ''+ obj.name + '';
	if(valToPass === 'auto-1-name') {
		pageToChange = 'auto-1';
	} else if(valToPass === 'auto-2-name') {
		pageToChange = 'auto-2';
	} else if(valToPass === 'auto-3-name') {
		pageToChange = 'auto-3';
	} else if(valToPass === 'auto-4-name') {
		pageToChange = 'auto-4';
	} else if(valToPass === 'bus-1-name') {
		pageToChange = 'bus-1';
	} else if(valToPass === 'bus-2-name') {
		pageToChange = 'bus-2';
	} else if(valToPass === 'bus-3-name') {
		pageToChange = 'bus-3';
	} else if(valToPass === 'bus-4-name') {
		pageToChange = 'bus-4';
	} else if(valToPass === 'bus-5-name') {
		pageToChange = 'bus-5';
	}

	hidePages();
}

function processPage() {
	hidePages();
}

function hidePages() {
	document.getElementById('auto-1').style.display = "none";
	document.getElementById('auto-2').style.display = "none";
	document.getElementById('auto-3').style.display = "none";
	document.getElementById('auto-4').style.display = "none";
	
	document.getElementById('bus-1').style.display = "none";
	document.getElementById('bus-2').style.display = "none";
	document.getElementById('bus-3').style.display = "none";
	document.getElementById('bus-4').style.display = "none";
	document.getElementById('bus-5').style.display = "none";
	
	document.getElementById(pageToChange).style.display = "block";
}

function checkValidation(val) {
	if(val === 'auto-2-name') {
		validateForm_AutoOne();
	} else if(val === 'auto-3-name') {
		validateForm_AutoTwo();
	} else if(val === 'auto-4-name') {
		validateForm_AutoThree();
	} else if(val === 'bus-2-name') {
		validateForm_BusOne();
	} else if(val === 'bus-3-name') {
		processPage();
	} else if(val === 'bus-4-name') {
		processPage();
	} else if(val === 'bus-5-name') {
		processPage();
	}
}
