var isExplorer = (navigator.appName == 'Microsoft Internet Explorer');
var divOnActive = null;
document.onmouseover = function ( e ) {
	if ( !e ) e = window.event;
	var el = e.target ? e.target : e.srcElement;
	while ( el != null && el.tagName != "A" ) el = el.parentNode;
	if ( el == null ) return;
	if ( e.preventDefault ) e.preventDefault();
	else e.returnValue = true;
};
var addEvent = function(elem, type, eventHandle) {
    if (elem == null || elem == undefined) return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    }
};

var documentTitle = document.title;
var chatTitle = document.title;
function setTitle(ttl) {
  document.title = ttl;
}

function checkForum() {
  if (document.ForumForm.message.value.indexOf("url=")!=-1) {
    return false;
  }
  return true;
}
function checkMessage() {
  var formobj = document.getElementsByName("MessageForm")[0];
  if (formobj.userName&&formobj.userName.value=='') {
    alert('Töltsd ki a címzettet!')
    return;
  }
  if (formobj.message.value=='') {
    alert('Az üzenet szövege üres!')
    return;
  }
  return true;
}
function checkBlog() {
  var formobj = document.getElementsByName("BlogForm")[0];
  if (formobj.title.value=='') {
    alert('Töltsd ki a címet!')
    return;
  }
  if (formobj.message.value=='') {
    alert('A jegyzet nincs kitöltve!')
    return;
  }
  return true;
}
function checkMessageAndSubmit() {
  var formobj = document.getElementsByName("MessageForm")[0];
  if (formobj.userName&&formobj.userName.value=='') {
    alert('Töltsd ki a címzettet!')
    return;
  }
  if (formobj.message.value=='') {
    alert('Az üzenet szövege üres!')
    return;
  }
  formobj.submit();
  disableAllLink();
  return true;
}
function checkMessageToContactAndSubmit() {
  var formobj = document.getElementsByName("MessageForm")[0];
  if (formobj.senderName&&formobj.senderName.value=='') {
    alert('Töltsd ki a feladót!')
    return;
  }
  if (formobj.message.value=='') {
    alert('Az üzenet szövege üres!')
    return;
  }
  formobj.submit();
  disableAllLink();
  return true;
}
function appendToRecipient(item) {
  var orig = document.getElementsByName("userName")[0].value;
  if (orig.length!=0) {
    document.getElementsByName("userName")[0].value = orig + ', '+item;
  } else {
    document.getElementsByName("userName")[0].value = item;
  }
}
function notInPreview() {
  alert('Ez a funckió előnézetben nem elérhető!');
  return;
}
function trim(s) {
  while(''+s.charAt(s.length-1)==' ')
    s=s.substring(0,s.length-1);
  return s;  
}

function cancelLink () {
  return false;
}
function disableLink (link) {
  if (link.onclick)
    link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
  if (link.style) {
    link.style.cursor = 'default';
    link.style.color = 'gray';
  }
  link.disabled = true;
  disableAllLink();
}
function disableAllLink() {  
  var as = document.getElementsByTagName("a")
  for (i = 0;i < as.length; i++) {
    if (as[i].onclick) as[i].oldOnClick = as[i].onclick;
    as[i].onclick = cancelLink;
    //as[i].disabled = true;
  }
}
if (window.parent.frames[0]) {window.location = "tiles/alert.jsp";}
function writetostatus(input){
    window.status=input;
    return true
}
function selectAllCheckbox(selectorCheckBox,checkBoxArray) {
  for(i=0; i<checkBoxArray.length; i++){
    checkBoxArray[i].checked=selectorCheckBox.checked;
  }
}
function setOption(button) {
  document.forms[0].option.value = button;
  return true;
}

function thisSubmit(f) {
  var fo = document.getElementById(f);
  if (fo) fo.submit(); 
  else document.forms[f].submit();
  disableAllLink();
  return true;
}
function pureSubmit(num) {
  if (num) document.forms[num].submit();
  else document.forms[0].submit();
  disableAllLink();
  return true;
}
function mySubmit(opt) {
  document.forms[0].option.value = opt;
  document.forms[0].submit();
  disableAllLink();
  return true;
}
function mySubmitForm(formname,button) {
  document.forms[formname].option.value = button;
  document.forms[formname].submit();
  disableAllLink();
  return true;
}
function forgottenPasswordSubmit(){
  if (document.ForgottenPasswordForm.forgotten.value=='') {
    alert('Az e-mail cím nics kitöltve!')
    return;
  }
  document.ForgottenPasswordForm.submit();
  return;
}
function pageSubmit(formname,number) {
  document.forms[formname].actualPage.value = number;
  document.forms[formname].submit();
  disableAllLink();
  return true;
}

function orderList(formname,oname) {
  document.forms[formname].option.value = 'list';

  if (document.forms[formname].orderName.value==oname) {
    if (document.forms[formname].orderWay.value=='') {
      document.forms[formname].orderWay.value = 'desc';
    } else {
      document.forms[formname].orderWay.value = '';
    }
  } else {
    document.forms[formname].orderWay.value = '';
    document.forms[formname].orderName.value = oname;
  }

  document.forms[formname].submit();
  disableAllLink();
  return true;
}
function setFileIndexAndSubmit(button, fIndex) {
  document.forms[0].fileIndex.value = fIndex;
  document.forms[0].option.value = button;
  document.forms[0].submit();
  disableAllLink();
  return true;
}
function selectAll(selectorCheckBox) {
  void(d=document);
  void(el=d.getElementsByTagName('INPUT'));
  for(i=0;i<el.length;i++)
    void(el[i].checked=selectorCheckBox.checked);
}
function selectCheckBoxes(flag) {
  void(d=document);
  void(el=d.getElementsByTagName('INPUT'));
  for(i=0;i<el.length;i++)
    void(el[i].checked=flag);
}
function printSite() {
  print();
}
function openPage(page) {
  window.open(page);
  return;
}
function openPopup(url) {
  return openWindow(url, 'data', '800', '600', '1', '0', false);
}
function openPopup(url, windowname, xsize, ysize) {
  return openWindow(url, windowname, xsize, ysize, '1', '1', false);
}
function openPopupBase(url, windowname, xsize, ysize) {
  return openWindow(url, windowname, xsize, ysize, '0', '1', false);
}
function openUpload(url, windowname) {
  return openWindow(url, windowname, '300', '80', '0', '0', false);
}
function openUpload(url) {
  return openWindow(url, 'upload', '300', '80', '0', '0', false);
}
function openDelete(url) {
  return openWindow(url, 'delete', '500', '400', '1', '0', false);
}

function openWindow(url, windowname, width, height, extra, ret, modal) {
  var pars, wnd, extr;
  var size = 'width='+width+',height='+height;
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  var top = (myHeight - height) / 2;
  var left = (myWidth - width) / 2;

  if (isExplorer) {
    pars = 'left='+left+',top='+top+',fullscreen=0,channelmode=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+extra+',resizable='+extra+','+size;
    //if (ret) pars = pars + ',depends=yes';
    if (modal) pars = pars + ',modal=1';
    wnd = window.open(url, windowname, pars);
  }
  else {
    extr = 'no';
    if (extra=='1') extr = 'yes';
    pars = 'screenX='+left+',screenY='+top+',fullscreen=0,channelmode=0,screenX=0,screenY=0,status=no,menubar=no,scrollbars='+extr+',resizable='+extr+','+size;
    //if (ret) pars = pars + ',depends=yes';
    if (modal) pars = pars + ',modal=yes';
    wnd = open(url, windowname, pars);
  }
  wnd.focus();
  if (ret=='1') return wnd;
  return;
}

function pureSubmitAndWaiting(formobj) {
  ww = openWindow("fileUpload.jsp?first=yes","monitor",480,220,'0','1',true);
  formobj.submit();
  ww.focus();
  disableAllLink();
  return;
}

function pureSubmitAndMonitor() {
  //if (window.showModalDialog) {
	//window.showModalDialog("fileUpload.jsp?first=yes", "monitor", "dialogWidth:480px;dialogHeight:220px");
    //document.forms[0].submit();
  //} else {
	ww = openWindow("fileUpload.jsp?first=yes","monitor",480,220,'0','1', true);
	document.forms[0].submit();
	ww.focus();
  //}
  disableAllLink();
  return;
}

function myInstantSubmit() {
  var formobj = document.getElementById("FileSendForm");
  if (formobj.recipient.value=='') {
    alert('Töltsd ki a címzettet!')
    return;
  }
  if (formobj.theFile_0.value=='') {
    alert('Válassz ki legalább egy fájlt!')
    return;
  }
  pureSubmitAndWaiting(formobj);
}
function registrationSubmit() {
  var formobj = document.getElementsByName("RegistrationForm")[0];
  if (formobj.name&&formobj.name.value.length<3) {
    alert('Válassz egy nevet, ami lagalább 3 hosszú!')
    return;
  }
  if (formobj.fullName&&formobj.fullName.value.length==0) {
    alert('Add meg a teljes neved!')
    return;
  }
  if (formobj.email&&formobj.email.value.length<5) {
    alert('Szükség van az e-mail címedre is!')
    return;
  }
  formobj.submit();
}
function fileSendSubmit() {
  var formobj = document.getElementById("FileSendForm");
  if ((formobj.sender&&formobj.sender.value=='')||formobj.recipient.value=='') {
    alert('Töltsd ki a feldót és a címzettet!')
    return;
  }
  if (formobj.theFile_0.value=='') {
    alert('Válassz ki legalább egy fájlt!')
    return;
  }
  pureSubmitAndWaiting(formobj);
}

function fileLinkSubmit() {
  var formobj = document.getElementById("FileSendForm");
  if (formobj.theFile_0.value=='') {
    alert('Válassz ki legalább egy fájlt!')
    return;
  }
  pureSubmitAndWaiting(formobj);
}
function introductionSubmit() {
  var f = document.getElementsByName("FileSendForm")[0];
  if (f.sender.value==''||f.recipient.value=='') {
    alert('Töltsd ki a feladót és a címzettet!')
    return;
  }
  if (f.recipient.value.indexOf('@')=='-1'||f.recipient.value.indexOf('.')=='-1') {
    alert('A címzett e-mail formátuma nem megfelelő!')
    return;
  }
  f.submit();
}

function closeAndSubmitOpener(soption) {
  window.opener.document.forms[0].option.value = soption;
  window.opener.document.forms[0].submit();
  window.close();
  return true;
}

function taLimit() {
  var taObj=event.srcElement;
  if (taObj.value.length==taObj.maxLength*1) return false;
}

function taCount(visCnt) {
  var taObj=event.srcElement;
  if (taObj.value.length>taObj.maxLength*1) taObj.value=taObj.value.substring(0,taObj.maxLength*1);
  if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
function textCounter(field, maxlimit) {
if (field.value.length > maxlimit)
  field.value = field.value.substring(0, maxlimit);
}
function changeClass(element, cname){
  //var erst;
  //var isExplorer = (navigator.appName == 'Microsoft Internet Explorer');
  //if (isExplorer) erst = element.firstChild.firstChild;
  //else erst = element.firstChild.nextSibling.firstChild;
  element.className = cname;
}
function changeClassById(id, cname) {
  document.getElementById(id).className = cname;
}

function replaceImage(element, imgname){
  //var erst;
  //var isExplorer = (navigator.appName == 'Microsoft Internet Explorer');
  //if (isExplorer) erst = element.firstChild.firstChild;
  //else erst = element.firstChild.nextSibling.firstChild;
  element.src = imgname;
}
function menuover(element){
  document.getElementById("image"+element).src = "img/menu"+element+"_over.gif";
  document.getElementById("text"+element).style.color = "#0923a4";
}
function menuout(element){
  document.getElementById("image"+element).src = "img/menu"+element+".gif";
  document.getElementById("text"+element).style.color = "#000000";
}

function textCounter(field, maxlimit) {
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
  }
}
function helpbubble(thiz, repImg, iname, isize) {
  replaceImage(thiz, repImg);
  divOnToDelay(iname, iname+"_help_bubble", isize, -135)
  return;
}
function closehelpbubble(thiz, repImg, iname) {
  replaceImage(thiz, repImg);
  eval('setTimeout(\'divOffWaiting(' + iname + '_help_bubble)\',' + 200 + ')');
  return;
}

function toAllWordsProperCase(s){
    if(void(0)==s||null==s) return "";
    if("object"==typeof(s)) s = s.nextNode.text;
    if(void(0)==s||""==s) return "";

    var result = "";
    var words = s.split(" ");
    var count = words.length;

    for(var i=0;i<count-1;i++) {
       result += parse(words[i]) + " ";
    }
    result += parse(words[i]);

    return result;

	function parse(s){
	   if(void(0)==s||""==s) return "";
	    return s.charAt(0).toUpperCase() + s.substr(1).toLowerCase();
	}
}

function f_clientWidth() {
  return f_filterResults (
    window.innerWidth ? window.innerWidth : 0,
    document.documentElement ? document.documentElement.clientWidth : 0,
    document.body ? document.body.clientWidth : 0
  );
}
function f_clientHeight() {
  return f_filterResults (
    window.innerHeight ? window.innerHeight : 0,
    document.documentElement ? document.documentElement.clientHeight : 0,
    document.body ? document.body.clientHeight : 0
  );
}
function f_scrollLeft() {
  return f_filterResults (
    window.pageXOffset ? window.pageXOffset : 0,
    document.documentElement ? document.documentElement.scrollLeft : 0,
    document.body ? document.body.scrollLeft : 0
  );
}
function f_scrollRight() {
  var sw = f_clientWidth();
  var sl = f_scrollLeft();
  return sw-sl;
}
function f_scrollTop() {
  return f_filterResults (
    window.pageYOffset ? window.pageYOffset : 0,
    document.documentElement ? document.documentElement.scrollTop : 0,
    document.body ? document.body.scrollTop : 0
  );
}
function f_filterResults(n_win, n_docel, n_body) {
  var n_result = n_win ? n_win : 0;
  if (n_docel && (!n_result || (n_result > n_docel)))
    n_result = n_docel;
  return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


