var NS4 = (document.layers)? 1 : 0;
var IE4 = (document.all)? 1 : 0;
var W3C = (document.getElementById)? 1 : 0;
var currentmenu = new Array();
var timerId;
var cGyik = "";
var cGyikKat = "";
var cTermek = "";
var masol = 0; 

function fSendPassword(){
	var stremail = new String(fGetObject("uemail").value);
	if(stremail == ""){
		alert(szotar[20][lang]);
		return false;
	}
	
	if(stremail.indexOf("@") == -1 || stremail.indexOf(".") == -1){
		alert(szotar[21][lang]);
		return false;
	}
	
	document.location = "../do.php?type=sendnewpassword&pemail="+stremail;
}

function fCheckBrowser(){
	if(BrowserDetect.browser == "Explorer" && BrowserDetect.version != 7){
		var answer = confirm(szotar[19][lang]);
		if (answer){	
			popUpWindow = window.open ("http://www.microsoft.com/hun/windows/ie/downloads/default.mspx", "popUpWindow","location=1,status=1,scrollbars=1, width=1024,height=400");
			popUpWindow.moveTo(0,0);
		}	
	}
}

function fGetObject(obj_name){
	if(W3C)
		return document.getElementById(obj_name);
	else if(NS4)
		return document.layers[obj_name];
	else
		return window.opener.document.all[obj_name];
}

function fIsNum(tmp){
	var szam = new String(tmp);
	var jok = new String("0123456789");
	for(k=0; k<szam.length; k++){
		if(jok.indexOf(szam.charAt(k)) == -1)
			return false;
	}
	return true;
}

function fOver(tmp){
	fGetObject("fejlec_1").style.display = "none";
	fGetObject("fejlec_2").style.display = "block";
	if(currentmenu[0]){
		currentmenu[0].style.display = "none";
		currentmenu[1].style.display = "none";
		clearTimeout(timerId);
	}
		
	currentmenu[0] = fGetObject("al"+tmp);
	currentmenu[1] = fGetObject("al"+tmp+"_bg");
	
	tmp = getAnchorPosition(tmp+"_x");
	currentmenu[0].style.left = tmp.x;
	currentmenu[1].style.left = tmp.x;
	
	currentmenu[0].style.display = "block";
	currentmenu[1].style.display = "block";
}

function fOut(tmp){
	timerId = setTimeout("fHideSubMenu()", 500)
}

function fHideSubMenu(){
	currentmenu[0].style.display = "none";
	currentmenu[1].style.display = "none";
	currentmenu[0] = null;
	currentmenu[1] = null;
	fGetObject("fejlec_2").style.display = "none";
	fGetObject("fejlec_1").style.display = "block";	
	clearTimeout(timerId);
}

// getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
	
function fClickGyik(name, count){
	if(name == cGyik){
		fGetObject(name).style.display = "none";
		cGyik = "";
	}else{
		for(k=1;k<=count;k++)
			fGetObject("gyik_"+String(k)).style.display = "none";
		
		fGetObject(name).style.display = "block";
		cGyik = name;
	}
}

function fClickGyikKat(name, count){
	if(name == cGyikKat){
		fGetObject(name).style.display = "none";
		cGyikKat = "";
	}else{
		for(k=1;k<=count;k++)
			fGetObject("kat_"+String(k)).style.display = "none";
		
		fGetObject(name).style.display = "block";
		cGyikKat = name;
	}
}

function fClickTermek(name, count){
	if(name == cTermek){
		fGetObject(name + "_2").style.display = "none";
		fGetObject(name + "_1").style.display = "block";
		cTermek = "";
	}else{
		for(k=1;k<=count;k++){
			fGetObject("ter_"+String(k) + "_2").style.display = "none";
			fGetObject("ter_"+String(k) + "_1").style.display = "block";
		}
		fGetObject(name + "_1").style.display = "none";
		fGetObject(name + "_2").style.display = "block";
		cTermek = name;
	}
}

function fCheckBelep(){
	if(document.sform.uemail.value == ""){
		alert(szotar[4][lang]);
		return false;
	}
	if(document.sform.upass.value == ""){
		alert(szotar[5][lang]);
		return false;
	}
	
	return true;
}

function fCheckSzemelyes(){
	if(document.sform.email.value == ""){
		alert(szotar[4][lang]);
		return false;
	}
	
	if(document.sform.cid.value == "-1"){
		if(document.sform.jelszo.value == ""){
			alert(szotar[5][lang]);
			return false;
		}
		if(document.sform.jelszo2.value == ""){
			alert(szotar[6][lang]);
			return false;
		}
	}
	if(document.sform.jelszo.value != document.sform.jelszo2.value){
		alert(szotar[7][lang]);
		document.sform.jelszo2.value = "";
		return false;
	}
	if(document.sform.vezeteknev.value == ""){
		alert(szotar[8][lang]);
		return false;
	}
	if(document.sform.keresztnev.value == ""){
		alert(szotar[9][lang]);
		return false;
	}
	if(document.sform.telefon.value == ""){
		alert(szotar[10][lang]);
		return false;
	}
	if(document.sform.szallit_nev.value == ""){
		alert(szotar[11][lang]);
		return false;
	}
	if(document.sform.szallit_uh.value == ""){
		alert(szotar[12][lang]);
		return false;
	}
	if(document.sform.szallit_ir.value == ""){
		alert(szotar[13][lang]);
		return false;
	}
	if(document.sform.szallit_varos.value == ""){
		alert(szotar[14][lang]);
		return false;
	}
	
	if(document.sform.szamla_nev.value == ""){
		alert(szotar[15][lang]);
		return false;
	}
	if(document.sform.szamla_uh.value == ""){
		alert(szotar[16][lang]);
		return false;
	}
	if(document.sform.szamla_ir.value == ""){
		alert(szotar[17][lang]);
		return false;
	}
	if(document.sform.szamla_varos.value == ""){
		alert(szotar[18][lang]);
		return false;
	}
	
	return true;
}

function fMezoMasol(obj){
	if(masol == 1){
		var tmp = new String(obj.id);
		fGetObject("szamla_" + tmp.substr(tmp.indexOf("_")+1)).value = obj.value;
	}
}

function fMezoMasol2(obj){
	if(masol == 1){
		var tmp = new String(obj.id);
		fGetObject("szallit_" + tmp.substr(tmp.indexOf("_")+1)).value = obj.value;
	}
}

function fMasol(obj){
	if(masol == 0){
		masol = 1;
		fGetObject("szamla_nev").value = fGetObject("szallit_nev").value
		fGetObject("szamla_uh").value = fGetObject("szallit_uh").value
		fGetObject("szamla_ir").value = fGetObject("szallit_ir").value
		fGetObject("szamla_varos").value = fGetObject("szallit_varos").value
	}else
		masol = 0;
}

function fBalMenu(obj, pclass){
	obj.className = pclass;
}

function fPrint(nr){
	win = window.open('../print.php?nr='+nr, 'auroprint', 'toolbar=1,location=0,status=0,menubar=1,scrollbars=1,resizable=0, width=740,height=700');
	win.focus();
}

function fShowResult(pid){
	szelesseg = screen.width - 7;
	magassag = document.body.clientHeight;	
	
	win = window.open('../talalat.php?pid='+pid+'&search='+fGetObject("search").value, 'aurosearch', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=0, width='+szelesseg+',height='+magassag);
	win.focus();
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();