var g_domain = 'nieuws.nl';

//om vensters uit externe banners uit te zetten
//function alert(s) { };

function nieuwsnl_openwindow(theURL, winName, features) 
 { 
  window.open(theURL, winName, features);
 }

function print_bericht(id)
 {
  nieuwsnl_openwindow('http://www.' + g_domain + '/' + id + '/--print--', 'lpt', 'width=500,height=500,scrollbars=0');
 } 
 
function print_advertorial(id)
 {
  nieuwsnl_openwindow('http://advertorial.' + g_domain + '/' + id + '/--print--', 'lpt', 'width=500,height=500,scrollbars=0');
 } 

function print_bericht_geknipt(id)
 {
  nieuwsnl_openwindow('http://geknipt.' + g_domain + '/' + id + '/--print--', 'lpt', 'width=500,height=500,scrollbars=0');
 } 
 
function print_lokaal_bericht(id, city_code)
 {
  nieuwsnl_openwindow('http://' + city_code + '.' + g_domain + '/' + id + '/--print--', 'lpt', 'width=500,height=500,scrollbars=0');
 } 
 
function print_lokaal_vacature(id, city_code)
 {
  nieuwsnl_openwindow('http://' + city_code + '.' + g_domain + '/vacatures/' + id + '/--print--', 'lpt', 'width=500,height=500,scrollbars=0');
 }  

function print_column(id)
 {
  nieuwsnl_openwindow('http://www.' + g_domain + '/Erik_de_Vlieger/'+ id + '/--print--', 'lpt', 'width=500,height=500,scrollbars=0');
 } 
 
function nieuwspoll()
 {
  nieuwsnl_openwindow('http://www.' + g_domain +  '/nieuwspoll', 'nieuwspoll','width=180,height=300,scrollbars=0');
 } 

function addcomment(id_column)
 {
  nieuwsnl_openwindow('http://www.' + g_domain + '/addcomment/'+ id_column,'Column','width=500,height=300,scrollbars=0');
 } 
 
function playvideo(video) 
 {
  LeftPosition = (screen.width) ? (screen.width-665)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-430)/2 : 0;
  popwin = window.open('http://videos.' + g_domain + '/playvideo/' + video,'MTV6_window','toolbar=no,width=665,height=430,top='+TopPosition+',left='+LeftPosition+',directories=no,status=no,scrollbars=yes,resizable=no,menubar=no');
  popwin.focus();
 }       

function banner_clicked_readystatechange()
 {
  if (http_request.readyState == 4)
   {
    if (http_request.status == 200)
     {
      s = http_request.responseText;
      //alert(s);
     }
   }
 }

function banner_clicked(id)
 {
  if (window.XMLHttpRequest)
   {
    http_request = new XMLHttpRequest();
   }
  else if (window.ActiveXObject)
   {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
   }

  http_request.onreadystatechange = banner_clicked_readystatechange;
  url = 'http://www.' + g_domain + '/banner_clicked/' + id;
  http_request.open('GET', url);
  http_request.send(null);
 }
 
function regionieuws_msg_not_ok(id)
 {
  if (confirm('Melding versturen ?') == false)
   {
    return;
   } 
   
  var f = document.createElement('form');
  f.method = 'post';
  f.style.display = 'none';
  
  input = document.createElement('input');
  input.name = 'action';
  input.value = 'regionieuws_msg_not_ok';   
  f.appendChild(input);
  
  input = document.createElement('input');
  input.name = 'id';
  input.value = id; 
  f.appendChild(input);  
  
  el = document.getElementsByTagName('body')[0];
  el.appendChild(f);
  f.submit();    
 }
 
function meld(id)
 {
  regionieuws_msg_not_ok(id);
 }

function search_all(category)
 {
  document.f.category.value = category;
  document.f.submit();
 }

function get_province_name(code)
 { 
  if (code == "DR") { return "drenthe"; }
  if (code == "FL") { return "flevoland"; }  
  if (code == "FR") { return "friesland"; }  
  if (code == "GE") { return "gelderland"; }         
  if (code == "GR") { return "groningen"; }
  if (code == "LI") { return "limburg"; }
  if (code == "NH") { return "noord-holland"; }               
  if (code == "NB") { return "noord-brabant"; } 
  if (code == "OV") { return "overijssel"; }
  if (code == "UT") { return "utrecht"; }              
  if (code == "ZE") { return "zeeland"; }       
  if (code == "ZH") { return "zuid-holland"; }  
 }
       
function select_regio(nr)
 {
  if (nr == null) { nr = 1; }    
  s = document.forms[0].regio.value;  
  if (nr == 2) { s = document.regioselect2.regio.value;}
  
  if (s == '') { el.innerHTML = ''; return;}
  s = s.toLowerCase();
 
  for (i=0; i < regio_data.length;  i++)
   {
    v = regio_data[i].split(':');
    s2 = v[0];
    s2 = s2.toLowerCase(); 
    if (s == s2)
     {
      s2 = s2.replace(' ', '_');        
      s2 = s2.replace('\/', '');           
      document.location.href = 'http://' + s2 + '.' + g_domain;
     }
   }
 }      
       
function regio_onfocus()
 {
  if (document.forms[0].regio.value =='Plaatsnaam...')
   {
    document.forms[0].regio.value = '';
   }
  el = document.getElementById('lokaal');
  el.style.height = 167;
 }
 
function regio_onblur()
 {
  document.forms[0].regio.value =='Plaatsnaam...';
  el = document.getElementById('lokaal');
  el.style.height = 63;
 }  
      
function is_email_valid(str) 
 {
  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);
  if (str.indexOf(at)==-1) { return false; }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
  if (str.indexOf(at,(lat+1))!=-1){ return false; }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
  if (str.indexOf(dot,(lat+2))==-1){ return false; }
  if (str.indexOf(" ")!=-1){ return false; }
  return true;   
 }
 

function setCookie(name, value, nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays == null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000 * 24 * nDays);
 document.cookie = name + "=" + escape(value) + ";expires=" + expire.toGMTString()+ ";domain=nieuws.nl;path=/";
}
 
function getCookie(name) 
{	
 var start = document.cookie.indexOf( name + "=" );	
 var len = start + name.length + 1;	
 if (( !start ) && ( name != document.cookie.substring( 0, name.length ))) 
  {
  	return null;	
  }	
 if ( start == -1 ) return null;	
 var end = document.cookie.indexOf( ';', len );	
 if ( end == -1 ) end = document.cookie.length;	
 return unescape( document.cookie.substring( len, end ) );
}

function store_showhide_data()
 {
  var data = '';
  for (var i=0; i<categories.length; i++) 
   { 
    if (document.getElementById('frontpage_subheadline_' + categories[i]).style.display == 'none')
     {	
     	if (data != '') { data += ',' }
 	   data += '"' + categories[i] + '"';
     }          
   }	

  setCookie('frontpage.hc', data, 365 * 5);
 } 

function showhide(category) 
 {
  var id = 'frontpage_subheadline_' + category;
  var el = document.getElementById(id);
  if (!el) { return; }
  
  img = document.images['frontpage_image_' + category];

  if ((el.style.display == '') || (el.style.display == 'block'))  
  { 
   el.style.display = 'none';
   img.src = './img/expand.gif';
  }
  else
  {
   el.style.display = 'block'; 
   img.src = './img/collapse.gif';
  }
  
  store_showhide_data();
 }

categories = ['economie','sport','muziek','film','opmerkelijk','boulevard','auto','geknipt'];
 
function set_showhide_data()
 {
  data = getCookie('frontpage.hc');
  if ((data == null) || (data == 'undefined')) { return; }

  eval('var hidden_categories = [' + data + ']');
      
  for (var i=0; i<hidden_categories.length; i++)  
   { 
    //var el = document.getElementById('frontpage_subheadline_' + hidden_categories[i]);	
    //if (!el) { continue; } 
  	 //el.style.display = 'none';
  	 showhide(hidden_categories[i]);
   }	
 }  