//-------------------------     // LOGIN hitelesítés
function login_validate() {
//-------------------------
  var ok = true;
  if (document.form_login.login.value=="") {
      document.form_login.login.style.backgroundColor = 'lightpink';
      ok = false;	
  } else {document.form_login.login.style.backgroundColor = 'white';  }
  
  if (document.form_login.pw.value=="") {   
      document.form_login.pw.style.backgroundColor = 'lightpink';
      ok = false;	
  } else { document.form_login.pw.style.backgroundColor = 'white'; }
	if (ok==true) {document.form_login.submit(); }
return ok; }


//-------------------------------------------------------
 function setStyle(elem, styl) {  elem.className=styl;  }  
//-------------------------------------------------------  

//-------------------------------------------------------  Elem létrehozása pl: addElement('szulodiv', 'div', 'div1') 
function addElement(vParrentId, vChild, vChildId, vCss) {
//-------------------------------------------------------
  if (document.getElementById(vChildId) == undefined) {   // ha nem létezik, akkor létrehozzuk
       var eParrent = document.getElementById(vParrentId);
       var eChild   = document.createElement(vChild);
           eChild.setAttribute('id', vChildId);
           eChild.setAttribute('class', vCss);             // FFox;
           eChild.setAttribute('className', vCss);         // IE
           eParrent.appendChild(eChild);
  } else {                                                 // ha létezik, akkor letöröljük
     var eParrent = document.getElementById(vParrentId);
     var eChild   = document.getElementById(vChildId);
     eParrent.removeChild(eChild);
  } 
}

//-----------------------
function xPost(formid) {
//-----------------------
 var obj, tipus, s_index, s_value;
 var poststr = '';
 var utolso = document.getElementById(formid).elements.length-1;
 for (i=0; i<=utolso; ++i) {
    obj = document.getElementById(formid).elements[i];
    tipus = obj.type;
    if (tipus=="text")     {poststr+=obj.name+"="+encodeURI(obj.value);}
    if (tipus=="password") {poststr+=obj.name+"="+encodeURI(obj.value);}
    if (tipus=="hidden")   {poststr+=obj.name+"="+encodeURI(obj.value);}
    if (tipus=="textarea") {poststr+=obj.name+"="+encodeURI(obj.value);}
    if (tipus=="radio")    {if(obj.checked==true) {poststr+=obj.name+"="+encodeURI(obj.value);}}
    if (tipus=="checkbox") {
       poststr+=obj.name+"="+((obj.checked==true)? "Y":"N");}
    if (tipus =="select-one") {
        s_index = obj.selectedIndex;
        s_value = obj.options[s_index].value;
        if (s_value=="") {s_value = s_index;}
        poststr+=obj.name+"="+encodeURI(s_value);
    }
    if (i != utolso) { poststr += "&";}
 }
return (poststr);
}

//-----------------------------------------------------           // ajax XHR 
function getAjax(phpfajl, DIVid, parameterek, stilus) {
//-----------------------------------------------------
  if (parameterek.indexOf('funkcio=erase')>-1) {if (!window.confirm('Valóban törli?')) {return;}}
  var xmlHttp;
  try         { xmlHttp=new XMLHttpRequest();   }                    // Firefox, Opera 8.0+, Safari
  catch (e)   { 
  try         { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }    // Internet Explorer
  catch (e)   {    
  try         { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
  catch (e)   { alert("Az Ön böngészője nem támogatja az AJAX-ot!");  return false;  }}}
    
  xmlHttp.onreadystatechange=function()    {
      if(xmlHttp.readyState<4) { document.getElementById(DIVid).innerHTML='<img src="images/loading.gif">'; }
      else                     { if (stilus != '') { document.getElementById(DIVid).className = stilus; }
                               document.getElementById(DIVid).innerHTML=xmlHttp.responseText;          
                               CB_Init();   }    // CB_Init: ClearBox technika init függv.!
  }  
  xmlHttp.open("GET",phpfajl+"?"+parameterek,true);  // paraméterek'' új, módosít; p3=view: nézet; p3=erase: törlés
  xmlHttp.send(null);
}
//-------------------------------------------------           // ajax XHR 
function postAjax(phpfajl, DIVid, FORMid, stilus) {
//-------------------------------------------------
  var poststr = xPost(FORMid);
  var xmlHttp;
  try         { xmlHttp=new XMLHttpRequest();   }                    // Firefox, Opera 8.0+, Safari
  catch (e)   { 
  try         { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }    // Internet Explorer
  catch (e)   {    
  try         { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
  catch (e)   { alert("Az Ön böngészője nem támogatja az AJAX-ot!");  return false;  }}}
    
  xmlHttp.onreadystatechange=function()    {
      if(xmlHttp.readyState<4) { 
        document.getElementById(DIVid).innerHTML='<img src="images/loading.gif">'; 
        
      } else { 
         if (xmlHttp.status==200) {
            document.getElementById(DIVid).innerHTML=xmlHttp.responseText;
            CB_Init();           // CB_Init: ClearBox technika init függv.!
            
         } else {
            document.getElementById(DIVid).innerHTML='kommunikációs hiba!'+xmlHttp.status;
         }                
      } 
  }  
  xmlHttp.open("POST",phpfajl,true);  
  xmlHttp.setRequestHeader("Content-type", 
                           "application/x-www-form-urlencoded");
  xmlHttp.setRequestHeader("Content-length",poststr.length);                           
  xmlHttp.setRequestHeader("Connection","close");                           
  xmlHttp.send(poststr);
}

//-----------------------------------------------------     // offset használa (offset (get) + a kereső mezők post értékei 
function pgAjax(phpfajl, DIVid, formnev, parameterek) {
//-----------------------------------------------------
  var poststr = xPost(formnev);
  getAjax(phpfajl, DIVid, poststr+parameterek, '');
}

//--------------------------------------------------     // Akkor használjuk, ha a
function newsAjax( phpfajl, par_id, param, stilus) {     // "harmonikára" van szükség....
//--------------------------------------------------
  var chi_id = 'chi_'   + par_id;   // '23' -->  'chi_23'
  addElement(par_id, 'DIV', chi_id, stilus);
  if (document.getElementById(chi_id) != undefined) { // nem törölte
      getAjax(phpfajl, chi_id, param, stilus); }
  }

//-----------------------                     // ezt már az ajax fogja meghívni 
function div_bezar(divid) {                   // lenyíló harmonika ablak bezárása
//-----------------------
 document.getElementById(divid).innerHTML = ''; 
 document.getElementById(divid).className = ''; 
}


