var jvmAffId;

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" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
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;
	}
}


// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function getDomain()
{
	var strEmail = gup('from');
	var temp = new Array;
	var temp2 = new Array;
	var strProvider
 
	if (strEmail != "")
	{
		temp = strEmail.split('%40');
		temp2 = temp[1].split('%2e');
		return temp2[0].toLowerCase();
	}
	else
	{
		return "";
	}
}

function printCookie()
{
	var strTemp = Get_Cookie('emailDomain');
	document.write(strTemp);
}

function showExitFrame()
{
	//frames[0].style.visible='visible'
	document.getElementById("A").style.visibility='visible';
}
function checkEmailSent()
{
	var strCookie = Get_Cookie('strRefered');
	var strReturn;
//	alert('test alert');
	if (strCookie == 'y')
	{
		parent.location='SocialInvite.html';
	}
	else
	{
		alert('Please invite your friends by following the short steps on this page before clicking this button. If you would prefer not to invite your friends, please click the button at the bottom of this page that says "Skip Straight To Tutorials"');
	}
//	document.write(strReturn);
}

function checkEmailSent2()
{
	var strCookie = Get_Cookie('strRefered');
	var strReturn;
//	alert('test alert');
	if (strCookie == 'y')
	{
		window.location='http://www.thebossbuster.com/freemoney/freesportsmoney';
	}
	else
	{
		alert('Please invite your friends by following the short steps on this page before clicking this button.');
	}
//	document.write(strReturn);
}

function checkSocialRefer()
{
	var strCookie = Get_Cookie('strReferedSocial');
	var strReturn;
//	alert('test alert');
	if (strCookie == 'y')
	{
		alert('Thanks for helping me build TheBossBuster community. Below is the URL for the 3rd set of free video tutorials. Please paste this into your browser and bookmark it, as there is no other way back to it.\r\n\r\nwww.TheBossBuster.com/freemoney/ongoing.\r\n\r\nPlease note that you will need to watch these videos in the same order as you got them, otherwise they will not make sense. So watch the above URL 3rd.\r\n\r\nWhen you click ok, you will be taken through to the origional set of videos you signed up for.\r\n\r\nThanks for all your help... Enjoy!');
		window.location='http://www.thebossbuster.com/freemoney/sportsfreemoney';
	}
	else
	{
		alert('Please invite your friends by following the short steps on this page before clicking this button. If you would prefer not to invite your friends, please click the button at the bottom of this page that says "Skip Straight To Tutorials"');
	}
//	document.write(strReturn);
}

function goToThankyouPage()
{
	var strDomain = getDomain();
	//document.write(strDomain);
	
	if ((strDomain == 'yahoo') || (strDomain == 'ymail') || (strDomain == 'rocketmail') || (strDomain == 'y7mail') || (strDomain == 'talk21') || (strDomain == 'btinternet') || (strDomain == 'btopenworld')) 
	{
		Set_Cookie('emailDomain', 'yahoo', 60, '/');
		document.write('<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thebossbuster.com/js/yThanks.html">');
	}
	else if (strDomain == 'gmail')
	{
		Set_Cookie('emailDomain', 'gmail', 60, '/');
		document.write('<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thebossbuster.com/js/gThanks.html">');
	}
	else if ((strDomain == 'hotmail') || (strDomain == 'live') || (strDomain == 'windowslive') || (strDomain == 'msn') || (strDomain == 'msnhotmail'))
	{
		Set_Cookie('emailDomain', 'hotmail', 60, '/');
		document.write('<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thebossbuster.com/js/hThanks.html">');
	}
	else if ((strDomain == 'mail') || (strDomain == 'email') || (strDomain == 'popstar') || (strDomain == 'name') || (strDomain == 'usa') || (strDomain == 'techie') || (strDomain == 'post') || (strDomain == 'europe') || (strDomain == 'myself') || (strDomain == 'cheerful') || (strDomain == 'whoever') || (strDomain == 'earthling') || (strDomain == 'unforgettable') || (strDomain == 'teacher')) 
	{
		Set_Cookie('emailDomain', 'mail', 60, '/');
		document.write('<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thebossbuster.com/js/mThanks.html">');
	}
	else if ((strDomain == 'aol') || (strDomain == 'aim') || (strDomain == 'netscape'))
	{
		Set_Cookie('emailDomain', 'aol', 60, '/');
		document.write('<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thebossbuster.com/js/aThanks.html">');		
	}
	else
	{
		Set_Cookie('emailDomain', 'other', 60, '/');
		document.write('<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.thebossbuster.com/js/oThanks.html">');
	}
}

function emailForm(strList)
{	
	var str = '';
	var strAffID = gup('aff_id');
	
	if (strAffID != '')
	{
		strAffID = '?aff_id=' + strAffID;
	}
	//str += '<form method="post" action="http://www.aweber.com/scripts/addlead.pl" onsubmit="return chkTwoEmail(''rightemail'',''http://www.aweber.com/scripts/addlead.pl'');">';
		str += '<input type="hidden" name="meta_web_form_id" value="770727345">';
		str += '<input type="hidden" name="meta_split_id" value="">';
		//str += '<input type="hidden" name="unit" value="silver_members">';
		str += '<input type="hidden" name="unit" value="' + strList + '">';
		str += '<input type="hidden" name="redirect" value="http://www.thebossbuster.com/js/thank.html" id="redirect_80f38aa3d17af0a476c147757e8c6198">';
		str += '<input type="hidden" name="meta_redirect_onlist" value="http://www.thebossbuster.com/freemoney/sportsfreemoney/overview">';
		str += '<input type="hidden" name="meta_adtracking" value="">';
		str += '<input type="hidden" name="meta_message" value="1">';
		str += '<input type="hidden" name="meta_required" value="from">';
		str += '<input type="hidden" name="custom affid" value="' + strAffID + '" size="20">';
		str += '<input type="hidden" name="meta_forward_vars" value="1">';
		//str += '<p style="text-align: center">Enter your email &nbsp;&nbsp;&nbsp; <input type="text" name="from" id="rightemail" value="" /></p>';
		//str += '<p style="text-align: center"><input class="btn" type="submit"  name="submit" value="" /></p>';
	//str += '</form>';
	document.write(str);
}

function emailForm2(strList)
{	
	var str = '';
	var strAffID = gup('aff_id');
	
	if (strAffID != '')
	{
		strAffID = '?aff_id=' + strAffID;
	}
	str += '<input type="hidden" name="meta_web_form_id" value="768059420">';
	str += '<input type="hidden" name="meta_split_id" value="">';
	str += '<input type="hidden" name="unit" value="silver_members2">';
	str += '<input type="hidden" name="redirect" value="http://www.thebossbuster.com/js/thank2.html" id="redirect_5f889e119733095449e30739b4f19b5e">';
	str += '<input type="hidden" name="meta_redirect_onlist" value="http://www.thebossbuster.com/freemembersarea">';
	str += '<input type="hidden" name="meta_adtracking" value="">';
	str += '<input type="hidden" name="meta_message" value="1">';
	str += '<input type="hidden" name="meta_required" value="from">';
	str += '<input type="hidden" name="custom affid" value="' + strAffID + '" size="20">';
	str += '<input type="hidden" name="meta_forward_vars" value="1">';

	document.write(str);
}

function emailForm3(strList)
{	
	var str = '';
	var strAffID = gup('aff_id');
	
	if (strAffID != '')
	{
		strAffID = '?aff_id=' + strAffID;
	}
	
	str += '<input type="hidden" name="meta_web_form_id" value="2130787126">';
	str += '<input type="hidden" name="meta_split_id" value="">';
	str += '<input type="hidden" name="unit" value="silver_members3">';
	str += '<input type="hidden" name="redirect" value="http://www.thebossbuster.com/js/thank3.html" id="redirect_33e79e7e7ea9cc943ecd9cf77cd95a5e">';
	str += '<input type="hidden" name="meta_redirect_onlist" value="http://www.thebossbuster.com/freemembersarea">';
	str += '<input type="hidden" name="meta_adtracking" value="">';
	str += '<input type="hidden" name="meta_message" value="1">';
	str += '<input type="hidden" name="meta_required" value="from">';
	str += '<input type="hidden" name="custom affid" value="' + strAffID + '" size="20">';
	str += '<input type="hidden" name="meta_forward_vars" value="0">';

	document.write(str);
}

function treeRedirect()
{
	var nLastNode = Get_Cookie('jvm_aff_id');
	var str = '';
	
	if (nLastNode == '121')
	{
		str = '<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com">';
	}
	else
	{
		str = nLastNode;
	}
	document.write(str);
}

function printAffID()
{
	document.write(gup('aff_id'));
	//var affid = gup('aff_id');
	//var str = '';
	//str = "<a href='http://www.thebossbuster.com/money?aff_id=" + affid + "'>" + strLinkText + "</a>";
	//document.write(str);
}

function printName()
{
	document.write(gup('name'));
}

function getPromoLink(strLinkText)
{
	var affid = gup('aff_id');
	var strName = gup('name');
	var str = '';
	str = "<a href='http://www.thebossbuster.com/PromoMaterials?aff_id=" + affid + "&name=" + strName + "' target='_blank'>" + strLinkText + "</a>";
	document.write(str);

}
