var debugging=false;

function event_obj(e){
	if (!e.target){
		return e.srcElement;
	}
	else {
		return e.target;
	}
}

function pop_up(url){
		var	win_options = "resizable=yes,toolbar=no,menubar=no,width=200,height=200,personalbar=no,scrollbars=no,resizable=yes";
		var win = window.open(url,'pop_up',win_options);
}

function debug(text){
    if (debugging){
        window.alert(text);
    }
}

function show_hide(id){
    obj = get_obj(id);
    if (obj){
        if (obj.style.display == 'none'){
            obj.style.display = 'block';
            obj.focus();
        }
        else {
            obj.style.display = 'none';
        }
    }
}

function show_help_text(obj,sText){
    if ((typeof(obj)!='object')){
        obj = get_obj(obj);
    }
	if (get_obj('help_text')){
		//find the caller
		var newX = objX(obj) + obj.offsetWidth + 3;
		var newY = objY(obj);
		
		if (newY > 0){
    		//position the help text
    		var obj_help = get_obj('help_text');
				obj_help.style.position = 'absolute';
    		obj_help.style.left = newX +'px';
    		obj_help.style.top = newY +'px';
    		//obj_help.style.zindex = 6;
    		obj_help.innerHTML = sText;
    		
    		obj_help.style.display = 'block';
		}
	}
}

function hide_help_text(){
    if (get_obj('help_text')){
        get_obj('help_text').style.display = 'none';
    }
}

function get_obj(id){
	if (document.getElementById){
		if (document.getElementById(id)){
			return document.getElementById(id);
		}
		else {
            debug('JS Error : id not found(' + id +').');
    		return false;
        }
	}
	else {
		return false;
	}
}

function objX(obj){
	if (obj.offsetParent==null){
		return obj.offsetLeft;
	}
	else{
		return obj.offsetLeft + objX(obj.offsetParent);
	}
}

function objY(obj){
	if (obj.offsetParent==null){
		return obj.offsetTop;
	}
	else{
		return obj.offsetTop + objY(obj.offsetParent);
	}
}

function win_resize(width,height){
	var left = 0;
	var top = 0;

	//center in the parent window or screen
	if (window.opener){
			left = opener.screenX + ((opener.outerWidth - width) / 2);
			top = opener.screenY + ((opener.outerHeight - height) / 2);
	}
	else {
		left = (screen.availWidth - width)/2;
		top = (screen.availHeight - height)/2;
	}
	//resize the window
	//it's a modal window (IE)
	if (window.dialogWidth){
		window.dialogWidth = width + 'px;';
		window.dialogHeight = height + 'px;';
	}
	//Normal window
	else {
		window.resizeTo(width,height);
		window.moveTo(left,top);
	}
}

