//parse query
var scripts = document.getElementsByTagName('script');
var myScript = scripts[ scripts.length - 1 ];

var queryString = myScript.src.replace(/^[^\?]+\??/,'');

var params = parseQuery( queryString );

function parseQuery ( query ) {
   var Params = new Object ();
   if ( ! query ) return Params; // return empty object
   var Pairs = query.split(/[;&]/);
   for ( var i = 0; i < Pairs.length; i++ ) {
      var KeyVal = Pairs[i].split('=');
      if ( ! KeyVal || KeyVal.length != 2 ) continue;
      var key = unescape( KeyVal[0] );
      var val = unescape( KeyVal[1] );
      val = val.replace(/\+/g, ' ');
      Params[key] = val;
   }
   return Params;
}
//

var cbtid = 'noid';
var dtname1 = "visitors_table_topfr";
var dtname2 = "cbtid_table_topfr";
var referring_url = escape(document.referrer);
var orig_url = getCookie("origurl");
var currentpage_url = escape(document.location.href);

if(referring_url == '')
	referring_url = "No_Referring_URL";
   
if(orig_url == '')
{
	setCookie("origurl", referring_url, 60);
	orig_url = referring_url;
}	

//go to new page
function gotopage(URL)
{			
	if(URL == 'webinarreplay')
	{
	   xss_ajax("webinarreplay", "webinarreplay");
	}
	else if(URL == 'webinarreplay2')
	{
	   xss_ajax("webinarreplay2", "webinarreplay2");
	}
	else if(URL == 'webinarpart2')
	{
	  xss_ajax("webinarpart2", "webinarpart2");
	}
	else if(URL == 'forexmentor')
	{
	  xss_ajax("http://www.jdoqocy.com/p298ft1zt0GKNJONPIGIHKOQNKL?sid=tfr", "forexmentor");
	}
	else if(URL == 'craigharris')
	{
	  xss_ajax("craigharris", "craigharris");
	}
	return('');
}
//

//store tracking info
var pageid = params['pageid'];
var tm = params['tm'];
var em = params['em'];
if(pageid != "mainpage")
    gotopage(pageid,tm,em);
else
	xss_ajax("", pageid);
//

//start get cbtid
function xss_ajax(vendurl, vendname, tm, em) 
{ 
	 var script_id = null;
     var script = document.createElement('script');
     script.setAttribute('type', 'text/javascript');
     script.setAttribute('src', "http://www.cbfootprint.com/cbfttrack/setmaininfo.php?vendorname=" + vendname + "&vis_table=" + dtname1 + "&cbtid_table=" + dtname2 + "&vis_reff=" + referring_url + "&orig_url=" + orig_url + "&currentpage_url=" + currentpage_url + "&vendurl=" + vendurl + "&tm=" + tm + "&em=" + em);
     script.setAttribute('id', 'script_id');

	 script_id = document.getElementById('script_id');
     if(script_id)
	 {
     	document.getElementsByTagName('head')[0].removeChild(script_id);
     }

     // Insert <script> into DOM
     document.getElementsByTagName('head')[0].appendChild(script);
}

function callback(data, vendurl) 
{  
    $redir_url = '';
	
	if(vendurl == "craigharris")
		$redir_url = 'http://www.craigharris-members-only.com/idevaffiliate/idevaffiliate.php?id=111';
	else if(vendurl == "webinarreplay")
		$redir_url = 'http://www.craigharris-members-only.com/index.php?option=com_content&view=article&id=153&Itemid=212';
	else if(vendurl == "webinarreplay2")
		$redir_url  = 'http://www.craigharris-members-only.com/index.php?option=com_content&view=article&id=154&Itemid=213';
	else if(vendurl == "webinarpart2")
		$redir_url = 'https://www2.gotomeeting.com/register/906205378';
	else
		$redir_url = vendurl + data
	document.location.href = $redir_url;
} 
//end 

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_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 setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}