function setDivDims(w_h)
{
	var w_h = String(w_h);
	var dims = w_h.split(",");
	var obj = document.getElementById('banners');
	obj.style.width = dims[0];
	obj.style.height = dims[1];
	var emb = document.getElementById('bannerEmb');
	emb.style.width = dims[0];
	emb.style.height = dims[1];
}

// Deze functie wordt door fsCommand aangeroepen
function openFlashBannerPopup(i_s_w_h)
{
	var i_s_w_h = String(i_s_w_h);
	var dims = i_s_w_h.split(",");
	var id = dims[0];
	win_width = dims[2];
	win_height = dims[3];
	var winX = Math.round((screen.width-win_width)/2);
	var winY = Math.round((screen.height-win_height)/2);

	window.open("http://www.boomla.nl/pub/banner_linker.php?b=" + id, "boomla_win", "width=" + win_width + ", height=" + win_height +", screenX=" + winX + ", screenY=" + winY + ",scrollbars=yes");
}

// Deze functie wordt door de ExternalInterface van flash aangeroepen 
function openPopup(id, linkInfo)
{
  var linkInfo = String(linkInfo);
  var dims = linkInfo.split(",");
  win_width = dims[1];
  win_height = dims[2];
  var winX = Math.round((screen.width-win_width)/2);
  var winY = Math.round((screen.height-win_height)/2);

  window.open("http://www.boomla.nl/pub/comart_linker.php?b=" + id, "boomla_win", "width=" + win_width + ", height=" + win_height +", screenX=" + winX + ", screenY=" + winY + ",scrollbars=yes");
}

var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function bannerRotor_DoFSCommand(command, args) {
	var bannersObj = isInternetExplorer ? document.all.bannerRotor : document.bannerRotor;
	if (command == 'setDivDims')
	{
		setDivDims(args)
	}
	else if (command == 'openPopup')
	{
		openFlashBannerPopup(args)
	}
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub bannerRotor_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call bannerRotor_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

function toggleCommForm(parent)
{
	with (document.commForm)
	{
		comm_parent.value = parent;
	}
	var td = document.getElementById('formCell');
	var div = document.getElementById('commLink');
	if (td.style.display == 'none')
	{
		td.style.display = 'block';
		div.style.display = 'none';
	}
}

function checkCommForm()
{
	with (document.commForm)
	{
		if (comm_creator.value == "")
		{
			alert('U dient een naam in te voeren');
			return false;
		}
		else if (comm_text.value == "")
		{
			alert('U dient een reatie in te voeren');
			return false;
		}
		else
		{
			return true;
		}
	}
}

function checkLoginForm()
{
	with (document.loginForm)
	{
		if (profiel_email.value == "" || profiel_email.value == "gebruikersnaam")
		{
			alert('U dient een gebruikersnaam in te voeren');
		}
		else if (profiel_login_password.value == "" || profiel_login_password.value == "wachtwoord")
		{
			alert('U dient een wachtwoord in te voeren');
		}
		else
		{
			submit();
		}
	}
}

function toggleContent(input, value)
{
	if (input.value == value)
	{
		if (value == "wachtwoord")
		{
			input.type = "password";
		}
		input.value = "";
	}
	else if (input.value.length == 0)
	{
		if (value == "wachtwoord")
		{
			input.type = "text";
		}
		input.value = value;
	}
}

function checkRegForm()
{
	with (document.newItemForm)
	{
		if (profiel_pers.value == "")
		{
			alert('U dient een naam in te voeren');
			return false;
		}
		else if (profiel_address.value == "")
		{
			alert('U dient een adres in te voeren');
			return false;
		}
		else if (profiel_zip.value == "")
		{
			alert('U dient een postcode in te voeren');
			return false;
		}
		else if(nl_id.value == "")
		{
			alert("U dient een locatie in te vullen");
			return false;
		}
		else if(selObj.style.display == "inline")
		{
			alert("U dient een locatie uit de keuzelijst te selecteren");
			return false;
		}
		else if (profiel_email.value == "")
		{
			alert('U dient een email adres in te voeren');
			return false;
		}
		else if (profiel_login_password.value == "")
		{
			alert('U dient een wachtwoord in te voeren');
			return false;
		}
		else if (profiel_login_password_check.value == "")
		{
			alert('U dient een wachtwoordbevestiging in te voeren');
			return false;
		}
		else if (profiel_login_password_check.value != profiel_login_password.value)
		{
			alert('De twee ingevoerde wachtwoorden komen niet oevereen');
			return false;
		}
		else
		{
			return true;
		}
	}
}

function checkQuery(form, query)
{
    if (query.length < 2)
    {
        alert("De zoekstring moet langer dan 1 teken zijn.");
        return false;
    }
    else if (query.length < 3)
    {
        if (confirm('Het zoeken op korte woorden kan veel tijd kosten en zeer veel resultaten opleveren!\r\nWeet u zeker dat u door wilt gaan?'))
        {
            form.submit(); 
        }   
    }
    else
    {
        form.submit();
    }
} 

function checkSearchForm(form, query)
{
  if (query.length < 4)
  {
    alert("De zoekstring moet langer dan 3 tekens zijn.");
    return false;
  }
  else if (!validDates(form))
  {
    alert("De einddatum dient groter of gelijk aan de startdatum te zijn");
    return false;  
  }
  else
  {
    form.submit();
  }
}

function raiseMessage()
{
	document.getElementById('reactMessage').style.color = 'red';
	document.getElementById('reactMessage').style.textDecoration = 'underline';
}

function lowerMessage()
{
	document.getElementById('reactMessage').style.color = '#333399';
	document.getElementById('reactMessage').style.textDecoration = 'none';
}

function saveAgendaItem()
{
  var price_filter = /^([0-9]+)(([.]{1}[0-9]{1,2})||([0-9]{+}))$/;
  with(document.newItemForm)
	{
    if(agenda_name.value == "")
    {
      alert("U dient een titel in te vullen");
    }
    else if(c_id.value == -1)
    {
      alert("U dient een categorie aan te geven voor dit agendapunt");
    }
    else if(r_id.value == -1)
    {
      alert("U dient een rubriek aan te geven voor dit agendapunt");
    }
    else if(agenda_text.value == "")
    {
      alert("U dient een omschrijving in te vullen");
    }
    else if(!price_filter.test(agenda_price.value) && agenda_price.value != "")
    {
      alert("U dient een geldige prijs in te vullen");
    }
    else if (!validAgendaDates(document.newItemForm))
    {
      alert("De einddatum dient groter of gelijk aan de startdatum te zijn"); 
    }
    else if(agenda_comp.value == "" && agenda_pers.value == "")
    {
      alert("U dient een bedrijfsnaam en/of contactpersoon in te vullen");
    }	
		else if(nl_id.value == "")
		{
			alert("U dient een plaats in te vullen");
		}
		else if(selObj.style.display == "inline")
		{
			alert("U dient een plaats uit de keuzelijst te selecteren");
		}
    else if(agenda_tel.value == "" && agenda_email.value == "")
    {
      alert("U dient een telefoonnummer en/of emailadres in te vullen");
    }
    else if(agenda_tel.value != "" && !agenda_tel.value.match('(^[0-9]{10}$)|(^[0-9]{3}[- ]{1}[0-9]+$)|(^[0-9]{4}[- ]{1}[0-9]+$)'))
    {
      alert("U dient een geldig telefoonnummer in te vullen");
    }
    else if(agenda_email.value != "" && !agenda_email.value.match('^[a-zA-Z0-9]+[_a-zA-Z0-9-]*(\.[_a-z0-9-]+)*@[a-z?0-9]+(-[a-z?0-9]+)*(\.[a-z?0-9-]+)*(\.[a-z]{2,4})'))
    {
      alert("U dient een geldig emailadres in te vullen");
    }
    else if(agenda_attach.value != "" && attach_name.value == "")
    {
      alert("U dient een naam voor de bijlage in te vullen");
    }
		else
		{
			submit();
		}
	}
}

function validDates(activeForm)
{
  with(activeForm)
  {
    var int_start_date = Date.parse((s_date.value).replace(/-/g, "/"));
    var int_end_date   = Date.parse((e_date.value).replace(/-/g, "/"));
    if (int_end_date < int_start_date)
    {
      return false;
    }
    return true;
  }
}

function validAgendaDates(activeForm)
{
  with(activeForm)
  {
    var int_start_date = Date.parse((s_date.value).replace(/-/g, "/"));
    var int_end_date   = Date.parse((e_date.value).replace(/-/g, "/"));
    if (int_end_date < int_start_date)
    {
      return false;
    }
    else if (int_end_date == int_start_date && parseInt(e_date_h.value) < parseInt(s_date_h.value))
    {
      return false;
    }
    else if (int_end_date == int_start_date && parseInt(e_date_h.value) == parseInt(s_date_h.value) && parseInt(e_date_m.value) < parseInt(s_date_m.value))
    {
      return false;
    }   
    return true;
  }
}

function showAgendaItemDetail(id, a_id)
{
	var ElementId = 'item_'+id;
	document.getElementById(ElementId).style.display = 'block';
	increaseItemCount('functions/item_counter.php?a_id='+a_id);
}

function hideAgendaItemDetail(id)
{
	document.getElementById(id).style.display = 'none';
}

function increaseItemCount(url)
	{
	xmlhttp=null
	// code for Mozilla, etc.
	if (window.XMLHttpRequest)
		{
		xmlhttp=new XMLHttpRequest()
		}
	// code for IE
	else if (window.ActiveXObject)
		{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	if (xmlhttp!=null)
		{
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
		}
	else
		{
		alert("Your browser does not support XMLHTTP.")
		}
	}

	function submitVoteForm()
	{
		with (document.voteForm)
		{
			if (pollstat_email.value == "")
			{
				alert("U dient een emailadres in te voeren.");
				return false;
			}
			else
			{
				submit();
			}
		}
	}
  
  // Handle all the FSCommand messages in a Flash movie.
  function fotoplayer_DoFSCommand(command, args) {
    var fotoplayerObj = isInternetExplorer ? document.all.fotoplayer : document.fotoplayer;
    if (command == "alertMessage")
    {
      var width = 270;
      var height = 180;
      var arguments = args.split(",");
      var b_uri      = arguments[0];
      var b_id      = arguments[1];
      var b_folder  = arguments[2];
      var w = window.open('http://www.boomla.nl/pub/view_image.php?b_uri='+b_folder+'&b_id='+b_id, '', 'status=yes, width='+width+', height='+height);
    }
  }

  // Hook for Internet Explorer.
  if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<script language=\"VBScript\"\>\n');
    document.write('On Error Resume Next\n');
    document.write('Sub fotoplayer_FSCommand(ByVal command, ByVal args)\n');
    document.write('  Call fotoplayer_DoFSCommand(command, args)\n');
    document.write('End Sub\n');
    document.write('<\/script\>\n');
  }
  
  function sendAgendaSearchForm()
  {
    with(document.newItemForm)
    {
      if (c_id.selectedIndex == -1)
      {
        var options = c_id.childNodes;
        for (i=0;i<options.length;i++)
        {
          if (options[i].nodeName == "OPTION")
          {
            options[i].selected = true;
          }
        } 
      }
      if (r_id.selectedIndex == -1)
      {
        var options = r_id.childNodes;
        for (i=0;i<options.length;i++)
        {
          if (options[i].nodeName == "OPTION")
          {
            options[i].selected = true;
          }
        }
      }
      if (Date.parse((e_date.value).replace(/-/g, "/")) < Date.parse((s_date.value).replace(/-/g, "/")))
      {
        alert("De einddatum dient groter of gelijk aan de startdatum te zijn"); 
      }
      else
      {
        c_id.name = "c_id[]";
        r_id.name = "r_id[]";
        submit();
      }
    }
  }
  
  function setPlaceField(toggle)
  {
    if (toggle == 0)
    {
      document.newItemForm.queryText.disabled = false;
    }
    else
    {
      document.newItemForm.nl_id.value = "-1";
      document.newItemForm.selectedValue.value = "-1";
      document.newItemForm.queryText.value = "";
      document.newItemForm.queryText.disabled = true; 
    }
  }
  
  function checkContactForm()
  {
    with (document.contactForm)
    {
      if (contact_naam.value == contact_email.value && contact_naam.value == contact_onderwerp.value)
      {
        alert("De waarden voor naam, email en onderwerp mogen niet hetzelfde zijn.");
      }
      else
      {
        submit();
      }
    }
  }
  
    function setCalLabel(id, text, date)
    {
        document.getElementById(id).innerHTML = "wat is er "+text+" te doen";
        document.calZoek.s_date.value = date;
        document.calZoek.e_date.value = date;
    }
    
    function resizeMediaTextBox()
    {
         var container = document.getElementById('media_text_container');
         var full_text = document.getElementById('full_text'); 
         var short_text = document.getElementById('short_text');
         container.style.height = "150px";
         container.style.overflowY = "auto";
         short_text.style.display = 'none';
         full_text.style.display = 'inline';  
    }
    
    function setPromoboxSize(_width, _height)
    {
        if (navigator.appName.indexOf("Microsoft") != -1)
        {
          var flash = window.promobox;
        }
        else
        {
          var flash = window.document.promobox;
        }
        if (parseInt(_width) > 300)
        {
            flash.style.width = "300px";
            flash.style.height = "200px"   
        }
        else
        {
            flash.style.width = _width+"px";
            flash.style.height = _height+"px";
        }
    }
    
    function getMouseXY(e)
    {
        if (!e) 
        {
            var e = window.event;
        }
        if (e.pageX || e.pageY)     
        {
            posx = e.pageX;
            posy = e.pageY;
        }
        else if (e.clientX || e.clientY)     
        {
            posx = e.clientX + document.body.scrollLeft
            + document.documentElement.scrollLeft;
            posy = e.clientY + document.body.scrollTop
            + document.documentElement.scrollTop;
        } 
        return [posx, posy];   
    }
    
    
    var active_calendar_id  = ''; 

    function showCalendarPopup(e, date_box)
    {
        active_calendar_id  = date_box;
        var mouseXY         = getMouseXY(e);
        
        var date_input      = document.getElementById(date_box);
        var date_time       = dateIntVal(date_input.value)/1000;
        
        var calendar_frame  = document.getElementById('calendar_frame');
        calendar_frame.src  = 'pages/calendar_frame.inc.php?time='+date_time;
        
        var popup = document.getElementById('calendarPopup');
        popup.style.display = 'block';
        popup.style.left = (mouseXY[0]+30)+'px';   
        popup.style.top  = (mouseXY[1]-80)+'px';   
    }

    function hideCalendarPopup()
    {
        var popup = document.getElementById('calendarPopup');
        popup.style.display = 'none';    
    }

    function dateIntVal(dateString)
    {
        var parts = dateString.split("-");
        var checkDate = new Date();  
        checkDate.setFullYear(parseInt(parts[2]), parseInt(parts[1])-1, parseInt(parts[0]));           
        return checkDate.getTime();
    }

    function saveDate(dateString)
    {
        var input_field = document.getElementById(active_calendar_id);
        input_field.value = dateString; 
        if (active_calendar_id == 'search_date_from')
        {
            document.mediaForm.s_date.value = dateIntVal(dateString)/1000;
        } 
        if (active_calendar_id == 'search_date_to')
        {
            document.mediaForm.e_date.value = dateIntVal(dateString)/1000;
        }     
        hideCalendarPopup();
    }

 function sendMediaSearchForm(reset_page)
{
    with (document.mediaForm)
    {
        var qField   = document.getElementById('media_search_query');
        if (qField != null)
        { 
            query.value  = qField.value;
        }
        if (reset_page == true)
        {
            n_page.value = 1;
        }
        if (s_date.value > e_date.value)
        {
            alert('De startdatum is groter dan de einddatum');   
        }
        else
        {
            submit();   
        }
    }   
}
    
function showBedrijfspresentatie(e, box)
{
    var mousePos   = getMouseXY(e); 
    box.style.top  = (mousePos[1]-150)+'px';      
    box.style.left = (mousePos[0]-200)+'px';
    box.style.display = 'block';      
}

function hideBedrijfspresentatie(box)
{
    if (navigator.appName.indexOf("Microsoft") != -1)
    {
        var flash = window.bedrijfsfilm;
    }
    else
    {
        var flash = window.document.bedrijfsfilm;
    }
    flash.resetPlayer();
    box.style.display = 'none';      
}    

function trim(value) 
{
  value = value.replace(/^\s+/,'');
  value = value.replace(/\s+$/,'');
  return value;
} 
