﻿if(navigator.userAgent.indexOf('Mac')==-1&&top!=self)top.location=self.location;


var mimg=new Array(6);
	mimg['konta']			='/retail/img/topmenu/over/konta.gif';
	mimg['karty']			='/retail/img/topmenu/over/karty.gif';
	mimg['inwestycje']		='/retail/img/topmenu/over/inwestycje.gif';
	mimg['kredyty']			='/retail/img/topmenu/over/kredyty.gif';
	mimg['ubezpieczenia']	='/retail/img/topmenu/over/ubezpieczenia.gif';
	mimg['uslugi']			='/retail/img/topmenu/over/uslugi.gif';

	for(i in mimg) {
		mlt=mimg[i].length;
		if(mlt>10) {
			mimg[i+'.gif']=new Image();
			mimg[i+'.gif'].src=mimg[i];
		}
	}


function footer() {
	if(!document.getElementById('footer')||!document.getElementById('main_container'))return true;
	var helper=0;
	if(document.getElementById('footer').style.position=='absolute')helper=110;
	if(document.documentElement.clientHeight>document.getElementById('main_container').offsetHeight+helper) {
		document.getElementById('footer').style.position='absolute';
		document.getElementById('footer').style.bottom='0';
		document.getElementById('footer').style.left='0';
		document.getElementById('footer').style.width='975px';
	}else{
		document.getElementById('footer').style.position='static';
	}
}

function getLink(what) {
	var dloc=new String(what);
	return dloc.substring(dloc.lastIndexOf("/"));
	return dloc.split('#')[0];
}

var strzalki=new Array();

function addOff() {
	//	 jquery  -> prepend ? 
	var rmnu=document.getElementById('rmenu');
	var radd='<li><a href="/PLGCB/JSO/signoff/SummaryRecord.do?logOff=true" style="color:#f00;">Wyloguj</a></li>';
	rmnu.innerHTML=radd+rmnu.innerHTML;
}

function rmenu_init(){
	if(_iCu)
		addOff();
	var clipLi=document.getElementById('rmenu').getElementsByTagName('li');
	var count2=0;
	for(var count=0; count<clipLi.length; count++) {
		if(clipLi[count].childNodes[2]) {
			if(clipLi[count].childNodes[2].nodeName=='UL') {
				if(clipLi[count].parentNode.parentNode.nodeName=='LI') {
					idek='sub_'+clipLi[count].parentNode.parentNode.childNodes[0].id;
					klacz='sub_rmenu_ul';
					kontent=clipLi[count].childNodes[2].innerHTML;
					clipLi[count].childNodes[2].innerHTML=makeEmNice(kontent,idek+(count2+1));
					clipLi[count].childNodes[0].style.backgroundImage='url(/retail/img/arrow-r.jpg)';
					strzalki[strzalki.length]=clipLi[count].childNodes[0];
					count2++;
				} else  {
					idek='rmenu'+count;
					klacz='rmenu_ul';
				}
				clipLi[count].childNodes[2].style.display='none';
				clipLi[count].childNodes[2].id=idek+count2+'_ul';
				clipLi[count].childNodes[2].className=klacz;
				clipLi[count].childNodes[0].id=idek+count2;
				clipLi[count].childNodes[0].className=klacz+'_a';
				clipLi[count].childNodes[0].onclick = function () {hShow(this.id); return false;};
				clipLi[count].childNodes[0].onfocus = function () {this.blur();};
			}
		}
	}
	document.getElementById('rmenu').style.display='block';
	footer();
}

function reset_strzalki() {
	for(ax=0;ax<strzalki.length;ax++)strzalki[ax].style.backgroundImage='url(/retail/img/arrow-r.jpg)';
}

function hShow(who) {
	reset_strzalki();
	dst=document.getElementById(who+'_ul').style;
	dsa=document.getElementById(who).style;
	cur=dst.display;
	for(i=0;i<document.getElementById('rmenu').getElementsByTagName('ul').length;i++) {
		document.getElementById('rmenu').getElementsByTagName('ul')[i].style.display='none';
	}
	if(cur=='block') {
		dst.display='none';
		if(who.indexOf('sub_')==0) {
			dsa.backgroundImage='url(/retail/img/arrow-r.jpg)';
		}
	} else  {
		dst.display='block';
		if(who.indexOf('sub_')==0) {
			dsa.backgroundImage='url(/retail/img/arrow-d.jpg)';
		}
	}
	if(who.indexOf('sub_')==0) {
		parka='rmenu'+who.substring(9,(who.length-1))+'_ul';
		document.getElementById(parka).style.display='block';
	}
	footer();
}

function pokazDefault() {
	clink=getLink(window.location);
	clink=clink.split('&')[0];
	asy=document.getElementById('rmenu').getElementsByTagName('A');
	asyl=asy.length;
	for(aa=0;aa<asyl;aa++) {
		if(getLink(asy[aa].href)==clink)
		{
			var str=window.location.search;
			str=str.indexOf("cg_");
			if(str!="-1") asy[aa].style.color="#554015";
			else asy[aa].style.color="#3399cc";
		asy[aa].style.textDecoration="none";
		}
		if(getLink(asy[aa].href)==clink&&asy[aa].id.indexOf('sub_')==-1&&asy[aa].id!='') {
			hShow(asy[aa].id);
		} else {
			rod=asy[aa].parentNode.parentNode;
			if(getLink(asy[aa].href)==clink&&rod&&rod.style.display=='none') {
				rod.style.display='block';
			}
		}
	}
	footer();
}

function makeEmNice(kontent,idek) {
	rmenu_start='\
	 <div class="rmenu_czopek"><img src="/retail/img/rmenu_outer.gif" alt="rmenu" /></div>\
	 <div class="rmenu_keeper">\
	  <div class="rmenu_top"><a href="#" onclick="hShow(\''+idek+'\');return false;" onfocus="this.blur();"><img src="/retail/img/rmenu_x.gif" alt="rmenu" /></a></div>\
	   <div class="rmenu_rbg"><div class="rmenu_left">\
	   <div class="rmenu_dots">&nbsp;</div>';
	
	rmenu_end='</div>\
	  <div class="rmenu_bleft">&nbsp;</div>\
	  <div class="rmenu_b">&nbsp;</div>\
	  <div class="rmenu_bright">&nbsp;</div>\
	 </div>';
	
	return rmenu_start+kontent+rmenu_end;
}

function hov(item,on) {
	cursrc=new String(item.src);
	cursrc=cursrc.substring(cursrc.lastIndexOf('/')+1);
	if (on) 
		item.src=mimg[cursrc].src;
	else 
		item.src="/retail/img/topmenu/"+cursrc;
}



var prid = '';
var toploc = new String(window.location.href)
toploc=toploc.toLowerCase();
if(toploc.indexOf("prid=")>-1){
	prid = toploc.substring(toploc.indexOf("prid=")+5);
	if(prid.indexOf("&")>0)prid = prid.substring(0,prid.indexOf("&"));
	if(prid.indexOf("#")>0)prid = prid.substring(0,prid.indexOf("#"));
}


function e_form() {
	if(prid)
		wups('/zagranica/e_form/index.htm?prID='+prid,860,720);	
	else 
		wups('/zagranica/e_form/index.htm',860,720);	
}

function formUp() {
	var erDiv=document.getElementById('error_content');
	var hdDiv=document.getElementById('error_div');
	if(erDiv) {
		doTop=document.documentElement.scrollTop+(screen.availHeight/5)+150;
		erDiv.style.top=doTop+'px';
		hdDiv.style.top=document.documentElement.scrollTop+'px';
		if(erDiv.style.display=='none') {
			erDiv.style.display='block';
			hdDiv.style.display='block';
		}else {
			erDiv.style.display='none';
			hdDiv.style.display='none';
		}
	}
}


// *****
function navBars() {
	var navAs=document.getElementById('customer1').getElementsByTagName('A');
	var logincnt=new String();
	logincnt+='<div id="login_l" style="font-size:10px;">&nbsp;</div><div id="login_m">';
	for(var na=0,navAsl=navAs.length;na<navAsl;na++)logincnt+='<a href="'+navAs[na].href+'" onclick="this.blur();">'+ucWords(navAs[na].innerHTML)+'</a>';
	logincnt+='</div><div id="login_r">&nbsp;</div><div class="clearer">&nbsp;</div>';
	document.getElementById('login').innerHTML=logincnt;
	document.getElementById('login').style.borderTop='none';
	document.getElementById('login').style.marginBottom='10px';
	document.getElementById('login').style.height='32px';
	if(window.klT=='G')document.getElementById('login').style.backgroundImage="url('/JFP/images/top_transmenu_bggold.gif')";
	else if(window.klT=='CB')document.getElementById('login').style.backgroundImage="url('/JFP/images/top_transmenu_bgcb.gif')";
	else document.getElementById('login').style.backgroundImage="url('/JFP/images/top_transmenu_bg.gif')";
}

//****
function changeiCu() {
	var signond=document.getElementById('sign_on');
	var llogind=document.getElementById('l_login');
	if(_iCu) {
		if(signond)signond.innerHTML='<div class="sign_on" style="width:auto;"><a href="/PLGCB/JSO/signoff/SummaryRecord.do?logOff=true"><img src="/retail/img/im_signoff_tr.gif" alt="Sign off" /></a></div><img src="/retail/img/cmn_cbol.gif" alt="Citibank Online" class="sign_img"/>';
		if(llogind)llogind.innerHTML='<a href="/PLGCB/JSO/signoff/SummaryRecord.do?logOff=true"><img src="/retail/img/im_signoff_l.gif" alt="Sign off" /></a>';
	}
	if(signond)signond.style.display='block';	
	if(llogind)llogind.style.display='block';	
}

//********
function addPR(lnk) {
	if(!prid) {
		var cPar=getUParam('content');
		if(cPar=='karty'||cPar=='k_student'||cPar=='k_citibank_plus'||cPar=='k_citibank_lot'||cPar=='k_citibank_bp')prid=10003014;
	}
	if(prid&&lnk) {
		if(lnk.href.indexOf('javascript')==-1&&lnk.href.indexOf('prID')==-1&&lnk.href.indexOf('prid')==-1){
			var doklej = '';
			if ( lnk.href.indexOf('?')>=0 ) {
				doklej += '&prid=' + prid;
			} else {
				doklej += '?prid=' + prid;
			}
			if ( lnk.href.indexOf('#') >=0 ) {
				var hashPosition = lnk.href.indexOf('#');
				if ( hashPosition > 0 ) {		//	nie doklejamy nic dla linków rozpoczynajacych sie od hasha (np taber)
					lnk.href = lnk.href.slice(0, hashPosition) + doklej + lnk.href.slice(hashPosition);
				}
			} else {
				lnk.href += doklej;
			}
		}
	}
}


function resetForms() {
	if(document.forms) {
		for(var nform=0,lform=document.forms.length;nform<lform;nform++) {
			document.forms[nform].reset();
		}
	}
}

function loginLink(side,locale,place) {
	var loc;
	if(locale=='pl_PL') loc='PL';
	else if(locale=='en_PL') loc='EN';
	var pageTracker = _gat._getTracker("UA-1972630-12");
	pageTracker._trackPageview('logowanie_'+side+'_'+loc+'_'+place);
	var loc = location.hostname;
	if(loc=='online.citibank.pl') loc = 'www.'+loc;
	if ( locale == 'pl_PL' ) {
		window.top.location.href="https://"+loc+"/copy.do?content=logowanie_pl";
	} else {
		window.top.location.href="https://"+loc+"/copy.do?content=logowanie_en";
	}
};
function login(lan) {
	var locale='pl_PL';
	if(lan=='en')locale='en_PL';
	loginLink('login', locale, 'none');
	//window.top.location.href="https://"+location.hostname+"/PLGCB/JPS/portal/LocaleSwitch.do?locale="+locale;
};


function kursy_walut() {
	if(_iCu	&& document.getElementById('kursy_walut') && document.getElementById('link_liINVESTMENTSERVICES'))
		document.getElementById('kursy_walut').href='/PLGCB/jba/fxi/InitializeSubApp.do?TTC=29';
}

 

function addDBL() {
	var DBLskr=document.createElement('IFRAME');
	var prot=self.location.protocol;
	var sitid='mcplci02';
	if(getUParam('content')=='karty')sitid='mcplci03';
	var axel = Math.random()+""; 
	var a = axel * 10000000000000;
	DBLskr.setAttribute('src',''+prot+'//fls.doubleclick.net/activityi;src=1113351;type=mcplciti;cat='+sitid+';ord=1;num='+a+'?');
	DBLskr.setAttribute('width','1');
	DBLskr.setAttribute('height','1');
	DBLskr.setAttribute('frameborder','0');
	document.getElementById('DBLskrheadquaters').appendChild(DBLskr);
}



function inits() {
	changeiCu();
	if(document.getElementById('footer'))footer();
	
	if(document.getElementById('rmenu')) {
		rmenu_init();
		pokazDefault();
	}
	
	if(document.getElementById('username')&&document.getElementById('customer1'))navBars();
	if(document.getElementById('login'))document.getElementById('login').style.display='block';

	kursy_walut();

	resetForms();

	if(document.getElementById('gaheadquaters')&&false) {
		addGAscr();
		checkGA();
	}

	if (document.location.protocol != 'https:'||true)	
		//get_gemius_code();
	
	if (document.getElementById('mapka')) 
		swapC(1);
	
	if ((getUParam('content')=='karty'||getUParam('content')=='home')&&self.location.protocol=='http:') 
		addDBL();
}

function showHide(objId){
	if (document.getElementById(objId)){
		var elId=document.getElementById(objId);
		if(elId.style.display=='block'){
			elId.style.display='none';
		}
		else{
			elId.style.display='block';
		}
	}
}

function dispLayer() { document.getElementById('error_content').style.display='block'; }

// go go ;) 
$(function() {
if(window.location.href.slice(-14)=='przenies_konto') $('#content h1').after('<div style="position:relative;"><div style="background:#fff;position:absolute;height: 40px;width:400px"></div></div>');
	inits();
	$(window).resize( function() {
		footer();
	});
	$(window).load(function() { 
		footer();
	});

	//	manage links
	var params="menubar=no, toolbar=no, location=yes, left=30, top=20, scrollbars=yes, status=yes, resizeable=yes, width="+(screen.availWidth-100)+", height="+(screen.availHeight-70)+" ";
	$('a').each( function() {
		if ( $(this).attr('href') && $(this).attr('href').indexOf('.pdf') != -1 ) {
			//	dodajp arametr antycashowy jesli .pdf nie ma zadnych parametrow juz... i nie jest kursami ;)
			if ( $(this).attr('href').indexOf('?') == -1 && $(this).attr('href').indexOf('kursy/pdf') == -1 ) {
				var d = new Date();
				$(this).attr('href', $.trim($(this).attr('href')) + '?a=' + d.getTime());
			}
			$(this).click( function() {
				//alert('pdf');
				window.open( $(this).attr('href'), '_blank', params );
				return false; 
			});
		}
		//	opacityOnHover
		//	odnosnikom z klasa opacityOnHover dodajemy zdarzeni hover z opacity 70%
		if ( $(this).hasClass('opacityOnHover') ) {
			$(this).hover( function() {
				$(this).fadeTo(100,0.7);
					},function() {
				$(this).fadeTo(100,1);
			});
		}
		$(this).focus(function() { $(this).blur(); });
		
		//	przekazywanie prid
		if ( !$(this).parent().parent().hasClass('taber_menu') &&
			  $(this).attr('href') && $(this).attr('href').charAt(0) != '#' 
			  && ( !$(this).attr('rel') || $(this).attr('rel').indexOf('external')<0 )
			) { 
			addPR( $(this).get(0) );
		}
		
		//	/PLGCB
		if(_iCu) {
			var href = $(this).attr('href');
			href = href.replace(/\/(page|base|copy)\.do/, '/PLGCB/$1.do');
			$(this).attr('href', href);
		}
	});
	
	$('a[rel*="external"]').live( 'click', function() {
		if ( window.location.host == 'onlineuat.citibank.pl' ) {
			if ( confirm('Próbujesz otworzyć stronę '+$(this).attr('href')+'. Czy chcesz kontynuować?') ) {
				window.open( $(this).attr('href') );
			}
		} else {
				window.open( $(this).attr('href') );
		}
		return false;
	});
	
	// *****
	//przekierowanie dla linkow kontaktowych
	if (_iCu) { $("a.contact_link").attr("href",'/PLGCB/jba/mc/InitializeSubApp.do?TTC=267'); }

	// *****
	
	
});
