String.prototype.stripHTML = function(){
	var strip = new RegExp();
	strip = /[<][^>]*[>]/gi;
	return this.replace(strip, "").replace(/&nbsp;/g, "")
}



function _contextmenu(win){
	this.parent = win	
	this.menu_array = []	
	this.current = false
	this.popup = win.createPopup();
	this.document = this.popup.document
	this.document.onselectstart = 
	this.document.onselect = 
	function(){ return false }
	this.window = this.popup.document.parentWindow
	try{
		this.style = this.document.createStyleSheet()
		this.style.cssText = this.parent.document.styleSheets[0].cssText
	}catch(e){}

	this.getTop = function(o){
		while(!o._contextmenu)
			o = o.parent
		return o
	}

	this.add = function(name,javascript,icon,sectionend,el){
		 
		var l = this.menu_array.length
		this.menu_array[l] = [name,javascript,icon,sectionend,el]
		var p = this.getTop(this)
		this.menu_array[l].submenu =  new p._contextmenu( this.popup.document.parentWindow )
		return this.menu_array[l].submenu
	}

	this._add = function(name,javascript,icon,sectionend,el,_ref){
		var new_row = this.table.insertRow(this.table.rows.length)
		var new_cell = new_row.insertCell()
		new_cell.innerHTML = ' &nbsp;&nbsp;' + name
		new_cell._ref = _ref
		new_cell.el = el
		new_cell.win = this
		new_cell.style.cursor = 'hand'
		new_cell.javascript = javascript
		new_cell.className = 'contextmenu_item'
		new_cell.onclick = function(){
			if(this.javascript){
				//alert("window."+ this.javascript + "; ")
				eval("window."+ this.javascript + "; ")
				var p = this.win.getTop(this.win)
				p.contextmenu.hide();

			}
		}
		new_cell.onmouseover = function(){
			this.className='contextmenu_item_mouseover'
				if(	this._ref.submenu.menu_array.length > 0 )
					this._ref.submenu.show(null,null,this)
				else this._ref.submenu.show(0,0,this,true)
		}
		new_cell.onmouseout = function(){
			this.className='contextmenu_item'
		}
		new_cell.oncontextmenu = function(){
			return false
		}
		if(sectionend){
			new_row = this.table.insertRow(this.table.rows.length)
			new_cell = new_row.insertCell()
			new_cell.innerHTML = '<HR>' 
		}
		return new_cell
	}
	this.hide = function(){
		if(this.popup){
			this.popup.hide()
		}
	}
	this.show = function(left,top,object,cancel){
		for(var i =0 ; i <this.menu_array.length;i++ )
			this.menu_array[i].submenu.hide()
		if(this.popup){
		if(!cancel){
			this.document.body.innerHTML = '<DIV class="contextmenu" style="width:150;"><TABLE ID="CTMENU" width="100%" cellspacing=0></TABLE></DIV>'
			this.table = this.document.getElementById('CTMENU')
			for(var i =0 ; i < this.menu_array.length;i++){
				var c = this.menu_array[i]
				this._add(c[0],c[1],c[2],c[3],c[4],c)
			//	status = (this.parent.screenLeft + 145)
			}
			this.popup.show(left || 140 ,top||3, 0, 0, object);
			this.popup.show(left || 140 ,top||3, 150, this.table.scrollHeight+4, object);
		}else this.popup.show(0,0,0,0, object);
		}
	}

	this.clear = function(){
		this.menu_array = [] 
	}
}
var contextmenu = new _contextmenu(window)

function makeTitleBars(win){
	var table = win.document.getElementsByTagName('TABLE')
	for(var i=0;i<table.length;i++){
		var e1 = table[i]	
		if(e1.className == 'titlebar'){	
			e1.onselectstart = function(){ return false }
			e1.ondrag = function(){ return false }
			e1.oncontextmenu = function(){ return false }
			e1.width  = '100%'
			e1.border = 0
		}
	}
}


function makeMenuBars(win){
	var table = win.document.getElementsByTagName('TABLE')
	for(var i=0;i<table.length;i++){
		var e1 = table[i]	
		if(e1.className == 'menubar'){	
			e1.onselectstart = function(){ 
				if(window.event.srcElement.tagName == 'INPUT')
				return true
								return false }
			e1.ondrag = function(){ return false }
			e1.oncontextmenu = function(){ return false }

			e1.cellspacing = 0
			e1.cellpadding = 0
			e1.border = 0
			// Insert menu start image
			var cell = e1.rows[0].insertCell(0)
			cell.innerHTML ='<img src="/sitetechnology2/images/bar_start.gif">'
		}
	}
}

function makeFlatButtons(win){
	var td = win.document.getElementsByTagName("TD")
	for(var i=0;i<td.length;i++){
		var e1 = td[i]

		if(e1.className == 'flatbutton'){
			e1.enabled_status = true
			e1.disable = function(){ 
				if(this.enabled_status){
					if (this.nobr.style.width == '')
						this.nobr.style.width = (parseInt(this.scrollWidth) ) 
					this.nobr.style.filter= "gray() dropShadow(color=white, offx=1, offy=1)" 

						this._onmouseover = this.onmouseup
						this._onmouseout = this.onmouseout
						this._onmousedown = this.onmousedown
						this._onmouseup = this.onmouseup
						this._onclick = this.onclick

					this.onclick = this.onmousedown = this.onmouseout = 
					this.onmouseup = this.onmouseover = null
					this.enabled_status = false
				}
					
			}
			e1.enable = function(){ 
				if(!this.enabled_status){
					this.nobr.style.filter= "" 
					this.onclick = this._onclick
					this.onmouseover = this.onmouseup = this._onmouseup
					this.onmouseout = this._onmouseout
					this.onmousedown = this._onmousedown
					this.enabled_status = true
				}
			}
			e1.onmouseover = e1.onmouseup = function(){ this.className = 'flatbutton_mouseover' }
			e1.onmouseout = function(){ this.className = 'flatbutton' }
			e1.onmousedown = function(){ this.className = 'flatbutton_mousedown' }

			e1.onselectstart = function(e){ 
	
				return false
			}
			e1.oncontextmenu = function(){ return false }
			e1.ondrag = function(){ return false }
			e1.innerHTML = '<nobr>' + e1.innerHTML + '</nobr>'
			e1.nobr = e1.getElementsByTagName('NOBR')[0]
		}
	}
}

function makeFlatButtons2(win){
	var td = win.document.getElementsByTagName("TD")
	for(var i=0;i<td.length;i++){
		var e1 = td[i]
		if(e1.className == 'flatbutton2'){
			
			e1.onmouseover = e1.onmouseup = function(){ this.className = 'flatbutton2_mouseover' }
			e1.onmouseout = function(){ this.className = 'flatbutton2' }
			e1.onmousedown = function(){ this.className = 'flatbutton2_mousedown' }

			e1.onselectstart = function(){ return false }
			e1.oncontextmenu = function(){ return false }
			e1.ondrag = function(){ return false }
			e1.innerHTML = '<nobr>' + e1.innerHTML + '</nobr>'
		}
	}
}

function makeListSelectable(){
	var tr = document.getElementsByTagName('TR')
	for(var i=0;i<tr.length;i++)
		if(tr[i].className == 'list'){
			tr[i].onmouseover= function(){
				this.className = 'list_highlight'
			}
			tr[i].onmouseout= function(){
				this.className = 'list'
			}
		}
}

function initXstreamOS(){
	try{ makeMenuBars(window)		}catch(e){}
	 makeFlatButtons(window)
	try{ makeFlatButtons2(window)	}catch(e){}
	try{ makeTitleBars(window)		}catch(e){}
	try{ makeListSelectable(window) }catch(e){}
}


window.onload = function(){
	try{ initXstreamOS() }catch(e){}
}


function selectBox(parent, width){
	function option(text,value){
		this.text = text
		this.value = value || text
	}
	this.width = width || 50
	this.options = []
	this.value = ''
	this.selectedIndex = 0
	this.repopulate = true

	this.setValue = function(value){
		for(var i=0;i<this.options.length;i++)
			if(this.options[i].value+'' == value+''){
				this._value.innerHTML = this.options[i].text
				this.value = value
				this.selectedIndex = i
				return true
			}
		this._value.innerHTML = this.value =''
		this.selectedIndex = -1
	}
	this.getValue = function(){
		return this.value
	}
	this.getSelectedOption = function(){
		return this.options[this.selectedIndex]
	}
	this.clear = function(){
		this.options = []
		this.value = ''
		this.selectedIndex = 0
		this.repopulate = true
	}

	this.add = function(text,value){
		this.options[this.options.length] = new option(text,value)
		this.repopulate = true
	}

	this.border = document.createElement('DIV')
	this.border.className = 'select_box'
	this.border.style.position = 'relative'
	this.border.style.overflow = 'hidden'
	this.border.style.width = this.width
	
	this.container = document.createElement('DIV')
	this.container.style.position = 'relative'
	this.container.style.width = '100%'
	this.border.appendChild(this.container)

	this._value = document.createElement('DIV')
	this.container.appendChild(this._value)
	this._value.style.position = 'absolute'
	this._value.style.top = 2
	//this._value.innerHTML = 'value here'
	this._value.style.left = 0
	this._value.style.border = 'none'
	this._value.style.width = '100%'
	this._value.style.textAlign  = 'left'
	this._value.parent = this
	this._value.onmousedown = function(){
		this.parent.showPopUp()
	}

	this.drop_arrow = document.createElement('DIV')
	this.container.appendChild(this.drop_arrow)
	this.drop_arrow.className = 'drop_arrow'
	this.drop_arrow.style.position = 'absolute'
	this.drop_arrow.style.top = 0
	this.drop_arrow.style.width = 12
	this.drop_arrow.style.textAlign = 'center'
	if(this.drop_arrow.style.cursor)
	this.drop_arrow.style.cursor = 'normal'

	this.drop_arrow.innerHTML = '6'
	this.drop_arrow.style.fontFamily = 'webdings'
	this.drop_arrow.style.fontSize = '8px'
	this.drop_arrow.style.right = 0

	this.drop_arrow.parent = this
	this.drop_arrow.onmousedown = function(){
		this.parent.showPopUp()
	}
	

	this.popup = window.createPopup();
	this.document = this.popup.document

	var style = this.document.createStyleSheet()
	style.cssText = document.styleSheets[0].cssText


	this.document.body.style.margin = '0'
	this.select_container = this.document.createElement('DIV')
	this.select_container.style.height='100%'
	this.select_container.style.width='100%'
	this.select_container.className = 'select_dropdown' 
	this.select_container.style.overflow = 'auto'
	this.select_container.style.overflowX = 'hidden'
	this.document.body.appendChild(this.select_container)
	this.document.onselectstart =
	this.document.onselect = 
	this.document.oncontextmenu =
	function(){ return false }

	//this.document.body.innerHTML='testing 123'
	this.document.body.style.backgroundColor = 'white'
	if(this.document.body.style.cursor)
	this.document.body.style.cursor = 'normal'

	parent.appendChild(this.border)
	
	this.showPopUp = function(){
		if(this.repopulate = true){
			this.repopulateSelect()
		}
		this.popup.show(0 ,this.border.scrollHeight-1,this.border.scrollWidth, 100, this.border);
	}
	this.onclick = function(){}
	this.onchange = function(){}

	this.repopulateSelect = function(){
		this.select_container.innerHTML = ''
		for(var i = 0; i< this.options.length ; i++){
			var el = this.document.createElement('DIV')
			el.innerHTML = this.options[i].text
			el.value = this.options[i].value
			el.index = i
			el.className = 'select_value'
			el.style.width = '100%'
			try{ el.style.cursor = 'normal' } catch(e){}
			el.parent = this
			el.popup = this.popup
			el.onmouseup = function(){
				this.parent._value.innerHTML = this.innerHTML
				var value = this.parent.value
				this.parent.value = this.value
				this.parent.selectedIndex = this.index
				this.popup.hide()
				if(value != this.value)
					this.parent.onchange()
				this.parent.onclick()

			}
			el.onmouseover = function(){
				this.className = 'select_value_onmouseover'
			}
			el.onmouseout = function(){
				this.className = 'select_value'
			}
			this.select_container.appendChild(el)
		}
		this.repopulate = false
	}
}
/*
window.onerror = function(e){
	alert('Xstream client side error : ' + e +'\n\nURL : '+ window.location)
	return true
}
*/
