//a ready túl késő néha
cookieHandler();
setupBanners();

//popup
function apopup(obj,w,h)
{
//        window.open(obj.href, 'bizhupopup', 'width=620,height=600');
        window.open(obj.href, 'bizhupopup', 'width='+w+',height='+h+'');

	return false;
}




// tartalomban lévő <h2> elemekből generál egy listát
function gen_toc() {

	if( location.pathname.match(/Casco-biztositas\/?$/i) )
	{
		return false;
	}

	if( location.pathname.match(/Lakasbiztositas\/?$/i) )
	{
		return false;
	}

	if( location.pathname.match(/Utasbiztositas\/?$/i) )
	{
		return false;
	}

	if( location.pathname.match(/Kotelezo-biztositas\/?$/i) )
	{
		return false;
	}

	
	var h2s = {};
//	var toc = "<ul class=\"menulevel2 ontheflytoc\">";
	var toc = "<ul class=\"ontheflytoc\">";
	if (document.getElementById("submenu")) {
		origtoc = document.getElementById("submenu").innerHTML;
		origtoc = origtoc.replace("<ul>","").replace("</ul>","");
		toc=toc+origtoc;
	}
	h2s = document.getElementById("content").getElementsByTagName("h2");
	for (var i = 0; i < h2s.length; i++) {
		var h2 = h2s[i];
		h2.id = "toc" + i;
		toc += "<li><a href=\"#" + h2.id + "\">" + h2.innerHTML + "</a></li>";
	}
	toc += "</ul>";
	if (document.getElementById("submenu")) {
		document.getElementById("submenu").innerHTML = toc;
	}
}




//felső menü hátterét kifehérítő függvény

function setSticked(){
	el=document.getElementById('sticked_online_biztositas_kotes');
	if ( el ) {
		if( location.pathname == "/" )
		{
			el.setAttribute("class","sdoc");el.className = "sdoc";
			return true;
		}
		
		if( location.pathname.match(/^\/(Partner\/)?Casco-biztositas/i) )
		{
			 el.setAttribute("class","sdoc");el.className = "sdoc";
			 return true;
		}
		
		if( location.pathname.match(/^\/(Partner\/)?Kotelezo-biztositas/i) )
		{
			el.setAttribute("class","sdoc");el.className = "sdoc";
			return true;
		}
		
		if( location.pathname.match(/^\/(Partner\/)?Utasbiztositas/i) )
		{
			el.setAttribute("class","sdoc");el.className = "sdoc";
			return true;
		}
		
		if( location.pathname.match(/^\/(Partner\/)?Lakasbiztositas/i) )
		{
			el.setAttribute("class","sdoc");el.className = "sdoc";
			return true;
		}
		
		if( location.pathname.match(/^\/(Partner\/)?Jovedelemkieses-biztositas/i) )
		{
			el.setAttribute("class","sdoc");el.className = "sdoc";
			return true;
		}
	}
	
	el=document.getElementById('sticked_hirek-informaciok');
	if ( el ) {
		if( location.pathname.match(/^\/(Partner\/)?Hirek-Informaciok/i) )
		{
			el.setAttribute("class","sdoc");el.className = "sdoc";
			return true;
		}
	}
	
	el=document.getElementById('sticked_sajat_mappa');
	if ( el ) {
		if( location.pathname.match(/^\/(Partner\/)?Online-biztositas-kotes/i) )
		{
			el.setAttribute("class","sdoc_long");el.className = "sdoc_long";
			return true;
		}
	}
	
	el=document.getElementById('sticked_tudasbazis');
	if ( el ) {
		if( location.pathname.match(/^\/(Partner\/)?Tudasbazis/i) )
		{
			el.setAttribute("class","sdoc");
			el.className = "sdoc";
			return true;
		}
	}
	
	
	return false;
}


function loadcounter() {
    if (location.host == "www.biztositas.hu" ||
        location.host == "static.biztositas.hu") {
        return "<p id=\"szamlalo\"><img src=\"http://partner.biztositas.hu/public/cikkkepek/counter1.png\" alt=\"\" /></p>";
    }
    return "";
}



//sidebar magasságállító script segédfüggvény
function getDim (id) {
	
	var doc_element =  document.getElementById(id);
	
	if(doc_element){
		doc_element.style.height="auto";
		// match box models
		var h;
		if (document.all) {
			h = doc_element.offsetHeight+10;
		}
		else {
			h = doc_element.offsetHeight;
		}
		return h;
	}else{
		return null;
	}
}



//bal sidebar magasságot állító függvény
function setSideBar()
{
  var ch;
  var lh = getDim("logo");
  var mh = getDim("menubar");
  
  if( lh == null && mh == null ){
	  return false;
  }
  
  if( document.getElementById("content-container") )
  {
	ch = getDim("content-container");
  }

  if( document.getElementById("content-container-wide") )
  {
	ch = getDim("content-container-wide");
  }
  
  if( document.getElementById("rightbar") )
  {
	rh = getDim("rightbar");
	
	if(rh  > ch)
	{
		ch = rh;
	}
  }
  
  
  if(ch > lh + mh + 500)
  {
	document.getElementById("sidebar").style.height = ch + "px";
  }

  return true;
}



//copy régi oldalból

function setCookie(name, value) {
    var curCookie = name + "=" + escape(value) + ";path=/;domain=biztositas.hu";
    document.cookie = curCookie;
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) {
            return null;
        }
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function cookieHandler() {
	var redirect = false;
	var args = location.href.split(/\?/);
	if ((typeof forcePromo == 'undefined') || (forcePromo == null) || (forcePromo == "")) {
		forcePromo = "bizt_hu";
	}
        if (args.length > 1) {
		var params = args[1].split(/\&/);
		
		for (var i = 0; i < params.length; i++) {
			var param = params[i].split(/=/);
			//promo code
			if (getCookie("bizt-hu-promo_kod") == null) {
				if ("promo_kod" == param[0]) {
					if (param.length > 1 && "" != param[1]) {
						setCookie("bizt-hu-promo_kod", param[1]);
					} else {
						setCookie("bizt-hu-promo_kod", forcePromo);
					}
				}
			}
			
			//advertbox parameters
			var sKeyStart=param[0].substring(0,5);
			if (sKeyStart=="param"){
				if (param.length > 1 && "" != param[1]) {
					setCookie(param[0], param[1]);
				}
			} else if (sKeyStart=="PARAM"){
				if (param.length > 1 && "" != param[1]) {
					setCookie(param[0].substring(5), param[1]);
					redirect = true;
				}
			}
		}
	}
	if (getCookie("bizt-hu-promo_kod") == null) {
		setCookie("bizt-hu-promo_kod", forcePromo);
	}
	if (redirect) {
		location.href = args[0];
	}
}


function deleteCookie(cookie_name) {
    if (getCookie(cookie_name) != null) {
        var cookie_date = new Date;
        cookie_date.setTime(cookie_date.getTime() - 1);
        document.cookie = cookie_name += "=;path=/;domain=biztositas.hu; expires=" + cookie_date.toGMTString();
    }
}

function setLogoutBox() {
    var login_name = getCookie("logged-user-name");
    var login_name_element = document.getElementById("login-name");
    var login_box_element = document.getElementById("login-box");
    
    if (login_name != null) {
        login_name = login_name.substring(0, 10);
        
	if(login_name_element)
	{
		login_name_element.innerHTML = login_name;
        }
	if(login_box_element)
	{
		login_box_element.style.visibility = "visible";
	}
    } else {
	if(login_box_element)
	{
		login_box_element.style.visibility = "hidden";
	}
    }
}

function doLogout() {
    deleteCookie("logged-user-name");
    deleteCookie("biztositasSID", 0);
    var protocol = document.location.protocol;
    var host = document.location.host;
    document.location.href = protocol + "//" + host + "/Partner/Online-biztositas-kotes/Sajat-mappa.html";
}


function doSearch(phrase)
{

	$.post('/search.php',{word: phrase},function(data){
	
		$("#content").html(data);
		window.scrollTo(0,0);
	        setSideBar();

	});//post

}

function loadstats()
{
    var stat_div = document.getElementById("median-stat");
	if ( stat_div ){
		stat_div.innerHTML = "<!-- Medián WebAudit biztositas.hu 1/2 --><img alt=\"\" src=\"http://audit.median.hu/cgi-bin/track.cgi?uc=11607335456119&amp;dc=1&amp;ui=" + same + " width=\"1\" height=\"1\" />";
	}
}




var current_utaskotes_image_id = 0;

var utaskotes_image_files = new Array();
utaskotes_image_files[0] = "hagyomanyos.jpg";
utaskotes_image_files[1] = "hagyomanyos.jpg";
utaskotes_image_files[2] = "si.jpg";
utaskotes_image_files[3] = "buvar.jpg";
utaskotes_image_files[4] = "tura.jpg";
utaskotes_image_files[5] = "tura.jpg";

function preload_utaskotes_images()
{
	if( document.getElementById("utaskotesleftimage") )
	{
		
		var imgs = new Array();
		var x;
		for( x in utaskotes_image_files )
		{
			var tmpimg = new Image();
			tmpimg.src = "/themes/bizthublue/images/utas/" + utaskotes_image_files[x];
		}
	}
}



function set_utaskotes_image()
{
	
	var current_image;
	current_image = getCookie("c_type_of_travel");
	
	if(current_image != null)
	{
		if( current_utaskotes_image_id != current_image)
		{
			if( utaskotes_image_files[current_utaskotes_image_id] != undefined )
			{
				current_utaskotes_image_id = current_image;
				if (document.getElementById("utaskotesleftimage")) {
					document.getElementById("utaskotesleftimage").src = "/themes/bizthublue/images/utas/" + utaskotes_image_files[current_utaskotes_image_id];
				}
			} else {
				if (document.getElementById("utaskotesleftimage")) {
					document.getElementById("utaskotesleftimage").src = "/themes/bizthublue/images/utas/" + utaskotes_image_files[0];
				}
			}
		}
	}
}

//ez gyakorlatilag onload jellegű jQuery dolog
$(document).ready(function(){
setSticked()
gen_toc();
setSideBar();
//cookieHandler();
loadstats();
//setupBanners();

$("#biztositas-search-button").click(function(){

	var word = document.getElementById('biztositas-search-field').value;
	doSearch(word);
	
	
	preload_utaskotes_images();

});

setVariant();
});//ready




function popup_info(url,xsize,ysize) {
	popupablak = window.open(url,'poppauppa_info','toolbar=no,location=no,directories=no,status=no,menubar=no,scrolling=0,scrollbars=1,resizable=no,alwaysRaised=1,width='+xsize+',height='+ysize);
	popupablak.focus();
	if ( document.getElementById('jovedelem_dijszamitogif_div') ) {
		document.getElementById('jovedelem_dijszamitogif').src = '/files/button_ani2.gif';//style="margin-left:300px;" href="/Partner/Jovedelemkieses-biztositas/Dijszamitas-kotes.html"><img src="/files/button_ani2.gif" border="0" alt="Díjszámítás, kötés"></img></a>
	}
}
//window.setTimeout("alert(document.getElementById('rightbar').style.width);",1);
//window.setTimeout("document.getElementById('rightbar').style.width='0px';",1);

function setVariant() {
	var agent_code = null;
	agent_code = getCookie('process_agent');
	agent_name = getCookie('process_agent_name');
	agent_logo = getCookie('process_agent_logo');
	if ( agent_code != null ) {
		//if ( agent_code.search('candi') != -1 ) {

		var variant_div = document.getElementById('variant_div');
		var variant_name_div = document.getElementById('variant_name_div');
		var variant_logo_img = document.getElementById('variant_logo_img');

			if ( variant_div && variant_name_div && variant_logo_img) {
				$("div").data(agent_code, agent_name.replace(/\+/g," "));

				variant_div.style.display = 'block';
				variant_name_div.innerHTML = $("div").data(agent_code);
				variant_logo_img.src = agent_logo;
				//$('#variant_logo_img').attr("src",agent_logo);
			}
		//}
	}
}



function call_user_func(cb) {
 
    var func;
    func = this[cb];
    return func.apply(null, Array.prototype.slice.call(arguments, 1));
}


function setupBanners() {
	var iNow = (new Date()).getTime();
	//<bannerdata>
	// ha az érték null, akkor le van tiltva
	
	aBanners = new Array(
//		new Array(
//			'<scr'+'ipt src="http://hugde.adocean.pl/_'+iNow+'/ad.js?id=_EFWAF6fQhI2JU.O1BWSAoFWw9xXa9KBNlBp694Rs6..R7" language="javascr'+'ipt"></scr'+'ipt>',
//			'<scr'+'ipt src="http://hugde.adocean.pl/_'+iNow+'/ad.js?id=RbNGji.64jf.lnBUNCpYnIlKDdTwe6e0v8BPefMSaKv.B7" language="javascr'+'ipt"></scr'+'ipt>',
//			'<scr'+'ipt src="http://hugde.adocean.pl/_'+iNow+'/ad.js?id=TBBHSOBChwuV8TES7QgoYISd8SxSo2cvDDEqRIKDHKP.47" language="javascr'+'ipt"></scr'+'ipt>'),
//		new Array("TGD9647_634x100.swf","TGD9647_120x240.swf","TGD9647_140x360.swf")
	);
	// URL-ek - csak nem flashnél - ha az érték null, akkor nincs belinkelve
	aUrls = new Array(
//		'/Tudasbazis/Biztositok/AXA.html',
//		'/Tudasbazis/Biztositok/AIG.html'
	);
	// Flash méret paraméterek - ha valamelyik érték null, az a banner le van tiltva,
	aParams = new Array(
//		new Array(1,1,1),
//		new Array('width="634" height="100"','width="120" height="240"', 'width="140" height="360"')
	);
	//</bannerdata>
	
	// aktuális banner kiválasztása
	iCurrentBanner = getCookie("current_banner");
	if ((iCurrentBanner==null) || (iCurrentBanner>aBanners.length)) {
		iCurrentBanner = Math.floor(Math.random() * aBanners.length);
		setCookie('current_banner',iCurrentBanner);
	}
}

function loadBanner(iId) {
	iId = iId-1;
	if (aBanners[iCurrentBanner]==null) return "";
	var sBanner = aBanners[iCurrentBanner][iId];
	if (sBanner.substr(sBanner.length-4)==".swf") { //Flash
		if (aParams[iCurrentBanner][iId]!=null) {
			return "<embed src=\"/files/banners/"+sBanner+"\" "+aParams[iCurrentBanner][iId]+" allowscriptaccess=\"always\" allowfullscreen=\"false\" />" +"<div align=\"right\" style=\"margin-top: 4px\"><img src=\"/files/hirdetes.png\" width=\"99\" height=\"20\" alt=\"Hirdetés\"></div>";
		}
	} else if (sBanner.substr(sBanner.length-4)==".jpg") { // JPEG
		var sHtml = "";
		if (sBanner != null) {
			sHtml = "<img src=\"/files/banners/"+sBanner+"\" border=\"0\" alt=\"A részletekért katt ide!\">";
			if (aUrls[iCurrentBanner]!=null) {
				sHtml = "<a href=\"javascript:void()\" onClick=\"window.open('"+aUrls[iCurrentBanner]+"','bannerinfo','width=400,height=400'); return false;\">"+sHtml+"</a>";
			}
			return sHtml+"<div align=\"right\" style=\"margin-top: 4px\"><img src=\"/files/hirdetes.png\" width=\"99\" height=\"20\" alt=\"Hirdetés\"></div>";
		}
	} else {
		if (sBanner!=null) { // JS
			return sBanner +"<div align=\"right\" style=\"margin-top: 4px\"><img src=\"/files/hirdetes.png\" width=\"99\" height=\"20\" alt=\"Hirdetés\"></div>";
		}
	}
}

function PopupCenter() {
	w=400;
	h=400;
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open ("http://www.biztositas.hu/Tudasbazis/Biztositok/AIG.html", "myPop1", 'toolbar=no, location=no, addressbar=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
