function getResultsSimple(start,q) {
	document.getElementById('catcontent').style.display = 'none';
	document.getElementById('searchresults').style.display = 'block';

		if(!q) {
            var qstring = $('#q')[0].value;
        } else {
            var qstring = q;
        }
        
        var aantal = 12;


	if(qstring != '') {
		targetDiv = $('#results');
		targetDiv[0].innerHTML = '<div id="loading"></div>';
		
		$.get("simplesearch.php",{ 
		      q: qstring, 
		      start: start, 
		      aantal: aantal 
		    }, function(result) { 
		   		targetDiv.hide();
		  		targetDiv[0].innerHTML = result;
		  		targetDiv.fadeIn('fast');
		  		//alert(document.getElementById('aantalresultaten').value);
		  		getPaging($('#aantalresultaten')[0].value, start, 'simple');
		});

	}
}

//#### FOR OVERVIEW PAGE PAGING 
function getResultsOverview(start,q) {

		if(!q) {
            var qstring = $('#q')[0].value;
        } else {
            var qstring = q;
        }
        
        var aantal = 5;

	if(qstring != '') {
		targetDiv = $('#results_overview');
		targetDiv[0].innerHTML = '<div id="loading"></div>';
		
		$.get("/overview.php",{ 
		      q: qstring, 
		      start: start, 
		      aantal: aantal 
		    }, function(result) { 
		   		targetDiv.hide();
		  		targetDiv[0].innerHTML = result;
		  		targetDiv.fadeIn('fast');
		  		//alert(document.getElementById('aantalresultaten').value);
		  		getPaging($('#aantalresultaten')[0].value, start, 'overview');					
				
				sIFR.replaceElement(named({sSelector:".overviewimage .title h2", sFlashSrc:"swf/sifr.swf", sColor: "#ffffff", sFlashVars: "textalign=left", sWmode: "transparent"}));
				sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"swf/sifr.swf", sColor: "#ffffff", sFlashVars: "textalign=left", sWmode: "transparent"}));
		});

	}
}

function closeCategoryPicker() {
	targetDiv = $('#categorypicker');
	targetDiv.fadeOut('fast');
}

function setResultsAdvanced(type, value) {
	targetDiv = $('#categorypicker');
	targetDiv.fadeOut('fast');
	
	if(type != '') {
		switch(type) {
			case 1:
				$("#provincie").selectOptions(value);
				break;
				
			case 6:
				$("#bouwperiode").selectOptions(value);
				break;
				
			case 2:
				$("#architect").selectOptions(value);
				break;
				
			case 3:
				$("#bouwstijl").selectOptions(value);
				break;
				
			case 7:
				$("#gebouwtype").selectOptions(value);
				break;																
		}
		
		//switchSearch('#search_advanced','#search');
		getResultsAdvanced(1);
	}
}

function getResultsAdvanced(start,q,plaats,provincie,bouwperiode,eigendom_sinds,restauratieperiode,architect,bouwstijl,gebouwtype) {
	document.getElementById('catcontent').style.display = 'none';
	document.getElementById('searchresults').style.display = 'block';
		
	
		if($('#plaats')[0].value==undefined)
			var plaats = $('#plaats')[0].value;

        if(!plaats) {
             plaats = $('#plaats')[0].value;
			
        }
        if(!provincie) {
            var provincie = $('#provincie option:selected').text();
        }
        if(!bouwperiode) {
            var bouwperiode = $('#bouwperiode option:selected').text();
        }
        if(!eigendom_sinds) {
            var eigendom_sinds = $('#eigendom_sinds option:selected').text();
        }
        if(!restauratieperiode) {
            var restauratieperiode = $('#restauratieperiode option:selected').text();
        }
        if(!architect) {
            var architect = $('#architect option:selected').text();
        }
        if(!bouwstijl) {
            var bouwstijl = $('#bouwstijl option:selected').text();
        }
        if(!gebouwtype) {
            var gebouwtype = $('#gebouwtype option:selected').text();
        }
        
	var aantal = 12;
	
	targetDiv = $('#results');
	targetDiv[0].innerHTML = '<div id="loading"></div>';
	
	plaats = (plaats == '(Voer een woonplaats in)') ? '' : plaats;
	provincie = (provincie == 'Maak uw keuze') ? '' : provincie;
	bouwperiode = (bouwperiode == 'Maak uw keuze') ? '' : bouwperiode;
	eigendom_sinds = (eigendom_sinds == 'Maak uw keuze') ? '' : eigendom_sinds;
	restauratieperiode = (restauratieperiode == 'Maak uw keuze') ? '' : restauratieperiode;
	architect = (architect == 'Maak uw keuze') ? '' : architect;
	bouwstijl = (bouwstijl == 'Maak uw keuze') ? '' : bouwstijl;
	gebouwtype = (gebouwtype == 'Maak uw keuze') ? '' : gebouwtype;

        if(!q) {
            var qstring = $('#q_adv')[0].value;
        } else {
            var qstring = q;
        }

        
	$.get("advancedsearch.php",{ 
	      q_adv: qstring,
	      plaats: plaats,
	      provincie: provincie,
	      bouwperiode: bouwperiode,
	      eigendom_sinds: eigendom_sinds,
	      restauratieperiode: restauratieperiode,
	      architect: architect,
	      bouwstijl: bouwstijl,	   
	      gebouwtype: gebouwtype,
	      start: start, 
	      aantal: aantal 
	    }, function(result) { 
	   		targetDiv[0].innerHTML = '';
	  		targetDiv[0].innerHTML = result;
	  		targetDiv.fadeIn('fast');
	  		getPaging($('#aantalresultaten')[0].value, start, 'advanced');
	});
}

function getPaging(aantal, start, type) {
	//alert(aantal);

	targetDiv = $('#paging');
	
	$.get("/getpaging.php",{ 
	      start: start, 
	      aantal: aantal,
	      type: type 
	    }, function(result) { 
	   		targetDiv.hide();
	  		targetDiv[0].innerHTML = result;
	  		targetDiv.fadeIn('fast');
	});	
}

function getPagingByType(aantal, start) {
	//alert(aantal);

	targetDiv = $('#paging');
	
	$.get("getpagingbytype.php",{ 
	      start: start, 
	      aantal: aantal 
	    }, function(result) { 
	   		targetDiv.hide();
	  		targetDiv[0].innerHTML = result;
	  		targetDiv.fadeIn('fast');
	});	
}

/********************** start functies voor agenda *********************/
function checkDate() {
	if($('#dag').selectedValues() == '' || $('#maand').selectedValues() == '' || $('#jaar').selectedValues() == '') {
		//zoekopdracht nog niet uitvoeren
	} else {
		getEvenementen();
	}
}

function getEvenementen() {
	var qstring = $('#q')[0].value;
	var plaats = $('#plaats option:selected').text();
	var provincie = $('#provincie option:selected').text();
	var soort = $('#soort option:selected').text();
	
	if($('#dag').selectedValues() == '' || $('#maand').selectedValues() == '' || $('#jaar').selectedValues() == '') {
		var datum = '';
	} else {
		var datum = $('#jaar').selectedValues()+'-'+$('#maand').selectedValues()+'-'+$('#dag').selectedValues();
	}
	
	if(qstring == '' && plaats == '' && provincie == '' && soort == '' && datum == '') {
		//er is geen keuze gemaakt, dan geen zoekopdracht uitvoeren.
	} else {	
	
		targetDiv = $('#agenda');
		targetDiv[0].innerHTML = '<div id="loading_agenda"></div>';
		
		plaats = (plaats == 'Maak uw keuze') ? '' : plaats;
		provincie = (provincie == 'Maak uw keuze') ? '' : provincie;
		soort = (soort == 'Maak uw keuze') ? '' : soort;
		datum = (datum == 'Maak uw keuze') ? '' : datum;
	
		$.get("searchevents.php",{ 
			  q: qstring,
		      plaats: plaats,
		      provincie: provincie,
		      soort: soort,
		      datum: datum 
		    }, function(result) { 
		   		targetDiv[0].innerHTML = '';
		  		targetDiv[0].innerHTML = result;
		  		targetDiv.fadeIn('fast');
		});
	}		
}
/********************** einde functies voor agenda *********************/

function switchSearch(on,off) {
	$(off)[0].style.display = 'none';
	$(on)[0].style.display = 'block';
}

/* example in textfield */
(function(A){A.fn.example=function(D,C){var B=A.extend({},A.fn.example.defaults,C);var E=A.isFunction(D);if(!A.fn.example.bound_class_names[B.class_name]){A(window).unload(function(){A("."+B.class_name).val("")});A("form").submit(function(){A(this).find("."+B.class_name).val("")});A.fn.example.bound_class_names[B.class_name]=true}return this.each(function(){var G=A(this);if(A.browser.msie&&!G.attr("defaultValue")&&(E?G.val()!="":G.val()==D)){G.val("")}if(G.val()==""){G.addClass(B.class_name);G.val(E?D.call(this):D)}if(B.hide_label){var F=A("label[@for="+G.attr("id")+"]");F.next("br").hide();F.hide()}G.focus(function(){if(A(this).is("."+B.class_name)){A(this).val("");A(this).removeClass(B.class_name)}});G.blur(function(){if(A(this).val()==""){A(this).addClass(B.class_name);A(this).val(E?D.call(this):D)}})})};A.fn.example.defaults={class_name:"example",hide_label:false};A.fn.example.bound_class_names=[]})(jQuery);
 




 // Email validation
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function is_email(email)
 {
	 if(isEmailAddr(email))
		 return true;
	 else
		 return false;
	  //if(!email.match(/^[A-Za-z0-9\._\-+]+@[A-Za-z0-9_\-+]+(\.[A-Za-z0-9_\-+]+)+$/)) 
		//   return false;

	  //return true;
 }

// End blank validation
//==========================================================
// used for blank testing
function trim(inputString) 
 {
    if (typeof inputString != "string") { return inputString; }
    var retValue = inputString;
    var ch = retValue.substring (0, 1);
    while (ch == " ") { 
    retValue = retValue.substring(1, retValue.length);
    ch = retValue.substring(0, 1);
    }
    ch = retValue.substring (retValue.length-1, retValue.length);
    while (ch == " ") { 
    retValue = retValue.substring(0, retValue.length-1);
    ch = retValue.substring(retValue.length-1 , retValue.length);
    }
    while (retValue.indexOf("  ") != -1) { 
    retValue = retValue.substring(0, retValue.indexOf ("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
    }
    return retValue; 
 } 
 // End for blank testing
