﻿var SeDragging = false; // Wordt er met een element gesleept?

/* -------------------------- jQuery -------------------------------  */

try
{
$(document).ready(function() {

   // Poll balkjes anim
   $(".iPoll").stop().animate({ width: "100%"}, 2000);  
   
   // Textgifs
   $("img[id*='tg__Im']").error(function() {
        textEditorGifErrorJQ(this, $(this).attr("src"));
    });

    document.body.onmouseup = function () {
        SeDragging = false;
    }
    document.onselectstart = SeCancelSelect; // Zorg ervoor dat er niets geselecteerd wordt tijdens het slepen.
   
});
}

catch (e)
{
    // Nothing
}


// 04 02 2011 M Zorg er voor dat er tijden slepen van bijvoorbeeld elementen niets geselecteerd wordt
function SeCancelSelect() {
    if (SeDragging) return false;
    else return true;
}

/* -------------------------- Einde jQuery -------------------------- */
 
//function seVoegToeClicked(sender, args)
//{
//    var itemValue = args.get_item().get_value();
//    if (itemValue != "nvt")
//    {
//        alert(itemValue);
//    }
//}

/* -------------------------- Postings ------------------------------- */

function sePostingOpenClose(postingId, imgId) {
    height = $("#" + postingId).css("height");
    if (height != "38px") {
        $("#" + postingId).stop().animate(
            { height: "38px"
            }, 200);
        $("#" + imgId).attr("src", "/images/se/postings/pClose.gif");
    } else {
        $("#" + imgId).attr("src", "/images/se/postings/pOpen.gif");
        $("#" + postingId).stop().animate(
                { height: "200px"
                }, 100, function () { sePostingAutoHeight(postingId) } );
    }
}

function sePostingAutoHeight(postingId) {
    $("#" + postingId).stop();
    $("#" + postingId).css("height", "auto"); 
}

/* -------------------------- Einde Postings ------------------------- */

/* -------------------------- Textgifs ------------------------------- */

//function doTG(id, url, key, brs, srt, hof) 
//{ 
//    try
//    {
//    var realUrl = url; 
//    var filterUrl = url; 
//    if (brs == "1" && url.indexOf('.png') > 0) realUrl = realUrl.replace('.png', '_s.gif'); 
//    var html = "<img style='border:0px;' src='" + realUrl + "' "; 
//    if (hof != "" && srt != "") {
//        html += "onmouseover=\"this.title=''; this.alt=''; this.src=this.src.replace('" + 
//            srt + "', '" + hof + "')\" "; 
//        html += "onmouseout=\"this.title=''; this.alt=''; this.src=this.src.replace('" + 
//            hof + "', '" + srt + "')\" "; 
//    }
//    if (brs == "1" && url.indexOf('.png') > 0) html += " style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + filterUrl + "', sizingMethod='scale';\" "; 
//    html += " onerror=\"textGifError2(this, '" + key + "')\" />"; 
//    if (document.getElementById(id))
//        document.getElementById(id).innerHTML = html; 
//    }
//    catch(err)
//    {
//    }
//} 

function doTGjq(key) 
{ 
    var start = key.lastIndexOf("tg__Hd");
    
    key = key.substring(start + 6, key.length);
    
    

    var id = "";
    var url = "";
    var brs = "";
    var srt = "";
    var hof = "";
    var html = "";

    for(i=0;i<tgd.length;i++) {
        if (tgd[i][0] == key)
        {
            
            id = tgd[i][1];
            url = tgd[i][5];
            brs = tgd[i][4];
            srt = tgd[i][2];
            hof = tgd[i][3];
        }
    } 

    if (id != "")
    {
        try
        {
        var realUrl = url; 
        var filterUrl = url; 
        if (brs == "1" && url.indexOf('.png') > 0) realUrl = realUrl.replace('.png', '_s.gif'); 
        html = "<img style='border:0px;' src='" + realUrl + "' "; 
        if (hof != "" && srt != "") {
            html += "onmouseover=\"this.title=''; this.alt=''; this.src=this.src.replace('" + 
                srt + "', '" + hof + "')\" "; 
            html += "onmouseout=\"this.title=''; this.alt=''; this.src=this.src.replace('" + 
                hof + "', '" + srt + "')\" "; 
        }
        if (brs == "1" && url.indexOf('.png') > 0) html += " style=\"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + filterUrl + "', sizingMethod='scale';\" "; 
        html += " onerror=\"textGifError2(this, '" + key + "');\" />"; 
        }
        catch(err)
        {
        }
    }
    
    return html;
} 

function textEditorGifErrorJQ(thetextgif, url)
{
    for(i=0;i<tgd.length;i++) {
        if (tgd[i][5] == url)
        {
            textGifError2(thetextgif, tgd[i][0]);
        }
    }
}

function textEditorGifError(textGif)
{
    textGif.src = "/editor/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
var seTextGifTimerRunning1 = 0;
var seTextGifObj1 = new Array();

function textGifError(textGif)
{
    textGif.src = "/editor/seResource/seImages/seTextGifLoading.gif";
    textGif.onerror = null;
    
    seTextGifObj1.push(textGif);   
    if (!seTextGifTimerRunning1) 
    {
        seTextGifTimerRunning1 = setTimeout("textGifErrorDo()", 9000);
    } 
}

function textGifErrorDo()
{
    textGif = seTextGifObj1.shift();
    if (textGif != null)
    {
        pathParts = textGif.src.split("/"); 
        textGif.src = "/editor/seMaakTextGif.ashx?filename=" + 
            pathParts[pathParts.length-1] + "&text=" + textGif.alt + "&width=" + 
            textGif.width + "&height=" + textGif.height + textGif.name;
        
        clearTimeout(seTextGifTimerRunning1);
        seTextGifTimerRunning1 = setTimeout("textGifErrorDo()", 250);
    } else {
        seTextGifTimerRunning1 = null;
    } 
}

var seTextGifTimerRunning = 0;
var seTextGifObj = new Array();
var seTextGifUniek = new Array();

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;
    
    seTextGifObj.push(textGif);
    seTextGifUniek.push(uniek);
    
    if (!seTextGifTimerRunning) 
    {
        seTextGifTimerRunning = setTimeout("textGifError2Do()", 10);
    }
    
}

function textGifError2Do()
{
    textGif = seTextGifObj.shift();
    uniek = seTextGifUniek.shift();
    if (textGif != null)
    {
        textGif.src = "/editor/seMaakTextGif.ashx?uniek2=" + uniek + "&rnd=" + (Math.random()*10000);
        clearTimeout(seTextGifTimerRunning);
        seTextGifTimerRunning = setTimeout("textGifError2Do()", 250);
    } else {
        seTextGifTimerRunning = null;
    } 
}


/* -------------------------- Einde Textgifs ------------------------------- */

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]+"'");
}
