var l_intCountLeft = 0;
var l_intCountRight = 0;
var l_intMax = 0;
var XMLHttpRequestObject = false;
var regexEmail = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
var regexPostcode = /^([1-9]{1}\d{3}\s{0,1}[a-zA-Z]{2}$)/;


function menudetails(p_strCasesId)
{
    ophalenMenu(p_strCasesId);
    ophalenCases(p_strCasesId);
    setTimeout('replaceSifrCases()', 50);
}

function menudetailsVoorbeelden(p_strVoorbeeldId, p_strProductId)
{
    ophalenMenuVoorbeelden(p_strVoorbeeldId, p_strProductId);
    setTimeout('ophalenVoorbeelden('+p_strVoorbeeldId+', '+p_strProductId+')', 50);
    setTimeout('replaceSifrCases()', 25);
}

function replaceSifrCases()
{
    sIFR.replaceElement(named({sSelector:".sIFRTitel", sFlashSrc:"/include/sifr/metaplus.swf", sColor:"#dc2c33", sLinkColor:"#dc2c33", sHoverColor:"#dc2c33", sWmode:"transparent"}));
}

function ophalenMenuVoorbeelden(p_strVoorbeeldId, p_strProductId)
{
    xmlHttp2=GetXmlHttpObject()
    if (xmlHttp2==null)
       {
          alert ("Browser does not support HTTP Request")
          return
        } 
    var url="/Templates/VoorbeeldenMenu.aspx?"
    
    if(p_strVoorbeeldId!="undefined")
    {
        url=url+"&rId="+p_strVoorbeeldId
    }
    if(p_strProductId!="undefined")
    {
        url=url+"&pId="+p_strProductId
    }
    xmlHttp2.open("GET",url,true)
    xmlHttp2.onreadystatechange = function()
        {
            if (xmlHttp2.readyState == 4 && xmlHttp2.status == 200) 
            {
             document.getElementById('VoorbeeldenMenu').innerHTML = xmlHttp2.responseText;
            }
       }
    xmlHttp2.send(null)
}

function ophalenVoorbeelden(p_strVoorbeeldId, p_strProductId)
{
    var l_objMenuDiv = document.getElementById('subMenuItems_'+p_strProductId);
    if (l_objMenuDiv)
    {
        l_objMenuDiv.className = 'subMenuItems red';
        for (var n=0;n<l_objMenuDiv.childNodes.length;n++) 
        {
            if (l_objMenuDiv.childNodes[n].className == 'redArrowDown')
            {
                l_objMenuDiv.childNodes[n].style.display = 'block';
            }
        }
    }

    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    } 
    var url="/Templates/VoorbeeldenDetails.aspx?"
    
    if(p_strVoorbeeldId!="undefined")
    {
        url=url+"&rId="+p_strVoorbeeldId
    }
    xmlHttp.open("GET",url,true)
    xmlHttp.onreadystatechange = function()
        {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
            {
             document.getElementById('VoorbeeldenDetails').innerHTML = xmlHttp.responseText;
            }
        }

    xmlHttp.send(null)
    setTimeout('replaceSifrCases()', 250);
}

function ophalenMenu(p_strCasesId)
{
    var div = document.getElementById('oplossingBox');
    var x = document.getElementsByTagName('input');
    var waardeCB="";
    for (var i=0;i<x.length;i++) 
    {
        if((document.getElementsByTagName("input")[i].type == "checkbox") && (x[i].checked)) {
            if (waardeCB.length != 0)
                {
                    waardeCB = waardeCB + ",";
                }
            waardeCB = waardeCB + x[i].value;
        }
    }

    xmlHttp2=GetXmlHttpObject()
    if (xmlHttp2==null)
       {
          alert ("Browser does not support HTTP Request")
          return
        } 
    var url="/templates/casesMenu.aspx?"
    
    if(p_strCasesId!="undefined")
    {
        url=url+"&rId="+p_strCasesId
    }
    if(waardeCB!="")
    {
        url=url+"&oplossing="+waardeCB
    }
    xmlHttp2.open("GET",url,true)
    xmlHttp2.onreadystatechange = function()
        {
            if (xmlHttp2.readyState == 4 && xmlHttp2.status == 200) 
            {
             document.getElementById('casesMenu').innerHTML = xmlHttp2.responseText;
            }
       }
    xmlHttp2.send(null)
}

function ophalenCases(p_strCasesId)
{
    var l_objSubMenuItems = (document.getElementById('SubMenuCasesBtn') != null) ? document.getElementById('SubMenuCasesBtn').childNodes : null;
    var l_objMenuDiv = document.getElementById('subMenuItems_'+p_strCasesId);
    var div = document.getElementById('oplossingBox');
    var x = document.getElementsByTagName('input');
    var waardeCB="";
    
    if (l_objSubMenuItems)
    {
        for (var i=0;i<l_objSubMenuItems.length;i++) 
        {
            if (l_objSubMenuItems[i].className == 'subMenuItems red')
            {
                l_objSubMenuItems[i].className = 'subMenuItems';
                for (var n=0;n<l_objSubMenuItems[i].childNodes.length;n++) 
                {
                    if (l_objSubMenuItems[i].childNodes[n].className == 'redArrowDown')
                    {
                        l_objSubMenuItems[i].childNodes[n].style.display = 'none';
                    }
                }
            }
        }
        if (l_objMenuDiv)
        {
            l_objMenuDiv.className = 'subMenuItems red';
            for (var n=0;n<l_objMenuDiv.childNodes.length;n++) 
            {
                if (l_objMenuDiv.childNodes[n].className == 'redArrowDown')
                {
                    l_objMenuDiv.childNodes[n].style.display = 'block';
                }
            }
        }
    }
    
    for (var i=0;i<x.length;i++) 
    {
        if((document.getElementsByTagName("input")[i].type == "checkbox") && (x[i].checked)) 
        {
            if (waardeCB.length != 0)
            {
                waardeCB = waardeCB + ",";
            }
            waardeCB = waardeCB + x[i].value;
        }
    }

    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
        alert ("Browser does not support HTTP Request")
        return
    } 
    var url="/templates/casesDetails.aspx?"
    
    if(p_strCasesId!="undefined")
    {
        url=url+"&rId="+p_strCasesId
    }
    if(waardeCB!="")
    {
        url=url+"&oplossing="+waardeCB
    }
    xmlHttp.open("GET",url,true)
    xmlHttp.onreadystatechange = function()
        {
            if (xmlHttp.readyState == 4 && xmlHttp.status == 200) 
            {
             document.getElementById('casesDetails').innerHTML = xmlHttp.responseText;
            }
        }

    xmlHttp.send(null)
 setTimeout('replaceSifrCases()', 250);
}

function GetXmlHttpObject()
{ 
    var objXMLHttp=null
    if (window.XMLHttpRequest)
    {
       objXMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
       objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    return objXMLHttp
} 

function setItemMoveLeft(l_intAantal)
{
    l_intMax = l_intAantal -5;
    if(l_intCountLeft<l_intMax)
    {
        l_intCountLeft = l_intCountLeft + 1;
        l_intCountRight = l_intCountRight  -1;
    }
    moveLeft(document.getElementById('SubMenuCasesBtn').offsetLeft);
}

function moveLeft(i)
{
// width menuitem 164  start = 28

    if (i>(28 -(164*l_intCountLeft)) && l_intCountLeft<=l_intMax)
    {
        i = i-4;
        document.getElementById('SubMenuCasesBtn').style.left = i + 'px';
        timer=setTimeout("moveLeft("+i+")",10); //aantal milliseconden tussen de pixelverschuiving
    }
}

function setItemMoveRight(l_intAantal)
{
    if(l_intCountRight < 0)
    {
        l_intCountRight = l_intCountRight + 1;
        l_intCountLeft = l_intCountLeft - 1;
    }
    l_intMax = l_intAantal -5;
    moveRight(document.getElementById('SubMenuCasesBtn').offsetLeft);
   
}

function moveRight(i)
{
    if (((i)<(28+(l_intCountRight*164))) && (l_intCountRight <= 0)&& (i!=28))
    {
        i = i+4;
        document.getElementById('SubMenuCasesBtn').style.left = i + 'px';
        timer=setTimeout("moveRight("+i+")",10); //aantal milliseconden tussen de pixelverschuiving
    }
}


function actiefMenu(p_strMenuId)
{
    document.getElementById('menuItem'+p_strMenuId).style.backgroundImage="url('/images/menuItem_actief.gif')";
}

function nonActiefMenu(p_strMenuId)
{
    document.getElementById('menuItem'+p_strMenuId).style.backgroundImage="url('/images/menuItem.gif')";
}

function checkCases()
{
    document.FormCases.submit();
}

function checkForm()
{

    if(document.getElementById('naam').value=='' )
    {
        window.alert('Naam is verplicht.');
        document.getElementById('naam').focus();
        return false;
    }
    if(document.getElementById('email').value=='' )
    {
        window.alert('E-mail adres is verplicht.');
        document.getElementById('email').focus();
        return false;
    }
    else if(!regexEmail.test(document.getElementById('email').value))
    { 
        alert("Het door u ingevulde emailadres is niet correct"); 
        document.getElementById('email').focus(); 
        return false; 
    }
    if(document.getElementById('telefoonnummer').value=='')
    {
        window.alert('Telefoonnummer is verplicht.');
        document.getElementById('telefoonnummer').focus();
        return false;
    }
    else if (document.getElementById('telefoonnummer').value.length < 10)
    {
        window.alert('Telefoonnummer moet minimaal 10 cijfers zijn.');
        document.getElementById('telefoonnummer').focus();
        return false;
    }
    document.FormContact.submit();
}

function startEnlargeStelVraag()
{
    enlargeStelVraag(0)
}

function enlargeStelVraag(p_intCount)
{
    //Enlarge Div
    var l_objDiv = document.getElementById('stelVraag');    
    l_objDiv.onclick = '';
    document.getElementById('stelVraagTitel').style.cursor = 'default';
    var l_intDivHeight = l_objDiv.offsetHeight - 34;
    var l_intDivTop = l_objDiv.offsetTop;

    if ((l_intDivHeight + 4) > 87)
    {
        l_objDiv.style.height = '87px';
    }
    else
    { 
        l_objDiv.style.height = (l_intDivHeight + 4) + 'px';
    }
    if ((l_intDivTop - 2) < -17)
    {
        l_objDiv.style.top = '-17px';
    }
    else
    { 
        l_objDiv.style.top = (l_intDivTop - 2) + 'px';
    }
    
    //Enlarge TextArea
    var l_objTextArea = document.getElementById('stelVraagVraag');
    l_objTextArea.style.display = 'block';
    var l_intTextAreaHeight = l_objTextArea.offsetHeight - 2;

    if ((l_intTextAreaHeight + 3) > 44)
    {
        l_objTextArea.style.height = '44px';
    }
    else
    { 
        l_objTextArea.style.height = (l_intTextAreaHeight + 3) + 'px';
    }
    
    //Enlarge Input   
    var l_objInput = document.getElementById('stelVraagEmail');
    l_objInput.style.display = 'block';
    var l_intInputHeight = l_objInput.offsetHeight - 2;

    if ((l_intInputHeight + 1) > 18)
    {
        l_objInput.style.height = '18px';
    }
    else
    { 
        l_objInput.style.height = (l_intInputHeight + 1) + 'px';
    }
    
    //Enlarge Image
    var l_objImage = document.getElementById('stelVraagImage');
    l_objImage.style.display = 'block';
    var l_intImageHeight = l_objImage.offsetHeight;

    if ((l_intImageHeight + 1) > 18)
    {
        l_objImage.style.height = '18px';
    }
    else
    { 
        l_objImage.style.height = (l_intImageHeight + 1) + 'px';
    }
    
    p_intCount = p_intCount + 1;
    
    if (p_intCount < 20)
    {
        setTimeout('enlargeStelVraag('+p_intCount+')',1)
    }
}

function shrinkStelVraag(p_intCount)
{
    //Shrink Div
    var l_objDiv = document.getElementById('stelVraag');    
    l_objDiv.onclick = '';
    var l_intDivHeight = l_objDiv.offsetHeight - 34;
    var l_intDivTop = l_objDiv.offsetTop;

    if ((l_intDivHeight - 4) < 15)
    {
        l_objDiv.style.height = '15px';
    }
    else
    { 
        l_objDiv.style.height = (l_intDivHeight - 4) + 'px';
    }
    if ((l_intDivTop + 2) > 20)
    {
        l_objDiv.style.top = '20px';
    }
    else
    { 
        l_objDiv.style.top = (l_intDivTop + 2) + 'px';
    }
    
    //Enlarge TextArea
    var l_objTextArea = document.getElementById('stelVraagVraag');
    var l_intTextAreaHeight = l_objTextArea.offsetHeight - 2;

    if ((l_intTextAreaHeight - 3) < 0)
    {
        l_objTextArea.style.height = '0px';
        l_objTextArea.style.display = 'none';
    }
    else
    { 
        l_objTextArea.style.height = (l_intTextAreaHeight - 3) + 'px';
    }
    
    //Enlarge Input   
    var l_objInput = document.getElementById('stelVraagEmail');
    var l_intInputHeight = l_objInput.offsetHeight - 2;

    if ((l_intInputHeight - 1) < 0)
    {
        l_objInput.style.height = '0px';
        l_objInput.style.display = 'none';
    }
    else
    { 
        l_objInput.style.height = (l_intInputHeight - 1) + 'px';
    }
    
    //Enlarge Image
    var l_objImage = document.getElementById('stelVraagImage');
    var l_intImageHeight = l_objImage.offsetHeight;

    if ((l_intImageHeight - 1) < 0)
    {
        l_objImage.style.height = '0px';
        l_objImage.style.display = 'block';
    }
    else
    { 
        l_objImage.style.height = (l_intImageHeight - 1) + 'px';
    }
    
    p_intCount = p_intCount + 1;
    
    if (p_intCount < 20)
    {
        setTimeout('shrinkStelVraag('+p_intCount+')',1)
    }
    else
    {
        l_objDiv.onclick = startEnlargeStelVraag;
        document.getElementById('stelVraagTitel').style.cursor = 'pointer';
    }
}

function checkStelVraag(p_objForm)
{
    if(document.getElementById('stelVraagVraag').value=='' || document.getElementById('stelVraagVraag').value=='Uw vraag...')
    {
        window.alert('U dient een vraag in te vullen');
        document.getElementById('stelVraagVraag').focus();
        return false;
    }
    if(document.getElementById('stelVraagEmail').value=='' || document.getElementById('stelVraagEmail').value=='Uw e-mailadres...')
    {
        window.alert('E-mail adres is verplicht.');
        document.getElementById('stelVraagEmail').focus();
        return false;
    }
    else
    {
        if(!regexEmail.test(document.getElementById('stelVraagEmail').value))
        { 
            alert("Het door u ingevulde e-mailadres is niet correct"); 
            document.getElementById('stelVraagEmail').focus(); 
            return false; 
        } 
    }
}



function clickedOutsideElement(e) {
    if (!e) var e = window.event;
    var l_objElement = getEventTarget(e);

    while(l_objElement != null) {
        if(l_objElement.id == 'stelVraag')
            return false;

        l_objElement = l_objElement.offsetParent;
    }

    return true;
}

function getEventTarget(l_objEvent) {
    var l_objTarget = (l_objEvent.target) ? l_objEvent.target : l_objEvent.srcElement;

    if(l_objTarget != null) {
        if(l_objTarget.nodeType == 3)
            l_objTarget = l_objTarget.parentNode;
    }

    return l_objTarget;
    
}

document.onclick = function(e) {
    if(clickedOutsideElement(e))
    {
        if (document.getElementById('stelVraag').offsetHeight == 121)
        {
            shrinkStelVraag(0);
        }
    }
}

