var szURL;
var szText;
var nHeight;
var nWidth;
   var http_request = false;
   var processor = new XSLTProcessor();  


var loaded = true;

if (document.images) {
menuImg = new Array( 18 );
menuImg[ 1 ] = new Image(); menuImg[ 1 ].src = "gifs/nav_B1.gif";
menuImg[ 2 ] = new Image(); menuImg[ 2 ].src = "gifs/nav_B1_over.gif";
menuImg[ 3 ] = new Image(); menuImg[ 3 ].src = "gifs/nav_B2.gif";
menuImg[ 4 ] = new Image(); menuImg[ 4 ].src = "gifs/nav_B2_over.gif";
menuImg[ 5 ] = new Image(); menuImg[ 5 ].src = "gifs/nav_B3.gif";
menuImg[ 6 ] = new Image(); menuImg[ 6 ].src = "gifs/nav_B3_over.gif";
menuImg[ 7 ] = new Image(); menuImg[ 7 ].src = "gifs/nav_B4.gif";
menuImg[ 8 ] = new Image(); menuImg[ 8 ].src = "gifs/nav_B4_over.gif";
menuImg[ 9 ] = new Image(); menuImg[ 9 ].src = "gifs/nav_B5.gif";
menuImg[ 10 ] = new Image(); menuImg[ 10 ].src = "gifs/nav_B5_over.gif";
menuImg[ 11 ] = new Image(); menuImg[ 11 ].src = "gifs/nav_B6.gif";
menuImg[ 12 ] = new Image(); menuImg[ 12 ].src = "gifs/nav_B6_over.gif";
menuImg[ 13 ] = new Image(); menuImg[ 13 ].src = "gifs/nav_B7.gif";
menuImg[ 14 ] = new Image(); menuImg[ 14 ].src = "gifs/nav_B7_over.gif";
menuImg[ 15 ] = new Image(); menuImg[ 15 ].src = "gifs/home1.gif";
menuImg[ 16 ] = new Image(); menuImg[ 16 ].src = "gifs/home2.gif";
menuImg[ 17 ] = new Image(); menuImg[ 17 ].src = "gifs/nav_B8.gif";
menuImg[ 18 ] = new Image(); menuImg[ 18 ].src = "gifs/nav_B8_over.gif";

menewImg = new Array( 16 );
menewImg[ 1 ] = new Image(); menewImg[ 1 ].src = "gifs/wwelet3_b1.gif";
menewImg[ 2 ] = new Image(); menewImg[ 2 ].src = "gifs/wxelet3_b1.gif";
menewImg[ 3 ] = new Image(); menewImg[ 3 ].src = "gifs/wwelet3_b2.gif";
menewImg[ 4 ] = new Image(); menewImg[ 4 ].src = "gifs/wxelet3_b2.gif";
menewImg[ 5 ] = new Image(); menewImg[ 5 ].src = "gifs/wwelet3_b3.gif";
menewImg[ 6 ] = new Image(); menewImg[ 6 ].src = "gifs/wxelet3_b3.gif";

}

function swapImg( imgName, imgNo ) 
    {
	if (document.images != null) {
    document[imgName].src = menuImg[ imgNo ].src;
    }
}

function swapnImg( imgName, imgNo ) 
    {
	if (document.images != null) {
    document[imgName].src = menewImg[ imgNo ].src;
    }
}

function team_sel(link)
        {
		var frm;
		var sel;
		var newp;

		frm = document.forms['FRoute'];
		if (link == 'home')
			{
			newp = 'index.php?item=news&team=0';
			window.location.replace(newp);
			}
		else
			{
			sel = frm.team.options[frm.team.selectedIndex].value;
//			alert(sel)
			if (sel == "0")
				{
				alert('Please select a team');
				frm.team.focus();
				}
			else
				{
				newp = 'index.php?item=' + link + '&team=' + sel;
				window.location.assign(newp.toString());
				}
			}

}

function league_sel()
        {
			var selectedSeason ="7596389";
			var selectedDivision = "";
			var ref;
			var sel;
			var frm;

			frm = document.forms['FRoute'];
			sel = frm.team.options[frm.team.selectedIndex].value;
//			alert(sel);

			if (sel == 0)
				{
				alert('Please select a team');
				frm.team.focus();
				}
			else
				{

				switch(sel)
				{
					case "19":  
						
						selectedSeason ="2550003";
						selectedDivision = "7647801";
						break; 
					case "18":  
						selectedSeason ="8040420";
						selectedDivision = "8493811";
						break; 
					case "17": 
						selectedDivision = "7287768";
						break; 
					case "16":  						
					    selectedSeason ="2550003";
						selectedDivision = "9833802";
						break; 
					case "15":  
						
					    selectedSeason ="2550003";
						selectedDivision = "7647801";
						break; 
					case "14":  
						selectedDivision = "4674070";
						break; 
					case "13": 
						selectedDivision = "3494714";
						break; 
					case "12": 
						selectedDivision = "7440207";
						break; 
					case "11": 
						selectedDivision = "6353581";
						break; 
					case "10": 
						selectedDivision = "1731749";
						break; 
					case "9": 
						selectedDivision = "1581369";
						break; 
					case "8": 
						selectedDivision = "9833802";
						break; 
					case "7": 
						selectedDivision = "9833802";
						break; 
					case "6": 
						selectedDivision = "1565324";
						break; 
					}

				if (selectedDivision == "")
					{
					alert("Sorry no league details for your team")
					}
				else
					{
					ref = "index.php?item=iframe&selectedDivision=" + selectedDivision + "&selectedSeason=" + selectedSeason + "&team=" + sel;
					parent.location.href=ref;
					}
				}
}


function teamcookie(sel)
		{
		var team = document.FRoute.team;
		var today = new Date();
		today.setTime( today.getTime() );
		var expires_date = new Date( today.getTime() + (90 * 1000 * 24 * 60) );

//		alert(team.options[team.selectedIndex].value);
//		document.cookie = 'team=' + team.options[team.selectedIndex].value + ';expires=' + expires_date.toGMTString() + '; path=/';
		}


function displayWindowResizable(szURL, nWidth, nHeight)
{
   MapWin=window.open(szURL, '_blank', 'scrollbars,resizable,width=' + nWidth + ',height=' + nHeight);
}

function displayWindownoResize(szURL, nWidth, nHeight)
{
   MapWin=window.open(szURL, '_blank', 'toolbar=0,status=0,width=' + nWidth + ',height=' + nHeight);
}

function NewWin(URL)
{
   MapWin = window.open(URL,'_blank');
}

function setStatusText(szText)
{
   window.status = szText;
   return true;
}
function openPage(szURL)
{
//  location.href = szURL;
}
function clearStatusText()
{
   window.status = '';
   return true;
}

function Bookmark()
{
    if (confirm("Do you want to add Vipers to your list of Favourites?"))
       {
       window.external.AddFavorite( top.location.href, 'The Vipers' );
       return false;
       }
}

function calcteam() {

         var steam = 0;
         var age_now;
         var age_then;

         ind = parent.FMiddle.document.Whatteam.day.selectedIndex;
         born_dd = parent.FMiddle.document.Whatteam.day.options[ind].text;
         ind = parent.FMiddle.document.Whatteam.month.selectedIndex;
         born_mm = parent.FMiddle.document.Whatteam.month.options[ind].value;
         ind = parent.FMiddle.document.Whatteam.year.selectedIndex;
         born_yy = parent.FMiddle.document.Whatteam.year.options[ind].text;

         today = new Date();
         today_dd = today.getDate();
         today_mm = today.getMonth() + 1;
         today_yy = today.getFullYear();

         now_yy = today_yy - born_yy;
         now_mm = today_mm - born_mm;
         now_dd = today_dd - born_dd;

         if (now_mm < 0)
            {
            now_yy = now_yy - 1;
            now_mm = now_mm + 12;
            }

         if (now_dd < 0)
            {
            now_mm = now_mm - 1;
            }

         age_now = now_yy + " years " + now_mm + " months"

         season_dd = 31;
         season_mm = 8;
         if (today_mm > 8)
            {
            season_yy = today_yy;
            }
         else
            {
            season_yy = today_yy - 1;
            }
         
         then_yy = season_yy - born_yy;
         then_mm = season_mm - born_mm;
         then_dd = season_dd - born_dd;

         if (then_mm < 0)
            {
            then_yy = then_yy - 1;
            then_mm = then_mm + 12;
            }
    
         if (then_dd < 0)
            {
            then_mm = then_mm - 1;
            }

         age_then = then_yy + " years " + then_mm + " months"

         season_team = then_yy + 1;      

         alert("You are " + age_now + ".\nWhen the season started on " + season_yy + ":09:01. \nyou were " + age_then + " old.\n\nYou are eligible to play for the Under " + season_team + "'s");

         return false;
         }

function login() 
         {
         alert("In submit");
         return false;
         }


function showadvert(obj) {

	var divn = document.getElementById('adv');
	var srcdoc = ".\/sponsors\/" + obj + ".htm";

	if(!loaded) return;
	if (divn != null)
		{
//		alert(srcdoc);
		divn.style.display = 'block'; 
    	document.getElementById("advrt").src=srcdoc;
		}
}

function hideadvert() {

	var divn = document.getElementById('adv');
	if(!loaded) return;
	if (divn != null)
		{
		divn.style.display = 'none'; 
		}

}

function ListCat()
	{
	document.Tabs.submit();
	}


function Reconed()
{

//  function Reconed(chk,amt)
//	var total = parseFloat(document.Recon.TOTAL.value);
//	total = (Math.round(total * 100)) / 100;
	
//	var amount = parseFloat(amt);
//	amount = (Math.round(amount * 100)) / 100;
	
//	alert(document.Recon.bfvalue.value);
//	var bf = document.Recon.bfvalue.value;
//	bf = (Math.round(bf * 100)) / 100;
//		alert(bf);
	
//	alert(total);
//	alert(amount);

	var bf = parseFloat(document.Recon.bfvalue.value);
	bf = (Math.round(bf * 100)) / 100;

	total = 0;

	for (x=0;x<document.Recon.elements.length ;x++ )
		{
   		if(document.Recon.elements[x].type == 'checkbox')
			{
    			if(document.Recon.elements[x].checked == true) 
      				{
        			total = total + parseFloat(document.Recon.elements[x+1].value);
      				}
			}
		}

//	alert (total);
	total = (Math.round(total * 100)) / 100;
//	alert(total);
    	document.Recon.TOTAL.value = reformatFloat(total, 2);  

	total = (Math.round((total + bf) * 100) / 100);
//	alert("bf=" + bf + ";total=" + total);
    	document.Recon.CF.value = reformatFloat(total, 2);  

}



function reformatFloat(s, requiredDecimalPlaces)
{
	//*** Ensure amounts input are displayed in correct format ***

	var decimalPoint, actualDecimalPlaces; 

	s = trimBlanks(s);
	decimalPoint  = s.indexOf(".");

	if (decimalPoint == -1) {
		s = s + ".";
		decimalPoint = s.length - 1;
	}
	else if (decimalPoint == 0) {
		s = "0" + s;
		decimalPoint = 1;
	}
	else
	{
	s = s.substring(0,decimalPoint + 3);
	}

	actualDecimalPlaces = s.length - decimalPoint - 1;

	for (i = actualDecimalPlaces; i < requiredDecimalPlaces; i++)
		s = s + "0";

	return s;
}


function trimBlanks(s) 
{
	var separator = " ";
	var arr;
	var trimmedString = "";
	var t = s.toString();

	arr = t.split(separator);

	for(var i=0; i<arr.length; i++)
		trimmedString = trimmedString.concat(arr[i]);
	return trimmedString;
}


function ValidatePlayer(frm)
{

	var field1 = frm.NAME;
	var field2 = frm.FIRSTNAME;

        if (field1.value=='' || field2.value=='')
           {
           alert("Please Enter first name and surname");
           return false;
           }

        document.Player.submit();
		return true;

}

function ValidateTeam(frm)
{

	var field1 = frm.NAME;
	var field2 = frm.SHORTNAME;

        if (field1.value=='' || field2.value=='')
           {
           alert("Please Enter name and short name");
           return false;
           }

        document.Team.submit();
		return true;

}

   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
	    alert(result);
            document.getElementById('adv').innerHTML = result;    
	    divn.style.display = 'block'; 
     
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function pitch(obj) {

	var divn = document.getElementById(obj);

	if (divn.style.display == 'block')
		{
		divn.style.display = 'none'; 
		}
	else
		{
		divn.style.display = 'block'; 
		}
				
   }
