function CheckDekking()
{
	var objBestemming		= document.getElementById('BestemmingSelect');
	var objOpAanvraag		= document.getElementById('OpAanvraag');
	
	var	strCountry				= objBestemming.options[objBestemming.selectedIndex].text;
	document.getElementById('ShowBestemming').innerHTML = strCountry.replace('*', '');
	
	if(strCountry.indexOf('*') != -1)
	{
		objOpAanvraag.className	= 'Visible';
	}
	else
	{
		objOpAanvraag.className	= 'InVisible';
	}
}

function FillTestValues()
{
	var strFillDate		= '29-08-2006';
	var strFillDate2	= '30-08-2006';

	document.getElementById('BestemmingSelect').selectedIndex = 2;
	
	//document.getElementById('PickUpDate').value				= strFillDate;
	document.getElementById('DepartureDate').value			= strFillDate;
	document.getElementById('DepartureTime').selectedIndex	= 12;
	document.getElementById('DepartureFlightNumber').value	= 'UA93';
	document.getElementById('ArrivalDate').value			= strFillDate2;
	document.getElementById('ArrivalTime').selectedIndex		= 20;
	document.getElementById('ArrivalFlightNumber').value	= 'UA175';
	
	CheckDekking()
}

function ValidateStapEen()
{
	blnValid		= true;
	strValidString	= 'Controleer de volgende velden:\n\n';
	
	//Datums ingevuld
	//Datums geldig
	//Datums niet in de verleden tijd
	//Datum verschil > 0 dagen
	//Datums niet verder weg dan 30 dagen

	var objBestemming		= document.getElementById('BestemmingSelect');
	var strBestemming		= objBestemming.options[objBestemming.selectedIndex].text;
	
	//var strOphaalDatum		= document.getElementById('PickUpDate').value;
	
	var strVertrekDatum		= document.getElementById('DepartureDate').value;
	
	var objVertrekTijd		= document.getElementById('DepartureTime');
	var strVertrekTijd		= objVertrekTijd.options[objVertrekTijd.selectedIndex].text;
	
	var strAankomstDatum	= document.getElementById('ArrivalDate').value;
	
	var objAankomstTijd		= document.getElementById('ArrivalTime');
	var strAankomstTijd		= objAankomstTijd.options[objAankomstTijd.selectedIndex].text;
	
	ValidateBestemming(strBestemming);
	
	//ValidateForEmpty('PickUpDate', 'Ophaaldatum');
	ValidateForEmpty('DepartureDate', 'Vertrekdatum');
	//ValidateForEmpty('DropOffDate', 'Inleverdatum');
	ValidateForEmpty('ArrivalDate', 'Aankomstdatum');
	
	
	//if(ValidateDatum(strOphaalDatum, 'Ophaaldatum', 1, 'reserveringsdatum', null, null, null))
	//{
		if(ValidateDatum(strVertrekDatum, 'Vertrekdatum', 1, 'reserveringsdatum', null, null, null))//Na reserveringsdatum, op of na VertrekDatum
		{
			//if(ValidateDatum(strInleverDatum, 'Inleverdatum', 1, 'reserveringsdatum', strVertrekDatum, 'vertrekdatum', 0))//Na reserveringsdatum, op of na vertrekdatum
			//{
				if(ValidateDatum(strAankomstDatum, 'Aankomstdatum', 1, 'reserveringsdatum', strVertrekDatum, 'vertrekdatum', 0))//Na reserveringsdatum, op of na vertrekdatum
				{
					//ValidateDatum(strAankomstDatum, 'Aankomstdatum', null, '', strInleverDatum, 'inleverdatum', -1);//Op of voor inleverdatum
				}
			//}
		}
			
	//}
	
	ValidateTijd(strVertrekTijd, 'Vertrektijd');
	ValidateForEmpty('DepartureFlightNumber', 'Vertrekvlucht');

	
		
	ValidateTijd(strAankomstTijd, 'Aankomsttijd');
	ValidateForEmpty('ArrivalFlightNumber', 'Aankomstvlucht');
	
	
	if(blnValid)
	{
		CalculatePrice();
	}
	else
	{
		alert(strValidString);
	}
	return blnValid;
}

function ValidateStapTwee()
{
	blnValid		= true;
	strValidString	= 'Controleer de volgende velden:\n\n';
	
	if(document.getElementById('KortingVoucherVink').checked)
	{
		ValidateForEmpty('KortingsCode', 'Kortingscode');
	}
	
	if(blnValid)
	{
		GoToStep(3);		
	}
	else
	{
		alert(strValidString);
	}
}


function ValidateStapDrie()
{

	blnValid		= true;
	strValidString	= 'Controleer de volgende velden:\n\n';

	ValidateForEmpty('Initials', 'Voorletters');
	ValidateForEmpty('LastName', 'Achternaam');
	ValidateForEmpty('Address', 'Adres');
	ValidateForEmpty('StreetNumber', 'Huisnummer');
	
	document.getElementById('PostalCode').value	= removeSpaces(document.getElementById('PostalCode').value.toUpperCase());
	
	if(ValidateForEmpty('PostalCode', 'Postcode'))
	{
		if(!checkExpression(document.getElementById('PostalCode').value, g_ReEx_dutchzipcode))
		{
			strValidString += 'Poscode:\t\tOngeldige waarde\n';
			blnValid	= false;
		}
	}
			
	ValidateForEmpty('City', 'Plaats');
	ValidateForEmpty('Telephone', 'Telefoonnummer');
	
	if(ValidateForEmpty('Email', 'E-mail'))
	{
		if(!checkExpression(document.getElementById('Email').value, g_ReEx_email))
		{
			strValidString += 'E-mail:\t\tOngeldige waarde\n';
			blnValid	= false;
		}
	}
	
	if(blnValid)
	{
		//document.getElementById('sendto').value = document.getElementById('Email').value;
		document.frmHuren.submit();		
	}
	else
	{
		alert(strValidString);
	}
}

function trimspaces(strValue)
{
	strValue=strValue.replace(/^[\s]+/g,"");
    strValue=strValue.replace(/[\s]+$/g,"");
	return strValue;
}

function removeSpaces(string)
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	{
		tstring += splitstring[i];
	}
	return tstring;
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}


function ShowHideKorting(blnChange)
{
	var objVoucher		= document.getElementById('CheckVoucher');
	
	var strKortingsCode	= document.getElementById('KortingsCode').value;
	
	var objKortingRow1	= document.getElementById('KortingRow1');
	var objKortingRow2	= document.getElementById('KortingRow2');
	var objKortingRow3	= document.getElementById('KortingRow3');
	
	if(blnChange)
	{
		if(objVoucher.value == '0')
		{
			objVoucher.value = '1';
		}
		else
		{
			objVoucher.value = '0';
		}
	}
	
	if(objVoucher.value == '1')
	{	
		objKortingRow1.className = 'Visible';
		if(strKortingsCode != '')
		{
			objKortingRow2.className = 'Visible';
			objKortingRow3.className = 'Visible';
		}
		else
		{
			objKortingRow2.className = 'Invisible';
			objKortingRow3.className = 'Invisible';
		}

			
	}
	else
	{
		objKortingRow1.className = 'Invisible';
		objKortingRow2.className = 'Invisible';
		objKortingRow3.className = 'Invisible';
	}

	CalculatePrice();
}


function GoToStep(intStepToGoTo)//Aansturen validatie
{
	var objCurrentStep	= document.getElementById('CurrentStep');
	var intCurrentStep	= objCurrentStep.value;
	
	switch(intStepToGoTo)
	{
		case 1:
		{
			ShowStep(1);
			break;
		}
		case 2:
		{
			if(intCurrentStep != 1 || ValidateStapEen())
			{
				ShowStep(2);
			}
			break;
		}
		case 3:
		{
			ShowStep(3);
			break;
		}
	}
	
	ShowHideKorting(false);
	
	
}

function ShowStep(intStep)
{
	var objCurrentStep	= document.getElementById('CurrentStep');
	var intCurrentStep	= objCurrentStep.value;
	
	var divStapEen	= document.getElementById('StapEen');
	var divStapTwee	= document.getElementById('StapTwee');
	var divStapDrie	= document.getElementById('StapDrie');
	
	divStapEen.className	= 'Invisible';
	divStapTwee.className	= 'Invisible';
	divStapDrie.className	= 'Invisible';
	
	switch(intStep)
	{
		case 1:
		{
			divStapEen.className	= 'Visible';
			break;
		}
		case 2:
		{
			divStapTwee.className	= 'Visible';
			break;
		}
		case 3:
		{
			divStapDrie.className	= 'Visible';
			break;
		}
	}
	objCurrentStep.value	= intStep;
}

function ValidateBestemming(strBestemming)
{
	if(strBestemming.indexOf('Kies') > -1)
	{
		strValidString += 'Vakantie bestemming:\tSelecteer een bestemming\n';
		blnValid	= false;
	}
}

function ValidateDatum(strDatum, strFieldName, intDays, strFieldName2, strDateToCompareTo, strFieldName3, intDays2)
{
	var blnThisValid	= true;
	var strFieldNameLower	= strFieldName.toLowerCase();

	if(strDatum.length == 0)
	{
		//strValidString += strFieldName + ':\t\tVul een ' + strFieldNameLower + ' in\n';
		strValidString += strFieldName + ':\t\tGeen waarde ingevuld\n';
		blnThisValid		= false;
	}
	else
	{	
		if(!IsDutchDate(strDatum))
		{
			strValidString += strFieldName + '\t\tOngeldige datum\n';
			blnThisValid	= false;
		}
		else
		{
			if(intDays != null && !CompareDutchDate(strDatum, intDays, null))
			{
				strValidString += strFieldName + ':\t\tTenminste ' + intDays + ' dag(en) na de ' + strFieldName2 + '\n';
				blnThisValid	= false;
			}
			else
			{
				if(strDateToCompareTo != null)
				{
					if(!CompareDutchDate(strDatum, intDays2, strDateToCompareTo))
					{
						if(intDays2 < 0)
						{
							strValidString += strFieldName + ':\t\tMoet voor ' + strFieldName3 + ' liggen\n';
						}
						
						if(intDays2 == -1)
						{
							strValidString += strFieldName + ':\t\tMoet op of voor ' + strFieldName3 + ' liggen\n';
						}
						
						if(intDays2 == 0)
						{
							strValidString += strFieldName + ':\t\tMoet op of na ' + strFieldName3 + ' liggen\n';
						}
						if(intDays2 > 0)
						{
							strValidString += strFieldName + ':\t\tMoet tenminste ' + intDays + ' dag(en) na '+ strFieldName3 + ' liggen\n';
						}
						blnThisValid	= false;
					}
				}
			}
					
		}
		if(!blnThisValid)
		{
			blnValid = false;
		}
		return blnThisValid;
	}
	

}

function ValidateTijd(strVertrekTijd, strFieldName)
{
	var strFieldNameLower	= strFieldName.toLowerCase();

	if(strVertrekTijd.indexOf('Kies') > -1)
	{
		strValidString += strFieldName + ':\t\tSelecteer een tijd\n';
		blnValid	= false;
	}
}
/*
function ValidateTijd(strTijd, strFieldName)
{
	var strFieldNameLower	= strFieldName.toLowerCase();
	
 	if(strTijd.length == 0)
	{
		//strValidString += strFieldName + ':\t\tVul een ' + strFieldNameLower + ' in\n';
		strValidString += strFieldName + ':\t\tGeen waarde ingevuld\n';
		
		blnValid	= false;
	}
	else
	{
		if(!IsDutchTime(strTijd))
		{
			strValidString += strFieldName + ':\t\tOngeldige tijd\n';
			blnValid	= false;
		}
	}	
}
*/

function ValidateForEmpty(strInputField, strFieldName)
{
	var blnThisValid	= true;
	var objInput		= document.getElementById(strInputField);
	
	if(trimspaces(objInput.value).length == 0)
	{
		strValidString += strFieldName + ':\t\t'
		if(strFieldName.toString().length < 7)
		{
			strValidString += '\t';
		}
		strValidString += 'Geen waarde ingevuld\n';
		blnThisValid	= false;
		blnValid	= false;
	}
	return blnThisValid;
}


function CalculateDayDifference(strBeginDatum, strEindDatum, strBeginTime, strEindTime)
{
	var dtmBegin	= CreateDateFromDutchString(strBeginDatum, strBeginTime);
	var dtmEind		= CreateDateFromDutchString(strEindDatum, strEindTime);
	
	var intMillisecPerDay	= 1000 * 60 * 60 * 24;

	return Math.ceil((dtmEind.getTime()-dtmBegin.getTime()) / (intMillisecPerDay))
}

function CalculatePrice()
{

	var strKortingsCode	= document.getElementById('KortingsCode').value;
	
	var strVertrekDatum		= document.getElementById('DepartureDate').value;
	
	var objVertrekTijd	= document.getElementById('DepartureTime')
	var strVertrekTijd	= objVertrekTijd.options[objVertrekTijd.selectedIndex].text;	
	var objAankomstTijd	= document.getElementById('ArrivalTime')
	var strAankomstTijd	= objAankomstTijd.options[objAankomstTijd.selectedIndex].text;	
	
	
	var strAankomstDatum	= document.getElementById('ArrivalDate').value;

	var intDayDiff	= CalculateDayDifference(strVertrekDatum, strAankomstDatum, strVertrekTijd, strAankomstTijd);
	document.getElementById('ShowHuurDagen').innerHTML = intDayDiff;
	document.getElementById('HuurDagen').value = intDayDiff;
	
	var intTotalAmount	= intDayDiff * 12.50;
	var intTotalKorting	= intDayDiff * 2.55;
	
	if(document.getElementById('CheckVoucher').value == '1' && strKortingsCode != '')
	{
	}
	else
	{
		intTotalKorting = 0;
	}
		
	
	intTotalAmount		= CurrencyFormatted(intTotalAmount - intTotalKorting).toString().replace('.', ',');
	intTotalKorting		= CurrencyFormatted(intTotalKorting).toString().replace('.', ',');
	
	document.getElementById('RentalAmount').value	= intTotalAmount;
	document.getElementById('TotaalKorting').value	= intTotalKorting;
	
	document.getElementById('lblRentalAmount').innerHTML	= 'EUR ' + intTotalAmount;
	document.getElementById('lblTotaalKorting').innerHTML	= 'EUR ' + intTotalKorting;
}
	
function OpenPopup(url,width,height, left, top,debug) 
{
	var curWinLeft = 0;
	var curWinTop = 0;
	var resizable = 'no';
	if(width==null||height==null)
	{
		width = 600;
		height = 400;
		resizable = 'yes';
	}
	curWinLeft = screen.availWidth/2-(width/2);
	curWinTop = screen.availHeight/2-(height/2);
	if (left >= 0 && top >=0 )
	{
	
		if (navigator.appName=="Microsoft Internet Explorer")
		{
			curWinLeft =  window.screenLeft;
			curWinTop =  window.screenTop;
		} else {
			curWinLeft =    window.screenX;
			curWinTop = window.screenY;
		}		
		curWinLeft += left;
		curWinTop += top;
	}
	
	if(debug)
	{
		var popup = window.open(url,'New_Window','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height + ', left=' + curWinLeft+',top=' + curWinTop);
	}
	else
	{
		var popup = window.open(url,'New_Window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable='+resizable+',copyhistory=no,width='+width+',height='+height + ', left=' + curWinLeft+',top=' + curWinTop);
	} 
}
