﻿/* Include eerst het algemene JavaScript bestand */

includeJavaScript( '/bauinfoconsult/algemeen/functies.js');


var keyActions = new Array ();
var tocItemField;

function importusers(){

//	if(confirm('Do you want to send emails to updated users?'))
//	{
//		document.location.href = 'toepassingen/bouwkennis/ASP/importbackoffice.asp?sendmail=1';
//	}
//	else
//	{
		document.location.href = 'toepassingen/bouwkennis/ASP/importbackoffice.asp?sendmail=0';
//	}

}

function verwerkTocSelectItem(tocID, targetItemID, beforeItemID){


    if(tocItemField == 1){
        if(document.formulier.fld_tocItem2ID){
            if(document.formulier.fld_tocItem2ID.value == targetItemID){
                alert('Article has already been assigned to this item.')
            }else{
                document.formulier.fld_tocItemID.value = targetItemID;
                haalTocItemPad(targetItemID);
            }
        }else{
            document.formulier.fld_tocItemID.value = targetItemID;
            haalTocItemPad(targetItemID);
        }
    }else if(tocItemField == 2){
        if(document.formulier.fld_tocItemID.value == targetItemID){
            alert('Article has already been assigned to this item.')
        }else{
            document.formulier.fld_tocItem2ID.value = targetItemID;
            haalTocItemPad2(targetItemID);
        }
	}


}


function toonPopup(blWijzig){


        var test;

				tocItemField = 1;
        var url = '../prog/Toc.asp?tocID=1&class=popup&mode=select&tocItemID='+ document.formulier.fld_tocItemID.value;

        //var url = '../prog/Toc.asp?tocID=1&class=popup&mode=selectwithdocs&tocItemID='+ document.formulier.fld_tocItemID.value + '&templateIDs=10,32';

        openPopup(test, url, 'width=550px, height=500px, status, resizable, left=200, top=300, dependant=yes');


}


function showTocLink(){

        var LinkDiv = document.getElementById('openTocLink');

				haalTocItemPad(document.formulier.fld_tocItemID.value);



}

function haalTocItemPad(tocItemID){


     		if (tocItemID > 0 && tocItemID != ''){

		        var url = '../toepassingen/bouwkennis/asp/haalTocItemPad.asp?tocItem=' + tocItemID;

		        // code for Mozilla, etc.
		        if (window.XMLHttpRequest){
		            xmlhttpTocItem = new XMLHttpRequest();
		            xmlhttpTocItem.onreadystatechange = xmlhttpChangeTocItem;
		            xmlhttpTocItem.open("POST", url, true);
		            xmlhttpTocItem.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		            xmlhttpTocItem.send(request);
		        }

		        // code for IE
		        else if (window.ActiveXObject){
		            xmlhttpTocItem = new ActiveXObject("Microsoft.XMLHTTP");
		            if (xmlhttpTocItem){
		                    xmlhttpTocItem.onreadystatechange = xmlhttpChangeTocItem;
		                    xmlhttpTocItem.open("POST",url,true);
		                    xmlhttpTocItem.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		                    var request = 'code=';
		                    xmlhttpTocItem.send(request);
		    				}
		        }
				}
				else
				{
      	  var LinkDiv = document.getElementById('openTocLink');
      	  LinkDiv.innerHTML = '<a href="#" onClick="toonPopup();" title="Click to assign this article to the navigation hierarchy">Click to assign this article to the navigation hierarchy</a>';
      		xmlhttpTocItem = null;
			}

}

function xmlhttpChangeTocItem(){

        // if xmlhttp shows "loaded"
        if (xmlhttpTocItem.readyState == 4){


                // if "OK"
                if (xmlhttpTocItem.status == 200){

                        strResult = xmlhttpTocItem.responseText;
                    	  var LinkDiv = document.getElementById('openTocLink');
                    	  LinkDiv.innerHTML = '<a href="#" onClick="toonPopup();" title="Click to reassign this article to the navigation hierarchy">' + unescape(strResult) + '</a><a href="#" onClick="verwijderTocItem(\'openTocLink\', \'fld_tocItemID\');"><img src="' + imagesURL + '/verwijder.gif" alt="Verwijder"></a>';
                    		xmlhttpTocItem = null;

                }
        }



}

function verwijderTocItem(toclinkname, tocfieldname)
{
    switch( toclinkname){
        case 'openTocLink':
            popupJSFunction = 'toonPopup()';

            break;
        case 'openTocLink2':
            popupJSFunction = 'toonPopup2()';

            break;
    }

    var LinkDiv = document.getElementById(toclinkname);
    document.formulier[tocfieldname].value = '';
    LinkDiv.innerHTML = '<a href="#" onClick="' + popupJSFunction + ';" title="Click to assign this page to the navigation hierarchy">Click to assign this page to the navigation hierarchy</a>';
}

function toonPopup2(blWijzig){


        var test;

				tocItemField = 2;

        //var url = '../prog/Toc.asp?tocID=1&class=popup&mode=selectwithdocs&tocItemID='+ document.formulier.fld_tocItem2ID.value + '&templateIDs=10,32';
        var url = '../prog/Toc.asp?tocID=1&class=popup&mode=select&tocItemID='+ document.formulier.fld_tocItem2ID.value;


        openPopup(test, url, 'width=550px, height=500px, status, resizable, left=200, top=300, dependant=yes');
}

function showTocLink2(){

        var LinkDiv2 = document.getElementById('openTocLink2');

				haalTocItemPad2(document.formulier.fld_tocItem2ID.value);



}

function haalTocItemPad2(tocItemID){


     		if (tocItemID > 0 && tocItemID != ''){

		        var url = '../toepassingen/bouwkennis/asp/haalTocItemPad.asp?tocItem=' + tocItemID;

		        // code for Mozilla, etc.
		        if (window.XMLHttpRequest){
		            xmlhttpTocItem2 = new XMLHttpRequest();
		            xmlhttpTocItem2.onreadystatechange = xmlhttpChangeTocItem2;
		            xmlhttpTocItem2.open("POST", url, true);
		            xmlhttpTocItem2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		            xmlhttpTocItem2.send(request);
		        }

		        // code for IE
		        else if (window.ActiveXObject){
		            xmlhttpTocItem2 = new ActiveXObject("Microsoft.XMLHTTP");
		            if (xmlhttpTocItem2){
		                    xmlhttpTocItem2.onreadystatechange = xmlhttpChangeTocItem2;
		                    xmlhttpTocItem2.open("POST",url,true);
		                    xmlhttpTocItem2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		                    var request = 'code=';
		                    xmlhttpTocItem2.send(request);
		    				}
		        }
				}
				else
				{
      	  var LinkDiv2 = document.getElementById('openTocLink2');
      	  LinkDiv2.innerHTML = '<a href="#" onClick="toonPopup2();" title="Click to assign this article to the navigation hierarchy">Click to assign this article to the navigation hierarchy</a>';
      		xmlhttpTocItem2 = null;
			}

}

function xmlhttpChangeTocItem2(){

        // if xmlhttp shows "loaded"
        if (xmlhttpTocItem2.readyState == 4){


                // if "OK"
                if (xmlhttpTocItem2.status == 200){

                        strResult2 = xmlhttpTocItem2.responseText;
                    	  var LinkDiv2 = document.getElementById('openTocLink2');
                    	  LinkDiv2.innerHTML = '<a href="#" onClick="toonPopup2();" title="Click to reassign this article to the navigation hierarchy">' + unescape(strResult2) + '</a><a href="#" onClick="verwijderTocItem(\'openTocLink2\', \'fld_tocItem2ID\');"><img src="' + imagesURL + '/verwijder.gif" alt="Verwijder"></a>';
                    		xmlhttpTocItem2 = null;

                }
        }



}

    function openRefBK( deEditor){
        var huidig;
    	 	xrefEditor = deEditor;
        huidig = deEditor.getCurrentElement();

        if( huidig.substring( 0, 5) == "<xref") {
            alert('U kunt hier geen link maken.');
        }
        else {
            var schermNaam, nu, scherm, url;
            var breedte, hoogte;
            var veld;


            url = virDir + '/toepassingen/bouwkennis/ASP/kiesDocument.asp?functie=insertRef&veld=' + deEditor.id;
            schermnaam = 'X-Link';
            breedte = '600';
            hoogte  = '550';

            scherm = window.open( url, schermNaam, 'scrollbars=yes,resizable=no,menubar=no,status=yes,top=100,left=100,width=' + breedte +  ',height=' + hoogte);
            return false;
        }
    }



function insertXRef( id, naam, nummer)
{
    xrefEditor.insertHTMLData( '<xref id="' + id + '">' + nummer + ' ' + naam + '</xref>');
    xrefEditor.pumpEvents();
}

function bouwkennis_beeldDB ( deEditor)
{
    beelddbEditor = deEditor;
    openPopup( 'Beelddatabank', '../prog/attachBeeld.asp?productID=1&kiezen=true&nieuw=true&pagesize=9&editor=' + deEditor, 'width=500,height=500', 'status=yes');
}



/* Runtime include van javascript */
function includeJavaScript( script_filename) {

    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');

    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);

    return false;
}



