function getById(id){
	return document.getElementById(id);
}

/*networking info*/
var file_name = '../location.php';
var tmp_text = 'loading';
function changeSubField(id_field){
	
	role_obj = getById('role');
	role_obj.innerHTML = '';
	
	str = 'sel=get_netw_fields&par=id_sub_field&id_spr='+id_field;
	destination_obj = getById('sub_field');
	anisochronous = true;
	ajaxRequest(file_name, str, destination_obj, tmp_text, anisochronous);
}
function changeRole(id_sub_field){
	str = 'sel=get_netw_fields&par=id_role&id_spr='+id_sub_field;
	destination_odj = getById('role');
	anisochronous = true;
	ajaxRequest(file_name, str, destination_odj, tmp_text, anisochronous);
}

function showNotice(msg){
	if (!msg) return;
	$("<div id='temp'>"+msg+"</div>").appendTo("body").addClass("notice_div").fadeIn("slow").fadeTo(2000,1).fadeOut("slow");
}

function ajaxLoadingImage(status, id_container){
	if (status) {
            //var id_height = $("#"+id_container).height();
            var width = $("#"+id_container).width();
            var height = $("#"+id_container).height();
            var left_pos = $("#"+id_container).position().left;	   			
            var top_pos = $("#"+id_container).position().top;

            var left_img = left_pos + width/2 - 8;
	        var top_img = top_pos + height/2 -8;	
            
            $("body").append('<div id="update_div"></div>');
            $("#update_div").css({'z-index':'9995','position':'absolute','left':left_pos,'top':top_pos,'width':width,'height':height,'border':'0px solid #cccccc'});
            $("#update_div").css("background-image", "url('"+TEMPLATE_PATH+"/images/bg_opacity.png')");
            $("#update_div").css('opacity','0.1');
            $("body").append('<img id="update_img"  src="'+TEMPLATE_PATH+'/images/ajax-loader.gif" style="position:absolute;z-index:9996; left: '+left_img+'px;top: '+top_img+'px;" alt="" border="0">');
            //alert(1);
		//$("#"+id_container).append('<div style="position:relative;left:50%; top:-'+(id_height/2)+';"><img id="img_loading" src="'+TEMPLATE_PATH+'/images/ajax-loader.gif" alt="" border="0"><\/div>');
                //$("#"+id_container).css('opacity','0.8');
        } else {
            $("#update_div").remove();
            $("#update_img").remove();
		//$("#"+id_container).html('');
              //  $("#"+id_container).css('opacity','1');
        }
}

function getJQData(data){
	if (!data){
		ShowAjaxError('system error!!!', '', 'error');
		return false;
	}
	var resp;
	resp = eval('('+data+')');
	
	if (!resp){
		ShowAjaxError('system error!!!', '', 'error');
		return false;
	}
	return resp;
}

function getRandColor(){
	min=0;
	max=16777215;
	random_int = getRandom(min,max);
	rand_color_hex = d2h(random_int);
	return rand_color_hex;
}

function getRandom(min,max){
	rand = Math.floor(min+(max-min)*Math.random());
	return rand;
}

function d2h(d) {
	return d.toString(16);
}
function h2d(h) {
	return parseInt(h,16);
}
function showNoticeOnEl(msg,jq_obj_el){
	if (!msg) return;
	var offset = jq_obj_el.offset();
	var x = offset.left;
	var y = offset.top;
	var rand = Math.random()*10;
	var rand_str = rand.toString();
	rand = rand_str.replace(".","");
	$("<div id='temp"+rand+"'>"+msg+"</div>").appendTo("body").addClass("notice_div1_on_el").fadeIn("slow").fadeTo(2000,1).fadeOut("slow",function(){
		$(this).remove();
	});
	$("#temp"+rand).click(function(){
		$(this).remove();
	});
	$("#temp"+rand).css("top",(y+15)+"px");
	$("#temp"+rand).css("left",(x+5)+"px");
}
function setSetting(name, value, jq_ident_for_mess){
	jq_obj = $(jq_ident_for_mess);
	str = "ajax=1&sel=set_setting&name="+name+"&val="+value;
	$.post("../backend.php", str, function(data){
		resp = getJQData(data);
		if (resp["code"] == '1'){
			ShowAjaxError(resp["msg"], '', 'success')
		}
	});
}

function ajaxIndicator(status, id_container){
    //<img id="update_img"  src="'+TEMPLATE_PATH+'/images/ajax-loader.gif">;
    if (status) {
        $('#'+id_container).show();
        $('#'+id_container).html('<img id="update_img" height="20" src="'+TEMPLATE_PATH+'/images/indicator.gif" >');
    } else {
        $('#'+id_container).html('');
    }
}