function intercept(event) {
    var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (key == 9) {
		if(navigator.appName=="Microsoft Internet Explorer") {
			event.returnValue = false;
		} else {
			event.preventDefault();
		}
		
		setTimeout("nextSection()",10);
	}
}

function changeHeight(newH) {
	if(navigator.appName=="Microsoft Internet Explorer") {
		addH = 175;		
	} else {
		addH = 140;
	}
	document.getElementById('formHolder').style.height = newH+'px';	
	//document.getElementById('maincont').style.height = (newH+addH)+'px';	
	//document.getElementById('smallcont').style.height = (newH+addH)+'px';	
	//document.getElementById('smallcont').style.overflow = 'auto';
}

function nextSection() {
	if(currentSection<=7) {
		if(validateSection(currentSection)==true) {
			currentSection++;
			loadSection(currentSection);
		}
	}
}

function prevSection() {
	if(currentSection>=1) {
		currentSection--;
		loadSection(currentSection);
	}
}

function createFocus(el) {
	if(el=="TravelAgent") {
		document.orderform.TravelAgent[1].focus();
	} else if(el=="CCType") {
		document.orderform.CCType[0].focus();
	} else {
		document.getElementById(el).focus();
	}
}

function loadSection(currentSection) {
	switch(currentSection) {
		case 1:
			new Effect.Move('section_yourDetails',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_hotelInfo',{ x: 750, y: 32, mode: 'absolute', duration: 1})
			document.getElementById('button_prev').style.display = 'none';
			setTimeout("createFocus('YourName')",1100);
			changeHeight(470);
		break;
		
		case 2:
			new Effect.Move('section_yourDetails',{ x: -750, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_hotelInfo',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_chairSelection',{ x: 750, y: 32, mode: 'absolute', duration: 1})
			document.getElementById('button_prev').style.display = 'inline';
			setTimeout("createFocus('NameOfHotel')",1100);
			changeHeight(230);
		break;
		
		case 3:
			new Effect.Move('section_hotelInfo',{ x: -750, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_chairSelection',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_riderInfo',{ x: 750, y: 32, mode: 'absolute', duration: 1})
			setTimeout("createFocus('QuantityStandardScooter')",1100);
			changeHeight(800);
		break;
		
		case 4:
			new Effect.Move('section_riderInfo',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_chairSelection',{ x: -750, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_travelAgent',{ x: 750, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_travelAgentDetails',{ x: 750, y: 82, mode: 'absolute', duration: 1})
			setTimeout("createFocus('RidersHeight')",1100);
			changeHeight(375);
		break;
		
		case 5:
			new Effect.Move('section_travelAgent',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_travelAgentDetails',{ x: 0, y: 82, mode: 'absolute', duration: 1})
			new Effect.Move('section_riderInfo',{ x: -750, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_paymentInfo',{ x: 750, y: 32, mode: 'absolute', duration: 1})
			
			if (document.orderform.TravelAgent[0].checked) {
				document.getElementById('section_travelAgentDetails').style.display = 'block';
				changeHeight(425);
			} else {
				document.getElementById('section_travelAgentDetails').style.display = 'none';
				changeHeight(100);
			}
			setTimeout("createFocus('TravelAgent')",1100);
		break;
		
		case 6:
			new Effect.Move('section_paymentInfo',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_travelAgent',{ x: -750, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_travelAgentDetails',{ x: -750, y: 82, mode: 'absolute', duration: 1})
			new Effect.Move('section_finalApproval',{ x: 750, y: 32, mode: 'absolute', duration: 1})
			document.getElementById('button_next').style.display = 'inline';
			setTimeout("createFocus('CCType')",1100);
			changeHeight(450);
		break;
		
		case 7:
			new Effect.Move('section_paymentInfo',{ x: -760, y: 32, mode: 'absolute', duration: 1})
			new Effect.Move('section_finalApproval',{ x: 0, y: 32, mode: 'absolute', duration: 1})
			document.getElementById('button_next').style.display = 'none';
			setTimeout("createFocus('agreement')",1100);
			changeHeight(350);
		break;
	}
}

function validateSection(currentSection) {
	var reason = "";
	var formVar = document.orderform;
	
	switch(currentSection) {
		case 1:
			reason += validateEmpty(formVar.YourName,"Name");
			reason += validateEmpty(formVar.HearAboutUs,"How did you hear about us?");
			reason += validateEmpty(formVar.PersonHolding,"Reservation Holder's Name");
			reason += validateEmpty(formVar.BillingAddress,"Billing Address");
			reason += validateEmpty(formVar.City,"City");
			reason += validateEmpty(formVar.State,"State");
			reason += validateEmpty(formVar.Zip,"Zip Code",5);
			reason += validateEmpty(formVar.Country,"Country");
			reason += validateEmpty(formVar.HomePhone,"Home Phone");
			reason += validateEmail(formVar.EmailAddress,"Email Address");
		break;
		
		case 2:
			reason += validateEmpty(formVar.NameOfHotel,"Name of Hotel");
		break;
		
		case 3:
		break;
		
		case 4:
			reason += validateEmpty(formVar.RidersHeight,"Rider's Height");
			reason += validateEmpty(formVar.RidersWeight,"Rider's Weight");
			reason += validateDD(formVar.DayNeeded,"Day Needed");
			reason += validateDD(formVar.MonthNeeded,"Month Needed");
			reason += validateEmpty(formVar.TimeNeeded,"Time Needed");
			reason += validateDD(formVar.AmPmNeeded,"AM or PM For Time Needed");
			reason += validateDD(formVar.DayFinished,"Day Finished");
			reason += validateDD(formVar.MonthFinished,"Month Finished");
			reason += validateEmpty(formVar.TimeFinished,"Time Finished");
			reason += validateDD(formVar.AmPmFinished,"AM or PM For Time Finished");
		break;
		
		case 5:
		break;
		
		case 6:
			reason += validateRadio(formVar.CCType,"Credit Card Type");
			reason += validateEmpty(formVar.CCNumber,"Credit Card Number");
			reason += validateEmpty(formVar.CCName,"Card Holder's Name");
			reason += validateEmpty(formVar.CCExp,"Expiration Date");
			reason += validateEmpty(formVar.CCSecurity,"Security Code");
		break;
		
		case 7:
		break;
	}
	
	if (reason != "") {
		alert("Please ensure all fields are properly filled out:\n" + reason);
		return false;
	}
	
	return true;
}

function validateEmpty(fld,fname) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#cf2929'; 
        error = "The "+fname+" field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
	
    return error;  
}

function validateNumeric(fld,fname,len) {
    var error = "";
	var fieldVal = fld.value;
	var validNums = "0123456789";
	var isNumber = true;
	
	fieldVal = fieldVal.replace(/ /g,"");
	fieldVal = fieldVal.replace(/-/g,"");

    if (fld.value.length == 0) {
        fld.style.background = '#cf2929'; 
        error = "The "+fname+" field has not been filled in.\n"
    } else if(fieldVal.length != len) {
        fld.style.background = '#cf2929'; 
        error = "The "+fname+" field must be "+len+" digits in length.\n"
	} else {        
		for (i = 0; i < fieldVal.length && isNumber == true; i++) 	{ 
			Char = fieldVal.charAt(i); 
			if (validNums.indexOf(Char) == -1) {
				isNumber = false;
			}
		}
		
		if(!isNumber) {
      	  	fld.style.background = '#cf2929'; 
      		error = "The "+fname+" field must numeric.\n"
		} else {
			fld.style.background = 'White';
		}
    }
	
    return error;  
}

function validateEmail(fld,fname) {
    var error = "";
	var posAt = fld.value.indexOf("@")
	var posDot = fld.value.lastIndexOf(".")
 
    if (fld.value.length == 0) {
        fld.style.background = '#cf2929'; 
        error = "The "+fname+" field has not been filled in.\n"
    } else if (posAt<1 || (posDot-posAt)<2) {
        fld.style.background = '#cf2929'; 
        error = "The email address entered is not valid.";
	} else {
        fld.style.background = 'White';
    }
	
    return error;  
}

function validateDD(fld,fname) {
    var error = "";
 
    if (fld.selectedIndex == 0) {
        fld.style.background = '#cf2929'; 
        error = "The "+fname+" drop-down does not have a selection made.\n"
    } else {
        fld.style.background = 'White';
    }
	
    return error;  
}

function validateRadio(fld,fname) {
    var error = "";
	var radioVal = false;

	for (i=0;i < fld.length;i++) {
		if (fld[i].checked) {
			radioVal = true;	
		}
	}

	if (!radioVal) {
        error = "The "+fname+" list does not have a selection made.\n"
	}
	
    return error;  
}

function killForm() {
	clearWaiver();
	document.orderform.reset();
	alert("Your Order Has Been Cancelled.");
}

function subForm() {
	clearWaiver();
	document.orderform.submit();
}


function centerWaiver() {
	var winWidth = 0, winHeight = 0;
	var offset = 300;
	if(typeof(window.innerWidth) == 'number') {
		winWidth = window.innerWidth;
		winHeight = window.innerHeight;
	} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		winWidth = document.documentElement.clientWidth;
		winHeight = document.documentElement.clientHeight;
	} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		winWidth = document.body.clientWidth;
		winHeight = document.body.clientHeight;
	}
			
	var xpos = ((winWidth/2)-offset)+'px';
			
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('waiver').style.left = xpos;
	} else { 
		if (document.layers) { // Netscape 4 
			document.waiver.left = xpos;
		} else { // IE 4 
			document.all.waiver.style.left = xpos;
		} 
	}
}

function loadWaiver() {
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('waiver').style.display = 'block'; 
	} else { 
		if (document.layers) { // Netscape 4 
			document.waiver.display = 'block'; 
		} else { // IE 4 
			document.all.waiver.style.display = 'block'; 
		} 
	}
}

function clearWaiver() {
	if (document.getElementById) { // DOM3 = IE5, NS6 
		document.getElementById('waiver').style.display = 'none'; 
	} else { 
		if (document.layers) { // Netscape 4 
			document.waiver.display = 'none'; 
		} else { // IE 4 
			document.all.waiver.style.display = 'none'; 
		} 
	}
}
