function Tracker(selector, action_code){
this.selector = selector;
this.action_code = action_code;
}
//***************************************************************
//* Mapeia os eventos para que seja gerado o log de estatistica *
//***************************************************************
$(document).ready(function(){
$("#link_empresa").click(function(){
SaveStatistic("1","");
return true;
});
$(".LogBusca a").click(function(){
SaveStatistic("15",this.id);
return true;
});
if(loadGuest()=="")
{
var guest_name = 'teste de carga';//prompt("Nome do usuario","");
saveGuest(guest_name);
}
});
//********************************************************
//* Salva a informação necessária no superpanel via ajax *
//********************************************************
function SaveStatistic(action_code,extra)
{
$.getJSON("http://" + service_url + "/index/save-statistic","action_code="+action_code+"&extra="+extra+"&reference="+client_id+"&domain="+domain+"&guest="+loadGuest()+"&callback=?",function(data)
{
//alert(data.result); //<-Debug
});
}
function saveGuest(guest_name)
{
document.cookie="guest_name=" + escape(guest_name);
}
function loadGuest()
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf("guest_name=");
if (c_start!=-1)
{
c_start=c_start + "guest_name".length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return "";
}
function print_r(theObj){
if(theObj.constructor == Array ||
theObj.constructor == Object){
document.write("
")
for(var p in theObj){
if(theObj[p].constructor == Array||
theObj[p].constructor == Object){
document.write("- ["+p+"] => "+typeof(theObj)+"
");
document.write("")
print_r(theObj[p]);
document.write("
")
} else {
document.write("- ["+p+"] => "+theObj[p]+"
");
}
}
document.write("
")
}
}
var sp_client_id;
var sp_domain;
var sp_service_url;
var flag_mailing = false;
function initMailingMessage(s, u, d) {
sp_client_id = u;
sp_domain = d;
sp_service_url = s;
}
$(document).ready(function() {
$('.mailingForm').submit(function(formEvent) {
if (flag_mailing == false)
formEvent.preventDefault();
else {
flag_mailing = false;
return true;
}
url = 'http://' + sp_service_url + '/api/mailing/mail/?Account[reference]=' + sp_client_id + '&Account[website]=' + sp_domain + '&' + $(this).serialize();
$.ajax({
url: url + '&callback=?',
dataType: "jsonp",
async: false,
success: function(data)
{
if (data.success) {
$.cookie('guest_email',data.email,{expires: 2050-01-01}); // Expire Never
flag_mailing = true;
$('.mailingForm').submit();
} else
alert(data.error)
},
error: function() {
alert('Erro de comunicação com o SuperPanel');
}
})
})
})
/* Videos */
$(function() {
$('.sp-open-video, .thumb-video-play').click(function(e) {
e.stopImmediatePropagation();
var $rel = ($(this).hasClass('thumb-video-play')) ? $(this).parent().children('img.sp-open-video').attr('rel') : $(this).attr('rel');
$rel = $rel.split('|');
if($.isFunction(spOpenVideo)) {
spOpenVideo($rel);
} else {
window.open('SPClient/playVideo.php?service=' + $rel[0] + '&url=' + $rel[1] + '&title=' + $rel[2], '', 'width=670,height=410');
}
});
});