
function get_translate_action(form){
	var section = form.Section.value;
	var actionUrl = 'http://www.tierrafino.'+section+'/textpattern/index.php';
	return actionUrl;
}

function translate_dialog(cat1,cat2){

	var dialogContent = '\
		<div id="dialog_content" style="padding:10px 30px">\
		<h3>Create a translated page</h3>\
		<form method="post" action="" onsubmit="this.action = get_translate_action(this);">\
			In what language do you want to translate this page?\
			<input type="hidden" name="Category1" value="'+cat1+'"/>\
			<input type="hidden" name="Category2" value="'+cat2+'"/>\
			<input type="hidden" name="event" value="article"/>\
			<input type="hidden" name="step" value="create"/>\
			<br/><br/>\
			<select name="Section">\
				<option value="cz">Czech</option>\
				<option value="pl">Polish</option>\
			</select>\
			<input type="submit" value="Create page"/>\
		</form>\
		</div>\
		';
	document.getElementById('dialogContainer').innerHTML=dialogContent;
	document.getElementById('dialog').style.display='block';
}


function validateContactForm(langcode){

    document.getElementById('submit-button').disabled = true;

    var alertmessage = '';

    if ((document.getElementById('Voornaam').value) == '') alertmessage = messageVoornaam;
    if ((document.getElementById('Naam').value) == '') alertmessage = alertmessage + messageAchternaam;
    if ((document.getElementById('E_mail_adres').value) == '') alertmessage = alertmessage + messageEmail;
    if (document.getElementById('E_mail_adres').value.indexOf(' ') != -1) alertmessage = alertmessage + messageEmailSpaces;
    if ((document.contactFormulier.mailto.options[document.contactFormulier.mailto.selectedIndex].value) == 'unknown_country') alertmessage = alertmessage + messageLand;

    if (alertmessage != ''){
        alert (messageHeader+alertmessage+messageFooter);
	document.getElementById('submit-button').disabled = false;
    }
    else {
	document.getElementById('submit-button').value = buttonTextSending;
	document.contactFormulier.submit();
    }
}


/***********************************************
* Pausing up-down scroller- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay){
    this.content=content //message array content
    this.tickerid=divId //ID of ticker div to display information
    this.delay=delay //Delay between msg change, in miliseconds.
    this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
    this.hiddendivpointer=1 //index of message array for hidden div
    document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
    var scrollerinstance=this
    if (window.addEventListener) //run onload in DOM2 browsers
    window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
    else if (window.attachEvent) //run onload in IE5.5+
    window.attachEvent("onload", function(){scrollerinstance.initialize()})
    else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
    setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
    this.tickerdiv=document.getElementById(this.tickerid)
    this.visiblediv=document.getElementById(this.tickerid+"1")
    this.hiddendiv=document.getElementById(this.tickerid+"2")
    this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
    //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
    this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
    this.getinline(this.visiblediv, this.hiddendiv)
    this.hiddendiv.style.visibility="visible"
    var scrollerinstance=this
    document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
    document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
    if (window.attachEvent) //Clean up loose references in IE
	window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
    setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
    var scrollerinstance=this
    if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+2)){
        this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-2+"px"
        this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-2+"px"
    setTimeout(function(){scrollerinstance.animateup()}, 50)
    }
    else{
	this.getinline(this.hiddendiv, this.visiblediv)
	this.swapdivs()
	setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
    }
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
    var tempcontainer=this.visiblediv
    this.visiblediv=this.hiddendiv
    this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
    div1.style.top=this.visibledivtop+"px"
    div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
    var scrollerinstance=this
    if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
	setTimeout(function(){scrollerinstance.setmessage()}, 100)
    else{
	var i=this.hiddendivpointer
        var ceiling=this.content.length
        this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
	this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
	this.animateup()
    }
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
    if (tickerobj.currentStyle)
	return tickerobj.currentStyle["paddingTop"]
    else if (window.getComputedStyle) //if DOM2
	return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
    else
	return 0
}

// einde scroll scripts


function kleurenVergelijkerInit(product,langcode) {


    if ((document.cookie || !(document.cookie) )){

        var product = product.replace("tfino_leemfinish", "finish");
        var product = product.replace("tfino_paint", "ipaint");
        var product = product.replace("tfino_stucverf", "tpaint");
        var product = product.replace("tfino_stampleem", "rammedearth");
        var product = product.replace("tfino_", "");


		if (getCookie('selected_colors_and_materials') && getCookie('selected_colors_and_materials') != null){
			//popitupOnReturnVisit('/scripts/colorpop.php');
		}

	    // make images clickable
        var images=document.getElementById('standaardtekstvak').getElementsByTagName('img');
        for(i=0;i<images.length;i++) {

            if (!(images[i].parentNode.href) && (images[i].src.match('/kleuren') || images[i].src.match('kleuren/') || images[i].src.match('/bronnen'))){
                images[i].style.cursor='pointer';
                images[i].onmousemove=function(event){
                    kleurenVergelijkerInfo(event,langcode,this.alt,this.src);
                }
                images[i].onmouseover=function(event){
                    kleurenVergelijkerInfo(event,langcode,this.alt,this.src);
                }
                images[i].onmouseout=function(){
                    //var product = 'stone';
                    kleurenVergelijkerHideInfo();
		    //document.body.style.overflow = '';
                }
                images[i].onclick=function(){
                    //var product = 'stone';
                    kleurenVergelijkerDialog(this.src,product,langcode);
                    kleurenVergelijkerHideInfo();
                }
                images[i].title='';
            }
        }
    }
}

function materialAndColorChooserInit(cookie){

parent.document.getElementById('fullscreenBG').style.background='black';

if (getCookie('selected_colors_and_materials') == '' || getCookie('selected_colors_and_materials') == null){
    parentHideFullscreenContainer ();
parent.document.getElementById('showChooserLink').style.display = 'none';
}
else {
	//resizeTo(00,screen.availHeight);
	//moveTo( (screen.availWidth - 200),0);
}



}










var kleurenKiezerWindow = '';



function kleurenVergelijkerInfo(event,langcode,alt,src){
    var tooltip = parent.document.getElementById('tooltip');
    var tooltipBG = parent.document.getElementById('tooltipBG');
    var tooltipContainer = parent.document.getElementById('tooltipContainer');

    if (src.match('-')) src = src.replace(src.substring(src.lastIndexOf('-')),'');

    if (getCookie('selected_colors_and_materials') && getCookie('selected_colors_and_materials').match(src)){
       var imgIsInChooser = true;
    }
    else var imgIsInChooser = false;

	if (imgIsInChooser) var htmlToShow = messageSampleIsInChooser;
	else var htmlToShow = messageSampleIsNotInChooser;
	htmlToShow += '<br/>'+messageClickForEnlargement+' ';
	if (imgIsInChooser) htmlToShow += messageOrToRemoveSampleFromChooser;
	else htmlToShow += messageOrToAddSampleToChooser;

    //tooltip.style.left="";

    tooltipContainer.innerHTML = '<h4 style="margin:0;">'+alt+'</h4>'+htmlToShow;

    var e = (window.event) ? window.event : event;
    var windowHeight = getFullSizeDimensions()[1];

    tooltip.style.right = "";
    tooltip.style.left = Math.min(e.clientX + 12,getFullSizeDimensions()[0] - 280)+"px";

    if (e.clientY > windowHeight - tooltip.clientHeight - 21){
	tooltip.style.top="";
	var offsetBottom = (windowHeight - e.clientY + 1) + "px";
    }
    else{
	tooltip.style.bottom = "";
	var offsetTop = e.clientY + 48+"px";
    }

    if (offsetBottom) tooltip.style.bottom = offsetBottom;
    if (offsetTop) tooltip.style.top = offsetTop;

    if (e.clientY != windowHeight - tooltip.clientHeight - 21)
	tooltip.style.display = 'block';
}


function kleurenVergelijkerHideInfo(){
    var tooltip = parent.document.getElementById('tooltip');
    tooltip.style.display = 'none';
}


function kleurenVergelijkerDialog(url,product,langcode){

    url = url.replace('cutout.','cutout-360.');

    if (getCookie('selected_colors_and_materials') && getCookie('selected_colors_and_materials').match(url) ){
        htmlToShow = (
			'<p>'+removeMessage + '</p>'
			+ '<div style="height:360px; width:360px; margin-left:auto; margin-right:auto; background:url(\''+url+'\') no-repeat center;"></div>'
			+ '<p style="text-align:right;">'
			+ '<button onclick="document.getElementById(\'dialog\').style.display = \'none\';">'+cancelButton+'</button>'
			+ '<button onclick="cookieRemoveElement(\'selected_colors_and_materials\',\''+url+','+product+'\');document.getElementById(\'dialog\').style.display = \'none\';">'+removeButton+'</button>'
			+ '</p>'
			);
    }

    else {
        htmlToShow = (
			'<p>'+addMessage + '</p>'
			+ '<div style="height:360px; width:360px; margin-left:auto; margin-right:auto; background:url(\''+url+'\') no-repeat center;"></div>'
			+ '<p style="text-align:right;">'
			+ '<button onclick="parent.document.getElementById(\'dialog\').style.display = \'none\';">'+cancelButton+'</button>'
			+ '<button onclick="kleurenVergelijkerOpen(\''+url+'\',\''+product+'\');document.getElementById(\'dialog\').style.display = \'none\';">'+addButton+'</button>'
			+ '</p>'
			);
    }


    parent.document.getElementById('dialogContainer').innerHTML = htmlToShow;
    parent.document.getElementById('dialog').style.display = 'block';

}


function getKleurstalenTellerTekst(){

    if (getCookie('selected_colors_and_materials') == null) var visibleThumbCount = 0;
    else var visibleThumbCount = (getCookie('selected_colors_and_materials').replaceAll('[^;]','').length);

    if (visibleThumbCount == 0) visibleThumbCount = messageContainsNoSamples;
    else if (visibleThumbCount == 1) visibleThumbCount = messageContainsOneSample;
    else visibleThumbCount = messageContainsSamplesStart+visibleThumbCount+messageContainsSamplesEnd;
    return messageSampleSentenceStart+visibleThumbCount;

}


function kleurenVergelijkerOpen(url,product){

cookieAppend('selected_colors_and_materials', url+','+product);
//moveTo(0,0);
//resizeTo( (screen.availWidth - 200),screen.availHeight);



parent.document.getElementById('kleurstalenTellerTekst').innerHTML = getKleurstalenTellerTekst();
parent.document.getElementById('showChooserLink').style.display = 'inline';
    if (frames['fullscreenContainer']) frames['fullscreenContainer'].location.reload();

	showFullscreenImage ();
}

function setCookie(name, value, expires, path, domain, secure) {

    if (!expires) expires = new Date(new Date().getTime() + (365*24*60*60*1000));
    if (!path) path = '/';

    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

String.prototype.replaceAll=function(s1, s2) {
	  return this.replace(new RegExp(s1,"g"), s2);
	}

function cookieAppend(cookiename,appendvalue){

    if (getCookie(cookiename)) {

        newCookieValue = (getCookie(cookiename) + appendvalue + ';');

        if (!(getCookie(cookiename).match(appendvalue)) ){
            setCookie(cookiename,newCookieValue);
        }
    }
    else setCookie(cookiename,appendvalue + ';' );



}
function cookieRemoveElement(cookiename,elementToRemove){

    if (getCookie(cookiename)) {

    oldCookieValue = getCookie(cookiename);
    newCookieValue = oldCookieValue.replace(elementToRemove+";", "")
    setCookie(cookiename,newCookieValue);
    if (frames['fullscreenContainer']) frames['fullscreenContainer'].location.reload();
    parent.document.getElementById('kleurstalenTellerTekst').innerHTML = getKleurstalenTellerTekst();

   }

}


function cookieClearAll(cookiename){

    if (confirm(messageConfirmClearSampler)){

	if (document.cookie) {
	    setCookie(cookiename,"");
	}
	if (parent.frames['fullscreenContainer']) parent.frames['fullscreenContainer'].location.reload();
	parent.document.getElementById('kleurstalenTellerTekst').innerHTML = getKleurstalenTellerTekst();

	alert (messageAllSamplesRemoved);
    }
}

function changeThumbSize(thumbSize){
    setCookie('sample_thumbsize', thumbSize);
    parent.fullscreenContainer.location.reload();
}

function showThumbText(thumbSize){
    var langcode = document.getElementById('langcode').value;


    var thumbText = messageShowThumbsNormalSize;
    if (thumbSize < 150) var thumbText = messageShowThumbsSmall;
    if (thumbSize < 100) var thumbText = messageShowThumbsExtraSmall;
    if (thumbSize > 200) var thumbText = messageShowThumbsLarge;
    if (thumbSize > 300) var thumbText = messageShowThumbsExtraLarge;


    document.getElementById('knop_'+thumbSize).className = 'active';
    document.getElementById('knop_tekst').innerHTML = thumbText+' ('+thumbSize+' x '+thumbSize+' px)';
}

function hideThumbText(thumbSize){
    document.getElementById('knop_tekst').innerHTML = '';
    document.getElementById('knop_'+thumbSize).className = '';
}

       function makeVisible(obj_id) {
			if (document.getElementById){
				var obj = document.getElementById(obj_id);
				obj.style.display = 'table-cell';
			}
		}

		function makeInvisible(obj_id) {
			if (document.getElementById){
				var obj = document.getElementById(obj_id);
				obj.style.display = 'none';
			}
		}



var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();
