 $(document).ready(function() { 

	$("#belform").css("display","none");

	
    var options = { 
        target:        '#notebelmij',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest,  // pre-submit callback 
        success: ajaxSuccess,
        resetForm: true        // reset the form after successful submit 
    }; 
    
	$('#belmij').submit(function() { 
        $(this).ajaxSubmit(options); 
        return false; 
    }); 
    
    
    $('#zoekButt').click(function() {
	
		var searchVal = $('#searchgoo').val();

        $('#q').val(searchVal)
		$('#cse-search-box').submit();
               
    });
    
 	
 	$('#searchgoo').bind('keyup', function(e) {
	
	if(e.keyCode==13){
		
		var searchVal = $('#searchgoo').val();

        $('#q').val(searchVal)
		$('#cse-search-box').submit();
               
    }});
    
    
    var optionsVal = { 
        target:        '#columnSecond',   // target element(s) to be updated with server response 
        beforeSubmit:  showRequest2,  // pre-submit callback 
        success:       showResponse,
        resetForm: true        // reset the form after successful submit 
    }; 
    $('#codeval').submit(function() { 
        $(this).ajaxSubmit(optionsVal); 
        return false; 
    }); 
 	
 	
}); 

// pre-submit callback 
function showRequest2(formData, jqForm, options) { 
	return true;
}

function ajaxSuccess(){
	$('#belmij').show();
	$('#progress').hide();
	
	$("#submitbutton").hide();
        
    $("#notebelmij").fadeOut(5000);
    
	var t=setTimeout("afterSubmit()",6500);
} 
// pre-submit callback 
function showRequest(formData, jqForm, options) { 
	if( trim($('#formname').attr("value")) == "")
	{
		alert('Alle velden zijn verplicht.');
		$('#formname').focus();
		return false;
	}
	
    if( trim($('#formemail').attr("value")) == "")
	{
		alert('Alle velden zijn verplicht.');
		$('#formemail').focus();
		return false;
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    if(reg.test(trim($('#formemail').attr("value"))) == false) 
	{
		alert('Ongeldig emailadres.');
		return false;
	} 
	
    if( trim($('#formphone').attr("value")) == "")
	{
		alert('Alle velden zijn verplicht.');
		$('#formphone').focus();
		return false;
	}
	
    if( trim($('#discount').attr("value")) == "")
	{
		alert('Alle velden zijn verplicht.');
		$('#discount').focus();
		return false;
	}
	
	$('#belmij').hide();
	$('#progress').show();
    return true; 
} 

/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function afterSubmit()
{
	var htmlNote = "Bedankt voor je aanmelding.<br />Centrum Het hof neemt binnen 3 werkdagen contact met je op voor een afspraak.<br />Tevens ontvang je een bevestiging per e-mail.<br /><br />Klik <a style='color:#FFFFFF;' href='http://www.centrumhethof.nl/default/frontpage'>hier</a> als je terug wilt naar de homepage.";
	
	$('#columnSecond').html(htmlNote);
	$('#belform').hide();
}

function showResponse(responseText, statusText)  { 
	
	var resp = $("#columnSecond").html();
	
	  if(resp.length == 5 || resp.length == 4)
	   {
		   $("#columnSecond").css("background-image","url(/sys/themes/public/centrumhethof/centrumhethof_theme/img/new/valentine_trans2.png)");
		   $("#columnSecond").css("background-repeat","no-repeat");
		   $("#columnSecond").css("padding","20px");
		   $("#columnSecond").css("width","350px");
		   $("#columnSecond").html("De code is onjuist. Nogmaals proberen? Ga terug naar de <a style='color:#fff' href='http://www.centrumhethof.nl/default/valentine'>Valentijnsactie</a> en zie wat jij en je hartendief hebben gewonnen.  Klik <a style='color:#fff' href='http://www.centrumhethof.nl/default/frontpage'>hier</a> als je terug wilt naar de homepage.");
       	  
	   }
	   else
	   {
			
	   		$("#columnSecond").css("background-image","url(/sys/themes/public/centrumhethof/centrumhethof_theme/img/new/valentine_trans2.png)");
		    $("#columnSecond").css("background-repeat","no-repeat");
		    $("#columnSecond").css("padding","5px");
		    $("#columnSecond").css("width","380px");
		    $("#columnSecond").css("font-size","9px");
		    
		    var htmlVal = "<table style='text-align:left;font-size:10px;line-height:12px;'><tr><td width='30%'>Spiritueel Therapie</td><td width='70%'>- sessie 50% korting:  van €40,00  voor €20,00</td></tr><tr><td width='30%'>NES-Gezondheidsscan</td><td width='70%'>- intake-scan 30% korting: van €75 ,00 voor €52,50<br />- 2e, 3e, 4e vervolg-scan 10% korting: van €50,00 voor e 45,00</td></tr><tr><td width='30%'>Voedingsscan</td><td width='70%'>- 1e scan 30% korting: van €150,00 voor €105,00<br />- 2e consult 10% korting: van €65,00 voor €58,50</td></tr><tr><td width='30%'>Yoga</td><td width='70%'>- 1e les GRATIS<br />-  maand lang (4 lessen) 2 personen voor de prijs van 1:<br />van €79,00  voor  €39,50  (e19,95 p.p.)</td></tr><tr><td width='30%'>Quantum Touch</td><td width='70%'>-  behandeling 20% korting: van €60,00 voor €48,00<br />- partner 40%: van €60,00 voor €36,00</td></tr><tr>		<td width='30%'>Souldance</td>		<td width='70%'>- cursus 10 lessen 15% korting: van €115,00 voor €98,00<br />- partner 25%: van €115,00 voor €86,00</td></tr><tr>	<td width='30%'>Guasha</td>	<td width='70%'>- behandeling 15% korting: van €60,00 voor  €51,00<br />- partner 25%: van €60,00  voor €45,00 </td></tr><tr><td width='30%'>Intuitieve Ontwikkeling</td><td width='70%'>- cursus 7 lessen 10% korting: van €140,00  voor €126,00 </td>	</tr><tr><td width='30%'>Ayurvedische Massage</td>	<td width='70%'>- massage 11% korting: van €70,00 voor €62,00</td></tr>	</table>"; 
		    
		    
		  
		    $("#columnSecond").html(htmlVal);

		    
       		$("#belform").slideDown("slow");
       		$("#token").val(responseText);
		
	   }
       
   
} 