function newImage(arg) {
  if (document.images) {
    rslt = new Image();
    rslt.src = arg;
    return rslt;
  }
}

function changeImages() {
  if (document.images && (preloadFlag == true)) {
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}

function MM_findObj(n, d) { //v4.0
    var p,i,x;
    if(!d) d=document;

    if ( (p = n.indexOf("?")) > 0 && parent.frames.length ) {
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
    }

  if(!(x=d[n]) && d.all) 
        x=d.all[n];

    for (i=0;!x && i<d.forms.length;i++) 
        x=d.forms[i][n];

    for(i=0;!x && d.layers&&i<d.layers.length;i++) 
        x=MM_findObj(n,d.layers[i].document);

    if(!x && document.getElementById) 
        x=document.getElementById(n); 

    return x;
}

function MM_showHideLayers(szam) { //v3.0
    var i,p,v,obj
    for (i=0; i<11; i++) {
        if ((obj=MM_findObj('Layer'+i))!=null) {
            v='hide';
            
            if (i==szam) 
                v='show';
            
            if (obj.style) {
                obj=obj.style;
                v=(v=='show')?'visible':(v='hide')?'hidden':v; 
            }
            
            obj.visibility=v; 
        }
        if ((obj=MM_findObj('Layeri'+i))!=null) {
                v='hide';
                if (i==szam)
                    v='show';
                if (obj.style) {
                    obj=obj.style;
                    v=(v=='show')?'visible':(v='hide')?'hidden':v; 
                }
                obj.display='block';
                obj.visibility=v; 
        }
    }
}

function showHideSubMenus(szam) {                    
    var menusor= document.getElementById('menusor');
    var layer= document.getElementById('Layer'+szam);
    
    if (szam==0)
        layer.style.left= parseInt(findPosX(document.getElementById('td'+szam)) + 5 )+'px'; 
    else
        layer.style.left= findPosX(document.getElementById('td'+szam))+'px'; 
    layer.style.top= findPosY(menusor) + menusor.offsetHeight - 1
    
    layer.style.visibility= 'visible'; 
    layer.style.display= 'inline'; 
    
}

var preloadFlag = false;
function preloadImages() {
    if (document.images) {                                
        lenyilokep = newImage("/images/lenyilo.gif");
        fejleckep= newImage("/images/fejlec_1-old.jpg");
                        
        preloadFlag = true;
    }
}        

function findPosX(obj) {
    var curleft = 0;
    if(obj.offsetParent)
    while(1) {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if(obj.offsetParent)
    while(1) {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}

function delete_cookie ( cookie_name ) {
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}

function changeLang(lang) {
    if (document.cookie.indexOf('langID') > -1)
        delete_cookie('langID');
    document.cookie= "langID=" + lang;
}        

function sendAnEmail() {
    who="dunapack"
    where="dunapack.hu"
    document.location = "mailto:"+who+"@"+where;
}

function popupPrint(lang) {            
    eval('window.open("/print_' + lang + '.htm","print","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=1,width=670,height=500,top=10,left=10")');
} 

function fillContent() {
    var tart= document.getElementById('tart');            
    var tartalom= window.opener.window.document.getElementById('tartalom');
    tart.innerHTML= tartalom.outerHTML;
}

function popupPic(theimg) {
    eval('window.open("/pic.htm#' + theimg + '","pic","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=1,width=100,height=100,top=10,left=10")');        
} 

function popupPic2(theimg) {
    eval('window.open("/pic2.htm#' + theimg + '","pic","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=0,width=100,height=100,top=10,left=10")');
}                     

function popupFlash(theflash, w, h) {
    if (navigator.appName == "Microsoft Internet Explorer")
        eval('window.open("/flash.htm#' + theflash + '","flash","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=0,width='+(parseInt(w)+20)+',height='+parseInt(h)+',top=10,left=10")');
    else
        eval('window.open("/flash.htm#' + theflash + '","flash","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=0,width='+parseInt(w)+',height='+parseInt(h)+',top=10,left=10")');
} 
        
function popupPic3(URLStr, alttext) {
    var url= '/pic3.htm#' + URLStr + '?' + alttext ;
    var title= alttext;            
    
    var ujablak2=window.open(url,"dunapack","toolbar=no,location=no,directories=0,status=no,menubar=no,scrollbars=yes,resizable=no,width=100,height=100,left=10,top=10");
    ujablak2.focus();
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {
  if (popUpWin) {
    if (!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function popup_print (ablaknev, forras) {
    var url2=forras;
    var nev2=ablaknev;
    var ujablak2=window.open(url2,nev2,"toolbar=1,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0,width=670,height=500,left=0,top=0");
    ujablak2.focus();
}

function popup (ablaknev, forras) {
    var url=forras;
    var nev=ablaknev;
    var ujablak=window.open(url,nev,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,width=450,height=400,left=250,top=100");
    ujablak.focus();
}

function popup_flash (ablaknev, forras) {
    var url=forras;
    var nev=ablaknev;
    var ujablak_flash=window.open(url,nev,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=0,width=770,height=500,left=250,top=100");
    ujablak_flash.focus();
}


function FormValidator(theform, langId)    {    
  if (langId == 2) { 
    searchUrl = '/en/search/search.html';
    searchAlert1 = 'Please fill the search form before submit!';
    searchAlert2 = 'Please type at least 3 character to search!';
    searchAlert3 = 'Please type only numbers and letters! Not valid character: ';
  }
  else {
    searchUrl = '/kereses/kereses.html';
    searchAlert1 = 'Kérem adjon meg egy szót a kereséshez!';
    searchAlert2 = 'Kérem legalább 3 karaktert adjon be a kereséshez!';
    searchAlert3 = 'Kérem csak számokat és a betűket írjon a keresési mezőbe! Nem megengedett karakter: ';
  }
  
  if (theform.searchText.value == "")    {
    alert(searchAlert1);
    theform.searchText.focus();
    return (false);
  }
  if (theform.searchText.value.length < 3) {
    alert(searchAlert2);
    theform.searchText.focus();
    return (false);
  }
  var checkOK = "0123456789aábcdeéfghiíjklmnoóöőprqstuúüűvwxyz-_.+*/,& ";
  var checkStr = theform.searchText.value;
  checkStr= checkStr.toLowerCase();
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++) {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++) {
      if (ch == checkOK.charAt(j)) {
        break;
      }
    }
    if (j == checkOK.length) {
      allValid = false;
      break;
    }
  }
  if (!allValid) {
    alert(searchAlert3 + ch);
    theform.searchText.focus();
    return (false);
  }
  document.location= searchURL + '&searchText=' + encodeURI(theform.searchText.value);
}
