﻿// JScript File

function checkLocatie()
{
 var _loc= $('LocatieAnders');
    if( $('Locatie').value == 'Anders')
    { 
       
        
        if (_loc.style.visibility == 'hidden')
        {
           _loc.style.visibility = 'visible'; 
        }
    }
    else
    {
        _loc.style.visibility = 'hidden'; 
    }
}


function hideIt()
{
    $('contentRechts').style.visibility = 'hidden';    
}

function showIt()
{
    $('contentRechts').style.visibility = 'visible';    
}


function toggleItem(s, id, classNaam, tagName, ParentNode)
{
    if(s && s.blur)
    {
        s.blur();
    }
    
    var _newP = $(id);
    var _check = ParentNode;

    if(_newP.clientHeight == 0)
    {
        if(_check == true)
        {        
            var _p = s.parentNode.parentNode.getElementsByTagName(tagName);
        }
          
        else
        {
            var _p = _newP.parentNode.getElementsByTagName(tagName);
        }

        for(i=0; i<_p.length; i++)
        {
            if(_p[i].className == classNaam && _p[i].id != _newP.id)
            {
                $(_p[i]).morph('height:0px');
            }
         }
        _newP.morph('height:' + (_newP.scrollHeight + 20) + 'px');
    }
}



function initContactSjabloon(lat, lng)
{
    if (GBrowserIsCompatible()) 
    {
        var map = new GMap2(document.getElementById("googlemaps"));
        map.addControl(new GSmallMapControl());
        map.setCenter(new GLatLng(lat, lng), 13);
        var icon = new GIcon();
        icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
        icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
        icon.iconSize = new GSize(12, 20);
        icon.shadowSize = new GSize(22, 20);
        icon.iconAnchor = new GPoint(6, 20);
        icon.infoWindowAnchor = new GPoint(5, 1);
        var point = new GLatLng(lat, lng);
        map.addOverlay(new GMarker(point, icon));
    }
    
}


// Slider
var slider = null;
var check = false;
var currentId = null;

var id = null;
var list = null;
var maxLenght = null;
var nextId = null;

function makeSlideReady()
{      
    
    id = $('sliderDiv'); 
    list = id.getElementsByTagName('div');
    maxLenght = list.length -1;
    check = true;
    currentId = 0;
    slider = setTimeout("slideIt()", '8000');
}

function nextSlide(s)
{
    if(s)
        s.blur();     

    if(slider != null)
        clearTimeout(slider);
        
    var _check = currentId + 1;


    if(_check != maxLenght)
    { 
       nextId = currentId + 1;       
       new Effect.Move(list[currentId], { x: 240, y: 0, mode: 'relative', afterFinish: SlideFinish });          
    }   
    else
    {
       new Effect.Move(list[currentId], { x: 240, y: 0, mode: 'relative', afterFinish: SlideFinish });    
       nextId=0;
    } 
}


function SlideFinish(obj)
{
    Effect.Appear(list[nextId], { duration: 1 });
    obj.element.style.display = "none";
    obj.element.style.left = "";
    
    currentId = nextId;
    slider = setTimeout("slideIt()", '8000');
}

function prevSlide(s)
{
    if(s)
        s.blur();    
          
    if(slider != null)
        clearTimeout(slider);
        
    if(currentId == 0)
    {
       new Effect.Move(list[currentId], { x: 240, y: 0, mode: 'relative', afterFinish: SlideFinish });         
       nextId = maxLenght -1;
    }
    else
    {
       nextId = (currentId - 1);       
       new Effect.Move(list[currentId], { x: 240, y: 0, mode: 'relative', afterFinish: SlideFinish }); 
    }
}

function slideIt()
{
    nextSlide();
}

function initFlash()
{
    var FO = { movie:"Custom/Components/FrontEnd/flash/Personen.swf", width:"320", id:"Personen", height:"364",majorversion:"7", build:"40", wmode:"transparent"};
    UFO.create(FO, "rechtsFlash");
}

function ShowProducts(deel, persoon) {
    WebService.GetProduct(persoon, deel, ShowProducts_Callback);
}

function ShowProducts_Callback(response) 
{
    showIt();
    $('flash-MSG').style.display = 'none';
    $('contentRechts').innerHTML = response;
}


function ShowMensen(id)
{
    WebService.GetMens(id, ShowMensen_Callback);
}

function ShowMensen_Callback(response) 
{
    $('MensenDiv').innerHTML = response;
}


function swapProduct(titel, productcode, text, picture) 
{
    $('PopTitel').innerHTML = titel;
    $('PopCode').innerHTML = productcode;
    $('PopUptxt').innerHTML = text;
    if(picture)
    {
        $('productAfbeelding').src = picture.replace(/&amp;/gi, "&");
        $('productAfbeelding').style.display = '';
    }
    else
        $('productAfbeelding').style.display = 'none';
          
    oPopUp.Show();
}

function swapOrtho(titel, categorie, isbn, schrijver, text, picture, bijlage) 
{    
    $('popUpTitle').innerHTML = categorie;
    $('PopTitel').innerHTML = titel;
    $('PopCode').innerHTML = schrijver;
    $('ISBN').innerHTML = isbn;
    $('PopUptxt').innerHTML = text;
    if(picture)
    {
        $('productAfbeelding').src = picture.replace(/&amp;/gi, "&");
        $('productAfbeelding').style.display = '';
    }
    else
        $('productAfbeelding').style.display = 'none';
    if(bijlage)
    {
        $('BijlageDiv').style.display = 'block';
        $('BijlageAnchor').href = bijlage.replace(/&amp;/gi, "&");
    }
    else
        $('BijlageDiv').style.display = 'none';
        
    oPopUp.Show();
}


function swapMe(name, code, text, img) {
    var targetDiv = document.getElementById('ajax-content');

    if (targetDiv.hasChildNodes()) {
        while (targetDiv.childNodes.length >= 1) {
            targetDiv.removeChild(targetDiv.firstChild);
        }

    }

    var newImage = new Image();
    newImage.src = img;


    var newP = document.createElement('p');
    var pText = document.createTextNode(name);
    newP.appendChild(pText);

    var newLink = new Image();
    newLink.src = "Custom/Components/FrontEnd/images/meer-informatie.gif";
    newLink.onclick = function() { swapProduct(name, code, text, img); };

    targetDiv.appendChild(newImage);
    targetDiv.appendChild(newP);
    targetDiv.appendChild(newLink);

}

function closePopUp(s)
{
	if(s)
		s.blur();
	
	oPopUp.Hide();
}

// Online Afspraak Maken

function afspraakMaken(o, h)
{
    $('Verzenden').blur();
    
    $('AjaxImage').src = 'Custom/Components/FrontEnd/images/ajax.gif';
    $('AjaxImage').style.display = '';
    $('Verzenden').style.display = 'none';
        
    WebService.AfspraakMaken(o, h, afspraakMaken_Callback);
}

function afspraakMaken_Callback(response)
{       
    $('afspraakMaken').innerHTML = response ;    
}

function contactOpnemen(o, h)
{
    $('Verzenden').blur();
    
    $('AjaxImage').src = 'Custom/Components/FrontEnd/images/ajax.gif';
    $('AjaxImage').style.display = '';
    $('Verzenden').style.display = 'none';
        
    WebService.ContactOpnemen(o, h, contactOpnemen_Callback);
}

function contactOpnemen_Callback(response)
{       
    $('contactOpnemen').innerHTML = response;    
}

function showHelpText(s)
{
    var _topMove = 10;        
    var _imgs = s.getElementsByTagName('img');
    var _img = _imgs[0];
    
    if (_img)
    {
        var v = "<b>" + s.id.replace("_Validator", "") + "</b><br/><br/>" + _img.alt.replace("\"", "'");
        var _div = $("HelpTekst");
        $("HelpTekstTarget").innerHTML = v;
        _div.style.display = 'block';
        _div.style.top = (S_General.Position.Top(s) + 5) + 'px';
        _div.style.left = (S_General.Position.Left(s) - 220) + 'px';
        _img.title = "";
    }
}

function initValidatorCells()
{
    var _tds = document.getElementById('formulierTabel').getElementsByTagName('span');
	
    for(var i=0;i<_tds.length;i++)
    {
        var _td = _tds[i];
        if(_td.id.indexOf('_Validator') >= 0)
        {
            _td.onmouseover = new Function("showHelpText(this);");
            _td.onmouseout = new Function("$('HelpTekst').style.display = 'none';");
            _td.alt = "";
        }
    }	  
}