﻿// JScript File

/**
* --------------------------- TEXT GIF -------------------------------
*/

function textEditorGifError(textGif)
{
    textGif.src = "seResource/seImages/seTextGifLoading.gif";
    
    pathParts = textGif.src.split("/"); 
    textGif.src = "seMaakTextGif.ashx?text=" + textGif.alt + "&width=" + textGif.width + "&height=" + textGif.height + textGif.name;
    textGif.onerror = null;
}

// Oude versie van de textgif error script
function textGifError(textGif)
{
    textGif.src = "editor/seResource/seImages/seTextGifLoading.gif";
    
    pathParts = textGif.src.split("/"); 
    textGif.src = "editor/seMaakTextGif.ashx?text=" + textGif.alt + "&width=" + 
        textGif.width + "&height=" + textGif.height + textGif.name;
    textGif.onerror = null;
}

function textGifError2(textGif, uniek)
{
    textGif.src = "editor/seResource/seImages/seTextGifLoading.gif"; 
    textGif.src = "editor/seMaakTextGif.ashx?uniek2=" + uniek + "&rnd=" + (Math.random()*10000);
    textGif.onerror = null;
}

function urlDecode(str){
    str=str.replace(new RegExp('\\+','g'),' ');
    return unescape(str);
}
function urlEncode(str){
    str=escape(str);
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
}

/**
* --------------------------- seAfbeelding -------------------------------
*/

var seAfbeeldingTimerRunning = 0;
var seAfbeeldingObj = new Array();

function seAfbeeldingError(seAfbeelding)
{
    seAfbeelding.onerror = null;
    seAfbeelding.src = "editor/seResource/seImages/sePlaceHolderImage.gif";
   
    seAfbeeldingObj.push(seAfbeelding);
    if (!seAfbeeldingTimerRunning) 
    {
        seAfbeeldingTimerRunning = setTimeout("seAfbeeldingenTimedLoad()", 10);
    }
}

function seAfbeeldingenTimedLoad(myTel)
{      
    myAf = seAfbeeldingObj.shift();
    if (myAf != null)
    {
        myAf.src = "editor/seMaakAfbeelding.ashx?" + myAf.name;
        clearTimeout(seAfbeeldingTimerRunning);
        seAfbeeldingTimerRunning = setTimeout("seAfbeeldingenTimedLoad()", 500);
    } else {
        seAfbeeldingTimerRunning = null;
    } 
}


function seLoadAfbeeldingen()
{
    for(i=0;i<seAfbeeldingenArray[0].length-1;i++) {
        var afObj = document.getElementById(seAfbeeldingenArray[0][i][1]);
        if (afObj != null)
        {
            afObj.src = seAfbeeldingenArray[0][i][0];
        } 
    }
}

var seClientLoadList = new Array();

function seClientLoadCL() {
	this.seAfbeelding = null; // afbeelding obj
	this.seFullPath = ""; 
	this.seLoadClientSideGroep = ""; 
	this.seLoadClientSideVolgorde = ""; 
	this.sePropList = ""; 
}

function seAfbeeldingClientLoad(seAfbeelding)
{
    seAfbeelding.onload = null;
    
    var myClientLoadCL	            = new seClientLoadCL();
    myClientLoadCL.seAfbeelding     = seAfbeelding;
    myClientLoadCL.sePropList       =  seAfbeelding.name;
    
    var propsArr= seAfbeelding.name.split("&");
    for(i=0;i<propsArr.length;i++) {
        var propsArrLos = propsArr[i].split("=");
       
        if (propsArrLos[0] == "seFullPath")
        {
            myClientLoadCL.seFullPath = propsArrLos[1];
        }
        if (propsArrLos[0] == "seLoadClientSideGroep")
        {
            myClientLoadCL.seLoadClientSideGroep = propsArrLos[1];
        }
        if (propsArrLos[0] == "seLoadClientSideVolgorde")
        {
            myClientLoadCL.seLoadClientSideVolgorde = propsArrLos[1];
        }
    } 
    
    if (seClientLoadList.length == 0) setTimeout("seAfbeeldingClientLoadTime()", 25);
    
    seClientLoadList.push(myClientLoadCL); // Opslaan
}

function seAfbeeldingClientLoadTime()
{
    var myClientLoadCL = seClientLoadList.shift();
    myClientLoadCL.seAfbeelding.src = myClientLoadCL.seFullPath;
    //myClientLoadCL.seAfbeelding.onerror = seAfbeeldingError(myClientLoadCL.seAfbeelding);
     
    if (seClientLoadList.length != 0) setTimeout("seAfbeeldingClientLoadTime()", 25);
}

/* ---------------------------------------- Wacht incoonje ------------------------------------ */

function seWaitIconOnClick(hideItem, showItem)
{
    document.getElementById(hideItem).style.display = "none";  
    document.getElementById(showItem).style.display = "inline";   
}

function seWaitIconOnClickLos(showItem, show)
{
    if (show == false)
    {
        document.getElementById(showItem).style.display = "none";  
    } else {
        document.getElementById(showItem).style.display = "inline";   
    }
}

/* ---------------------------------------- Javascript Debug --------------------------------- */

// Als doDebug = 1 dan wordt het debug window automatisch geopend 
// als er een debug bericht geschreven moet worden
// anders niets
var doDebug = 1;
var seDebugBasePath = "";

// Open een nieuw window als debug window
function seShowDebug() {
  window.top.debugWindow =
      window.open("",
                  "JavascriptDebug",
                  "left=0,top=0,width=300,height=700,scrollbars=yes,"
                  +"status=yes,resizable=yes");
  if (window.top.debugWindow) {
    window.top.debugWindow.opener = self;
    // open the document for writing
    window.top.debugWindow.document.open();
    window.top.debugWindow.document.write(
        "<HTML><HEAD><TITLE>Debug Window</TITLE></HEAD><BODY>siteEditor Javascript Debuger</BODY>");
    window.top.debugWindow.location = seDebugBasePath + "controls/baseControls/javaScriptDebug/debugWindow.htm";
  }
}

function seDebugWriteVar(varNr, text, sender) 
{
    seDoDebugWriteLine(text, sender, varNr);
}

function seDebugWriteLine(text, sender)
{
    seDoDebugWriteLine(text, sender, 0);
}

// If the debug window exists, then write to it
function seDoDebugWriteLine(text, sender, varNr) {
  if (doDebug == 1) {
    if (!window.top.debugWindow || window.top.debugWindow.closed) {
        // window nog niet open dus openen
        seShowDebug();
        
        do { 
            // wachten op het openen van het window 
        } 
        while(!window.top.debugWindow);
        
        do { 
            // wachten op het laden van het window 
        } 
        while(!window.top.debugWindow.seOntvanger);
    }
    
    if (window.top.debugWindow && !window.top.debugWindow.closed) {
        if (varNr == 0) {
            // regel naar het debug window sturen
            window.top.debugWindow.seOntvanger("list", text, sender, 0);
        } else {
            // variabele naar het debug window sturen
            window.top.debugWindow.seOntvanger("var" + varNr, text, sender, varNr);
        }
    } else {
        // window wilt niet open dus een alert
        alert(text);
    }
  }
}


/* ----------------------------- Z basis scripts -------------------------- */

//change the opacity for different browsers
function Z_ChangeOpac(theDiv, opacity) {
	var object = document.getElementById(theDiv).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";	
}


function Z_Menu_moveDivTop(theDiv, the_top)
{
  var the_style = Z_Menu_getStyleObject(theDiv);
  if (document.layers)
  {
    the_style.top = the_top;
  }
  else 
  {
    the_style.top = the_top + "px";  
  }
} //Z_Menu_moveDiv

function Z_Menu_moveDivLeft(theDiv, the_left)
{
  var the_style = Z_Menu_getStyleObject(theDiv);
  if (document.layers)
  {
    the_style.left = the_left;
  }
  else 
  {
    the_style.left = the_left + "px";  
  }
} //Z_Menu_moveDiv

function Z_Menu_moveDivHeight(theDiv, the_height)
{
  var the_style = Z_Menu_getStyleObject(theDiv);
  if (document.layers)
  {
    the_style.height = the_height;
  }
  else 
  {
    the_style.height = the_height + "px";
  }
} //Z_Menu_moveDiv

function Z_Menu_getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    } else {
        return false;
    }
} // Z_Menu_getStyleObject


function seMM_swapImage() { //v3.0
  var i,j=0,x,a=seMM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**
* --------------------------- Een aantal basis functie die meestal gebruikt worden --------------------------------------- 
*/

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}