var akt_menu = 1;
var akt_almenu = 1;
var max_menu = 6;
var max_almenu = 4;

function ol() {
	menuvalt( akt_menu );
}

function menu_elem_on( obj, id ) {
	obj.className='menuelem_on';
	var o = document.getElementById( "menu_auto_" + id );
	o.src = "images/menu_auto.jpg";
}

function menu_elem_off( obj, id ) {
	obj.className='menuelem';
	if ( id != akt_menu ) {
		var o = document.getElementById( "menu_auto_" + id );
		o.src = "images/menu_auto_on.jpg";
	}
}

function almenu_elem_on( obj, id ) {
	obj.className='almenuelem-td-on';
}

function almenu_elem_off( obj, id ) {
	if ( id != akt_almenu ) {
		obj.className='almenuelem-td';
	}
}

function menuvalt( id ) {
	var o = null;
	for ( var i = 1; i <= max_menu; i++ ) {
		o = document.getElementById( "menu_auto_" + i );
		if ( id != i )
			o.src = "images/menu_auto_on.jpg";
		else
			o.src = "images/menu_auto.jpg";
	}
	akt_menu = id;
	var pagename = 'bemutatkozunk';
	switch ( id ) {
		case 1: pagename = 'bemutatkozunk'; break;
		case 2: pagename = 'szolgaltatasok'; break;
		case 3: pagename = 'dijtablak'; break;
		case 4: pagename = 'elerhetosegek'; break;
		case 5: pagename = 'hasznoslinkek'; break;
		case 6: pagename = 'BIZTOSITASI_KIS_SZOTAR'; break;
	}
	getPage( pagename, 1 );
}

function almenuvalt( obj, id ) {
	var o = null;
	for ( var i = 1; i <= max_almenu; i++ ) {
		o = document.getElementById( 'almenu_' + i );
		if ( id != i )
			o.className='almenuelem-td';
		else
			o.className='almenuelem-td-on';
	}
	akt_almenu = id;
	var pagename = 'KGFB';
	switch ( id ) {
		case 1: pagename = 'KGFB'; break;
		case 2: pagename = 'FAF'; break;
		case 3: pagename = 'KAF'; break;
		case 4: pagename = 'CASCO'; break;
	}
	getPage( pagename, 2 );
}

function dummy() {};

var httpRequest = null;

function newXMLHttpRequest() {
	if ( window.XMLHttpRequest ) {
		httpRequest = new XMLHttpRequest();
		if ( httpRequest.overrideMimeType ) {
			httpRequest.overrideMimeType( 'text/xml' );
		}
	} else if ( window.ActiveXObject ) {
		try {
			httpRequest = new ActiveXObject( "Msxml2.XMLHTTP" );
		} catch ( e ) {
		try {
			httpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
			} catch ( e ) {}
		}
	}

	if ( !httpRequest ) {
		alert( 'Giving up :( Cannot create an XMLHTTP instance' );
		return false;
	}
}

function getPage( page, menu ) {
	newXMLHttpRequest();
	httpRequest.onreadystatechange = function() { alertContents( httpRequest, page, menu ) };
	if ( menu == 1 ) {
		httpRequest.open( 'GET', 'pages/' + page + '.htm', true );
	} else if ( menu == 2 ) {
		httpRequest.open( 'GET', 'pages/szolgaltatasok/' + page + '.htm', true );
	}
	httpRequest.setRequestHeader( "Connection", "close" );
	httpRequest.send( "" );
	/*
	var obj = document.getElementById( "loading" );
	obj.style.display = 'block';
	*/
}

function alertContents( httpRequest, page, menu ) {

	var obj = document.getElementById( "loading" );

	if ( httpRequest.readyState == 4 ) {
		if ( httpRequest.status == 200 ) {

			if ( menu == 1 ) {

				cont = document.getElementById( "tartalom_body" );
				cont.innerHTML = httpRequest.responseText;

				if ( akt_menu == 4 )
					terkep_init();
				else if ( akt_menu == 2 ) {
					akt_almenu = 1;
					getPage( 'KGFB', 2 );
				}

			} else if ( menu == 2 ) {

				cont = document.getElementById( "altartalom-body" );
				cont.innerHTML = httpRequest.responseText;

			}

		} else {
			alert( 'There was a problem with the request.' );
		}

		obj.style.display = 'none';

	}

}

function nyit( mit ) {
	window.open( 'http://' + mit, '_BLANK', '' );
}

function nyitCalc() {
	wn = window.open( "http://www.kobe.hu/kobewww/main/w_sys_rates.php?dc=3", "_BLANK", "width=1000,height=700,scrollbars=1,resizable=1" );
}

function semmi() { }

var map;

var varosInfo = [
    {varos: "Szolnok",
     cimek: [{keresocim: "5, Szapary utca, Szolnok, Magyarorszag", 
              location: null, 
              munkatarsak: [{titulus: "Megyei képviselet vezető", nev: "Juhász József"},
                            {titulus: "Üzletkötő", nev: "Juhász Norbert"}],
              cim: "Szapáry út 19. földszint 3.",
              levelcim: "5001 Szolnok, Postafiók 119.",
              tel: "56/513-459", 
              fax: "56/421-100",
              mobil: ["20/942-3212", "70/319-6234"],
              nyitvatartas: [{nap: "Hétfőtől-csütörtökig", ora: "8:00-16:00"},
                             {nap: "Pénteken", ora: "8:00-12:00"}],
              email: "autobiztosito@t-online.hu"}]
    },
    {varos: "Eger",
     cimek: [{keresocim: "32, Csiki Sandor, Eger, Magyarorszag", 
              location: null,
              munkatarsak: [{titulus: "Üzletkötő", nev: "Csépányiné Kaknics Katalin"},
                            {titulus: "Üzletkötő", nev: "Bakosné Szanday Edit"}],
              cim: "3300 Eger, Csiky Sándor u. 32.",
              levelcim: "",
              tel: "36/313-033, 36/516-388",
              fax: "36/516-387",
              mobil: ["70/384-4794", "70/384-4798"],
              nyitvatartas: [],
              email: "iposzeger@iposzeger.t-online.hu"}]
    },
    {varos: "Fegyvernek",
     cimek: [{keresocim: "45, Ady Endre, Fegyvernek, Magyarorszag", 
              location: null,
              munkatarsak: [{titulus: "Üzletkötő", nev: "Gácsi Jánosné"}],
              cim: "5231 Fegyvernek, Ady Endre u. 45.",
              levelcim: "",
              tel: "",
              fax: "",
              mobil: ["30/507-0853"],
              nyitvatartas: [],
              email: "tothmari55@freemail.hu"}]},
    {varos: "Jaszbereny",
     cimek: [{keresocim: "9, Zerge ut, Jaszbereny, Magyarorszag", 
              location: null,
              munkatarsak: [{titulus: "Üzletkötő", nev: "Nagy-Temesvári Bíborka"}],
              cim: "5100 Jászberény, Zegre u. 9.",
              levelcim: "",
              tel: "",
              fax: "",
              mobil: ["30/912-5433"],
              nyitvatartas: [],
              email: "tbiborka@freemail.hu"}]},
    {varos: "Tiszafoldvar",
     cimek: [{keresocim: "5, Szapary utca, Tiszafoldvar, Magyarorszag", 
              location: null,
              munkatarsak: [{titulus: "Üzletkötő", nev: "Jobbágy Zsigmondné"}],
              cim: "5430 Tiszaföldvár, Kossuth Lajos út 91.",
              levelcim: "5001 Szolnok, Postafiók 119.",
              tel: "56/470-395",
              fax: "",
              mobil: [],
              nyitvatartas: [],
              email: "autobiztosito@t-online.hu"}]},
    {varos: "Tiszafured",
     cimek: [{keresocim: "45, Orvenyi ut, Tiszafured, Magyarorszag", 
              location: null,
              munkatarsak: [{titulus: "Üzletkötő", nev: "Nagy Nándor"}],
              cim: "5350 Tiszafüred, Örvényi út 45/b.",
              levelcim: "",
              tel: "",
              fax: "",
              mobil: ["20/394-6785"],
              nyitvatartas: [],
              email: "nandor.nagy.tf@t-online.hu"},
             {keresocim: "32, Dozsa Gyorgy utca, Tiszafured, Magyarorszag", 
              location: null,
              munkatarsak: [{titulus: "Üzletkötő", nev: "Péntek Piroska"}],
              cim: "5350 Tiszafüred, Dózsa György út 32.",
              levelcim: "",
              tel: "",
              fax: "",
              mobil: ["20/368-3074"],
              nyitvatartas: [],
              email: "fortuna217@t-online.hu"}]}
  ];

var infowindow;

function terkep_init() {

  infowindow = new google.maps.InfoWindow();

  var myOptions = {
    minZoom: 7,
    scrollwheel: false,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("terkep_holder"), myOptions);

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': 'Hungary' }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      map.fitBounds(results[0].geometry.viewport);
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[0].cimek[0].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[0].cimek[0].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Szolnok', 0));
        infowindow.open(map, marker);
      });
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[1].cimek[0].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[1].cimek[0].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Eger', 0));
        infowindow.open(map, marker);
      });
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[2].cimek[0].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[2].cimek[0].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Fegyvernek', 0));
        infowindow.open(map, marker);
      });
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[3].cimek[0].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[3].cimek[0].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Jaszbereny', 0));
        infowindow.open(map, marker);
      });
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[4].cimek[0].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[4].cimek[0].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Tiszafoldvar', 0));
        infowindow.open(map, marker);
      });
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[5].cimek[0].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[5].cimek[0].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Tiszafured', 0));
        infowindow.open(map, marker);
      });
    }
  });

  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varosInfo[5].cimek[1].keresocim }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      varosInfo[5].cimek[1].location = results[0].geometry.location;
      var marker = new google.maps.Marker({
        position: results[0].geometry.location,
        map: map,
        icon: 'images/pics/kobe_zaszlo.png'
      });
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(getInfoContent('Tiszafured', 1));
        infowindow.open(map, marker);
      });
    }
  });
}

function zoomToVaros(varos) {
  var geocoder = new google.maps.Geocoder();
  geocoder.geocode( { 'address': varos + ", Magyarorszag" }, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
      map.setCenter(results[0].geometry.location);
      map.setZoom(13);
    }
  });
}

function getInfoContent(varos, cimIdx) {
  varosIdx = -1;

  for (i in varosInfo)
    if (varosInfo[i].varos == varos) {
      varosIdx = i;
    }

  if (varosIdx == -1)
    return "";
    
  if (varosInfo[varosIdx].cimek[cimIdx] == null)
    return "";

  var s = '<div style="overflow-x: hidden;"><table border="0" width="100%" cellspacing="1" cellpadding="0">';

  if (varosInfo[varosIdx].cimek[cimIdx].munkatarsak.length != 0) {
    s += '<tr>' +
						'<td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Munkatársaink:</td>' +
						'<td>' +
							'<table border="0" width="100%" cellspacing="1">';

    for (i in varosInfo[varosIdx].cimek[cimIdx].munkatarsak) {
      s += '<tr>' +
             '<td class="elerhetoseg-td-sima">' + varosInfo[varosIdx].cimek[cimIdx].munkatarsak[i].titulus + ':</td>' +
             '<td class="elerhetoseg-td-felkover">' + varosInfo[varosIdx].cimek[cimIdx].munkatarsak[i].nev + '</td>' +
           '</tr>';
    }

    s += '</table></td></tr>';
  }

  s += '<tr><td>&nbsp;</td></tr>';

  if (varosInfo[varosIdx].cimek[cimIdx].cim != "") {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Cím:</td>' +
         '<td class="elerhetoseg-td-sima" >' + varosInfo[varosIdx].cimek[cimIdx].cim + '</td></tr>';
  }

  if (varosInfo[varosIdx].cimek[cimIdx].levelcim != "") {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Levélcím:</td>' +
         '<td class="elerhetoseg-td-sima" >' + varosInfo[varosIdx].cimek[cimIdx].levelcim + '</td></tr>';
  }

	if (varosInfo[varosIdx].cimek[cimIdx].tel != "") {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Telefon:</td>' +
         '<td class="elerhetoseg-td-sima" >' + varosInfo[varosIdx].cimek[cimIdx].tel + '</td></tr>';
  }				

	if (varosInfo[varosIdx].cimek[cimIdx].fax != "") {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Fax:</td>' +
         '<td class="elerhetoseg-td-sima" >' + varosInfo[varosIdx].cimek[cimIdx].fax + '</td></tr>';
  }				

	if (varosInfo[varosIdx].cimek[cimIdx].mobil.length != 0) {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Mobil:</td>' +
         '<td class="elerhetoseg-td-sima" >';
    for (var i in varosInfo[varosIdx].cimek[cimIdx].mobil) {
      s += varosInfo[varosIdx].cimek[cimIdx].mobil[i] + '<br/>';
    }
    s += '</td></tr>';
  }							

	s += '<tr><td>&nbsp;</td></tr>';

	if (varosInfo[varosIdx].cimek[cimIdx].nyitvatartas != 0) {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">Nyitva tartás:</td><td>' +
         '<table border="0" width="100%" cellspacing="1">';
    
    for (var i in varosInfo[varosIdx].cimek[cimIdx].nyitvatartas) {
      s += '<tr>' +
             '<td class="elerhetoseg-td-piros">' + varosInfo[varosIdx].cimek[cimIdx].nyitvatartas[i].nap + ':&nbsp;</td>' +
             '<td class="elerhetoseg-td-piros">' + varosInfo[varosIdx].cimek[cimIdx].nyitvatartas[i].ora + '</td>' +
           '</tr>';
    }
	
    s += '</table><br/></td></tr>';
	}

	if (varosInfo[varosIdx].cimek[cimIdx].email != "") {
    s += '<tr><td class="elerhetoseg-td-zold" valign="top" align="left" width="100">E-mail:</td>' +
         '<td class="elerhetoseg-td-sima" >' +
           '<a href="mailto:' + varosInfo[varosIdx].cimek[cimIdx].email + '">' + varosInfo[varosIdx].cimek[cimIdx].email + '</a></td></tr>';
  }

  s += '</table></div>';

  return s;
}
