//Mijn locatie: Postcode opzoeken in postcode tabel
function setcookie (name, value) {
 var expDays = 30;
 var exp = new Date(); 
 exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
 expirationDate = exp.toGMTString();
 document.cookie = name + "=" + escape(value)
 document.cookie += "; expires=" + expirationDate
 document.cookie += "; path=/";

}

function delete_mijnlocatie (name, value) {
 var expDays = -1;
 var exp = new Date(); 
 exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
 expirationDate = exp.toGMTString();
 document.cookie = name + "=" + escape(value)
 document.cookie += "; expires=" + expirationDate
 document.cookie += "; path=/";

 window.location.reload();  
}

function mijn_locatie() {
 if (parent.document.getElementById('input_postcode').value!='bv. 5236HD') {
  postcode=document.getElementById('input_postcode').value;
  setcookie('postcode',postcode);

  get_postcode(postcode);
 }
}

function get_postcode(postcode){
 var xmlHttp = getHTTPObject(); 
 xmlHttp.onreadystatechange = function() {
  if(xmlHttp.readyState == 4){ 
   parent.document.getElementById("plaats1").value=xmlHttp.responseText;
   addAddresses();
  }
 }	 
 xmlHttp.open("GET", "/backsite_get_postcode.php?postcode=" + postcode + "", true);
 xmlHttp.send(null);
}

//Zoekopdracht verwerken
function zoeken_balk() {
 if (parent.document.getElementById('searchitem_frame').value=='Wie of waar...') {
  document.getElementById('searchitem_frame').value='';
 }
 window.open('/zoekresultaten.php?query=' + document.getElementById('searchitem_frame').value + '&pagina=1', '_self');
}

//Kalender
function viewcalendar(datum) {
  kalendarik = window.open('../calendar_main.php?modify_time=12&insertdatum=' + datum + '', "kalendarik" , "location=0, menubar=0, scrollbars=0, status=0, titlebar=0, toolbar=0, directories=0, resizable=1, width=200, height=240, top=50, left=250");
  kalendarik.resizeTo(160, 240);
  kalendarik.moveTo(250, 50);
}

function insertbegindatum(d) {
  window.close();
  window.opener.document.getElementById('begindatum').value = d;
}

function inserteinddatum(d) {
  window.close();
  window.opener.document.getElementById('einddatum').value = d;
}

//Beoordelingen
function rank(type,ster) {
  document.getElementById('rank_' + type + '_1').src='/images/ster_active.gif';
  document.getElementById('rank_' + type + '_2').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_3').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_4').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_5').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_6').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_7').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_8').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_9').src='/images/ster_inactive.gif';
  document.getElementById('rank_' + type + '_10').src='/images/ster_inactive.gif';

  var i=0;
  for (i=1;i<=ster;i++) {
    document.getElementById('rank_' + type + '_' + i + '').src='/images/ster_active.gif';
    document.getElementById('reactie_beoordeling_' + type + '').value=i;
  }

  //x001
  n_eten=document.getElementById('reactie_beoordeling_eten').value*1;
  n_bediening=document.getElementById('reactie_beoordeling_bediening').value*1;
  n_ambiance=document.getElementById('reactie_beoordeling_ambiance').value*1;
  n_prijs=document.getElementById('reactie_beoordeling_prijs').value*1;

  n_totaal=n_eten+n_bediening+n_ambiance+n_prijs;
  n_score=n_totaal/4;
  document.getElementById('reactie_beoordeling_x001').value=Math.round(n_score);

  //x002
  n_algemeen=document.getElementById('reactie_beoordeling_algemeen').value*1;
  n_service=document.getElementById('reactie_beoordeling_service').value*1;
  n_prijs=document.getElementById('reactie_beoordeling_prijs').value*1;

  n_totaal=n_algemeen+n_service+n_prijs;
  n_score=n_totaal/3;
  document.getElementById('reactie_beoordeling_x002').value=Math.round(n_score);

  //x005
  n_service=document.getElementById('reactie_beoordeling_service').value*1;
  n_comfort=document.getElementById('reactie_beoordeling_comfort').value*1;
  n_locatie=document.getElementById('reactie_beoordeling_locatie').value*1;
  n_faciliteiten=document.getElementById('reactie_beoordeling_faciliteiten').value*1;

  n_totaal=n_service+n_comfort+n_locatie+n_faciliteiten;
  n_score=n_totaal/4;
  document.getElementById('reactie_beoordeling_x005').value=Math.round(n_score);
}

//Suggesties
function show_popup(item, item2) {
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (parent.document.body.scrollHeight > parent.document.body.offsetHeight){ // all but Explorer Mac
			xScroll = parent.document.body.scrollWidth;
			yScroll = parent.document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = parent.document.body.offsetWidth;
			yScroll = parent.document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(parent.document.documentElement.clientWidth){
				windowWidth = parent.document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (parent.document.documentElement && parent.document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = parent.document.documentElement.clientWidth;
			windowHeight = parent.document.documentElement.clientHeight;
		} else if (parent.document.body) { // other Explorers
			windowWidth = parent.document.body.clientWidth;
			windowHeight = parent.document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		posx = parent.document.body.scrollLeft + parent.document.documentElement.scrollLeft;
		posy = parent.document.body.scrollTop + parent.document.documentElement.scrollTop	+ 100;
		
  parent.document.getElementById('popup_bg').style.display='';
  parent.document.getElementById('popup_bg').style.left='0px';
  parent.document.getElementById('popup_bg').style.top='0px';
  parent.document.getElementById('popup_bg').style.width=pageWidth+'px';
  parent.document.getElementById('popup_bg').style.height=pageHeight+'px';
  parent.document.getElementById('popup_bg').style.opacity='0.6';
  parent.document.getElementById('popup_bg').style.filter='alpha(opacity=60)';

  parent.document.getElementById('popup').style.display='';
  parent.document.getElementById('popup').style.left=((pageWidth/2)-330)+'px';

  //parent.document.getElementById('popup').style.top='50px';
  parent.document.getElementById('popup').style.top=posy+'px';

  parent.document.getElementById('popup').style.width=660+'px';
  parent.document.getElementById('popup').style.height=500+'px';

  //parent.document.getElementById('popup').style.position='fixed';

  if (item=="popup_map") { parent.document.getElementById('popup_frame').src='/popup_map_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_map_evenement") { parent.document.getElementById('popup_frame').src='/popup_map_evenement_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_addtofav") { parent.document.getElementById('popup_frame').src='/popup_addtofav_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_review") { parent.document.getElementById('popup_frame').src='/popup_review_frame.php'; }
  if (item=="popup_suggestie") { parent.document.getElementById('popup_frame').src='/popup_suggestie_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_avondplanner") { parent.document.getElementById('popup_frame').src='/popup_avondplanner_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_tellafriend") { parent.document.getElementById('popup_frame').src='/popup_tellafriend_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_avondplanner_mail") { parent.document.getElementById('popup_frame').src='/popup_avondplanner_mail_frame.php?popup_id=' + item2 + ''; }
  if (item=="popup_login") { parent.document.getElementById('popup_frame').src='/popup_login_frame.php'; }
}

function hide_popup(item){
 parent.document.getElementById('popup_bg').style.display='none';
 parent.document.getElementById('popup').style.display='none';
 parent.document.getElementById('popup_frame').src='/popup_default_frame.php';
}

//Nieuwsbrief
function echeck(str) {
 var at="@"
 var dot="."
 var lat=str.indexOf(at)
 var lstr=str.length
 var ldot=str.indexOf(dot)
 
 if (str.indexOf(at)==-1){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }

 if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }

 if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }

 if (str.indexOf(at,(lat+1))!=-1){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }

 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }

 if (str.indexOf(dot,(lat+2))==-1){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }
		
 if (str.indexOf(" ")!=-1){
  alert("Er is een ongeldig emailadres ingegeven")
  return false
 }

 set_nieuwsbrief(str);
 parent.document.getElementById('nieuwsbrief0').style.display='none';
 parent.document.getElementById('nieuwsbrief1').style.display='';
 					
}


function snel_zoeken() {
 var plaats;
 var categorie;
 
 plaats=document.getElementById('snelzoek_plaats').value
 categorie=document.getElementById('snelzoek_categorie').value
 
 window.open('/zoekresultaten.php?plaats='+plaats+'&soort='+categorie+'','_self');
}

//LATLNG
var map=null ;
var geocoder=null;
var addr_arr,geo_arr;
var count;
	
function initialise() {
 if (GBrowserIsCompatible()) {
  count=0;
  addr_arr=new Array();
  geo_arr= new Array();
 }
}

function addAddresses(){
 initialise();
 addr_arr[0]=document.getElementById('input_postcode').value + ',' + document.getElementById('plaats1').value;
 geocoder = new GClientGeocoder();

 for (var i=0;i<addr_arr.length;i++){
  geocoder.getLatLng(addr_arr[i], addToMap);  
 }
}
 
function addToMap(response){
 var latlng;
 latlng = response// 
 if(response==null){
  //alert("Bad adress");
 }
 else{
  traceLine(latlng);
 }
}
 
function traceLine(item){
 var myString = '' + item + '';
 var myString = myString.replace("(","");
 var myString = myString.replace(")","");
 var mySplitResult = myString.split(", ");

 for(i = 0; i < mySplitResult.length; i++){
  document.getElementById("latlng" + i).value = mySplitResult[i]; 
 }
 postcode_lat=document.getElementById('latlng0').value;
 postcode_lng=document.getElementById('latlng1').value;
 setcookie('postcode_lat',postcode_lat);
 setcookie('postcode_lng',postcode_lng);

 window.location.reload();  
}
 
 
