﻿var menuTimer;
var menuPostbackControl;
var menuItemID;

function ScrollDown(sName, iScrollSpeed)
{
	var divObject = document.getElementById(sName)
	var divObjectHeight = divObject.offsetHeight
	var divObjectTop = parseInt(divObject.style.top)
	if (divObjectTop >= (divObjectHeight * (-1) + 100))
	{
		divObject.style.top = divObjectTop - iScrollSpeed
	}
	ScrollDownTimeOut = setTimeout("ScrollDown('" + sName + "', " + iScrollSpeed + ")", 100)
}

function ScrollUp(sName, iScrollSpeed)
{
	var divObject = document.getElementById(sName)
	var divObjectHeight = divObject.offsetHeight
	var divObjectTop = parseInt(divObject.style.top)
	if (divObjectTop < 0)
	{
		divObject.style.top = divObjectTop + iScrollSpeed
	}
	ScrollUpTimeOut = setTimeout("ScrollUp('" + sName + "', " + iScrollSpeed + ")", 100)
}

function FocusTextbox(obj, defaultText, focusStyle)
{
    if(obj.value==defaultText)obj.value=''
    obj.setAttribute("class", focusStyle); 
    obj.setAttribute("className", focusStyle); 
}
function BlurTextbox(obj, defaultText, blurStyle, filledStyle)
{
    if(obj.value=='')
    {
        obj.value=defaultText
        obj.setAttribute("class", blurStyle); 
        obj.setAttribute("className", blurStyle); 
    }
    else
    {
        obj.setAttribute("class", filledStyle); 
        obj.setAttribute("className", filledStyle); 
    }
}
function FocusDropdown(obj, defaultText, focusStyle)
{
    obj.setAttribute("class", focusStyle); 
    obj.setAttribute("className", focusStyle); 
}
function BlurDropdown(obj, defaultText, blurStyle, filledStyle)
{
    if(obj.options[obj.selectedIndex].value==defaultText)
    {
        obj.value=defaultText
        obj.setAttribute("class", blurStyle); 
        obj.setAttribute("className", blurStyle); 
    }
    else
    {
        obj.setAttribute("class", filledStyle); 
        obj.setAttribute("className", filledStyle); 
    }
}

function clearText(obj, defaultText)
{
    if (obj.value = defaultText)
    {
        obj.value="";
    }
}

function toggleDisplay(e)
{
    element = document.getElementById(e).style;
    element.display == 'none' ? element.display = 'block' : element.display = 'none';
}

function setActiveClass(obj, cls)
{ 
    var elem = document.getElementById(obj); 

    elem.setAttribute("class", cls); 
    elem.setAttribute("className", cls); 

    return; 
}

function IIf(Expression, TruePart, FalsePart) {
    var result = FalsePart;
    try {
        if (Expression) { result = TruePart; }
    }
    catch (e) { }
    return result;
}

function handleDragStart(ItemID, AllowDragDrop) {
    try {
        if (AllowDragDrop == 1) {
            window.event.dataTransfer.setData("ItemID", ItemID);
            window.event.dataTransfer.effectAllowed = "move";
        }
	    else {
		    window.event.dataTransfer.setData("ItemID", "nomove");
		    window.event.dataTransfer.effectAllowed = "none";
	    }
    }
    catch (e) { }
}

function handleDragOver() {
	cancelDefaultEvent();
}

function cancelDefaultEvent() {
    try {
        window.event.returnValue = false;
    }
	catch (e) { }
}

function handleDragEnter() {
	cancelDefaultEvent;
	
	try {
	    window.event.dataTransfer.dropEffect = "move";
    }
    catch (e) { }
}

function handleDrop(ItemID) {
	cancelDefaultEvent();
	
    try {
        var src = window.event.dataTransfer.getData("ItemID");

	    if (src != "nomove") {
		    if (ItemID != src) {
		        __doPostBack(src, 'move$' + ItemID);
		    }
	    }
    }
    catch (e) { }
}

function hideMenu() {
    try {
        var contextMenu = document.getElementById('contextMenu')
        contextMenu.style.visibility = 'hidden';
        contextMenu.setAttribute('pageid', '');
    }
    catch (e) { }
}

function showMenu(PostbackControl, isTopMostPage) {
    try {
        menuPostbackControl = PostbackControl;
        // menuItemID = ItemID;

        var contextMenu = document.getElementById('contextMenu');
        contextMenu.style.left = event.clientX;
        contextMenu.style.top = event.clientY;

        document.getElementById('cmsMenuDelete').style.display = 'inline';
        document.getElementById('cmsMenuUp').style.display = 'inline';
        document.getElementById('cmsMenuDown').style.display = 'inline';
        
        if (isTopMostPage) {
            document.getElementById('cmsMenuDelete').style.display = 'none';
            document.getElementById('cmsMenuUp').style.display = 'none';
            document.getElementById('cmsMenuDown').style.display = 'none';
        }
        
        contextMenu.style.visibility = 'visible';
    }
    catch (e) { }
    
    return false;
}

function __menuPostBack(action) {
    try {
        if ((action != 'Delete') || (vbMsgBox('Weet u zeker dat u dit item wilt verwijderen?', 292, '') == 'Yes')) {
            __doPostBack(menuPostbackControl, action);
        }
    }
    catch (e) { }
}

function setHideMenuTimer() {
    cancelHideMenuTimer();
    
    try {
        menuTimer = setTimeout('hideMenu();', 1000);
    }
    catch (e) { }
}

function cancelHideMenuTimer() {
    try {
        clearTimeout(menuTimer);
    }
    catch (e) { }
}

// Ondersteuning van de defaultbutton.
function CheckKey(oEvent)
{
	var oEvent = (oEvent)? oEvent : event;
	if(oEvent.keyCode==13) 
	{
		if (typeof(Page_ClientValidate) != 'function' || Page_ClientValidate()) 
			__doPostBack(defaultbutton,'');
		return false;
	}
}

// Ondersteuning van het eenmalig klikken van een button.
var alreadyClicked = false;
function ClickOnce (eventTarget, eventArgument)
{
	if (alreadyClicked)
	{
		return false;
	}
	else
	{
		alreadyClicked = true;
		var buttonSpan = document.all[eventTarget + "Span"];
		if (buttonSpan != null)
		{
			buttonSpan.className = buttonSpan.className.replace("GBFButtonEnabled", "GBFButtonProcessing");
			buttonSpan.innerText = "Momentje";
		}
	}
}

// Ondersteuning voor het printen van het scherm
function Print()
{
	window.print();
}

// Ondersteuning van het zetten van de focus op een invoercontrol.
function SetFocus(strID)
{
    var nPgIdx, nIdx, ctl, ctlParent, htmlCol;

    ctl = document.getElementById(strID);

    // If not found, exit
    if(ctl == null || typeof(ctl) == "undefined")
        return false;

    // NOTE: This section is IE-specific.
    // See if there is a parent element.  If so, work back up the chain
    // to see if the control is embedded in an PageView IE Web Control.
    // If so, select that page before giving focus to the control.  If not,
    // it may not work as the control may not be visible.
    if(typeof(ctl.parentElement) != "undefined")
    {
        ctlParent = ctl.parentElement;

        while(ctlParent != null && ctlParent.tagName != "PageView")
            ctlParent = ctlParent.parentElement;

        // If found, set the page as the active one in the containing
        // MultiPage control.
        if(ctlParent != null && ctlParent.tagName == "PageView")
        {
            nPgIdx = ctlParent.PageIndex;
            ctlParent = ctlParent.parentElement;

            if(ctlParent != null && ctlParent.tagName == "MultiPage")
            {
                ctlParent.selectedIndex = nPgIdx;

                // We also have to set the index of any TabStrip
                // associated with the MultiPage.
                htmlColl = document.getElementsByTagName("TabStrip");

                for(nIdx = 0; nIdx < htmlColl.length; nIdx++)
                    if(htmlColl[nIdx].targetID == ctlParent.id)
                    {
                        htmlColl[nIdx].selectedIndex = nPgIdx;
                        break;
                    }
            }
        }
    }
    // End IE-specific section

    // Focus the control.  If it's a table, we may have been asked to
    // set focus to a radio button or checkbox list.  If so, select
    // the control in the first cell of the table.
    if(ctl.tagName == "TABLE")
    {
        ctl = ctl.cells(0);
        ctl = ctl.firstChild;
    }

    ctl.focus();
    ctl.scrollIntoView(false);

    // If it is a textbox-type control, select the text in the control
    if(ctl.type == "text" || ctl.tagName == "TEXTAREA")
        ctl.select();

    return false;
}

// Ondersteuning voor tooltips
var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
	var thisKDE=agt;
	var splitKDE=thisKDE.split("konqueror/");
	var aKDE=splitKDE[1].split("; ");
	var KDEn=parseFloat(aKDE[0]);
	if(KDEn>=2.2){
		kde=1;
		ns6=1;
		exclude=0;
		}
	}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
	exclude=0;
	if(/opera[\/ ][5]/.test(agt)){op5=1;}
	if(/opera[\/ ][6]/.test(agt)){op6=1;}
	if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
	}
else if(typeof document.all!="undefined"&&!kde){
	exclude=0;
	ie=1;
	if(typeof document.getElementById!="undefined"){
		ie5=1;
		if(agt.indexOf("msie 6")!=-1){
			ie6=1;
			dcm=document.compatMode;
			if(dcm!="BackCompat"){com=1;}
			}
		}
	else{ie4=1;}
	}
else if(typeof document.getElementById!="undefined"){
	exclude=0;
	if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
	else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
	else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
	if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
	}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
	exclude=0;
	ns4=1;
	if(typeof navigator.mimeTypes['*']=="undefined"){
		exclude=1;
		ns4=0;
		}
	}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

/***********************************************
* Fixed ToolTip script- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
		
var tipwidth=150 //default tooltip width
var disappeardelay=500  //tooltip disappear speed onMouseout (in miliseconds)
var vertical_offset=0 //horizontal offset of tooltip from anchor link
var horizontal_offset=-3 //horizontal offset of tooltip from anchor link

if (ie5||ns6)
	document.write('<div id="fixedtipdiv"></div>')

function getposOffset(what, offsettype)
{
	var totaloffset = 0;
	while (what)
	{
		totaloffset=(offsettype=="left")? totaloffset+what.offsetLeft : totaloffset+what.offsetTop;
		what = what.offsetParent;
	}
	if ((ie5) && offsettype=="top") totaloffset = totaloffset + 81
	if ((ie5) && offsettype=="left") totaloffset = totaloffset
	
	totaloffset=(offsettype=="left")? totaloffset + 16 : totaloffset - 16;
	return totaloffset;
}

function showhide(obj, e, visible, hidden, tipwidth)
{
	if (ie5||ns6||op7)
		dropmenuobj.style.left=dropmenuobj.style.top=-500
	if (tipwidth!="")
	{
		dropmenuobj.widthobj=dropmenuobj.style
		dropmenuobj.widthobj.width=tipwidth+'px'
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible
	else if (e.type=="click")
		obj.visibility=hidden
}
function iecompattest()
{
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function clearbrowseredge(obj, whichedge)
{
	var edgeoffset=(whichedge=="rightedge")? parseInt(horizontal_offset)*-1 : parseInt(vertical_offset)*-1
	if (whichedge=="rightedge")
	{
		var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth 
	}
	else
	{
		var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
	}
	return edgeoffset
}
function fixedtooltip(menucontents, obj, e, tipwidth)
{
	var shifttop = 0
	if (window.event) event.cancelBubble=true
	else if (e.stopPropagation) e.stopPropagation()
	clearhidetip()
	dropmenuobj=document.getElementById? document.getElementById("fixedtipdiv") : fixedtipdiv
	dropmenuobj.innerHTML=menucontents

	if (ie5||ns6)
	{
		showhide(dropmenuobj.style, e, "visible", "hidden", tipwidth)
		dropmenuobj.x=getposOffset(obj, "left")
		dropmenuobj.y= getposOffset(obj, "top")
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
		if (clearbrowseredge(obj, "rightedge") > 10) shifttop = 25
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge") + shifttop + obj.offsetHeight+"px"
		obj.title = ""
	}
}
function hidetip(e)
{
	if (typeof dropmenuobj!="undefined")
	{
		if (ie5||ns6||op7)
			dropmenuobj.style.visibility="hidden"
	}
}

function delayhidetip()
{
	if (ie5||ns6||op7)
		delayhide=setTimeout("hidetip()",disappeardelay)
}

function clearhidetip()
{
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide)
}

function StartSearchOnEnter(e, ctrl)
{
  //e is event object passed from function invocation
  var characterCode; //literal character code will be stored in this variable
  if(e && e.which)
  {
    //if which property of event object is supported (NN4)
    e = e;
    characterCode = e.which; //character code is contained in NN4's which property
  }
  else
  {
    e = event
    characterCode = e.keyCode; //character code is contained in IE's keyCode property
  }

  if(characterCode == 13)
  {
    return StartSearch(ctrl);
  }
  else
  {
    return characterCode;
  }
}

function StartSearch(ctrl)
{
//    var controlCollection = ASPxClientControl.GetControlCollection();
    var textBox = document.getElementById(ctrl);
    var text = textBox.value;

    //alert(text);
    if (text != "")
    {
    window.location = "/index.aspx?do=search&find=" + text;
    }
    return false;
}

// JavaScript Function
function AllowOnlyNumeric()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9), plus sign (+), comma (,), hyphen/minus (-) or a decimal (.)
    if ( (key >= 48 && key <= 57) || (key >= 43 && key <= 46) )
        // If it was, then allow the entry to continue
        return;
    else
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
}

// JavaScript Function
function AllowOnlyNumericCMS()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9), comma (,), hyphen/minus (-)
    if ( (key > 47 && key < 58) || key == 44 || key == 45 )
    {
        // If it was, then allow the entry to continue
        return;
    }
    else if (key == 46 )
    {
        window.event.keyCode = 44;
    }
    else
    {
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
    }
}

// JavaScript Function
function AllowOnlyNumericUS()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9), comma (,), hyphen/minus (-)
    if ( (key > 47 && key < 58) || key == 44 || key == 45 )
    {
        // If it was, then allow the entry to continue
        return;
    }
    else if (key == 44 )
    {
        window.event.keyCode = 46;
    }
    else
    {
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
    }
}

// JavaScript Function
function AllowOnlyDigitsCMS()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9)
    if ( (key > 47 && key < 58) )
        // If it was, then allow the entry to continue
        return;
    else
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
}

// JavaScript Function
function AllowNumericWebshop()
{
    // Get the ASCII value of the key that the user entered
    var key = window.event.keyCode;

    // Verify if the key entered was a numeric character (0-9), comma (,)
    if ( (key > 47 && key < 58) || key == 44 )
    {
        // If it was, then allow the entry to continue
        return;
    }
    else if (key == 46 )
    {
        window.event.keyCode = 44;
    }
    else
    {
        // If it was not, then dispose the key and continue with entry
        window.event.returnValue = null; 
    }
}

function DoPostbackForControlOnEnter(e, ctrl)
{
  //e is event object passed from function invocation
  var characterCode; //literal character code will be stored in this variable
  if(e && e.which)
  {
    //if which property of event object is supported (NN4)
    e = e;
    characterCode = e.which; //character code is contained in NN4's which property
  }
  else
  {
    e = event
    characterCode = e.keyCode; //character code is contained in IE's keyCode property
  }

  if(characterCode == 13)
  {
    __doPostBack(ctrl,'');
    return false;
  }
  else
  {
    return characterCode;
  }
}

function StartSearchWebshopOnEnter(e, ctrl)
{
  //e is event object passed from function invocation
  var characterCode; //literal character code will be stored in this variable
  if(e && e.which)
  {
    //if which property of event object is supported (NN4)
    e = e;
    characterCode = e.which; //character code is contained in NN4's which property
  }
  else
  {
    e = event
    characterCode = e.keyCode; //character code is contained in IE's keyCode property
  }

  if(characterCode == 13)
  {
    return StartSearchWebshop(ctrl);
  }
  else
  {
    return characterCode;
  }
}


function StartSearchWebshop(ctrl)
{
//    var controlCollection = ASPxClientControl.GetControlCollection();
    var textBox = document.getElementById(ctrl);
    var text = textBox.value;

    //alert(text);
    if (text != "")
    {
        window.location = "/webshop.aspx?find=" + text;
    }
    return false;
}

function PadLeft(str, len, chr)
{
    str = str.toString();

    while (str.length < len)
    {
        str = chr + str;
    }
    
    return str;
}

var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;
 
function StringPad(str, len, pad, dir) {
 
	if (typeof(len) == "undefined") { var len = 0; }
	if (typeof(pad) == "undefined") { var pad = '0'; }
	if (typeof(dir) == "undefined") { var dir = STR_PAD_LEFT; }
 
	if (len + 1 >= str.length) {
 
		switch (dir){
 
			case STR_PAD_LEFT:
				str = Array(len + 1 - str.length).join(pad) + str;
			break;
 
			case STR_PAD_BOTH:
				var right = Math.ceil((padlen = len - str.length) / 2);
				var left = padlen - right;
				str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
			break;
 
			default:
				str = str + Array(len + 1 - str.length).join(pad);
			break;
 
		} // switch
 
	}
 
	return str;
 
}

function Count(text,long) 
{
    var maxlength = new Number(long); // Change number to your max length.
    if (text.value.length > maxlength)
    {
        text.value = text.value.substring(0,maxlength);
        alert("Max " + long);
    }
}

function ResizeWindow()
{
    if (self.innerWidth)
    {
        frameWidth = self.innerWidth;
        frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth)
    {
        frameWidth = document.documentElement.clientWidth;
        frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
        frameWidth = document.body.clientWidth;
        frameHeight = document.body.clientHeight;
    }
    else return;

    if (self.screen.width < frameWidth *2 || self.screen.height < frameHeight *2)
    {
        newWidth = 650; //self.screen.width/2;
        newHeight = 550; //self.screen.height/2;
        if (document.layers)
        {
	        tmp1 = parent.outerWidth - parent.innerWidth;
	        tmp2 = parent.outerHeight - parent.innerHeight;
	        newWidth -= tmp1;
	        newHeight -= tmp2;
        }
        parent.window.resizeTo(newWidth,newHeight);
        parent.window.moveTo(self.screen.width/4,self.screen.height/4);
    }
}
