var ServiceName = new Array(
"winks",
"emoticons",
"mood-avatars",
"buddy-bubbles",
"video-winks",
"bigemos",
"invitation",
"tv",
"firenudge",

"guinos",
"clin-d-oeil",

"emoticonos",
"emoticones",

"mood-avatares",

"video-guinos",
"clin-d-oeil-video",

"invitacion",
"invito",
"invitacao",
"invitation1n",

"facebook",
"immailsign",
 
"Games",
"Giochi",
"Jeux",
"Jogos",
"Juego",

"Pranks",
"Pieges",
"Scherzi",
"Brincadeiras",
"Travesuras"
);
var ServiceUid = new Array(
"11D7568F-2919-4C92-A11E-14C8A69FE7E6",
"5AFD7C4B-1766-4AB3-99B8-51810FE9566A",
"DC7B92AB-9DE6-4951-A328-623F4368019B",
"181DA7C9-EBAE-4132-A10C-7394C318D726",
"554C7505-F5C0-43DC-B741-8FA59DF9ED83",
"FEC1396D-F5C5-484C-BE04-B6D22AD8A44D",
"098164D2-0730-431E-9428-BEE5EB59B07B",
"D51FC335-D9FA-491A-937B-E4E2BCC5FD67",
"F04D3C9C-E00D-4AAA-9CA5-F936959BBB0F",

"11D7568F-2919-4C92-A11E-14C8A69FE7E6",
"11D7568F-2919-4C92-A11E-14C8A69FE7E6",

"5AFD7C4B-1766-4AB3-99B8-51810FE9566A",
"5AFD7C4B-1766-4AB3-99B8-51810FE9566A",

"DC7B92AB-9DE6-4951-A328-623F4368019B",

"554C7505-F5C0-43DC-B741-8FA59DF9ED83",
"554C7505-F5C0-43DC-B741-8FA59DF9ED83",

"098164D2-0730-431E-9428-BEE5EB59B07B",
"098164D2-0730-431E-9428-BEE5EB59B07B",
"098164D2-0730-431E-9428-BEE5EB59B07B",
"4289589B-45D0-4B72-95AA-1E384561F80B",

"96EAB1FA-CF5E-4BFB-A86E-3373893A955E",
"371B947A-44DA-4D60-8FAB-EC66492143F6",

"360C42F8-0A60-480A-90C3-59163AF80001",
"360C42F8-0A60-480A-90C3-59163AF80001",
"360C42F8-0A60-480A-90C3-59163AF80001",
"360C42F8-0A60-480A-90C3-59163AF80001",
"360C42F8-0A60-480A-90C3-59163AF80001",

"D65E0698-44B4-45E0-AD85-D24CF724918D",
"D65E0698-44B4-45E0-AD85-D24CF724918D",
"D65E0698-44B4-45E0-AD85-D24CF724918D",
"D65E0698-44B4-45E0-AD85-D24CF724918D",
"D65E0698-44B4-45E0-AD85-D24CF724918D"  
);
var ref;
var uid;
var downloadLink = false;
function getRef(){
//var ref;
	ref=getQueryVariable('ref');
	if ((ref==null)||(ref==''))
	ref = Get_Cookie('ref');
	else 
	Set_Cookie( 'ref', ref, 10, '/', '.iminent.com', '');
	return ref;
}

function getUid(){
//var uid;
	uid=getQueryVariable('uid');
	if ((uid==null)||(uid==''))
	uid = Get_Cookie('uid');
	else 
	Set_Cookie( 'uid', uid, 10, '/', '.iminent.com', '');
	return uid;
}

function getBk(){
var bk;
	bk = Get_Cookie('IM.bk');
	if  ((bk!=null)&&(bk!='')) 	return bk;
	else
	{ 
	bk=randomString();
	Set_Cookie( 'IM.bk', bk, 1, '/', '.iminent.com', '' );
	return bk;
	}
}

function getServiceUid()
{ 
	var sUid = '2ab234df-8b86-471a-a544-9056516d64ce';
 
	if (getQueryVariable('v')=='true')
	{
		var folder=getUriFolder().toLowerCase();
		for (var i=0; i<ServiceName.length; i++) {
			if (ServiceName[i]==folder)	{
				sUid = ServiceUid[i];
			}
		}
		Set_Cookie( 'iService', sUid, 10, '/', '.iminent.com', '');
	}
	else
	{
		var iService = Get_Cookie('iService');
		if ( (iService!=null) && (iService.length=='36') ) 
		{
		sUid = iService;
		}
	}
	return sUid;
}

function randomString() {
	var chars = "0123456789abcdefghijklmnopqrstuvwxyz";
	var string_length = 24;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function insertPecker()
{
try {
		document.getElementById('peckerDiv').innerHTML= '<IFRAME src="http://logevent.iminent.com/cook/pecker.aspx?dwnl=true&dwnlUrl='+getDownloadLink()+'" width="1" height="1" scrolling="no" frameborder="0"></IFRAME>';
    }catch (e) {}
}

function insertSwf(swfPath,bannerDiv,width, height)
{
var swf='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ID="homer" name="homer" WIDTH="'+width+'" HEIGHT="'+height+'" ALIGN="" data="'+swfPath+'"  wmode="opaque">'
+'<PARAM NAME=movie VALUE="'+swfPath+'">'
+'<PARAM NAME=quality VALUE=high>'
+'<PARAM NAME=bgcolor VALUE=#FFFFFF>'	
+'<param name=wmode value=opaque>'
+'<EMBED src="'+swfPath+'" quality=high bgcolor=#FFFFFF  WIDTH="'+width+'" HEIGHT="'+height+'" swLiveConnect=true ID="homer" NAME="homer" ALIGN=""  TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" wmode=opaque></EMBED>';

var lg= '<div id="logodrop2"><a href="'+getDownloadLink()+'" target="_self" onclick="insertPecker();"><img src="http://www.iminent.com/wp-images/pixel.gif" height="405" width="775" /></a></div>';
try {
document.getElementById(bannerDiv).innerHTML = lg+swf;
//alert(document.getElementById('homephoto').innerHTML);
    }catch (e) {}
}

function getCustomLink(base_url, link_id, askedRef) {
	var nodeLink = document.getElementById(link_id);
	var theLink = base_url+(askedRef == true ? '?ref='+Get_Cookie('IM.REF') : '');
	nodeLink.href = theLink;
}
		
function getDownloadLink(){
var link_to_return;
	if(!downloadLink || downloadLink.length < 10)
	{
		
		if ((window.location.href.indexOf('.iminent.com/front/')!=-1) || (window.location.href.indexOf('pub.iminent.com') !=-1)){
			var link_root = 'http://dwnl.iminent.com'; // Define root for pages that have /front/ in the url
		}
		else{
			var link_root='http://dwnl1st.iminent.com'; // Define root for all the other cases	
		}
		var link_extend  = getServiceUid(); // Define identification of "mother site"
		var link_ref = getRef(); // Define reference (if no get, this var aqual "noref")
		if (link_ref==null) link_ref='noref';
		var link_content_uid = getUid();
		if (link_content_uid==null) link_content_uid='00000000-0000-0000-0000-000000000000';
		var bagkey = getBk(); // Recuperation of the user session id, the goal is to be able to trace him
		// Concaténation of all those stuff
		link_to_return = link_root+'/'+link_extend+'/'+link_ref+'/'+link_content_uid+'/IMBoosterSetup.'+bagkey+'.exe';
		downloadLink = link_to_return;
	}
	else
		link_to_return = downloadLink;
	return link_to_return;
}

function insertImageLink(divname,link,picture)
{
try {
document.getElementById(divname).innerHTML= '<div id="peckerDiv"></div><a href="'+link+'"><br /><img src="'+picture+'" alt="" onclick="insertPecker();"/></a>';
}catch (e) {}
}

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}
function Set_Cookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}

function getQueryVariable(n) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0].toLowerCase() == n.toLowerCase()) {
            return pair[1];
        }
    }
    return "";
}	

function getUriFolder() {
    var query = window.location.pathname;
    var vars = query.split("/");
   if (vars.length>2) {
        return vars[1];
    }
    return "";
}	
//alert(Get_Cookie('PHPSESSID'));