var balnyil ='' ;
var jobbnyil='' ;
var altok = new Array();

function wfocus(){
window.focus();
}

function change_image(pic,id){
    depo=document.images['picture1'].src;
    document.images['picture1'].src= pic;
    document.images[id].src= depo
}

//------------------------------------------------------------


//============================AJAX ÁLTALÁNOS ===================================
//=================  url : hivando oldal url - je
//=================  post : post adat
//=================  divname : a div, amibe töltünk
//=============================================================================
/**
 * Ajax objektum
 *
 *@param : url (string) post(string) divname(string) betolt(string) betolt(obj) feldolgozas(obj) loadstring(string)
 *
 */
function Ajax_alap(){
  this.url = '' ;
  this.post = '' ;   
  this.divname = '';
  this.betolt = function() { feltolt(this.url,this.divname,this.extra,this.post,this.loadstring);};
  this.feldolgozas = feldolgoz;
  this.loadstring = '...... Loading, please wait ........'; 
  this.extra = '';
 
//---------------------------------------
function feltolt(url,div,extra,post,loadstr) {  
if(this.divname!='')
    var adatok = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
   adatok = new XMLHttpRequest();
   if (adatok.overrideMimeType) {
    adatok.overrideMimeType('text/xml');        
   }
  } else if (window.ActiveXObject) { // IE
   try {
    adatok = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
      try {
       adatok = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
     }
   }
   
   if (!adatok) {
    alert('Feladtam :( Nem tudok XMLHTTP példányt létrehozni');
            return false;
   }
   /* 
    div = this.divname;
    extra = this.extra;
    */
    
    adatok.onreadystatechange = function() { feldolgoz(adatok,div,extra); };    
    adatok.open('POST',url, true);
    adatok.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    //adatok.setRequestHeader('Content-Type', 'charset=UTF-8');
    adatok.send(post);
  }
  
 
//-----------------------------------
 

function feldolgoz(adatok,divname,extra) {
 
 if (adatok.readyState == 4) {
    //if (adatok.status == 200) {
    if (true) {    	
    	//alert(adatok.responseText);
       adat = adatok.responseText;
       if(extra=='category_uploadomage'){
       	 categoryrefres();
       }else if(extra=='filter_parser'){
       	adatp = new Array();
        adatp = adat.split('::||::');
       	adat = adatp[0];    // tartalom   
       	combotolt(adatp[1]);      	
       }
      // alert(divname);
   if(divname!=''){     
     document.getElementById(divname).innerHTML=(adat);
   }
    } else {
    	 alert(adatok.responseText);
       alert('Valami gond van a kéréssel.');
      }
    }
  }
  
  function combotolt(cadat){
  //	cousinedata =  cadat.substring(cadat.search('<cousinecombo')+21,cadat.search('</cousinecombo>'));
  //--------- Cousine parser
  	cousinedata1 =  cadat.substring(cadat.search('<cousinecombo'),cadat.search('</cousinecombo>'));
  	   cousinedata1 = cousinedata1.replace(/</,'');
  	   cdata = new Array();
  	   cdata = cousinedata1.split('>');
       cousinedata = cdata[1];  // értékek

    cparam = new Array();
    cparam = cdata[0].split(' ');
     cselect = new Array();
     cselect = cparam[2].split('=');
     cselectID = cselect[1];					//// Találatok száma COUSINE

     ckellarr =  new Array();
     ckellarr = cparam[1].split('=');
     ckell = ckellarr[1];

    //-----------------


  	//profiledata = cadat.substring(cadat.search('<profilecombo')+21,cadat.search('</profilecombo>'));
  	//---------- profiledata parser
  	profiledata1 =  cadat.substring(cadat.search('<profilecombo'),cadat.search('</profilecombo>'));
  	   profiledata1 = profiledata1.replace(/</,'');
  	   pdata = new Array();
  	   pdata = profiledata1.split('>');
       profiledata = pdata[1];  // értékek
   // alert(profiledata);
    pparam = new Array();
    pparam = pdata[0].split(' ');
     pselect = new Array();
     pselect = pparam[2].split('=');
     pselectID = pselect[1];              /// találatok száma PROFILE

     pkellarr =  new Array();
     pkellarr = pparam[1].split('=');
     pkell = pkellarr[1];
    //------------------------


  //	servicedata = cadat.substring(cadat.search('<servicescombo')+22,cadat.search('</servicescombo>'));
  	//------------ service parser
  	servicedata1 =  cadat.substring(cadat.search('<servicescombo'),cadat.search('</servicescombo>'));
  	   servicedata1 = servicedata1.replace(/</,'');
  	   sdata = new Array();
  	   sdata = servicedata1.split('>');
       servicedata = sdata[1];  // értékek

    sparam = new Array();
    sparam = sdata[0].split(' ');
     sselect = new Array();
     sselect = sparam[2].split('=');
     sselectID = sselect[1];					///// Találatok száma SERVICE

     skellarr =  new Array();
     skellarr = sparam[1].split('=');
     skell = skellarr[1];
  //	alert(sselectID);
  	//alert(cousinedata);
  	// alert(servicedata);
	  	if(cousinedata.length>2){
	  	 divkapcs('cousinediv',true);
	  if(ckell==1){
	  	 z = document.filterform.cousinecombo.length;  // combobox törlése
		     for(i=1;i<z;i++){
		   		document.filterform.cousinecombo.options[1] = null;
		     }
		   	op1 = new Option("Cuisine ------ "+cselectID,"0");
		   	document.filterform.cousinecombo.options[0] = op1;
		   	prof = new Array();
		   	prof = cousinedata.split(';');

		   	for(i=0;i<prof.length;i++){
		   		opdata = new Array();
		   		opdata = prof[i].split('||');
		   	    op = new Option(opdata[0],opdata[1],false,false);
		   		document.filterform.cousinecombo.options[i+1] = op;
		   	}
	  }

	  	}else{
	     divkapcs('cousinediv',false);
	   }


	   if(profiledata.length>2){
		   	divkapcs('profilediv',true );
		if(pkell==1){
		   	z = document.filterform.profilecombo.length;  // combobox törlése
		     for(i=1;i<z;i++){
		   		document.filterform.profilecombo.options[1] = null;
		     }
		   	op1 = new Option("Profile ------ "+pselectID,"0");
		   	document.filterform.profilecombo.options[0] = op1;
		   	prof = new Array();
		   	prof = profiledata.split(';');

		   	for(i=0;i<prof.length;i++){
		   		opdata = new Array();
		   		opdata = prof[i].split('||');
		   		op = new Option(opdata[0],opdata[1],false,false);
		   		document.filterform.profilecombo.options[i+1] = op;
		   	}
		}

	   }else{
	   	divkapcs('profilediv',false);
	   }


	   if(servicedata.length>2){

	   	divkapcs('servicediv',true);
	   	if(skell==1){
	     	z = document.filterform.servicescombo.length;  // combobox törlése
		     for(i=1;i<z;i++){
		   		document.filterform.servicescombo.options[1] = null;
		     }
		   	op1 = new Option("Services ------ "+sselectID,"0");
		   	document.filterform.servicescombo.options[0] = op1;
		   	prof = new Array();
		   	prof = servicedata.split(';');

		   	for(i=0;i<prof.length;i++){
		   		opdata = new Array();
		   		opdata = prof[i].split('||');
		   		op = new Option(opdata[0],opdata[1],false,false);
		   		document.filterform.servicescombo.options[i+1] = op;
		   	}
	   	}
	   }else{
	   	divkapcs('servicediv',false);
	   }


  }


}


//------- DIV  - ek kikapcsolása -----------------------

function divkapcs(nev,ertek){
  if(ertek){
    document.getElementById(nev).style.display='block';
  }else{
    document.getElementById(nev).style.display='none';
  }
}


/**
 * Objektum ID - t adja vissza.
 * 
 * @param objektum obj
 * @return ID
 */
function $(obj){
	l = document.getElementById(obj);
	return l;
}


//--------------- IMAGE UPLOAD -------------------------

function uploadimage(mod,id,maxkep,menuid){
 if(!menuid) menuid=0;
 if(!id) id = 0;
 if(!maxkep) maxkep = 99;    
  a = window.open('ownerzone/down_image.php?reference='+maxkep+'&downtype='+mod+'&id='+id+'&menuid='+menuid+'','down_image','width=500,height=150');
  a.moveTo(300,150);
  a.focus();
}


//-------------- GOOGLE MAP -----------------------------

function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(37.4419, -122.1419), 13);
      }
    }

//------------------------------------------------------
//-------------------- CITY SEARCH ---------------------

function city_search(sr){
  if((sr*1) && sr.length > 4){
  	 zipsearch(sr,'kozepe');
  }else if((isNaN(parseInt(sr))) && sr.length > 3){
   c_search = new Ajax_alap();
   c_search.url = 'utils/city_search.php';
   c_search.divname='kozepe';
   c_search.post = 'csearch='+sr+'&searchmode=name';
   c_search.betolt();
   }
}

function refresh(val) {
    if(val=='City or Zip code'){
    document.getElementById("field").value ="";

}
}

function csakszam(sz){
		v='';
			for (i=0;i<sz.length;i++) {
				c=sz.substr(i,1);
				if (!isNaN(parseInt(c))) v=v+c;
			}
		if(v.length==5){
		  zipsearch(v,'');	
		}
			return v;
}

function zipsearch(zip,divname){
	zsearch = new Ajax_alap();
	
	if(divname == ''){                                      /* Ownerreg oldal*/
		zsearch.url = 'ownermain/state_price_search.php';
		zsearch.divname = 'reg_province_div';
		zsearch.post = 'zip='+zip;
        setTimeout("set_package_reload('zip','','','')",2000);
	}else if(divname=='kozepe'){                            /*Kereso fent*/
		zsearch.url = 'utils/city_search.php';
		zsearch.divname = divname;
		zsearch.post = 'zip='+zip+'&searchmode=toredek';
	}
	zsearch.betolt();
	}
 


function vizsgal(telszam, hossz, id, kov){
	   z='';
       x= telszam.length;
       if(x>hossz){x=hossz;}
	   for (i=0;i<x;i++){
	        k=telszam.substr(i,1);
		    if (!isNaN(parseInt(k))){z=z+k;}
	        }
       document.getElementById(id).value=z;
       if(z.length >= hossz & kov !=''){
            document.getElementById(kov).focus();
            }
}


//------------------PRINT----------------------
function nyomtat(mod,kid){	
	a = window.open('print/'+mod+'_print.php?nyid='+kid+'','print','width=900,height=700,scolbars=yes');
	a.moveTo(150,50);
}


function kismap_betolt(cimk,zoom) {
    var map = new GMap2(document.getElementById("kismap"));
    var geocoder = new GClientGeocoder();
    geocoder.getLatLng(cimk,function(point) {
    //alert(cimk);
        if (point){
            //alert(cim + point);
            //var pont=point.x+','+point.y;
            //map.setCenter(new GLatLng(point.x, point.y), 13);
            //GEvent.addListener(map, "click", function() {
                //alert("You clicked the map.");
                //});
            map.setCenter(point, zoom);
            var marker = new GMarker(point);
           // map.addControl(new GLargeMapControl());
            map.addOverlay(marker);
            //marker.openInfoWindowHtml(bubi)
            }
        }
    );
}

function set_package_reload(pack,state1,province1,state2){
	province = new Ajax_alap();
 	province.url='ownermain/set_package.php';
    if(pack=='zip'){province.post='';
    }
    else {province.post='packageid='+pack+'&stateid='+state1+'&province1='+province1+'&state2='+state2;}
 	province.divname='set_package';
 	province.betolt();
}

function features_select_reload(features){
    if(features=='reset'){
       document.getElementById('filtered_restaurant').style.display='none';
       document.getElementById('nofiltered').style.display='block';
    }
    else {
       document.getElementById('nofiltered').style.display='none';
       //document.getElementById('filtered_restaurant').style.display='block';
    }
	features_select = new Ajax_alap();
 	features_select.url='picnav/restaurant_filter.php';
    features_select.post='features='+features;
 	features_select.divname='restaurant_filter';
 	features_select.betolt();
}

function features_review_reload(page){
    //document.getElementById('nofiltered').style.display='none';
	features_review = new Ajax_alap();
 	features_review.url='picnav/restaurant_filter.php';
    features_review.post='features=82&page='+page;
 	features_review.divname='restaurant_filter';
 	features_review.betolt();
}
function set_focus(fok){
    document.getElementById(fok).focus();
}

function set_value(div_name,val){
    document.getElementById(div_name).value=val;
}

function set_background(div_name,value){
    document.getElementById(div_name).style.background=value;
}

function set_visibility(div_name,value){
    document.getElementById(div_name).style.visibility=value;
}
function set_display(div_name,value){
    document.getElementById(div_name).style.display=value;
}
