/*
	// ------------------------------------------------------------------------------------------------- >>>>>>>>>>
	// Filename : misc.js
	// Author: OMEOM Ltd.
	// Date: 11/09/2008
	// Version: 1.0
	// Description: Global JavaScript file for this client/site
	//						  DO NOT EDIT WITHOUT PRIOR PERMISSON FROM AUTHOR.
	// Notice: This software is not open source and should not be distributed or reused with out consent from the author.
	// Copyright (c) 2008, OMEOM Ltd,  All rights reserved.
	// ------------------------------------------------------------------------------------------------- >>>>>>>>>>
*/

function openAnySize (url, w, h, name) {
	var winopts = "toolbar=no,location=no,directories=no,status=no,";
	winopts = winopts + "menubar=no,scrollbars=yes,resizable=yes,";
	winopts = winopts + "width=" + w + ",height=" + h; remote = window.open(url,name,winopts);
}

/* -------------------------------------------------------------------------------------------------------------- */

function openAnySizeWithToolbar (url, w, h, name) {
	var winopts = "toolbar=yes,location=no,directories=no,status=no,";
	winopts = winopts + "menubar=no,scrollbars=yes,resizable=yes,";
	winopts = winopts + "width=" + w + ",height=" + h; remote = window.open(url,name,winopts);
}

/* -------------------------------------------------------------------------------------------------------------- */

function openAnySizeWithStatus (url, w, h, name) {
	var winopts = "toolbar=no,location=no,directories=no,status=yes,";
	winopts = winopts + "menubar=no,scrollbars=yes,resizable=yes,";
	winopts = winopts + "width=" + w + ",height=" + h; remote = window.open(url,name,winopts);
}

/* -------------------------------------------------------------------------------------------------------------- */

function findObj(n, d) {
  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 && document.getElementById) x=document.getElementById(n); return x;
}

/* -------------------------------------------------------------------------------------------------------------- */

function showHideLayers() {
	var i,p,v,obj,args=showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	obj.visibility=v; }
}

/* -------------------------------------------------------------------------------------------------------------- */

function ShowField(option) {
	var formField = document.getElementById(option);

	if(formField.value == 'GB') {
		document.getElementById('toggleCounty1').style.display='inline';
		document.getElementById('toggleCounty2').style.display='inline';
		document.getElementById('toggleCounty3').style.display='inline';
	} else {
		document.getElementById('toggleCounty1').style.display='none';
		document.getElementById('toggleCounty2').style.display='none';
		document.getElementById('toggleCounty3').style.display='none';
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function ShowField2(option) {
	if(option == '39') {
		document.getElementById('otherTitle').style.display = 'inline';
		document.getElementById('otherField').style.display = 'inline';
	} else {
		document.getElementById('otherTitle').style.display = 'none';
		document.getElementById('otherField').style.display = 'none';
	}
}


/* -------------------------------------------------------------------------------------------------------------- */

function ShowCountyOptions(refVal) {
	/*var val = '';
	val = document.forms["account-form-step1"].country.value;
	val = document.getElementById('country').value; 
	alert(val);*/

	if(refVal != 'GB') {
		document.getElementById('toggleCounty1').style.display='none';
		document.getElementById('toggleCounty2').style.display='none';
		document.getElementById('toggleCounty3').style.display='none';
	} else {
		document.getElementById('toggleCounty1').style.display='inline';
		document.getElementById('toggleCounty2').style.display='inline';
		document.getElementById('toggleCounty3').style.display='inline';
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function ShowHideElement(element, id, val) {

	var formField = document.getElementById(element);

	if(formField.value == val)
	{
		document.getElementById(id).style.display = 'inline';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function ShowDownloadButton(element, id) {
	if(document.getElementById(element).checked == true)
	{
		document.getElementById(id).style.display = 'inline';
	} else {
		document.getElementById(id).style.display = 'none';
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function ShowProgressBar(id) {
		document.getElementById(id).style.display = 'inline';
		document.getElementById("darkBackgroundLayer").style.display = "";
}

/* -------------------------------------------------------------------------------------------------------------- */

function showLogin(option) {
	if(option == 'manager') {
		document.getElementById('optionsForm').style.display = 'none';
		document.getElementById('playerForm').style.display = 'none';
		document.getElementById('managerForm').style.display = 'inline';
	} else if (option == 'player') {
		document.getElementById('optionsForm').style.display = 'none';
		document.getElementById('playerForm').style.display = 'inline';
		document.getElementById('managerForm').style.display = 'none';
	} else {
		document.getElementById('optionsForm').style.display = 'inline';
		document.getElementById('playerForm').style.display = 'none';
		document.getElementById('managerForm').style.display = 'none';
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function RefreshParent()
{
	window.parent.location.href = window.parent.location.href;
}

/* -------------------------------------------------------------------------------------------------------------- */

function clearInput(id)
{
	if (document.getElementById(id).value == document.getElementById(id).value) {
	document.getElementById(id).value = "" ;
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function popUp(URL)
{
	//alert("javascript: popUp(" + URL + ")");
	day = new Date();
	id = day.getTime();
	var height = 550;
	//alert("getAvailableHeight()=" + getAvailableHeight());

	if(getAvailableHeight() >= 700)
	{
		height = 850;
	}

	eval("page" + id + " = window.open('" + URL + "', '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=750,height=" + height + ", left=400,top=50');");
}

/* -------------------------------------------------------------------------------------------------------------- */

function cropperPopUp(URL)
{
	//alert("javascript: cropperPopUp(" + URL + ")");
	day = new Date();
	id = day.getTime();
	var height = 550;
	//alert("getAvailableHeight()=" + getAvailableHeight());

	if(getAvailableHeight() >= 800)
	{
		height = 800;
	}

	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=750,height=" + height + ",left=400,top=50');");
}

/* -------------------------------------------------------------------------------------------------------------- */

function getAvailableHeight()
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}

	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//window.alert( 'Width = ' + myWidth );
	//window.alert( 'Height = ' + myHeight );

	return myHeight;
}
/* -------------------------------------------------------------------------------------------------------------- */

function call_refreshTeamData()
{
	thisMovie("flashDiv").call_refreshTeamData();
}

/* -------------------------------------------------------------------------------------------------------------- */

function call_refreshImage()
{
	thisMovie("flashDiv").call_refreshImage();
}

/* -------------------------------------------------------------------------------------------------------------- */

function CreateBookmarkLink(bookmarkTitle,bookmarkURL) 
{
	if (window.sidebar) // Mozilla Firefox Bookmark
	{
		window.sidebar.addPanel(bookmarkTitle, bookmarkURL, "");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite(bookmarkURL, bookmarkTitle); 
	} else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
 }

/* -------------------------------------------------------------------------------------------------------------- */

function addP(e,ta)
{
	lengthCount = document.forms[0].elements[0].value.length
	var characterCode
	e = e||event // ff || ie
	if(e && e.which)
	{//ff
		characterCode = e.which
	} else {//ie
		characterCode = e.keyCode
	}	 

	if(characterCode == 8)
	{ 
		ta.value = ta.value.substring(0,ta.value.length-1)
		// ta.select();ta.focus();
		document.forms[0].managerUserName.value=ta.value
		return false
	} else {
		ta.value += String.fromCharCode(characterCode)	 
		//ta.select();ta.focus(); 
		document.forms[0].managerUserName.value=ta.value
		return false
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

var lengthCount = 1
function checkBackspace()
{ //for ie
	if(document.all && event.keyCode)
	{
		var el = event.srcElement//||e.target
		if(event.keyCode == 8)
		{
			if(el.value.length-lengthCount==3)
			{
				el.value = el.value.substring(0,el.value.length-3)
			}else{
				el.value = el.value.substring(0,el.value.length-1)
			}
			
			//el.select();el.focus();
			document.forms[0].managerUserName.value=el.value
			event.returnValue = false
		}
	}
	lengthCount-=1
}

/* -------------------------------------------------------------------------------------------------------------- */

function checkAllFields(ref, fieldName)
{
var chkAll = document.getElementById('checkAll');
var checks = document.getElementsByName(fieldName);
var boxLength = checks.length;
var allChecked = false;
var totalChecked = 0;
	if ( ref == 1 )
	{
		if ( chkAll.checked == true )
		{
			for ( i=0; i < boxLength; i++ )
			checks[i].checked = true;
		}
		else
		{
			for ( i=0; i < boxLength; i++ )
			checks[i].checked = false;
		}
	}
	else
	{
		for ( i=0; i < boxLength; i++ )
		{
			if ( checks[i].checked == true )
			{
			allChecked = true;
			continue;
			}
			else
			{
			allChecked = false;
			break;
			}
		}
		if ( allChecked == true )
		chkAll.checked = true;
		else
		chkAll.checked = false;
	}
	for ( j=0; j < boxLength; j++ )
	{
		if ( checks[j].checked == true )
		totalChecked++;
	}
}

/* -------------------------------------------------------------------------------------------------------------- */

function submitFormPlusField(formName, fieldName, feildValue)
{
   var form = document.forms[formName];
   var el = document.createElement("input");
   el.type = "hidden";
   el.name = fieldName;
   el.value = feildValue;
   form.appendChild(el);
   form.submit();
}
