var flashObj;

//some common functions
function pageOnLoad() {
	getFlashObj();
}

function getFlashObj() {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        flashObj = window["home"];
    } else {
        flashObj = document["home"];
    }
}

function openUrl(url,winOptions){
	if(winOptions == undefined) winOptions = "";
	window.open(url,"sanmiguelWin" ,winOptions);
	//win.focus();
}
var xWin;
var mTimer;
function openGroupFriendWin(){
	xWin =window.open('http://www.facebook.com/inbox/?compose=1','groupFriendWin',	'resize=1,toolbar=0,status=0,width=626,height=436');
	clearInterval(mTimer);
	mTimer = setInterval('checkHeight()',100);
}

function checkHeight(){
	if($('.fb_feedIFrame').height() > 200){
		clearInterval(mTimer);
	}else{
		if(xWin)
			xWin.focus();
	}
}

function getServerName(){
	var serverPath = document.location.href;
	serverPath = serverPath.substr(serverPath.indexOf("/") + 2)
	return serverPath.substr(0,serverPath.indexOf("/"))
}

function shareSite(lang) {
	if(lang == "eng")
		u="http://"+getServerName()+"/index_english.html?rnd=1&lang=" + lang;
	else
		u="http://"+getServerName()+"/?rnd=1&lang=" + lang;
		
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
}

function shareSiteDirect(section, lang) {
	u="http://"+getServerName()+"/flash/php/fbshare.php?to="+ section + "&lang=" + lang + "&rnd=" + Math.random();
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
}

function sharePromotion(id, lang){
	u="http://"+getServerName()+"/flash/php/fbshare.php?to=promotion&id="+ id+"&lang="+lang;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
}
				
function openExternalSite(urlLink){	
	var linkWindow = window.open(urlLink);
	try{
        linkWindow.focus();
    }
	catch(e){}
}

/*
*	Get GET parameters on the url
*/
function queryString(key) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == key) {
			return ft[1];
		}
	}
}


function ecTrack(code){
	pageTracker._trackPageview(code);
}

function openGame(url,windowsOption,trackCode){
	ecTrack(trackCode);
	var name = "smbGame";
	var popupWin = window.open(url,name,windowsOption);
	popupWin.focus();
}

//javascript:downloadSoccerSticker()
function downloadSoccerSticker(){
	$("#wrapper").append('<iframe width="100%" height="100%" frameborder="0" style="position:absolute;top:0px;left:0px;z-index:100000" src="/forum/forum.html" />')
}

function closeForum(){
	$("#flash_flash").get(0).sendToActionScript("close");
	$("#forumFrame").remove();
}

function openForum(){
	//$("#wrapper").append('<div id="forumFrame" ><a id="closeBtn" href="#" onclick="closeForum()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image1\',\'\',\'../images/soccer/btn_closebox_o.jpg\',1)"><img src="../images/soccer/btn_closebox.jpg" name="Image1" border="0" id="Image1" /></a><!--<iframe allowtransparency="true" frameborder="0" width="915" height="450" src="/forum/forum.html" />--><table border="0" cellpadding="0" cellspacing="0">  <tr>   <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/top_left.jpg" width="5" height="5" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/top_right.jpg" width="5" height="5" /></td>      </tr>  <tr>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="600" height="400" align="center" valign="middle" bgcolor="#ad9f5c"><iframe allowtransparency="true"  width="915" height="450" frameborder="0"  src="/forum/forum.html" /></div></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>  </tr>  <tr>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/bottom_left.jpg" width="5" height="5" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/bottom_right.jpg" width="5" height="5" /></td>  </tr></table>')	
	//$("#wrapper").append('<div id="forumFrame" ><table border="0" cellpadding="0" cellspacing="0"><tr><td><iframe allowtransparency="true" frameborder="0" width="915" height="100" src="../flash/swf/soccerHompage/forum/forum.html" /><table border="0" cellpadding="0" cellspacing="0">  <tr>   <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/top_left.jpg" width="5" height="5" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/top_right.jpg" width="5" height="5" /></td>      </tr>  <tr>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="600" height="400" align="center" valign="middle" bgcolor="#ad9f5c"><iframe allowtransparency="true"  width="915" height="450" frameborder="0"  src="/forum/forum.html" /></div></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>  </tr>  <tr>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/bottom_left.jpg" width="5" height="5" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/bottom_right.jpg" width="5" height="5" /></td>  </tr></table></td><td  valign="top"><a id="closeBtn" href="#" onclick="closeForum()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image1\',\'\',\'../images/soccer/btn_closebox_o.jpg\',1)"><img src="../images/soccer/btn_closebox.jpg" name="Image1" border="0" id="Image1" /></a></td></tr></table>')	
	$("#wrapper").append('<div id="forumFrame" ><table border="0" cellpadding="0" cellspacing="0"><tr><td><!--<iframe allowtransparency="true" frameborder="0" width="915" height="100" src="../flash/swf/soccerHompage/forum/forum.html" />--><table border="0" cellpadding="0" cellspacing="0">  <tr>   <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/top_left.jpg" width="5" height="5" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/top_right.jpg" width="5" height="5" /></td>      </tr> <tr>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="600" align="left" bgcolor="#ad9f5c"><img src="../forum/images/tit_soccerforum.jpg" width="164" height="40" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>  </tr>   <tr>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="600" height="400" align="center" valign="middle" bgcolor="#ad9f5c"><iframe allowtransparency="true" frameborder="0" width="915" height="150" scrolling="no" src="../flash/swf/soccerHompage/forum/forum.html" /><iframe allowtransparency="true"  width="915" height="380" frameborder="0"  src="/forum/forum.html" /></div></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>  </tr>  <tr>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/bottom_left.jpg" width="5" height="5" /></td>    <td bgcolor="#ad9f5c"><img src="../images/soccer/spacer.gif" width="5" height="5" /></td>    <td width="5" height="5" bgcolor="#ad9f5c"><img src="../images/soccer/bottom_right.jpg" width="5" height="5" /></td>  </tr></table></td><td  valign="top"><a id="closeBtn" href="#" onclick="closeForum()" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image1\',\'\',\'../images/soccer/btn_closebox_o.jpg\',1)"><img src="../images/soccer/btn_closebox.jpg" name="Image1" border="0" id="Image1" /></a></td></tr></table>')	
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}










var frameDialog;
var frameDialogInterval;

function FBFlashBridgeInviteFriendsWdo(title, actionTitle, messageCopy,actionURL){
	
	FB.ensureInit(function() {
        frameDialog= new FB.UI.FBMLPopupDialog(title, "");        
        var fbml = "<fb:fbml>" + 
        				"<fb:iframe " +  
        						"src=\"http://"+serverHost+"/flash/php/facebook/facebookSelector.php\" " + 
								"width=\"760\" " + 
								"height=\"650\" " + 
								"frameborder=\"0\" " + 
								"id=\"frameDialogDiv\" " + 
        						">" +  
        				"</fb:iframe>" + 
        			"</fb:fbml>";
        
        frameDialog.setFBMLContent(fbml);
        frameDialog.setContentWidth(760); 
        frameDialog.setContentHeight(650);
        
        frameDialog.show();
    });
}