var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var sendOmnitureCode = true;

var s_LPCtoGPCArray = new Array();
s_LPCtoGPCArray["Sigorta"]="Insurance";
s_LPCtoGPCArray["Mortgage"]="Mortgages";
s_LPCtoGPCArray["KOBİ Kredileri"]="Others";
s_LPCtoGPCArray["Ticari Krediler"]="Others";
s_LPCtoGPCArray["Leasing/Factoring"]="Others";
s_LPCtoGPCArray["Emeklilik"]="Others";
s_LPCtoGPCArray["Şubesiz"]="Others";
s_LPCtoGPCArray["KOBİ Bankacılığı"]="Others";
s_LPCtoGPCArray["Garanti Masters"]="Others";
s_LPCtoGPCArray["Ticari Bankacılık"]="Others";
s_LPCtoGPCArray["Kurumsal Bankacılık"]="Others";
s_LPCtoGPCArray["Yatırım"]="Others";
s_LPCtoGPCArray["Bireysel Krediler"]="Personal Loans";
s_LPCtoGPCArray["Kredi Kartları"]="PLCC";
s_LPCtoGPCArray["Bireysel Bankacılık"]="Savings/Deposits";
s_LPCtoGPCArray["Ana Sayfa"]="HomePage";
s_LPCtoGPCArray["Tablo/Hesap Makinesi"]="Others";
s_LPCtoGPCArray["Kampanya"]="Others";
s_LPCtoGPCArray["Garanti'yi Tanıyın"]="Company Information";
s_LPCtoGPCArray["İnsan Kaynakları"]="Others";
s_LPCtoGPCArray["Arama"]="Others";
s_LPCtoGPCArray["Yatırımcı İlişkileri"]="Others";
s_LPCtoGPCArray["Site Haritası"]="SiteMap";
s_LPCtoGPCArray["Haklı Müşteri Hattı"]="Customer Support";
s_LPCtoGPCArray["Güvenlik"]="Others";


function s_getGPC(s_theProductName){
	return typeof(s_LPCtoGPCArray[s_theProductName])!=UNDEFINED?s_LPCtoGPCArray[s_theProductName]:"";
}

/*** Custom Functions ***/
function s_getQueryParameter(s_param)
{
	var regexS = "[\\?&]"+s_param+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var tmpURL = window.location.href;
	var results = regex.exec( tmpURL );
	if( results == null )
		return undefined;
	else
		return results[1];
}

function s_addSlashes(s_addslash_params)
{
	var result="";

	for (var i in s_addslash_params)
	{
		if (s_addslash_params[i]=="") 
			break;
		result+="/"+s_addslash_params[i];
	}
	
	return result.length>0?result.substring(1):"";
}

function s_trimString(val,len)
{
	if (val.length > len)
	{
		tmp_oversize = val.length - len;
		return val.substr(0,(val.length/2)-(tmp_oversize/2)-2) + ".." + val.substr((val.length/2)+(tmp_oversize/2));
	}
	return val;
}

function replaceTurkish(input)
{
	var trChars = "ığüşöçİĞÜŞÖÇ";
	var ingChars = "igusocIGUSOC";
	var output = "";
	var lchar = "";
      var i = 0
      for( i = 0; i < input.length; i++ )
      {
       lchar = input.charAt(i);
	 if (trChars.indexOf(lchar) >= 0)
       {
        output += ingChars.charAt(trChars.indexOf(lchar));
       }
	 else
 	 {
        output += lchar;
	 }
      }
     return output;
}

function s_sendErrorInfo(errorDetail)
{
	// This will send a request to Omniture, i.e. extra cost (same as a page view request)
	var s=s_gi(s_account);
	s.usePlugins=false;

	s.dynamicAccountSelection=true;
	s.dynamicAccountList=s_dynamicAccountList;
	s.linkTrackVars="prop22,prop21,eVar22";

	s.prop21=errorDetail;
	s.prop22=errorDetail;
	s.eVar22=errorDetail;
		
	s.tl(obj,'o','Validation Error');
	s.usePlugins=true;
	s.linkTrackVars="";
	s.prop21=""
	s.prop22=""
	s.eVar22=""
}

function ControlVersion()
{
	var version;
	var axo;
	var e;

	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry

	try {
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} catch (e) {
	}

	if (!version)
	{
		try {
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} catch (e) {
		}
	}

	if (!version)
	{
		try {
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} catch (e) {
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer(){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");			
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			var versionRevision = descArray[3];
			if (versionRevision == "") {
				versionRevision = descArray[4];
			}
			if (versionRevision[0] == "d") {
				versionRevision = versionRevision.substring(1);
			} else if (versionRevision[0] == "r") {
				versionRevision = versionRevision.substring(1);
				if (versionRevision.indexOf("d") > 0) {
					versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
				}
			}
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) {
		flashVer = ControlVersion();
	}	
	return flashVer;
}
/*** End Custom Functions ***/


/*** Constants***/
var UNDEFINED = "undefined";
/*** Constants ***/


/*** Custom Insights configuration ***/
var tmpTitle=document.title;
if (typeof(s_pName) == UNDEFINED){
	if (tmpTitle.indexOf("Garanti Bankası >> Garanti'yi Tanıyın >> Garanti'den Haberler >> ŞubeSiz'den Yenilikler >>") == 0)
		tmpTitle = "Garanti Bankası >> Haberler >> ŞubeSiz " + tmpTitle.substring(88);
	else 	if (tmpTitle.indexOf("Garanti Bankası >> Garanti'yi Tanıyın >> Garanti'den Haberler >> Başarılar ve Ödüller >>") == 0)
		tmpTitle = "Garanti Bankası >> Haberler >> Ödüller " + tmpTitle.substring(86);
	else 	if (tmpTitle.indexOf("Garanti Bankası >> Garanti'yi Tanıyın >> Garanti'den Haberler >> Garanti Sanat >>") == 0)
		tmpTitle = "Garanti Bankası >> Haberler >> Sanat " + tmpTitle.substring(79);
	else 	if (tmpTitle.indexOf("Garanti Bankası >> Garanti'yi Tanıyın >> Garanti'den Haberler >> Kampanyalar >>") == 0)
		tmpTitle = "Garanti Bankası >> Haberler >> Kampanyalar " + tmpTitle.substring(77);
	else 	if (tmpTitle.indexOf("Garanti Bankası >> Garanti'yi Tanıyın >> Garanti'den Haberler >> Önemli Gelişmeler >>") == 0)
		tmpTitle = "Garanti Bankası >> Haberler >> Önemli " + tmpTitle.substring(83);
	else 	if (tmpTitle.indexOf("Garanti Bankası >> Garanti'yi Tanıyın >> Toplumsal Sorumluluk >> Kültür - Sanata Destek >>") == 0)
		tmpTitle = "Garanti Bankası >> Toplumsal Sorumluluk >> Sanat " + tmpTitle.substring(88);
	else 	if (tmpTitle.indexOf("Garanti Bankası >> Haklı Müşteri Hattı >> Sıkça Sorulan Sorular >>") == 0)
		tmpTitle = "Garanti Bankası >> HMH >> SSS " + tmpTitle.substring(64);

	s_pName = tmpTitle.indexOf(">>")!=-1?tmpTitle.substring(tmpTitle.indexOf(">>")+2).replace(/>>/gi,": "):" Ana Sayfa";
}
if (typeof(s_productType) == UNDEFINED){
	s_productType="";
	if (tmpTitle.indexOf(" : ") != -1){
		var tmpIndex = tmpTitle.substring(0,tmpTitle.lastIndexOf(" : ")).lastIndexOf(" : ");
		if (tmpIndex != -1)
			s_productType = tmpTitle.substring(tmpIndex+3);
	}
}
if (typeof(s_productCat) == UNDEFINED)
	s_productCat="";
if (typeof(s_featureName) == UNDEFINED)
	s_featureName="N.A.";
if (typeof(s_UID) == UNDEFINED)
	s_UID="";


s_prop1="CEE";															// Region
s_prop2="Turkey";														// Country	
s_prop3="Garanti";												// website name
s_prop4=typeof(s_prop4)==UNDEFINED?"Products":s_prop4;					// site section
// s_prop5=s_productCat;		// global product category
// s_prop6=s_productCat;		// local product category
s_prop5=typeof(s_prop5)==UNDEFINED?s_getGPC(s_productCat):s_prop5;  // global product category
s_prop6=typeof(s_prop6)==UNDEFINED?s_productCat:s_prop6; 		 // local product category
s_prop7=s_productType;
s_prop8="TR";
s_prop10=s_trimString(document.location.href,100);
s_prop30=s_UID;
s_prop24=GetSwfVer();

s_eVar2=s_prop2;
s_eVar3=s_prop3;
s_eVar4=s_prop8;
s_eVar5=s_prop5;
s_eVar6=s_prop6;
s_eVar7=s_prop7;
s_eVar30=s_prop30;
s_eVar24=s_prop24;

if(s_productType!=""&&s_productCat!="")
	s_products=s_productCat+";"+s_productType;

s_prop22=typeof(s_prop21)!=UNDEFINED?s_prop21:"";
s_eVar21=typeof(s_prop21)!=UNDEFINED?s_prop21:"";

if (typeof(s_pageState)!=UNDEFINED)
{
	switch(s_pageState)
	{
		case "page not found":
			s_pageType="errorPage";
			s_pageName="";
		break;
		
		case "server error":
			s_pName=s_pName+"[error "+s_errorId+"]";
			if (s_errorId == "404")
			{
				s_pageType="errorPage";
				s_pageName="";
			}
		break;
			
		default:
	}
}
/*** End Custom Insights configuration ***/


/*** Other Omniture variables ***/
s_account="gemoneydtr";
s_prodAccount="gemoneystrgaranti";
s_prodUrls="www.garanti.com.tr,arama.garanti.com.tr,sube.garanti.com.tr,www.paragaranti.com,form.garanti.com.tr,demo.garanti.com.tr,finans.tr.msn.com";
s_testUrls="localhost";

s_currencyCode="TRY";
s_linkInternalFilters="javascript:,"+s_testUrls+","+s_prodUrls;
s_dynamicAccountSelection=true;
s_dynamicAccountList=s_prodAccount+"="+s_prodUrls;

s_server=location.host.toLowerCase();

/* Site Section */
s_channel= s_prop2 + ":" + s_prop3;

// PageName Specific code
s_pageName=s_prop3+" :";
s_pageName+=s_pName
s_pageName = replaceTurkish(s_pageName);
s_pageName=s_trimString(s_pageName, 80);

s_prop9=typeof(s_pageType)!=UNDEFINED?"":s_pageName+"("+s_prop8+")";

/* Hierarchy Variables */

s_hier1=s_addSlashes(new Array(s_prop1,s_prop2,s_prop3,s_prop4,s_prop5,s_prop7,s_pageName));
s_hier2=s_addSlashes(new Array(s_prop1,s_prop2,s_prop3,s_prop5,s_pageName));
s_hier3=s_addSlashes(new Array(s_prop2,s_prop3,s_prop4,s_prop6,s_prop7,s_pageName));
s_hier4=s_pageName; // local hierarchy

s_cookieDomainPeriods=location.host.match(/\.(co(m?)|net)\.(in|sg|ph|tr)/)?3:2;

//s_visitorNamespace="garanti"
s_dc=112

s_trackingServer="webstat.garanti.com.tr"
s_trackingServerSecure="webstats.garanti.com.tr"
s_vmk="483ED314"


/*** End Other Omniture variables ***/

/*** Custom functions ***/
/* Custom Function - Run plugin functions 10.04.2008'de Nicolas'tan gelen kod ile degistirildi*/
function runLocalOmniturePluginFunctions()

{

       s.campaignStackingExpires = 60; //in days
       s.campaignStackingCount = 5; //number of campaign codes to keep in cache
       s.campaignStackingCookieName = 's_cs'; //name of cookie that is used
       s.campaignStackingDelimiter = '>';
       s.campaignStackingSuccessEvent = 'event2';

       s.campaign=s.getValOnce(s.getQueryParam('gbid1'),'s_gbid1');

       if(typeof(s_eVar1)=="undefined")
              s.eVar1=s.getQueryParam('gbid2');
       s.eVar9 = s.eVar1
       s.eVar10=s.campaignStacking();       

       /* Form Analysis Config */
       // s.formList="";
       // s.trackFormList=false;
       // s.trackPageName=true;
       // s.useCommerce=true;
       // s.varUsed="eVar20,prop20";
       // s.linkTrackVars="prop3,prop9,prop20,prop22,eVar20";
       // s.eventList="event10"; Abandon,Success,Error
       // s.setupFormAnalysis();

       s.prop31=(typeof(s.prop19)!="undefined"&&s.prop19!=""?s.prop19+" - ":"")+ s.pageName;
       s.prop32=(typeof(s.campaign)!="undefined"&&s.campaign!=""?s.campaign+" - ":"")+ s.pageName;
       s.prop34=(typeof(s.eVar34)!="undefined"&&s.eVar34!=""?s.eVar34+" - ":"")+ s.pageName;
       s.prop35=(typeof(s.eVar1)!="undefined"&&s.eVar1!=""?s.eVar1+" - ":"")+ s.pageName;
}


/* Custom Function - Instanciate oo Omniture code based on non-oo code or a default value*/
function setOV(name,defaultVal)
{
	if(typeof(window['s_'+name])!=UNDEFINED)
	{
		if(typeof(window['s_'+name])=="string")
		{
			eval("s."+name+"='"+eval('s_'+name+'.replace(/[\'\"]/g,\"\")')+"'");
		}
		else
		{
			eval("s."+name+"=s_"+name);
		}
	}
	else
	{
		if(typeof(defaultVal)=="string")
		{
			if(defaultVal!="")
			{
				eval("s."+name+"='"+defaultVal.replace(/[\'\"]/g,'')+"'");
			}
			else
			{
				eval("s."+name+"=''");
			}
		}
		else if(typeof(defaultVal)!=UNDEFINED)
		{
			eval("s."+name+"="+defaultVal);
		}
	}
}

/* Custom Function - triggers the instanciation of all oo omniture variables */
function setPrevDefinedOmniVars(){
	var k;
	for(k=1;k<=50;k++){
		setOV('prop'+k,"");
		setOV('eVar'+k,"");
	}
	for(k=1;k<=5;k++){
		setOV('hier'+k,"");
	}
	setOV('pageName',"");
	setOV('channel',"");
	setOV('products',"");
	setOV('zip',"");
	setOV('state',"");
	setOV('events',"");
	setOV('currencyCode',"USD");
	setOV('trackDownloadLinks',true);
	setOV('trackExternalLinks',true);
	setOV('trackInlineStats',true);
	setOV('linkDownloadFileTypes',"exe,zip,wav,mp3,mov,mpg,avi,wmv,doc,pdf,xls,flv");
	setOV('linkLeaveQueryString',true);
	setOV('linkTrackVars',"None");
	setOV('linkTrackEvents',"None");
	setOV('purchaseID');
	setOV('pageType');
	setOV('linkInternalFilters',"javascript:");
	setOV('dynamicAccountSelection', true);
	setOV('dynamicAccountList');
	setOV('dynamicAccountMatch');
	setOV('visitorNamespace');
	setOV('dc');
	setOV('trackingServer');
	setOV('trackingServerSecure');
	setOV('vmk');
	setOV('server');
	setOV('cookieDomainPeriods');
	setOV('charSet','UTF-8');
}
