/* $$$
   $$$    BROWSER DETECT
   $$$
*/

function Browser(){
	var ua = navigator.userAgent.toLowerCase(); 
	this.Gecko = (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1);
	this.Safari = (ua.indexOf('safari') != - 1);
	this.IE = (ua.indexOf('msie') != -1 && !this.Opera && (ua.indexOf('webtv') == -1) ); 
	this.Firefox = ( (ua.indexOf('firebird/') != -1) || (ua.indexOf('firefox/') != -1) );
	this.IECompatible = ( (ua.indexOf('msie') != -1) && !this.IE);
	this.NSCompatible = ( (ua.indexOf('mozilla') != -1) && !this.NS && !this.Mozilla);
	this.geckoVersion = ( (this.Gecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );
	this.equivalentMozilla = ( (this.Gecko) ? parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) ) : -1 );
	this.versionMinor = parseFloat(navigator.appVersion); 
	if (this.Gecko && !this.Mozilla) this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
	else if (this.Mozilla) this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
	else if (this.IE && this.versionMinor >= 4) this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
	else if (this.Safari) this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
	this.versionMajor = parseInt(this.versionMinor); 
	this.DOM1 = (document.getElementById);
	this.DOM2Event = (document.addEventListener && document.removeEventListener);
	this.mode = document.compatMode ? document.compatMode : 'BackCompat';
	this.Win = (ua.indexOf('win') != -1);
	this.Mac = (ua.indexOf('mac') != -1);
	this.NS6up = (this.NS && this.versionMajor >= 6);
	this.NS7up = (this.NS && this.versionMajor >= 7); 
	this.IE4 = (this.IE && this.versionMajor == 4);
	this.IE5 = (this.IE && this.versionMajor == 5);
	this.IE55 = (this.IE && this.versionMinor == 5.5);
	this.IE5up = (this.IE && this.versionMajor >= 5);
	this.IE6x = (this.IE && this.versionMajor == 6);
	this.IE6up = (this.IE && this.versionMajor >= 6);
}
var is = new Browser();

/* $$$
   $$$    POPUPS
   $$$
*/

var Popwin = null;

function intBankCheck(){
    var checkIntBanking = setInterval(function(){
        if(Popwin!=null && Popwin.closed){
            clearInterval(checkIntBanking);
            document.location.reload();
        }
    },1200);
} 

function PopItUp(src,w,h,s) {

    var fr = /\/fon-fiyat-getirileri\//i;
    var pst = "";

    // fon fiyat getirileri
    if(fr.test(src)) {
        pst = ", left=20, top=130"
    }

	if(s) w=w+17;
	if(w){
	    Popwin = window.open(src,"pop_up","toolbar=0,width=" + w + ", height=" + h + ", location=0, directories=0, status=1, scrollbars="+s+", menubar=0, resizable=0, copyhistory=0" + pst);
	    Popwin.focus();
	}
	else {
	    window.location = src
	}

}



function PopItUp_Fixed(src) {
	Popwin = window.open(src,"pop_up","toolbar=0, width=600, height=600, location=0, directories=0, status=1, scrollbars=1, menubar=0, resizable=0, copyhistory=0");
	Popwin.focus();
}

function PopItUpResize(src,w,h,s) {
	if(s) w=w+17;
    Popwin = window.open(src,"pop_up","toolbar=0,width=" + w + ", height=" + h + ", location=0, directories=0, status=1, scrollbars="+s+", menubar=0, resizable=1, copyhistory=0");
    Popwin.focus();
}
function PopSube(src,w,h,s,r,hi) {
	if(s) w=w+17;
	    Popwin = window.open(src,"FWFINTBANK","width="+ w +",height="+ h +",top=0,left=0,toolbar=0,location=0,address=no, directories=0,status=1,menubar=0,scrollbars=yes,resizable=1,copyhistory=1");
	    if (Popwin != null) {
	        Popwin.focus();
	    }
}



function externalSite(src){
	var externalSite = window.open(src);
	externalSite.focus();
}


function PopItUp2(src,w,h,s) {
	if(s) w=w+17;
	Popwin = window.open(src,"pop_up","toolbar=0,width=" + w + ", height=" + h + ", location=0, directories=0, status=1, scrollbars="+s+", menubar=0, resizable=1, copyhistory=0");
	Popwin.focus();
}

/* $$$
   $$$    WINDOW HEIGHT
   $$$
*/


function getWindowHeight(){
	var windowHeight = 0;
	if(typeof(window.innerHeight) == 'number'){
		windowHeight = window.innerHeight;
	}else{
		if(document.documentElement && document.documentElement.clientHeight){
			windowHeight = document.documentElement.clientHeight;
		}else{
			if(document.body && document.body.clientHeight){
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

/* $$$
   $$$    WINDOW WIDTH
   $$$
*/

function getWindowWidth(){
	var windowWidth = 0;
	if(typeof(window.innerWidth) == 'number'){
		windowWidth = window.innerWidth;
	}else{
		if(document.documentElement && document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		}else{
			if(document.body && document.body.clientWidth){
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

/* $$$
   $$$    FOOTER
   $$$
*/

function setFooter(){

	if (document.getElementById){
		var windowHeight = getWindowHeight();
		if (windowHeight>0){

			var wrapperHeight = document.getElementById('wrapper').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (wrapperHeight)>= 76) {
				footerElement.style.marginTop = (windowHeight - (wrapperHeight))-76  + 'px';
				//alert((windowHeight - (wrapperHeight))-43  + 'px')
			}else{
				
			}

		}
	}
	
}


/* $$$
   $$$    MAIL ENCODE
   $$$
*/

function mailTo(m,e,t) {
	if (!e) {
		e='finansbank.com.tr';
	}
	if (!t) {
		t=m+String.fromCharCode(64)+e;
	}
	
	document.write('<a href="mailto:'+m+String.fromCharCode(64)+e+'" class="contentlink">'+t+'</a>');
}

/* $$$
   $$$    INPUT CONTROLS
   $$$
*/

function onlyLetter(e) {
	var keyCode = (is.ns) ? e.which : event.keyCode;
	if (keyCode > 47 && keyCode<58){
	return false;}
}

function onlyNumber(e) {
	var keyCode = (is.ns) ? e.which : event.keyCode;
	if ((keyCode<48 || keyCode>57)&&keyCode!=8&&keyCode!=0) {
	return false;}
}

function onlyEmail(e) {
	var InvalidChars=" !#/*{[()]},;^><\\?+:'`|þÞÐðÜüÇçÝýÖö";

	kCode=InvalidChars.charAt(5);

	var keyCode = (is.ns) ? e.which : event.keyCode;

	if (keyCode>127) {
		return false;
	}
	for (i=0;i<=InvalidChars.length-1;i++) {
		if (keyCode==InvalidChars.charCodeAt(i)) {
			return false;
		}
	}
	return true;
}

function stopt(){
    
}

function KontrolMaxlength(t,l) {
if (document.getElementById(t).value.length >= l)
    {
        document.getElementById(t).value = document.getElementById(t).value.substr(0,l);
        return false;
    }
}

/* $$$
   $$$    INPUT AUTOFOCUS
   $$$
*/

function autofocus(field, limit, next, evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode > 31 && field.value.length == limit) {
        field.form.elements[next].focus();
    }
}



function init(){
	/*if (!document.getElementsByTagName) return;
	imgArray = document.getElementsByTagName("img");
		for (i=0;i<imgArray.length;i++){
			if(imgArray[i].alt!=-1) imgArray[i].title=imgArray[i].alt;
		}
	aArray = document.getElementsByTagName("a");
		for (i=0;i<aArray.length;i++){
			if(aArray[i] && aArray[i].href && !aArray[i].title && aArray[i].childNodes[0])	aArray[i].title = aArray[i].childNodes[0].nodeValue;
		}*/
}


function delCookie(name) {
	createCookie(name,"",-1);
}

function intSube(ref){
    if(ref){
    PopSube('/redirect/internet-subesi.aspx'+ref+' ',1000,599)
    }
    else {
    var fbURL = window.location.pathname;
    PopSube('/redirect/internet-subesi.aspx?FB_URL='+fbURL,1000,599)
    }
}

function intSubeFlash(ref){
    intSube(ref);
    intBankCheck();
}

function hizliLogininPopUp(ref){
    if(ref){
    PopSube('/redirect/hb-aninda-sifre.aspx',600,650)
    }
    else {
    var fbURL = window.location.pathname;
    PopSube('/redirect/hb-aninda-sifre.aspx?FB_URL='+fbURL,600,650)
    }
}

function intSubeEN(ref){
    if(ref){
        PopSube('/redirect/internet-banking.aspx' + ref,1000,584)
    }
    else {
        var fbURL = window.location.pathname;
        PopSube('/redirect/internet-banking.aspx?FB_URL='+fbURL,1000,584)
    }
}

function hizliLogin(ref){
    if(ref){
        PopItUp('/redirect/hb-aninda-sifre.aspx' + ref,600,650)
    }
    else {
        var fbURL = window.location.pathname;
        PopItUp('/redirect/hb-aninda-sifre.aspx?FB_URL='+fbURL,600,650)
    }
}
function anindaKredi(ref){
    if(ref){
	  PopItUp('/redirect/hb-aninda-kredi.aspx'+ ref +' ',593,700,1)
    }
    else {
        var fbURL = window.location.pathname;
		PopItUp('/redirect/hb-aninda-kredi.aspx?FB_URL='+fbURL,593,700,1)
    }
}
function anindaKart(ref){
    if(ref){
        PopItUp('/redirect/hb-cardfinans.aspx'+ref,720,480,1)
    }
    else {
        var fbURL = window.location.pathname;
        PopItUp('/redirect/hb-cardfinans.aspx?FB_URL='+fbURL,720,480,1)
    }
}
function ortakMarkaliKartlar(ref){
    if(ref){
        PopItUp('http://www.cardfinans.com.tr/cardfinans-ile-tanisin/popup/hizli-kart-basvurusu-ortak-markali-kartlar.aspx'+ref,750,742,1)
    }
    else {
        var fbURL = window.location.pathname;
        PopItUp('http://www.cardfinans.com.tr/cardfinans-ile-tanisin/popup/hizli-kart-basvurusu-ortak-markali-kartlar.aspx?FB_URL='+fbURL,750,742,1)
    }
}
function eEkstre(ref){
    if(ref){
        PopItUp('/redirect/hb-webden-eekstre.aspx',609,690,1)
    }
    else {
        var fbURL = window.location.pathname;
        PopItUp('/redirect/hb-webden-eekstre.aspx?FB_URL='+fbURL,609,690,1)
    }
}
function anindaSifre(ref){
    if(ref){
        PopItUp('/redirect/hb-aninda-sifre.aspx' + ref,600,650,1)
    }
    else {
        var fbURL = window.location.pathname;
        PopItUp('/redirect/hb-aninda-sifre.aspx?FB_URL='+fbURL,600,650,1)
    }
}
function anindaSifre2(ref){
    if(ref){
        PopItUp('/redirect/as-aninda-sifre.aspx',600,650,1)
    }
    else {
        var fbURL = window.location.pathname;
        PopItUp('/redirect/as-aninda-sifre.aspx?FB_URL='+fbURL,600,650,1)
    }
}

function krediHesapMakinesi(state) {

    if(!state) {
        state = "ihtiyac";
    }

    var states = {
        "ihtiyac":1,
        "tasit":2,
        "konut":3
    };

    if( $("#fadeMask").length != 0 ) {
        return false;
    }

    var mask = $("<div id=\"fadeMask\">&nbsp;</div>");
    var hesapMakinesi = $("<div id=\"hesapMakinesi\">&nbsp;</div>");
    
    
    hesapMakinesi.flash({
        src: root + 'swf/hesap-makinesi/calculator.swf',
        width: "577",
        height: "660",
        id: "flashHeader",
        wmode: "transparent",
        flashvars: {
            "xmlPath": root + "swf/xml/hesap-makinesi.xml",
            "initialState": states[state]
        }

    },
    {
        version: "9"
    });
    
    var pageHeight= $(document).height();
    
    $(window).resize(function(){
        var maskHeight = $(document).height();
        var maskWidth = $(document).width();
        var actualWidth = "100%";
        var actualHeight = "100%";

        if (maskWidth < 950) {
            actualWidth = maskWidth + "px";
        } else {
            actualWidth = "100%"
        }

        if (maskHeight < pageHeight) {
            actualHeight = maskHeight + "px";
        } else {
            actualHeight = pageHeight + "px";
        }

        hesapMakinesi.css({
            top: Math.round(maskHeight / 2) - 330,
            left: Math.round(maskWidth / 2) - 280
        });

        mask.css({ "width": actualWidth, "height": actualHeight });
    }).resize();

    $("body").append(mask).append(hesapMakinesi);

    mask.fadeIn(100);
    mask.fadeTo("fast", "0.7", function(){
        hesapMakinesi.show();
    });

    mask.click(function(){
        mask.remove();
        hesapMakinesi.remove();
    });

}

function khmKapat() {
    $("#hesapMakinesi,#fadeMask").remove();
}

function KrediHesapSonuc(faiz, taksit, kredi, vade, krediTipi) {
    var inputs = [
        "<html>",
        "<head></head>",
        "<body>",
        //"<form id=\"formid\" method=\"POST\" action=\"" + root + "kredi-hesap-makinesi/sonuc.aspx\">",
        "<form id=\"formid\" method=\"POST\" action=\"" + root + "hesap-makinesi/sonuc.aspx\">",
        "<input type=\"hidden\" name=\"kmh_popup_faiz\" value=\"" + faiz + "\" />",
        "<input type=\"hidden\" name=\"kmh_popup_taksit\" value=\"" + taksit + "\" />",
        "<input type=\"hidden\" name=\"kmh_popup_kredi\" value=\"" + kredi + "\" />",
        "<input type=\"hidden\" name=\"kmh_popup_vade\" value=\"" + vade + "\" />",
        "<input type=\"hidden\" name=\"kmh_popup_kredi_tipi\" value=\"" + krediTipi + "\" />",
        "</form>",
        "<script type=\"text/javascript\">document.getElementById(\"formid\").submit();</script>",
        "</body>",
        "</html>"
    ];
    
    //krediWin = window.open(root + "kredi-hesap-makinesi/sonuc.aspx","krediHesap","toolbar=0,width=710, height=670, location=0, directories=0, status=1, scrollbars=1, menubar=0, resizable=0, copyhistory=0");
    krediWin = window.open(root + "hesap-makinesi/sonuc.aspx","krediHesap","toolbar=0,width=710, height=670, location=0, directories=0, status=1, scrollbars=1, menubar=0, resizable=0, copyhistory=0");
    krediWin.focus();
    
    krediWin.document.write(inputs.join(""));
}

function getPageParam() {
    var r1 = /^http:\/\/[^/]+\/([^\?\.]+).*$/i;
    var r2 = /(\/|\.|-|\x20)/gi;
    var param = r1.exec(document.location)[1];
    
    return param.replace(r2, "_");
}

function linkToFaqItem(id) {
    var y = $("#"+id).click();
    
    
    
    setTimeout(function(){
    
        var pos = y.offset();
    
        window.scrollTo(pos.left, pos.top);
    
    },2000);
    
    return false;
}


/* $$$
   $$$    ONLOAD - ONRESIZE
   $$$
*/

