/* facebook style popup */

function helper(Hkod) {
	
  popup.create("H"+Hkod, 520, "H"+Hkod, Hkod, 1, 154);
  $('html, body').animate({scrollTop: $("#mainPageTitle").offset().top }, 500);
}

function pop(iid) {
  popup.create('p'+iid, 520, "p"+iid, iid, 1, 154);
}
 

var popup = { 
  pop_id : null,

	  create : function(id, width, ajaxname, callback, center, height) {
		    if (!id || !width || !ajaxname) return false;
		    if (document.getElementById(id)) return false;

		    popup.pop_id = id;
		    var top = 125;
		    if (center && height) {
		      if(typeof(window.innerWidth) == 'number') {
		        //nem IE
		        maxx = window.innerWidth;
		        maxy = window.innerHeight;
		      } else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		      //IE 6+ es mas ujabb bongeszok
		        maxx = document.documentElement.clientWidth;
		        maxy = document.documentElement.clientHeight;
		      } else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		        //IE 4 kompatibilis
		        maxx = document.body.clientWidth;
		        maxy = document.body.clientHeight;
		      }
		      //top = Math.round(maxy/2)-Math.round(height/2)-100;
		      top = 100;
		    }
		    var content = '<div class="generic_dialog_popup" style="top: '+top+'px;">'+
		    '<table class="pop_dialog_table" id="pop_dialog_table" style="width:'+width+'px;">'+
		    '<tbody>'+
		    '<tr>'+
		    '<td class="pop_topleft"/>'+
		    '<td class="pop_border pop_top"/>'+
		    '<td class="pop_topright"/>'+
		    '</tr>'+

		    '<tr>'+
		    '<td class="pop_border pop_side"/>'+
		      '<td id="pop_content" class="pop_content">'+
		      '</td>'+
		    '<td class="pop_border pop_side"/>'+
		    '</tr>'+

		    '<tr>'+
		    '<td class="pop_bottomleft"/>'+
		    '<td class="pop_border pop_bottom"/>'+
		    '<td class="pop_bottomright"/>'+
		    '</tr>'+

		    '</tbody>'+
		    '</table>'+
		    '</div>';

		    var pop_node = document.createElement('div');
		    pop_node.id = id;
		    pop_node.className = 'generic_dialog';
		    pop_node.innerHTML = content;

		    var body_node = document.body.childNodes[0];
		    body_node.parentNode.insertBefore(pop_node, body_node);

		    var target = document.getElementById('pop_content');
		    //target.innerHTML = document.getElementById(callback).innerHTML;
		    target.innerHTML = $('#'+callback).html();
		    // preload
		    //var newimg = new Image;
		    //newimg.src = "styles/retro/g_mehet.gif";
		    //var newimg2 = new Image;
		    //newimg2.src = "styles/retro/g_megse.gif";
		    //$('#pop_content').load('http://192.168.111.2:8080/ugyfelszolgalat/ajax/help/H_CONF_NP_F3/');
		    //$('#pop_content').slideDown("slow");
		    
		    //ajax.get("http://192.168.111.2:8080/ugyfelszolgalat/ajax/help/H_CONF_NP_F3/", function(response){
			
			//target.innerHTML = "";
		      //var newdiv = document.createElement('div');
		      //newdiv.innerHTML = response;
		      //target.appendChild(newdiv);
		      //document.getElementById('pop_dialog_table').style.width=width+"px";
		      //if (callback) eval(callback);
		    //});

		    var d = document;
		    if(d.addEventListener) d.addEventListener('keydown', popup.over, true);
		    else if(d.attachEvent){
		      d=(d.documentElement.clientHeight)? d.documentElement: d.body;
		      d.attachEvent('onkeypress', popup.over);
		    }
		  },

  over : function(e){
    if(!e) e=window.event;
    var key = e.keyCode ? e.keyCode : e.which;
    if(key == "27") {
      popup.close();
    }
  },

  close : function(quick) {
    // removeolni az eventet!
    var d = document;
    if(d.removeEventListener) d.removeEventListener('keydown', popup.over, true);
    else if(d.detachEvent){
      d=(d.documentElement.clientHeight)? d.documentElement: d.body;
      d.detachEvent('onkeypress', popup.over);
    }
    var obj = document.getElementById(popup.pop_id);
    if (quick) {
      obj.parentNode.removeChild(obj);
    } else {
      popup.fadeOut(popup.pop_id, 100);
    }
  },

  fadeOut : function(objId, opacity) {
    if (document.getElementById) {
      obj = document.getElementById(objId);
      if (opacity > 0) {
        popup.setOpacity(obj, opacity);
        opacity -= 10;
        window.setTimeout("popup.fadeOut('"+objId+"',"+opacity+")", 40);
      } else {
        obj.parentNode.removeChild(obj);
      }
    }
  },

  setOpacity : function(obj, opacity) {
    // alert(opacity+"\n"+obj.style.opacity);
    opacity = (opacity == 100)?99.999:opacity;
    // exporer
    obj.style.filter = "alpha(opacity = "+opacity+")";
    // obj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+opacity+")";
    // webkit
    obj.style.KHTMLOpacity = opacity/100;
    // mozilla,firefox
    obj.style.MozOpacity = opacity/100;
    // uj webkit, moz, firefox
    obj.style.opacity = opacity/100;
    // alert(opacity+"\n"+obj.style.opacity+"\n"+obj.style.filter);
  }
};



function ch_irsz(s, d){
	// s - irányítószám
	// d - város
	var vissza= false;
	
	if (dest=document.getElementById(d)){
		// Több, mint 4 karakter az ir.szám, akkor levágja a végét!
		if (s.value.length>4) {
			s.value= s.value.substring(0, 4);
		}
		if (irsz[s.value]){
			dest.value=irsz[s.value];
		}else{
			dest.value='';
		}
		vissza= true;
	}
	return vissza;
}

function only_numeric(tar){
	tar.value=tar.value.replace(/[^0-9]/g, '');
}

function kamat_szamol() {
/*	
	fi = $('#futamido_id').val();
	tt_elo = $('#id_egyenleg').val();
	//le kell szedni a commat
	tt = tt_elo.replace(/\ /g,'');
	tt = tt * -1;
	$('#rf_error_id').text('');
	//szamitas regi
	//tr = tt/fi + (tt*0.085/12);
	
	tr = tt/fi 
	tk = tt*0.085/12*fi
	
	if(Math.floor(tr) >= 5000) {
		tr = tr.toFixed(2);
		$('#torlesztoreszlet').attr('value', tr);
		tk = tk.toFixed(2);
		$('#kamat').attr('value', tk);
		a = $('#torlesztoreszlet').get(0);
		k = $('#kamat').get(0);
		addCommas(a);
		addCommas(k);
		
		$('#rf_sub_id').removeAttr('disabled');
	}else {
		$('#torlesztoreszlet').attr('value', '');
		$('#kamat').attr('value', '');
		$('#rf_sub_id').attr('disabled', 'disabled');
		$('#rf_error_id').text('A törlesztőrészlet nem éri el a minimum 5 000 Ft/hó összeget. Kérjük válasszon más futamidőt!');
	}
*/
	$('#rf_error_id').text('');
	fi = $('#futamido_id').val();
	if(Math.floor(data[fi]['toke']) >= 5000) {
		tr = data[fi]['toke'];
		tr = tr.toFixed(2);
		$('#torlesztoreszlet').attr('value', tr);
		tk = data[fi]['kamat'];
		tk = tk.toFixed(2);
		$('#kamat').attr('value', tk);
		a = $('#torlesztoreszlet').get(0);
		k = $('#kamat').get(0);
		addCommas(a);
		addCommas(k);
		
		$('#rf_sub_id').removeAttr('disabled');
	}else {
		$('#torlesztoreszlet').attr('value', '');
		$('#kamat').attr('value', '');
		$('#rf_sub_id').attr('disabled', 'disabled');
		$('#rf_error_id').text('A törlesztőrészlet nem éri el a minimum 5 000 Ft/hó összeget. Kérjük válasszon más futamidőt!');
	}
	
}


$(document).ready(function() {
	$("#types").change(function () { 
		 document.fizform.submit();
	});
	
	$("#mod_gomb").click(function () { 
		$("#postinfo_id").attr("value","1");
		document.fizform.submit();
	});
	
	$("#valt_gomb").click(function () {
		 $("#postinfo_id").attr("value","2");
		 document.fizform.submit();
	});
	
	//irsz
	$("#id_szla_irsz").change(function () {
		ch_irsz(this,'id_szla_varos');
	});
	
	$("#id_szla_irsz").keyup(function () {
		only_numeric(this);
		ch_irsz(this,'id_szla_varos');
	});
	
	$("#id_bankszamla_szam_0").keyup(function () {
		only_numeric(this);
		if($(this).val().length == 8) {
			$("#id_bankszamla_szam_1").focus();
		}
	});
	
	$(".numeric").keyup(function () {
		only_numeric(this);
	});
	
	$("#id_bankszamla_szam_1").keyup(function () {
		only_numeric(this);
		if($(this).val().length == 8) {
			$("#id_bankszamla_szam_2").focus();
		}
	});
	
	$("#id_bankszamla_szam_2").keyup(function () {
		only_numeric(this);
	});
	
	$("#futamido_id").change(function () { 
		kamat_szamol();
	});
	
	$("#id_ervenyesseg_kezdete").attr("readonly", true); 
	$("#id_ervenyesseg_vege").attr("readonly", true); 
	
	
	$("#id_ervenyesseg_visszavonasig").click(function () { 
		if($("#id_ervenyesseg_visszavonasig").attr("checked") == true) {
			$("#id_ervenyesseg_vege").attr("value", "");
			$('#ervenyesseg_vege_tr_id').addClass('tr_hide');
		}
		if($("#id_ervenyesseg_visszavonasig").attr("checked") == false) {
			//megjeleniteni a datumpickert
			$('#ervenyesseg_vege_tr_id').removeClass('tr_hide');
		}
	});
	
	if($("#id_ervenyesseg_visszavonasig").attr("checked") == true) {
		$("#id_ervenyesseg_vege").attr("value", "");
		$('#ervenyesseg_vege_tr_id').addClass('tr_hide');
	}else if($("#id_ervenyesseg_visszavonasig").attr("checked") == false) {
		//megjeleniteni a datumpickert
		$('#ervenyesseg_vege_tr_id').removeClass('tr_hide');
	}
	
	//$("#tulfiz_rendelkezes").click(function () { 
	//	$('#befizetes').attr('action', '/dijfizeto/befizetesek/visszafizetes');
	//});
	
	$("#rf_sub_id").click(function () { 
		$('#befizetes').attr('action', '/ugyfelszolgalat/dijfizeto/befizetesek/reszletfizetes');
	});
	
	$("#csekk_btn").click(function () { 
		$('#befizetes').attr('action', '/ugyfelszolgalat/dijfizeto/befizetesek/csekk');
	});
	
	$("#nullas_sub_id").click(function () { 
		$('#befizetes').attr('action', '/ugyfelszolgalat/dijfizeto/befizetesek/nullasigazolas');
	});
	
	$("#szamla_radio").click(function () { 
		$('.bszamla-details').slideDown("slow");
	});
	
	$(".radio").click(function () {
		$('.bszamla-details').removeClass("checked");
		$('.bszamla-details').slideUp("slow");
	});

	
	
	if($('.open').is('.second')) {
		$('.open a.details-show').text("Részletek elrejtése");
		a = $('.open a.details-show').parent().next().get(0)
		id = $('.open a.details-show').parent().attr("id")
		if(id) {
			$(a).load('http://' + document.location.hostname + document.location.pathname + id + "/ajax/", function(){
				   
			 });
		}	
	}
	
	
	$("a.details-show").click(function () {
		a = $(this).parent().next().get(0)
		id = $(this).parent().attr("id")
      if ($(a).is(":hidden")) {
    	  //meg kell mutatni plusz kell neki egy load is
		  //bentin nem kerul bele a port, figyelj oda
		  //$(a).load('http://' + document.location.hostname + ':8080' + document.location.pathname + id + "/ajax/");
    	  $(a).load('http://' + document.location.hostname + document.location.pathname + id + "/ajax/");
        $(a).slideDown("slow");
        $(this).text("Részletek elrejtése");
      } else {
    	$('.open').removeClass("open");
        $(a).slideUp("slow");
        $(this).text("Részletek megjelenítése");
      }
    });
	
	$('.open a.details-show-velsz').text("Részletek elrejtése");
	a = $('.open a.details-show-velsz').parent().next().get(0)
	$(a).slideDown("slow");
	$("a.details-show-velsz").click(function () {
		a = $(this).parent().next().get(0)
		id = $(this).parent().attr("id")
      if ($(a).is(":hidden")) {
        $(a).slideDown("slow");
        $(this).text("Részletek elrejtése");
      } else {
    	$('.open').removeClass("open");
        $(a).slideUp("slow");
        $(this).text("Részletek megjelenítése");
      }
    });

})




