﻿var modalTimeout;
var onlineDestekTime = 1000*60*1;
    $(document).ready(function() {
        RunSeTime();
        $('.btn_randevu_al').flash({ src: '/_swf/randevu_al.swf', width: 192, height: 66, menu: false, wmode: 'transparent' }, { version: 8 });
        //$('.menu_flash').flash({ src: '/_swf/swf_menu.swf', width: 950, height: 32, menu: false, wmode: 'transparent' }, { version: 8 });
        $(".subleft-flash").flash({ src: '/_swf/danisma_hatti.swf', width: 200, height: 65, menu: false, wmode: 'transparent' }, { version: 8 });
    
        $('.hassub').hover(function() {
            $(this).find('.menuover').show();
            $('#overlay').show();
            //$('#overlay').css('height', $(window).height());
            $('#overlay').css('height', document.documentElement.clientHeight);
            
        }, function() {
            $(this).find('.menuover').hide();
            $('#overlay').hide();
        });
        
        $(".Modal-Box .modal-close a").click(function(){
         ModalClose()
        });
        
        $(".OnlineChat-Modal-Box .chat-close a").click(function(){
         OnlneChatModalClose()
        });        
        
        $(window).bind('load resize', function() {
            $('#overlay').css({ 'height': $(window).height()});
        });
        
        $(window).scroll(function() {
            $(".Modal-Box, .OnlineChat-Modal-Box").css("position","absolute");
            $(".Modal-Box, .OnlineChat-Modal-Box").css("margin-top", $(window).scrollTop()-180 + "px");
        });
        
        $('.topmenu a').hover(function() {
            $(this).addClass('tmover');
        }, function() {
            $(this).removeClass('tmover');
        });
        
        
        $('#topbar .toplink').hover(function() {
            $(this).addClass('tbarhover');
        }, function() {
            $(this).removeClass('tbarhover');
        });
        
        
        jQuery.each(jQuery.browser, function(i) {
           if(!$.browser.msie){
                $('body').css('min-height', document.documentElement.clientHeight - 25); 
                $(window).resize(function() {
                    $('body').css('min-height', document.documentElement.clientHeight - 25); 
                });
           }
         });            
         
         $("ul.bc-list li:first").css({"padding-left":"0","background":"none"});
         
        $("#btnBelgeler").click(function () {
              $("#btnBelgelerCont").toggle("slow");
        });
         $("#btnTable_01").click(function () {
              $(".TableArea_01").toggle("slow");
        });

        readRate();
        
        $('#btnHesapla_01').bind('click', function(){
            if ($('#mortgage_kredisi_miktari').val().length<=0)
            {
                alert("Lütfen Kredi Tutarı hanesini doldurunuz.");
                $('#mortgage_kredisi_miktari').focus();
            }
            else if ($('#vade_01').val() == "0") {
                alert("Lütfen Vade hanesini doldurunuz.");
                $('#vade_01').focus();
            }
            else {
                hesapla_aylik_odeme();
            }
        });         


        $(".fltTikla").click(function () {
            OnlneChatModalClose()
        });
        
        $(document).click(function() {
            clearTimeout(modalTimeout);
            RunSeTime();
        });
        
        $('.OnlineChat-Modal-Box').click(function(e) {
            e.stopPropagation();
        });
         
    });
    
    function ModalOpen(){
        $('#overlay').css('height', document.documentElement.clientHeight);
        $('#overlay').addClass("overlay-strng");
        $('#overlay').show();
        $(".Modal-Box").show();
        $(".overlay-strng").bind('click', function() {
            ModalClose()
        }); 
    }    
     
    function ModalClose(){    
        $('#overlay').hide();
        $(".Modal-Box").hide();
        $('#overlay').removeClass("overlay-strng");
        $(".overlay-strng").unbind('click');
        clearTimeout(modalTimeout);
        RunSeTime();
    }


    function OnlneChatModalOpen(){
        if(!$('.Modal-Box').is(':visible')) {
            $('#overlay').css('height', document.documentElement.clientHeight);
            $('#overlay').addClass("overlay-strng");
            $('#overlay').show();
            $(".OnlineChat-Modal-Box").show();
            $(".overlay-strng").bind('click', function() {
                OnlneChatModalClose()
            });
        }
    }
    
    function OnlneChatModalClose(){    
        $('#overlay').hide();
        $(".OnlineChat-Modal-Box").hide();
        $('#overlay').removeClass("overlay-strng");
        $(".overlay-strng").unbind('click');
        clearTimeout(modalTimeout);
    }
    
    function RunSeTime(){
         modalTimeout = setTimeout("OnlneChatModalOpen()",onlineDestekTime);
    }
    
    function _openWnd(url, wndName){
       var popW = 675;
       var popH = 630;

       if (document.all || document.layers) {
          var screenW = screen.width;
          var screenH = screen.height;
       } else {
          var screenW = 800;
          var screenH = 600;
       }

       var leftPos = (screenW-popW)/2;
       var topPos = ((screenH-popH)/2) - 40;
       var wndFeatures = 'status=yes,menubar=no,scrollbars=yes,resizable=yes,toolbar=no,width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos;
       var win = window.open(url, wndName, wndFeatures);
       if (win != null) win.focus();
    }

    function GoChatPage(){
        //window.open('https://chat.yapikredi.com.tr/chatapp/index.do?loc=tr&kanal=10&banner=banner.gif', 'OnlineChat', 'width=680,height=620,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes,resizable=yes,top=150,left=500');
        _openWnd('https://chat.yapikredi.com.tr/chatapp/index.do?new=y&loc=tr&kanal=16&banner=banner_mortgage.gif', 'openChat');
    }

    function KrediniHesaplaChat(){
        window.blur();
        window.opener.focus();
        window.opener.OnlneChatModalOpen();
    }    

    function FuncFocusFrmFlash(){
        window.opener.focus();
        window.opener.ModalOpen();
    }


var _resp=null;
var faizOran;
var faizOran1;

    function readRate(){
        $.ajax({
            type: "GET",
            cache: true,
            dataType: "xml",
            url: _webRoot + "_xml/faiz_oranlari.aspx",
            success: function(xmlResponse){
                _resp=xmlResponse;
                faizOran1 = parseFloat($('vade',xmlResponse).attr('faiz'));
                $("#faizOranInput").text(faizOran1);
           }
         });
        
    }
function onChange(obj){
    var monthFrom = 0;
    var monthTo = 0;
    
    $('vade',_resp).each(function(){
          monthTo = parseInt($(this).attr('to'));
          if(parseInt(obj.value) == '0')  $("#faizOranInput").text(faizOran);
          if(parseInt(obj.value) <= monthTo && parseInt(obj.value) > monthFrom)
               faizOran = parseFloat($(this).attr('faiz'));
          monthFrom = parseInt($(this).attr('to'));
    $("#faizOranInput").text(faizOran);      
    });
    
}
    function raund(val){
	val = ""+Math.round(100*val);
	for (var i = val.length; i < 3; i++)
		val = 0 + val;
	var dec_point = val.length-2;
	var first_part = val.substring(0,dec_point);
	if (first_part == '')
		first_part = 0;
	var second_part = val.substring(dec_point,val.length);
	var result = first_part+","+second_part;
	return result;
}

function del_comma(str)  {
   while (str.indexOf(".") > 0) {str = str.replace(".","");}
   return str;
}

function refresh_Num(input){
	var tmpVal = "";
	var index = 0;
	var inputVal = input;
	var dot_pos = inputVal.indexOf(",");
	if (dot_pos > 0)
		inputVal = inputVal.substr(0, dot_pos);

	inputVal = del_comma(inputVal);
	var len = Math.floor(((inputVal.length-1)/3));
	var begin = inputVal.length - len*3;
	
	tmpVal = inputVal.substr(0, begin);
	var i = 0;
	for (i = 0; i < len; i++){
		tmpVal = tmpVal + ".";
		var start_pos = i*3 + begin;
		var tmp = inputVal.substr(start_pos, 3);
		tmpVal = tmpVal + tmp;
	}
	inputVal = tmpVal;
	return inputVal;
}

function refresh_NumRound(inputVal){
	var after_dot = "";
	var before_dot = "";	
	var dot_pos = inputVal.indexOf(",");
	if (dot_pos > 0)
	{
		after_dot = inputVal.substr(dot_pos + 1, inputVal.length);
		before_dot = inputVal.substr(0, dot_pos);
	}
	else
		before_dot = inputVal;
	
	inputVal = refresh_Num(before_dot);

	if (dot_pos > 0)
		inputVal = inputVal + "," + after_dot.substr(0,2);
	return inputVal;
}

function nm_onkeyup(e) {
	var Nets = (document.all) ? 0 : 1;
	var inputVal = "";
	if (Nets)
		inputVal = e.target.value;
	else
	{
		inputVal = window.event.srcElement.value;
		if (window.event.keyCode==37 || window.event.keyCode==39){
			return false;
		}
	}
	inputVal = refresh_NumRound(inputVal);
	if (Nets)
		e.target.value = inputVal;
	else
		window.event.srcElement.value = inputVal;
	return true;
}

function Num_onkeypress(e) {
	var Nets = (document.all) ? 0 : 1;
	var keyCode = 0;
	var charCode = 0;
	var inputVal = "";
	var tmp = "";

	if (Nets){
		keyCode = e.keyCode;
		charCode = e.charCode;
		inputVal = e.target.value;
	} else{
		keyCode = window.event.keyCode;
		charCode =  window.event.keyCode;
		inputVal = window.event.srcElement.value;
	}
	
	if (charCode==46 && (inputVal.length<=0 || inputVal.indexOf(",")>=0))
	  return false;

	if (charCode!=46 && keyCode!=8 && keyCode!=37 && keyCode!=39 && (charCode<48 || charCode>57))
		return false;
	return true;
}


function hesapla_aylik_odeme(){
	var faiz = faizOran/100;
	var vadeValue = $("#vade_01").val();
	var mortgageKredisiValue = del_comma($("#mortgage_kredisi_miktari").val());
	var sonuc_01 = ((mortgageKredisiValue*faiz)/(1-(1/Math.pow((1+faiz),vadeValue))));
	var tutar_aylikOdeme = refresh_NumRound(raund(sonuc_01));
	sonuc_01 = tutar_aylikOdeme;
	$("#sonucArea_aylik_odeme").val(sonuc_01);
	
}





