
document.onselectstart=function(){ return false; }

var BS=function(){
	var _public={
		timezoneOffset:0,	
		user:null,
		pass:null,
		userBits:null,
		_debug:"ON",
		UI		:{},
		GENERIC	:{},
		UTILS	:{},
		INPUT   :{},
		Dialog  :{},
		misc	:{},
		Debug:function (name,e,data){ 
			if(!e) var e=""; 
			if(this._debug=="ON") {
				var data2="\r{ \r   "; 
				for(a in data) {
					if(data2.length>7) data2+=",\r   ";
					data2+=a+":"+data[a];
				}
				alert(name+": "+e.toString()+data2+"\r}"); 
			}
		}//END DEBUG
	}

	return _public;
}();

BS.GENERIC=function(){
	var _public={
			getStyle:function (style){
				var sheets = document.styleSheets;
				var ruleLength=0;
				var sheetLength=sheets.length;
				style="."+style;

				for(var sheet=0;sheet<sheetLength;sheet++){
					if(sheets[sheet].cssRules) {							//FIREFOX
						ruleLength=sheets[sheet].cssRules.length;
						for(var rule=0;rule<ruleLength;rule++){
							if(selectorText=sheets[sheet].cssRules[rule].selectorText.toLowerCase()== style.toLowerCase()) {
								return sheets[sheet].cssRules[rule];
							}
						}
					} else{													//IE
						ruleLength=sheets[sheet].rules.length;	
						for(var rule=0;rule<ruleLength;rule++){
							if(sheets[sheet].rules[rule].selectorText.toLowerCase()== style.toLowerCase()) {
								return sheets[sheet].rules[rule];
							}
						}//end rule loop
					}
				}//end sheet loop
				return null;
			},
            rollOver:function(uid,imageObj){
                try {
                    var target=window.document.getElementById(uid);
					if(target) {
                    	target.style.backgroundImage="url('"+imageObj+"')";
					}
				} catch(ex) { BS.Debug("Rollover",ex,id); }
            },
			toggleElement:function(element){
				var d=window.document.getElementById(element);
				if(d) { if(d.style.display=="none") d.style.display="block"; else d.style.display="none"; }	},
			//m.left,,m.top,m.width1,m.width2,m.width3,m.height
			slice3:function(m){
				m.x1=m.left;
				m.x2=m.left+m.width1;
				m.x3=m.left+m.width1+m.width2;
				m.width=m.width1+m.width2+m.width3;

			/*	if(!m.leftRepeat  ) m.leftRepeat  ="repeat";
				if(!m.centerRepeat) m.centerRepeat="repeat";
				if(!m.rightRepeat ) m.rightRepeat ="repeat";
				*/
				var o1={element:"div",left:m.x1,top:m.top,width:m.width1,height:m.height,id:m.id+"l",css:m.css1};
				var o2={element:"div",left:m.x2,top:m.top,width:m.width2,height:m.height,id:m.id+"c",css:m.css2};
				var o3={element:"div",left:m.x3,top:m.top,width:m.width3,height:m.height,id:m.id+"r",css:m.css3};
				
				if(m.bg1			) o1.backgroundImage=m.bg1;
				if(m.leftRepeat		) o1.repeat=m.leftRepeat;
				if(m.bg2			) o2.backgroundImage=m.bg2;
				if(m.centerRepeat	) o2.repeat=m.centerRepeat;
				if(m.bg3			) o3.backgroundImage=m.bg3;
				if(m.rightRepeat	) o3.repeat=m.rightRepeat;

				var o=new Object();
				o.d1 =BS.GENERIC.createElement(o1);
				o.d2 =BS.GENERIC.createElement(o2);
				o.d3 =BS.GENERIC.createElement(o3);
				return o;	
			},
			resizeSlice3:function(m){
				m.x1=m.left;
				m.x2=m.left+m.width1;
				m.x3=m.left+m.width1+m.width2;
				m.width=m.width1+m.width2+m.width3;
				
				var o1={left:m.x1,top:m.top,width:m.width1,height:m.height,id:m.id+"l"};
				var o2={left:m.x2,top:m.top,width:m.width2,height:m.height,id:m.id+"c"};
				var o3={left:m.x3,top:m.top,width:m.width3,height:m.height,id:m.id+"r"};

				BS.GENERIC.moveDiv(o1);
				BS.GENERIC.moveDiv(o2);
				BS.GENERIC.moveDiv(o3);
			},

			moveDiv:function (metrics) {
				var element=window.document.getElementById(metrics.id);	    
				if(!element) {
				    return false;
				}
				
				if(metrics.css   ) element.className=metrics.css;
				
				if(metrics.left  ) metrics.left		=BS.GENERIC.varLimit(metrics.left	,{less:0});
				if(metrics.top	 ) metrics.top 		=BS.GENERIC.varLimit(metrics.top 	,{less:0});
				if(metrics.width ) metrics.width	=BS.GENERIC.varLimit(metrics.width  ,{less:0});
				if(metrics.height) metrics.height	=BS.GENERIC.varLimit(metrics.height ,{less:0});
				
				if(metrics.condition)
					switch(metrics.condition)		{
						case 'ifnotempty': if(element.innerHTML=="") {
				            return false;
				        }
					}
			
				if(metrics.left     || metrics.left     ==0) element.style.left    =metrics.left   +"px"; 
				if(metrics.width    || metrics.width    ==0) element.style.width   =metrics.width  +"px"; 
				if(metrics.top      || metrics.top      ==0) element.style.top     =metrics.top    +"px"; 
				if(metrics.height   || metrics.height   ==0) element.style.height  =metrics.height +"px"; 
				if(metrics.display) element.style.display    =metrics.display;        
					try{
				if(metrics.background     ) element.style.background="url('"+metrics.background+"');";
				} catch(ex) { alert("style.background"); }

				if(metrics.backgroundImage)	 element.style.backgroundImage="url('"+metrics.backgroundImage+"')";//

				if(metrics.bgColor) {
				if(metrics.bgColor=="unset") {    element.style.backgroundColor=null; }
				else {    element.style.backgroundColor=metrics.bgColor;     }    }    
				if(metrics.zIndex    || metrics.zIndex    ==0) element.zIndex=metrics.zIndex; 
				if(metrics.overflowX) element.style.overflowX=metrics.overflowX; 
				if(metrics.overflowY) element.style.overflowY=metrics.overflowY; 
				if(metrics.innerHTML) element.innerHTML=metrics.innerHTML; 
				if(metrics.appendChild) element.appendChild(metrics.appendChild);
				    return true;
		},
		
		stripSlashes:function (str) {
			str=str.replace(/\\'/g,'\'');
			str=str.replace(/\\"/g,'"');
			str=str.replace(/\\\\/g,'\\');
			str=str.replace(/\\0/g,'\0');
			return str;
		},

		StringBuffer:function () { 	this.buffer = []; } ,
		
		deleteElement:function (div_id){
			var target=window.document.getElementById(div_id);
			if(target) target.parentNode.removeChild(target);
		},
		startlog:false,
		logIn:function (name){
			if(_public.startlog){
				var o=new Object();
				var d=new Date();
				o.name=name;
				o.entry=d.getTime();
				o.exit=null;
				log.push(o);
				return o;
			}
		},
		
		logOut:function (o)	{   
			if(_public.startlog){
		        var d=new Date();
		        o.exit=d.getTime();
		        o.elapsed=o.exit-o.entry;
		    } 
		},
		varLimit:function(varible,metrics){
			varible=parseInt(varible);
			if((metrics.less) || (metrics.less==0)) if(varible<metrics.less) varible=metrics.less;
			if((metrics.greater) || (metrics.greater==0)) if(varible>metrics.greater) varible=metrics.greater;
		    return varible;
		},
		humanReadableNumber:function (size) {
			var iec = Array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
			var i=0;
			size=parseInt(size);
			while((size/1024)>=1){
				size=Math.floor(size/1024);
				i++;
			}
			var str=size+iec[i];
			return str;
		},
		createElement:function(metrics)	{
		        var element=document.createElement(metrics.element);

				if(metrics.bgColor) {
		            if(metrics.bgColor=="unset") {    element.style.backgroundColor=null; }
		            else {    element.style.backgroundColor=metrics.bgColor;     }    }    
				
				if(metrics.element=="div") element.style.position='absolute';
				if(metrics.element=="DIV") element.style.position='absolute';
							  
				try{
				if(metrics.background     ) element.style.background="url('"+metrics.background+"');";
				} catch(ex) { alert("style.background"); }

				if(metrics.backgroundImage)	 element.style.backgroundImage="url('"+metrics.backgroundImage+"')";//

				if(metrics.repeat) element.style.backgroundRepeat=metrics.repeat; 
				if(metrics.left     || metrics.left     ==0) element.style.left     =metrics.left   +"px"; 
				if(metrics.width    || metrics.width    ==0) element.style.width    =metrics.width  +"px"; 
				if(metrics.top      || metrics.top      ==0) element.style.top      =metrics.top    +"px"; 

				if(metrics.paddingLeft|| metrics.paddingLeft==0) element.style.paddingLeft=metrics.paddingLeft+"px"; 
				if(metrics.paddingTop || metrics.paddingTop ==0) element.style.paddingTop =metrics.paddingTop+"px"; 
				if(metrics.marginLeft || metrics.marginLeft ==0) element.style.marginLeft =metrics.marginLeft+"px"; 
				if(metrics.marginTop  || metrics.marginTop  ==0) element.style.marginTop  =metrics.marginTop+"px"; 

				if(metrics.height   || metrics.height   ==0) element.style.height   =metrics.height +"px"; 
				if(metrics.zIndex   || metrics.zIndex   ==0) element.style.zIndex   =metrics.zIndex; 
				if(metrics.id       ) element.id                =metrics.id; 
				if(metrics.overflowX) element.style.overflowX   =metrics.overflowX; 
				if(metrics.overflowY) element.style.overflowY   =metrics.overflowY; 
				if(metrics.overflow ) element.style.overflow    =metrics.overflow; 
				if(metrics.innerHTML) element.innerHTML         =metrics.innerHTML; 
				if(metrics.type     ) element.type              =metrics.type; 
				if(metrics.onclick  ) element.onclick           =metrics.onclick; 
				if(metrics._class   ) element.className         =metrics._class; 
				if(metrics.display  ) element.style.display     =metrics.display;        
				if(metrics.checked  ) element.defaultChecked    =metrics.checked;    
				if(metrics.css		) element.className			=metrics.css;
				return element;

		}//end create element
	};//end public object

		_public.StringBuffer.prototype.append 	= function append(string)	{ this.buffer.push(string); return this; }
		_public.StringBuffer.prototype.toString = function toString() 		{ return this.buffer.join(""); }

	return _public;
}();

BS.INPUT=function(){
		var _public={
		shifter:false,
		keyCTRL:false,
		keyDown:function (e){
			var KeyID = (window.event) ? event.keyCode : e.keyCode;
			if(KeyID == 17) keyCTRL= true;
			if(KeyID == 16) shifter = true;
			if((KeyID == 40) && (browser.isIE)) {
				return false;
			}
			BS.GENERIC.logOut(lentry);
		},
		keyUp:function (e){
			var KeyID = (window.event) ? event.keyCode : e.keyCode;
			switch(KeyID){
							case 16: shifter = false; break;
							case 17: keyCTRL = false; break;
							case 38: left(); break;
							case 40: right(); break;
							case 46: _delete(); break;
			}
		},
		getMouseMetrics:function (ev){
		    var posx=0,posy=0,button;
		    if ((!ev))  ev = window.event;
		    if (ev.pageX || ev.pageY) {
		        posx = ev.pageX;
		        posy = ev.pageY;
		    } else   
    			if((ev.clientX) || (ev.clientY))  {
		            posx=ev.clientX;
		            posy=ev.clientY;
		        }
			var _button=null;
            if (ev.button)	{
				_button=parseInt(ev.button);
			} else
			if (ev.which){
				_button=parseInt(ev.which);
			}

		    BS.INPUT.metrics={ x:posx,y:posy,button:_button };
		},
		metrics:{}
	};
	return _public;
}();

try{
document.onmousemove=BS.INPUT.getMouseMetrics;
} catch(ex) { alert("MouseMove: "+ex.toString()); }

BS.button={defualtState:function(){
			var o=new Object;
			o.parentNode		=null;
			o.width				=60;
			o.height			=21;
			o.content			="button";
			o.id				=null;
			o.padding			=5;
			//CSS
			o.icon				=null;
			o.lw				=7;
			o.rw				=7;
			o.color				="orange";
			o.textOut			="orangeButtonText";
			o.buttonOutLeft     ="orangeButtonLeft";
			o.buttonOutCenter   ="orangeButtonCenter";
			o.buttonOutRight    ="orangeButtonRight";
			o.textOver		    ="orangeButtonTextOver";
			o.buttonOverLeft    ="orangeButtonLeftOver";
			o.buttonOverCenter  ="orangeButtonCenterOver";
			o.buttonOverRight   ="orangeButtonRightOver";
			o.textDown			="orangeButtonTextDown";
			o.buttonDownLeft    ="orangeButtonLeftDown";
			o.buttonDownCenter  ="orangeButtonCenterDown";
			o.buttonDownRight   ="orangeButtonRightDown";
			//Callbacks
			o.overCallback      =null;
			o.outCallback       =null;
			o.hoverCallback     =null;
			o.clickCallback     =null;
			o.dblclickCallback  =null;
			return o;
		},			
		create:function(userState){
		var state=BS.button.defualtState();
		//copy user defined vars into state..
		if(userState.color=="silver") {
			state.textOut			="silverButtonText";
			state.buttonOutLeft     ="silverButtonLeft";
			state.buttonOutCenter   ="silverButtonCenter";
			state.buttonOutRight    ="silverButtonRight";
			state.textOver		    ="silverButtonTextOver";
			state.buttonOverLeft    ="silverButtonLeftOver";
			state.buttonOverCenter  ="silverButtonCenterOver";
			state.buttonOverRight   ="silverButtonRightOver";
			state.textDown			="silverButtonTextDown";
			state.buttonDownLeft    ="silverButtonLeftDown";
			state.buttonDownCenter  ="silverButtonCenterDown";
			state.buttonDownRight   ="silverButtonRightDown";
		}
		if(userState.color=="red") {
			state.textOut			="redButtonText";
			state.buttonOutLeft     ="redButtonLeft";
			state.buttonOutCenter   ="redButtonCenter";
			state.buttonOutRight    ="redButtonRight";
			state.textOver		    ="redButtonTextOver";
			state.buttonOverLeft    ="redButtonLeftOver";
			state.buttonOverCenter  ="redButtonCenterOver";
			state.buttonOverRight   ="redButtonRightOver";
			state.textDown			="redButtonTextDown";
			state.buttonDownLeft    ="redButtonLeftDown";
			state.buttonDownCenter  ="redButtonCenterDown";
			state.buttonDownRight   ="redButtonRightDown";
		}
		for(var o in userState){
			state[o]=userState[o];
		}

		if(!state.id) state.id=state.parentNode+"x";

		var m={id:state.id,left:0,top:0,height:state.height,width1:state.lw,width2:state.width,width3:state.rw,
				css1:state.buttonOutLeft,css2:state.buttonOutCenter,css3:state.buttonOutRight};
		var parts=BS.GENERIC.slice3(m);
		//create elements
		
		var c=BS.GENERIC.createElement({element:'div',width:state.width+state.lw+state.rw});
		var d=BS.GENERIC.createElement({element:'div'});

		var table =document.createElement('table');
		var tbody =document.createElement('tbody');
		var tr    =document.createElement('tr');
		var td    =document.createElement('td');

		m.x1=m.left;
		m.x2=m.left+m.width1;
		m.x3=m.left+m.width1+m.width2;
		m.width=m.width1+m.width2+m.width3;

		var o1={element:"div",left:m.x1,top:m.top,width:m.width1,height:m.height,id:m.id+"l",css:m.css1};
		var o2={element:"div",left:m.x2,top:m.top,width:m.width2,height:m.height,id:m.id+"c",css:m.css2};
		var o3={element:"div",left:m.x3,top:m.top,width:m.width3,height:m.height,id:m.id+"r",css:m.css3};

		var o=new Object();
		o.d1 =BS.GENERIC.createElement(o1); 
		o.d2 =BS.GENERIC.createElement(o2);
		o.d3 =BS.GENERIC.createElement(o3);

		c.appendChild(o.d1);
		c.appendChild(o.d2);
		c.appendChild(o.d3);
		
		var d4=BS.GENERIC.createElement({element:'div',id:state.id+"t",left:state.lw,top:0,width:state.width,height:state.height,innerHTML:state.content,css:state.textOut});
		c.appendChild(d4);

		//set callbacks....
//		c.ondblclick =function() { BS.button.changeImage(state,'dblclick'); }
//		c.onclick    =function() { BS.button.changeImage(state,'click'   ); }
//		c.onhover    =function() { BS.button.changeImage(state,'hover'   ); }
		c.onmouseout =function() { BS.button.changeImage(state,'out'     ); }
		c.onmouseover=function() { BS.button.changeImage(state,'over'    ); }
		c.onmousedown=function() { BS.button.changeImage(state,'click'   ); }
		c.onmouseup  =function() { BS.button.changeImage(state,'overClick' ); 	}
		c.style.position="relative";
		//append to body...
/*
		table.style.cursor="default";
		table.cellSpacing="0px";
		table.cellPadding="0px";
		table.style.paddingRight=state.width+state.lw+state.rw+"px";
//		table.style.paddingBottom=state.height+"px";
//		table.width=state.width+state.lw+state.rw+"px";
//		td.appendChild(c);
/		tr.appendChild(td);
		tbody.appendChild(tr);
		table.appendChild(tbody);
*/
var parent=document.getElementById(state.parentNode);
	//	c.style.marginLeft=state.width;
	//	c.style.marginBottom=state.height;
		if(parent) parent.appendChild(c);
		
		
	},
		changeImage:function (state,type){
				var css1,css2,css3,css4;
				switch(type)    {
					case 'dblclick' : css1=state.buttonDownLeft;  css2=state.buttonDownCenter; css3=state.buttonDownRight; css4=state.textDown; break;
					case 'click'    : css1=state.buttonDownLeft;  css2=state.buttonDownCenter; css3=state.buttonDownRight; css4=state.textDown; break;
					case 'hover'    : css1=state.buttonOverLeft;  css2=state.buttonOverCenter; css3=state.buttonOverRight; css4=state.textOver; break;
					case 'over'     : css1=state.buttonOverLeft;  css2=state.buttonOverCenter; css3=state.buttonOverRight; css4=state.textOver; break;
					case 'overClick'     : css1=state.buttonOverLeft;  css2=state.buttonOverCenter; css3=state.buttonOverRight; css4=state.textOver; break;
					case 'out'      : css1=state.buttonOutLeft;   css2=state.buttonOutCenter;  css3=state.buttonOutRight;  css4=state.textOut;  break;
				}

				BS.GENERIC.moveDiv({id:state.id+"l",css:css1});
				BS.GENERIC.moveDiv({id:state.id+"c",css:css2});
				BS.GENERIC.moveDiv({id:state.id+"r",css:css3});
				BS.GENERIC.moveDiv({id:state.id+"t",css:css4});
				//Execute callback.....
				switch(type)    {
					case 'dblclick' : if(state.dblclickCallback)   state.dblclickCallback(state);	break;
				//	case 'click'    : if(state.clickCallback)      state.clickCallback(state);		break;
					case 'hover'    : if(state.hoverCallback)      state.hoverCallback(state);		break;
					case 'overClick': if(state.clickCallback)      state.clickCallback(state);     	break;
					case 'over'     : if(state.overCallback)       state.overCallback(state);     	break;
					case 'out'      : if(state.outCallback)        state.outCallback(state); 		break;
				}//end switch callbacks
		}//end changeImage
	};


BS.Dialog=function ()
{
	var minHeight				=34;
	var minWidth				=131;
	var minPadding				=15;
	var minCount 				=0;
    var dialog_left_limit		=0;
    var dialog_top_limit		=0;
    var dialog_right_limit		=160;
    var dialog_bottom_limit		=40;
    var dialog_control_height	=29;
	var skin="indeed";
	
	
		
	var top_left     		="dialogInactiveTopLeft";
	var top_center   		="dialogInactiveTopCenter";
	var top_right    		="dialogInactiveTopRight";
	var active_top_left     ="dialogActiveTopLeft";
	var active_top_center   ="dialogActiveTopCenter";
	var active_top_right    ="dialogActiveTopRight";
	var center_left  		="dialogCenterLeft";
	var center_body  		="dialogCenterBody";
	var center_right 		="dialogCenterRight";
	var bottom_left  		="dialogBottomLeft";
	var bottom_center		="dialogBottomCenter";
	var bottom_right 		="dialogBottomRight";
	var resize_up    		="dialogResize";
	var close_up	 		="dialogCloseUp";
	var close_down	 		="dialogCloseDown";
	var close_hover	 		="dialogCloseHover";
	var min_up       		="dialogMinUp";
	var min_down	 		="dialogMinDown";
	var min_hover    		="dialogMinHover";
	var max_up       		="dialogMaxUp";
	var max_down     		="dialogMaxDown";
	var max_hover    		="dialogMaxHover";
    
	var _public={
        dragItem:null,
		dragOffsetX:null,
		dragOffsetY:null,
		instance:new Array(),
		close:function(instance){
			//if(BS.Dialog.instance[instance].close_callBack) BS.Dialog.instance[instance].close_callBack(instance);
			BS.GENERIC.deleteElement(instance+'d');
			BS.Dialog.instance.splice(instance,1);
		},
	
		defaultDialog:function(){
			var o=new Object();
			o.id				="default_dialog";
			o.drag				=true;
			o.windowmanager		=true;
			o.type				="";
			o.x					=0;
			o.y					=0;
			o.width				=150;
			o.height			=400;
			o.title				="Title";
			o.content			="";
			o.min				=false;
			o.max				=false;
			o.close				=false;
			o.resize			=false;
			o.shadow			=false;
			o.min_callback		=null;
			o.max_callback		=null;
			o.close_callback	=null;
			o.resize_callback	=null;
			return o;
		},
    	addMinIcon:function(id,title){
            var newdiv = document.createElement('div');
            var row = 0;
            var col = 0;
            var tempID = "min:"+id;
            
            var height = window.innerHeight != undefined ? window.innerHeight : document.body.offsetHeight;
            var width = window.innerWidth != undefined ? window.innerWidth    : document.body.offsetWidth;
            
            col = Math.floor((width-minPadding) /  (minWidth + minPadding));
            row = Math.floor((minPadding+((minCount) * (minWidth + minPadding))) / (col * (minWidth + minPadding)));
            col = minCount% col;
            
            newdiv.setAttribute('id',tempID );
            newdiv.style.width = minWidth+"px";
            newdiv.style.height = minHeight+"px";
            newdiv.style.position = "absolute";
            
            newdiv.style.left = 	minPadding+(col*(minWidth + minPadding))+"px";
            newdiv.style.bottom = 	32+minPadding+(row*(minPadding+minHeight ))+"px";
            
//            newdiv.style.background = "#FFFFFF";
			newdiv.style.background="url('webart/minIcon/minimizebutton.png')'";
            newdiv.onclick = function () {
									minCount--;
                                    var target=document.getElementById(id);
                                    target.style.display="block";
                                    BS.GENERIC.deleteElement(tempID);
                            }
    
            newdiv.innerHTML ="<span class='minIcon'>"+title+"<\/span>";
			newdiv.style.overflow="hidden";
            document.body.appendChild(newdiv);
            minCount++;
        },
		create:function (dialogState){
			//start with an empty state....
			var defaultState=BS.Dialog.defaultDialog();
			//copy user defined vars into state..
			for(var o in dialogState){
				defaultState[o]=dialogState[o];
			
			}
			if(defaultState.width ==null) defaultState.width=250;
			if(defaultState.height==null) defaultState.height=100;
			if(defaultState.x     ==null) { defaultState.x=(BS.UI.metrics.width -defaultState.width)/2;  }
			if(defaultState.y     ==null) { defaultState.y=(BS.UI.metrics.height-defaultState.height)/2; }

			if(window.document.getElementById(defaultState.id+'d')) {
				BS.Dialog.setTop(defaultState.id);
				return false;
			}            

			//save object for later reference
			BS.Dialog.instance[defaultState.id]=defaultState;

			var temp1=BS.GENERIC.getStyle(active_top_left);
			var temp2=BS.GENERIC.getStyle(active_top_center);
			var temp3=BS.GENERIC.getStyle(active_top_right);
			var temp4=BS.GENERIC.getStyle(center_left);
			var temp5=BS.GENERIC.getStyle(center_body);
			var temp6=BS.GENERIC.getStyle(center_right);
			var temp7=BS.GENERIC.getStyle(bottom_left);
			var temp8=BS.GENERIC.getStyle(bottom_center);
			var temp9=BS.GENERIC.getStyle(bottom_right);
			var o=new Object();
			o.x=-1*parseInt(temp1.style.left);
			o.y=-1*parseInt(temp1.style.top);
			o.width=defaultState.width;
			o.height=defaultState.height;
			var tl={	
				element:"div",
				left:o.x+parseInt(temp1.style.left),
				top :o.y+parseInt(temp1.style.top),
				width:parseInt(temp1.style.width),
				height:parseInt(temp1.style.height),
				id:defaultState.id+":tl",
				css:active_top_left
			}
			var tr={	
				element:"div",
				left:o.x+parseInt(o.width)+parseInt(temp3.style.left),
				top :o.y+parseInt(temp3.style.top),
				width:parseInt(temp3.style.width),
				height:parseInt(temp3.style.height),
				id:defaultState.id+":tr",
				css:active_top_right    		
			}
			var tc={	
				element:"div",
				left:tl.left+tl.width,
				top :o.y+parseInt(temp2.style.top),
				width:(tr.left-tl.left)-tl.width,
				height:parseInt(temp2.style.height),
				id:defaultState.id+":tc",
				css:active_top_center
			}
			
			var bl={	
				element:"div",
				left:o.x+parseInt(temp7.style.left),
				top :o.y+o.height+parseInt(temp7.style.top),
				width:parseInt(temp7.style.width),
				height:parseInt(temp7.style.height),
				id:defaultState.id+":bl",
				css:bottom_left
			}
			var br={	
				element:"div",
				left:o.x+o.width+parseInt(temp9.style.left),
				top :o.y+o.height+parseInt(temp9.style.top),
				width:parseInt(temp9.style.width),
				height:parseInt(temp9.style.height),
				id:defaultState.id+":br",
				css:bottom_right
			}
			
			var bc={	
				element:"div",
				left:bl.left+bl.width,
				top :o.y+o.height+parseInt(temp8.style.top),
				width:br.left-bl.left-bl.width,
				height:parseInt(temp8.style.height),
				id:defaultState.id+":bc",
				css:bottom_center
			}
			
			var ml={	
				element:"div",
				left:o.x+parseInt(temp4.style.left),
				top :o.y+parseInt(temp4.style.top),
				width:parseInt(temp4.style.width),
				height:o.height,
				id:defaultState.id+":ml",
				css:center_left
			}
			var mr={	
				element:"div",
				left:o.x+o.width+parseInt(temp6.style.left),
				top :o.y+parseInt(temp6.style.top),
				width:parseInt(temp6.style.width),
				height:o.height,
				id:defaultState.id+":mr",
				css:center_right
			}
			
			var mc={	
				element:"div",
				left:o.x+parseInt(temp5.style.left),
				top :o.y+parseInt(temp5.style.top),
				width:o.width,
				height:o.height,
				id:defaultState.id+":mc",
				css:center_body
			}
			
			var mainDiv={
				element:"div",
				left:defaultState.x,
				top:defaultState.y,
				width:br.left+br.width+1,
				height:br.top+br.height+1,
				id:defaultState.id+"d"
			};
			
			var title={	
				element:"div",
				left:tl.left+tl.width+5,
				top :o.y+parseInt(temp2.style.top)+3,
				width:(tr.left-tl.left)-tl.width-10,
				height:parseInt(temp2.style.height)-6,
				id:defaultState.id+":title",
				innerHTML:defaultState.title,
				css:"dialogTitleActive"
			}
			
			
			var d    =BS.GENERIC.createElement(mainDiv);
			var divTL=BS.GENERIC.createElement(tl);
			var divTC=BS.GENERIC.createElement(tc);
			var divTR=BS.GENERIC.createElement(tr);
			
			var divML=BS.GENERIC.createElement(ml);
			var divMC=BS.GENERIC.createElement(mc);
			var divMR=BS.GENERIC.createElement(mr);
			
			var divBL=BS.GENERIC.createElement(bl);
			var divBC=BS.GENERIC.createElement(bc);
			var divBR=BS.GENERIC.createElement(br);
			var divTitle=BS.GENERIC.createElement(title);
			divTitle.style.overflow="hidden";
			
			
			divMC.innerHTML=dialogState.content;
			divMC.style.overflow="hidden";
			if(defaultState.drag==true) divTitle.onmousedown=function () { BS.Dialog.dragStart(defaultState.id); }
			
			d.appendChild(divTL);
			d.appendChild(divTC);
			d.appendChild(divTR);
			d.appendChild(divTitle);
			
			d.appendChild(divML);
			d.appendChild(divMC);
			d.appendChild(divMR);
			
			d.appendChild(divBL);
			d.appendChild(divBC);
			d.appendChild(divBR);


			if(defaultState.resize) {
				var tempResize=BS.GENERIC.getStyle(resize_up);
				var resize={
					element:"div",
					left:br.left+br.width-parseInt(tempResize.style.width),
					top :br.top+br.height-parseInt(tempResize.style.height),
					width:parseInt(tempResize.style.width),
					height:parseInt(tempResize.style.height),
					id:defaultState.id+":resize",
					css:resize_up
				};
				var dResize=BS.GENERIC.createElement(resize);
				dResize.style.cursor="SE-RESIZE";
				dResize.onmousedown=function (){ BS.Dialog.resizeStart(defaultState.id); }
				d.appendChild(dResize);
			}


			if(defaultState.close) {
				var tempClose=BS.GENERIC.getStyle(close_up);
				var close={
					element:"div",
					left:tc.left+tc.width-parseInt(tempClose.style.width),
					top :tc.top+tc.height/2-parseInt(tempClose.style.height)/2,
					width:parseInt(tempClose.style.width),
					height:parseInt(tempClose.style.height),
					id:defaultState.id+":close",
					css:close_up
				};
				
				var dClose=BS.GENERIC.createElement(close);
				dClose.onmouseover=function () { BS.GENERIC.moveDiv({id:defaultState.id+":close",css:close_hover}); }
				dClose.onmouseout =function () { BS.GENERIC.moveDiv({id:defaultState.id+":close",css:close_up}); }
				dClose.onmousedown=function () { BS.GENERIC.moveDiv({id:defaultState.id+":close",css:close_down}); }
				dClose.onmouseup  =function () { BS.GENERIC.moveDiv({id:defaultState.id+":close",css:close_up}); }
				dClose.onclick    =function () { 
						if(defaultState.close_callback) defaultState.close_callback(defaultState.id); 
						else BS.Dialog.close(defaultState.id);
				}
				d.appendChild(dClose);
			}

		
			if(defaultState.max) {
				var tempMax=BS.GENERIC.getStyle(max_up);
				var left=0;
				if(defaultState.close) left=close.left;
				var max={
					element:"div",
					left:left-parseInt(tempMax.style.width),
					top :tc.top+tc.height/2-parseInt(tempMax.style.height)/2,
					width:parseInt(tempMax.style.width),
					height:parseInt(tempMax.style.height),
					id:defaultState.id+":max",
					css:max_up
				};
				
				var dMax=BS.GENERIC.createElement(max);
				dMax.onmouseover=function () { BS.GENERIC.moveDiv({id:defaultState.id+":max",css:max_hover}); }
				dMax.onmouseout =function () { BS.GENERIC.moveDiv({id:defaultState.id+":max",css:max_up}); }
				dMax.onmousedown=function () { BS.GENERIC.moveDiv({id:defaultState.id+":max",css:max_down}); }
				dMax.onmouseup  =function () { BS.GENERIC.moveDiv({id:defaultState.id+":max",css:max_up}); }
				dMax.onclick    =function () { 
						if(defaultState.max_callback) defaultState.max_callback(); 
				}
				d.appendChild(dMax);
			}

			if(defaultState.min) {
				var tempMin=BS.GENERIC.getStyle(min_up);
				var left=0;
				if(defaultState.close) left=close.left;
				if(defaultState.max)   left=max.left;
				var min={
					element:"div",
					left:left-parseInt(tempMin.style.width),
					top :tc.top+tc.height/2-parseInt(tempMin.style.height)/2,
					width:parseInt(tempMin.style.width),
					height:parseInt(tempMin.style.height),
					id:defaultState.id+":min",
					css:min_up
				};
				
				var dMin=BS.GENERIC.createElement(min);
				dMin.onmouseover=function () { BS.GENERIC.moveDiv({id:defaultState.id+":min",css:min_hover}); }
				dMin.onmouseout =function () { BS.GENERIC.moveDiv({id:defaultState.id+":min",css:min_up}); }
				dMin.onmousedown=function () { BS.GENERIC.moveDiv({id:defaultState.id+":min",css:min_down}); }
				dMin.onmouseup  =function () { BS.GENERIC.moveDiv({id:defaultState.id+":min",css:min_up}); }
				dMin.onclick    =function () { 
						d.style.display="none";  
						BS.Dialog.addMinIcon(defaultState.id+"d",defaultState.title);  
						if(defaultState.min_callback) defaultState.min_callback(); 
				}
				d.appendChild(dMin);
			}

			document.body.appendChild(d); //add to window
			if(defaultState.resize_callback) defaultState.resize_callback(defaultState.id);
			BS.Dialog.setTop(defaultState.id);
			return true;
		},

		dragStart:function(item){
			BS.Dialog.dragItem=item+"d";
			var element=window.document.getElementById(item+"d");
            if(element)    {
				BS.Dialog.setTop(item);
				var div_x=0;
				var div_y=0;
				if(element.style.left) div_x=parseInt(element.style.left);
				if(element.style.top)  div_y=parseInt(element.style.top);
				
                BS.Dialog.dragOffsetX=div_x - BS.INPUT.metrics.x;
				BS.Dialog.dragOffsetY=div_y - BS.INPUT.metrics.y;
                      
				if(document.addEventListener) {
                    document.addEventListener("mousemove", BS.Dialog.drag,false);
                    document.addEventListener("mouseup"  , BS.Dialog.dragStop,false);
				}else{
					document.attachEvent("onmousemove", BS.Dialog.drag);
                    document.attachEvent("onmouseup"  , BS.Dialog.dragStop);
                }
			}
		},

		drag:function (){
            if(BS.Dialog.dragItem) {
                var element=window.document.getElementById(BS.Dialog.dragItem);
                if(element) {

                    var x    =BS.INPUT.metrics.x+BS.Dialog.dragOffsetX;
                    var x_max=BS.UI.metrics.width-parseInt(element.style.width);
                    
                    var y    =BS.INPUT.metrics.y+BS.Dialog.dragOffsetY;
                    var y_max=BS.UI.metrics.height-parseInt(element.style.height);
                    if(x>x_max) x=x_max;
                    if(y>y_max) y=y_max;
                    if(x<0) x=0;
                    if(y<0) y=0;
                    try {
                        element.style.left=x+"px";
                        element.style.top =y+"px";
                    } catch(ex) { BS.Debug("Drag_Dialog Error ",ex); }
                }
            }
        },

        dragStop:function (){
           try   {
                if(document.removeEventListener)        {
					document.removeEventListener("mousemove",BS.Dialog.drag,false);
                    document.removeEventListener("mouseup"  ,BS.Dialog.dragStop,false);
                }else{
                    document.detachEvent("onmousemove",BS.Dialog.drag);
                    document.detachEvent("onmouseup"  ,BS.Dialog.dragStop);
                }
                BS.Dialog.dragItem=null;
           }catch(ex){ BS.Debug("dragstop",ex);  }
        },
         
        resizeStart:function (item){
            this.dialog_resize_item=item;
            var element=window.document.getElementById(item+"d");
            if(element)    {
				this.setTop(item);
                this.dialog_resize_x=BS.INPUT.metrics.x;
                this.dialog_resize_y=BS.INPUT.metrics.y;

                this.dialog_resize_width =parseInt(element.style.width);
                this.dialog_resize_height=parseInt(element.style.height);
                      
                if(document.addEventListener){
                    document.addEventListener("mousemove", BS.Dialog.resize,false);
                    document.addEventListener("mouseup"  , BS.Dialog.resizeStop,false);
                }else{
                    document.attachEvent("onmousemove", BS.Dialog.resize);
                    document.attachEvent("onmouseup"  , BS.Dialog.resizeStop);
                }
            }
        },

        resize:function(event) {
            if(BS.Dialog.dialog_resize_item)
            {
                var x    =BS.INPUT.metrics.x-BS.Dialog.dialog_resize_x;
                var y    =BS.INPUT.metrics.y-BS.Dialog.dialog_resize_y;
                
                var width =BS.Dialog.dialog_resize_width+x-4;
                var height=BS.Dialog.dialog_resize_height+y-29-4;
				if(height<29) height=29;
                if(width<150 ) width=150;
                BS.Dialog.resizeDialog(BS.Dialog.dialog_resize_item,width,height);
				if(BS.Dialog.instance[BS.Dialog.dialog_resize_item].resize_callback) 
					BS.Dialog.instance[BS.Dialog.dialog_resize_item].resize_callback(BS.Dialog.dialog_resize_item);
            }
        },

        resizeStop:function(){
           try   {
                if(document.removeEventListener)        {
                    document.removeEventListener("mousemove",BS.Dialog.resize,false);
                    document.removeEventListener("mouseup"  ,BS.Dialog.resizeStop,false);
                }else{
					document.detachEvent("onmousemove",BS.Dialog.resize);
                    document.detachEvent("onmouseup"  ,BS.Dialog.resizeStop);
                }
           } catch(ex) { BS.Debug("resize.stop",ex);  }
        },

		resizeDialog:function(id,w,h){
            var element=window.document.getElementById(id+'d');
            if(!element) return;

            var defaultState=BS.Dialog.instance[id];
			defaultState.x=element.style.left;
			defaultState.y=element.style.top;
			defaultState.width=w;
			defaultState.height=h;
	
			var temp1=BS.GENERIC.getStyle(active_top_left);
			var temp2=BS.GENERIC.getStyle(active_top_center);
			var temp3=BS.GENERIC.getStyle(active_top_right);
			var temp4=BS.GENERIC.getStyle(center_left);
			var temp5=BS.GENERIC.getStyle(center_body);
			var temp6=BS.GENERIC.getStyle(center_right);
			var temp7=BS.GENERIC.getStyle(bottom_left);
			var temp8=BS.GENERIC.getStyle(bottom_center);
			var temp9=BS.GENERIC.getStyle(bottom_right);
			var o=new Object();
			o.x=-1*parseInt(temp1.style.left);
			o.y=-1*parseInt(temp1.style.top);
			o.width=defaultState.width;
			o.height=defaultState.height;
			var tl={	
				element:"div",
				left:o.x+parseInt(temp1.style.left),
				top :o.y+parseInt(temp1.style.top),
				width:parseInt(temp1.style.width),
				height:parseInt(temp1.style.height),
				id:defaultState.id+":tl",
				css:active_top_left
			}
			var tr={	
				element:"div",
				left:o.x+parseInt(o.width)+parseInt(temp3.style.left),
				top :o.y+parseInt(temp3.style.top),
				width:parseInt(temp3.style.width),
				height:parseInt(temp3.style.height),
				id:defaultState.id+":tr",
				css:active_top_right    		
			}
			var tc={	
				element:"div",
				left:tl.left+tl.width,
				top :o.y+parseInt(temp2.style.top),
				width:(tr.left-tl.left)-tl.width,
				height:parseInt(temp2.style.height),
				id:defaultState.id+":tc",
				css:active_top_center
			}
			
			var bl={	
				element:"div",
				left:o.x+parseInt(temp7.style.left),
				top :o.y+o.height+parseInt(temp7.style.top),
				width:parseInt(temp7.style.width),
				height:parseInt(temp7.style.height),
				id:defaultState.id+":bl",
				css:bottom_left
			}
			var br={	
				element:"div",
				left:o.x+o.width+parseInt(temp9.style.left),
				top :o.y+o.height+parseInt(temp9.style.top),
				width:parseInt(temp9.style.width),
				height:parseInt(temp9.style.height),
				id:defaultState.id+":br",
				css:bottom_right
			}
			
			var bc={	
				element:"div",
				left:bl.left+bl.width,
				top :o.y+o.height+parseInt(temp8.style.top),
				width:br.left-bl.left-bl.width,
				height:parseInt(temp8.style.height),
				id:defaultState.id+":bc",
				css:bottom_center
			}
			
			var ml={	
				element:"div",
				left:o.x+parseInt(temp4.style.left),
				top :o.y+parseInt(temp4.style.top),
				width:parseInt(temp4.style.width),
				height:o.height,
				id:defaultState.id+":ml",
				css:center_left
			}
			var mr={	
				element:"div",
				left:o.x+o.width+parseInt(temp6.style.left),
				top :o.y+parseInt(temp6.style.top),
				width:parseInt(temp6.style.width),
				height:o.height,
				id:defaultState.id+":mr",
				css:center_right
			}
			
			var mc={	
				element:"div",
				left:o.x+parseInt(temp5.style.left),
				top :o.y+parseInt(temp5.style.top),
				width:o.width,
				height:o.height,
				id:defaultState.id+":mc",
				css:center_body
			}
			
			var mainDiv={
				element:"div",
				left:defaultState.x,
				top:defaultState.y,
				width:br.left+br.width+1,
				height:br.top+br.height+1,
				id:defaultState.id+"d"
			};
			
			var title={	
				element:"div",
				left:tl.left+tl.width+5,
				top :o.y+parseInt(temp2.style.top)+3,
				width:(tr.left-tl.left)-tl.width-10,
				height:parseInt(temp2.style.height)-6,
				id:defaultState.id+":title",
				innerHTML:defaultState.title,
				css:"dialogTitleActive"
			}
			
			
			BS.GENERIC.moveDiv(mainDiv);
			BS.GENERIC.moveDiv(tl);
			BS.GENERIC.moveDiv(tc);
			BS.GENERIC.moveDiv(tr);
			
			BS.GENERIC.moveDiv(ml);
			BS.GENERIC.moveDiv(mc);
			BS.GENERIC.moveDiv(mr);
			
			BS.GENERIC.moveDiv(bl);
			BS.GENERIC.moveDiv(bc);
			BS.GENERIC.moveDiv(br);
			BS.GENERIC.moveDiv(title);
			
			if(defaultState.resize) {
				var tempResize=BS.GENERIC.getStyle(resize_up);
				var resize={
					element:"div",
					left:br.left+br.width-parseInt(tempResize.style.width),
					top :br.top+br.height-parseInt(tempResize.style.height),
					width:parseInt(tempResize.style.width),
					height:parseInt(tempResize.style.height),
					id:defaultState.id+":resize",
					css:resize_up
				};
				BS.GENERIC.moveDiv(resize);
			}

			if(defaultState.close) {
				var tempClose=BS.GENERIC.getStyle(close_up);
				var close={
					element:"div",
					left:tc.left+tc.width-parseInt(tempClose.style.width),
					top :tc.top+tc.height/2-parseInt(tempClose.style.height)/2,
					width:parseInt(tempClose.style.width),
					height:parseInt(tempClose.style.height),
					id:defaultState.id+":close",
					css:close_up
				};
				BS.GENERIC.moveDiv(close);
			}

			if(defaultState.max) {
				var tempMax=BS.GENERIC.getStyle(max_up);
				var left=0;
				if(defaultState.close) left=close.left;
				var max={
					element:"div",
					left:left-parseInt(tempMax.style.width),
					top :tc.top+tc.height/2-parseInt(tempMax.style.height)/2,
					width:parseInt(tempMax.style.width),
					height:parseInt(tempMax.style.height),
					id:defaultState.id+":max",
					css:max_up
				};
				BS.GENERIC.moveDiv(max);
			}

			if(defaultState.min) {
				var tempMin=BS.GENERIC.getStyle(min_up);
				var left=0;
				if(defaultState.close) left=close.left;
				if(defaultState.max)   left=max.left;
				var min={
					element:"div",
					left:left-parseInt(tempMin.style.width),
					top :tc.top+tc.height/2-parseInt(tempMin.style.height)/2,
					width:parseInt(tempMin.style.width),
					height:parseInt(tempMin.style.height),
					id:defaultState.id+":min",
					css:min_up
				};
				BS.GENERIC.moveDiv(min);
			}
        },

        InnerMETRICS:function(id)
        {
            var target=window.document.getElementById(id+"body");
            if(!target) return null;
            if(!target.style) return null;
            var w=parseInt(target.style.width);
			var h=parseInt(target.style.height);
           return { width:w,height:h };
		},

        content:function(id, content) {
            var target=window.document.getElementById(id+":mc");
            if(!target) return null;
            target.innerHTML=content;
        },

		exists:function(instance){
		    var target=window.document.getElementById(instance+"d");
            if(!target) return false;
			return true;
		},

        setTop:function(instance) {
            var target;
			var id;
            for(var i in BS.Dialog.instance)  {
				id=BS.Dialog.instance[i].id;
				target=window.document.getElementById(id+"d");
				if(target) {
					if(target.style.zIndex!="0") {
						target.style.zIndex="0";
						BS.GENERIC.moveDiv({id:id+":title",css:'dialogTitleInactive'});
						BS.GENERIC.moveDiv({id:id+":tl",css:top_left});
						BS.GENERIC.moveDiv({id:id+":tc",css:top_center});
						BS.GENERIC.moveDiv({id:id+":tr",css:top_right});
					}
				}
			}

			target=window.document.getElementById(instance+"d");
			if(target) {
				if(target.style.zIndex!="1") {
					target.style.zIndex="1";
					BS.GENERIC.moveDiv({id:instance+":title",css:'dialogTitleActive'});
					BS.GENERIC.moveDiv({id:instance+":tl",css:active_top_left});
					BS.GENERIC.moveDiv({id:instance+":tc",css:active_top_center});
					BS.GENERIC.moveDiv({id:instance+":tr",css:active_top_right});
				}
			}
		},

		appendChild:function(instance,element) {
			var target=window.document.getElementById(instance+"cb");
			target.appendChild(element);
		},
		alert:function(state) {
			state.content=state.content+"<div align='right' style='margin-right:10px;' id='alertok'></div>",
			state.title="<div align='left'>"+state.title+"<\/div>"
			BS.Dialog.create(state);
			BS.button.create({parentNode:'alertok',width:40,content:"<div align='center'>ok<\/div>",clickCallback:state.clickCallback,color:"silver"});
		},
		confirm:function(title,content,metrics,yescallback,nocallback){
			var x=0,y=0,w=250,h=50;

			if(metrics) {
				x=metrics.left;
				y=metrics.top;
				w=metrics.width;
				h=metrics.height;
			}

			 var content ="<div class=\"dialog_alert\" align=\"center\">"+content+"</div>";
			 content+="<br/><div align='right'><table><tr>";
			 content+="<td><div id='d_a_y'></div></td>";
			 content+="<td><div id='d_a_n'></div></td>";
			 content+="</tr></table></div>";
			 
			 if(BS.Dialog.create(title,x,y,w,h,title,content,null,null,null,null,true,null,null,null,
			 null,null)) {
            BS.UTILS.button._new('d_a_y','x_d_a_y',"Ok",'std_button',50,25,BS.UTILS.button.type["standard_over"],null,
                   BS.UTILS.button.type["standard_out"],null,null,null,BS.UTILS.button.type["standard_hit"],
                   function() { if(yescallback) {  if(yescallback()) BS.Dialog.close(title); } else  Dialog_Close(title); },
                        null,null,null);
            BS.UTILS.button._new('d_a_n','x_d_a_n',"Cancel",'std_button',50,25,BS.UTILS.button.type["standard_over"],null,
                   BS.UTILS.button.type["standard_out"],null,null,null,BS.UTILS.button.type["standard_hit"],
                   function() { if(nocallback) {if(nocallback()) BS.Dialog.close(title); } else  BS.Dialog.close(title);  },
                   null,null,null);
            }
        }
    }//public
    return _public;
}();

BS.UTILS=function(){
	var _public={
		browserMetrics:function () {
			    var lentry=BS.GENERIC.logIn("Window_Size");
			    var myWidth=0;
			    var myHeight=0;
			    if( typeof( window.innerWidth ) == 'number' )  {
			        myWidth  = window.innerWidth;
			        myHeight = window.innerHeight;
			    }   else 
			    if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			        myWidth  = document.documentElement.clientWidth;
			        myHeight = document.documentElement.clientHeight;
			    }   else 
			    if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			        myWidth  = document.body.clientWidth;
			        myHeight = document.body.clientHeight;
			    }
			    
			    
			    BS.UI.metrics= {
			        width:myWidth, 
			        height:myHeight 
			    }
			    BS.GENERIC.logOut(lentry);
			}
	};
	return _public;
}();


var rsa=function(){
    try{
    var key="C05F1CA645B1ABFDC30A012355149854AF1C5BC055AEDE1990FDFDA2CD\
		    462DB35A901EDC24031BA1AC379A99D04A05CDE0F37E4ECA50B81137FAC\
		    94C9037353A1836AAF14804A7727A274AC204E2625FE33BA49292AF8717\
		    90B43AEB427AB131A1E7626DA3B97BFCF85EA498395B0299C34DEAF44CD\
		    BAEDABEAAAF7E512A4601";
	var secret= new RSAKey();
	secret.setPublic(key,"10001");
		
	_public={
		encrypt:function(text){
			rng_seed_time();
			var data		=new Array();
			var encrypted	=new Array();
			var len=text.length;
			var stride=50,a,start,end,subString;
			var rows=Math.floor(len/stride),temp;
			if(rows*stride<len) rows++;
			for(a=0;a<rows;a++) {
				start=a*stride;
				end=stride+start;
				if(end>len) { end=len; }
				subString=text.substring(start,end);
				data.push(subString);
			}
			for(a=0;a<data.length;a++) {
				var res = secret.encrypt(data[a]);
				if(res) { 
					temp=linebrk(hex2b64(res),64);
				}
				encrypted.push(temp);
			}
			return encrypted.join();
		}
	};//end public;
	return _public;
    } catch(e) {}
}();

function accountObject (){
    var o=new Object();
    var dSeed= new Date();
    var randNumber=Math.random()*dSeed.getTime();
	var uid=Math.floor(randNumber);
    o.uid		="uid"+uid;
	o.user		=null;
	o.pass		=null;
	o.port		="-1";
	o.service	=null;
	o.status	="unknown";
	o.mode		="start";
	o.data		=new Array();
	o.customData="";
	o.command	=new Array();
	o.buddyList =new Object();
	return o;
}

function serialize (txt) {
	var type=typeof(txt);
	
	switch(type){
	case 'string' : return 's:'+txt.length+':"'+txt+'";';
	case 'number' : if(txt>=0 && String(txt).indexOf('.') == -1 && txt < 65536) return 'i:'+txt+';';	return 'd:'+txt+';';
	case 'boolean': return 'b:'+( (txt)?'1':'0' )+';';
	case 'array':   return "a"; break;
	case 'object':
		var i=0,k,ret='';
		for(k in txt){
			//alert(isNaN(k));
			if(!isNaN(k)) k = Number(k);
			ret += serialize(k)+serialize(txt[k]);
			i++;
		}
		return 'a:'+i+':{'+ret+'}';
	default:
		return 'N;';
		alert('var undefined: '+typeof(txt));return undefined;
	}
}

function unserialize(txt){
	var level=0,arrlen=new Array(),del=0,final=new Array(),key=new Array(),save=txt;
	while(1){
		switch(txt.substr(0,1)){
		case 'N':
			del = 2;
			ret = null;
		break;
		case 'b':
			del = txt.indexOf(';')+1;
			ret = (txt.substring(2,del-1) == '1')?true:false;
		break;
		case 'i':
			del = txt.indexOf(';')+1;
			ret = Number(txt.substring(2,del-1));
		break;
		case 'd':
			del = txt.indexOf(';')+1;
			ret = Number(txt.substring(2,del-1));
		break;
		case 's':
			del = txt.substr(2,txt.substr(2).indexOf(':'));
			ret = txt.substr( 1+txt.indexOf('"'),del);
			del = txt.indexOf('"')+ 1 + ret.length + 2;
		break;
		case 'a':
			del = txt.indexOf(':{')+2;
			ret = new Array();
			arrlen[level+1] = Number(txt.substring(txt.indexOf(':')+1, del-2))*2;
		break;
		case 'O':
			txt = txt.substr(2);
			var tmp = txt.indexOf(':"')+2;
			var nlen = Number(txt.substring(0, txt.indexOf(':')));
			name = txt.substring(tmp, tmp+nlen );
			//alert(name);
			txt = txt.substring(tmp+nlen+2);
			del = txt.indexOf(':{')+2;
			ret = new Object();
			arrlen[level+1] = Number(txt.substring(0, del-2))*2;

		break;
		case '}':
			txt = txt.substr(1);
			if(arrlen[level] != 0){alert('var missed : '+save); return undefined;};
			//alert(arrlen[level]);
			level--;
		continue;
		default:
			if(level==0) return final;
			alert('syntax invalid(1) : '+save+"\nat\n"+txt+"level is at "+level);
			return undefined;
		}
		if(arrlen[level]%2 == 0){
			if(typeof(ret) == 'object'){alert('array index object no accepted : '+save);return undefined;}
			if(ret == undefined){alert('syntax invalid(2) : '+save);return undefined;}
			key[level] = ret;
		} else {
			var ev = '';
			for(var i=1;i<=level;i++){
				if(typeof(key[i]) == 'number'){
					ev += '['+key[i]+']';
				}else{
					ev += '["'+key[i]+'"]';
				}
			}
			eval('final'+ev+'= ret;');
		}
		arrlen[level]--;//alert(arrlen[level]-1);
		if(typeof(ret) == 'object') level++;
		txt = txt.substr(del);
		continue;
	}
}

function decrypt(data){
	//return data;
	var output=Base64.decode(data);	
	return output;
}

function encrypt(data){
//	return data;
	var output=Base64.encode(data);	
	return output;
}
