//Fetch an object instance by id

function $E(id){
	if(typeof(id)=='object'){
		return id;
	}else{
		return document.getElementById(id);
	}
}

 function AddFavorite(sURL, sTitle)
            {
                try
                {
                    window.external.addFavorite(sURL, sTitle);
                }
                catch (e)
                {
                    try
                    {
                        window.sidebar.addPanel(sTitle, sURL, "");
                    }
                    catch (e)
                    {
                        alert("sorry");
                    }
                }
            }
            
function SetHome(obj,vrl)
            {
                try
                {
                        obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
                }
                catch(e){
                        if(window.netscape) {
                                try {
                                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
                                } 
                                catch (e) { 
                                        alert("sorry'"); 
                                }
                                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                                prefs.setCharPref('browser.startup.homepage',vrl);
                         }
                }
            }
            
            
function openmenu(li_id) {
	var li2 = $E(li_id);
	li2.className = "open";
	var m = $E("menulist");
	m.style.display = "";
}
function closemenu(li_id) {
	var li2 = $E(li_id);
	li2.className = "";
	var m = $E("menulist");
	m.style.display = "none";
}



function show(_id) {
	
	$E("li1").className = "";
	$E("li2").className = "";
	$E("li3").className = "";
	$E("li4").className = "";
	$E("li5").className = "";
	$E("li6").className = "";
	$E("li7").className = "";
	$E("li8").className = "";
	_id = _id == "" ? "li1" : _id;
	$E(_id).className = "selected";
}
            
//
function setProperty(id,val,pro){
	var obj=$E(id);
	if(obj){
		pro=(pro?pro:'value');
		try{
			obj.setAttribute(pro,val);
		}catch(e){
			return false;
		}
	}else{
		return false;
	}
}

//Get customer explorer type
function agentType(){
	var domType='';
	if (document.all) {
		domType = "ie";
	} else if (document.getElementById) {
		domType = "std";
	} else if (document.layers) {
		domType = "ns";
	}
	return domType;
}

//Get current cursor position;
function getCursorPos(){
	var xp=0;
	var yp=0;
	var agt=agentType();

	var e=getEvent();
	if (agt=='ie'){
		xp=document.body.scrollLeft+e.clientX;
		yp=document.body.scrollTop+e.clientY;
	}else{
		xp=e.pageX;
		yp=e.pageY;
	}	
	return {x:xp,y:yp}
}

//Add body.onload event
function addBodyOnloadEvent(func){
	if(typeof(func)!='function'){
		return false;
	}
	
	var atp=agentType();
	var oldf=null;
	if(atp=='ie'){
		document.onreadystatechange=function(){
			if(document.readyState=='complete'){
				if(document.body.onload){
					oldf=document.body.onload;
					document.body.onload=function(){
						oldf();
						func();
					}
				}else{
					document.body.onload=func;
				}
			}
		}
	}else{
		var t=setInterval(function(){if(document.body){clearInterval(t);if(document.body.onload){var oldf=document.body.onload;document.body.onload=function(){oldf();func();}}else{document.body.onload=func();}}else{document.write('');}},100);
	}	
}


//Fetch event object
function getEvent() 
{   
	if(document.all)   return window.event;
	func=getEvent.caller;
	while(func!=null){
		var arg0=func.arguments[0];
		if(arg0){ 
		  if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)){   
			return arg0;
		  }
		}
		func=func.caller; 
	}
	return null; 
} 

function getAbsPoint(obj)   
{   
   var  xPos,yPos;   
   oRect =obj.getBoundingClientRect();
   xPos=oRect.left;
   yPos=oRect.top;
   alert("("+xPos+","+yPos+")");
   return {x:xPos,y:yPos};
} 
function getAbsPoint1(e){
    var xPos=e.offsetLeft,yPos=e.offsetTop;
    while(e=e.offsetParent){
	   xPos+=e.offsetLeft;   
       yPos+=e.offsetTop;
    }
    //alert("x:"+xPos+","+"y:"+yPos); 
	return {x:xPos,y:yPos};
} 

function selectCap(ids,func,capidArray,varName){		
	if(typeof(func)=='function'){
		func();
	}else if(typeof(func)=='string'){
		try{eval(func)}catch(e){}
	}
	
	if(!varName) varName='selected';

	if(!eval('window.'+varName)){
		if(!capidArray){
			var capid=new Array('cap_1','cap_2','cap_3','cap_4');
		}else{
			var capid=capidArray;
		}
		for(var i=0;i<4;i++){
			var o=$E(capid[i]);
			if(o){
				if(o.id==ids){
					o.className='selected';
					eval('window.'+varName+'=ids');
				}else{
					o.className='';
				}
			}
		}
	}else{
		var o=$E(ids);

		if(eval('window.'+varName)!=o.id){
			$E(eval('window.'+varName)).className='';
		}
		o.className='selected';
		eval('window.'+varName+'=ids');
	}
}


