var 
	siteWidth = 741,
	firstDay  = wdMonday;
	
//-------------------------------------------------------------------------------------------------
var countSelHouses = 0;
function toggleWoning(object, idx)
{
	if (document.getElementsByName("cb_"+idx)[0].checked ) 
	{
		document.getElementsByName("cb_"+idx)[0].checked = false;
		countSelHouses--;
		for (var i = 0; i < 3; i++)
		{	
			if (document.getElementsByName("selHouse"+i)[0].value == idx)
			{
				document.getElementsByName("selHouse"+i)[0].value = "";
				break;
			}
			
		}
		object.value = "selecteer";
	}
	else
	{
		if (countSelHouses < 3)
		{
			document.getElementsByName("cb_"+idx)[0].checked = true;
			countSelHouses++;
			for (var i = 0; i < 3; i++)
			{	
				if (document.getElementsByName("selHouse"+i)[0].value == "")
				{
					document.getElementsByName("selHouse"+i)[0].value = idx;
					break;	
				}
			}
			object.value = "deselecteer";
		}
	}
}
//-------------------------------------------------------------------------------------------------
function toggleCBWoning(object, idx)
{
	if (object.checked ) 
	{
		if (countSelHouses < 3)
		{
			countSelHouses++;
			for (var i = 0; i < 3; i++)
			{	
				if (document.getElementsByName("selHouse"+i)[0].value == "")
				{
					document.getElementsByName("selHouse"+i)[0].value = idx;
					break;	
				}
			}
			document.getElementsByName("btn_"+idx)[0].value = "deselecteer";
		}
		else
			object.checked = false;
	}
	else
	{
		countSelHouses--;
		for (var i = 0; i < 3; i++)
		{	
			if (document.getElementsByName("selHouse"+i)[0].value == idx)
			{
				document.getElementsByName("selHouse"+i)[0].value = "";
				break;
			}
		}
		document.getElementsByName("btn_"+idx)[0].value = "selecteer";
		
	}
}
//-------------------------------------------------------------------------------------------------
function Submit()
{
	if (document.getElementsByName("selHouse0")[0].value == "" 
		&& document.getElementsByName("selHouse1")[0].value == "" 
		&& document.getElementsByName("selHouse2")[0].value == "")
	{
		alert("Er moet minimaal 1 woning geselecteerd zijn");
		return false;
	}
	else
		document.frmCompare.submit();
}
//=================================================================================================
function toggleHead( sender )
{
	var
		nr   = String( sender.id ).split("_")[1], 
		img1 = sender.childNodes[0], 
		img2 = sender.childNodes[1], 
		head = document.getElementById("tbHead_" + nr ), 
		spcr = document.getElementById("tbSpacer_" + nr );
	
	toggleDisplay( img1 );
	toggleDisplay( img2 );
	toggleDisplay( head );
	toggleDisplay( spcr );
}
//=================================================================================================
function toggleTabBezetting( idx )
{
	for (var i = 1; i <= 4; i++)
	{
		if ( i == idx)
			document.all['tbl_'+i].style.display = '';
		else
			document.all['tbl_'+i].style.display = 'none';
	}
	
	if ( idx == 1 )
	{
		document.all['btn_1'].className = 'btnMidweekSel';
		document.all['btn_2'].className = 'btnWeek';
		document.all['btn_3'].className = 'btnWeekend';
		document.all['btn_4'].className = 'btnDag';
	}
	
	if ( idx == 2 )
	{
		document.all['btn_1'].className = 'btnMidweek';
		document.all['btn_2'].className = 'btnWeekSel';
		document.all['btn_3'].className = 'btnWeekend';
		document.all['btn_4'].className = 'btnDag';
	}
	
	if ( idx == 3 )
	{
		document.all['btn_1'].className = 'btnMidweek';
		document.all['btn_2'].className = 'btnWeek';
		document.all['btn_3'].className = 'btnWeekendSel';
		document.all['btn_4'].className = 'btnDag';
	}
	
	if ( idx == 4 )
	{
		document.all['btn_1'].className = 'btnMidweek';
		document.all['btn_2'].className = 'btnWeek';
		document.all['btn_3'].className = 'btnWeekend';
		document.all['btn_4'].className = 'btnDagSel';
	}
}
//=================================================================================================
function pMouseOver( type, idx )
{	
	if (idx > 0)
	{
		for (var i = 1; i <= 7; i++)
		{
			if ( document.getElementById(type+'_'+idx+'_'+i) )
			{	
				if ( document.getElementById(type+'_'+idx+'_'+i).className != 'outSelectionArea')
					document.getElementById(type+'_'+idx+'_'+i).style.background = '#69946B';
			}
		}
	}
}
//=================================================================================================
function pMouseOut( type, idx )
{	
	if (idx > 0)
	{
		for (var i = 1; i <= 7; i++)
		{
			if ( document.getElementById(type+'_'+idx+'_'+i) )
			{
				if ( document.getElementById(type+'_'+idx+'_'+i).className != 'outSelectionArea')
					document.getElementById(type+'_'+idx+'_'+i).style.background = '#567858';
			}
		}
	}
}
//=================================================================================================
	function prevMonth()
	{
		if (document.getElementById('selectMonth').selectedIndex > 0 )
		{
			document.getElementById('selectMonth').selectedIndex--;
			document.frmSelect.submit();
		}
	}

	function nextMonth()
	{
		document.getElementById('selectMonth').selectedIndex++;
		document.frmSelect.submit();
	}
	var scrollTimer;
	function goLeft(stappen)
	{
		stappen--;
		
		if ( containerPhotoSlide.scrollLeft >= 5 )
			containerPhotoSlide.scrollLeft = containerPhotoSlide.scrollLeft - 5;
		else 
			containerPhotoSlide.scrollLeft = 0;
		
		if (stappen >= 0)
			scrollTimer = setTimeout( 'goLeft('+stappen+')', 10 );
	}
	function stopTimer()
	{
		clearTimeout( scrollTimer );
		scrollTimer = null;
	}
	function goRight(stappen)
	{
		stappen--;
		
		if ( containerPhotoSlide.scrollLeft < containerPhotoSlide.scrollWidth )
			containerPhotoSlide.scrollLeft = containerPhotoSlide.scrollLeft + 5;
		else
			containerPhotoSlide.scrollLeft = containerPhotoSlide.scrollWidth;
		
		if (stappen >= 0)
			scrollTimer = setTimeout('goRight(' + stappen + ')', 10);
	}
//=================================================================================================
function checkLastMinute()
{
	if( !document.getElementById('edtBegindatum').value)
	{
		document.getElementById('edtBegindatum').focus();
		alert( 'Begindatum is verplicht.');
		return false;
	}
	else if( !document.getElementById('edtEinddatum').value)
	{
		document.getElementById('edtEinddatum').focus();
		alert( 'Einddatum is verplicht.');
		return false;
	}
	else if( !document.getElementById('edtPrijs').value)
	{
		document.getElementById('edtPrijs').focus();
		alert( 'Prijs is verplicht.');
		return false;
	}

	var
		date;

	date = validDate( document.getElementById('edtBegindatum').value );
			
	if ( ! date || date == NaN )
	{
		document.getElementById('edtBegindatum').focus();
		alert( 'Begindatum bevat geen juiste waarde.');
		return false;

	}

	date = validDate( document.getElementById('edtEinddatum').value );
			
	if ( ! date || date == NaN )
	{
		document.getElementById('edtEinddatum').focus();
		alert( 'Einddatum bevat geen juiste waarde.');
		return false;

	}

	if( !ValFloat( document.getElementById('edtPrijs').value, true))
	{
		document.getElementById('edtPrijs').focus();
		alert( 'Prijs bevat geen juiste waarde.');
		return false;
	}

	document.frmLastMinute.submit();
	return true;
}
//=================================================================================================
function validDate( value )
{
	if ( new String( value ).length == 0 )
		return true;
	
	if ( value.indexOf("T") > -1 ) 
		return isXMLDate( value );
	
	if ( value.substr(0, 1) == "0")
		value = value.substr(1);
	
	var
		fields = new String( value ).split("-"),
		day    = parseInt( fields[0] ),
		month,
		year;
	
	if ( fields.length < 2 || fields.length > 3 || day < 1 )
		return false;
	
	if ( fields[1].substr(0, 1) == "0")
		fields[1] = fields[1].substr(1);
	
	month = parseInt( fields[1] );
	
	if ( fields.length == 3 )
	{
		year = parseInt( fields[2] );
		
		if ( fields[2].length == 2 )
		{
			if ( year < 40 ) 
				year += 2000;
			else
				year += 1900;
		}
	}
	else
		year = new Date().getYear();
	
	if ( year < 1753 || year > 9999 ) 
		return false;
	
	switch ( month )
	{
		case 2:
			if ( year % 4 == 0 && (year % 100 != 0 || year % 1000 == 0) ) 
			{
				if ( day > 29 ) 
					return false;
			}
			else if ( day > 28 )
				return false;
			
			break;
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if ( day > 31 ) 
				return false;
			
			break;
		case 4:
		case 6:
		case 9:
		case 11:
			if ( day > 30 ) 
				return false;
			
			break;
		default:
			return false;
	}
	
	return new Date( year, month - 1, day, 0, 0 );
}
//=================================================================================================
function ValFloat(ObjectValue,AllowComma)
{
	if (ObjectValue.length == 0) return true;
	
	//Returns true if value is a number defined as
	//   having an optional leading + or -.
	//   having at most 1 decimal point.
	//   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	if (AllowComma == 1) number_format=number_format + ',';
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;
	
	//The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(ObjectValue.charAt(0))
	//Was it a decimal?
	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;
	
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < ObjectValue.length; i++)
	{
		check_char = number_format.indexOf(ObjectValue.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits) trailing_blank = true;
			// ignore leading blanks
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
	//All tests passed, so...
	return true
}
//=================================================================================================
function checkDate( sender, bd, ed)
{
	if( sender.value.length == 0)
		return;
		
	var begindatum = validDate( bd);
	var einddatum = validDate( ed);
	var datum = validDate( sender.value);
	
	if( datum < begindatum || datum > einddatum)
	{
		sender.focus();
		alert( 'Datum moet binnen geselecteerde periode vallen.');
	}
	
}
//=================================================================================================

