var sBrowserVersion = navigator.appVersion;

var IE = (document.all) ? true : false;
var IE4 = (IE && !document.getElementById) ? true : false;
var IE5 = (IE && document.getElementById) ? true : false;
var IE6 = IE5 ? (sBrowserVersion.match(/MSIE 5/) ? false : true) : false;

var NS4 = (document.layers) ? true : false;
var NS6 = (document.getElementById && !IE) ? true : false;

var map;
var geocoder;
var gsZoom;

//-----------------------------------------------------------------------------------------
// Google mapping
//-----------------------------------------------------------------------------------------

function loadMap( lsPostcode, lsZoom) {
    if (GBrowserIsCompatible() && document.getElementById("map")) {
        var bounds = new GLatLngBounds();
        map = new GMap2(document.getElementById("map"));
        geocoder = new GClientGeocoder();
        map.addControl(new GSmallMapControl());
        //map.addControl(new GMapTypeControl());
        map.setCenter( new GLatLng(0,0), 7);
        geocoder.getLocations( lsPostcode, addAddressToMap);
        gsZoom = lsZoom;
    }
    else 
    {
        //alert("Sorry, mapping feature not compatible with this browser");
    }
}

function addAddressToMap(response) 
{
  map.clearOverlays();
  if (!response || response.Status.code != 200) 
  {
    //alert("Sorry, we were unable to geocode that address");
  } 
  else 
  {
    place = response.Placemark[0];
    bounds = new GLatLngBounds();
    point = new GLatLng( place.Point.coordinates[1], place.Point.coordinates[0]);
    bounds.extend( point);
    map.setZoom( map.getBoundsZoomLevel(bounds));
    map.setCenter( bounds.getCenter(), gsZoom);
    marker = new GMarker(point);
    map.addOverlay(marker);
    //map.openInfoWindowHtml(map.getCenter(), '<b style="font-family:arial">Lincoln City Football</b>');
  }
}


//-----------------------------------------------------------------------------------------

function ValidateLogin( loInputForm)
{
	var sErrors =''
	var bErrors, loForm;
	try
	{
		gbFieldFocus = false;
		loForm = GetForm(loInputForm);
			
		sErrors += RequiredField(loForm, "Password", "Password")
				+ ValidField(loForm, "email", "Email", "Email address")
		bErrors = Boolean(sErrors);
		
		if (bErrors)
		{
			sErrors = "Please complete the following in your form:\n\n"
				+ sErrors;
			alert(sErrors);
		}
		else
		{
			document.body.style.cursor='wait';
		}
	}
	catch (eError)
	{
		alert('eError: ' + eError.description);
		bErrors = true;
	}
	return (!bErrors);
}

//-----------------------------------------------------------------------------------------

function IsIn(inArray, inItem)
{
	var iArrayIndex, bIsIn;
	bIsIn = false;
	for (iArrayIndex in inArray)
	{
		if (inArray[iArrayIndex] == inItem)
		{
			bIsIn = true;
			break;
		}
	}
	return(bIsIn);
}

//---------------------------------------------------------------------------

function ScrollToEnd()
{
	window.scrollTo(0,999999);
}

//---------------------------------------------------------------------------

/* use this to find width (& height) : javascript:alert(document.body.clientWidth) */

var winPopup;

function popupWindow(strUrl, intWidth, intHeight, strName, bNoScroll, bWindowFeatures, bPopunder)
{
	var sParams, iScreenX, iScreenY;
	if (!strName)
	{
		strName = 'winPopup';
	}

	if(window.screen)
	{
		intWidth = (intWidth ? Math.min(intWidth, window.screen.availWidth-45) : window.screen.availWidth-45);
		intHeight = (intHeight ? Math.min(intHeight, window.screen.availHeight-60) : window.screen.availHeight-60);

		iScreenX = (window.screen.availWidth - intWidth) /2
		iScreenY = (window.screen.availHeight - 20 - intHeight) /2
	}

	//alert(iScreenX + '::' + intWidth)
	//alert(iScreenY + '::' + intHeight)

	sParams = (bWindowFeatures ? 'toolbar=1,titlebar=1,status=1,' : 'toolbar=0,titlebar=0,status=0,') 
		+ 'scrollbars=' + (bNoScroll ? 0 : 1) + ',resizable=' + (bNoScroll ? 0 : 1) 
		+ (intWidth ? ',width=' + intWidth : '') + (intHeight ? ',height=' + intHeight : '')
		+ ",left=" + iScreenX + ",top=" + iScreenY + ",screenX=" + iScreenX + ",screenY=" + iScreenY ;
		
	winPopup = window.open(strUrl, strName, sParams);
	if (bPopunder && winPopup)
	{
		window.focus()
	}
	else if (winPopup)
	{
		winPopup.focus();
	}
	return (winPopup);
}

function popupNoScrollWindow(strUrl, intWidth, intHeight, strName, bPopunder)
{
	winPopup = popupWindow(strUrl, intWidth, intHeight, strName, true, false, bPopunder)
	return (winPopup);
}

function popupNormal(strUrl, strName)
{
	if (!strName)
	{
		strName = 'winPopup';
	}
	winPopup = window.open(strUrl, 'winPopup');
	return (winPopup);
}

//-----------------------------------------------------------------------------------------


function SelectAllCheckboxes(sCheckBoxName, bSelValue)
{
	var oCheckBoxes, j
	oCheckBoxes = document.getElementsByName(sCheckBoxName);
	for(j = 0; j < oCheckBoxes.length; j++) 
	{
		oCheckBoxes[j].checked = bSelValue
	}
}

//-----------------------------------------------------------------------------------------


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

//-----------------------------------------------------------------------------------------

function InStr(strSearch, charSearchFor)
{
            for (i=0; i < strSearch.length; i++)
            {
                  if (charSearchFor == Mid(strSearch, i, 1))
                  {
                        return i;
                  }
            }
            return -1;
}
