var url = document.location.href;
url = url.split('/');
url_ = '';
for(i=0;i<url.length-1;i++) {
 url_ = url_ + url[i] + '/';
}


var oldal = new Array();
oldal['porzsak'] = 0;
oldal['filter'] = 1;
oldal['tartozek'] = 2;

param = url[url.length-1].split("?");
var c = 0;
var c1 = 0;
var p = '';
if(param[1] != undefined) {
 param = param[1].split('&');
 for(i=0;i<param.length;i++) {
  temp = param[i].split("=");
  if(temp[0] == "p") {
   p = temp[1];
  }
  if(temp[0] == "c") {
   c = temp[1];
  }
  if(temp[0] == "c1") {
   c1 = temp[1];
  }
 }
}

if(c) {
 porszivoKeres(c, oldal[p]);
}

function porszivoKeres(gyarto, tipus) {
 if(gyarto == '') {
  var s = $('tipus');
 	//console.log("frissítem a selectet: " + options[0]);
 	s.options.length = 0;
 	s.disabled = true;
  return;
 }
 new Ajax.Request('http://www.porzsakcentrum.hu/ajax.php', {
  method: 'get',
  parameters: 'tipus=porszivotipus&c=' + gyarto + '&t=' + tipus, 
		onComplete: valasztFeldolgoz
});
}

function valasztFeldolgoz(_valasz) {
 _valasz = _valasz.responseText.split("\n"); 
 //console.log(_valasz);
 valasz = new Array();
 for(i=1; i<_valasz.length; i++) {
			valasz[i-1] = _valasz[i].split("\t");
		}
		updateSelect(valasz);
  //console.log(valasz); 
}

function updateSelect(options) {
 var s = $('tipus');
	//console.log("frissítem a selectet: " + options[0]);
	s.options.length = 0;
	s.options[0] = new Option("-----");
	s.options[0].value = "";
	s.options[0].selected = true;
	//console.log("válaszlehetőségeket hozzáadom...");
	for(i=0; i<options.length; i++) {
	 //console.log(i + ". option start!");
	 s.options[i+1] = new Option(options[i][1]);
		s.options[i+1].value = options[i][0];
		if(options[i][0] == c1) {
		 //console.log("teszt 2");
   s.options[i+1].selected = true;
  }
  //console.log(i + ". option kész!");
	}
	s.disabled = false;
}

function ajanlo(form) {
 elem = form.getElementsByTagName("input");
 for(i=0;i<elem.length;i++) {
  a = elem[i];
  if(a.type=="text" && a.value.replace(/\s/g, "")=="") {
   alert("Minden mezőt ki kell tölteni!");
   a.focus();
   return false;
  }
  //console.log(elem[i].name + " - " + elem[i].type +" - " + elem[i].value);
 }
 elem = form.getElementsByTagName("textarea");
 for(i=0;i<elem.length;i++) {
  a = elem[i];
  if(a.value.replace(/\s/g, "")=="") {
   alert("Minden mezőt ki kell tölteni!");
   a.focus();
   return false;
  }
  //console.log(elem[i].name + " - " + elem[i].type +" - " + elem[i].value);
 }
 return true;
}

function menu(id) {
 if(document.getElementById('karcher_menu_' + id).style.display != "none") {
  document.getElementById('karcher_menu_' + id).style.display = "none";
  document.getElementById('karcher_pm_' + id).innerHTML = "+";
 }
 else {
  document.getElementById('karcher_menu_' + id).style.display = "block";
  document.getElementById('karcher_pm_' + id).innerHTML = "&minus;";
 }
}

function kosar_db_novel(id) {
 $("csokkent_" + id).value = 0;
 $("darab_" + id).submit();
}

function kosar_db_csokkent(id) {
 $("csokkent_" + id).value = 1;
 $("darab_" + id).submit();
}

function ful(aktivFul) {
 var fulek = new Array("leiras", "kapcsolodoTermekek", "csomagok", "ertekeles", "ajanlo");
 for(i=0;i<fulek.length;i++) {
  if($(fulek[i]) != undefined) {
   $(fulek[i]).style.display = "none";
   $("ful_" + fulek[i]).className = "";
  }
 }
 $(aktivFul).style.display = "block";
 $("ful_" + aktivFul).className = "aktiv";
}
