

var websiteURL = "http://props.ubf.nl/";


function scrollDiv() 
{
    $('scrollArea').style.display = "inline";
    var docH = $('subsub').offsetHeight;
    var contH = $('subscroll').offsetHeight;
    var scrollAreaH = $('scrollArea').offsetHeight;
    var scrollH = (contH * scrollAreaH) / docH;
    if(docH > contH) 
    {
        $('scrollUp').style.display = "inline";
        $('scrollDwn').style.display = "inline";
   		
        $('scroller').style.height = Math.round(scrollH) + "px";
        var scrollDist = Math.round(scrollAreaH-scrollH);
        Drag.init($('scroller'), null, 0, 0, -1, scrollDist);
			
        $('scroller').onDrag = function (x,y)
        {
            var scrollY = parseInt($("scroller").style.top);
            var docY = 0 - (scrollY * (docH - contH) / scrollDist);
            $('subsub').style.top = docY + "px";
        }
    }
    else
    {
        $('scrollUp').style.display = "none";
        $('scrollDwn').style.display = "none";
        $('scrollArea').style.display = "none";
    }
}

function wScrollDiv(to) 
{
    $('wScrollArea').style.display = "inline";
    var docH = $('wWishlist').offsetHeight;
    var contH = $('wSubscroll').offsetHeight;
    var scrollAreaH = $('wScrollArea').offsetHeight;
    var scrollH = (contH * scrollAreaH) / docH;
    if(docH > contH) 
    {
        $('wScrollUp').style.display = "inline";
        $('wScrollDwn').style.display = "inline";
   		
        $('wScroller').style.height = Math.round(scrollH) + "px";
        var scrollDist = Math.round(scrollAreaH-scrollH);
        Drag.init($('wScroller'), null, 0, 0, -1, scrollDist);
			
        $('wScroller').onDrag = function (x,y)
        {
            var scrollY = parseInt($("wScroller").style.top);
            var docY = 0 - (scrollY * (docH - contH) / scrollDist);
            $('wWishlist').style.top = docY + "px";
        }
    }
    else
    {
        $('wScrollUp').style.display = "none";
        $('wScrollDwn').style.display = "none";
        $('wScrollArea').style.display = "none";
    }
}
/*
var cal = false;
var sCalendar = function(id, type){
	date = $(id + type).innerHTML;

	var dmy = stringToArray(date, '-');
	
   	if(cal) { 
   		cal.toggleCalendar(); 
   		cal.destroy();
   	}
	
  	   	
    $('scal').show();
    cal = new scal('scal', id + type );

 	cal.setCurrentDate(
 		new Date(
 			(parseInt(dmy[2])),
 			(parseInt(dmy[1])-1),
 			(parseInt(dmy[0]))
 		));

};
*/


/* ===| Global Functions                                 |=== */ 
/* ---------------------------------------------------------- */


function stringToArray(arr, on) {
    return arr.split(on);
}

function onSelect(id, type) {
    if (type == "product")
    {
        product_select_handler(id);
    }
    else if (type == "search")
    {
        search_select_handler(id);
    }
    else
    {
        tag_select_handler(id, type);
    }
}


function onTab(fn) 
{
    comesFromWishlist();
    if (fn == 't')
    {
        if(get_active_screen(1) != 'thema') {
            flip_screen(1, get_active_screen(1), 'thema');
            send_message('tab_thema', false);
        }
    }
    else if (fn == 'c')
    {
        if(get_active_screen(1) != 'categorie') {
            flip_screen(1, get_active_screen(1), 'categorie');
            send_message('tab_categorie', false);
        }
    }
	
}


function kill_effect(eff) 
{
    var queue = Effect.Queues.get(eff);
    queue.each(function(e) {
        e.cancel()
    });
}


function onSort(on) 
{
    new Ajax.Request('js/function.ajax.php?a=sort', {
        method: 'get',
        parameters: "on=" + on,
        onSuccess: function(){}
    });
}


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 pcheck(strng) 
{
    if (strng == "") {
        return "U heeft geen wachtwoord opgegeven.\n";
    }
    
    var illegalChars = /[\W_]/; // allow only letters and numbers

    if ((strng.length < 5) || (strng.length > 14)) {
        return "Het wachtwoord bevat niet de juiste lengte.\nGeef tussen de 5 en 14 karakters op.\n";
    }
    
    else if (illegalChars.test(strng)) {
        return "Het wachtwoord bevat niet geldige karakters.\n";
    }
    
    else if (!((strng.search(/[a-z]+/) > -1)
        && (strng.search(/[A-Z]+/) > -1)
        && (strng.search(/[0-9]+/) > -1))) {
        return "Het wachtwoord moet minstens 1 hoofdletter, 1 kleine letter en 1 cijfer bevatten.\n";
    }
  	
    else return false;
  		
}

function match_date(dateStr)
{
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
	
    if (matchArray == null) {
        return false;
    }
	
    return [matchArray[1], matchArray[3], matchArray[5]];
}

function compare_date(dfr, dto)
{
    dv = match_date(dfr);
    dt = match_date(dto)

    if(Date.parse(dv[2] + '/' + dv[1] + '/' + dv[0]) < Date.parse(dt[2] + '/' + dt[1] + '/' + dt[0])){
        return true;
    }
    return false;
}

function date_change(id, go)
{
    var rqstURL = websiteURL + 'js/function.ajax.php?a=date_change';

    var dv = $(id + '_3').getValue();
    var dt = $(id + '_4').getValue();
	
    if(isDate(dv) && isDate(dt))
    {
        if(go == 0 || (compare_date(dv, dt) && go == 1))
        {
            new Ajax.Request(rqstURL, {
                method: 'post',
                parameters: {
                    dv: dv,
                    dt: dt,
                    id: id
                },
                onSuccess: function() {
                    detailListList();
                }
            });
        }
        else
        {
            alert("Einddatum moet na de begindatum komen.");
            detailListList();
        }
    }
    else
    {
        alert("Geen geldige datum invoer gebruik '/' of '-' om dag, maand en jaar te scheiden.");
        detailListList();
    }
}

function date_change_all(id)
{
    var rqstURL = websiteURL + 'js/function.ajax.php?a=date_change_all';

    var datum = $('date_' + id + '_all').getValue();

    if(isDate(datum))
    {
        new Ajax.Request(rqstURL, {
            method: 'post',
            parameters: {
                datum: datum,
                id: id
            },
            onLoading: function() {
                if(id == 'from') {
                    date_from_loading();
                }
                else if(id == 'to') {
                    date_to_loading();
                }
            },
            onSuccess: function() {
                detailListList();
                if(id == 'from') {
                    date_from_loading();
                    pop_date_from()
                }
                else if(id == 'to') {
                    date_to_loading();
                    pop_date_to()
                }
            }
        });
    }
}

function day_change_all()
{
    var rqstURL = websiteURL + 'js/function.ajax.php?a=day_change_all';

    var day = $('day_all').getValue();

    new Ajax.Request(rqstURL, {
        method: 'post',
        parameters: {
            day: day
        },
        onLoading: day_loading(),
        onSuccess: function() {
            detailIndicationList();
            day_loading();
            pop_day()
        }
    });
}

function date_change_enter_all(evt, id)
{	
    var k = (evt.which) ? evt.which : event.keyCode
    if(k == 13) {
        date_change_all(id);
        return true;
    }
    return false;
}

function date_change_enter(evt, id, go)
{
    var k = (evt.which) ? evt.which : event.keyCode
    if(k == 13) {
        date_change(id, go);
        return true;
    }
    return false;
}
 
function day_change_enter_all(evt)
{	//     0        9
    var k = (evt.which) ? evt.which : event.keyCode
    if(k>=48 && k<=57){
        return true;
    }else if(k == 13) {
        day_change_all();
        return true;
    }
    return false;
}

function day_change_enter(evt, id, aantal)
{
    var k = (evt.which) ? evt.which : event.keyCode
    if(k>=48 && k<=57){
        return true;
    }else if(k == 13) {
        setAantalDagen(id, aantal);
        return true;
    }
    return false;
}

function count_change_enter(evt, id, count, type)
{
    var k = (evt.which) ? evt.which : event.keyCode
    if(k>=48 && k<=57){
        return true;
    }else if(k == 13) {
        setToList(id, count, type);
        return true;
    }
    return false;
}

function setAantalDagen(id, aantal)
{
    var requestUrl = websiteURL + 'js/function.ajax.php?a=set_dagen';

    var request = new Ajax.Request(
        requestUrl, {
            method: 'get',
            parameters: "id=" + id + "&aantal=" + aantal,
            onSuccess: function(resp){
                detailIndicationList()
                }
        }
        );
}


function setToList(id, count, type){
    if(count == 0) {
        if(type == 1){
            detailIndicationList()
            }else{
            detailListList()
            }
    }else {
        var request = new Ajax.Request(
            websiteURL + 'js/function.ajax.php?a=wish_set',	{
                method: 'get',
                parameters: "code=" + id + "&count=" + count,
                onSuccess: function(resp){
                    if(type == 1){
                        detailIndicationList()
                        }else{
                        detailListList()
                        }
                    }
        });
}
}

function setStyle(x){
    $(x).style.border="red";
}


function isDate(dateStr) {
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
	
    if (matchArray == null) {
        return false;
    }
	
    day = matchArray[1]; // p@rse date into variables
    month = matchArray[3];
    year = matchArray[5];
	
    if (month < 1 || month > 12) { // check month range
        alert("Maand moet tussen de 1 en 12 zitten.");
        return false;
    }
	
    if (day < 1 || day > 31) {
        alert("Dagen moet tussen de 1 en 31 zitten.");
        return false;
    }
	
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        alert("Maand "+month+" heeft geen 31 dagen!");
        return false;
    }
	
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            alert("Februari " + year + " heeft geen " + day + " dagen!");
            return false;
        }
    }
    return true; // date is valid
}



function parse_order_form()
{
    var bedrijfsnaam = $('c_bedrijfsnaam').getValue();
    var voornaam 	 = $('c_voornaam').getValue();
    var achternaam 	 = $('c_achternaam').getValue();
    var adres 		 = $('c_adres').getValue();
    var woonplaats   = $('c_woonplaats').getValue();
    var telefoon 	 = $('c_telefoon').getValue();
    var url 	 	 = $('c_url').getValue();

	
    var validated = false;
    var illegalChars = /[\W_]/;
	
    var msg = false;
    if(bedrijfsnaam.length < 3) {
        if(!msg) msg = "Geef uw bedrijfsnaam op (minstens 3 karakters).";
        $('input1_c_bedrijfsnaam_check').style.display = "none";
    }else {
        $('input1_c_bedrijfsnaam_check').style.display = "";
    }
	
    if(voornaam.length < 2) {
        if(!msg) msg = "Geef uw voornaam op (minstens 2 karakters).";
        $('input1_c_voornaam_check').style.display = "none";
    }else {
        $('input1_c_voornaam_check').style.display = "";
    }
	
    if(achternaam.length < 2) {
        if(!msg) msg = "Geef uw achternaam op (minstens 2 karakters).";
        $('input1_c_achternaam_check').style.display = "none";
    }else {
        $('input1_c_achternaam_check').style.display = "";
    }
	
    if(adres.length < 3) {
        if(!msg) msg = "Geef uw adres op (minstens 3 karakters).";
        $('input1_c_adres_check').style.display = "none";
    }else {
        $('input1_c_adres_check').style.display = "";
    }
	
    if(woonplaats.length < 2) {
        if(!msg) msg = "Geef uw woonplaats op (minstens 2 karakters).";
        $('input1_c_woonplaats_check').style.display = "none";
    }else {
        $('input1_c_woonplaats_check').style.display = "";
    }
	
    if(telefoon.length < 10) {
        if(!msg) msg = "Geef uw telefoonnummer op (minstens 10 karakters)";
        $('input1_c_telefoon_check').style.display = "none";
    }else {
        $('input1_c_telefoon_check').style.display = "";
    }
		

    if($('c_email')){
        var email = $('c_email').getValue();
        if(!echeck(email)) {
            if(!msg) msg = "Geef uw e-mail adres op.";
            $('input1_c_email_check').style.display = "none";
        }else {
            $('input1_c_email_check').style.display = "";
        }
    }
	
    if($('c_ww')) {
        var ww = $('c_ww').getValue();
        var passwd = pcheck(ww);
        if(passwd){
            if(!msg) msg = passwd;
            $('input1_c_ww_check').style.display = "none";
        }else{
            $('input1_c_ww_check').style.display = "";
        }
    }
	
    if(!msg) {
        $('msgform').style.display = "none";
        $('btnform').style.display = "";
        return true;
    }else {
        $('msgform').innerHTML = msg;
        $('msgform').style.display = "";
        $('btnform').style.display = "none";
        return false;
    }

}

function submit_order_form(type)
{
    if(type == 0)
    {
        var rqstURL = websiteURL + 'js/function.ajax.php?a=submit_offerte';
    }
    else
    {
        var rqstURL = websiteURL + 'js/function.ajax.php?a=submit_indicatie';
    }
	
    var form = $('offerte');
    var secure = "";
	
    if (form['c_ww'] && form['c_email'])
    {
        secure = $F(form['c_email']) + '||' + $F(form['c_ww']);
    }
    var rqst = new Ajax.Request(rqstURL, {
        method: 'post',
		
        parameters: {
            v1: $F(form['c_bedrijfsnaam']),
            v2: $F(form['c_voornaam']),
            v3: $F(form['c_achternaam']),
            v4: $F(form['c_adres']),
            v5: $F(form['c_woonplaats']),
            v6: $F(form['c_telefoon']),
            v7: $F(form['c_url']),
            secure: secure
        },
        onSuccess: function(resp){
            if(resp.responseText != '0')
            {
                alert(resp.responseText);
                if(type == 0) {
                    parent.parent.cleanList();
                }else if(type == 1){
                    parent.parent.myLightWindow.deactivate();
                }
            }
            else
            {
                alert("Er is iets fout gegaan, probeer het opnieuw.");
            }
        }
    });
}



/* ===| Wenslijst                                        |=== */ 
/* ---------------------------------------------------------- */

function processList(count)
{
	
    var requestUrl = websiteURL + 'js/function.ajax.php?a=logininfo';
		
	
    var request = new Ajax.Request(requestUrl, {
        onSuccess: function(resp){
	
            var loggedin = resp.responseText;
            var layers1 = ['wish_l1_n1', 'wish_l1_n2'];
            var layers2 = ['wish_l2_n1', 'wish_l2_n2', 'wish_l2_n3', 'wish_l2_n4'];
            var layers3 = ['wish_l3_n1', 'wish_l3_n2'];
            var deactivate = [0, 0, 0];
            var activate   = [0, 0, 0];
			
		
            layers1.each(function(item, i){
                if($(item).style.display != 'none')	{
                    deactivate[0] = i;
                }
            });
        layers2.each(function(item, i){
            if($(item).style.display != 'none')	{
                deactivate[1] = i;
            }
        });
    layers3.each(function(item, i){
        if($(item).style.display != 'none')	{
            deactivate[2] = i;
        }
    });
					
					
    if(loggedin == 0 && count == 0) {
        activate = [0, 0, 0];
    }
    else if (loggedin == 0 && count > 0) {
        activate = [1, 1, 1];
    }
    else if (loggedin == 1 && count == 0) {
        activate = [0, 3, 0];
    }
    else if (loggedin == 1 && count > 0) {
        activate = [1, 2, 1];
    }
				
    if(activate[0] != deactivate[0]){
        kill_effect('wish_l1')
        Effect.Fade(layers1[deactivate[0]], {
            queue : {
                position : 'front',
                scope: 'wish_l1',
                limit:2
            } ,
            duration:0.3
        });
        Effect.Appear(layers1[activate[0]], {
            queue : {
                position : 'end',
                scope: 'wish_l1',
                limit:2
            } ,
            duration:0.5
        });
    }
    if(activate[1] != deactivate[1]){
        kill_effect('wish_l2')
        Effect.Fade(layers2[deactivate[1]], {
            queue : {
                position : 'front',
                scope: 'wish_l2',
                limit:2
            } ,
            duration:0.3
        });
        Effect.Appear(layers2[activate[1]], {
            queue : {
                position : 'end',
                scope: 'wish_l2',
                limit:2
            } ,
            duration:0.5
        });
    }
    if(activate[2] != deactivate[2]){
        kill_effect('wish_l3')
        Effect.Fade(layers3[deactivate[2]], {
            queue : {
                position : 'front',
                scope: 'wish_l3',
                limit:2
            } ,
            duration:0.3
        });
        Effect.Appear(layers3[activate[2]], {
            queue : {
                position : 'end',
                scope: 'wish_l3',
                limit:2
            } ,
            duration:0.5
        });
    }
}
});

$('wish_count').update(count);	
}


function addToList(id, type)
{
	
    var listitem = stringToArray(id, ".");
    if(listitem[0] == 'THE1')
    {
        var requestUrl = websiteURL + 'js/function.ajax.php?a=wish_thema_add';

        var request = new Ajax.Request(
            requestUrl,
            {
                method: 'get',
                parameters: "code=" + id,
                onSuccess: function(resp){
                    refreshList(resp.responseText, type);
                }
            }
            );
    }
    else
    {
        var requestUrl = websiteURL + 'js/function.ajax.php?a=wish_add';

        var request = new Ajax.Request(
            requestUrl,
            {
                method: 'get',
                parameters: "code=" + id,
                onSuccess: function(resp){
                    refreshList(resp.responseText, type);
                }
            }
            );
    }
}

function refreshList(count, type)
{
    if($('wishlist_ov_list'))
    {
        if(type == 0){
            detailListList();
        }else if(type == 1){
            detailIndicationList();
        }
		
        if(count == 0) onTab('t');
    }
	
    if(parent.parent.myLightWindow)
    {
        parent.parent.processList(count);
        parent.parent.myLightWindow.deactivate();
    }
    else
    {
        processList(count);
    }
}




function removeFromList(id, type)
{
    var requestUrl = 'js/function.ajax.php?a=wish_remove';
				
    var request = new Ajax.Request(
        requestUrl,
        {
            method: 'get',
            parameters: "code=" + id,
            onSuccess: function(resp)
            {
                refreshList(resp.responseText, type);
            }
        });
}

function def_removeFromList(id, type)
{
    var requestUrl = 'js/function.ajax.php?a=wish_def_remove';
				
    var request = new Ajax.Request(
        requestUrl,
        {
            method: 'get',
            parameters: "code=" + id,
            onSuccess: function(resp)
            {
                refreshList(resp.responseText, type);
                if(resp.responseText == 0) onTab('t');
            }
        });
}

function cleanList() {
    var request = new Ajax.Request(
        websiteURL + 'js/function.ajax.php?a=wish_clean', 	{
            onSuccess: function(resp){
                refreshList(0, 0);
            }
        });
}

function comesFromWishlist()
{
    var requestThema = 'js/function.ajax.php?a=random_thema';
    var screen = get_active_screen(1);
    if(screen != 'thema' && screen != 'categorie' && $('wish-div'))
    {
        new Ajax.Request(
            requestThema,
            {
                onSuccess: function(resp)
                {
                    onSelect(resp.responseText, 0);
                }
            });
    }
}

function getList() 
{
    var url = 'js/function.ajax.php?a=wish_get';
	
	
    var form = $('login');
	
    var mail = form['mail'];
    var pw = form['pw'];
	
    if($F(mail) != "" && $F(pw) != "")
    {
	   
        var request = new Ajax.Request(
            url,
            {
                method: 'post',
                parameters: {
                    mail: $F(mail),
                    pw: $F(pw)
                },
                onSuccess: function(resp)
                {
                    var response = resp.responseText;
                    if(response == parseInt(response) || response == parseFloat(response))
                    {
						
                        parent.parent.processList(response);
                        // hier lightwindow dichtgooien
                        parent.parent.myLightWindow.deactivate();
                        send_message('ophalengoed1', false);
                    }
                    else
                    {
                        alert(response);
                    }
                }
            });
    }

}



function saveList()
{
    var url = 'js/function.ajax.php?a=wish_save';
    var form = $('save_cart');
	
    var mail1 = form['mail'];
    var mail2 = form['mail2'];
    var pw1 = form['pw'];
    var pw2 = form['pw2'];
	
    if($F(mail1) != "" && $F(mail2) != "" && $F(pw1) != "" && $F(pw2) != "")
    {
        var error = false;
        if(echeck($F(mail2)) && ($F(mail1) == $F(mail2)))
        {
            error = pcheck($F(pw2));
            if($F(pw1) != $F(pw2))
            {
                error = "Wachtwoorden komen niet overeen."
            }
            else if(!error)
            {
                var request = new Ajax.Request(
                    url,
                    {
                        method: 'post',
                        parameters: {
                            mail: $F(mail2),
                            pw: $F(pw2)
                        },
                        onSuccess: function(resp)
                        {

                            var response = stringToArray(resp.responseText, '||');

                            if(response[0] == 0) {
                                alert(response[1]);
                            }
                            else {
                                parent.parent.processList(response[1]);
                                parent.parent.myLightWindow.deactivate();
                                // hier lightwindow dichtgooien
                                send_message('opslaangoed2', false);
                            }
                        }
                    });
            }
			
        }
        else
        {
            error = "Email adres(en) syntax onjuist of komen niet overeen.";
        }
       
        if (error) alert(error);
    }
}


function detailList()
{
    var url1 = 'js/function.ajax.php?u=wishdetail';
    var url2 = 'js/function.ajax.php?u=wishterms';
    var url3 = 'js/function.ajax.php?u=deadlink';
    var urlR = 'js/function.ajax.php?a=wish_countprice';
    try {

        var active_scr = get_active_screen(1);
        if(active_scr == 'thema' || active_scr == 'categorie') {
            Effect.Fade('tab_' + active_scr, {
                queue : {
                    position : 'front',
                    scope: 'tab2',
                    limit:2
                } ,
                duration:0.3
            })
        }
        $(active_scr).style.display = 'none';
	
        $('scrn1').style.display = '';
		
        new Ajax.Updater(get_active_screen(1), url1, {
            onComplete: wScrollDiv
        });
        new Ajax.Updater(get_active_screen(2), url2, {
            method: 'get',
            parameters: 'type=0'
        });
        new Ajax.Updater(get_active_screen(3), url3);
        new Ajax.Request(urlR,{
            onSuccess: function(resp) {
                var cp = stringToArray(resp.responseText, '||');
                send_message('wenslijst_offerte', cp[1]);
            }
        });
}catch(e) {}
}

function detailIndication()
{
    var url1 = 'js/function.ajax.php?u=wishindication';
    var url2 = 'js/function.ajax.php?u=wishterms';
    var url3 = 'js/function.ajax.php?u=deadlink';
    var urlR = 'js/function.ajax.php?a=wish_iCountprice';
    try {
		
        var active_scr = get_active_screen(1);
        if(active_scr == 'thema' || active_scr == 'categorie') {
            Effect.Fade('tab_' + active_scr, {
                queue : {
                    position : 'front',
                    scope: 'tab2',
                    limit:2
                } ,
                duration:0.3
            })
        }
        $(active_scr).style.display = 'none';
	
        $('scrn1').style.display = '';
	
        new Ajax.Updater('scrn1', url1, {
            onComplete: wScrollDiv
        });
        new Ajax.Updater(get_active_screen(2), url2, {
            method: 'get',
            parameters: 'type=1'
        });
        new Ajax.Updater(get_active_screen(3), url3);
        new Ajax.Request(urlR,{
            onSuccess: function(resp) {
                var cp = stringToArray(resp.responseText, '||');
                send_message('wenslijst_indicatie', cp[1]);
            }
        });

		
}catch(e) {}
  	
}

function detailListList()
{
    var updateURL = 'js/function.ajax.php?u=wishdetaillist';
    var requestURL = 'js/function.ajax.php?a=wish_countprice';
    try {
        new Ajax.Updater('wishlist_ov_list', updateURL, {
            onLoading: list_loading,
            onComplete: wScrollDiv
        });
        new Ajax.Request(requestURL,{
            onSuccess: function(resp){
                list_loading()
                var cp = stringToArray(resp.responseText, '||');
                $('cart_ap_html').innerHTML = cp[0];
                $('cart_tp_html').innerHTML = cp[1];
            }
        });
		 
}catch(e) {}
}

function detailIndicationList()
{
    var updateURL = 'js/function.ajax.php?u=wishindicationlist';
    var requestURL = 'js/function.ajax.php?a=wish_iCountprice';
    try {
        new Ajax.Updater('wishlist_ov_list', updateURL, {
            onLoading: indication_loading,
            onComplete: wScrollDiv
        });
        new Ajax.Request(requestURL,{
            onSuccess: function(resp){
                indication_loading()
                var cp = stringToArray(resp.responseText, '||');
                $('cart_ap_html').innerHTML = cp[0];
                $('cart_tp_html').innerHTML = cp[1];
            }
        });
}catch (e) {}
}

/* ===| Message                                          |=== */ 
/* ---------------------------------------------------------- */

function send_message(mN, input) {
    var url = 'js/function.ajax.php?u=message';
    try {
        kill_effect('message');
        if($('msg').style.display != 'none') {
            fade_this = 'msg';
            appear_this = 'msgNew';
        } else {
            fade_this = 'msgNew';
            appear_this = 'msg';
        }
        new Ajax.Updater(appear_this, url, {
            method: 'get',
            parameters: 'input=' + input + '&mN=' + mN,
            onSuccess: function() {
                Effect.Fade(fade_this, {
                    queue : {
                        position : 'front',
                        scope: 'message',
                        limit:2
                    } ,
                    duration:0.4
                });
                Effect.Appear(appear_this, {
                    queue : {
                        position : 'end',
                        scope: 'message',
                        limit:2
                    } ,
                    duration:1.2
                });
            }
        });
        return true;
    }
    catch(e) {
        return false;
    }
}




/* ===| Search Display Functions                         |=== */ 
/* ---------------------------------------------------------- */

function search_get_results(str, pos) {
    var url1 = 'js/function.ajax.php?u=search_cat_the';
	
    try {
		
        if(str.length > 2)
        {
            search_hints();
		
            new Ajax.Updater(get_inactive_screen(1), url1, {
                method: 'get',
                parameters: "str=" + str,
                onSuccess: function() {
                    flip_screen(1, get_active_screen(1), get_inactive_screen(1));
                }
            });
	
			
            search_list(str, pos);
		
            send_message("sc01", str);
        }
        else
        {
            send_message("searchfout01", false);
        }
    }
    catch(e) {
        return false;
    }
}


function search_list(str, pos, option) {
    var url2 = 'js/function.ajax.php?u=search_art';
    new Ajax.Updater(get_inactive_screen(3), url2, {
        method: 'get',
        parameters: "str=" + str + "&pos=" + pos,
        onSuccess: function() {
            flip_screen(3, get_active_screen(3), get_inactive_screen(3));
        }
    });
}


function search_hints() {
    var url = 'js/function.ajax.php?u=searchstat';
		
    new Ajax.Updater(get_inactive_screen(2), url, {
        method: 'get',
        onSuccess: function() {
            flip_screen(2, get_active_screen(2), get_inactive_screen(2));
        }
    });
}





/* ===| Tagcloud Display Functions                       |=== */ 
/* ---------------------------------------------------------- */

function product_list(tag, pos, option) {
    var url = 'js/function.ajax.php?u=productlist';
    try {
        new Ajax.Updater(get_inactive_screen(3), url, {
            method: 'get',
            parameters: "tag=" + tag + "&pos=" + pos + "&option=" + option,
            onSuccess: function() {
                flip_screen(3, get_active_screen(3), get_inactive_screen(3));
            }
        });
		
    }
    catch(e) {

    }
}

function subcloud(tag) {
    var url = 'js/function.ajax.php?u=subcloud';
	
    try
    {
        new Ajax.Updater('scrn2', url, {
            method: 'get',
            parameters: "tag=" + tag,
            onSuccess: function()
            {
                if(get_active_screen(2) != 'scrn2')
                    flip_screen(2, get_active_screen(2), 'scrn2');
            },
            onComplete: scrollDiv
        });
		
    }
    catch(e)
    {

    }
	
	
	
}


function thema_detail(tag) {
	
    var url = 'js/function.ajax.php?u=themadetail';
    try
    {
        new Ajax.Updater(get_inactive_screen(3),
            url,
            {
                method: 'get',
                parameters: "tag=" + tag,
                onSuccess: function()
                {
                    flip_screen(3, get_active_screen(3), get_inactive_screen(3));
                }
            }
            );
		
    }
    catch(e)
    {

    }
	

}


/* ===| Tagcloud Refreshers                              |=== */ 
/* ---------------------------------------------------------- */

function default_tag_style_maincloud() {
	
    kill_effect('pulseffect');
	
    $$('div#theCloud a').each(function(el) {
        tag = stringToArray(el.id, ".");
        $(el).style.borderColor = '#ffffff';
        $(el).style.color       = '#727272';
        $(el).style.textDecoration = "none";
        if (Element.getOpacity(el) < 1.0)
            new Effect.Opacity($(el), {
                to: 1.0
            });
    });
 	
    $$('div#catCloud a').each(function(el) {
        tag = stringToArray(el.id, ".");
        $(el).style.borderColor = '#ffffff';
        $(el).style.color       = '#727272';
        $(el).style.textDecoration = "none";
        if (Element.getOpacity(el) < 1.0)
            new Effect.Opacity($(el), {
                to: 1.0
            });
    });
}


function default_tag_style_subcloud() {
    $$('div#subsub a').each(function(el) {
        $(el).style.borderColor = '#ffffff';
        $(el).style.color       = '#727272';
        $(el).style.textDecoration = "none";
        if (Element.getOpacity(el) < 1.0)
            new Effect.Opacity($(el), {
                to: 1.0
            });
    });
}





/* ===| Tagcloud Handler Functions                       |=== */ 
/* ---------------------------------------------------------- */

function tag_select_handler(tag, option) {
    var requestCategorieUrl = 'js/function.ajax.php?a=categorie';
    var requestThemaUrl = 'js/function.ajax.php?a=thema';
	
    try {
		
        default_tag_style_maincloud();
		
        var code = stringToArray(tag, ".");
        if(code[0] == 'NEW1')
        {
            var request = new Ajax.Request(
                requestCategorieUrl,
                {
                    method: 'get',
                    parameters: "tag=" + tag,
                    onSuccess: function(resp)
                    {
 					
                        color_this(tag, "self_main_cat");

                        Effect.Pulsate(tag, {
                            duration : 32,
                            from : 0.25,
                            to: 1.00,
                            pulses : 16,
                            queue: {
                                scope : 'pulseffect'
                            }
                        });

                }
            }
            );
					
        product_list(tag, 1, option);
			
        send_message('tc01', 0);
			
    }
    else if(code[0] == 'C1')
    {
        var request = new Ajax.Request(
            requestCategorieUrl,
            {
                method: 'get',
                parameters: "tag=" + tag,
                onSuccess: function(resp)
                {
  				
                    var arrID = stringToArray(resp.responseText, "||||");
 					
                    color_this(tag, "self_main_cat");

                    Effect.Pulsate(tag, {
                        duration : 32,
                        from : 0.25,
                        to: 1.00,
                        pulses : 16,
                        queue: {
                            scope : 'pulseffect'
                        }
                    });

                cat2 = stringToArray(arrID[1], "||");
                for(i = 0; i < cat2.length; i++) {
                    color_this(cat2[i], "related_cat2");
                }
  						
                send_message('tc01', arrID[0]);
            }
        }
        );
			
    subcloud(tag);
			
    product_list(tag, 1, option);
			
			
			
}
		
else if(code[0] == 'C2') 
		
{
			
    var request = new Ajax.Request(
        requestCategorieUrl,
        {
            method: 'get',
            parameters: "tag=" + tag,
            onSuccess: function(resp)
            {
                var arrID = stringToArray(resp.responseText, "||||");
 					
                color_this(tag, "self_sub_cat");

                Effect.Pulsate(tag, {
                    duration : 32,
                    from : 0.25,
                    to: 1.00,
                    pulses : 16,
                    queue: {
                        scope : 'pulseffect'
                    }
                });
					
            cat1 = stringToArray(arrID[1], "||");
            color_this(cat1[0], "related_cat1");
  					
            send_message('tc04', arrID[0]);
        }
    }
    );
			
subcloud(tag);
			
product_list(tag, 1, option);

}
		
else if(code[0] == 'C3') 
		
{
			
    default_tag_style_subcloud();
			
    var request = new Ajax.Request(
        requestCategorieUrl,
        {
            method: 'get',
            parameters: "tag=" + tag + "&option=" + option,
            onSuccess: function(resp)
            {
                var arrID = stringToArray(resp.responseText, "||||");
 					
                cat1 = stringToArray(arrID[1], "||");
                color_this(cat1[0], "related_cat1");

                cat2 = stringToArray(arrID[2], "||");
                color_this(cat2[0], "related_cat2");
  					
                if(option != 0) {
                    color_this(option, "related_the1");
                }
  						
                color_this(tag, "self_sub_cat");
                Effect.Pulsate(tag, {
                    duration : 32,
                    from : 0.25,
                    to: 1.00,
                    pulses : 16,
                    queue: {
                        scope : 'pulseffect'
                    }
                });
						
            mess = stringToArray(arrID[0], "|");
            send_message('tc02', mess[0] + '||' + mess[1]);

        }
    }
    );
			
product_list(tag, 1, option);
			
}
		
else if(code[0] == 'THE1') 
		
{

    var request = new Ajax.Request(
        requestThemaUrl,
        {
            method: 'get',
            parameters: "tag=" + tag,
            onSuccess: function(resp)
            {
  						
                color_this(tag, "self_thema");
  					
                Effect.Pulsate(tag, {
                    duration : 32,
                    from : 0.25,
                    to: 1.00,
                    pulses : 16,
                    queue: {
                        scope : 'pulseffect'
                    }
                });
            if(option != 99) send_message('tc03', resp.responseText);
        }
    }
    );

if(option != 99) subcloud(tag);
			
if(option == 1) 
{
    product_list(tag, 1, option);
}
else 
{
    thema_detail(tag);
}
}
		
		
}
catch(e) {
    return false
}
}

function product_select_handler(code) {
    var requestUrl = 'js/function.ajax.php?a=product';
    var updateUrl = 'js/function.ajax.php?u=product';
	
    try {
		
        if(get_active_screen(1) != "categorie" && get_active_screen(1) != "thema") {
            flip_screen(1, get_active_screen(1), 'categorie');
        }
        if(get_active_screen(2) != "scrn2") {
            flip_screen(2, get_active_screen(2), 'scrn2');
        }
			
        default_tag_style_maincloud();
        default_tag_style_subcloud();
			
        var request = new Ajax.Request(
            requestUrl,
            {
                method: 'get',
                parameters: "code=" + code,
                onSuccess: function(resp)
                {
                    var arrID = stringToArray(resp.responseText, "||||");
				
                    cat1 = stringToArray(arrID[0], "||");
                    for (i = 0; i < cat1.length; i++) {
                        color_this(cat1[i], "related_cat1")
                    }

                    cat2 = stringToArray(arrID[1], "||");
                    for (i = 0; i < cat2.length; i++) {
                        color_this(cat2[i], "related_cat2")
                    }
			
                    if($('subsub')){
                        cat3 = stringToArray(arrID[2], "||");
                        color_this(cat3[0], "related_cat3")
                    }

                    the1 = stringToArray(arrID[3], "||");
                    for (i = 0; i < the1.length; i++) {
                        color_this(the1[i], "related_the1")
                    }

                }
            }
            );
		
        new Ajax.Updater(
            get_inactive_screen(3),
            updateUrl,
            {
                method: 'get',
                parameters: "code=" + code,
                onSuccess: function()
                {
                    flip_screen(3, get_active_screen(3), get_inactive_screen(3));
  					   
                }
            }
            );
		
    }
    catch(e) {
        return false;
    }
}

function product_go(code)
{
    var updateUrl = 'js/function.ajax.php?u=product';
    new Ajax.Updater(
        get_inactive_screen(3),
        updateUrl,
        {
            method: 'get',
            parameters: "code=" + code,
            onSuccess: function()
            {
                flip_screen(3, get_active_screen(3), get_inactive_screen(3));
            }
        }
        );
}

function search_select_handler(tag) {
    var s_url = 'js/function.ajax.php?u=subcloud';
		
    code = tag.split(".");
    if(code[0] == "C3") {
        new Ajax.Updater(get_inactive_screen(2), s_url, {
            method: 'get',
            parameters: "tag=" + tag,
            onSuccess : function()
            {
                flip_screen(2, get_active_screen(2), get_inactive_screen(2));
            }
        });
    }
	
	

    if (code[0] == "C1" || code[0] == "C2" || code[0] == "C3") {
        flip_screen(1, get_active_screen(1), 'categorie');
    }
    else if(code[0] == "THE1") {
        flip_screen(1, get_active_screen(1), 'thema');
    }
		
	
    tag_select_handler(tag, 0);
	
}




/* ===| Tagcloud Colors                                  |=== */ 
/* ---------------------------------------------------------- */

function color_this(id, type) {
    switch(type) {
        case "self_main_cat":
            $(id).style.color = "#285f8a";
            $(id).style.borderLeft = "4px solid #285f8a";
            $(id).style.textDecoration = "none";
            break;
        case "self_sub_cat":
            $(id).style.color = "#ff980b";
            $(id).style.borderLeft = "4px solid #ff980b";
            $(id).style.textDecoration = "none";
            break;
        case "self_thema":
            $(id).style.color = "#ff980b";
            $(id).style.borderLeft = "4px solid #ff980b";
            $(id).style.textDecoration = "none";
            break;
        case "related_cat1":
            $(id).style.color = "#285f8a";
            $(id).style.textDecoration = "underline";
            //$(id).style.borderLeft = "4px solid #285f8a";
            break;
        case "related_cat2":
            $(id).style.color = "#ff980b";
            $(id).style.textDecoration = "underline";
            break;
        case "related_cat3":
            $(id).style.color = "#ff980b";
            $(id).style.textDecoration = "underline";
            break;
        case "related_the1":
            $(id).style.color = "#ff980b";
            $(id).style.textDecoration = "underline";
            break;
		
    }
}




/* ===| Scherm Functies                                  |=== */ 
/* ---------------------------------------------------------- */

function get_active_screen(scr) {
    if (scr == 1)
    {
        if($('thema').style.display != 'none') return "thema";
        if($('categorie').style.display != 'none') return "categorie";
        if($('scrn1').style.display != 'none') return "scrn1";
        if($('shdw1').style.display != 'none') return "shdw1";
    }
    else if (scr == 2)
    {
        if($('scrn2').style.display != 'none') return "scrn2";
        if($('shdw2').style.display != 'none') return "shdw2";
    }
    else if (scr == 3)
    {
        if($('scrn3').style.display != 'none') return "scrn3";
        if($('shdw3').style.display != 'none') return "shdw3";
    }
}


function get_inactive_screen(scr) {
    if (scr == 1)
    {
        if($('scrn1').style.display != 'none')
            return "shdw1";
        else if($('shdw1').style.display != 'none')
            return "scrn1";
        else
            return "scrn1";
    }
    else if (scr == 2)
    {
        if($('scrn2').style.display != 'none') return "shdw2";
        if($('shdw2').style.display != 'none') return "scrn2";
    }
    else if (scr == 3)
    {
        if($('scrn3').style.display != 'none') return "shdw3";
        if($('shdw3').style.display != 'none') return "scrn3";
    }
}


function flip_screen(scr, from, to) 
{
    if(scr == 1) {
		
        if((to == "categorie" || to == "thema") && from != to)
        {
            kill_effect('tab1');
			
            Effect.Appear('tab_' + to, {
                queue : {
                    position : 'end',
                    scope: 'tab1',
                    limit:2
                } ,
                duration:0.5
            })
        }
		
        if((from == "thema" || from == "categorie") && from != to)
        {
            kill_effect('tab2');
			
            Effect.Fade('tab_' + from, {
                queue : {
                    position : 'front',
                    scope: 'tab2',
                    limit:2
                } ,
                duration:0.3
            })
        }

    }
	
    if ($(from) && $(from).style.display != 'none')
    {
        kill_effect('shadow' + scr + '1')
		
        Effect.Fade(from, {
            queue : {
                position : 'front',
                scope: 'shadow' + scr + '1',
                limit:2
            } ,
            duration:0.3
        })
        Effect.Appear(to, {
            queue : {
                position : 'end',
                scope: 'shadow' + scr + '1',
                limit:2
            } ,
            duration:0.5
        })
    }
    else if ($(to) && $(to).style.display != 'none')
    {
        kill_effect('shadow' + scr + '2')
		
        Effect.Fade(to, {
            queue : {
                position : 'front',
                scope: 'shadow' + scr + '2',
                limit:2
            } ,
            duration:0.3
        })
        Effect.Appear(from, {
            queue : {
                position : 'end',
                scope: 'shadow' + scr + '2',
                limit:2
            } ,
            duration:0.5
        })
    }
}




function date_from_loading()
{
    if($('date_from_loader').style.display != 'none') {
        Effect.Fade('date_from_loader', {
            queue : {
                position : 'front',
                scope: 'from_loader',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('date_from_loader', {
            queue : {
                position : 'end',
                scope: 'from_loader',
                limit:2
            } ,
            duration:0.5
        })
    }
}

function date_to_loading()
{
    if($('date_to_loader').style.display != 'none') {
        Effect.Fade('date_to_loader', {
            queue : {
                position : 'front',
                scope: 'to_loader',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('date_to_loader', {
            queue : {
                position : 'end',
                scope: 'to_loader',
                limit:2
            } ,
            duration:0.5
        })
    }
}


function day_loading()
{
    if($('day_loader').style.display != 'none') {
        Effect.Fade('day_loader', {
            queue : {
                position : 'front',
                scope: 'day_loader',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('day_loader', {
            queue : {
                position : 'end',
                scope: 'day_loader',
                limit:2
            } ,
            duration:0.5
        })
    }
}

function list_loading()
{
    if($('list_loader').style.display != 'none') {
        Effect.Fade('list_loader', {
            queue : {
                position : 'front',
                scope: 'list_loader',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('list_loader', {
            queue : {
                position : 'end',
                scope: 'list_loader',
                limit:2
            } ,
            duration:0.5
        })
    }
}

function indication_loading()
{
    if($('indication_loader').style.display != 'none') {
        Effect.Fade('indication_loader', {
            queue : {
                position : 'front',
                scope: 'indication_loader',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('indication_loader', {
            queue : {
                position : 'end',
                scope: 'indication_loader',
                limit:2
            } ,
            duration:0.5
        })
    }
}

function pop_date_from()
{
    if($('wish-date-from').style.display != 'none') {
        Effect.Fade('wish-date-from', {
            queue : {
                position : 'front',
                scope: 'pop_from',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('wish-date-from', {
            queue : {
                position : 'end',
                scope: 'pop_from',
                limit:2
            } ,
            duration:0.5
        })
    }
}

function pop_date_to()
{
    if($('wish-date-to').style.display != 'none') {
        Effect.Fade('wish-date-to', {
            queue : {
                position : 'front',
                scope: 'pop_to',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('wish-date-to', {
            queue : {
                position : 'end',
                scope: 'pop_to',
                limit:2
            } ,
            duration:0.5
        })
    }
}

function pop_day()
{
    if($('wish-day').style.display != 'none') {
        Effect.Fade('wish-day', {
            queue : {
                position : 'front',
                scope: 'pop_day',
                limit:2
            } ,
            duration:0.3
        })
    }else {
        Effect.Appear('wish-day', {
            queue : {
                position : 'end',
                scope: 'pop_day',
                limit:2
            } ,
            duration:0.5
        })
    }
}