<!--

function display_payment_panel() {

	document.getElementById('payment_panel').style.display='block';	

}

// submit the form to process payment
function buy_form(){
	
	var validation_result = validate_questions();
	if (validation_result==true) {
		document.quotation_form_details.action = "app/blocks/processpayment.php";
		document.quotation_form_details.submit();	
	} else {
		alert("You must answer the questions for a valid quotation");	
	}		
	
}
// update the form, answer questions
function update_form(action) {
	
	var validation_result = false;
        if(action != "quote-pay")
        {
          validation_result= validate_questions();
        } else validation_result = true;

        if (validation_result==true) {
		document.quotation_form_details.action = "app/lib/actionprocessor.php?action="+action;
		document.quotation_form_details.submit();
	} else {
		alert("You must answer the questions for a valid quotation");	
	}
	
}

function save_form() {
	if (validate_questions() && valueCheck()) {
		document.quotation_form_details.action = "app/lib/actionprocessor.php?action=finished";
		document.quotation_form_details.submit();
	}
}

// Popular the Vessel Types dropdown based on the Vessel chosen
function update_vessel_types(vessel_id) {

	// clear the drop down
	document.getElementById('cmb_vessel_type').options.length = 0;
	addOption(document.quotation_form.cmb_vessel_type, '-Select Vessel Type-','');
	var vesselTypeDiv = document.getElementById('vesselTypeDiv');
        var vesselOtherDiv = document.getElementById('vesselOtherDiv');
                vesselTypeDiv.style.display = "block";
                vesselOtherDiv.style.display = "none";
	// hide the Options
	document.getElementById('vessel_options').style.display='none';		
	
	// Call a PHP Script to return the vessel types
	var test ="app/lib/vessel_types.php?vessel_id="+ vessel_id;
		var req = getXMLHTTP();
		//alert(strURL);
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
				
					// only if "OK"
					if (req.status == 200) {	
					
						// read the string back from the call to the PHP page in the format : vessel_type_id, vessel label
						vessel_types=req.responseText;
											
						if(vessel_types) {
							// split the string into an array of seperate vessel types
							var vessel_types_array = vessel_types.split("~");	
												
							//loop through array, 
							for (i=0;i<vessel_types_array.length;i++) {
								var vessel_type_details = vessel_types_array[i].split(",");
								var vessel_type_id = vessel_type_details[0];
								var vessel_type_label = vessel_type_details[1];
								
								// add this exercise item to the vessel type Dropdown
								addOption(document.quotation_form.cmb_vessel_type, vessel_type_label, vessel_type_id);
							}
							
							// If there is only one option, pre select the Vessel Type
							if(vessel_types_array.length==1) {
								// clear the drop down
								document.getElementById('cmb_vessel_type').options.length = 0;
								
								var vessel_type_details = vessel_types_array[0].split(",");
								var vessel_type_id = vessel_type_details[0];
								var vessel_type_label = vessel_type_details[1];
								
								// add the 1 element to the drop down
								addOption(document.quotation_form.cmb_vessel_type, vessel_type_label, vessel_type_id);
								
								// update the options for this vessel
								update_vessel_options(vessel_type_id);
							}
						
						}
						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", test, true);
			req.send(null);
		}
}

function update_vessel_options(vessel_type_id) {
	
	// clear the drop down
	document.getElementById('cmb_vessel_option').options.length = 0;
	// hide the Options
	document.getElementById('vessel_options').style.display='none';		
	
	// Call a PHP Script to return the vessel types
	var test ="app/lib/vessel_insurance_options.php?vessel_type_id="+ vessel_type_id;
		var req = getXMLHTTP();
		//alert(strURL);
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
				
					// only if "OK"
					if (req.status == 200) {	
					
						// read the string back from the call to the PHP page in the format : vessel_type_id, vessel label
						vessel_insurance_options=req.responseText;
							
						if(vessel_insurance_options) {
							// split the string into an array of seperate vessel types
							var vessel_insurance_options_array = vessel_insurance_options.split("~");	
												
							//loop through array, 
							for (i=0;i<vessel_insurance_options_array.length;i++) {
								var vessel_options_details = vessel_insurance_options_array[i].split(",");
								var vessel_option_id = vessel_options_details[0];
								var vessel_option_label = vessel_options_details[1];
												
								// add this option to the vessel option Dropdown
								addOption(document.quotation_form.cmb_vessel_option, vessel_option_label, vessel_option_id);

							}
							
							// if there are more options, show the drop down
							if(vessel_insurance_options_array.length>1) {
								// unhide the options
								document.getElementById('vessel_options').style.display='inline';				
							}
						
						}

						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", test, true);
			req.send(null);
		}
}




function validateQuote() {
    if (document.getElementById('cmb_vessel').value=="-1") {
        alert("Please choose a Vessel");
        return false;
    }

    if (document.getElementById('cmb_vessel_type').value=="-1" && document.getElementById('cmb_vessel').value!="99" ) {
        alert("Please choose a Vessel Type");
        return false;
    }

    if (document.getElementById('dob').value !="") {
        var yearsofage = 16;
        var today = new Date();

        var dt1 = today.getDate();
        if (dt1<10) {dt1='0'+dt1}
        var mon1 = today.getMonth()+1;//January is 0!
        if (mon1<10) {mon1='0'+mon1}

        // Go back 16 years
        var yr1 = today.getFullYear()-yearsofage;

        var targetdate = mon1+'/'+dt1+'/'+yr1;

        var dateText = document.getElementById('dob').value;
        var dt2  = parseInt(dateText.substring(0,2),10);
        var mon2 = parseInt(dateText.substring(3,5),10);
        var yr2  = parseInt(dateText.substring(6,10),10);
        var actualdate = mon2+'/'+dt2+'/'+yr2;

        var error = false;

        if (yr2 > yr1) {
            //year issue test month
            error = true;
        }

        if (yr2==yr1) {
            if (mon2 > mon1) {
                //Month issue
                error = true;
            }
            if (mon2 == mon1) {
                if (dt2 > dt1) {error = true;}
            }
        }

        if (error) {
            alert('Sorry you must be 16 years or older to retrieve a quote.');
            document.getElementById('dob').value = "";
            return false;
        }
    }
}


function validatecheckbox(thisval) {
	if (document.getElementById("agreeterms").checked) {
		document.getElementById("nextstep").value = thisval;
		document.quotation_form.submit();
	}
	else {
		alert("You need to agree to the terms in order to proceed.")
	}
}


// script to add an item to a drop down
function addOption(selectbox,text,value ) {
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
	selectbox.options.add(optn);
}


function resetPersonalDetails(){
	// Call a PHP Script to return the vessel types
	var test ="app/lib/reset_details.php?reset=1";
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
						//Go back to get-a-quote page, i.e. start over
						document.location.href = "get-a-quote.html";
					}
				}				
			}
			//call php
			req.open("GET", test, true);
			req.send(null);
		}
}

function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}

	return xmlhttp;
}
-->
