// JScript source code
//Browser check

function browser(){
	this.ver=navigator.appVersion; 
	this.agent=navigator.userAgent
	this.dom=document.getElementById?1:0
	this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
	this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom)?1:0;
	this.ie4=(document.all && !this.dom)?1:0; 
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("Mac")>-1; 
	this.opera=this.agent.indexOf("Opera")>-1
	this.opera5=this.agent.indexOf("Opera 5")>-1; 
	this.ns = ((this.agent.indexOf('mozilla')!=-1) && ((this.agent.indexOf('spoofer')==-1) && (this.agent.indexOf('compatible') == -1)));
	this.ns2 = (this.ns && (this.ver == 2));
        this.ns3 = (this.ns && (this.ver== 3));
        this.ns4 = (this.ns && (this.ver == 4));
        this.ns5 = (this.ns && (this.ver > 4));
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
	this.ns4=(document.layers && !this.dom)?1:0;
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera4)
	return this
}
var is=new browser();

function myobj()
{
	this.frmObj = getObj('Hfrm');
}

function getObj(obj) {
	if (document.getElementById)
	{
		obj1 = document.getElementById(obj);
	}
	else if (document.all)
	{
		obj1 = document.all[obj];
	}
	else if (document.layers)
	{
		obj1 = document.anchors[obj];
	}
	return obj1;
}

function findXY(obj)
{
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while ((obj = obj.offsetParent) != null)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop
		}

	}
	else {
		if (obj.x)
			curleft += obj.x;
		if (obj.y)
			curtop += obj.y;
	}
	return [curleft, curtop]
}



//Menu related script
function MenuTimeout(curObj,myParent) {
	if (typeof(curObj) != 'object')
	{
		curObj = getObj(curObj);
	}
	else { curObj = curObj}
	
//	if (typeof(myParent) != 'object')
//	{
//		myParent = getObj(myParent);
//	}
//	else { myParent = myParent}
	
	window.setTimeout("hideMenu1('" + curObj.id + "','" + myParent + "');",500);
//	alert(curObj.id)
//	if (curObj.style.display !='block')
	if (typeof(activeMenu) != 'object')
	{
		activeMenu = getObj(activeMenu);
	}
	else { activeMenu = activeMenu}

//alert(menuOn + " as " + activeMenu.id + " dfd " + curObj.id)
//	if (menuOn && activeMenu.id == curObj.id)
//	{
//		var aa = new myobj();
//		aa.frmObj.style.visibility = 'hidden'
//	}
	menuOn=false;
}

function hideMenu1(obj,myParent)
{
	if (typeof(obj) != 'object')
	{
		obj = getObj(obj);
	}
	else { obj = obj}
	
	if (typeof(activeMenu) != 'object')
	{
		activeMenu = getObj(activeMenu);
	}
	else { activeMenu = activeMenu}
	
	if (menuOn && activeMenu.id == obj.id)
	{return }
	if (!(menuOn) && activeMenu.id == obj.id)
	{
		var aa = new myobj();
		aa.frmObj.style.visibility = 'hidden'
	}
	
	obj.style.display = 'none'
	
	if (typeof(myParent) != 'object')
	{
		myParent = getObj(myParent);
	}
	else { myParent = myParent};
	/*if (myParent.id == "root5")
	{
		myParent.firstChild.className = "right"
	}
	else
	{
		myParent.firstChild.className = "left"
	}*/
	//alert("here " + obj.style.display)
}
function setMenuProperty(menuObj,myParent)
{
	menuOn = true
	activeMenu = menuObj
	activeMenuParent = myParent
}

function hideMenu(obj)
{  
	if (typeof(obj) != 'object')
	{
		obj = getObj(obj);
	}
	else { obj = obj}
	if (menuOn && activeMenu.id == obj.id)
	{return }
	
	obj.style.display = 'none'
}

function showMenu(el,m) 
{
	menuOn = true
	prevMenu = activeMenu
	activeMenu = m
	if (prevMenu)
		hideMenu(prevMenu)

	if (typeof(m) != 'object')
	{
		obj = getObj(m);
	}
	else { obj = m}
	m = obj

	if (typeof(el) != 'object')
	{
		obj = getObj(el);
	}
	else { obj = el}
	el = obj
	
	var aa = new myobj();

	if (m) {
		m.style.display='block';
		//aa.frmObj.style.visibility = 'visible';
		//Hfrm.style.display = 'block';
		m.style.zIndex = "999999";
		if ((is.mac) && (is.ie))
		{
			m.style.left = findXY(el)[0] + 10; 
			m.style.top = parseInt(findXY(el)[1]) + el.offsetHeight + 8;
			aa.frmObj.style.left = findXY(el)[0] + 10;
			aa.frmObj.style.top = parseInt(findXY(el)[1]) + el.offsetHeight + 8;
			
		}
		else
		{
			m.style.left = findXY(el)[0];
			m.style.top = parseInt(findXY(el)[1]) + el.offsetHeight;
			if (!is.mac)
			{
				aa.frmObj.style.left = findXY(el)[0];
				aa.frmObj.style.top = parseInt(findXY(el)[1]) + el.offsetHeight;
				aa.frmObj.style.visibility = 'visible';	 
			}
		}

	}
//for (i in m.firstChild) alert(i)
//alert(m.firstChild.offsetHeight + " width " + m.firstChild.offsetWidth)
aa.frmObj.style.height=m.firstChild.offsetHeight;
aa.frmObj.style.width=m.firstChild.offsetWidth;//alert(aa.frmObj.style.height + " AS " + aa.frmObj.style.width + " asd sd " + aa.frmObj.innerText)
//aa.frmObj.innerHTML = m.innerHTML;
//m.style.display='none'
}

//Left Nav
function openSubNav(total, current) { 
     var i = 0 
     for(i=1;i<total+1;i++) { 
		var sel = document.getElementById('subNav'+i); 
		if (i != current) {
			sel.style.display = 'none';
			if ((arguments.length==3) || (arguments[2]==true))  
				document.getElementById('imgsubNav' + i).src = "";
		}
     } 
     var sel = document.getElementById('subNav'+current); 
     if (sel.style.display == 'block'){
		sel.style.display = 'none';
		if ((arguments.length==3) || (arguments[2]==true))  
			document.getElementById('imgsubNav' + current).src = "";
	 }
	 else {
		sel.style.display = 'block';
		if ((arguments.length==3) || (arguments[2]==true))  
			document.getElementById('imgsubNav' + current).src = "";
	 }
  } 
  function openChild(total,childNavName, current) { 
     var i = 0 
     var sel = document.getElementById(childNavName + current);
     if (sel.style.display == 'block')
     {
		sel.style.display = 'none';
		document.getElementById('img' + childNavName + current).src = ""
	  }
	  else
	  {
		sel.style.display = 'block';
		document.getElementById('img' + childNavName + current).src = ""
	}
  } 
  
//Menu

function submenu(menuObj, subMenuObj)
{
	if (typeof(subMenuObj) != 'object')
	{
		subMenuObj = getObj(subMenuObj);
	}
	else { subMenuObj = subMenuObj}
	
	prevMenuObj = curMenu
	curMenu = menuObj;
	if ((arguments.length==3) || (arguments[2]==true)) {
		btnMenu = subMenuObj;
		curMenu.className = "menubutton";
	}
	else
	{
		//curMenu.firstChild.className = "current"
	}
	if ((prevMenuObj) && (prevMenuObj != curMenu))
		if ((arguments.length==3) || (arguments[2]==true)) {
			prevMenuObj.className = "menubutton"
		}
		else
		{
			if (btnMenu)
			{
				btnMenu = null
				prevMenuObj.className = "menubutton"
			}
			else
				prevMenuObj.className = ""
		}
	if ((arguments.length==3) || (arguments[2]==true))
	{
		if (subMenuObj.style.display.match("none") ) {
			showMenu(menuObj,subMenuObj);
		}
		else {
			subMenuObj.style.display = "none"
		}
	}
	else
		showMenu(menuObj,subMenuObj.id);
}
//Selection box
function copyOptions(from,to) {
	var options = new Object();
	if (hasOptions(to)) {
		for (var i=0; i<to.options.length; i++) {
			options[to.options[i].value] = to.options[i].text;
			}
		}
	if (!hasOptions(from)) { return; }
	for (var i=0; i<from.options.length; i++) {
		var o = from.options[i];
		if (o.selected) {
			if (options[o.value] == null || options[o.value] == "undefined" || options[o.value]!=o.text) {
				if (!hasOptions(to)) { var index = 0; } else { var index=to.options.length; }
				to.options[index] = new Option( o.text, o.value, false, false);
				}
			}
		}
	if ((arguments.length<3) || (arguments[2]==true)) {
		sortSelect(to);
		}
	from.selectedIndex = -1;
	to.selectedIndex = -1;
	}
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}

//move Up
function moveUp(obj) 
{
	for (i=0; i<obj.options.length; i++) {
		if (obj.options[i].selected) {
			if (i != 0 && !obj.options[i-1].selected) {
				swapOptions(obj,i,i-1);
				obj.options[i-1].selected = true;
				top = i - 1
				totSel = totSel + 1
			}
		}
	}
}

// Move Down
var top
var down
var totSel
function moveDown(obj) 
{
	for (i=obj.options.length-1; i>=0; i--) {
		if (obj.options[i].selected) {
			if (i != (obj.options.length-1) && ! obj.options[i+1].selected) {
				swapOptions(obj,i,i+1);
				obj.options[i+1].selected = true;
				down = i + 1
				totSel = totSel + 1
			}
		}
	}
}

//Move Top
function moveTop(obj)
{
	totSel = 0
	top = null
	moveUp(obj)
	while ( (totSel <= top) && top != null)
	{
		totSel = 0
		moveUp (obj)
	}
}

//Move Bottom

function moveBottom(obj)
{
	totSel = 0
	down = null
	moveDown(obj)
	while ((obj.options.length - 1) >= (down + totSel) && down != null)
	{
		totSel = 0
		moveDown(obj)
	}
	
}

// Swap

function swapOptions(obj,i,j) 
{
	var o = obj.options;
	var i_selected = o[i].selected;
	var j_selected = o[j].selected;
	var temp = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	var temp2= new Option(o[j].text, o[j].value, o[j].defaultSelected, o[j].selected);
	o[i] = temp2;
	o[j] = temp;
	o[i].selected = j_selected;
	o[j].selected = i_selected;
}
	
//Remove Options
function removeOptions(from) 
{ 
	for (var i=(from.options.length-1); i>=0; i--) { 
		var o=from.options[i]; 
		if (o.selected) { 
			from.options[i] = null; 
		} 
	} 
	from.selectedIndex = -1; 
}

// Sort options

function sortSelect(obj) 
{
	var o = new Array();
	if (obj.options==null) { return; }
	for (var i=0; i<obj.options.length; i++) {
		o[o.length] = new Option( obj.options[i].text, obj.options[i].value, obj.options[i].defaultSelected, obj.options[i].selected) ;
	}
	if (o.length==0) { return; }
	o = o.sort( 
		function(a,b) { 
			if ((a.text+"") < (b.text+"")) { return -1; }
			if ((a.text+"") > (b.text+"")) { return 1; }
			return 0;
		} 
	);

	for (var i=0; i<o.length; i++) {
		obj.options[i] = new Option(o[i].text, o[i].value, o[i].defaultSelected, o[i].selected);
	}
}
