
var telExp =  new RegExp("[0-9/\+]{3,}", "i");
var linkExp = new RegExp("http:|ftp:|news:[a-z0-9.]+", "ig");
var linkExpAdmin = new RegExp("http:|ftp:|news:[a-z0-9.]+|/", "ig"); 


var browserName = window.navigator.appName;
var browserVersion = window.navigator.appVersion;
var enableEvent = (browserName=='Netscape')?0:((parseInt(browserVersion.substring(0,1))<4)?0:1);

var maxLen = 300;
var oldMessage = ''; 
var InAction = 0;

function textarea_onkeydown(paObject){	
  if(paObject.value.length + InAction < maxLen ){
	oldMessage = paObject.value;
	if(enableEvent==1){
	  InAction = ((window.event.keyCode>15) && (window.event.keyCode<19))?0:1;
	  window.event.cancelBubble = true;
	} 
	else 
	  ++InAction;
  } 
  else{
	if(enableEvent==1){
	  if(window.event.keyCode >=65 ){
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	  }
	} 
	else 
	  return false;
  }
}
		
function textarea_onkeyup(paObject){
  var newMessage = paObject.value;
		  
  if(newMessage.length > maxLen ){
	paObject.value = oldMessage;
	if(enableEvent==1){
	  window.event.returnValue = false;
	  window.event.cancelBubble = true;
	}
  }  
  InAction = 0;
}


function isInteger( val ) {
   if(isNaN(parseInt(val))){
	 return false;
   }	 
   return true;	 
}

function isValidEmail(email){
   return email.match(/^[a-z0-9-_\.+]+\@([a-z0-9-]+\.)+[a-z]{2,6}$/gi);
}	

function isValidPasswd(paPasswd) {
  return new RegExp("^([a-z0-9]{6,})$", "i").test(paPasswd);
}


function isValidLink(link){
   return link.match(/^http:\/\/|ftp:\/\/|news:\/\/[a-z0-9.]+$/gi);
}	

function isJpeg(paFileName){

 if(paFileName.substring(paFileName.lastIndexOf(".")+1,paFileName.length).toLowerCase()=="jpg" 
    || paFileName.substring(paFileName.lastIndexOf(".")+1,paFileName.length).toLowerCase()=="jpeg")
   return true;
 else
   return false;
}

function windowOpen(url,name,features,replace){
   var win=window.open(url,name,features,replace);
   win.focus();
}

function URLOpen(url){
  var win=window.open(url);
  win.focus();
}     

function protectEmail(email) {
  var s=new String(email);
  s=s.replace('@','(&#64;)');
  while(s.indexOf('.')!=-1)
    s=s.replace('.','(&#46;)');
  return s;
}

function unprotectEmail(email) {
  var s=new String(email);
  s=s.replace('(@)','@');
  while(s.indexOf('(.)')!=-1)
    s=s.replace('(.)','.');
  return s;


  var s=new String(email);
  s=s.replace('(&#64;)','@');
  while(s.indexOf('(&#46;)')!=-1)
    s=s.replace('(&#46;)','.');
  return s;
}

function mailTo(to,subject){
  window.location = "mailto:"+unprotectEmail(to)+'\n?subject='+escape(subject);
}
 
function in_array(needle, haystack) {
  for(var i=0;i<haystack.length;i++)
    if(needle==haystack[i])  return true;
  return false;	
}

function adacontact() {
    win=window.open('http://www.skrz.sk/adastranet.php', 'adastranet', 'toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, copyhistory=0, width=300, height=200');
    win.focus();
}

function setActiveStyleSheet(title) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("title")) {
       a.disabled = true;
       if(a.getAttribute("title") == title) a.disabled = false;
     }
   }
}

function printPage() {
  window.print();
}

function sendPageUrl(){
  window.location = 'mailto:\n?body='+escape(window.location);
}

function getCookie(n) {
  var s = document.cookie;
  if(!s.length)
    return null;

  var beg = s.indexOf(n+"=");
  if(beg == -1)
    return null;

  beg += n.length + 1;
  var end = s.indexOf(";", beg);
  if(end == -1)
    end = s.length;
  return unescape(s.substring(beg, end));
}

function setCookie(name, value, expires, path, domain, secure) {
  var s = "";
  if(expires) s += "; expires=" + expires;
  if(path   ) s += "; path="    + path;
  if(domain ) s += "; domain="  + domain;
  if(secure ) s += "; secure="  + secure;
  //TODO:EASY: escape() is obsolete, which new version belongs here?
  document.cookie = name + "=" + escape(value) + s;
}

function delCookie(name) {
  setCookie(name, "", -1);
}

/* -------------------------------------------- */
/* -- Browser information --------------------- */
/* -------------------------------------------- */

Browser = new Object();
Browser.agt     = navigator.userAgent.toLowerCase();
Browser.is_ie	= ((Browser.agt.indexOf("msie") != -1) && (Browser.agt.indexOf("opera") == -1));


document.addLoadEvent = function(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

/* ------------------------------------------------- */
/* -- Browser information active width and height -- */
/* ------------------------------------------------- */
function getWindowClientHeight() {
	var offset = -80;
	if (window.innerHeight!=window.undefined) return window.innerHeight+offset;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight+offset;
	if (document.body) return document.body.clientHeight+offset; 

	return window.undefined; 
}

function getWindowClientWidth() {
	var offset = -80;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth+offset; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth+offset; 
	if (document.body) return document.body.clientWidth+offset; 
}


var clientInnerWidth  = getWindowClientWidth();
var clientInnerHeight = getWindowClientHeight();



var JSTextFilter = {

  removeDiacritics: function (string) {

    string = string.replace(/á/g,'a');
    string = string.replace(/ä/g,'a');
    string = string.replace(/ą/g,'a');
    string = string.replace(/č/g,'c');
    string = string.replace(/ć/g,'c');
    string = string.replace(/ď/g,'d');
    string = string.replace(/é/g,'e');
    string = string.replace(/ě/g,'e');
    string = string.replace(/í/g,'i');
    string = string.replace(/ľ/g,'l');
    string = string.replace(/ĺ/g,'l');
    string = string.replace(/ł/g,'l');
    string = string.replace(/ň/g,'n');
    string = string.replace(/ń/g,'n');
    string = string.replace(/ó/g,'o');
    string = string.replace(/ô/g,'o');
    string = string.replace(/ő/g,'o');
    string = string.replace(/ŕ/g,'r');
    string = string.replace(/ř/g,'r');
    string = string.replace(/ś/g,'s');
    string = string.replace(/š/g,'s');
    string = string.replace(/š/g,'s');
    string = string.replace(/ť/g,'t');
    string = string.replace(/ú/g,'u');
    string = string.replace(/ü/g,'u');
    string = string.replace(/ž/g,'z');
    string = string.replace(/Á/g,'A');
    string = string.replace(/Č/g,'C');
    string = string.replace(/Ď/g,'D');
    string = string.replace(/É/g,'E');
    string = string.replace(/Ě/g,'E');
    string = string.replace(/Í/g,'I');
    string = string.replace(/Ľ/g,'L');
    string = string.replace(/Ĺ/g,'L');
    string = string.replace(/Ň/g,'N');
    string = string.replace(/Ó/g,'O');
    string = string.replace(/Ŕ/g,'R');
    string = string.replace(/Ř/g,'R');
    string = string.replace(/Š/g,'S');
    string = string.replace(/Ś/g,'S');
    string = string.replace(/Ť/g,'T');
    string = string.replace(/Ú/g,'U');
    string = string.replace(/Ž/g,'Z');

    return string;    
  }
}