/*
 Remember define..
 
 <script type="text/javascript">var googleAnalyticsId = 'UA-123456-78';</script>
 
 ... with the real analytics id before load this script
*/

googleAnalyticsConfigVars = {id : (googleAnalyticsId) ? googleAnalyticsId : '',url : window.location.href.replace(/[\?\&]c=[a-zA-Z]?[a-zA-Z]\d{5}m\d{4}/i,""),p : {w : 'pilar-web',s : 'pilar-buscadores',a : 'pilar-afiliacion',v : 'pilar-portales-verticales',h : 'pilar-portales-horizontales',b : 'pilar-blogs',r : 'pilar-redes-sociales',e : 'pilar-emailing'}};
var _gaCamp={
get:function (){var re = new RegExp("(?:^| )__utmz=([^;]*)", "i");var matches = document.cookie.match(re);return matches && matches.length == 2 ? matches[1] : null;},
set:function (value,days){var date=new Date;d=document.domain.toString(); date.setTime(date.getTime() + (typeof days != "undefined" ? days : 3) * 24 * 60 * 60 * 1000);var expires = "; expires=" + date.toGMTString();document.cookie = '__utmz' + ("=" + value + expires + "; path=/; domain=."+d ); },
setSource:function(value){var ac=_gaCamp.get();if (ac && ac.match(/utmcsr/)) _gaCamp.set( ac.replace(/utmcsr=[^\|]*/,"utmcsr="+value) ); else _gaCamp.set(ac+"|utmcsr="+value);},
setName:function(value){var ac=_gaCamp.get();if (ac && ac.match(/utmccn/))_gaCamp.set( ac.replace(/utmccn=[^\|]*/, "utmccn="+value) );else _gaCamp.set("|utmccn="+value);},
setMedium:function(value){var ac=_gaCamp.get();if (ac && ac.match(/utmcmd/))_gaCamp.set( ac.replace(/utmcmd=[^\|]*/, "utmcmd="+value) );else _gaCamp.set("|utmcmd="+value);},
setTerm:function(value){var ac=_gaCamp.get();if (ac && ac.match(/utmctr/))_gaCamp.set( ac.replace(/utmctr=[^\|]*/, "utmctr="+value) );else _gaCamp.set("|utmctr="+value);},
setContent:function(value){var ac=_gaCamp.get();if (ac && ac.match(/utmcct/))_gaCamp.set( ac.replace(/utmcct=[^\|]*/, "utmcct="+value) );else _gaCamp.set("|utmcct="+value);},
i:[],init:function(f){_gaCamp.i.push(f);},launchInit:function(){for(var i=0;i<_gaCamp.i.length;i++)_gaCamp.i[i]();}
};_gaCamp.init(function () {var re = new RegExp( /[\?\&]c=(([a-zA-Z]?)([a-zA-Z]\d{5})(m\d{4}))/i );var matches = window.location.href.match(re); if (matches[0]) {_gaCamp.setSource(matches[3]);_gaCamp.setMedium((googleAnalyticsConfigVars.p[matches[2]]) ? googleAnalyticsConfigVars.p[matches[2]] : 'pilar-no-definido');_gaCamp.setName(matches[3]+matches[4]); }});
var _gaq = _gaq || [];
_gaq.push(['_setAccount', googleAnalyticsConfigVars.id ]);
_gaq.push(['_setCampMediumKey', 'c'],['_setCampSourceKey', 'c'],['_setCampNameKey', 'c']);
/*_gaq.push(['_initData']);
_gaq.push(function(){_gaCamp.launchInit();});*/
_gaq.push(['_trackPageview', googleAnalyticsConfigVars.url]);
(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();

// jquery!!!
if ($ != undefined) {
_gaUser = {
levels : ['no-vio-formulario','vio-formulario','intento-de-envio','lead'],
get:function (){var re = new RegExp("(?:^| )__utmul=([^;]*)", "i");var matches = document.cookie.match(re);return matches && matches.length == 2 ? matches[1] : null;},
set:function (value,days){var date=new Date;d=document.domain.toString(); date.setTime(date.getTime() + (typeof days != "undefined" ? days : 3) * 24 * 60 * 60 * 1000);var expires = "; expires=" + date.toGMTString();document.cookie = '__utmul' + ("=" + value + expires + "; path=/; domain=."+d ); },
noform : function (){ var c=_gaUser.get(); if (!c || c==0) { _gaUser.set(0); _gaq.push(['_setCustomVar', 5, 'nivel-de-conversion', _gaUser.levels[0], 2],  ['_trackEvent','none','none']); }},
viewform : function (){ var c=_gaUser.get(); if (!c || c<=1) { _gaUser.set(1); _gaq.push(['_setCustomVar', 5, 'nivel-de-conversion', _gaUser.levels[1], 2],  ['_trackEvent','none','none']); }},
submitform : function (){ var c=_gaUser.get(); if (!c || c<=2) { _gaUser.set(2); _gaq.push(['_setCustomVar', 5, 'nivel-de-conversion', _gaUser.levels[2], 2],  ['_trackEvent','none','none']); }},
lead : function (){ var c=_gaUser.get(); if (!c || c<=3) { _gaUser.set(3); _gaq.push(['_setCustomVar', 3, 'nivel-de-conversion', _gaUser.levels[3], 2],  ['_trackEvent','none','none']); }}
};

// Esto lanza automaticamente los tres primeros estados pero el estado "lead" hay que lanzarlo manualmente con "_gaUser.lead();"
$(document).ready(function(){
if ( $("form")[0] )	_gaUser.viewform()
else _gaUser.noform();
$("form").submit(function() { _gaUser.submitform(); } );
}); 

}
var trackLead = function ( idLead, CourseId, CourseName )
{
_gaq.push(['_addTrans',idLead,CourseName,'1.00']);
_gaq.push(['_addItem',idLead,CourseId,CourseName,'cupon',1,1]);                
_gaq.push(['_trackTrans']);
_gaUser.lead();
}

var trackLeadByType = function ( idLead, CourseId, CourseName, Type )
{
if( Type == '' || Type == undefined ){ Type = "cupon"; }
_gaq.push(['_addTrans',idLead,CourseName,'1.00']);
_gaq.push(['_addItem',idLead,CourseId,CourseName,Type,1,1]);                
_gaq.push(['_trackTrans']);
_gaUser.lead();
}
