// JavaScript Document
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
/*
	use for pilot logs in committee and pilot section
*/

// for inserts
	function displayCostOfLandings()
	{	
		var cost = 0;
		var fee =0;
		var num_landings;
		fee = document.getElementById('home_landing_fee').value;
		num_landings = document.getElementById('landings').value;//alert(num_landings);
		if(num_landings == "")
		{
			num_landings = 0;
		}
		num_landings = num_landings.replace("-", " ");
		//num_landings = eval(num_landings);
		num_landings = num_landings;
		cost = (num_landings * fee);
		cost = cost.toFixed(2);
		document.getElementById('cost_of_landings1').value = cost;
		document.getElementById('cost_of_landings').value = cost;
		displayTotalCost();
	}
	function setAircraftRateValue(Value)
	{
		var new_val;
		var home_landing;
		var other_fee = 0;
		home_landing = document.getElementById('drpAirCrafts').value;
		home_landing = home_landing.split(",");
		other_fee	 = home_landing[2];
		document.getElementById('other_fee').value = other_fee;
		home_landing = home_landing[1];
		new_val = Value.split(",");
		document.getElementById('home_landing_fee').value = home_landing;
		new_val = new_val[2].split(" ");
		document.getElementById('aircraft_rate_per_hour').value = new_val[2];
		//displayTotalCost();
		displayCostOfLandings();
	}
	function setUpdateAircraftRateValue(Value)
	{
		var new_val;
		var home_landing;
		var other_fee = 0;
		home_landing = document.getElementById('drpAirCrafts').value;
		home_landing = home_landing.split(",");
		other_fee	 = home_landing[2];
		document.getElementById('other_fee').value = other_fee;
		home_landing = home_landing[1];
		new_val = Value.split(",");
		document.getElementById('txt_home_landing_fee').value = home_landing;
		new_val = new_val[2].split(" ");
		document.getElementById('hdn_aircraft_rate_per_hour').value = new_val[2];
		//UpdateDisplayTotalCost();
		UpdateDisplayCostOfLandings();
	}
	function displayTotalCost()
	{	
		var cost = 0;
		var fee =0;
		var other_fee = 0;
		var flight_duration = 0;
		var flight_duration_hrs = 0;
		var flight_duration_mins = 0;
		var aircraft_rate_per_hour = 0;
		var num_landings = 0;
		fee = eval(document.getElementById('home_landing_fee').value);
		flight_duration_hrs = eval(document.getElementById('flight_duration_hrs').value);
		flight_duration_mins = eval(document.getElementById('flight_duration_mins').value);
		flight_duration_mins = flight_duration_mins / 60;
		aircraft_rate_per_hour = eval(document.getElementById('aircraft_rate_per_hour').value);
		num_landings = document.getElementById('landings').value;
		num_landings = num_landings.replace("-", " ");
		num_landings = eval(num_landings);
		other_fee = eval(document.getElementById('other_fee').value);

		if(num_landings == "")
		{
			num_landings = 0;
		}
		if(flight_duration_mins == 0)
			flight_duration = flight_duration_hrs;
		else	
			flight_duration = (flight_duration_hrs) + (flight_duration_mins);
		document.getElementById('flight_duration').value = flight_duration;
		//alert(flight_duration);
		if(flight_duration == "")
		{
			flight_duration = 0;
		}

		//num_landings = eval(num_landings);
		num_landings = num_landings;
		cost = (num_landings * fee) + (flight_duration * aircraft_rate_per_hour);
		cost = cost + other_fee;
		cost = cost.toFixed(2);
		if(cost == 'NaN')
			cost = 0;
			
		document.getElementById('cost1').value = cost;
		document.getElementById('cost').value = cost;
	}
	
// for update	
	function UpdateDisplayCostOfLandings()
	{	
		var cost = 0;
		var fee =0;
		var other_fee = 0;
		var num_landings;
		fee = document.getElementById('txt_home_landing_fee').value;
		num_landings = document.getElementById('txtlandings').value;//alert(num_landings);
		if(num_landings == "")
		{
			num_landings = 0;
		}
		num_landings = num_landings.replace("-", " ");
		num_landings = parseInt(num_landings);
		//num_landings = eval(num_landings);
		cost = (num_landings * fee);
		cost = cost.toFixed(2);
		document.getElementById('txt_cost_of_landings1').value = cost;
		document.getElementById('txt_cost_of_landings').value = cost;
		UpdateDisplayTotalCost()
	}

	function UpdateDisplayTotalCost()
	{	
		var cost = 0;
		var fee =0;
		var other_fee = 0;
		var flight_duration;
		var flight_duration_hrs;
		var flight_duration_mins;
		var aircraft_rate_per_hour;
		var num_landings;
		fee = eval(document.getElementById('txt_home_landing_fee').value);
		flight_duration_hrs = eval(document.getElementById('txt_flight_duration_hrs').value);
		flight_duration_mins = eval(document.getElementById('txt_flight_duration_mins').value);
		flight_duration_mins = eval(flight_duration_mins / 60);
		aircraft_rate_per_hour = eval(document.getElementById('hdn_aircraft_rate_per_hour').value);
		num_landings = document.getElementById('txtlandings').value;
		other_fee = eval(document.getElementById('other_fee').value);
		
		
		if(num_landings == "")
		{
			num_landings = 0;
		}
		flight_duration = (flight_duration_hrs + flight_duration_mins);
		document.getElementById('txt_flight_duration').value = flight_duration;
		//alert(flight_duration);
		if(flight_duration == "")
		{
			flight_duration = 0;
		}
		num_landings = num_landings.replace("-", " ");
		//num_landings = eval(num_landings);
		num_landings = parseInt(num_landings);
		cost = (num_landings * fee) + (flight_duration * aircraft_rate_per_hour);
		cost = cost + other_fee;
		cost = cost.toFixed(2);
		document.getElementById('txtUpdateCost1').value = cost;
		document.getElementById('txtUpdateCost').value = cost;
	}

	
// for terms and condition

function showAgreement()
{
	var stats;
	stats = document.getElementById('hdnStats').value;
	if(stats == "on")
	{
		document.getElementById('agreementText').style.display = '';
		document.getElementById('hdnStats').value = "off";
	}
	else if(stats == "off")
	{
		document.getElementById('agreementText').style.display = 'none';
		document.getElementById('hdnStats').value = "on";
	}
	else{}
}


function AddToFavorites()
{
	var sitename="Loughborough Students Flying Club"
	var siteurl="http://www.lsflying.co.uk"

if (window.sidebar) window.sidebar.addPanel(sitename, siteurl,"");
else if( window.opera && window.print )
{
var
	dcE = document.createElement('a');
	dcE.setAttribute('rel','sidebar');
	dcE.setAttribute('href',siteurl);
	dcE.setAttribute('title',sitename);
	dcE.click();
}
else if( document.all ) window.external.AddFavorite( siteurl, sitename);
}


// "Accept Terms" Form Submission

var checkobj

function agreeSubmit(el)
{
	checkobj=el
	if (document.all||document.getElementById){
		for (i=0;i<checkobj.form.length;i++){
			var tempobj=checkobj.form.elements[i]
			if(tempobj.type.toLowerCase()=="submit")
				tempobj.disabled=!checkobj.checked
			}
		}
	}

	function defaultAgree(el)
	{
		if (!document.all&&!document.getElementById){
			if (window.checkobj&&checkobj.checked)
			return true
		else{
			alert("Please read/accept terms to submit form")
			return false
		}
	}
}
// start for validating sponsors fields
function isValidName(name){
	if (name == "") {
		return (false);
	}else{
		return (true);
	}
}

function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}	

function checkField(obj){

	var error = "";
    if(!isValidName(obj.txtName.value)){
        error += "Organization name is required.<br/>";
    }

    if(!isValidURL(obj.txtURL.value)){
        error += "A valid URL is required.<br/>";
    }
   
    if(error != ""){
        alert(error);
        return false;
    }else{
        return true;
    }
}
// end for validating sponsors fields

// for validating the search form
function doValidateSearch(frmSearch)
{
	var numericExpression = /^[0-9-]+$/;
	
	if (frmSearch.from.value == "")
	{
		alert("Start date is required.");
		frmSearch.from.focus();
		return (false);
	} else {
		if(frmSearch.from.value.match(numericExpression)){
			//return true;
		} else {
			alert("Please enter a valid date format (dd-mm-yyyy).");
			frmSearch.from.focus();
			return (false);
		}
	}

	if (frmSearch.to.value == "")
	{
		alert("End date is required.");
		frmSearch.to.focus();
		return (false);
	} else {
		if(frmSearch.to.value.match(numericExpression)){
			//return true;
		} else {
			alert("Please enter a valid date format (dd-mm-yyyy)");
			frmSearch.to.focus();
			return (false);
		}
	}

}
