var Tbuffer =	[	["currentimage",""],
					["currselected",""],
					["currenttext",""],
					["currentclub",""],
					["currentposition","*"],
					["currentzone",""]
				];
var allpars=	[	['player',''],
					['club',''],
					['pname',''],
					['value',''],
					['clubkit','empty.gif'],
					['position','...']
			];
var currentFormation = 0;




function putaj(){
	var fr=document.createElement('iframe');
	fr.src='javascript:false;';
	fr.name="ajaxObj";
	fr.id="ajaxObj";
	fr.style.position='absolute';
	fr.style.margin=fr.style.padding='0px';
	fr.style.zIndex=1;
	fr.style.display='none';
	fr.style.width=fr.style.height='0px';
	document.getElementsByTagName('body')[0].appendChild(fr);	

}


function create_fader(){
	var bodyObj=document.getElementsByTagName('body')[0];
	var fadeObj = document.createElement("div");
	fadeObj.setAttribute('id','fade');
	fadeObj.onclick = function () {destrpopcont();}
	fadeObj.style.display = 'none';
	fadeObj.style.position = 'absolute';
	fadeObj.style.top = '0';
	fadeObj.style.left = '0';
	fadeObj.style.zIndex = '20';
 	fadeObj.style.width = '100%';
	bodyObj.insertBefore(fadeObj, bodyObj.firstChild);
}



function sbmtr(formname,copyfrom,e){
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	var getfrom=document.getElementById(copyfrom);
	if (keycode == 13){
		var func = new Function;
		func = getfrom.onclick;
		func();
		return false;
	}else return true;
}





function sbmt(formname,newparam){
	eval("document.forms['"+formname+"'].su.value=newparam");
	eval("document.forms['"+formname+"'].submit()");
}

function sbmt1(sssu,id,noconfirm){
	if (noconfirm)
	{
		document.forms['ad'].sssu.value=sssu;
		document.forms['ad'].id.value=id;
		document.forms['ad'].submit();
		
	} 
	else 
	{	

		var message = "******************************************************\n\n\n\nWARNING!\n\nAre you sure you want to perform this action?\n\n\n\n******************************************************";
		
		if (sssu == 'lleave') 
			message ="******************************************************\n\n\n\nWARNING!\n\nThis tournament is currently in progress. If you leave this tournament you will not be allowed to re-enter. Are you sure you wish to leave this tournament?\n\n\n\n******************************************************";
		
		if (window.confirm(message))
		{
			document.forms['ad'].sssu.value=sssu;
			document.forms['ad'].id.value=id;
			document.forms['ad'].submit();
			
		}
	}
	return false;
	
}


function conf_opup(a,b,c){
	if (window.confirm("Any players already selected will be lost!\n Are you sure you want to change your formation?"))
	{
    currentFormation = document.getElementById(a).selectedIndex;
		return getA(a,b,c);
	}
  else
  {
    document.getElementById(a).selectedIndex = currentFormation;
    return false;
  }
}

// Core code from - quirksmode.org
function wholePage(){
	
	var pageXscroll, pageYscroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		pageXscroll = document.body.scrollWidth;
		pageYscroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		pageXscroll = document.body.scrollWidth;
		pageYscroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		pageXscroll = document.body.offsetWidth;
		pageYscroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(pageYscroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = pageYscroll;
	}

	// for small pages with total width less then width of the viewport
	if(pageXscroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = pageXscroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function getPageScroll(){
	var pageYscroll;

	if (self.pageYOffset) {
		pageYscroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		pageYscroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		pageYscroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',pageYscroll) 
	return arrayPageScroll;
}


function getpopup(cond){
	var popupObj= document.getElementById ? document.getElementById("popup") : null;
	if (cond)
	{
		var coords= wholePage();
		var scroll=getPageScroll();
		var fadeObj = document.getElementById('fade');

		chngvis('fade','block');
		fadeObj.style.height = (coords[1] + 'px');
		fadeObj.style.display = 'block';

		selects = document.getElementsByTagName("select");
        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
        }

		popupObj.style.display = 'block';
		popupObj.style.top = scroll[1]+(coords[3]-300)/2+'px';
		popupObj.style.left = (coords[0]-500)/2+'px';
	} 
	else 
	{
		popupObj.style.display = 'none';
	}

}

function destrpopcont() {
	selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
	}

	chngvis('fade','none');
	var objPop = document.getElementById ? document.getElementById("popcont") : null;
	objPop.innerHTML = '';
	chngvis('popup','none');
	return false;
}

function chngvis(name,val){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.style.display=val;

	/*hide system messages - both errors and oks*/
	var objok = document.getElementById ? document.getElementById('oks') : null;
	var objerror = document.getElementById ? document.getElementById('error') : null;
	
	if (objok)
	{
		objok.style.display='none';
	}

	if (objerror)
	{
		objerror.style.display='none';
	}

	return false;
}


function refIm(imagename){
	var ima=document.getElementById(imagename);
	var src=ima.src;
	var regs=	/\&tst\=.*/;
	if (src.match(regs))
	{
		newshit="&tst="+Math.random();
		src = src.replace(regs,newshit);
	} else {
		src=src+"&tst="+Math.random();
	}
	ima.src = src;
	return false;
}

function chngMenu(wah){
	var all=new Array("s","m","d","g","a");
	for (var i=0;i<all.length;i++ )
	{
		obj=document.getElementById('pos_'+all[i]);
		tab=document.getElementById('tab_'+all[i]);
		
		if (wah == all[i])
		{
			obj.className='vis';
			tab.className='i';
			document.forms['ad'].ps.value=wah;
		} else {
			obj.className='';
			tab.className='';
		}
	}
	return false;
}

function tabChange(qty,id){
	for (var i=0; i<qty; i++)
	{	
		obja=document.getElementById('tab_'+i);
		objd=document.getElementById('tabholder_'+i);
		obja.className='';
		objd.style.display='none';	
		
		if (i == id)
		{
			obja.className='a';
			objd.style.display='inline';
		}
	}
	return false;
}


function posOpen(id,zone,subs){
	
	if (!(zone)) zone = 'f';
	if (document.forms['ad'].currselected.value != '') {

		/*		try to interchange		*/
		eval("var newplace  =	document.forms['ad'].player_"+id+".value;");
		eval("var newpos	=	document.forms['ad'].position_"+id+".value;");
		eval("var newim		=	document.forms['ad'].clubkit_"+id+".value;");

		var isval		= document.forms['ad'].currselected.value;
		eval("var oldplace  =	document.forms['ad'].player_"+isval+".value;");
		eval("var oldpos	=	document.forms['ad'].position_"+isval+".value;");
		eval("var oldim		=	document.forms['ad'].clubkit_"+isval+".value;");

		/*	1	to empty place on field	*/

		if (zone=='f')										clearposnew=0; else clearposnew=1;
		if (document.forms['ad'].currentzone.value=='f')	clearposold=0; else clearposold=1;

		
		/*			If assistant manager	*/
		if (newpos == 'a' || oldpos == 'a')
		{
			deselect(isval);
			return false;
		}

		if (id == isval)  
		{	
			deselect(id);
			deselect(isval);
			return false;
		}
		else if (newplace	== '' && oldplace == '')
		{	
			deselect(id);
			deselect(isval);
		}
		else if (newplace	!= '' || oldplace != '')
		{		
				if(oldpos != newpos){
					if(oldpos != '*' && newpos != '*'){
						if (!(zone =='s' && document.forms['ad'].currentzone.value =='s'))
						{
							Calert("Positions are unmatched [1]");
							deselect(isval);
							return false;
						}
						
					} else if(oldpos == '*'  || newpos == '*'){
						if (oldpos != '*') var parampos = oldpos; else parampos = newpos;
						if (wrongSubst(parampos))
						{
							deselect(isval);
							deselect(id);
							return false;
						}
					}
					
				}
		
				for (var i=0;i<allpars.length;i++ )
				{
					eval("var "+allpars[i][0]+"_buffer =	document.forms['ad']."+allpars[i][0]+"_"+id+".value;");
					eval("var "+allpars[i][0]+"_buffer1 =	document.forms['ad']."+allpars[i][0]+"_"+isval+".value;");
				}
				clearPos(id,clearposnew);
				clearPos(isval,clearposold);
				showCloseButton(isval,0);
				showCloseButton(id,0);

				document.forms['ad'].currselected.value=isval;
				document.forms['ad'].currenttext.value=pname_buffer;		
				//document.forms['ad'].currentzone.value=zone;
				
				if (player_buffer) {
					pass(player_buffer,position_buffer,pname_buffer,value_buffer,club_buffer,clubkit_buffer,1);
				} else {
					deselect(id);
				}
				

				document.forms['ad'].currselected.value=id;
				document.forms['ad'].currenttext.value=pname_buffer1;	
				document.forms['ad'].currentzone.value=zone;
				if (player_buffer1){
					pass(player_buffer1,position_buffer1,pname_buffer1,value_buffer1,club_buffer1,clubkit_buffer1,1);
				} else {
					deselect(isval);
				}
				//
				return false;
		}
	}
	document.forms['ad'].currselected.value=id;
	currIm=document.getElementById("kit_"+id);	
	eval("document.forms['ad'].currentposition.value=document.forms['ad'].position_"+id+".value");
	currIm.src="/im/clubs/kits/active.gif";

	var position= document.getElementById("pos_"+id);
	document.forms['ad'].currenttext.value=position.innerHTML;	
	document.forms['ad'].currentzone.value=zone;
	eval("document.forms['ad'].currentclub.value=document.forms['ad'].club_"+id+".value");
	return false;
}


function deselect(id){
	if (!id)
	{
		id = document.forms['ad'].currselected.value;
	}
	var currIm=document.getElementById("kit_"+id);
	eval("var kit=document.forms['ad'].clubkit_"+id+".value;");
	currIm.src="/im/clubs/kits/"+kit;
	clearBuffer();
}



function clearPos(id,poos){
	clearHidden(id,poos);
	currIm=document.getElementById("kit_"+id);
	currIm.src="/im/clubs/kits/empty.gif";

	var position= document.getElementById("pos_"+id);
	position.innerHTML = '...';
	
	if (poos)
	{
		var letterOdj=	document.getElementById('posletter_'+id);
		letterOdj.innerHTML='*';
	}
}


function posFree(id,poos){
	showCloseButton(id,0);
	updwallet(0,id);
	deselect(id);
	clearPos(id);
	return false;
}

function showCloseButton(id,direction){
	var currCloseButton=document.getElementById("closebutt_"+id);
	if (!currCloseButton) return;
	if (direction)
	{
		var visibility='visible'
	} 
	else 
	{
		var visibility='hidden';
	}
	currCloseButton.style.visibility = visibility;
}


function clearHidden(id,poos){
	for (var i=0;i<(allpars.length-1);i++ )
	{
		eval("document.forms['ad']."+allpars[i][0]+"_"+id+".value=allpars[i][1];");
	}
	if (poos)
	{
		eval("document.forms['ad'].position_"+id+".value='*';");
	}
}



function clearBuffer(){
	for (var i=0; i<Tbuffer.length;i++)
	{
		eval ("document.forms['ad']."+Tbuffer[i][0]+".value='"+Tbuffer[i][1]+"';");
	}
}



function pass(playerid,pos,pname,value,club,kit,changeprice,closebutt){

	if (document.forms['ad'].currselected.value == '') {
		Calert("Choose respective position on the field or on the substitutions bench first");
		return false;
	}

	var id=document.forms['ad'].currselected.value;

	if(!(changeprice))
	{
		if(!checkWallet(value,id))
		{	
			return false;
		}
	}
	
	if (!correctCompose(playerid,pos,club)) return false;

	if (document.forms['ad'].currentzone.value == 'f')
	{
		eval("var allowedpos = document.forms['ad'].position_"+id+".value");
		if (allowedpos != pos && pos !='*')
		{
			Calert("Positions are unmatched [2]");
			return false;
		}
	} 
	else if (document.forms['ad'].currentzone.value == 's')
	{
		/*	No place here for AM man */
		if (pos == 'a')
		{
			Calert("Positions are unmatched [3]");
			return false;
		}
		if (wrongSubst(pos))
		{
			deselect(id);
			return false;
		}

		/*	set position	*/
		eval("document.forms['ad'].position_"+id+".value=pos;");
		var letterOdj=	document.getElementById('posletter_'+id);
		letterOdj.innerHTML=pos.toUpperCase();

	}

	clearBuffer();

	currIm=document.getElementById("kit_"+id);
	currIm.src='/im/clubs/kits/'+kit;
	currIm.width="56";
	currIm.height="45";

	var position= document.getElementById("pos_"+id);
	document.forms['ad'].currenttext.value=position.innerHTML;
	position.innerHTML = pname;
	showCloseButton(id,1);
	if(!(changeprice)) updwallet(value,id);
	eval("document.forms['ad'].player_"+id+".value=playerid;");
	eval("document.forms['ad'].club_"+id+".value=club;");
	eval("document.forms['ad'].pname_"+id+".value=pname;");
	eval("document.forms['ad'].value_"+id+".value=value;");
	eval("document.forms['ad'].clubkit_"+id+".value=kit;");

	return false;
}

function checkWallet(value,id){
	var curr = document.forms['ad'].wallet.value;
	eval("var valminus = document.forms['ad'].value_"+id+".value");
	if (valminus == '')
	{
		valminus=0;
	}
	var available = parseFloat(curr)+parseFloat(valminus);
	curr=parseFloat(curr)+parseFloat(valminus)-parseFloat(value);
	
	if (curr < 0)
	{
		Calert("Not enough money on account!<br>Available: "+format_decimal(available)+"<br>Needed: "+format_decimal(parseFloat(value)));
		return false;
	}
	return true;
}

function updwallet(value,id){
	var curr = document.forms['ad'].wallet.value;
	eval("var valminus = document.forms['ad'].value_"+id+".value");
	if (valminus == '')
	{
		valminus=0;
	}
	curr=parseFloat(curr)+parseFloat(valminus)-parseFloat(value);
	document.forms['ad'].wallet.value=curr;
	var walletview=document.getElementById("available");

	walletview.innerHTML=format_decimal(curr);
}


function format_decimal(n){
	n=parseInt(Math.round(n*1000000));
	str=n.toString();
	var d=1;
	var formatted='';
	for (var e=(str.length-1);e>-3;e=e-3)
	{
		if ((e-2)>0)
		{
			formatted=','+str.substr(e-2,3)+formatted;
		} else {
			var bias=3-e;
			formatted=str.substr(0,(1+e))+formatted;
		} 
			
	}
	return formatted;
}

function correctCompose(id,pos,club){

	var plids = new Array();
	var plclubs = new Array();
	for (var i=1;i<=17 ;i++ )
	{
		eval("var plid = document.forms['ad'].player_"+i+".value");
		eval("var plclub = document.forms['ad'].club_"+i+".value");
		
		if (plid)	{plids[plid]=(!(plids[plid])) ? 1 : (plids[plid]+1);}
		if (plclub)	{plclubs[plclub]=(!(plclubs[plclub])) ? 1 : (plclubs[plclub]+1);}
	}

	
	if (plids[id] > 0)
	{
		Calert("You have already chosen this player");
		deselect(0);
		return false;
	}

	if (document.URL.indexOf("/substitutions") == -1 && plclubs[club] > 1 && document.forms['ad'].currentclub.value != club)
	{
		Calert("You are not allowed to choose more that 2 players from the same club!");
		deselect(0);
		return false;
	}

	return true;
}

function wrongSubst(parampos){
	var taken=0;
	var arr = new Array();
	for (var i=12;i<=16 ;i++ )
	{
		eval("var posid = document.forms['ad'].position_"+i+".value");
		
		if (posid !='*')
		{
			taken++;
			if (!arr[posid]) arr[posid] = 0;
			arr[posid]=arr[posid]+1;

		}
	}

	if (taken == 5)
	{
		if (document.forms['ad'].currentposition.value == 'd' && arr['d']== 1 && parampos != 'd')
		{
			alertSubs();
			return true;
			
		} 
		else if (document.forms['ad'].currentposition.value == 'g' && arr['g']== 1 && parampos != 'g')
		{
			alertSubs();
			return true;
		}
	}



	if (taken == 4) 
	{
		if(document.forms['ad'].currentposition.value == '*')
		{
			if (!(arr['g']))
			{
				if (parampos != 'g')
				{
					alertSubs();
					return true;
				}
			} 
			else if (!(arr['d']))
			{
				if (parampos != 'd')
				{
					alertSubs();
					return true;
				}
			}
		}
		else 
		{
			if (document.forms['ad'].currentposition.value == 'd' && arr['d']== 1 && (parampos != 'g' && parampos != 'd')) 
			{
					alertSubs();
					return true;
			} 
			else if(document.forms['ad'].currentposition.value == 'g' && arr['g']== 1 && (parampos != 'g' && parampos != 'd')) 
			{
					alertSubs();
					return true;
			}
		}
	} 
	

	if (taken == 3)
	{
		if (!(arr['g']) && !(arr['d']) && document.forms['ad'].currentposition.value == '*')
		{
			if (parampos != 'g' && parampos !='d')
			{
				alertSubs();			
				return true;
			}
			
		}
	}

	return false;
}

function alertSubs(){
	Calert("Substitution is impossible!<br>You have to choose at least 1 Defender (D) and 1 Goalkeeper (G)");
}

function getClub(val,closebutt){	
	
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	var obJholder = document.getElementById ? document.getElementById("sqdcont") : null;
	obJholder.innerHTML="<img src='/im/clock.gif' style='margin:200px 0 0 200px;'>";
	
	if (val == '0') {
		objaj.src = "/upd.php?act=clublist&"+"&tst="+Math.random()+"&closebutt="+closebutt;
		
	} else {
		objaj.src = "/upd.php?act=club&club="+val+"&ps="+document.forms['ad'].ps.value+"&tst="+Math.random()+"&closebutt="+closebutt;
	}
	return false;
}

function getA(actpar,val,clockholder){
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	var obJholder = document.getElementById ? document.getElementById(clockholder) : null;
	obJholder.innerHTML="<img src='/im/clock.gif' style='margin:150px 165px;'>";
	objaj.src = "/upd.php?act="+actpar+"&value="+val+"&tst="+Math.random();
	return false;
}

function setvalue(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
}

function setvalue1(formname,elementname,elvalue){
	eval("document.forms['"+formname+"']."+elementname+".value = elvalue");
}

function submitSquad(ind){
	/*check all positions*/
	isE=0;
	for (i=1; i<=17; i++)
	{
		eval("var u=document.forms['ad'].player_"+i+".value");
		if (!u || isNaN(u))
		{
			if (!isE)
			{
				isE=i;
			}
		}
	}
	if (isE)
	{
		Calert("There are empty positions in your team! ("+isE+")");
		return false;
	}

	/*	check teams */
	var qty=new Array();
	for (i=1; i<=17; i++)
	{
		eval("var u=document.forms['ad'].club_"+i+".value");
		
		if (isNaN(qty[u]))
		{
			qty[u]=1;
		} else {
			qty[u]=qty[u]+1;
		}

		if (qty[u]>2)
		{
			Calert("You cannot choose more than 2 players from the same club!");
			return false;
		}
	}


	/*	check name */
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	if (!(ind))
	{
		objaj.src= "/upd.php?act=chkteam&value="+escape(document.forms['ad'].teamname.value)+"&tst="+Math.random();
	} else if(ind=='chktransf') {
		var thestring='';
		for (i=1; i<=17; i++)
		{
			thestring+="&player_"+i+"="+eval("document.forms['ad'].player_"+i+".value");
		
		}
		objaj.src= "/upd.php?act="+ind+"&tst="+Math.random()+thestring;
	}

	


	return false;
	
}



function SS(frm,alert){
	if (!(alert))
	{	
		Calert("Checking ....");
	} else {
		Cmessage("Checking ....")
	}
	
	document.forms[frm].submit();
	return false;
}



function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}



function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}



function Calert(message,okbt){
	var error_content = document.getElementById('popcont');
	var popup = document.getElementById('popup');
	var top = document.getElementById('toppop');
	var ssubmit = document.getElementById('popupsubmit');
	ssubmit.className='submit';
	popup.className='';
	top.className='';
	error_content.className='';
	if (okbt)
	{
		ssubmit.style.display='none';
	} else {
		ssubmit.style.display='inline';
	}
	getpopup(1);
	error_content.innerHTML = message;
	//window.alert(message);
}



function Cmessage(message,okbt){
	var error_content = document.getElementById('popcont');
	var popup = document.getElementById('popup');
	var top = document.getElementById('toppop');
	var ssubmit = document.getElementById('popupsubmit');
	ssubmit.className='submit1';
	popup.className='okout';
	top.className='okbg';
	error_content.className='oktext';
	if (okbt)
	{
		ssubmit.style.display='none';
	} else {
		ssubmit.style.display='inline';
	}
	getpopup(1);
	error_content.innerHTML = message;
	
	//window.alert(message);
}



function processMail(){
	Cmessage("Processing ...");
	var objaj = document.getElementById ? document.getElementById("ajaxObj") : null;
	var emails='';
	for (var i=1; i<=7; i++)
	{
		eval ("var ema=document.forms['ad'].email_"+i+".value;");
		emails=emails+"&email_"+i+"="+escape(ema);
	}
	objaj.src = "/upd.php?act=mailsender&value="+document.forms['ad'].uniq_no.value+emails+"&tst="+Math.random();
	return false;

}



function Clearemail(){
	for (var i=1; i<=7; i++)
	{
		eval ("document.forms['ad'].email_"+i+".value='';");
	}
}


function chUp(action,formname,showalert){
	if (!(showalert))
	{
		Cmessage("Checking Login Information...",1)
	} else {
		Cmessage("Processing ...");
	}
	
	var objScript = document.getElementById ? document.getElementById("ajaxObj") : null;
	var reqLine='';
	var currform	=	eval("document."+formname);
	for(var i=0;i<currform.length;i++){
		reqLine+=currform[i].name+"="+escape(currform[i].value)+"&";
	}
	reqLine= "/upd.php?"+reqLine+"act="+action+"&timestamp="+Math.random();
	//window.alert(reqLine);
	objScript.src = reqLine;
	return false;
}



function chgLoc(loc){
	var timerA;
	timerA=setTimeout(document.location.href=loc, 500);
}


function getTeam(teamid){
	//if (window.mywin) mywin.close();
	var coords= wholePage();
	var scroll=getPageScroll();


	matop = (coords[3]-300)/2-100;
	maleft = (coords[0]-500)/2;
	
	mywin=window.open("/viewteam/"+teamid,"teamInfo","width=520,height=560,menubar=auto,resizable=no,status=no") ;
	mywin.moveTo(maleft,matop);
	mywin.focus();
	return false;
}


function initAnchors()
{
	
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];

		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "iinfo")){
			anchor.onmouseover = function () {showTip1(this); return false;}
			anchor.onmouseout = function () {hideTip1(); return false;}
		}
	}

	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','tip');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.zIndex = '90';
	//objOverlay.onmouseover=function{DonthideTip1(); return false;}
	
	objBody.insertBefore(objOverlay, objBody.firstChild);
}


function loadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}


function showTip1(obj){
	var tipid=obj.getAttribute("id");
	//window.alert(obj.offsetParent);
	if (tipid == '1')
	{
		//objtxt='Invite this team to join your Mini Leagues.';
		objtxt=obj.getAttribute("tip");
		showtip('tip',objtxt,obj);
	}
	
}

function hideTip1(){
	var ObjTip = document.getElementById ? document.getElementById('tip') : null;
	ObjTip.style.display='none';
	
}

function showtip(tipid,objtxt,obj){
	var ObjTip = document.getElementById ? document.getElementById(tipid) : null;
	//var objScript = document.getElementById ? document.getElementById("tipcontainer") : null;
	//ObjTip.style.top=obj.clientY+document.body.scrollTop+5+'px';
	//ObjTip.style.left=obj.clientX+document.body.scrollLeft-252+'px';
	//obj.offsetParent = document.getElementsByTagName("body").item(0);
	ObjTip.style.top = obj.offsetTop-45;
	ObjTip.style.left = obj.offsetLeft+50;
	//ObjTip.style.top='100px';
	if (ObjTip.style.display == 'none') 
	{
		
		ObjTip.style.display='block';
		ObjTip.innerHTML="<div>"+objtxt+"</div>";
	}	//else {
		//ObjTip.style.display='none';

		//if (currentID != tipid){
		//	clearTimeout(timerB);
		//	hideLayer();
		//}
	//}

	
}

function hidetip(){	
	str='hideLayer()';				
	timerB=setTimeout('eval(str)', 500);
}

function hideLayer(){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	var objScript = document.getElementById ? document.getElementById("tipcontainer") : null;
	ObjTip.style.visibility="hidden";objScript.src = "/tip.php";

}


function updatetip(name,value){
	var obj = document.getElementById ? document.getElementById(name) : null;
	obj.innerHTML = value;
}


function movetip(obj){
	var ObjTip = document.getElementById ? document.getElementById("tip") : null;
	ObjTip.style.top=obj.clientY+document.body.scrollTop;
	ObjTip.style.left=obj.clientX+document.body.scrollLeft-250;
}






loadEvent(initAnchors);

