﻿
// JScript File


//detect browser version
var BrowserDetect = {
    init: function () {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
        this.OS = this.searchString(this.dataOS) || "an unknown OS";
    },
    searchString: function (data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function (dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1) return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [
		{ string: navigator.userAgent,
		    subString: "OmniWeb",
		    versionSearch: "OmniWeb/",
		    identity: "OmniWeb"
		},
		{
		    string: navigator.vendor,
		    subString: "Apple",
		    identity: "Safari"
		},
		{
		    prop: window.opera,
		    identity: "Opera"
		},
		{
		    string: navigator.vendor,
		    subString: "iCab",
		    identity: "iCab"
		},
		{
		    string: navigator.vendor,
		    subString: "KDE",
		    identity: "Konqueror"
		},
		{
		    string: navigator.userAgent,
		    subString: "Firefox",
		    identity: "Firefox"
		},
		{
		    string: navigator.vendor,
		    subString: "Camino",
		    identity: "Camino"
		},
		{		// for newer Netscapes (6+)
		    string: navigator.userAgent,
		    subString: "Netscape",
		    identity: "Netscape"
		},
		{
		    string: navigator.userAgent,
		    subString: "MSIE",
		    identity: "IE",
		    versionSearch: "MSIE"
		},
		{
		    string: navigator.userAgent,
		    subString: "Gecko",
		    identity: "Mozilla",
		    versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
		    string: navigator.userAgent,
		    subString: "Mozilla",
		    identity: "Netscape",
		    versionSearch: "Mozilla"
		}
	],
    dataOS: [
		{
		    string: navigator.platform,
		    subString: "Win",
		    identity: "Windows"
		},
		{
		    string: navigator.platform,
		    subString: "Mac",
		    identity: "Mac"
		},
		{
		    string: navigator.platform,
		    subString: "Linux",
		    identity: "Linux"
		}
	]

};
BrowserDetect.init();

function SlidableDomObject(object)
{
	this.targetObject = object;
	this.changeStep = 1;
	this.timerId = 0;
	this.oldHeight = 0;
	this.overflowY = "";
	
	this.adjust = 0; //keep the difference of pixelHeight and offsetHeight
	this.HideObjectSmoothly = function()
	{
	    var objThis = this;
		this.targetObject.style.height = this.targetObject.offsetHeight + "px";
		this.adjust = this.targetObject.offsetHeight - this.targetObject.style.pixelHeight;
		this.targetObject.style.pixelHeight = this.targetObject.style.pixelHeight - this.adjust;
		this.changeStep = this.targetObject.style.pixelHeight / 10;
		this.oldHeight = this.targetObject.style.pixelHeight;
		this.overflowY = this.targetObject.style.overflowY;
		this.targetObject.style.overflowY = "hidden";
		this.targetObject.style.display = "block";
		if(this.changeStep <= 0)
		{
			this.changeStep = 1;
		}
		this.timerId = setInterval(function (){
		    objThis.DecreaseObjectHeight();
		} ,10)
	}
	
	this.DecreaseObjectHeight = function()
	{
		if(this.targetObject == null)
		{
			return;
		}
		if(this.targetObject.style.pixelHeight - 1 >= this.changeStep)
		{
			this.targetObject.style.pixelHeight -=  this.changeStep;
		}
		else
		{
			this.targetObject.style.display = "none";
    		this.targetObject.style.overflowY = this.overflowY;
			clearInterval(this.timerId);
			this.targetObject.style.pixelHeight = this.oldHeight;
		}

	}


	this.IncreaseObjectHeight = function()
	{
		if(this.targetObject == null)
		{
			return;
		}
		
		if((this.targetObject.style.pixelHeight + this.changeStep) < this.oldHeight)
		{
			this.targetObject.style.pixelHeight +=  this.changeStep;
		}
		else
		{
       		this.targetObject.style.overflowY = this.overflowY;
			clearInterval(this.timerId);
			this.targetObject.style.pixelHeight = this.oldHeight;
		}
	}
	
	this.ShowObjectSmoothly = function()
	{
	    var objThis = this;
		this.changeStep = this.targetObject.style.pixelHeight / 10;
		if(this.changeStep <= 0)
		{
			this.changeStep = 1;
		}
		this.oldHeight = this.targetObject.style.pixelHeight;
		this.overflowY = this.targetObject.style.overflowY;
		this.targetObject.style.overflowY = "hidden";
		this.targetObject.style.pixelHeight = 1;
		this.adjust = this.targetObject.offsetHeight - this.targetObject.style.pixelHeight;
		this.targetObject.style.display = "block";
		this.timerId = setInterval(function() {
			        objThis.IncreaseObjectHeight();
		        } ,10)
	}
	
}

Date.prototype.toISO8601String = function (format, offset) {
    /* accepted values for the format [1-6]:
     1 Year:
       YYYY (eg 1997)
     2 Year and month:
       YYYY-MM (eg 1997-07)
     3 Complete date:
       YYYY-MM-DD (eg 1997-07-16)
     4 Complete date plus hours and minutes:
       YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
     5 Complete date plus hours, minutes and seconds:
       YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
     6 Complete date plus hours, minutes, seconds and a decimal
       fraction of a second
       YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
    */
    if (!format) { var format = 6; }
    if (!offset) {
        var offset = 'Z';
        var date = this;
    } else {
        var d = offset.match(/([-+])([0-9]{2}):([0-9]{2})/);
        var offsetnum = (Number(d[2]) * 60) + Number(d[3]);
        offsetnum *= ((d[1] == '-') ? -1 : 1);
        var date = new Date(Number(Number(this) + (offsetnum * 60000)));
    }

    var zeropad = function (num) { return ((num < 10) ? '0' : '') + num; }

    var str = "";
    str += date.getUTCFullYear();
    if (format > 1) { str += "-" + zeropad(date.getUTCMonth() + 1); }
    if (format > 2) { str += "-" + zeropad(date.getUTCDate()); }
    if (format > 3) {
        str += "T" + zeropad(date.getUTCHours()) +
               ":" + zeropad(date.getUTCMinutes());
    }
    if (format > 5) {
        var secs = Number(date.getUTCSeconds() + "." +
                   ((date.getUTCMilliseconds() < 100) ? '0' : '') +
                   zeropad(date.getUTCMilliseconds()));
        str += ":" + zeropad(secs);
    } else if (format > 4) { str += ":" + zeropad(date.getUTCSeconds()); }

    if (format > 3) { str += offset; }
    return str;
}

Date.parseIso8601 = function(CurDate) {

		// Check the input parameters
	if ( typeof CurDate != "string" ) {
		return null;
	};
		// Set the fragment expressions
	var SS = "[ Tt]";
	var S = "[\\-/:.]";
	var Yr = "((?:1[6-9]|[2-9][0-9])[0-9]{2})";
	var Mo = S + "((?:1[012])|(?:0[1-9])|[1-9])";
	var Dy = S + "((?:3[01])|(?:[12][0-9])|(?:0[1-9])|[1-9])";
	var Hr = "(2[0-4]|[01]?[0-9])";
	var Mn = S + "([0-5]?[0-9])";
	var Sd = "(?:" + S + "([0-5]?[0-9])(?:[.,]([0-9]+))?)?";
	var TZ = "(?:(Z)|(?:([\+\-])(1[012]|[0]?[0-9])(?::?([0-5]?[0-9]))?))?";
		// RegEx the input
		// First check: Just date parts (month and day are optional)
		// Second check: Full date plus time (seconds, milliseconds and TimeZone info are optional)
	var TF;
	if ( TF = new RegExp("^" + Yr + "(?:" + Mo + "(?:" + Dy + ")?)?" + "$").exec(CurDate) ) {} else if ( TF = new RegExp("^" + Yr + Mo + Dy + SS + Hr + Mn + Sd + TZ + "$").exec(CurDate) ) {};
		// If the date couldn't be parsed, return null
	if ( !TF ) { return null };
		// Default the Time Fragments if they're not present
	if ( !TF[2] ) { TF[2] = 1 } else { TF[2] = TF[2] - 1 };
	if ( !TF[3] ) { TF[3] = 1 };
	if ( !TF[4] ) { TF[4] = 0 };
	if ( !TF[5] ) { TF[5] = 0 };
	if ( !TF[6] ) { TF[6] = 0 };
	if ( !TF[7] ) { TF[7] = 0 };
	if ( !TF[8] ) { TF[8] = null };
	if ( TF[9] != "-" && TF[9] != "+" ) { TF[9] = null };
	if ( !TF[10] ) { TF[10] = 0 } else { TF[10] = TF[9] + TF[10] };
	if ( !TF[11] ) { TF[11] = 0 } else { TF[11] = TF[9] + TF[11] };
		// If there's no timezone info the data is local time
	if ( !TF[8] && !TF[9] ) {
		return new Date(TF[1], TF[2], TF[3], TF[4], TF[5], TF[6], TF[7]);
	};
		// If the UTC indicator is set the date is UTC
	if ( TF[8] == "Z" ) {
		return new Date(Date.UTC(TF[1], TF[2], TF[3], TF[4], TF[5], TF[6], TF[7]));
	};
		// If the date has a timezone offset
	if ( TF[9] == "-" || TF[9] == "+" ) {
			// Get current Timezone information
		var CurTZ = new Date().getTimezoneOffset();
		var CurTZh = TF[10] - ((CurTZ >= 0 ? "-" : "+") + Math.floor(Math.abs(CurTZ) / 60))
		var CurTZm = TF[11] - ((CurTZ >= 0 ? "-" : "+") + (Math.abs(CurTZ) % 60))
			// Return the date
		return new Date(TF[1], TF[2], TF[3], TF[4] - CurTZh, TF[5] - CurTZm, TF[6], TF[7]);
	};
		// If we've reached here we couldn't deal with the input, return null
	return null;

};

Date.parseIso8601IgoneTimeZone = function(CurDate) {

		// Check the input parameters
	if ( typeof CurDate != "string" ) {
		return null;
	};
		// Set the fragment expressions
	var SS = "[ Tt]";
	var S = "[\\-/:.]";
	var Yr = "((?:1[6-9]|[2-9][0-9])[0-9]{2})";
	var Mo = S + "((?:1[012])|(?:0[1-9])|[1-9])";
	var Dy = S + "((?:3[01])|(?:[12][0-9])|(?:0[1-9])|[1-9])";
	var Hr = "(2[0-4]|[01]?[0-9])";
	var Mn = S + "([0-5]?[0-9])";
	var Sd = "(?:" + S + "([0-5]?[0-9])(?:[.,]([0-9]+))?)?";
	var TZ = "(?:(Z)|(?:([\+\-])(1[012]|[0]?[0-9])(?::?([0-5]?[0-9]))?))?";
		// RegEx the input
		// First check: Just date parts (month and day are optional)
		// Second check: Full date plus time (seconds, milliseconds and TimeZone info are optional)
	var TF;
	if ( TF = new RegExp("^" + Yr + "(?:" + Mo + "(?:" + Dy + ")?)?" + "$").exec(CurDate) ) {} else if ( TF = new RegExp("^" + Yr + Mo + Dy + SS + Hr + Mn + Sd + TZ + "$").exec(CurDate) ) {};
		// If the date couldn't be parsed, return null
	if ( !TF ) { return null };
		// Default the Time Fragments if they're not present
	if ( !TF[2] ) { TF[2] = 1 } else { TF[2] = TF[2] - 1 };
	if ( !TF[3] ) { TF[3] = 1 };
	if ( !TF[4] ) { TF[4] = 0 };
	if ( !TF[5] ) { TF[5] = 0 };
	if ( !TF[6] ) { TF[6] = 0 };
	if ( !TF[7] ) { TF[7] = 0 };
	if ( !TF[8] ) { TF[8] = null };
	if ( TF[9] != "-" && TF[9] != "+" ) { TF[9] = null };
	if ( !TF[10] ) { TF[10] = 0 } else { TF[10] = TF[9] + TF[10] };
	if ( !TF[11] ) { TF[11] = 0 } else { TF[11] = TF[9] + TF[11] };
	return new Date(TF[1], TF[2], TF[3], TF[4], TF[5], TF[6], TF[7]);

};

//retrive offset top 
function GetOffsetTop(obj ,parent)
{
	var offset;
	offset = 0;
	while(true)
	{
		if(obj != null)
		{
			if(obj != parent)
			{
				offset += obj.offsetTop;
			}
			else
			{
				return offset;
			}
		}
		else
		{
			return offset;
		}
		obj = obj.offsetParent;
	}
	return offset;
}

//retrive offset left 
function GetOffsetLeft(obj ,parent)
{
	var offset;
	offset = 0;
	while(true)
	{
		if(obj != null)
		{
			if(obj != parent)
			{
				offset += obj.offsetLeft;
			}
			else
			{
				return offset;
			}
		}
		else
		{
			return offset;
		}
		obj = obj.offsetParent;
	}
	return offset;
}

//retrive offset top 
function GetScrollTop(obj ,parent)
{
	var offset;
	offset = 0;
	while(true)
	{
		if(obj != null)
		{
			if(obj != parent)
			{
				offset += obj.scrollTop;
			}
			else
			{
				return offset;
			}
		}
		else
		{
			return offset;
		}
		obj = obj.offsetParent;
	}
	return offset;
}

//retrive offset left 
function GetScrollLeft(obj ,parent)
{
	var offset;
	offset = 0;
	while(true)
	{
		if(obj != null)
		{
			if(obj != parent)
			{
				offset += obj.scrollLeft;
			}
			else
			{
				return offset;
			}
		}
		else
		{
			return offset;
		}
		obj = obj.offsetParent;
	}
	return offset;
}


Date.prototype.toFormattedString = function (format){
	if (format == null) format = "yyyy/MM/dd HH:mm:ss.SSS";
	var year = this.getFullYear();
	var month = this.getMonth();
	var sMonth = ["January","February","March","April","May","June","July","August","September","October","November","December"][month];
	var date = this.getDate();
	var day = this.getDay();
	var hr = this.getHours();
	var min = this.getMinutes();
	var sec = this.getSeconds();
	var daysInYear = Math.ceil((this-new Date(year,0,0))/86400000);
	var weekInYear = Math.ceil((daysInYear+new Date(year,0,1).getDay())/7);
	var weekInMonth = Math.ceil((date+new Date(year,month,1).getDay())/7);
	return format.replace("yyyy",year).replace("yy",year.toString().substr(2)).replace("dd",(date<10?"0":"")+date).replace("HH",(hr<10?"0":"")+hr).replace("KK",(hr%12<10?"0":"")+hr%12).replace("kk",(hr>0&&hr<10?"0":"")+(((hr+23)%24)+1)).replace("hh",(hr>0&&hr<10||hr>12&&hr<22?"0":"")+(((hr+11)%12)+1)).replace("mm",(min<10?"0":"")+min).replace("ss",(sec<10?"0":"")+sec).replace("SSS",this%1000).replace("a",(hr<12?"AM":"PM")).replace("W",weekInMonth).replace("F",Math.ceil(date/7)).replace(/E/g,["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][day]).replace("D",daysInYear).replace("w",weekInYear).replace(/MMMM+/,sMonth).replace("MMM",sMonth.substring(0,3)).replace("MM",(month<9?"0":"")+(month+1));
}

Date.prototype.toUTCDate= function ()
{
    var localOffset = this.getTimezoneOffset() * 60000;
    var utc = this.getTime() + localOffset; 
    return new Date(utc);
} 

Date.prototype.toLocalDate= function ()
{
    var localOffset = this.getTimezoneOffset() * 60000;
    var utc = this.getTime() - localOffset; 
    return new Date(utc);
} 

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

function RemoveEvent(obj,eventType,fn){
	if ( obj.removeEventListener )
	{ 
		obj.removeEventListener(eventType, fn, false); 
	}
	else if ( obj.detachEvent )
	{ 
		obj.detachEvent('on'+eventType,fn); 
	}
	else {
	}
}

function AddRemoveableEvent(obj,eventType,fn){
	if ( obj.addEventListener )
	{ 
		obj.addEventListener(eventType, fn); 
	}
	else if ( obj.attachEvent )
	{ 
		obj.attachEvent('on'+eventType,fn); 
	}
	else {
	}
}


// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to,callback) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
		if(callback)
		{
		    var cbf =  Function.createCallback(callback, id); 
		    setTimeout(cbf, delay ,id);
		}
	},
	set_bgcolor : function (id, c )
	{
		var o = document.getElementById(id);
		if(o)
		{
    		o.style.backgroundColor = c;
    	}
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		if(o)
		{
		    while(o)
		    {
			    var c;
			    if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			    if (o.currentStyle) c = o.currentStyle.backgroundColor;
			    if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			    o = o.parentNode;
		    }
		    if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		    var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		    if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		    return c;
        }
        else
        {
            c = "#FFFFFF";
        }
	}
}

//js dictionary object
function Dictionary()
{
	this.addItem = mAdd;
	this.lookup = mLookup;
	this.deleteItem = mDelete

	function mLookup(strKeyName) {
		return(this[strKeyName]);
	}
	
	function mAdd(strKeyName ,strValue)
	{
		this[strKeyName] = strValue;
	}

	function mDelete(strKeyName)
	{
		this[strKeyName] = null;
	}
}

function Fade()
{
    var m_id;
    var m_timer;
    var m_to;
    var m_flag;
    var m_opacity;
    var m_timeInterval;
    var m_opacityInterval;
    
    
    this.started = false;
    this.start = start;
    this.stop = stop;
    
    function start(id, fps, duration, from, to)
    {
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		
        var frames = Math.round(fps * (duration / 1000));
		m_timeInterval = Math.round(1000 / fps);
		
        m_to = to;
        m_id = id;
        m_opacityInterval = (to - from) / frames;
        m_opacity = from + m_opacityInterval;
        m_timer = setTimeout(timeOut, m_timeInterval);
        this.started = true;
        if(to >= from)
            m_flag = true;
        else
            m_flag = false;
    }
    
    function timeOut()
    {
        if((m_opacity >= m_to && m_flag == true) || (m_opacity <= m_to && m_flag == false))
        {
    		var opacity,h;
			opacity = m_to;
			h = "alpha(opacity=" + opacity + ")";
            setOpacity(m_id, h);
            this.started = false;
        }
        else
        {
    		var opacity,h;
			opacity = Math.round(m_opacity);
			h = "alpha(opacity=" + opacity + ")";
            setOpacity(m_id, h);
            m_opacity += m_opacityInterval;
            m_timer = setTimeout(timeOut, m_timeInterval);
        }
    }
    
    function stop(opacity)
    {
        if(this.started == true)
        {
            setOpacity(m_id, opacity);
            clearTimeout(m_timer);
            this.started = false;
        }
    }
    
    function started()
    {
        return m_started;
    }
    
    function  setOpacity(id, c )
    {
		var o = $get(id);
		if(o != null)
		{
    		o.style.filter = c;
    	}
    }

}

var __isIE = navigator.appVersion.match(/MSIE/);
var __userAgent = navigator.userAgent;
var __isFireFox = __userAgent.match(/firefox/i);
var __isFireFoxOld = __isFireFox &&
   (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;



function __parseBorderWidth(width) {
    var res = 0;
    if (typeof (width) == "string" && width != null
                && width != "") {
        var p = width.indexOf("px");
        if (p >= 0) {
            res = parseInt(width.substring(0, p));
        }
        else {
            //do not know how to calculate other 
            //values (such as 0.5em or 0.1cm) correctly now
            //so just set the width to 1 pixel
            res = 1;
        }
    }
    return res;
}



//returns border width for some element
function __getBorderWidth(element) {
    var res = new Object();
    res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;
    if (window.getComputedStyle) {
        //for Firefox
        var elStyle = window.getComputedStyle(element, null);
        res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));
        res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));
        res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));
        res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));
    }
    else {
        //for other browsers
        res.left = __parseBorderWidth(element.style.borderLeftWidth);
        res.top = __parseBorderWidth(element.style.borderTopWidth);
        res.right = __parseBorderWidth(element.style.borderRightWidth);
        res.bottom = __parseBorderWidth(element.style.borderBottomWidth);
    }

    return res;
}


function __getElementPos(element, parent) {
    var res = new Object();
    res.x = 0; res.y = 0;
    while (true) {
        if (element !== null) {
            if (element == parent)
                break;

            res.x += element.offsetLeft;
            res.y += element.offsetTop;

            var offsetParent = element.offsetParent;
            var parentNode = element.parentNode;
            var borderWidth = null;

            if (offsetParent != null) {
                var parentTagName = offsetParent.tagName.toLowerCase();

                if ((BrowserDetect.browser == "IE" && BrowserDetect.version < 8 && parentTagName != "table") ||
                (__isFireFoxNew && parentTagName == "td")) {
                    borderWidth = __getBorderWidth(offsetParent);
                    res.x += borderWidth.left;
                    res.y += borderWidth.top;
                }

                if (offsetParent != document.body &&
                offsetParent != document.documentElement) {
                    res.x -= offsetParent.scrollLeft;
                    res.y -= offsetParent.scrollTop;
                }

                //next lines are necessary to support FireFox problem with offsetParent
                if (!__isIE) {
                    while (offsetParent != parentNode && parentNode !== null) {
                        res.x -= parentNode.scrollLeft;
                        res.y -= parentNode.scrollTop;

                        if (__isFireFoxOld) {
                            borderWidth = __getBorderWidth(parentNode);
                            res.x += borderWidth.left;
                            res.y += borderWidth.top;
                        }
                        parentNode = parentNode.parentNode;
                    }
                }
            }
            element = offsetParent;
        }
        else
            break;
    }
    return res;
}
