
//(c)2007-Quintrics
//
//Common Functions

//Korte versie van GetElementById
function $()
{
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function getBrowserHeight()
{

	var er;

	try
	{
		//Hoogte onafhankelijk van browser
		var browserHeight = 0;
		if (typeof(self.innerHeight) == 'number')
		{
    		//Non-IE

    		browserHeight = window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
    		//IE 6+ in 'standards compliant mode'
    		browserHeight = document.documentElement.clientHeight;
		}
		else if (document.body && document.body.clientHeight)
		{
    		//IE 4 compatible
    		browserHeight = document.body.clientHeight;
		}
		return browserHeight;
	}
	catch (er)
	{
		return 0;
	}
	

}

function setBrowserHeight(aHeight)
{

	var er;
	
	try
	{
		//Hoogte onafhankelijk van browser
		if (typeof(self.innerHeight) == 'number')
		{
    		//Non-IE
    		window.innerHeight = aHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
    		//IE 6+ in 'standards compliant mode'
    		document.documentElement.clientHeight = aHeight;
		}
		else if (document.body && document.body.clientHeight)
		{
    		//IE 4 compatible
    		document.body.clientHeight = aHeight;
		}
	}
	catch (er)
	{
		return 0;
	}

}

function setBrowserWidth(aWidth)
{

	var er;
	
	try
	{
		//Hoogte onafhankelijk van browser
		if (typeof(self.innerWidth) == 'number')
		{
    		//Non-IE
    		window.innerWidth = aWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
    		//IE 6+ in 'standards compliant mode'
    		document.documentElement.clientWidth = aWidth;
		}
		else if (document.body && document.body.clientWidth)
		{
    		//IE 4 compatible
    		document.body.clientWidth = aWidth;
		}
	}
	catch (er)
	{
		return 0;
	}

}



function getBrowserWidth()
{

    var er;

	try
	{

		//Breedte onafhankelijk van browser
		var browserWidth = 0;
		if (typeof(self.innerWidth) == 'number')
		{
    		//Non-IE
    		browserWidth = window.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientWidth)
		{
    		//IE 6+ in 'standards compliant mode'
    		browserWidth = document.documentElement.clientWidth;
		}
		else if (document.body && document.body.clientWidth)
		{
    		//IE 4 compatible
    		browserWidth = document.body.clientWidth;
		}
		return browserWidth;
		
	}
	catch (er)
	{
		return 0;
	}

}

function getObjectHeight(aObject)
{
    var er;
    try
    {
        var objectHeight = -1;
        if (aObject.clientHeight)
        {
            objectHeight = aObject.clientHeight;
        }
        else
        {
            aObject.style.height='100%';
            objectHeight = aObject.clientHeight;
        }
        return objectHeight;
    }
    catch (er)
    {
        return -1;
    }
}

function getObjectWidth(aObject)
{
    var er;
    try
    {
        var objectWidth = -1;
        if (aObject.clientWidth)
        {
            objectWidth = aObject.clientWidth;
        }
        else
        {
            aObject.style.Width='100%';
            objectWidth = aObject.clientWidth;
        }
        return objectWidth;
    }
    catch (er)
    {
        return -1;
    }
}


function getObjectHeight2(aObject)
{
 var er;
 try
 {
  var objectHeight = 0;
  DumpObject(aObject);
  
  objectHeight = aObject.clientHeight;
  window.alert('aObject.clientHeight' + aObject.clientHeight);
  return objectHeight;
 }
 catch (er)
 {
 //window.alert('error objectheight');
   return 0;
 }
}





var Url = {

    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

//urlDecode
function urlDecode(str)
{
    str = str.replace(/\+/g , ' ');
    str = unescape(str);
    str = Url.decode(str);
    return str;
}

//urlEncode
function urlEncode(str)
{
    str = escape(str);
    str = str.replace(/\+/g, '%2B');
    str = str.replace(/%20/g, '+');
    str = str.replace(/\*/g, '%2A');
    str = str.replace(/\//g, '%2F');
    str = str.replace(/@/g, '%40');
    
    return str;
}


function hDecode(str)
{
   var div = document.createElement('div');
   var text = document.createTextNode(str);
   div.appendChild(text);
   return div.innerHTML;
}


function getBrowserLanguage()
{
    var myLanguage = navigator.userLanguage;
    
    if (!myLanguage)
    {
        myLanguage = navigator.systemLanguage;
    }
    
    if (!myLanguage)
    {
        myLanguage = 'nl-nl';
    }

    return myLanguage;
}

function getBrowserVersion()
{
    var navName = navigator.appName ;
    var brVer = navigator.userAgent;
    var brNum;
    var brVerId;
    
    var er;
    
    try
    {
        if (navName=='Microsoft Internet Explorer')
        {
            //IE
            brVerId = brVer.indexOf('MSIE');
            brNum = brVer.substr(brVerId+5,1);
           
            return "IE" + brNum; 
            
        }
        else if (navName=='Netscape')
        {
            
            if (brVer.indexOf('Mozilla')==0)
            {
                
                brVerId = brVer.indexOf('Firefox/');
                if (brVerId>0)
                {
                    //FireFox
                    brNum = brVer.substr(brVerId+8,1);
                    return "FF" + brNum;

                }
                else
                {
                    //Mozilla
                    brNum = brVer.substr(8,1);
                    return "MZ" + brNum;
                }
                
            }
            
            else
            {
                //Overige
                brVerId = Math.min((brVer+' ').indexOf(' '),(brVer+'/').indexOf('/'));
                brNum = brVer.substr(brVerId+1,1);
                
                return (brVer.substr(0,2)).toUpperCase() + brNum;
                
            }
        }
      
    }
    catch (er)
    {
        return "EE0";

    }
    
}

function insertScript(aScriptText)
{
    var newScript = document.createElement("script");
    newScript.defer = true;
    newScript.type = "text/javascript";
    newScript.text = aScriptText
    document.getElementsByTagName('head')[0].appendChild(newScript);
}

function insertBodyScript(aScriptText)
{
    var newScript = document.createElement("script");
    newScript.defer = true;
    newScript.type = "text/javascript";
    newScript.text = aScriptText
    document.getElementsByTagName('body')[0].appendChild(newScript);
}


function showMessage(aMessage)
{
    window.alert(aMessage)
}

function DumpObject(myObject, myLevel)
{
	try
	{
		if (typeof(myObject) == 'object')
		myLevel++;
		{
			var i;
			for (i in myObject)
			{
				var sp;
				for(sp=0; sp<myLevel; sp++)
				{
					document.write('&nbsp;&nbsp;');
				}

				document.write(i + ' - ');
				DumpAttribute(myObject,i, myLevel);
				document.write('<br />');

			}
			
		}
	}
	catch (er)
	{
		document.write(' [DumpObject:' + er + ']<br />');
	}
}

function DumpAttribute (myAttrObject,myAttribute, myAttrLevel)
{
	try
	{
		var myValue = myAttrObject.getAttribute(myAttribute);
		document.write(myValue);
		if (''+myValue == '[object]')
		{
			document.write('<br />');
			//DumpObject(myAttrObject.getAttribute(myAttribute),myAttrLevel)
		}
	}
	catch (er)
	{
		document.write(' [DumpAttribute:' + myAttribute + ', ' + er + ']<br />');
	}
}

function FullSizeFrame(objIframe, objBorder, objBorderSize, objBorderClass, intBorderStyle)
{

	var er;


	try
	{

	    objBorder.style.position = "absolute";

        switch (intBorderStyle) 
        {
            case 1: //border volledig rondom
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = objBorderSize + "px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*2) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = objBorderSize + "px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*2) + "px";
		    break;
        
            case 2: //border zonder bovenkant
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = "0px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*1) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = objBorderSize + "px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*2) + "px";
		    break;
        
        
            case 3: //border zonder onderkant
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = objBorderSize + "px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*1) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = objBorderSize + "px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*2) + "px";
		    break;

            case 4: //border alleen links en boven
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = objBorderSize + "px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*1) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = objBorderSize + "px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*1) + "px";
		    break;
            
            case 5: //border alleen rechts en onder
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = "0px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*1) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = "0px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*1) + "px";
		    break;

            case 6: //schaduw border links en boven
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = objBorderSize-1 + "px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*1) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = objBorderSize-1 + "px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*1) + "px";
		    break;

            case 7: //schaduw border rechts en onder
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = "1px";
		        objIframe.style.height =  getBrowserHeight() - (objBorderSize*1) + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = "1px";
		        objIframe.style.width = getBrowserWidth() - (objBorderSize*1) + "px";
		    break;
 
		    		    		    
            default:
		        objBorder.style.top = "0px";
		        objBorder.style.height =  getBrowserHeight() + "px";
		        objIframe.style.position = "absolute";
		        objIframe.style.top = "0px";
		        objIframe.style.height =  getBrowserHeight() + "px";

		        objBorder.style.left = "0px";
		        objBorder.style.width = getBrowserWidth() + "px";
		        objIframe.style.left = "0px";
		        objIframe.style.width = getBrowserWidth() + "px";
	    
        }		

		objBorder.className = objBorderClass;

		return true;
	}
	catch (er)
	{
		return false;
	}
	
}

function handleEvent(event) {
var returnValue = true;
// grab the event object (IE uses a global event object)
event = event || fixEvent(window.event);
// get a reference to the hash table of event handlers
var handlers = this.events[event.type];
// execute each event handler
for (var i in handlers) {
this.$$handleEvent = handlers[i];
if (this.$$handleEvent(event) === false) {
returnValue = false;
}
}
return returnValue;
};

function fixEvent(event) {
// add W3C standard event methods
event.preventDefault = fixEvent.preventDefault;
event.stopPropagation = fixEvent.stopPropagation;
return event;
};
fixEvent.preventDefault = function() {
this.returnValue = false;
};
fixEvent.stopPropagation = function() {
this.cancelBubble = true;
};



function initQ()
{
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) clearInterval(_timer);

    // do stuff
    try
    {
        initOnLoad();
    }
    catch (er)
    {
        //geen initOnLoad function aanwezig
    }

}



//------------------ [window.onload] BrowserCompatible WorkArround ----------------------
/* for Mozilla/Opera9 */
if (document.addEventListener)
{
    document.addEventListener("DOMContentLoaded", initQ, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            initQ(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            initQ(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = initQ;


//------------------ [window.onresize] BrowserCompatible WorkArround ----------------------
var widthCheck = 0;
var heightCheck = 0;

function myOnResizeQ()
{

//if (document.title=='SampleWebControls.asp')
//{
//    window.alert('hc=' + heightCheck + '\nhb=' + getBrowserHeight())
//}
    
   if (widthCheck != getBrowserWidth() || heightCheck != getBrowserHeight()  )
    {

        widthCheck = getBrowserWidth();
        heightCheck = getBrowserHeight();        
        
        // do stuff
        try
        {
            myOnResize();
        }
        catch (er)
        {

        }
        //body.onresize = myOnResizeQ;
    }   
}

//window.alert('- ' + document.title + '\nresize' + window.onresize)
window.onresize = myOnResizeQ;
//if (window.parent)
//{
//    window.parent.window.onresize = myOnResizeQ;
//}
//document.onmouseup =  myOnResizeQ;