function checkOrderForm(form)
{
	//reset inputboxes
	form.customerName.style.border = "";
	form.customerEmail.style.border = "";
	form.customerStreet.style.border = "";
	form.customerZip.style.border = "";
	form.customerPhone.style.border = "";
	form.cardNameBaby.style.border = "";
	form.cardBirthName.style.border = "";
	form.cardBirthDate.style.border = "";
	form.cardLength.style.border = "";
	form.cardWeight.style.border = "";
	form.cardPoetry.style.border = "";
	form.cardText.style.border = "";
	form.cardAdres.style.border = "";
	
	//check inputs
	if(!checkInputBox(form.customerName)) { return false; } else
	if(!checkEmailAddress(form.customerEmail.value)) 
	{
		alert("Het ingevulde emailadres is niet geldig!");
		form.customerEmail.value = ""; 
	}
	if(!checkInputBox(form.customerEmail)) { return false; } else
	if(!checkInputBox(form.customerStreet)) { return false; } else
	if(!checkInputBox(form.customerZip)) { return false; } else
//	if(!checkInputBox(form.customerPhone)) { return false; } else
	if(!checkInputBox(form.cardNameBaby)) { return false; } else
//	if(!checkInputBox(form.cardBirthName)) { return false; } else
//	if(!checkInputBox(form.cardBirthDate)) { return false; } else
//	if(!checkInputBox(form.cardLength)) { return false; } else
//	if(!checkInputBox(form.cardWeight)) { return false; } else
//	if(!checkInputBox(form.cardPoetry)) { return false; } else
//	if(!checkInputBox(form.cardText)) { return false; } else
//	if(!checkInputBox(form.cardAdres)) { return false; } else
	{ return true; }
}

function checkProefdrukForm(form)
{
	//reset inputboxes
	form.customerName.style.border		= "";
	form.customerEmail.style.border		= "";
	form.customerStreet.style.border	= "";
	form.customerZip.style.border		= "";
	form.customerPhone.style.border		= "";
	
	//check inputs
	if( !checkInputBox(form.customerName)			) { return false; } else
	if( !checkEmailAddress(form.customerEmail.value)) 
	{
		alert("Het ingevulde emailadres is niet geldig!");
		form.customerEmail.value = ""; 
	}
	if( !checkInputBox(form.customerEmail)			) { return false; } else
	if( !checkInputBox(form.customerStreet)			) { return false; } else
	if( !checkInputBox(form.customerZip)			) { return false; }
	return true;
}

function OnSubmitForm($post)
{
	alert($post);
	if(document.myform.paymethod[1].checked == true)
	{
		window.open('http://www.spoody.nl/ideal.php?post=$post', 'Betaal met Ideal', 'width=400,height=500,scrollbars=yes,toolbar=yes,location=yes' );
		window.open('https://ideal.rabobank.nl/ideal/mpiPayInitRabo.do', 'Betaal met Ideal', 'width=400,height=500,scrollbars=yes,toolbar=yes,location=yes' );
	}
	return true;
}

function OnSubmitForm1()
{
	if(document.myform.paymethod[1].checked == true)
	{
		document.myform.action="https://ideal.rabobank.nl/ideal/mpiPayInitRabo.do";
	}
	return true;
}

function checkInputBox(inputBox)
{
	if(!checkLength(inputBox.value)) {
		inputBox.style.border = "1px solid #FF0000";
		inputBox.focus();
		return false;
	} else {
		return true;
	}
}

function checkLength(word)
{
	return (word.length >= 2);
}

function checkEmailAddress(emailAddress) 
{
	return (emailAddress.indexOf('@') > 0 && emailAddress.indexOf('.') > 0 && emailAddress.length > 3 );
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}

function Get_Cookie( check_name )
{
	var a_all_cookies	= document.cookie.split( ';' );
	var a_temp_cookie	= '';
	var cookie_name		= '';
	var cookie_value	= '';
	var b_cookie_found	= false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		a_temp_cookie	= a_all_cookies[i].split( '=' );
		cookie_name		= a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}

function checkSlabCouponCode( Coupon )
{
	var I = Get_Cookie( 'slabCHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 5 )
	{
		if( ( Coupon.value.length == 6		)	&&
			( isFinite( Coupon.value )		)	&&
			( ( Coupon.value % 131 ) == 0 )	)	{
			Set_Cookie( 'slabCHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_slab").checked		= 1;
			document.getElementById("opt_slab").disabled	= 1;
			document.getElementById("slab_ok").value		= 1;
			document.getElementById("slab_coup_text").innerHTML = "Coupon code is correct.";
			document.getElementById("txt_slab").innerHTML	= "<b>gratis</b>";
			return true;
		} else {
			if( Coupon.value.length > 1 ) {
				Set_Cookie( 'slabCHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 5 ) {
					document.getElementById("slab_coup").disabled	= 1;
					document.getElementById("slab_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
				}
			}
			return false;
		}
	} else {
		document.getElementById("slab_coup").disabled	= 1;
		document.getElementById("slab_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
	}
}

function checkBoekCouponCode( Coupon )
{
	var I = Get_Cookie( 'plakCHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 5 )
	{
		if( ( Coupon.value.length == 6		)	&&
			( isFinite( Coupon.value )		)	&&
			( ( Coupon.value % 131 ) == 0 )	)	{
			Set_Cookie( 'plakCHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_plak").checked			= 1;
			document.getElementById("opt_plak").disabled		= 1;
			document.getElementById("plak_ok").value			= 1;
			document.getElementById("plak_coup_text").innerHTML = "Coupon code is correct.";
			document.getElementById("txt_plak").innerHTML		= "<b>gratis</b>";
			return true;
		} else {
			if( Coupon.value.length >= 1 ) {
				Set_Cookie( 'plakCHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 5 ) {
					document.getElementById("plak_coup").disabled	= 1;
					document.getElementById("plak_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
				}
			}
			return false;
		}
		
	} else {
		document.getElementById("plak_coup").disabled	= 1;
		document.getElementById("plak_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
	}
}

function checkCanvas30CouponCode( Coupon )
{
	var I = Get_Cookie( 'canvas30CHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 6 )
	{
		if( ( Coupon.value.length == 7		)	&&
			( isFinite( Coupon.value )		)	&&
			( ( Coupon.value % 131 ) == 0 )	)	{
			Set_Cookie( 'canvas30CHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_canvas30").checked			= 1;
			document.getElementById("opt_plak").checked		    	= 1;
			document.getElementById("opt_plak").disabled	    	= 1;
			document.getElementById("opt_canvas30").disabled		= 1;
			document.getElementById("canvas30_ok").value			= 1;
			document.getElementById("canvas30_coup_text").innerHTML = "Coupon code is correct.";
			document.getElementById("txt_canvas30").innerHTML		= "€ 35,00";
			return true;
		} else {
			if( Coupon.value.length >= 1 ) {
				Set_Cookie( 'canvas30CHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 6 ) {
					document.getElementById("canvas30_coup").disabled	= 1;
					document.getElementById("canvas30_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
				}
			}
			return false;
		}
		
	} else {
		document.getElementById("canvas30_coup").disabled	= 1;
		document.getElementById("canvas30_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
	}
}

function checkCanvas50CouponCode( Coupon )
{
	var I = Get_Cookie( 'canvas50CHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 7 )
	{
		if( ( Coupon.value.length == 8		)	&&
			( isFinite( Coupon.value )		)	&&
			( ( Coupon.value % 131 ) == 0 )	)	{
			Set_Cookie( 'canvas50CHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_canvas50").checked			= 1;
			document.getElementById("opt_plak").checked		    	= 1;
			document.getElementById("opt_plak").disabled	    	= 1;
			document.getElementById("opt_canvas50").disabled		= 1;
			document.getElementById("canvas50_ok").value			= 1;
			document.getElementById("canvas50_coup_text").innerHTML = "Coupon code is correct.";
			document.getElementById("txt_canvas50").innerHTML		= "€ 45,00";
			return true;
		} else {
			if( Coupon.value.length >= 1 ) {
				Set_Cookie( 'canvas50CHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 7 ) {
					document.getElementById("canvas50_coup").disabled	= 1;
					document.getElementById("canvas50_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
				}
			}
			return false;
		}
		
	} else {
		document.getElementById("canvas50_coup").disabled	= 1;
		document.getElementById("canvas50_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
	}
}

function checkProefCouponCode( Coupon )
{
	var I = Get_Cookie( 'proefCHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 5 )
	{
		if( ( Coupon.value.length == 6		)	&&
			( isFinite( Coupon.value )		)	&&
			( ( Coupon.value % 131 ) == 0 )	)	{
			Set_Cookie( 'proefCHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_proef").checked		= 1;
			document.getElementById("opt_proef").disabled	= 1;
			document.getElementById("proef_ok").value		= 1;
			document.getElementById("proef_coup_text").innerHTML = "Coupon code is correct.";
			document.getElementById("txt_proef").innerHTML	= "<b>gratis</b>";
			return true;
		} else {
			if( Coupon.value.length >= 1 ) {
				Set_Cookie( 'proefCHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 5 ) {
					document.getElementById("proef_coup").disabled	= 1;
					document.getElementById("proef_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
				}
			}
			return false;
		}
	} else {
		document.getElementById("proef_coup").disabled	= 1;
		document.getElementById("proef_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
	}
}

function checkEnvCouponCode( Coupon )
{
	var I = Get_Cookie( 'envCHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 5 )
	{
		if( ( Coupon.value.length == 6		)	&&
			( isFinite( Coupon.value )		)	&&
			( ( Coupon.value % 131 ) == 0 )	)	{
			Set_Cookie( 'envCHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_env").checked		= 1;
			document.getElementById("opt_env").disabled	= 1;
			document.getElementById("env_ok").value		= 1;
			document.getElementById("env_coup_text").innerHTML = "Coupon code is correct.";
			document.getElementById("txt_env").innerHTML	= "<b>gratis</b>";
			return true;
		} else {
			if( Coupon.value.length >= 1 ) {
				Set_Cookie( 'envCHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 5 ) {
					document.getElementById("env_coup").disabled	= 1;
					document.getElementById("env_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
				}
			}
			return false;
		}
	} else {
		document.getElementById("env_coup").disabled	= 1;
		document.getElementById("env_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
	}
}

function checkBeursCouponCode( Coupon )
{
	var I = Get_Cookie( 'couponCHECK' );

	if( I == null ) {
		I = 0;
	} else {
		I = parseInt( I );
	}
	if( I < 5 )
	{
		if( ( Coupon.value.length == 5		)	&&
			( isFinite( Coupon.value )		)	&&
			( Coupon.value == '12838' )	) 	{
			Set_Cookie( 'couponCHECK', 0, 30, '/', '', '' );
			document.getElementById("beurs_coup_text").innerHTML = "Coupon code is correct.";
			alert("U hebt de juiste code ingevoerd,\nvul nu de datum in wanneer jij denkt dat je baby geboren wordt.\nDeze moet minimaal 30 dagen later zijn dan de huidige datum!!");
			return true;
		} else {
			if( Coupon.value.length >= 1 ) {
				Coupon.value	= "";
				I += 1;
				Set_Cookie( 'couponCHECK', I, 30, '/', '', '' );
				alert("Het ingevulde coupon nummer is niet geldig!");
				if( I > 5 ) {
					document.getElementById("beurs_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
					document.getElementById("beurs_coup").disabled	= 1;
					document.getElementById("beurs_date").disabled	= 1;
				}
			}
			return false;
		}
	} else {
		document.getElementById("beurs_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
		document.getElementById("beurs_coup").disabled	= 1;
		document.getElementById("beurs_date").disabled	= 1;
	}
}

function checkBeursBirthDay( BirthDate )
{
	return true;
}
function _setDefaultCouponValues(){
	// default values for plak
	document.getElementById("opt_plak").checked			= 0;
	document.getElementById("opt_plak").disabled		= 0;
	document.getElementById("plak_ok").value			= 0;
	document.getElementById("plak_coup").value			= '';
	document.getElementById("txt_plak").innerHTML		= document.getElementById("default_txt_plak").value;
	// default values for coupon30
	document.getElementById("opt_canvas30").checked			= 0;
	document.getElementById("opt_canvas30").disabled		= 0;
	document.getElementById("canvas30_ok").value			= 0;
	document.getElementById("canvas30_coup").value			= '';
	document.getElementById("txt_canvas30").innerHTML		= document.getElementById("default_txt_canvas30").value;
	// default values for coupon50
	document.getElementById("opt_canvas50").checked			= 0;
	document.getElementById("opt_canvas50").disabled		= 0;
	document.getElementById("canvas50_ok").value			= 0;
	document.getElementById("canvas50_coup").value			= '';
	document.getElementById("txt_canvas50").innerHTML		= document.getElementById("default_txt_canvas50").value;
}

function _checkCouponCode(coupon_name){
	var Coupon = document.getElementById(coupon_name);
	
	
	if (Coupon.value.length > 0) {
		_setDefaultCouponValues();
		if ((Coupon.value.length == 6) &&
		(isFinite(Coupon.value)) &&
		((Coupon.value % 131) == 0)) {
			//Set_Cookie( 'plakCHECK', 0, 30, '/', '', '' );
			document.getElementById("opt_plak").checked = 1;
			document.getElementById("opt_plak").disabled = 1;
			document.getElementById("plak_ok").value = 1;
			document.getElementById("plak_coup").value = Coupon.value;
			document.getElementById("coup_code_text").innerHTML = "Gratis felicitatieboek.";
			//document.getElementById("coup_code_text").innerHTML = "Coupon code is correct.";
			
			document.getElementById("txt_plak").innerHTML = "<b>gratis</b>";
			return true;
		}
		else 
			if ((Coupon.value.length == 6) &&
			(isFinite(Coupon.value)) &&
			(Coupon.value == 260903)) {
				//Set_Cookie( 'canvas30CHECK', 0, 30, '/', '', '' );
				document.getElementById("opt_canvas30").checked = 1;
				document.getElementById("opt_plak").checked = 1;
				document.getElementById("opt_plak").disabled = 1;
				document.getElementById("opt_canvas30").disabled = 1;
				document.getElementById("canvas30_ok").value = 1;
				document.getElementById("canvas30_coup").value = Coupon.value;
				document.getElementById("coup_code_text").innerHTML = "Gratis felicitatieboek + 25% korting op canvasdoek 30 x 30 cm.";
				document.getElementById("txt_canvas30").innerHTML = "<b>25% korting</b>";
				//document.getElementById("txt_plak").innerHTML		= "<b>gratis</b>";
				return true;
			}
			else 
				if ((Coupon.value.length == 6) &&
				(isFinite(Coupon.value)) &&
				(Coupon.value == 120506)) {
					//Set_Cookie( 'canvas50CHECK', 0, 30, '/', '', '' );
					document.getElementById("opt_canvas50").checked = 1;
					document.getElementById("opt_plak").checked = 1;
					document.getElementById("opt_plak").disabled = 1;
					document.getElementById("opt_canvas50").disabled = 1;
					document.getElementById("canvas50_ok").value = 1;
					document.getElementById("canvas50_coup").value = Coupon.value;
					document.getElementById("coup_code_text").innerHTML = "Gratis felicitatieboek + 25% korting op canvasdoek 50 x 50 cm.";
					document.getElementById("txt_canvas50").innerHTML = "<b>25% korting</b>";
					//document.getElementById("txt_plak").innerHTML		= "<b>gratis</b>";
					return true;
				}
				else {
					if (Coupon.value.length >= 1) {
						//Set_Cookie( 'plakCHECK', I, 30, '/', '', '' );
						alert("Het ingevulde coupon nummer is niet geldig!");
						_setDefaultCouponValues();
					//			if( I > 5 ) {
					//				document.getElementById("plak_coup").disabled	= 1;
					//				document.getElementById("plak_coup_text").innerHTML = "Te veel foutieve codes ingevoerd.";
					//			}
					}
					return false;
				}
	}
}
