//Fetch an object instance by id
function $E(id){
	if(typeof(id)=='object'){
		return id;
	}else{
		return document.getElementById(id);
	}
}


//
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;
   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');
	}
}
