/* ****************************************************

	Application: Athletics Australia
	
	File: common.js
	
	Type: Javascript Source
	
	Desc: global js code library
	
	Comments: file duplicated from Olympics > SydHob > Roadtrain
	
	Author: Fred Randell <fred@redsquare.com.au>
	Date:  01/08/00
	Version: 1.0.0
	
	***** Modification Details *****
	
	DATE  NAME  MODIFICATION

**************************************************** */

/* START JS Browser detect code */
var bow="n";
var bow1="n";

bName = navigator.appName;
bVer = parseInt(navigator.appVersion);

if (bName == "Netscape" && bVer >= 3)
{
	bow = "ok";
	bow1 = "ok";
}
else if (bName == "Microsoft Internet Explorer" && bVer > 3)
{
	bow = "ok";
	bow1="ok";
}
else if (bName == "Microsoft Internet Explorer" && bVer >=2)
{
	bow = "ok";
}

var IS_AOL=0;

if (navigator.userAgent)
{
	if (navigator.userAgent.indexOf("AOL") >=0)
	{
		IS_AOL=1;
		bow1="n";
	}
}
else
{
	bow="n"
	bow1="n";
}
/* END JS Browser detect code */

/* changeImage function modified to work with the open/close images on the schedule page */
function changeImage(row,s,sched)
{
	var h = (s==1)?"r":"";
	var row_src = (parseInt(sched)>=1)?'r'+sched:row;

	if(document.images) document.images[row].src = eval(h + row_src + ".src");
}

/* general utility function that accepts parameters for url of filename (f),
target Window (t), 
menubar (m - yes/no), location (l - yes/no), 
scrollbars (s - yes/no), resizeable (r - yes/no), 
window width (w), window height (h). 
Default values are laid out in the function.

23/10: add directories and toolbar options (fred)*/

function openWindow(f, t, m, l, s, r, w, h, st, tool, d)
{
	var fn_filename = "";
	var fn_target = "_blank";
	var fn_menubar = "yes";
	var fn_location = "yes";
	var fn_scrollbars = "yes";
	var fn_resizable = "yes";
	var fn_width = "600";
	var fn_height = "400";
	var fn_status = "yes";
	var fn_toolbar = "yes";
	var fn_directories = "yes";
	
	if (arguments.length > 0)
	{
		if (f != "" || f != null) fn_filename = f;
		if (t != "" || t != null) fn_target = t;
		if (m == "no") fn_menubar = m;
		if (l == "no") fn_location = l;
		if (s == "no") fn_scrollbars = s;
		if (r == "no") fn_resizable = r;
		if (w > 0) fn_width = w;
		if (h > 0) fn_height = h;
		if (st == "no") fn_status = st;
		if (tool == "no") fn_toolbar = tool;
		if (d == "no") fn_directories = d;
	}
	
	self.name="mainWin";
	
    if (bow!="ok") return (true);
	
	argumentString = 'menubar='+fn_menubar+',location='+fn_location+',scrollbars='+fn_scrollbars+',resizable='+fn_resizable+',width='+fn_width+',height='+fn_height+',status='+fn_status+',toolbar='+fn_toolbar+',directories='+fn_directories;
	
	remote =  window.open(fn_filename,fn_target,argumentString);

    if (remote == null) return true;

    if(bow1 == "ok"){
		window.setTimeout('focusWin()',1000);
	}
	return (false);
}

function focusWin(){
	if(!remote.closed){
		remote.focus();
	}
}

/* short cut function for opening banner ad or external link windows 
uses the openWindow general utility which should be above */
function openLinkWin(fName,targetName,winWidth,winHeight)
{
    if (bow!="ok") return (true);

	var fn_fName = "";
	var fn_targetName = "_blank";
	var fn_winWidth = 620;
	var fn_winHeight = 400;

	if (arguments.length > 0)
	{
		if (fName != "" || fName != null) fn_fName = fName;
		if (targetName != "" || targetName != null) fn_targetName = targetName;
		if (winWidth > 0) fn_winWidth = winWidth;
		if (winHeight > 0) fn_winHeight = winHeight;
	}

	return openWindow(fn_fName,fn_targetName,'yes','yes','yes','yes',fn_winWidth,fn_winHeight,'yes','yes','yes')
}

function isEmpty(inStr){
	if(trim(inStr).length == 0){
		return true;
	}else{
		return false;
	}
}

//************************************************************************
// trims a form element
function trim(tmpStr) 
{
  var atChar;
 
  if (tmpStr.length > 0) atChar = tmpStr.charAt(0);
  while (isSpace(atChar)) 
  {
    tmpStr = tmpStr.substring(1, tmpStr.length);
    atChar = tmpStr.charAt(0);
  }
  if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length-1);
  while (isSpace(atChar)) 
  {
    tmpStr = tmpStr.substring(0,( tmpStr.length-1));
    atChar = tmpStr.charAt(tmpStr.length-1);
  }
//  alert("here'"+tmpStr+"'");
  return tmpStr;
}

function isSpace(inChar) 
{
  return (inChar == ' ' | inChar == '\t' || inChar == '\n');
}

//************************************************************************
// checks for specfic telstra email only
function isValidTelstraEmail(str)
{
	str += '';
	namestr= '';
	domainstr = '';
	namestr = str.substring(0,str.indexOf("@")); // get all the info before the "@"
	domainstr = str.substring(str.indexOf("@")+1,str.length); // get all the info after the "@"
	tailstr = str.substring(str.indexOf(".")+1,str.length) // after the first "." how many chars are they

	if( (namestr.length == 0) || (domainstr.indexOf(".") <= 0) || (domainstr.length == 0) || (domainstr.indexOf("@") != -1) || tailstr.length == 0) return false;
	if(	domainstr.toUpperCase() != 'TELSTRA.COM') return false;


	return true;
}
//************************************************************************
// checks for valid email only
function isValidEmail(str)
{
	str += '';
	namestr= '';
	domainstr = '';
	namestr = str.substring(0,str.indexOf("@")); // get all the info before the "@"
	domainstr = str.substring(str.indexOf("@")+1,str.length); // get all the info after the "@"
	tailstr = str.substring(str.indexOf(".")+1,str.length) // after the first "." how many chars are they

	if( (namestr.length == 0) || (domainstr.indexOf(".") <= 0) || (domainstr.length == 0) || (domainstr.indexOf("@") != -1) || tailstr.length == 0) return false;

	return true;
}
//************************************************************************
// As default none of the radio boxes are select hence on submit check to see if atleat one is selected else throw error
function radioCheck(field)
{
	for (j = 0; j < field.length; j++)
		{
			if (field[j].checked)
				return true
	  	}
	return false;
}

//***************************************************************************
// validate phone numbers
function validatePhone(string) {

    var Chars = "0123456789() ";
 
    for (var i = 0; i < string.length; i++) 
	{
       if (Chars.indexOf(string.charAt(i)) == -1)
	    return false;
    }
    return true;
}

function gotoSiteNavUrl(){
	if (document.siteNavFrm.siteNav[document.siteNavFrm.siteNav.selectedIndex].value == -1) return false;
	else
	{
		url = document.siteNavFrm.siteNav[document.siteNavFrm.siteNav.selectedIndex].value;
		top.location.href = url;
		return false;
	}
}