﻿
function remove_element( id )
{
    var element = document.getElementById(id);
    
    if ( element )
        element.parentNode.removeChild( element ) ;
}

function display_element( id, display )
{
    var element = document.getElementById(id);
    element.style.display = display;
}

function disableElement(id, disabled)
{
    var element = document.getElementById(id);
    element.disabled = disabled ;
}

function disableElements(id1, id2, disabled )
{
    disableElement(id1, disabled ) ;
    disableElement(id2, disabled ) ;
}

function DeleteItem()
{
	var Delete = confirm('Verwijderen?');

	return (Delete);
}

function SetToZero(id)
{
    var element = document.getElementById(id);
    
    //element.selectedIndex = 0 ;
    element.value = '0' ;
    
    GetSelectedValues() ;
}

function select_focus(id)
{
    var element = document.getElementById(id);
    element.select() ;
}

function GetForm()
{
    var theForm = document.forms['aspnetForm'];
    if (!theForm)
        theForm = document.aspnetForm;
        
    if ( !theForm )
        theForm = document.forms['form1'];
        
    if (!theForm)
        theForm = document.form1;
        
    return theForm ;
}

function GetSelectedValues()
{
    var theForm = GetForm() ;

    var action = ( theForm )
        ? theForm.getAttribute("action")
        : "." ;
    
    var form = document.createElement("form");
    form.setAttribute("method", "POST");
    form.setAttribute("action", action);
    document.body.appendChild( form ) 
    
    var i = 0 ;
    while ( true )
    {
        //var id = "ctl00_ctl00_Body_ContentPlaceHolder_Content_ucResultaatset1_ListView1_ctrl" + i + "_DropDownList1" ;
        var id = "ctl00_ctl00_Body_ContentPlaceHolder_Content_ucResultaatset1_ListView1_ctrl" + i + "_TextBox1" ;
        var id2 = "ctl00_ctl00_Body_ContentPlaceHolder_Content_ucResultaatset1_ListView1_ctrl" + i + "_TextBox2" ;
        
        var element = document.getElementById( id ) ;
        var element2 = document.getElementById( id2 ) ;
        
        if ( ! element )
        {
            //id = "ucResultaatset1_ListView1_ctrl" + i + "_DropDownList1" ;
            id = "ucResultaatset1_ListView1_ctrl" + i + "_TextBox1" ;
            id2 = "ucResultaatset1_ListView1_ctrl" + i + "_TextBox2" ;
            element = document.getElementById( id ) ;
            element2 = document.getElementById( id2 ) ;
        }
        
       
        i++ ;
            
        if ( element == null )
            break ;
        else
        {
            var value = element.value ;
            var value2 = element2.value ;
            
            var item = value + ":" + value2 ;
                
            var input = document.createElement("input");
            input.setAttribute("name", "selecties");
            input.setAttribute("type", "hidden");
            input.setAttribute("value", item) ;
            
            form.appendChild( input ) ;
        }
    }
    
    form.submit() ;
}

function Shake_This( id )
{
    var element = document.getElementById(id);
    if ( element )
        new Effect.Shake(element);
}

var timeoutID = -1 ;
function SpaceDivs()
{
    timeoutID = window.setInterval( "SpaceDiv('footer', 'rightside')", 500 );
}

function SpaceNieuwsbalk()
{
    var div_rightside = document.getElementById('rightside');
    var curleft_curtop = findPos(div_rightside) ;
    
    var nieuwsbalk = document.getElementById('Nieuwsbalk');
    if ( nieuwsbalk != null )
    {
        var curleft = curleft_curtop[0] - 290 ;
        if ( curleft > 0 )
            nieuwsbalk.style.width = (curleft_curtop[0] - 290) + "px" ;
    }
}

var height_rightside = 0 ;
var max_corrections = 2;

function SpaceDiv( footer, rightside )
{
    var div_footer = document.getElementById(footer);
    var div_rightside = document.getElementById(rightside);
    
    if ( div_footer && div_rightside)
    {
        var curleft_curtop = findPos( div_footer ) ;
        
        if ( curleft_curtop[1] > 500 )
        {
            if ( height_rightside + 300 < curleft_curtop[1] )
            {
                height_rightside = curleft_curtop[1] - div_rightside.offsetTop ;
            
                div_rightside.style.height = height_rightside + "px" ;
                
                max_corrections-- ;
                if ( max_corrections == 0 )
                    window.clearTimeout(timeoutID);
             }
        }
    }
}

// http://www.quirksmode.org/js/findpos.html
function findPos(obj)
{
	var curleft = curtop = 0;
	
	if (obj.offsetParent)
        do  {
    			curleft += obj.offsetLeft;
    			curtop += obj.offsetTop;
    	    }
    	while (obj = obj.offsetParent);

    return [curleft,curtop];
}

function CallPage()
{
    var xmlhttp = new XMLHttpRequest();

    if ( ! xmlhttp )
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

    if ( xmlhttp != null )
    {
        xmlhttp.open( "GET", "/KeepAlive.aspx?" + AddTail(), false );
        xmlhttp.send( null );
    }
}

// http://www.quirksmode.org/js/popup.html
function popitup(url)
{
	var newwindow = window.open(url, 'Kleurenstaal', 'top=50,left=50,height=625,width=600');
}

function Bevestiging(id)
{
    var answer = confirm("Combinatie niet op voorraad. Doorgaan?");
    
    document.cookie = "bevestiging=" + escape(answer) ;
    
    if ( ! answer )
    {
        var effect_1 = Effect.SlideUp(id,{duration:1.0});
        display_element('a' + id, 'block');
    }
    
    return answer ;
}

function SetIFrameHeight(id)
{
    var iframe_id = GetIframe(id) ;
    
    var scrollHeight = iframe_id.contentWindow.document.body.scrollHeight ;
    if ( scrollHeight < 50 )
        scrollHeight = 400 ;
    
    var offset = 2 ;

    iframe_id.style.height = ( scrollHeight + offset ) + "px";
   
}

function ResetWinkelWagen(id)
{
    var iframe_id = GetIframe(id) ;
   
    var url = iframe_id.src + "?" + AddTail() ;
    
    //iframe_id.location = url ;
    iframe_id.src = url ;
}

function LinkNaarAfrekenen(pagina)
{
    parent.document.location = pagina ;
}

function GetIframe(id)
{
    var iframe_id = parent.document.getElementById(id);
    
    return iframe_id ;
}

function AddTail()
{
    var d = new Date() ;
    
    var anticache = d.getHours() * 60 * 60 + d.getMinutes() * 60 + d.getSeconds() ;
    
    var tail = "t=" + anticache ;
    
    return tail ;
}

function clickButton(e, buttonid)
{ 
    var evt = ( e )
        ? e
        : window.event ;

      var bt = document.getElementById(buttonid);

      if (bt)
          if (evt.keyCode == 13)
          { 
                bt.click(); 

                return false; 
          } 
}

function SelectItemFromDropDownList( DropDownListId, kleur, kleur_BEZQUAL )
{
    var DropDownList = document.getElementById(DropDownListId); 
    
    if ( kleur == "0000" )
        DropDownList.selectedIndex = 1 ;
    else
        for ( i = 0 ; i < DropDownList.options.length ; i++ )
        {
            if (DropDownList.options[i].value == kleur_BEZQUAL || DropDownList.options[i].value.indexOf( kleur ) == 0 )
            {
                DropDownList.selectedIndex = i;
                break;
            }
        }
    
    var theForm = GetForm() ;
    theForm.submit();
}

function stopError()
{
    return true;
}
window.onerror = stopError;

window.setInterval( "CallPage()", 60000 * 10 )
