////////////////////////////////////////////////////////////////////////////////////////////////////

//includes the flash Object JS file 
var flashObjectJS = "<script src='/premium/tools/clientScripts/getFlashElement.js' language='javascript'></script>";
document.write(flashObjectJS);
/////////////////


featureUnlockPurchaseDone = false;
abortFeatureUnlockOffer = false;

//this function checks what happens when the page is unloaded
function FeatureUnlockOfferUnload()
{
	try
	{	
		if(!featureUnlockPurchaseDone) //if purchase wasn't unlocked (opens a feedback)
		{
			FeatureUnlockDone('','');
			window.open('/tools/feedback/index_ActivityTemplate.pl?project=gsAbortFeatures','gsAbortFeaturesWin','scrollbars=yes,resizable=yes,left=10,top=10,width=480,height=320');
		}
	}	
	catch(e){}
}

function FeatureUnlockOffer(activity, merchandise, tokens)
{
	//alert("FeatureUnlockOffer: activity="+activity+" merchandise="+merchandise+" tokens="+tokens)
	var fromLeft = window.screenLeft + 20;
	var fromTop = window.screenTop;
	theLink = 'http://www.girlsense.com/premium/trade/featureUnlockOffer.pl?activity=' + activity + '&merchandise=' + merchandise + '&tokens=' + tokens;
	unlockFeatureOfferWinHandler = parent.window.open(theLink,'unlockFeatureOfferWin','scrollbars=yes,resizable=yes,left='+fromLeft+',top='+fromTop+',width=790,height=490');
}


function FeatureUnlockPurchase(activity, merchandise, tokens)
{
	featureUnlockPurchaseDone = true;
	document.forms.unlockForm.submit();
}


function FeatureUnlockDone(activity, merchandise)
{
	var frameObj = null; //this variable holds the frameObj which the flash App is in.
	
	//alert("FeatureUnlockDone " + activity + " " + merchandise)
	featureUnlockPurchaseDone = true;

	// PollCenterFeatures case
	if(activity.indexOf("PollCenterFeatures") != -1)
	{
		opener.document.location.href = "/premium/myPolls/";
	}

	// GSBoardFeatures case
	if(activity.indexOf("GSBoardFeatures") != -1)
	{
		opener.document.location.href = "/premium/GSBoard/";
	}

	// GSNotesFeatures case
	if(activity.indexOf("GSNotesFeatures") != -1)
	{
		opener.document.location.href = "/premium/quickNotes/index.pl?action=new";
	}
	     
	// CleaFeatures case
	if(activity.indexOf("CleaFeatures") != -1)
	{
		opener.document.location.href = "/premium/clea/";
	}

	// eBoutiqes
	if( (activity.toLowerCase().indexOf("boutique") != -1)  )
	{
		//window.opener.FeatureUnlock(activity, merchandise)
		window.opener.FeatureUnlock(activity, merchandise);
	}

	// FDS, eBoutiqes, Journal, CdollsRockstar, WSD cases
	if((activity.toLowerCase().indexOf("fds") != -1) || (activity.toLowerCase().indexOf("journal") != -1) || (activity.toLowerCase().indexOf("cdollsrockstar") != -1) || (activity.toLowerCase().indexOf("wsd") != -1) )
	{
		try
		{
			if (activity.toLowerCase().indexOf("fds") != -1)  //the only activity with ADSPEED TEMPLATE
				frameObj = GetFrameObject(window.opener, 'iframeID');
			else
				frameObj = GetFrameObject(window.opener.parent, 'iframeID');
			frameObj.FeatureUnlock(activity, merchandise);
		}
		catch (e)
		{
			alert(e.message);	
		}
	}

	// other case - Manicure, Pedicure
	if((activity.toLowerCase().indexOf("manicure") != -1) || (activity.toLowerCase().indexOf("pedicure") != -1))
	{
		//window.opener.FeatureUnlock(activity, merchandise);
		window.opener.frames[2].FeatureUnlock(activity, merchandise); //must be written that way for FF
		/*
		frameObj = GetFrameObject(window.opener, 'iframeID');
		if(frameObj)
		{
			frameObj.FeatureUnlock(activity, merchandise);
		}
		*/
		
	}

	try
	 {	
	 	self.close()
 	 }
 	 catch(e){}
}

function FeatureUnlock(activity, merchandise)
{
	//alert("FeatureUnlock " + activity + " " + merchandise)
	if(activity=='' && merchandise=='')
	{
		abortFeatureUnlockOffer = true;
	}	
	else
	{
		abortFeatureUnlockOffer = false;
	}	
		
	try
	{
		//var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
		//var flashObj = isInternetExplorer ? document.all.loader : document.loader;
		if (activity.toLowerCase().indexOf("boutique") != -1)
		{
			var flashObj = getFlashMovieObject('boutique');
		}
		else
		{
			var flashObj = getFlashMovieObject("loader");
		}

		if(flashObj==null)
		{
			flashObj = getFlashMovieObject("loader_new");
		} 

		// FDS, Journal, cdollsrockstar, wsd cases
		if((activity.toLowerCase().indexOf("fds") != -1) || (activity.toLowerCase().indexOf("journal") != -1) || (activity.toLowerCase().indexOf("cdollsrockstar") != -1) || (activity.toLowerCase().indexOf("wsd") != -1))
		{
			flashObj.SetVariable("/:featureObj", merchandise);
		}
	     
		// other cases - Manicure, Pedicure, eBoutiqes
		else
		{
			flashObj.FeatureUnlock(activity, merchandise);
		}
	}
	catch(e){ }
}

function SelfClose()
{
	self.close()
}

function HowToEarn()
{
	howToEarnWinHandler = window.open('http://www.girlsense.com/premium/eBoutiques/howToEarnGcents.htm','howToEarnWin','scrollbars=no,toolbar=no,resizable=yes,status=yes,left=10,top=10,width=720,height=553');	
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function GetFrameObject(referrer, frame_name)
{
	var frameObj = null;
	//referrer = window.opener.parent
	var i;
	for(i=0; i<referrer.frames.length; i++)
	{
		try  //the try is very nesaccery here
		{
			loopFrameName = referrer.frames[i].name || '';
			//alert("loopFrameName: "+loopFrameName+" frame_name:"+frame_name);
			if(loopFrameName == frame_name)
			{
				return referrer.frames[i];
			}
		}
		catch(e)
		{}
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

