function _pcz_readystatechange() 
 { 
  if (pcz_http_request.readyState == 4) 
   { 
    if (pcz_http_request.status == 200) 
     { 
      s = pcz_http_request.responseText;
      //document.write(s); return;
      try
       {
        eval('var response=' + s);
       }
      catch(e)
       {  
        pcz_handle_error('Fout in respons\n\n' + pcz_http_request.responseText, 'pcz_action', 14);
        //document.write(pcz_http_request.responseText);
        return;
       } 
           
      if (response == undefined)
       {
        pcz_handle_error('Fout in respons\n\n' + s, 'pcz_action', 20);
        return;
       }
      
      if (response["result"] != '1')
       {
        pcz_handle_error('Fout in resultaat\n\n' + s, 'pcz_action', 26);
        return;
       }
       
      action = response["action"]; 
      if ((action == 'addcomment') || (action == 'vote')) 
       {
//=== compleet infoblock vervangen          
        el = document.getElementById('pcz_moviebox_panel');
        //alert(response["params"]["html"]);
        el.innerHTML = response["params"]["html"];
        if (action == 'addcomment') { pcz_showtab('comments'); }
        if (action == 'vote') { pcz_showtab('info'); }        
       }
       
      if (action == 'mailtofriend') 
       {
        el = document.getElementById('pcz_tabsheet_mailtofriend_form');
        el.style.display = 'none';
        el = document.getElementById('pcz_tabsheet_mailtofriend_message');
        el.style.display = 'block';
        el.innerHTML = response["params"]["html"]; 
       }
     }
    else 
     { 
      pcz_handle_error('Fout in request\n\n' + pcz_http_request.status, 'pcz_action', 35);
     } 
   } 
  } 
      
function pcz_post_request(s)
 { 
  if (window.XMLHttpRequest) 
   {  
    pcz_http_request = new XMLHttpRequest(); 
   } 
  else if (window.ActiveXObject) 
   { 
    pcz_http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
   } 
        
  url = './index.php';  
  pcz_http_request.onreadystatechange = _pcz_readystatechange;  
  pcz_http_request.open('POST', url, true); 
  pcz_http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  pcz_http_request.send(s);         
 }
 
function pcz_newcomment()
 {
  el = document.getElementById('pcz_tabsheet_comments'); el.style.display = 'none';
  el = document.getElementById('pcz_tabsheet_addcomment'); el.style.display = 'block';
  document.pcz_form_addcomment.name.value = '';
  document.pcz_form_addcomment.comment.value = '';
 } 
 
function pcz_postcomment(video_id, popup)
 {
  name = pcz_trim(document.pcz_form_addcomment.name.value);
  comment = pcz_trim(document.pcz_form_addcomment.comment.value);

  if (name.length < 2) { alert('er moet een naam ingevuld worden'); return; }
  if (comment.length < 2) { alert('wel commentaar invoeren'); return; }
  
  pcz_post_request('action=addcomment&video_id=' + video_id + 
                   '&name=' + name + 
                   '&comment=' + comment + 
                   '&popup=' + popup);
 }

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

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){
		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 pcz_postmailtofriend(video_id, popup)
 {
  text = pcz_trim(document.pcz_mailtofriend.text.value);
  from_name = pcz_trim(document.pcz_mailtofriend.from_name.value);
  from_email = pcz_trim(document.pcz_mailtofriend.from_email.value);
  to_email = pcz_trim(document.pcz_mailtofriend.to_email.value);  

//=== controles  
  if (from_name.length < 2) { alert('Je moet een naam invoeren.'); return; }
  if (!echeck(from_email)) { alert('Je moet een geldig email adres van jezelf ingeven.'); return; }
  if (to_email.length < 6) { alert('minimaal een geldig email adres invoeren'); return; }
  
  pcz_post_request('action=mailtofriend&video_id=' + video_id + 
                   '&text=' + text + 
                   '&from_name=' + from_name + 
                   '&from_email=' + from_email + 
                   '&to_email=' + to_email + 
                   '&popup=' + popup);
                   
  pcz_set_cookie('pcz_name', from_name, 180);                                   
  pcz_set_cookie('pcz_email', from_email, 180);  
                   
  document.pcz_mailtofriend.text.value = '';
  document.pcz_mailtofriend.to_email.value = '';
 } 
 
function pcz_stop()
 {
  el = document.getElementById('pcz_videoplayer_frame');
  if (el) { el.innerHTML = ''; }
 } 
 
 
function pcz_can_vote(video_id)  
 {
  s = pcz_get_cookie('votes');
  if (s == '') { return 1; }
  votes = s.split(',');
 
  for (i=0; i < votes.length; i++)
   {
    if (video_id == votes[i]) { return 0; } 
   }
  return 1; 
 } 
 
function pcz_store_vote(video_id)  
 {
  if (pcz_can_vote(video_id) == 0) { return; }
  
  s = pcz_get_cookie('votes');
  votes = s.split(',');
  max_elements = 50;
  
  r = new Array();
//=== wanneer groter dan max_elements dan de eerste verwijderen  
  if (votes.length >= max_elements)
   {
    for (i=1; i < max_elements; i++)
     {
      r[i - 1] = votes[i];
     }
    votes = r;     
   }
  
  votes.push(video_id);   
  s = votes.toString(',');
  pcz_set_cookie('votes', s, 180);
 } 
 
 
function pcz_vote(video_id, s, popup)
 {
  p = 'thumb_up=1'; if (s == 'down') { p = 'thumb_up=0'; } 
  p = p + '&action=vote&video_id=' + video_id;
  p = p + '&popup=' + popup;
  pcz_post_request(p);
  el = document.getElementById('pcz_btn_thumbup'); el.style.visibility = 'hidden';
  el = document.getElementById('pcz_btn_thumbdown'); el.style.visibility = 'hidden';
  pcz_store_vote(video_id);
 }
 
function pcz_brokenlink(video_id, popup)
 {
  p = 'action=brokenlink&video_id=' + video_id;
  p = p + '&popup=' + popup;
  pcz_post_request(p);
  el = document.getElementById('pcz_btn_thumbup'); el.style.visibility = 'hidden';
  el = document.getElementById('pcz_btn_thumbdown'); el.style.visibility = 'hidden';
  el = document.getElementById('pcz_btn_brokenlink'); el.style.visibility = 'hidden';  
 } 
 
/**
* eventueel popup sluiten
*/
function pcz_popup_mode_off()
 {
//=== de pm=1 eruit filteren
  url = document.location.href;
  url = url.replace(/&pm=1/, '');
  url = url.replace(/pm=1/, '');
  
  if (url.search(/\?/) == -1) 
   { 
    url = url + '?pm=0'; 
   }
  else
   { 
    url = url + '&pm=0';     
   } 
   
//=== opgelet: deze waarde wordt gezet DOOR de POPUP !   
  if (pcz_curr_v != '') 
   {
    url = url + '&v=' + pcz_curr_v;     
   } 
   
//=== wanneer popup mode (deze globale var wordt geset onder in document)   
  if (popup_mode == 1)
   {
//=== deze wordt nu op 0 gezet 
//=== want deze geeft aan     
    pcz_close_popup_on_onload_event = 0;
    var winName = 'pcz_videoplayer';
//=== document met alleen window.close javascript
    var w = window.open(pcz_base_url + '/pcz_close_popup.html', winName, 'width=100,height=100');
   }
  document.location.href = url;
 }
 
/**
*/
function pcz_popup_mode_on()
 {
  pcz_popup_modus(pcz_curr_v, 0);
 } 