
function getFlashMovie(movieName) {

	var isIE = navigator.appName.indexOf("Microsoft") != -1;

	return (isIE) ? window[movieName] : document[movieName];

}

function popWindow(url) {

	/*if(window.open(url,'mobilegames','height=200,width=240,resizable=0,scrollbars="auto",location=0,toolbar=0,status=0,left=250,top=250,screenX=250,screenY=250').focus)
	{
		return("true");	
	}
	else
	{
		getFlashMovie("att").sendToAS();
		return("false");
	}*/
}

var interfaceIsAvailable = false;	// flag to determine if external interface is ready

var sendCounter;					// counter interval handle for later clearing
var sendSticker;					// sticker interval handle for later clearing

var counterCount;					// count value passed to counter
var stickerCount;					// count value passed to sticker
var stickerSiteName;				// sitename value passed to sticker

/**
 *  interfaceAvailable : 
 * 		called by flash when the external interface
 * 		is available.  the purpose is to avoid a call
 * 		before flash has loaded interface.
 */
function interfaceAvailable( status )
{
	interfaceIsAvailable = true;
}
/**
 *  sendCounterDetails : 
 * 		check if landing external interface is available
 * 		  if yes: send the data and clear the interval
 * 		  if no: skip over and wait for next interval call
 */
 function thisURLIsBroke ( errormsg, flashid ) {
	getFlashMovie(flashid).urlIsInvalid( errormsg ); 
 }
function sendCounterDetails() {
	if( interfaceIsAvailable ){
		getFlashMovie("rwordcounter").sendToCounter(counterCount);
		clearInterval(sendCounter);	
	}
}
/**
 *  sendStickerDetails : 
 * 		check if sticker external interface is available
 * 		  if yes: send the data and clear the interval
 * 		  if no: skip over and wait for next interval call
 */
function sendStickerDetails(sitename, count)
{
	if( interfaceIsAvailable ){
		//alert(stickerSiteName + " | " + stickerCount);
		//getFlashMovie("rwordcounter").sendToSticker( stickerSiteName, stickerCount );
		clearInterval(sendSticker);	
	}
	
}
/**
 * 	setStickerInterval : 
 * 		set data to global var and start interval
 */
function setStickerInterval(sitename, count) {
	stickerCount = count;
	stickerSiteName = sitename;
	sendSticker = setInterval( 'sendStickerDetails();', 2000 );
}

/**
 * validate Url
 *  	Validates the given url against the following rules
 *		  1.  Url has an extension ( i.e. .com, .org, etc...)
 *  	  2.  given extension is a valid tld
 */
 function validateUrl(url)
 {
	
	var domain = url.replace( /.+:\/\//gi, "" );
	domain = domain.replace( /www\./gi, "" );
	domain = domain.replace( /\/.+/gi, "" );
				
	var arr = domain.split(".");
	var len = arr.length;
				
	if(len == 1)
		return "Please enter a valid url.";
	else {
		//var tld_exists = false;
		//var TLD = arr[len-1].toUpperCase();
		
		//$.each(tldList, function() {
		//	if (TLD == this) {
		//		tld_exists = true;
		//	}
		//});		
		
		//if( tld_exists == false )
		//	return "Please enter the full url.";
		//else
			return "";
	}
 }
