var forceok = false;

function enableExportButton() {
	//ContentChanged();
	this.parent.GetElement("cmsexportbutton").style.visibility = "visible";
}


function IsNumeric(sText)
{
	var ValidChars = "0123456789.,";
	var IsNumber=true;
	var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	
	}
	
	return IsNumber;
   
}

function isValidEmail(strEmail){
	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	
	// search email text for regular exp matches
	if (strEmail.search(validRegExp) == -1) 
	{
		return false;
	} 

	return true; 
}




function validate_polisnummer(f)
{
	//if (forceok == true) return true;

	var o = document.getElementById("polisnummer");
	o.style.border = "1px solid #c4c4c4";

	if (o.value.length == 0)
	{
		o.style.border = "1px solid #ff0000";
		document.getElementById("error").innerHTML = "U bent het polisnummer vergeten in te vullen";
		return false;
	}
	

	if (IsNumeric(o.value) == false)
	{
		o.style.border = "1px solid #ff0000";
		document.getElementById("error").innerHTML = "Het polis nummer bestaat alleen uit cijfers";
		return false;
	}

	return true;
}


function validate_gegevens(f)
{
	if (forceok == true) return true;

	var fields = new Array('txtreissom', 'txtpremie', 'txtnaam', 'txtadres', 'txtpostcode', 'txtplaats', 'txtemail', 'startDate', 'endDate');
	var names = new Array('reissom', 'premie', 'naam', 'adres', 'postcode', 'plaats', 'email', 'begindatum', 'einddatum');

	for (var i = 0 ; i < fields.length ; i++ )
	{

		var o = document.getElementById(fields[i]);
		o.style.border = "1px solid #c4c4c4";
		if (o.value.length == 0)
		{		
			o.style.border = "1px solid #ff0000";
			document.getElementById("error").innerHTML = "U bent het veld '" + names[i] + "' vergeten in te vullen";
			//alert("U bent het veld '" + names[i] + "' vergeten in te vullen");
			return false;
		}
	}
	
	//Speciale check:
	if (IsNumeric(document.getElementById('txtreissom').value) == false)
	{
		document.getElementById("error").innerHTML = "De reissom mag alleen uit cijfers bestaan";
		document.getElementById('txtreissom').style.border = "1px solid #ff0000";
		return false;
	}

	if (isValidEmail(document.getElementById('txtemail').value) == false)
	{
		document.getElementById("error").innerHTML = "Dit e-mail adres is ongeldig";
		document.getElementById('txtemail').style.border = "1px solid #ff0000";

		//alert('Dit E-mail adres is ongeldig');
		return false;
	}
	
	var theFromYear = document.getElementById("fromyear").value;
	var theFromMonth = document.getElementById("frommonth").value;
	var theFromDay = document.getElementById("fromday").value;
	
	var theToYear = document.getElementById("toyear").value;
	var theToMonth = document.getElementById("tomonth").value;
	var theToDay = document.getElementById("today").value;
	
	
	// Check begindate
	if(checkDate(theFromDay, theFromMonth, theFromYear) == false)
	{
		document.getElementById("error").innerHTML = "De begindatum is onjuist.";
		document.getElementById('startDate').style.border = "1px solid #ff0000";
		return false;
	}
	
	// Check the end date
	if(checkDate(theToDay, theToMonth, theToYear) == false)
	{
		document.getElementById("error").innerHTML = "De einddatum is onjuist.";
		document.getElementById('endDate').style.border = "1px solid #ff0000";
		return false;
	}
	
	
	if((""+theToYear+theToMonth+theToDay) <= (""+theFromYear+theFromMonth+theFromDay))
	{
		document.getElementById("error").innerHTML = "De einddatum moet na de begindatum liggen.";
		document.getElementById('endDate').style.border = "1px solid #ff0000";
		return false;
	}
	
	//Alles ok.
	return true;
}

function checkDate(day, month, year)
{
	var today = new Date();
	if(!isNaN(day) && !isNaN(month) && !isNaN(year)){
		if(day < 1 || day > 31){
			return false;
		}
		if(month < 1 || month > 12){
			return false;
		}
		if(year < today.getFullYear() || year > (today.getFullYear() + 2)){
			return false;
		}
	} else {
		return false;
	}
	return true;
}

function validate_rekeningnummer(f)
{
	if (forceok == true) return true;

	//Geen incasso..
	if (document.getElementById('oincasso').checked == false)
	{
		return true;
	}
	document.getElementById("error").innerHTML  = '';
	var o = document.getElementById("rekeningnummer");
	o.style.border = "1px solid #c4c4c4";
	if (o.value.length < 4)
	{
		document.getElementById("error").innerHTML = "U bent het rekeningnummer vergeten in te vullen.";
		o.style.border = "1px solid #ff0000";
		//alert("U bent het rekeningnummer vergeten in te vullen");
		return false;
	}

	if (o.value.length >= 9)
	{
		//  do elf proef
		if (!elfproef(o.value)) {
			document.getElementById("error").innerHTML = "U heeft geen geldig rekeningnummer ingevuld.";
			o.style.border = "1px solid #ff0000";
			return false;
		}
	}
	
	return true;
}




function placeflashmovie(video1, video2, forcestop)
{
	if (video1 == undefined)
	{
		video1 = "/cms/images/swf-5289385dcfe9892a37b981634632d4cb.swf";
	} 

	if (video2 == undefined)
	{
		video2 = "/cms/images/swf-de57b732955546f77650962772ad938f.swf";
	}

	if (forcestop == undefined)
	{
		forcestop = 0;
	}

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" height="209" width="230" id="Player" align="middle">');
	document.write('<param name="allowScriptAccess" value="sameDomain" />');
	document.write('<param name="movie" value="/cms/images/swf-897e1847abf4a6a8852774ad0446c320.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#ffffff" />');
	document.write('<param name="FlashVars" value="forcestop=' + forcestop + '&videoFilename=' + video1+ '&video8Filename=' + video2 + '">');
	document.write('<embed src="/cms/images/swf-897e1847abf4a6a8852774ad0446c320.swf" FlashVars="videoFilename=' + video1+ '&video8Filename=' + video2 + '&forcestop=' + forcestop + '" quality="high" bgcolor="#ffffff" height="209" width="230" name="Player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}


function validateDate(val) {
	 var regex = /^\d{1,2}-\d{1,2}-\d{4}$/

	 if ((val.match(regex)) && (val!=''))
	 {
		return true;
	 }

	 return false;
   
   /*
	var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    
    if ((fld.value.match(RegExPattern)) && (fld.value!='')) {
		return true;
    } else {
		return false;
	} 
	*/
}


function elfproef(val)
{
	var llAantal = 0;
	var llSom = 0;
	var i = 0;
	


	llAantal = val.length;

	for (i = 0; i < llAantal ; i++ )
	{
		var num = val.charAt(llAantal - i - 1);
		//alert(num);
		llSom = llSom + ((i+1) * num);
		//alert(llSom);
	}
	
	//alert(llSom);

	if (llSom == 0)
	{
		return false;
	}

	//alert(llSom % 11);

	if ((llSom % 11) != 0)
	{
		return false;
	}

	//Alles goed:

	return true;

}
function cleanrekening(nr)
{
	if (nr.length > 0)
	{
		nr = nr.replace(/-/g, '');
		nr = nr.replace(/\./g, '');
		nr = nr.replace(/\s/g, '');
	}
	return nr;
}

function openDirectSchade()
{
	window.open("http://www.recronservice.nl/cms/files/schadeformulier.pdf");
}
function openSchadeForm()
{
	//window.location = "javascript: OpenPageByID(6826);";
	window.location = "/cms/Uwpolisgegevens-6826.php";
}

function parseDateNumber(aValue)
{
	if(aValue.toString().length < 2 && aValue < 10){
		aValue = "0" + aValue;
	}
	return aValue;
}

function copyLink(aLink)
{
	window.clipboardData.setData('Text', aLink);
	alert('De link naar het bestand is gekopiëerd. Plak deze vervolgens als externe link in een tekstvak.');
	return false;
}

var myStartCal, myEndCal, currentCal;
	
 
function doOnload()
{
	myStartCal = new Calendar(0, null, ourOnSelect, ourOnClose);
	myStartCal.setDateFormat("%d-%m-%Y");
	myStartCal.setDateStatusHandler(ourDateStatusFunc);
	myStartCal.showTime = false;
	myStartCal.setRange(2008, 2099);
	myStartCal.showsOtherMonths = false;
	myStartCal.create(null);
	
	myEndCal = new Calendar(0, null, ourOnSelect, ourOnClose);
	myEndCal.setDateFormat("%d-%m-%Y");
	myEndCal.setDateStatusHandler(ourDateStatusFunc);
	myEndCal.showTime = false;
	myEndCal.setRange(2008, 2099);
	myEndCal.showsOtherMonths = false;
	myEndCal.create(null);

}

function openStartCal(obj)
{
	currentCal = "start";
	myStartCal.refresh();
	
	var theStartDatum = document.getElementById("startDate").value;
	var myOpenDate = new Date();
	
	if (theStartDatum == "") {
		myStartCal.setDate(myOpenDate);
	}
	
	myStartCal.showAtElement(obj, "Tl");
}

function openEndCal(obj)
{
	currentCal = "end";
	myEndCal.refresh();
	
	var theStartDatum = document.getElementById("startDate").value;
	
	if (theStartDatum != "") {
		var theDate = theStartDatum.split("-");
		var myOpenDate = new Date(theDate[1]+"/"+theDate[0]+"/"+theDate[2]);
		myEndCal.setDate(myOpenDate);
	}
	
	myEndCal.showAtElement(obj, "Tl");
}


function ourOnClose(calendar) {
  calendar.hide();
};


function ourOnSelect(calendar, aDate) {
	var d = calendar.date;
	var theStartDatum = document.getElementById("startDate");
	var theEindDatum = document.getElementById("endDate");
	var theDate = aDate.split("-");
	switch(currentCal) {
		case "start":
			theStartDatum.value = aDate;
			
			document.getElementById("fromyear").value = theDate[2];
			document.getElementById("frommonth").value = theDate[1];
			document.getElementById("fromday").value = theDate[0];				
			break;
			
		case "end":
			theEindDatum.value = aDate;
			
			document.getElementById("toyear").value = theDate[2];
			document.getElementById("tomonth").value = theDate[1];
			document.getElementById("today").value = theDate[0];
			break;
	}

	var ta = theStartDatum.value.split("-");
	var tv = theEindDatum.value.split("-");
	
	if (ta[2]+""+ta[1]+""+ta[0] > tv[2]+""+tv[1]+""+tv[0]) {
		theEindDatum.value = "";
		document.getElementById("toyear").value = "";
		document.getElementById("tomonth").value = "";
		document.getElementById("today").value = "";
	}	
	
	if (calendar.dateClicked) {
		calendar.callCloseHandler();
	}
};


// this is the actual date status handler.  Note that it receives the
// date object as well as separate values of year, month and date, for
// your confort.
function ourDateStatusFunc(date, y, m, d) {
	var theStartDatum = document.getElementById("startDate").value;
	if ((currentCal == "end") && theStartDatum != "") {
		var myStartDate = theStartDatum.split("-");
		var ty = myStartDate[2];
		var tm = myStartDate[1];
		var td = myStartDate[0];
	}
	else {
		var today = new Date();
		var ty = today.getFullYear();
		var tm = today.getMonth();
		var td = today.getDate();
		tm = tm+1;
		if (td < 10) {td = "0"+td;}
		if (tm < 10) {tm = "0"+tm;}
	}
	
	m = m+1;

	if (d < 10) {d = "0"+d;}
	if (m < 10) {m = "0"+m;}
	
	// Always select today; otherwise bug in calendar (null date object)
	if ( (y == ty) && (m == tm) && (d == td) ) {
		return false;
	}
	
	//alert(y+"-"+m+"-"+d +" < "+ ty+"-"+tm+"-"+td);
	
	// disable days in the past or smaller than aankomstdatum
	if (y+""+m+""+d < ty+""+tm+""+td) {
		return true;
	}
	else {
		return 'available';//false;
	}
	
	return true;
}

