﻿var myWindowLoadEventArr = [];
var navArr = [];
var orientationArr = [];
var myApplicationName=""
var noRunOrientation=false;
var runEventHandler = true;
var topMenuSelectedItem="";
Array.prototype.removeItem = function(_item){
	if(typeof(_item)!= "undefined"){
		var tempArray = new Array();
		if(typeof(_item)=="number"){			
			tempArray = this.slice(_item, _item)	
			//this = tempArray;
			return tempArray;			
		}
	}
}

function addEvent(_obj,_event, _func){
	if(!_func) return false;
	if(_obj.addEventListener){		
		_obj.addEventListener(_event,_func,false)
	}
	else{	
		_obj.attachEvent('on' + _event, _func)
	}
}

function addLoadEvent(_obj,_event, _func){
	runMe = _func || runEventByArray;
	if(_obj.addEventListener){		
		_obj.addEventListener(_event,runMe,false)
	}
	else{	
		_obj.attachEvent('on' + _event, runMe)
	}
}


function runEventByArray(){
	if(!runEventHandler) return false;
	for(var i=0,len=myWindowLoadEventArr.length;i<len;i++){	
		myWindowLoadEventArr[i][1]();
	}	
}

/*menu ayarlanması ve searchbox geyigi*/
myWindowLoadEventArr.push(["defaultLoadFuncs",function(){
    mE("#internetBanking").onclick=function(){
        //openisube();
    }
	mE("#txtSearch").onfocus=function(){
		if(this.className=="tr"){
			this.setAttribute("_defaultValue", "site içerisinde arama")
		}
		else{
			this.setAttribute("_defaultValue", "Enter keywords here")
		}
		_defaultValue = this.getAttribute("_defaultValue");
		if(this.value==_defaultValue) this.value="";
	}	
	mE("#txtSearch").onblur=function(){
		_defaultValue = this.getAttribute("_defaultValue");
		if(this.value=="") this.value=_defaultValue;
	}
	var myMainMenuItems = mE("#mainMenu ul li");
	var countMenuItem = myMainMenuItems.length
	var selectedMenuItem = -2;
	var testClass = new RegExp("(^|\\s)selected(\\s|$)");
	for(var i=0;i<countMenuItem;i++){
		if(testClass.test(myMainMenuItems[i].className)){
			selectedMenuItem = i;
		}	
	}
	

	if(typeof(myMainMenuItems[selectedMenuItem+1])!= "undefined") myMainMenuItems[selectedMenuItem+1].className="selectedAfter";
}]
)

myWindowLoadEventArr.push(["reSizeFunc",reSizeMe])
myWindowLoadEventArr.push(["mainButtonBigClickArea",function(){gotoMyChildHref("#mainMenu li");}])



addLoadEvent(window, "load")



/*Kar Payı Kaydırma*/
var loadKarPaylari = false;
function homeKarPayiPiyasalar(whichObj){
	if(whichObj==0){
		mE("#PiyasaContainer li a")[0].className="selected"
		mE("#PiyasaContainer li a")[1].className=""
		mE("#anlikPiyasalarContainer").style.display='block';
		mE("#karpayiContainer").style.display='none';
	}
	else{
		mE("#PiyasaContainer li a")[0].className=""
		mE("#PiyasaContainer li a")[1].className="selected"
		mE("#anlikPiyasalarContainer").style.display='none';
		mE("#karpayiContainer").style.display='block';
		
		if(loadKarPaylari==false){
		    divAjaxLoader =  mE("#loaderKarPayi");
	        divAjaxLoaderP =  mE("#loaderKarPayi p")[0];
	        divAjaxLoader.style.display="block";
	        divAjaxLoaderP.style.display="block";
		    var myAjx = new Acaks(
		    {
			    url: myApplicationName+ "/usercontrol/kar_payi_oranlari.aspx",
			    parameters: Math.random(1000),
			    responseType: "text",			
			    successRun : function(html){
			        loadKarPaylari = true;
			        divAjaxLoader.style.display="none";
	                divAjaxLoaderP.style.display="none";
	                mE("#scrollEffectElement").innerHTML=html;	 
	                mE("#karPayiResult").style.display="block"; 
			    }
			});
		}
	}
}

/*Footer Hizalama*/
function reSizeMe(){
	myBody = mE("body")[0].id
	if( myBody !="home") {
		setFooter();
		addEvent(window, "resize", setFooter)
	}
	/*setFooter();
	addEvent(window, "resize", setFooter)*/
}

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;
}


function setFooter(){
	try{
		if (document.getElementById){
			var windowHeight = getWindowHeight();
			if (windowHeight>0){
				var contentHeight = document.getElementById('container').offsetHeight;
				var footerElement = document.getElementById('footerContainer');
				var footerHeight  = footerElement.offsetHeight;
				if (windowHeight - (contentHeight + footerHeight)>= 0) {
					footerElement.style.marginTop = (windowHeight - (contentHeight+footerHeight)) + 'px';
				}else{
					footerElement.style.marginTop = '0';
				}
			}
		}
	}
	catch(err){
	}
}


function getCenter(pwidth,pheight){
	wwidth=screen.width;
	wheigth=screen.height;
	lpos= (wwidth - pwidth)/2;
	tpos= (wheigth - pheight)/2;
	return lpos, tpos;
}


function popLink(src,w,h,s) {
	if(s) w=w+17;
	getCenter(w,h);
	Popwin = window.open(src,"pop_up","toolbar=0,width=" + w + ", height=" + h + ", left="+ lpos +", top="+ tpos +"; location=0, directories=0, status=1, scrollbars="+s+", menubar=0, resizable=0, copyhistory=0");
	Popwin.focus();
	return false;
}

function orientationBar(){  
    
    if (noRunOrientation==true) return false;

    myBody = mE("body")[0].id
    if( myBody !="home") {
    if(topMenuSelectedItem!="") mE("#" + topMenuSelectedItem).className +=" selected";
    //lang choice
        if(siteLang=="tr"){
            orientationArr.push(["Ana Sayfa",myApplicationName + "/tr/index.aspx"])
        }
        else{
            orientationArr.push(["Home Page",myApplicationName + "/en/index.aspx"])
        }
    // first level menu read
        _topMenu = mE("#topmenu .selected");
        if(_topMenu.length>0){            
           orientationArr.push([_topMenu[0].title,_topMenu[0].href]);
        }
        else{
            _mainMenu = mE("#mainMenu .selected");   
            if(_mainMenu.length>0) {            
                myA = mE("a", _mainMenu[0])[0];
                orientationArr.push([myA.title,myA.href]);
            }            
        }
        
      // second- third level menu read
      if(mE("#menuContainer")!= null){
        _othersMenu = mE("#menuContainer .selected > a");      
          for(var i=0,p=_othersMenu.length;i<p;i++){
             orientationArr.push([_othersMenu[i].title,_othersMenu[i].href]);
          }
      }
      //-----------------------
      if(orientationArr.length>0){
        var myPageTitle = "";
        myOrientMenu = mE("#whereAmI");        
        for(var i=0,p=orientationArr.length;i<p;i++){        
            var _myLi = document.createElement("li");
            if(i==0) _myLi.className="f";
            if(i==p-1){
                var _myHref = document.createElement("span");
            }
            else{
                var _myHref = document.createElement("a");
                _myHref.href=orientationArr[i][1];
            }
            _myHref.title=orientationArr[i][0];
            _myHref.innerHTML = _myHref.title
            _myLi.appendChild(_myHref);
            myOrientMenu.appendChild(_myLi);
           if(i!=0)myPageTitle += " " + orientationArr[i][0] + " >"
        }
        
        if(siteLang=="tr"){
            SiteName = "Türkiye Finans Katılım Bankası > "
            orientationArr.push(["Ana Sayfa",myApplicationName + "/tr/index.aspx"])
        }
        else{
             SiteName = "Türkiye Finans Katilim Bankasi > "
              orientationArr.push(["Home Page",myApplicationName + "/en/index.aspx"])
        }
        
        document.title = SiteName + myPageTitle.substr(0,myPageTitle.length-1)
      }
       
    }
}


function otherSiteLink(_hrefObj){
    window.open(_hrefObj.href)
    return false;
}


function blankLink(_hrefObj){
    window.open(_hrefObj.href)
    return false;
}


var ddListActiveCont =null;
function changeDdList(_ddList){
   myActiveObj = _ddList.options[_ddList.selectedIndex].value;
   mE("#" + myActiveObj).style.display="block";
   if(ddListActiveCont!= null)  ddListActiveCont.style.display="none";
   ddListActiveCont =  mE("#" + myActiveObj);
}


function flashAreaBg(_className){

    //mE("#flashArea").style.height="281px";
    mE("#flashBgArea").style.backgroundImage="url(../_i/flashAreaBg/"+_className+"?asdsd)";   
}
function showBigFlasArea(_type){    
    if(_type=="show"){
        mE("#flashArea").style.height="637px";   
        mE("#myFlashObject").style.zIndex="10000";
    }
    else{
        mE("#flashArea").style.height="281px";
    }
}



function openisube() {
    theURL="https://internetsube.turkiyefinans.com.tr/";
	var mytop = Math.abs((screen.height - 543) / 2);	
	var myleft = Math.abs((screen.width - 790) / 2);	  
	var s = "top=" +  mytop + ",left=" + myleft; 
	scrll = 0;
	var brws = navigator.userAgent.toLowerCase();
	var _isIE = ((brws.indexOf("msie") != -1) && (brws.indexOf("opera") == -1)) ? true : false; 
	
	if (_isIE){
		myarr = navigator.appVersion.split("compatible; MSIE");
		vers = parseFloat(myarr[1].substring(1,4));
		if ( vers < 5.0 ){
			window.navigate('browser.htm')
		}
		else{
			h=543;
			if (vers==7){h=563;}		
			splashWin = window.open(theURL,"anadolu_isube","toolbar=0,width=790 , height="+ h +"," + s + "; location=0, directories=0, status=1, scrollbars="+ scrll +", menubar=0, resizable=0, copyhistory=0");
		}
	}
	else{
		Opera = (brws.indexOf("opera") != -1)	
		if (Opera){scrll = 1;}
		splashWin = window.open(theURL,"anadolu_isube","toolbar=0,width=790 , height=546," + s + "; location=0, directories=0, status=1, scrollbars="+ scrll +", menubar=0, resizable=0, copyhistory=0");
		//window.location.href="browser.html"
	}
}

function searchFormValid(_controlField){
    if(_controlField.value.length>2){
        if(siteLang=="tr" && _controlField.value == "site içerisinde arama"){
            alert("Arama yapmak istediğiniz kelimeyi 'site içerisinde arama' bölümüne yazınız.")
            return false;
        }
        if(siteLang=="en" && _controlField.value == "Enter keywords here"){
            alert("Please enter the keyword(s) you want to search for.")
            return false;
        }

       return true
    }
    else{
        if(siteLang=="tr"){
            alert("Arama yapabilmek için en az 3 karakterden oluşan bir kelime yazmanız gerekmektedir.")
        }
        else{
            alert("Please enter at least 3 characters.")
        }
        return false;
    }   
}
