////////////////////////////////////////////////////////
///             RamoSoft NameSpace (Global)
///                 (RamoSoft.NameSpace.js)
///_____________________________________________________
/// Creates a global namespace set to group lib features
///_____________________________________________________
/// Last modification  : Ago/10/2007
/// Last modified by   : Leontti A. Ramos M.
/// Project: RamoSoft Web Framework v3.0
/// Author: Leontti A. Ramos M. (leontti@ramosoft.com)
/// RM International Services S.A. de C.V.
/// http://www.ramosoft.com/
////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
///             RamoSoft Root Namespace
///-----------------------------------------------------
/// Adds library import functionallity and base features
////////////////////////////////////////////////////////
if (typeof(RamoSoft) == 'undefined') {
    RamoSoft = RWF = {
		_Imports : [],
		NAME : 'RamoSoft',
		VERSION : '3.0.9.1107',
		versionString : function(){return 'RamoSoft.Web v' + this.VERSION;},
		toString : function(){return '[' + this.versionString() + ']';}
    };
};
window.status = RamoSoft.toString(); // Let's user know wich version are we using...
////////////////////////////////////////////////////////
///             JavaScript Enhancing Routines
///-----------------------------------------------------
/// Functions to extend javascript and DOM 
////////////////////////////////////////////////////////
/************** FROM PROTOTYPE *********************/
var undefined;// Para comparacion

Object.extend = function(target, source){
	for(var property in source){target[property] = source[property];};
	return target;
};

Object.extend(Object, {
	keys: function(object) {
		var keys = [];
		for (var property in object)keys.push(property);
 		return keys;
 	},
	values: function(object) {
		var values = [];
		for (var property in object)values.push(object[property]);
		return values;
	},
	clone:function(object){return Object.extend({}, object);},
	createSubClass:function(baseDef, newDef){return this.extend(this.clone(baseDef), newDef);},
	allowSubClass:function(Class){
		Class.getSubClass = function(Extender){
			return Object.extend(Object.clone(this), Extender);
		}
	}
});

/*
Object.extend(Object.prototype,{
	isArray: function(){return !!(this.splice && this.join);},
	isString: function(){return this.constructor==String;}
	//isXML: function(){return (this.isString() && (this.indexOf('<?xml') != (-1)));}
});
*/
/*******************************************/
Object.extend(String.prototype, {
	ltrim: function(){return this.replace(/^\s */,'');},
	rtrim: function(){return this.replace(/\s *$/,'');},
	trim: function(){return this.replace(/^s+|s+$/g,'');},
	empty: function(){return '';},
	startsWith: function(test){return this.indexOf(test) === 0;},
	endsWith: function(test){
		var delta = this.length - test.length;
		return ((delta >= 0) && (this.lastIndexOf(test) === delta));
  	},
	isString:true,
	isEmpty: function(){return this == '';}
});

Object.extend(Array.prototype,{
	indexOf: function(Value, fromIdx){
		if(fromIdx == window.undefined) fromIdx = 0;
		if(fromIdx < 0) fromIdx = this.length + fromIdx;
		for (var Index =  fromIdx; Index < this.length; Index++){
			if (this[Index] === Value) return Index;
		}
		return -1;
	},
	exists: function(Value, fromIdx){return this.indexOf(Value, fromIdx) != (-1);},
	clone: function(){return [].concat(this);},
	clear: function(){this.length = 0;return this;},
	first: function(){return this[0];},
	last: function(){return this[this.length - 1];},
	each: function(callBack, Args){return RWF.each(this, callBack, Args)},
	grep: function(test){return RWF.grep(this,test)},
	isArray:true
});

//Function.prototype.bind = function() {
//	var __method = this, args = $A(arguments), object = args.shift();
//	return function(){return __method.apply(object, args.concat($A(arguments)));}
//}
//
//Function.prototype.bindAsEventListener = function(object) {
//  var __method = this, args = $A(arguments), object = args.shift();
//  return function(event) {
//    return __method.apply(object, [event || window.event].concat(args));
//  }
//}

isNothing = function(Obj){return ((Obj == window.undefined) || (Obj == null));}

$ = function(id,node){
	if(id.isString){
		if(!id.startsWith('<')){
		//if('#.:*'.indexOf(id.substring(0,1))>(-1)){
			var ids = id.split(/\s+/)
			//if(id=='.db_viewporttitle .db_titlecommands')alert(node)
			if(node==undefined)node = self.document;
			for(var idx=0;idx<ids.length;idx++){
				if(node.length!=undefined)node=node[0];
				switch(ids[idx].substring(0,1)){
					case "#":
						node = node.getElementById(ids[idx].substring(1));
						//alert(ids[idx]+': '+node)
						break;
					case ".":
						var items;
						ids[idx]=ids[idx].substring(1);
						if(node.getElementsByClassName){
    						items = node.getElementsByClassName(ids[idx]);
					        node=[];
			                for(var itm=0; itm<items.length; itm++){
				                node.push(items[itm])
			                }
    					}else{
                            items = node.getElementsByTagName("*");
                            node=[];
			                for(var itm=0; itm<items.length; itm++){
                                items[itm].className.split(/\s+/).each(function(i,elm){
                                    if(elm==ids[idx])node.push(items[itm]);
                                })
                            }
    					}
						break;
					//case ":":
					//	node = node.getElementById(ids[idx].substring(1));
					//	break;
					//case "@":
					//	node = node.getElementById(ids[idx].substring(1));
					//	break;
					default:
						node = node.getElementsByTagName(ids[idx]);
						if(node.length == 0 && idx == 0) return self.document.getElementById(id)
				}
			}
			return new RWF.query(node);
		}else if(/^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/.exec(id)[1]){
			var div = self.document.createElement('div');
			var items = [];
			div.innerHTML = id;
			for(var idx=0; idx<div.childNodes.length; idx++){
				items.push(div.childNodes[idx])
			}
			div=null;
			return new RWF.query(items);
		}else{
			return self.document.getElementById(id);
		}
	}else if(id.nodeType){
		return new RWF.query(id);
	}else if(typeof id=='object'){
		return id;
    }else if(id.constructor==Function){
        RWF.onReady(id);
        return null;
	}else{return undefined;}
}

RWF.query = function(Elmt){
	var This = this;
	if(Elmt.length==undefined){Elmt = new Array(Elmt)}
	//if(Elmt.length==1)Elmt=Elmt[0];
	this.html = function(html){
		if(html==undefined){
			return Elmt[0].innerHTML;
		}else{
			Elmt[0].innerHTML=html;
			return this;
		}
	}
	this.css = function(style,value){
	    style = RWF.css2Style(style);
		if(value==undefined){
			return Elmt[0].style[style];
		}else{
		    Elmt.each(function(idx,elm){if(elm.nodeType == 1){elm.style[style] = value}})
			return this;
		}
	}
	this.attr = function(name, value){
		if(value==undefined){
			return Elmt[0].getAttribute(name);
		}else{
			Elmt.each(function(idx,elm){elm.setAttribute(name,value)})
			return this;
		}
	}
	this.context = Elmt;
	this.clss = function(){return Elmt[0].className || ''}
	this.hasClass = function(clsName){return this.clss().split(/\s+/).exists(clsName)}
	this._hasCls = function(elm,clsName){return elm.className.split(/\s+/).exists(clsName)}
	this.removeClass = function(clsName){
		Elmt.each(function(idx,elm){
			if(elm.nodeType == 1 && This._hasCls(elm,clsName)){
				elm.className = elm.className.split(/\s+/).grep(function(value){return value!=clsName}).join(' ');
			}
		})
		return this;
	}
	this.addClass = function(clsName){
		Elmt.each(function(idx,elm){
			if (elm.nodeType == 1 && !This._hasCls(elm,clsName)){
				elm.className += (elm.className?' ':'')+clsName;
			}
		})
		return this;
	}
	this.toggleClass = function(clsName){
		Elmt.each(function(idx,elm){
			if(elm.nodeType == 1){
				if(This._hasCls(elm,clsName)){
					elm.className = elm.className.split(/\s+/).grep(function(value){return value!=clsName}).join(' ');
				}else{
					elm.className += (elm.className?' ':'')+clsName;
				}
			}
		})
		return this;
	}
	this.appendTo = function(id){
	    var target = $(id).context[0];
		Elmt.each(function(idx,elm){target.appendChild(elm)})
	}
	RWF.each(('mouseout,mouseover,click,dblclick').split(','),
	    function(idx,fncName){
	        This[fncName] = function(callback){
	            if(callback&&callback.constructor==Function){
    		        Elmt.each(function(idx,elm){elm['on'+fncName] = callback;})
	            }else{
    		        Elmt.each(function(idx,elm){elm['on'+fncName](callback);})
	            };
	        }
	    }
    );
	this.$ = function(selector){return $(selector,Elmt)};
	this.find = this.$;
}

//if (document.getElementById){
//	$ = function(id){return self.document.getElementById(id)}
//	//return self.document.getElementById(ObjId);
//} else if (document.all) {
//	$ = function(id){return self.document.all[ObjId]}
	//return self.document.all[ObjId];
//} else if (document.anchors && document.anchors.length > 0) {
//	for (var Index=0; Index<self.document.anchors.length; Index++) {
//		if(self.document.anchors[Index].name == ObjId) { 
//			return document.anchors[Index];
//		};
//	};
//};

//$ = function(id){return self.document.getElementById(id)}
$$ = function(tag){return self.document.getElementsByTagName(tag)}
RWF.css2Style = function(cssName){
    return cssName.toLowerCase().replace(/\-(\w)/g,function(Key, Val){return Val.toUpperCase()})
};
RWF.style2Css = function(styName){
    return styName.replace(/([A-Z])/g, '-$1').toLowerCase()
};
////////////////////////////////////////////////////////
///             RWF Routine Definition
///-----------------------------------------------------
/// Functions to extend RamoSoft Framework
////////////////////////////////////////////////////////
Object.extend(RamoSoft, {
	addNameSpace: function(Name, useAlias){
		if (typeof(RamoSoft[Name]) == 'undefined') {
			RamoSoft[Name] = {
				NAME : 'RamoSoft.' + Name,
				versionString : function(){return this.NAME + ' v' + RWF.VERSION;},
				toString : function(){return '[' + this.versionString() + ']';}
			};
			if(useAlias){
				if(useAlias.constructor != String){
					useAlias = Name.substr(0,3).toUpperCase();
				}
				eval('_$'+useAlias+'=RWF.'+Name); // It creates a "_$NAM" alias for "RamoSoft.Name"
			};
		};
	},

	include: function(){
	    RWF.each(arguments,function(idx,LibName){
	        if(LibName.constructor==String){
		        try{
			        if(LibName.substring(LibName.length - 4).toLowerCase() == '.css'){
				        if(!RWF.CSSBasePath) RWF.CSSBasePath = './Style/';
				        RWF.importCSS(RWF.CSSBasePath + LibName);
			        } else if(LibName.substring(LibName.length - 3).toLowerCase() == '.js'){
				        RWF.importLib(LibName);
			        } else {
				        if(!RWF.LibBasePath) RWF.LibBasePath = './Script/';
				        RWF.importLib(RWF.LibBasePath + 'RamoSoft.' + LibName + '.js');
			        };
		        }catch(e){
			        throw new Error('Error importing library: ' + LibName);
		        };
            };
	    });
	},

	importLib: function(LibName){
		var KeyName = LibName.toLowerCase();
		var TokenPos = KeyName.lastIndexOf('/');
		if(TokenPos > 0){KeyName = KeyName.substring(TokenPos + 1);};
		if(!RamoSoft._Imports[KeyName]){
			RamoSoft._Imports[KeyName] = LibName;
			var IsLoaded = ($$('body').length > 0);
			if(IsLoaded){
				var DocHead = $$('head')[0];
				var JSObject = document.createElement('script');
				JSObject.type = 'text/javascript';
				JSObject.language = 'JavaScript1.2';
				JSObject.src = RamoSoft._Imports[KeyName];
				JSObject.onload = function(){window.status = 'Import Loaded: ' + JSObject.src};
				DocHead.appendChild(JSObject);
			} else {
				document.write('<scr'+'ipt');
				document.write(' language="JavaScript1.2"');
				document.write(' type="text/javascript"');
				document.write(' src="'+RamoSoft._Imports[KeyName]+'">');
				document.write('</scr'+'ipt>');
			};
		};
	},

	importCSS: function(CSSName){
		var DocHead = $$('head')[0];
		var CSSLink = self.document.createElement('link');
		CSSLink.rel = 'stylesheet';
		CSSLink.type = 'text/css'; 
		CSSLink.href = CSSName;
		DocHead.appendChild(CSSLink);
	},

	executeScript: function(JSCode){
		//alert('Script: >'+JSCode+'<')
		try{
			if(JSCode.length){
				if (window.execScript){        	
					window.execScript(JSCode)
				}else{        	
					window.setTimeout(JSCode, 0);
				};
			};	
		} catch(e){
			throw new Error(this.toString() + ': Error in script ' + JSCode);
		};
	},
	
	addEvent: function(Obj, evType, CallBack){
		if (Obj.addEventListener){
			Obj.addEventListener(evType, CallBack, false);
			return true;
		} else if (Obj.attachEvent){
			return Obj.attachEvent("on"+evType, CallBack);
		} else {
			return false;
		};
	},

	removeEvent: function(Obj, evType, CallBack){
		if (Obj.removeEventListener){
			Obj.removeEventListener(evType, CallBack, false);
			return true;
		} else if (Obj.detachEvent){
			return Obj.detachEvent("on"+evType, CallBack);
		} else {
			//alert("Handler could not be removed");
		};
	},

	resolveElement: function(ObjId){
		if(ObjId && ObjId.constructor == String){
		//if(typeof(Element) == 'string'){
			if (document.getElementById){
				return self.document.getElementById(ObjId);
			} else if (document.all) {
				return self.document.all[ObjId];
			} else if (document.anchors && document.anchors.length > 0) {
				for (var Index=0; Index<self.document.anchors.length; Index++) {
					if(self.document.anchors[Index].name == ObjId) { 
						return document.anchors[Index];
					};
				};
			};
		} else {
			return ObjId;
		};
	},
	each: function(arry, callFunc, callArgs){ // RWF.each(obj|arr,function(){},[args])
		var key, idx = 0,
		arrSize = arry.length;
		if(callArgs){
			if(arrSize === undefined){
				for(key in arry){
					if(callFunc.apply(arry[key], callArgs)===false){break}
				}
			}else{
				for(; idx < arrSize;){
					if(callFunc.apply(arry[idx++], callArgs)===false){break}
				}
			}
		}else{
			if(arrSize===undefined){
				for(key in arry){
					if(callFunc.call(arry[key], key, arry[key]) === false){break}
				}
			}else{
				for(var J = arry[0]; idx < arrSize && callFunc.call(J, idx, J) !== false; J = arry[++idx]){}
			}
		}
		return arry
	},
	grep: function(arry, test) {
		var match = [];
		for(var idx = 0; idx < arry.length; idx++){
			if(test(arry[idx],idx)){match.push(arry[idx])}
		}
		return match;
	}
});
	
////////////////////////////////////////////////////////
///             RamoSoft Import Namespaces
///-----------------------------------------------------
/// Library imports shortcuts
/// This function allows to import Ramosoft.base libraries
/// with a short name
////////////////////////////////////////////////////////
(function(Aliases){
	RamoSoft.addNameSpace('Import');
	var Alias = Aliases.split(',');
	for(var Idx = 0; Idx < Alias.length; Idx++){
		RamoSoft.Import[Alias[Idx]] = function(){RamoSoft.include(arguments.callee.libName);};
		RamoSoft.Import[Alias[Idx]].libName = Alias[Idx];
	};
})('Ajax,Window,Effects,Grid,Input,TabStrip,MenuBar,WorkSpace,SearchBox,Time,DragDrop,XML,Bubble,Grid,TopMenu,Language');

//RamoSoft.addNameSpace('Import');
//
//RamoSoft.Import.defAlias = function(Aliases){
//	var Alias = Aliases.split(',');
//	for(var Idx = 0; Idx < Alias.length; Idx++){
//		RamoSoft.Import[Alias[Idx]] = function(){RamoSoft.include(arguments.callee.libName);};
//		RamoSoft.Import[Alias[Idx]].libName = Alias[Idx];
//	};
//};
//
//RamoSoft.Import.defAlias('Ajax,Window,Effects,Grid,Input,TabStrip,MenuBar,WorkSpace,SearchBox,Time,DragDrop,XML,JSON,Grid,TopMenu');
//RamoSoft.Import.Ajax = function(){RamoSoft.include('Ajax');};

////////////////////////////////////////////////////////
///             RamoSoft Common Namespace
///-----------------------------------------------------
/// Group commonly used functions for global usage
////////////////////////////////////////////////////////
//RamoSoft.addNameSpace('Common','CMN');
////////////////////////////////////////////////////////
///             RamoSoft Environment Namespace
///-----------------------------------------------------
/// Group environment values for global usage
////////////////////////////////////////////////////////
RamoSoft.addNameSpace('Environment',true);

Object.extend(RamoSoft.Environment, {
	viewPortHeight: function() {
		if(window.innerHeight != window.undefined) return window.innerHeight; //Non-IE
		if(document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight; //IE 6+ in 'standards compliant mode'
		if(document.body && document.body.clientHeight) return document.body.clientHeight; //IE 4 compatible
	},

	viewPortWidth: function() {
		if(window.innerWidth != window.undefined) return window.innerWidth; //Non-IE
		if(document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth; //IE 6+ in 'standards compliant mode'
		if(document.body && document.body.clientWidth) return document.body.clientWidth; //IE 4 compatible
	},

	scrollTop: function() {
		if(window.pageYOffset != window.undefined) return window.pageYOffset; //Non-IE
		if(document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop; //IE 6+ in 'standards compliant mode'
		if(document.body && document.body.scrollTop) return document.body.scrollTop; //IE 4 compatible
	},

	scrollLeft: function() {
		if(window.pageXOffset != window.undefined) return window.pageXOffset; //Non-IE
		if(document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft; //IE 6+ in 'standards compliant mode'
		if(document.body && document.body.scrollLeft) return document.body.scrollLeft; //IE 4 compatible
	}
});

////////////////////////////////////////////////////////
///             RamoSoft UI Namespace
///-----------------------------------------------------
/// Functions to build base screen elements
////////////////////////////////////////////////////////
//RamoSoft.addNameSpace('Platform',true);

Object.extend(RamoSoft, {
	os: {
		isMac:false,
		isWin:false,
		isWin32:false,
		isUnix:false
	},
	browser: {
		isIE:false,
		isNetscape:false,
		isMozilla:false,
		isFirefox:false,
		isOpera:false,
		isSafari:false,
		isChrome:false,

		majorVersion:0,
		minorVersion:0
	}
});

(function(os,browser){
	var an=navigator.appName.toLowerCase();
	var ua=navigator.userAgent.toLowerCase();

	os.isMac=(ua.indexOf('mac')!=-1);
	os.isWin=(ua.indexOf('win')!=-1);

	os.isWin32=os.isWin && (
		ua.indexOf('95')!=-1||
		ua.indexOf('98')!=-1||
		ua.indexOf('nt')!=-1||
		ua.indexOf('win32')!=-1||
		ua.indexOf('32bit')!=-1
	);
	os.isUnix=(ua.indexOf('x11')!=-1);

	browser.isIE=(an.indexOf("microsoft")!=-1);
	browser.isNetscape=(an.indexOf("netscape")!=-1);
	browser.isMozilla=(ua.indexOf("mozilla")!=-1);
	browser.isFirefox=(ua.indexOf("firefox")!=-1);
	browser.isOpera=(an.indexOf("opera")!=-1);
	browser.isChrome=(ua.indexOf("chrome")!=-1);

	var parseVersionString=function(s,browser){
		var a=s.split(".");
		browser.majorVersion=parseInt(a[0]);
		browser.minorVersion=parseInt(a[1]);
	};
	var indexOf=function(s,sub,start){
		var i=s.indexOf(sub,start);
		return i>=0?i:s.length;
	};

	if(browser.isMozilla){
		var offset=ua.indexOf("mozilla/");
		if(offset>=0) parseVersionString(ua.substring(offset+8,indexOf(ua," ",offset)),browser);
	}
	if(browser.isIE){
		var offset=ua.indexOf("msie ");
		if(offset>=0) parseVersionString(ua.substring(offset+5,indexOf(ua,";",offset)),browser);
	}
	if(browser.isNetscape){
		var offset=ua.indexOf("rv:");
		if(offset>=0) parseVersionString(ua.substring(offset+3,indexOf(ua,")",offset)),browser);
	}
	if(browser.isFirefox){
		var offset=ua.indexOf("firefox/");
		if(offset>=0) parseVersionString(ua.substring(offset+8,indexOf(ua," ",offset)),browser);
	}
})(RamoSoft.os,RamoSoft.browser);

////////////////////////////////////////////////////////
///             RamoSoft UI Namespace
///-----------------------------------------------------
/// Functions to build base screen elements
////////////////////////////////////////////////////////
RamoSoft.addNameSpace('UI',true);
// _$UI equals to RamoSoft.UI
Object.extend(RamoSoft.UI, {
	screenLockzIndex: 200000,

	getChildVersion: function(Name){'['+this.NAME+'.'+Name+' v'+this.VERSION+']'},

	getPageBody: function(){
		return (document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body
	},

	getIFrameDocument: function(IFrame){
		try{
			return IFrame.contentWindow ? IFrame.contentWindow.document : IFrame.contentDocument;
		} catch(e) {
			return null;
		};
	},

	getIFrameBody: function(IFrame){
		var Doc = this.getIFrameDocument(IFrame);
		if(Doc){
			if(Doc.documentElement) return Doc.documentElement; //IE 6+ in 'standards compliant mode'
			if(Doc.body) return Doc.body; //IE 4 compatible
		};
	},

	getEmptyTable: function(CellCount, RowCount) {
		var Table = self.document.createElement('TABLE');

		Table.border= 0;
		Table.cellPadding = 0;
		Table.cellSpacing = 0;
		if (!CellCount) CellCount = 0;
		if(CellCount > 0) {
			if (!RowCount) RowCount = 1;
			for(var RowIdx = 0; RowIdx < RowCount; RowIdx++){
				Table.insertRow(RowIdx);
				for(var CellIdx = 0; CellIdx < CellCount; CellIdx++){
					Table.rows[RowIdx].insertCell(CellIdx);
				};
			};
		};
		return Table;
	},

	getEventPoint: function(e, relatedTo) {
		var Point = this.getEmptyPoint();
		if(!e) e = window.event;
		Point.x = e.clientX;
		Point.y = e.clientY;
		Point.x += this.getScrollLeft();
		Point.y += this.getScrollTop();
		if(relatedTo){
			var Relat = this.getPosition(relatedTo);
			Point.x -= Relat.x;
			Point.y -= Relat.y;
		};
		return Point;
		/*
		function getPosition(e) {
		    e = e || window.event;
		    var cursor = {x:0, y:0};
		    if (e.pageX || e.pageY) {
		        cursor.x = e.pageX;
		        cursor.y = e.pageY;
		    } else {
		        cursor.x = e.clientX - document.documentElement.clientLeft +
		            (document.documentElement.scrollLeft || document.body.scrollLeft);
		        cursor.y = e.clientY - document.documentElement.clientTop +
		            (document.documentElement.scrollTop || document.body.scrollTop);
		    }
		    return cursor;
		}
		*/
	},

	getScrollLeft: function(){
		if(window.pageXOffset){
			return window.pageXOffset;
		} else {
			return Math.max(document.body.scrollLeft,document.documentElement.scrollLeft);
		};
	},

	getScrollTop: function(){
		if(window.pageYOffset){
			return window.pageYOffset;
		 } else {
			return Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		 };
	},

	getLeftPos: function(Elem){return this.getPosition(Elem).x;},
	
	getTopPos: function(Elem){return this.getPosition(Elem).y;},

	getWidth: function(Elem) {
		return this.getBoundingRect(Elem).w
		//if (document.getBoundingClientRect){
		//	var rect = document.getBoundingClientRect(Elem)
		//	return rect.right - rect.left;
		//} else if (document.getBoxObjectFor){
		//	//if(Elem.tagName!='INPUT' && Elem.tagName!='SELECT' && Elem.tagName!='TEXTAREA')
		//	return document.getBoxObjectFor(Elem).width;
		//} else {
		//	this._forceVisibility(Elem);
		//	var orgWidth = Elem.offsetWidth?Elem.offsetWidth:Elem.clientWidth;
		//	this._restoreVisibility(Elem);
		//	return orgWidth;
		//};
	},

	getHeight: function(Elem) {
		return this.getBoundingRect(Elem).h
		//if (document.getBoundingClientRect){
		//	var rect = document.getBoundingClientRect(Elem)
		//	return rect.bottom - rect.top;
		//} else if (document.getBoxObjectFor){
		//	//if(Elem.tagName!='INPUT' && Elem.tagName!='SELECT' && Elem.tagName!='TEXTAREA')
		//	return document.getBoxObjectFor(Elem).height;
		//} else {
		//	this._forceVisibility(Elem);
		//	var orgHeight = Elem.offsetHeight?Elem.offsetHeight:Elem.clientHeight;
		//	this._restoreVisibility(Elem);
		//	return orgHeight;
		//};
	},

	getPosition: function(Elem) {
		var Point = this.getEmptyPoint();
		
		if (document.getBoundingClientRect){
			var box = document.getBoundingClientRect(Elem);
			Point.x = box.left;Point.y = box.top;
		} else if (document.getBoxObjectFor){
			//var box = document.getBoxObjectFor(Elem);
			//Point.x = box.x;Point.y = box.y;
			if(Elem.parentNode.tagName.toLowerCase()=='body'){
				Point.x = Elem.offsetLeft;
				Point.y = Elem.offsetTop;
			}else{
				var box = document.getBoxObjectFor(Elem);
				Point.x=box.x; Point.y=box.y; 
			}
		} else {
			var TagName = '';
			Point.x = Elem.offsetLeft;
			Point.y = Elem.offsetTop;
			while((Elem = Elem.offsetParent) != null){
				TagName = Elem.tagName.toLowerCase();
				if(TagName != 'html'){
					Point.x += (Elem.offsetLeft - Elem.scrollLeft);
					Point.y += (Elem.offsetTop - Elem.scrollTop);
					if(Elem.clientLeft && TagName != 'table' && TagName!='body') {
						Point.x += Elem.clientLeft;
						Point.y += Elem.clientTop;
					};
				};
			};
		};
		//Point.x += this.getScrollLeft();
		//Point.y += this.getScrollTop();
		return Point;
	},

	getBoundingRect: function(Elem) {
		var Rect = this.getEmptyRect();
		if (document.getBoundingClientRect){
			//alert('document.getBoundingClientRect')
			var box = document.getBoundingClientRect(Elem);
			Rect.x=box.left; Rect.y=box.top; Rect.w=(box.right - box.left); Rect.h=(box.bottom - box.top);
		} else if (document.getBoxObjectFor){
			var box = document.getBoxObjectFor(Elem);
			Rect.w=box.width; Rect.h=box.height;
			Rect.x=box.x; Rect.y=box.y;
			//do{
			//	box = document.getBoxObjectFor(Elem);
			//	alert('Tag:'+Elem.tagName)
			//	alert('Elem.clientLeft:'+Elem.clientLeft)
			//	alert('box.x:'+box.x)
			//	Rect.x += Elem.clientLeft;
			//	Rect.y += Elem.clientTop;
			//}while((Elem = Elem.offsetParent) != null)
			//if(Elem.parentNode.tagName.toLowerCase()=='body'){
			//	Rect.x=box.x; Rect.y=box.y; 
			//}else{
			//	while((Elem = Elem.offsetParent) != null){
			//	Rect.x = Elem.offsetLeft;
			//	Rect.y = Elem.offsetTop;
			//}
		} else {
			this._forceVisibility(Elem);
			Rect.w = Elem.offsetWidth?Elem.offsetWidth:Elem.clientWidth;
			Rect.h = Elem.offsetHeight?Elem.offsetHeight:Elem.clientHeight;
			this._restoreVisibility(Elem);

			var TagName = '';
			Rect.x = Elem.offsetLeft;
			Rect.y = Elem.offsetTop;
			while((Elem = Elem.offsetParent) != null){
				TagName = Elem.tagName.toLowerCase();
				if(TagName != 'html'){
					Rect.x += (Elem.offsetLeft - Elem.scrollLeft);
					Rect.y += (Elem.offsetTop - Elem.scrollTop);
					if(Elem.clientLeft && TagName != 'table' && TagName!='body') { 
						Rect.x += Elem.clientLeft;
						Rect.y += Elem.clientTop;
					};
				};
			};
		}
		Rect.x += this.getScrollLeft();
		Rect.y += this.getScrollTop();
		return Rect;
	},

	getEmptyRect: function(){return {x:0,y:0,w:0,h:0,toString:function(){return '{x:'+this.x+',y:'+this.y+',w:'+this.w+',h:'+this.h+'}';}};},
	
	getEmptyPoint: function(){return {x:0,y:0,toString:function(){return '{x:'+this.x+',y:'+this.y+'}';}};},

	getCenteredRect: function(Width,Height){
		var Rect = this.getEmptyRect();

		Rect.w = Width;
		var ScrW = _$ENV.viewPortWidth() - Width;
		Rect.x = (ScrW / 2);

		Rect.h = Height;
		var ScrH = _$ENV.viewPortHeight() - Height;
		Rect.y = (ScrH / 2);

		return Rect;
	},

	_forceVisibility: function(El){
		El._orgVisibility = El.style.visibility;
		El._orgPosition = El.style.position;
		El._orgDisplay = El.style.display;
		El.style.visibility = 'hidden';
		El.style.position = (El.parentNode.tagName == 'BODY')?'absolute':'relative'//'absolute';
		El.style.display = 'block';
	},

	_restoreVisibility: function(El){
		El.style.display = El._orgDisplay;
		El.style.position = El._orgPosition;
		El.style.visibility = El._orgVisibility;
		El._orgDisplay = null;
		El._orgPosition = null;
		El._orgVisibility = null;
		try{
			delete El._orgDisplay;
			delete El._orgPosition;
			delete El._orgVisibility;
		}catch(e){};
	},

	sendToTop: function(Elem){
		if(!this._maxZIndex) this._maxZIndex = 0;
		if(Elem.style.zIndex <= this._maxZIndex){
			Elem.style.zIndex = ++this._maxZIndex;
		};
	},

	unlockScreen: function(){
		this._lockCount--;
		if(this._lockCount < 0){
			this._lockCount = 0;
		}else if(this._lockCount == 0){
			this.getPageBody().removeChild(this._divScrMask);
			this._hideDDowns(true);
			this._enableTabs();
			this._divScrMask = null
			delete this._divScrMask;
			RamoSoft.removeEvent(window,'scroll',this._repositionLockMask);
			RamoSoft.removeEvent(window,'resize',this._repositionLockMask);
		};
	},

	lockScreen: function(Opacity,inner){
		//throw '';
		Opacity=Opacity?((Opacity>100)?100:((Opacity<0)?0:Opacity)):40;
		if(!this._lockCount) this._lockCount = 0;
		if(this._lockCount == 0){
			this._disableTabs();
			this._hideDDowns();
			this._divScrMask = self.document.createElement('div');
			if(inner != window.undefined){
				this._divScrMask.style.textAlign = 'center';
				this._divScrMask.style.verticalAlign = 'middle';
				if(typeof(inner) == 'string'){
					this._divScrMask.innerHTML = inner;
				}else{
					this._divScrMask.appendChild(inner);
				}
			}
			this.getPageBody().appendChild(this._divScrMask);
			var sty = this._divScrMask.style;
			sty.filter = 'alpha(opacity='+Opacity+')';/* Transparency */
			sty.opacity = (Opacity / 100)//'0.4';/* Transparency */
			sty.backgroundColor = '#AAA';//'silver'//'rgb(237,245,250)';//'#AAA';
			sty.position = 'absolute';
			sty.zIndex = this.screenLockzIndex;
			this._repositionLockMask();
			RWF.addEvent(window,'scroll',this._repositionLockMask);
			RWF.addEvent(window,'resize',this._repositionLockMask);

		}
		this._lockCount++;
	},

	_repositionLockMask: function(){
		var msk = RWF.UI._divScrMask;
		msk.style.top = Math.max(document.body.scrollTop,document.documentElement.scrollTop) + 'px';
		msk.style.left = Math.max(document.body.scrollLeft,document.documentElement.scrollLeft) + 'px';
		msk.style.width = RWF.Environment.viewPortWidth() + 'px';
		msk.style.height = RWF.Environment.viewPortHeight() + 'px';		
		//msk.style.width = RWF.Environment.viewPortWidth() + 'px';
		//msk.style.height = RWF.Environment.viewPortHeight() + 'px';		
	},

	_hideDDowns: function(restore){
		if(RWF.browser.isIE) { // For IE
			var items = document.getElementsByTagName("select");
			var ifrms = document.getElementsByTagName("iframe");
			if(restore){
				for(var itm=0; itm<items.length; itm++){
					if(ifrsl[ifs].getAttribute('bkVisibility') != undefined){
						items[itm].style.visibility = items[itm].getAttribute('bkVisibility');
						items[itm].setAttribute('bkVisibility',null);
					}
				}
				for(var frm=0; frm<ifrms.length; frm++){
					var ifrsl=ifrms[frm].contentWindow.document.getElementsByTagName("select");
					for(var ifs=0;ifs<ifrsl.length;ifs++){
						if(ifrsl[ifs].getAttribute('bkVisibility') != undefined){
							ifrsl[ifs].style.visibility = ifrsl[ifs].getAttribute('bkVisibility');
							ifrsl[ifs].setAttribute('bkVisibility',null);
						}
					};
				}
			}else{
				for(var itm=0; itm<items.length; itm++){
					items[itm].setAttribute('bkVisibility',items[itm].style.visibility);
					items[itm].style.visibility = 'hidden';
				}
				for(var frm=0; frm<ifrms.length; frm++){
					try{
						var ifrsl=ifrms[frm].contentWindow.document.getElementsByTagName("select");
						for(var ifs=0;ifs<ifrsl.length;ifs++){
							ifrsl[ifs].setAttribute('bkVisibility',ifrsl[ifs].style.visibility);
							ifrsl[ifs].style.visibility = 'hidden';
						};
					}catch(e){}
				}
			}
		};
	},

	_disableTabs: function(){
		if(document.all) { // For IE
			this.TabIndexes = [];
			this._TabTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	
			var ItemIdx = 0;
			for (var TypeIdx = 0; TypeIdx < this._TabTags.length; TypeIdx++) {// For each tag type
				var Elements = $$(this._TabTags[TypeIdx]);// Get all elements of that type
				for (var ListIdx = 0 ; ListIdx < Elements.length; ListIdx++) {// For each element of current type
					this.TabIndexes[ItemIdx] = Elements[ListIdx].tabIndex;
					Elements[ListIdx].tabIndex = '-1';
					ItemIdx++;
				};
			};
		} else { // For Mozilla, Firefox, etc.
			this._KeyDwnHandler = document.onkeypress;
			document.onkeypress = function (e) {
				if (e.keyCode == 9) return false;
			};
		};
	},

	_enableTabs: function(){
		if (document.all) { // For IE
			var ItemIdx = 0;
			for (var TypeIdx = 0; TypeIdx < this._TabTags.length; TypeIdx++) {
				var Elements = $$(this._TabTags[TypeIdx]);
				for (var ListIdx = 0 ; ListIdx < Elements.length; ListIdx++) {
					Elements[ListIdx].tabIndex = this.TabIndexes[ItemIdx];
					Elements[ListIdx].tabEnabled = true;
					ItemIdx++;
				};
			};
		} else { // For Mozilla, Firefox, etc.
			document.onkeypress = this._KeyDwnHandler;
		};
	}
});


RamoSoft.addNameSpace('Ajax');
////////////////////////////////////////////////////////
RamoSoft.Ajax = Ajax = function(url, postData, options, callBack){
	var This=this;
	this.onLoading = function(){};
	this.onLoaded = function(){};
	this.onInteractive = function(){};
	this.onCompletion = function(httpCode){};
	this.onError = function(httpCode){};
	this.isBusy = false;
    if(!options)options={}
	this.XmlHttp = (function(){
		if(window.XMLHttpRequest){return new XMLHttpRequest();}
		else{
			try {return new ActiveXObject('Msxml2.XMLHTTP');}
			catch(e){
				try {return new ActiveXObject('Microsoft.XMLHTTP');}
				catch(e){return null;}
			}
		}
	})()
	
	this.paramString = (function(params,cache){
			if(params.constructor == String){
				// just proceed
			}else if((params.constructor == Object) || (params.constructor == Array)){
				var query = '';

				for (key in params) {
					if(params[key].constructor != Function){
						query+='&'+encodeURIComponent(key);
						query+='='+encodeURIComponent(params[key]);
					};
				};
			}
			if(!cache){query+='&_tmst_='+new Date().getTime()};
			return (query.length)?query.substring(1):'';
		})(postData, (options.cache?true:false));

	this.executeJScripts = function(Element){
		var JSBlocks = Element.getElementsByTagName('SCRIPT');
		var JSCode = '';
		for(var ScriptIdx = 0; ScriptIdx < JSBlocks.length; ScriptIdx++){	
			if(JSBlocks[ScriptIdx].src){RamoSoft.importLib(JSBlocks[ScriptIdx].src);}
			else{
				if(navigator.userAgent.indexOf('Opera') >= 0){JSCode += JSBlocks[ScriptIdx].text + '\n';}
				else{JSCode += JSBlocks[ScriptIdx].innerHTML;}
			}
		}
		RWF.executeScript(JSCode);
	};

	this.setContent = function(targetID, innerText){
		targetID = $(targetID)
		if(targetID && targetID != window.undefined){
				targetID.innerHTML = innerText;
				this.executeJScripts(targetID);
		}
	}

	if(this.XmlHttp){
		this.XmlHttp.onreadystatechange = function() {
			switch (This.XmlHttp.readyState) {
				case 1:
					This.onLoading();
					break;
				case 2:
					This.onLoaded();
					break;
				case 3:
					This.onInteractive();
					break;
				case 4:
					try{
						This.onCompletion(This.XmlHttp.status);
					}catch(e){}
					if ((This.XmlHttp.status == 200) && (This.XmlHttp.responseText.length > 0)){
						if(callBack && callBack.constructor == Function){
							var response;
							switch(options.dataType.toLowerCase()){
								case 'text':
									response = This.XmlHttp.responseText;
									break;
								case 'json':
									response = RamoSoft.json(This.XmlHttp.responseText);
									break;
								case 'xml':
									response = This.XmlHttp.responseXML;
									break;
								default:
									response = This.XmlHttp.responseText;
									break;
							}
							var retCD = callBack(response,This.XmlHttp.responseText);
							if(!retCD && options.htmlHost){
								This.setContent(options.htmlHost, This.XmlHttp.responseText);
							}
						} else if(callBack && (callBack.constructor == String || callBack.constructor == Object)){
							This.setContent(callBack, This.XmlHttp.responseText);
						} else if(options.htmlHost){
							This.setContent(options.htmlHost, This.XmlHttp.responseText);
						}
						
					}else if(This.XmlHttp.status == 500){
						This.onError(500);
					}
					This.isBusy = false;
					break;
			}
		};
	}else{
		return null;
	}
	this.isBusy = true;
	var sendData = null;
	if(options.method && options.method.toUpperCase()=='GET'){
		if(this.paramString.length>0){
			url+='?'+this.paramString;
		}
		this.XmlHttp.open('GET',url,true);
	}else{
		this.XmlHttp.open('POST',url,true);
		this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
		sendData = this.paramString;
	}
	this.XmlHttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	this.XmlHttp.setRequestHeader('X-Powered-By', RWF.versionString());
	try{
		this.XmlHttp.send(sendData);
	} catch(e){
		this.onError(0);
	}
	return true;
};
////////////////////////////////////////////////////////
RWF.getCookie = function(Name,defVal){ //get cookie value
	if(document.cookie && document.cookie!=''){
		var rgex=new RegExp(Name+'=[^;]+', 'i'); 
		if(document.cookie.match(rgex)){
			return decodeURIComponent(document.cookie.match(rgex)[0].split('=')[1]) 
		}
	}
	if(!defVal || defVal==window.undefined) defVal='';
	return defVal;
}

RWF.setCookie = function(name, value, options) {
	options = options || {};
	if(value===null){
		value = '';
		options.expires = -1;
	}else{
		options.expires=options.expires || 365;
	}
	var expires = '', expDate
	if(options.expires.toUTCString){
		expDate = options.expires;
	}else{
		expDate=new Date();
		expDate.setDate(expDate.getDate()+parseInt(options.expires))
	}
	expires='; expires='+expDate.toUTCString();
	// Needed to parenthesize options.path and options.domain
	document.cookie = name+'='+encodeURIComponent(value)
		+expires
		+(options.path?'; path='+(options.path):'')
		+(options.domain?'; domain='+(options.domain):'')
		+(options.secure?'; secure':'');
};
////////////////////////////////////////////////////////
RWF.appendHTML = function(html,owner){
	var div = self.document.createElement('div');
	var items = [];
	if(owner && owner.nodeType==1){}else{owner = RWF.UI.getPageBody()}
	div.innerHTML = html;
	for(var idx=0; idx<div.childNodes.length; idx++){
		owner.appendChild(div.childNodes[idx])
	}
	div=null;
}
////////////////////////////////////////////////////////
function quickTip(owner,tipText){
/*	if(isNothing($('_divQuicktip'))){
		
		$('body').append('<div id="chat_tooltip"><div class="chat_tooltip_content">'+tipText+'</div></div>')
	}else{
		$('_divQuicktip').firstChild.innerHTML = tipText
	}
	
	var offSet=$("#"+tipObj).offset();
	var objWdt=$("#"+tipObj).width();
	var tipWdt=$(cssChatTip).width();
	if(left2Right==1){
		$(cssChatTip).css(cssBottom,29).css(cssLeft,(offSet.left+objWdt)-16).css(cssDisplay,cssBlock).addClass('chat_tooltip_left')
	}else{
		$(cssChatTip).css(cssBottom,29).css(cssLeft,(offSet.left+objWdt)-tipWdt+12).css(cssDisplay,cssBlock).removeClass('chat_tooltip_left')
	}
	if(IsIE6){
		$(cssChatTip).css(cssPosition,cssAbsolute);
		$(cssChatTip).css('top',parseInt($(window).height())-parseInt($(cssChatTip).css(cssBottom))-parseInt($(cssChatTip).height())+$(window).scrollTop()+'px')
	}*/
}
////////////////////////////////////////////////////////
RamoSoft.json = function(jsonText, tranformRoutine) {
    if(jsonText.lenght == 0) return null;
    this._transform = tranformRoutine; //|| function(key, value){return value;};
    this._walkObj = function(key, value){
        if(value){
            if(value.constructor == Object){
                for(var property in value){
                    if(value.hasOwnProperty(property)){
                        value[property] = this._walkObj(property,value[property]);
                    };
                };
            } else if(value.constructor == Array){
                for(var Idx in value){
                    value[Idx] = this._walkObj(null,value[Idx]);
                };
            };
            return this._transform(key,value);
        } else {
            return value;
        };
    };
    var regx = [/^[\],:{}\s]*$/,/\\./g,/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(:?[eE][+\-]?\d+)?/g,/(?:^|:|,)(?:\s*\[)+/g];
    if (regx[0].test(jsonText.replace(regx[1], '@').replace(regx[2], ']').replace(regx[3], ''))) {
        try{
            var newObj = eval('(' + jsonText + ')');
            if(typeof(this._transform) == 'function'){
                return this._walkObj(null,newObj);
            } else {
                return newObj;
            };
        }catch(e){
            return null;
        }
    }
};
////////////////////////////////
var _docReadyFlag = false;
Object.extend(RWF,{
    redirect:function(newURL){
        if(RWF.browser.isIE)window.location.href=newURL;
        else window.location=newURL;
    },
    isReady:false,
    readyList:[],
    doReady:function(){
        if (!RWF.isReady) {
            RWF.isReady = true;
            if(RWF.readyList)RWF.readyList.each(function(){this.call(document)});
            RWF.readyList= null
        }
    },
    onReady:function(fnCall){
        if(!_docReadyFlag){
            _docReadyFlag=true;
            (function(){
                if(document.addEventListener){
                    document.addEventListener('DOMContentLoaded',function(){
                        document.removeEventListener('DOMContentLoaded', arguments.callee, false);
                        RWF.doReady();
                    },false)
                }else if(document.attachEvent){
                    document.attachEvent('onreadystatechange',function(){
                        if(document.readyState==='complete'){
                            document.detachEvent('onreadystatechange', arguments.callee);
                            RWF.doReady();
                        }
                    });
                }
            })();
        }
        if(RWF.isReady)fnCall.call(document);
        else RWF.readyList.push(fnCall);
        return null;
    }
});


