var FlashObject = function(swf, id, a, w, h, ver, c) {
	this.swf = swf;
	this.id = id;
	this.width = w;
	this.height = h;
	this.version = ver;
	if (a) this.align = a;

	this.params = new Object();
	this.variables = new Object();
	this.escapeString = true;

	this.redirect = "";
	this.sq = document.location.search.split("?")[1] || "";
	//this.bypassTxt = "<p>Already have Macromedia Flash Player? <a href='?detectflash=false&"+ this.sq +"'>Click here if you have Flash Player "+ this.version +" installed</a>.</p>";
	this.bypassTxt = '';

	if (c) this.color = this.addParam('bgcolor', c);
	this.addParam('quality', 'best'); // default to high
	this.doDetect = getQueryParamValue('detectflash');
}
var FOP = FlashObject.prototype;
FOP.addParam = function(name, value) { this.params[name] = value; }
FOP.getParams = function() { return this.params; }
FOP.getParam = function(name) { return this.params[name]; }
FOP.addVariable = function(name, value) { this.variables[name] = value; }
FOP.getVariable = function(name) { return this.variables[name]; }
FOP.setEscape = function( boolValue ) { this.escapeString = boolValue; }
FOP.getVariables = function() { return this.variables; }
FOP.getParamTags = function() {
    var paramTags = "";
    for (var param in this.getParams()) {
        paramTags += '<param name="' + param + '" value="' + this.getParam(param) + '" />';
    }
    return (paramTags == "") ? false:paramTags;
}
FOP.getHTML = function() {
    var flashHTML = "";
    if (navigator.plugins && navigator.mimeTypes.length) { // netscape plugin architecture
        flashHTML += '<embed type="application/x-shockwave-flash" src="' + this.swf + '" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" name="' + this.id + '" align="' + this.align + '"';
        for (var param in this.getParams()) {
            flashHTML += ' ' + param + '="' + this.getParam(param) + '"';
        }
        if (this.getVariablePairs()) {
            flashHTML += ' flashVars="' + this.getVariablePairs() + '"';
        }
        flashHTML += '></embed>';
    } else { // PC IE
        flashHTML += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + this.width + '" height="' + this.height + '" id="' + this.id + '" name="' + this.id + '" align="' + this.align + '">';
        flashHTML += '<param name="movie" value="' + this.swf + '" />';
        if (this.getParamTags()) {
            flashHTML += this.getParamTags();
        }
        if ( this.getVariablePairs() != null) {
            flashHTML += '<param name="flashVars" value="' + this.getVariablePairs() + '" />';
        }
        flashHTML += '</object>';
    }
    return flashHTML;
}
FOP.EscapeChars = function( txtString ) {
  var theRegExp = new RegExp( '%[a-f0-9]{2}', 'gi' );
  return ( !theRegExp.test( txtString ) && this.escapeString )
    ? escape( txtString ) : txtString;
}
FOP.getVariablePairs = function() {
    var variablePairs = new Array();
    for (var name in this.getVariables()) {
    	variablePairs.push(name + "=" + this.EscapeChars(this.getVariable(name)));
    }
    return (variablePairs.length > 0) ? variablePairs.join("&"):false;
}
FOP.write = function(elementId) {
	// detectFlash( this.version ) : renvoie true si plugin flash version superieure ou egale a this.version
	if(detectFlash(this.version) || this.doDetect=='false') {
		if (typeof(elementId) != 'undefined') {
			document.getElementById(elementId).innerHTML = this.getHTML();
		} else {
			document.write(this.getHTML());
		}
	} else {
		if (this.redirect != "") {
			// ici redirection vers la page noflash :
			document.location.replace(this.redirect);
		} else if (this.altTxt) {
			// affichage message alternatif dans un element de la page ou fa�on porc :
			if (elementId) {
				document.getElementById(elementId).innerHTML = this.altTxt + this.bypassTxt;
			} else {
				document.write(this.altTxt + this.bypassTxt);
			}
		}
	}
}
// detection functions
function getFlashVersion() {
	var flashversion = 0;
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			var y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
		}
	} else {
		result = false;
			for(var i = 15; i >= 3 && result != true; i--){
				execScript('on error resume next: result = IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+i+'"))','VBScript');
				flashversion = i;
			}
	}
	return flashversion;
}
function detectFlash(ver) {	return (getFlashVersion() >= ver) ? true:false; }
// get value of query string param
function getQueryParamValue(param) {
	var q = document.location.search || document.location.href.split("#")[1];
	if (q) {
		var detectIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", detectIndex) > -1) ? q.indexOf("&", detectIndex) : q.length;
		if (q.length > 1 && detectIndex > -1) {
			return q.substring(q.indexOf("=", detectIndex)+1, endIndex);
		} else {
			return "";
		}
	}
}
// add Array.push if needed
if(Array.prototype.push == null){
	Array.prototype.push = function(item) { this[this.length] = item; return this.length; }
}


function getElementsByClassName(cl) {
	var retnode = [];
	var myclass = new RegExp("\\b" + cl + "\\b");
	var elem = document.getElementsByTagName("*");
	for (var i = 0; i < elem.length; i++) {
		var classes = elem[i].className;
		if (myclass.test(classes)) retnode.push(elem[i]);
	}
	return retnode;
}



function rollover(menu) {
	var anchorTags = document.getElementById(menu).getElementsByTagName("a");
	for (var a=0; a<anchorTags.length; a++) {
		anchorTags[a].onmouseover = function() {
			if (!this.parentNode.className) {
				this.parentNode.style.background = "url(../g/menuitem_bg.gif) right -28px no-repeat";
			}
		};
		anchorTags[a].onmouseout = function() {
			if (!this.parentNode.className) {
				this.parentNode.style.background = "url(../g/menuitem_bg.gif) right 0 no-repeat";
			}
		};
	}
}


var menuids = ["menu"];
var offset = 0;

function createSubmenu() {
	var ultags = document.getElementById(menuids).getElementsByTagName("ul");
	for (var t=0; t<ultags.length; t++) {
		ultags[t].style.top = ultags[t].parentNode.offsetHeight + offset + "px";
		ultags[t].parentNode.onmouseover = function() {
			for (var u=0; u<this.getElementsByTagName("ul").length; u++) {
				this.getElementsByTagName("ul")[u].style.visibility = "visible";
			}
		};
		ultags[t].parentNode.onmouseout = function() {
			for (var u=0; u<this.getElementsByTagName("ul").length; u++) {
				this.getElementsByTagName("ul")[u].style.visibility = "hidden";
			}
		};
	}
}

function btnsEvent() {
	var btns = getElementsByClassName("btn");
	for (var b=0; b<btns.length; b++) {
		btns[b].onmouseover = function() {
			this.className = "btn_over";
		};
		btns[b].onmouseout = function() {
			this.className = "btn";
		};
	}
}

// applications
// Ajax progres
function hideBackground() {
	var hiding_div = document.getElementById("av_body_hiding_div");
	if ((hiding_div == null) || (hiding_div == "undefined")) {
		hiding_div = document.createElement("div");
		hiding_div.setAttribute("id", "av_body_hiding_div");
		hiding_div.id = "av_body_hiding_div";
		document.body.appendChild(hiding_div);
	}
	hiding_div.style.display = "block";

	var progress_div = document.getElementById("progress_div");
	if ((progress_div == null) || (progress_div == "undefined")) {
		progress_div = document.createElement("div");
		progress_div.setAttribute("id", "progress_div");
		progress_div.id = "progress_div";
		document.body.appendChild(progress_div);
	}
	progress_div.innerHTML = "<p style=\"margin-top: 50px; text-align: center;\">Betöltés</p>";
	progress_div.style.display = "block";
}

function showBackground() {
	var hiding_div = document.getElementById("av_body_hiding_div");
	if (hiding_div != null) {
		hiding_div.style.display = "none";
	}
	var progress_div = document.getElementById("progress_div");
	if (progress_div != null) {
		progress_div.style.display = "none";
	}
}

// Ajax
var xmlHttp;

function createXmlHttpRequestObject(){
	if (xmlHttp){
		return xmlHttp;
	}
	try {
		xmlHttp = new XMLHttpRequest();
		return xmlHttp;
	} catch(e) {
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
										"MSXML2.XMLHTTP.5.0",
										"MSXML2.XMLHTTP.4.0",
										"MSXML2.XMLHTTP.3.0",
										"MSXML2.XMLHTTP",
										"Microsoft.XMLHTTP");
		for (var i = 0; i < XmlHttpVersions.length && !xmlHttp; i++) {
			try {
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
				return xmlHttp;
			}
			catch (e) {}
		}
	}
	return null;
}

function getBranches(countyId) {
	xmlHttp = createXmlHttpRequestObject();
	if (xmlHttp) {
		var uri = "countyId=" + encodeURIComponent(countyId);
		try {
			if ((xmlHttp.readyState == 4) || (xmlHttp.readyState == 0)) {
				xmlHttp.open("POST", "../public/branches.html", true);
				xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
				xmlHttp.onreadystatechange = onGetBranches;
				xmlHttp.send(uri);
				hideBackground();
			}
		}
		catch (e) {}
	}
}

function onGetBranches(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			try {
				document.getElementById("branches").innerHTML = xmlHttp.responseText;
				showBackground();
			}
			catch (e) {}
		}
	}
}

function getCustomerServices(countyId) {
	xmlHttp = createXmlHttpRequestObject();
	if (xmlHttp) {
		var uri = "countyId=" + encodeURIComponent(countyId);
		try {
			if ((xmlHttp.readyState == 4) || (xmlHttp.readyState == 0)) {
				xmlHttp.open("POST", "../public/customer_services.html", true);
				xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
				xmlHttp.onreadystatechange = onGetBranches;
				xmlHttp.send(uri);
				hideBackground();
			}
		}
		catch (e) {}
	}
}

function onGetCustomerServices(){
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			try {
				document.getElementById("customer_service").innerHTML = xmlHttp.responseText;
				showBackground();
			}
			catch (e) {}
		}
	}
}

$(document).ready(function() {
	if ($("#q_email").val() == '') {
		$("#q_email").val('az Ön email címe');
	}
	if ($("#q_question").val() == '') {
		$("#q_question").val('Kérjük írja meg kérdését ...');
	}
	if ($("#q_captcha").val() == '') {
		$("#q_captcha").val('Írja be az ellenőrző kódot!');
	}


	$("#q_email").focus(function() {
		if ($("#q_email").val() == 'az Ön email címe') {
			$("#q_email").val('');
		}
	});
	$("#q_email").blur(function() {
		if ($("#q_email").val() == '') {
			$("#q_email").val('az Ön email címe');
		}
	});
	$("#q_captcha").focus(function() {
		if ($("#q_captcha").val() == 'Írja be az ellenőrző kódot!') {
			$("#q_captcha").val('');
		}
	});
	$("#q_captcha").blur(function() {
		if ($("#q_captcha").val() == '') {
			$("#q_captcha").val('Írja be az ellenőrző kódot!');
		}
	});
	$("#q_question").focus(function() {
		if ($("#q_question").val() == 'Kérjük írja meg kérdését ...') {
			$("#q_question").val('');
		}
	});
	$("#q_question").blur(function() {
		if ($("#q_question").val() == '') {
			$("#q_question").val('Kérjük írja meg kérdését ...');
		}
	});
	$("#n_email").focus(function() {
		if ($("#n_email").val() == 'az Ön email címe') {
			$("#n_email").val('');
		}
	});
	$("#n_email").blur(function() {
		if ($("#n_email").val() == '') {
			$("#n_email").val('az Ön email címe');
		}
	});

	var content_height = $("#content").height();
	var left_height = $("#leftColumn").height();
	var middle_height = $("#middleColumn").height();
	var right_height = $("#rightColumn").height();

	$("#leftColumn").css("background-position", '4px ' + left_height + 'px');
	if (left_height < content_height) {
		$("#leftColumn").css("height", (content_height - 5) + 'px');
	}

	$("#rightColumn").css("background-position", '4px ' + right_height + 'px');
	if (right_height < content_height) {
		$("#rightColumn").css("height", (content_height - 5) + 'px');
	}

	$("#n_submit").click(function() {
		$('#hld').submit();
	});

	$("#t_submit").click(function() {
		$('#tkd').submit();
	});

	if ($.browser.msie) {
		var settings = {
			tl: { radius: 10 },
			tr: { radius: 10 },
			bl: { radius: 10 },
			br: { radius: 10 },
			antiAlias: true
		}
		curvyCorners(settings, ".highlight_box");
	}
});
