function restrict(jsObj,regex){
  jsObj.keypress(function(e){
    return e.which == 8 || regex.test(String.fromCharCode(e.which)+jsObj.val());
  });
}

function SetOffset(off,lim){
  window.location.href = URLPREFIX+"/"+off+"/"+lim;
}

function SetOrder(order,off){
  URLPREFIX = URLPREFIX.replace(/(.*)\/(cim|datum)/,"$1/"+order);
  SetOffset(0,off);
}

function isValidEmail(email,required){
  required = required || true;
  email = email || '';
  return /^[a-z0-9._-]+@([a-z0-9-]{2,})([.][a-z0-9-]{2,})*[.][a-z]{2,6}$/.exec(email);
}
 

function repairBaseBug(){
  $('a').each(function(){
    var $this = $(this);
    var href = $this.attr("href");
    if(href.substr(0,1) == "#")
      if(href.substr(1,1) != "")
        $this.attr("href",window.location+href);
      else $this.attr("href","javascript:;");
  });
}

function printPage(){
	return popup(LANG_URL+'/Print','print',740,400,"scrollbars=yes,resizable=yes");
}

function sendPage(){
	return popup(LANG_URL+'/Send','send',600,400,"scrollbars=no,resizable=no");

}

function sendPrint(){
  $("#print-content").html(window.opener.print_content);
  $(".title-actions, a.details, div.pages-text, table.pager").css("display","none");
  $("div.text-content").css("display","block");
  $("a").click(function(){return false});
  $("div.navbar a").append("&nbsp;>&nbsp;");
  $("div.list-item").css("background-image","none");
  window.print();
}

function popup(mylink,windowname,width,height,otherparam){
    if (! window.focus)return false;
    if(width == undefined) width = 690;
    if(height == undefined) height = 550;;
    if(otherparam == undefined) otherparam = "scrollbars=yes";
    var href;
    if (typeof(mylink) == 'string')
       href=mylink;
    else
       href=mylink.href;
    if(windowname == undefined) windowname = href;
    window.open(href, windowname, 'width='+width+',height='+height+','+otherparam);
    return false;
}

function gotoPage(ix){
  var $contents = $("div.text-content");
  $contents.css("display","none");
  $contents.eq(ix).css("display","block");
  $("div.inner-content div.pages-text").each(function(){
    var $objs = $("a.normal",this);
    $objs.removeClass("selected");
    $objs.eq(ix).addClass("selected");
  });
  var $objs = $("div.inner-content div.pages-text a.text");
  $objs.removeClass("selectedtext");
  $objs.eq(ix).addClass("selectedtext");
  return false;
}
