
/* 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");
}

/* go to a page in the main window */
function openPageInMain(pageUrl){
	if(!window.opener || window.opener.closed){
		window.opener = window.open(pageUrl,'','');
		return false;
	}else{
		window.opener.document.location.href = pageUrl;
		window.opener.focus();
		return false;
	}
}

/* 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 openGallery(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"yes","no","yes","yes","530","500","yes","no","no");	
}
function openProduct(strLink,strWindowName)
{
	return openWindow(strLink,strWindowName,"yes","no","yes","yes","600","600","yes","no","no");	
}
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')
}


//************************************************************************
// sets a cookie
function setCookie(sKey, sValue, sExpires, sDomain, sPath){
	sExpires = (sExpires != null) ? ';expires=' + sExpires : '';
	sDomain = (sDomain != null) ? ';domain=' + sDomain : '';
	sPath = (sPath != null) ? ';path=' + sPath : '';
	document.cookie = sKey + '=' + sValue + sExpires + sDomain + sPath;
	return true;
}

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;
	}
}

var errormsg="";
//***************************************************************************
// function used to validate the Search form [site wide]
function doSearchSubmit(frmObj,searchscope)
{
//searchscope
// 1 => the simple search on the left hand top corner in being search on from within the search section
// 2 => the simple search on the left hand top corner in being search on from outside the search section

frmAction = '';

	if(isEmpty(frmObj.search_field.value))
		errormsg = errormsg + 'Please enter some search criteria.';
		
	if (errormsg!="")
	{
	alert(errormsg);
	errormsg="";
	return false;
	}
	else
	{
		if (searchscope == 1)//called from within the search section
		{
			if (frmObj.searchsection.value == 'normal')
				frmAction = 'index.cfm';
			if (frmObj.searchsection.value == 'images')
				frmAction = 'index_images.cfm';	
			if (frmObj.searchsection.value == 'audiovideo')
				frmAction = 'index_audiovideo.cfm';
		}
		if (searchscope == 2)//called from outside the search section
				frmAction = ''; // its left blank so the action attribute in the form tag is used and the IF statement is bypasssed below
		//alert(frmObj.searchsection.value + ' : ' +frmAction);

		if (!isEmpty(frmAction))
		{
			frmObj.action = frmAction;
			frmObj.submit();
		}
	}
return true;
}

function dollarFormat(iAmount){
	if(iAmount - parseInt(iAmount) == 0){
		sAmount = iAmount + '.00';
	}else{
		iAmount += '';
		sAmount = (iAmount.split('.')[1].length == 2) ? iAmount : iAmount + '0';
	}
	return sAmount;
}