/**
 *	@author ANC
 *	@package 
 *	@version vDB115 release
 *  @Copyright 2007 Digital Web Technologies
 *
 *
 *  @lisence-to : Dal Consulting S.R.L
 *  @lisence-type : private.
 *
 *  Permission to use this software and its documentation for any purpose is hereby granted with fee documented in reciepts.
 *  Any reproduction, modification, distribution of source code will result in conviction of the lisencee itself.
 *
 */

var dwt = 
{
	NS4 : (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false,
	IE : (document.all && !document.getElementById)? true : false,
	IE4 : (document.all && !document.getElementById)? true : false,
	IE5 : (document.getElementById && document.all && navigator.userAgent.indexOf("MSIE 5.5") >= 0 )? true : false,
	IE6 : (document.all && document.getElementById && navigator.userAgent.indexOf("MSIE 6") >= 0 )? true : false,
	IE7 : (document.all && document.getElementById && navigator.userAgent.indexOf("MSIE 7") >= 0 )? true : false, 
	NS6 : (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false,
	W3C : (document.getElementById)? true : false,
		
	Firefox : (navigator.userAgent.indexOf("Firefox") >= 0) ? true : false,
	MSIE : (navigator.userAgent.indexOf("MSIE") >= 0) ? true : false,
	Mozilla : (navigator.userAgent.indexOf("Mozilla") >= 0) ? true : false,
	Gecko : (navigator.userAgent.indexOf("Gecko") >= 0) ? true : false,
	Safari : (navigator.userAgent.indexOf("Safari") >= 0) ? true : false,
	Opera : (navigator.userAgent.indexOf("Opera") >= 0) ? true : false,
	
	MOUSE_DOWN 	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onmousedown" : "mousedown",
	MOUSE_MOVE 	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onmousemove" : "mousemove",
	MOUSE_OUT  	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onmouseout" : "mouseout",
	MOUSE_OVER 	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onmouseover" : "mouseover",
	MOUSE_UP  	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onmouseup" : "mouseup",
	MOUSE_MOVE  : (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onmousemove" : "mousemove",
	
	CLICK		: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onclick" : "click",
	DB_CLICK	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "ondbclick" : "dbclick",
	HELP		: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onhelp" : "help",
	KEY_DOWN 	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onkeydown" : "keydown",
	KEY_PRESS	: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onkeypress" : "keypress",
	KEY_UP		: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onkeyup" : "keyup",
	RESIZE		: (document.all && navigator.userAgent.indexOf("Opera") != 0) ? "onresize" : "resize",
	
	
	get : function(arg)
	{
		try
		{
			if (document.all )
				return document.all(arg);
			else if (document.getElementById)
				return document.getElementById(arg);
			else if (document.layers)	
				return document.layers(arg);
		}
		catch(e)
		{
			alert('Incomplete loading... Please reopen this window.');
		}
	},
	
	set  :   function(arga, argb)
	{
		try
		{
			if (document.all)
				eval(arga = document.all(argb));
			else if (document.getElementById)
				eval(arga = document.getElementById(argb));
			else if (document.layers)
				eval(arga = document.layers(argb));
		}
		catch(e)
		{
			alert('Incomplete loading... Please reopen this window.');
		}
	},
	
	
	getDA : function(arg)
	{
		try
		{
			if (document.all)
				return window.dialogArguments.document.all(arg);
			else if (document.getElementById)
				return window.dialogArguments.document.getElementById(arg);
			else if (document.layers)	
				return window.dialogArguments.document.layers(arg);
		}
		catch(e)
		{
			alert('Incomplete loading... Please reopen this window.');
		}
		
	},
	
	addListener : function(obj, evt, func)
	{
		if(window.addEventListener)
			return dwt.get(obj).addEventListener(evt, func, false);
		else if (window.attachEvent)
			return dwt.get(obj).attachEvent(evt, func);
	},
	
	
	innerWidth : function()
	{
		if (window.innerWidth)
			return window.innerWidth;
		else if(document.documentElement && document.documentElement.clientWidth)
			return document.documentElement.clientWidth;
		else if (document.body)
			return document.body.clientWidth;
		else
			return "undefined";
	},
	
	innerHeight : function()
	{
		if (window.innerHeight)
			return window.innerHeight;
		else if (document.documentElement && document.documentElement.clientHeight)
			return document.documentElement.clientHeight;
		else if (document.body)
			return document.body.clientHeight;
		else
			return "undefined";
	},
	
	
	
	// private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
   	
    // public method for encoding
    base64_encode : function (input) 
    {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = dwt.base64_utf8_encode(input);

        while (i < input.length) 
        {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2))
                enc3 = enc4 = 64;
            else if (isNaN(chr3))
                enc4 = 64;

            output = output +
            this.iso_8859_2.charAt(enc1) + this.iso_8859_2.charAt(enc2) +
            this.iso_8859_2.charAt(enc3) + this.iso_8859_2.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    base64_decode : function (input) 
    {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length)
        {

            enc1 = this.iso_8859_2.indexOf(input.charAt(i++));
            enc2 = this.iso_8859_2.indexOf(input.charAt(i++));
            enc3 = this.iso_8859_2.indexOf(input.charAt(i++));
            enc4 = this.iso_8859_2.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = dwt.base64_utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    base64_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
    base64_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;
    }
	
	
	
}
