var is = {
	ua: navigator.userAgent.toLowerCase(),
	tArray: [],
	fArray: [],
	browser: function (trueArray, falseArray) {
		is.tArray.length=0;
		is.fArray.length=0;
		for (var i=0; i<trueArray.length; i++) {
			is.ua.search(trueArray[i])!=-1 ? is.tArray.push(1) : is.tArray.push(0);
		}
		for (var j=0; j<falseArray.length; j++) {
			is.ua.search(falseArray[j])==-1 ? is.fArray.push(0) : is.fArray.push(1);
		}
		return ((is.tArray.inArray(0) ? 0 : 1) && (is.fArray.inArray(0) ? 1 : 0));
	},
	debug:function(){
		return is.ua;
	}
};

Array.prototype.inArray=function(value){
	for(i=0;i<this.length;i++){
		if(this[i]===value) return i;
	}
	return false;
};

var externalLinks = function(){
	if(!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0;i<anchors.length;i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel")=="external"){
			anchor.onclick = function(e){
				window.open(this.href);
				return false;
			}
		}
	}
};

var pop={
	pw:null,
	l:0,
	t:0,
	gc:function(w,h){
		pop.l=(screen.width-w)/2;
		pop.t=(screen.height-h)/2;
		return pop.l,pop.t;
	},
	up:function(url,n,w,h,s,r,lp,tp){
		w = s?w+17:w;
		n = (!n?'popwindow':n);
		(!lp && !tp) ? pop.gc(w,h) : (pop.l=lp, pop.t=tp);
		pw = window.open(url,n,"toolbar=0,width="+w+", height=" +h+", left="+pop.l+", top="+pop.t+"; location=0, directories=0, status=1, scrollbars="+s+", menubar=0, resizable="+r+", copyhistory=0");
		pw!=null ? pw.focus() : void(0);
	}
};

function searchFocus(obj, inputText) {
	if($(obj)){
		$(obj).onfocus=function() {
			$(obj).value = $(obj).value!='Arama' ? $(obj).value : '';
		};
		$(obj).onblur=function(inputText) {
			$(obj).value = ($(obj).value.length > 0 ? $(obj).value : 'Arama');
		};
		return true
	}
	else {
		return false;
	}
};

function searchFocusEn(obj, inputText) {
	if($(obj)){
		$(obj).onfocus=function() {
			$(obj).value = $(obj).value!='Search' ? $(obj).value : '';
		};
		$(obj).onblur=function(inputText) {
			$(obj).value = ($(obj).value.length > 0 ? $(obj).value : 'Search');
		};
		return true
	}
	else {
		return false;
	}
};

function bltFocus(obj, inputText) {
	if($(obj)){
		$(obj).onfocus=function() {
			$(obj).value = $(obj).value!='e-posta' ? $(obj).value : '';
		};
		$(obj).onblur=function(inputText) {
			$(obj).value = ($(obj).value.length > 0 ? $(obj).value : 'e-posta');
		};
	}
};

function acc(){
	var accordion = new Accordion('h3.atStart', 'div.atStart', {
		opacity: true, start: 'all-closed', alwaysHide: true,
		onActive: function(toggler, element){
			toggler.setStyle('color', '#ed6e00');
			toggler.setStyle('background', '#fdfdfd url(/i/assets/i/bg-acc-up.png) no-repeat 100% 100%');
		},
		onBackground: function(toggler, element){
			toggler.setStyle('color', '#807f7f');
			toggler.setStyle('background', '#fdfdfd url(/i/assets/i/bg-acc-down.png) no-repeat 100% 100%');
		}
	}, $('accordion'));
};

function sphesapla(str, ishome){

	str!=false ? str = "?parametre=" + String(str) : str="?x=null";
	str=str + "&refid=" + refidJs;
	ishome ? ishome=true : ishome=false;
	var FO = {movie:"/i/Assets/i/swf/yatay.swf"+ str + "&sp=true", width:662, height:415, majorversion:7, build:0, menu:false, quality:"best", setcontainercss:true, flashvars: str + "&sp=true", id:"yatayhesaplaswf", name:"yatayhesaplaswf"};
	 UFO.create(FO, "sp-hesapla-yatay");

	splashBox.open('#sp-hesapla-yatay', "", "splashbox[width:670,height:600]");
	if (ishome!=true) {
		return true;
	};
};

function spAc(url, width, height) {
	url = (url.indexOf('http://')!=-1 || url.indexOf('https://')!=-1) ? url : url="#"+url;
	splashBox.open(url, "", "splashbox[width:"+ width +", height:"+ height +"]");
};

function dovizAc(url, width) {
	url = (url.indexOf('http://')!=-1 || url.indexOf('https://')!=-1) ? url : url="#"+url;
	splashBox.open(url, "", "splashbox[width:"+ width +"]");
	LoadCurrencies();
};

function fonAc(url, url2, where, width) {
	spwhere = '#' + where;
	new Ajax(url , {
		method: 'get',
		update: where,
		evalScripts: true
		}
	).request();
	new Ajax(url2 , {
		method: 'get',
		update: 'divFons',
		evalScripts: true
		}
	).request();
	splashBox.open(spwhere , "", "splashbox[width:"+ width +",height:600]");
	return false
};

function komisyonAc(url, where, width) {
	spwhere = '#' + where;
	new Ajax(url , {
		method: 'get',
		update: where,
		evalScripts: true
		}
	).request();
	splashBox.open(spwhere , "", "splashbox[width:"+ width +",height:600]");
	return false
};

var getURL = function (o){
	var selectedIndexValue = o.options[o.selectedIndex].getAttribute('value');
	if(selectedIndexValue && selectedIndexValue.length>0){
		(selectedIndexValue.indexOf('http://')>0 || selectedIndexValue.indexOf('https://')>0) ? window.open(selectedIndexValue, _blank) : window.location.href = selectedIndexValue;
		return true;
	}
	return false;
};

var getBgSize = function(){
	//if(window.ie && !window.ie7){
	if(is.browser(['msie', '6.0'], ['linux'])){
		var wh = window.getHeight();
		var wsh = window.getScrollHeight();
		var wsx = window.getWidth();
		if($('root-bg')){
			var finw = wsx>862 ? 862+"px" : (wsx>968 ? 100+"%" : 968+"px");
			$('root-bg').style.width = finw;
			$('root-bg').style.left = (wsx-862)/2+"px";
		}
		$('root-bg').style.height = (wsh>wh ? wsh + "px" : wh + "px");
	}
}

function OpenRetailBanking(){
    window.open("https://online.bankpozitif.com.tr/retail/", "c_retail", "toolbar=0,top=0,left=0,width=1050,height=680,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,copyhistory=1");
}

function OpenCorporateBanking(){
    window.open("https://online.bankpozitif.com.tr/corp/", "c_corp", "toolbar=0,top=0,left=0,width=1050,height=680,location=0,directories=0,status=0,menubar=0,scrollbars=no,resizable=0,copyhistory=1");
}

function OpenVendorBanking(){
    window.open("https://online.bankpozitif.com.tr/bayii/", "c_vendor", "toolbar=0,top=20,left=100,width=795,height=580,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,copyhistory=1,titlebar=no");
}

function OpenMortgagePartner(){
    window.open("http://mortgagepartner.bankpozitif.com.tr", "partner", "toolbar=0,top=0,left=0,width=1024,height=768,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,copyhistory=1,titlebar=no");
}

var getQueryValue = function (req) {
	if(unescape(location.href).indexOf('?')!=-1){
		var twins = unescape(location.href).split('?')[1].split('&');
		var singles = [];
		for (var i=0; i<twins.length; i++){
			singles.push(twins[i].split('=')[0]);
			singles.push(twins[i].split('=')[1]);
		}
		return (singles.inArray(req)!=-1 ? singles[singles.inArray(req) + 1] : -1);
	}
}

function splashBoxClose(){
	splashBox.close();
}

var initFonbox = function() {
	if($('fonlar')){
		switch (getQueryValue('fonlar')) {
			case 'blikit':
				return fonAc('/plugins/pure_content/213', '/plugins/Fonlar/fonB' , 'fonlar', '930'), false;
			break;
			case 'adegisken':
				return fonAc('/plugins/pure_content/212', '/plugins/Fonlar/fonA' , 'fonlar', '930'), false;
			break;
			case 'btahvil':
				return fonAc('/plugins/pure_content/214', '/plugins/Fonlar/fonT' , 'fonlar', '930'), false;
			break;
		}
	}
};


var initCallme = function() {
	if($('cmbSplash')){
		switch (getQueryValue('callmeback')) {
			case 'seyahat':
			openCMB();
			return spAc('cmbSplash' , '600'), false;
			break;
		}
	}
};

var initKredibox = function() {
	if($('sp-hesapla-yatay')){
		switch (getQueryValue('splash')) {
			case 'faiz':
				return spAc('http://kredi.bankpozitif.com.tr/loantools/ratelist.aspx' , '800'), false;
			break;
			case 'anindakredi':
				return sphesapla(false, true), false;
			break;
			case 'kredihesap':
				return spAc('http://kredi.bankpozitif.com.tr/loantools/PaymentPlanCalculator.aspx' , '800'), false;
			break;
		}
	}
	if($('interest')){
		switch (getQueryValue('doviz')) {
			case 'doviz':
				return dovizAc('currency' , '600'), false;
			break;
		}
	}
	if($('sunum')){
		switch (getQueryValue('sunum')) {
			case 'sunum':
			return spAc('sunum' , '640'), false;
			break;
		}
	}
};


window.onload=function () {
	splashBox.init();
	initCallme();
	initKredibox();
	initFonbox();
	searchFocus('search-input', 'Arama');
	searchFocus('main-search-input', 'Arama');
	searchFocusEn('main-search-input-en', 'Search');
	searchFocusEn('search-input-en', 'Search');
	bltFocus('EMAIL', 'e-posta');
	$('accordion') ? acc() : void(0);
	externalLinks();
	getBgSize();
};

window.onresize = function() {
	getBgSize();
};