function intval(val){if(val==null)return 0;var r=/^(0*)([0-9]*)?.*$/gi;var tmp=val.replace(r,"$2");return(tmp=="")?0:parseInt(tmp);}
function openCentered(tUrl,tName,tFeatures,w,h){tFeatures="width="+w+",height="+h+","+tFeatures;if(screen.height&&screen.width){h=parseInt((screen.height-h)/2);if(h<0)h=0;w=parseInt((screen.width-w)/2);if(w<0)w=0;tFeatures="left="+w+",top="+h+","+"screenX="+w+",screenY="+h+","+tFeatures;}var o=window.open(tUrl,tName,tFeatures);o.focus();}
function NewWin(url_element,win_name,win_width,win_height){openCentered(url_element.href,win_name,'resizable=1,status=0,toolbar=0,menubar=0,scrollbars=1',win_width,win_height);return(false);}
function SwitchBlock(id){type=(arguments[1]=="show"||arguments[1]=="hide")?arguments[1]:'auto';if(document.getElementById(id))document.getElementById(id).style.display=((type=='auto'&&document.getElementById(id).style.display=='none')||type=='show')?'':'none';}
function elPos(el){var posx=el.offsetLeft;var posy=el.offsetTop;while(el.offsetParent!=null&&el.style.position!='absolute'){el=el.offsetParent;posx+=el.offsetLeft;posy+=el.offsetTop;}if(el.style.position=='absolute'){posx-=el.offsetLeft;posy-=el.offsetTop;}this.x=posx;this.y=posy;return this;}
function showLyr(which){document.getElementById(which).style.visibility="visible";}
function hideLyr(which){document.getElementById(which).style.visibility="hidden";}
function setLyrPos(which,x,y){document.getElementById(which).style.left=x+'px';document.getElementById(which).style.top=y+'px';}
function esc(s){return escape(s).replace(new RegExp('\\+','g'),'%2B');}
function gel(id){return document.getElementById(id);}
function advPos() {var pl = document.getElementById('advPlace'); var tx = document.getElementById('advText'); if (pl && tx) {var pos = elPos(pl); setLyrPos('advText', pos.x, pos.y);}}
function pause(ms){	var date = new Date();var curDate = null;do { curDate = new Date(); } while(curDate-date < ms); }
function myNewWin(url_element,win_name,win_width,win_height){openCentered(url_element,win_name,'resizable=1,status=0,toolbar=0,menubar=0,scrollbars=1',win_width,win_height);return(false);}
function parse_uri(uri){ parts = uri.split('|'); var ret = []; for (i=0; i<parts.length; i=i+2) { ret[parts[i]] = parts[i+1];} return ret;}

var system_class = 'sys_msg';

function clearSystemMsg() {
    $('.' + system_class).remove();
}

function showSystemMsg(isOk, str) {

    clearSystemMsg();

    var system_msg = $('<div ></div>');
    $(system_msg).addClass(system_class);
    
    
    if (isOk) {
        $(system_msg).addClass('sys_ok')
    } else {
        $(system_msg).addClass('sys_err')
    }
    
    $(function(){
        $($(system_msg).text(str)).click(function(){
        	$(this).remove()
        }).appendTo('body');
        setTimeout('clearSystemMsg()', 5000);
    })
    
}


//Preload progress bar
var img = new Image;
img.src = '/i/admin/ajax-loader.gif';

//Ajax request
$.sendAjaxRequest = function(url, data, type, obj, where_show_progressbar, callback) {
  $.post(url, data, function(ht){
      if (type == 'html') {
        $(obj).html(ht);
      }
      if (callback) callback();  
  }, type);
}

var ajaxTimeout = 500,
	ajaxtimer=[],
	ix;


function close_cover(){
	for(var i in ajaxtimer){
		clearTimeout(ajaxtimer[i])
	}
	
	$('.cover, .fon').remove();
	$('iframe .cover, iframe .fon').remove();
}

//Progress bar
$.showProgressBar = function(){
    var win_w = $(window).width(),
        win_h = $(window).height(),
        sc_top = $(window).scrollTop(),
        sc_left = $(window).scrollLeft(),
        doc_w =$(document).width(),
        doc_h =$(document).height();

    var cover = img;
    $(cover).appendTo('body').show().addClass('cover');
    $('<div class="fon"></div>').css({
        opacity:0.1,
        background:'#000',
        position:'absolute',
        width:doc_w,
        height:doc_h,
        top:0,
        left:0,
        'z-index':10002,
        'cursor': 'wait'
    }).prependTo('body');

    var w = $(cover).width(),
        h = $(cover).height();
    $(cover).css({
        top:parseInt(win_h/2-h/2) + sc_top,
        left:parseInt(win_w/2-w/2) + sc_left
    })
}	