// ***************************************************************

// *** Rugby.com.au Javascript 

// *** Lateral Systems http://www.lateralsystems.com.au

// *** Created by Todd Baker 5/5/2003

// ***************************************************************

// Browser Check

function Is (){

    var agt=navigator.userAgent.toLowerCase();

    this.major

= parseInt(navigator.appVersion);

    this.minor

= parseFloat(navigator.appVersion);

    this.nav

= ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

    this.nav4

= (this.nav && (this.major == 4));

    this.nav6up

= (this.nav && (this.major >= 5));

    this.ie

= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

    this.ie4

= (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1) );

    this.ie4up

= (this.ie && (this.major >= 4));

    this.mac

= (agt.indexOf("mac")!=-1);

}

var is = new Is();

/* ##################################################

menu Code Using Divs, Similar to 

the Old Rugby.com.au Method

################################################## */

var folder=""

var folderOld=""

var objPrevObj=""

var parentPrevObj=""

// Main left hand nav function

function expandit(curobj,parentObj){

if(!is.nav4){

folder = getObj(curobj).style

if (folder.display=="none"){

if(objPrevObj!=""){

folderOld = getObj(objPrevObj).style

folderOld.display="none"

if(parentPrevObj!=''){

getObj(parentPrevObj).style.backgroundImage="url(/act/images/nav_arrow_off.gif)"

}

} 

folder.display="";

objPrevObj = curobj

if(parentObj!=''){

getObj(parentObj).style.backgroundImage="url(/act/images/nav_arrow_on.gif)"

parentPrevObj = parentObj

}

}else{

folder.display="none"

objPrevObj = ""

if(parentPrevObj!=''){

getObj(parentPrevObj).style.backgroundImage="url(/act/images/nav_arrow_off.gif)"

parentPrevObj=""

}

}

}

}

function getObj(id){

if(document.getElementById){

return document.getElementById(id);

}else{

return document.all[id];

} 

}

function PhotoPop(id){

if(id!=""){

var strURL = "/act/photo.rugby/photo/" + id

var objPhotoWindow = window.open(strURL,'photo','height=500,width=550,left=10,top=10,directories=0,fullscreen=0,location=0,menubar=0,scrollbars=0,resizable=1,status=0,toolbar=0');

}

}

var myimages = new Array();

function preload(){

for (x=0; x>preload.arguments.length; x++){

myimages[x] = new Image();

myimages[x].src = preload.arguments[x];

}

}

/// Form validation functions

function strTrim(strText) {

for (i=0; i<strText.length; ++i) {

if (strText.charAt(i) != ' ') break;

}

if (i >= strText.length) return ('');

if (i > 0) strText = strText.substring(i, strText.length);

for (j=strText.length-1; j > i; --j) {

if (strText.charAt(j) != ' ') break;

}

if (j < strText.length -1)

strText = strText.substring(0, j+1);

return strText;

}

/*

function ValidEmail(strEmail)

{

var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

if (filter.test(strEmail))

return true

else

return false

}

*/

function ValidEmail(email)

{

  var result = false

  var theStr = new String(email)

  var index = theStr.indexOf("@");

  if (index > 0)

  {

    var pindex = theStr.indexOf(".",index);

    if ((pindex > index+1) && (theStr.length > pindex+1))

result = true;

  }

  if (theStr.indexOf(" ") > 0 )  return false;  

  if (theStr.indexOf("@", index + 1) > 0 ) return false;

  return result;

}

function isInteger(s)

{   var i;

    for (i = 0; i < s.length; i++)

    {   

        // Check that current character is number.

        var c = s.charAt(i);

        if (((c < "0") || (c > "9"))) return false;

    }

    // All characters are numbers.

    return true;

}

function stripCharsInBag(s, bag)

{   var i;

    var returnString = "";

    // Search through string's characters one by one.

    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)

    {   

        // Check that current character isn't whitespace.

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}

function ValidPhone(strPhone, minDigitsInIPhoneNumber)

{

var phoneNumberDelimiters = "()- ";

var validWorldPhoneChars = phoneNumberDelimiters + "+";

s=stripCharsInBag(strPhone, validWorldPhoneChars);

return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);

}

function ValidPhoneStripped(strPhone, minDigitsInIPhoneNumber)

{

var phoneNumberDelimiters = "()- ";

var validWorldPhoneChars = phoneNumberDelimiters + "+";

s=stripCharsInBag(strPhone, validWorldPhoneChars);

if ((isInteger(s) && s.length >= minDigitsInIPhoneNumber))

return stripCharsInBag(strPhone, phoneNumberDelimiters);

else

return false;

}

function ValidText(strText, intMin)

{

if (strText == "" || strText.length < intMin)

return false;

else

return true;

}

function TextStartNumber(strText)

{   

// Check if first character is a number

if ((strText.charAt(0) < "0") || (strText.charAt(0) > "9"))

{

return false;

}

else

{

return true;

}

}

function ValidChecked(objField) {

// This can be used for both checkboxes and radio buttons

if(objField.length) {

for (var i=0 ; i<objField.length ; i++) {

if (objField[i].checked)

return true;

}

} else {

//only one item

if(objField.checked)

return true;

}

}

function IsValidDate(intDay, strMonth, intYear) {

var blnLeapYear = false;

var blnRet = false;

if ((intDay>0) && (intDay<32) && (intYear>1900)) {

switch (strMonth.toLowerCase()) {

case "4":

case "6":

case "9":

case "11":

case "apr":

case "jun":

case "sep":

case "nov":

if (intDay < 31) blnRet = true;

break;

case "2":

case "feb":

if (intYear % 100 == 0) {

if (intYear % 400 == 0)

blnLeapYear = true;

}

else {

if (intYear % 4 == 0)

blnLeapYear = true;

}

if (blnLeapYear) {

if (intDay < 30)

blnRet = true;

}

else {

if (intDay < 29)

blnRet = true;

}

break;

default:

blnRet = true;

}

}

return blnRet

}

function ValidateForm(obj){

var strAlert = "";

strAlert = "______________________________________\n\nPlease\n\n";

var isAlert = false;

// trim the values of white space

var strTitle = obj.title.options[obj.title.selectedIndex].value;

var strFirstName = strTrim(obj.firstName.value);

var strLastName = strTrim(obj.lastName.value);

var strMethod = obj.contactMethod.options[obj.contactMethod.selectedIndex].value

var strEmail = strTrim(obj.email.value);

var strHomePhone = strTrim(obj.homePhone.value);

var strMobilePhone = strTrim(obj.mobilePhone.value);

var strWorkPhone = strTrim(obj.workPhone.value);

var strFeedback = strTrim(obj.feedback.value);

if (!ValidText(strTitle,1)){

strAlert += "- Select your title\n";

isAlert = true;

}

if (!ValidText(strFirstName,1)){

strAlert += "- Enter your first name\n";

isAlert = true;

}

else if (isInteger(strFirstName))

{

strAlert += "- Your first name must contain alphabetic characters.\n";

isAlert = true;

}

if (!ValidText(strLastName,1)){

strAlert += "- Enter your last name\n";

isAlert = true;

}

else if (isInteger(strLastName))

{

strAlert += "- Your last name must contain alphabetic characters.\n";

isAlert = true;

}

if (!ValidText(strMethod,1)){

strAlert += "- Select your preferred method of contact\n";

isAlert = true;

}

 

switch (strMethod) {

case "home_phone": 

if ( strHomePhone == "" ){

strAlert += "- Enter a home phone number\n";

isAlert = true;

}

break;

case "mobile_phone": 

if ( strMobilePhone == "" ){

strAlert += "- Enter a mobile number\n";

isAlert = true;

}

break;

case "work_phone": 

if ( strWorkPhone == "" ){

strAlert += "- Enter a work phone number\n";

isAlert = true;

}

break;

case "email":

if(strEmail == "") {

strAlert += "- Enter an email address\n";

isAlert = true;

}

}

if (strEmail != ""){

if (!ValidEmail(strEmail)){

strAlert += "- Enter a valid email address\n";

isAlert = true;

}

}

if (strHomePhone != ""){

var strStrippedPhone = ValidPhoneStripped(strHomePhone, 10);

if (!strStrippedPhone){

strAlert += "- Enter a 10 digit phone number (including area code)\n";

isAlert = true;

} else obj.homePhone.value = strStrippedPhone;

}

if (strMobilePhone != ""){

var strStrippedPhone = ValidPhoneStripped(strMobilePhone, 10);

if (!strStrippedPhone){

strAlert += "- Enter a 10 digit mobile phone number\n";

isAlert = true;

} else obj.mobilePhone.value = strStrippedPhone;

}

if (strWorkPhone != ""){

var strStrippedPhone = ValidPhoneStripped(strWorkPhone, 10);

if (!strStrippedPhone){

strAlert += "- Enter a 10 digit work phone number\n";

isAlert = true;

} else obj.workPhone.value = strStrippedPhone;

}

if (strFeedback == ""){

strAlert +="- Enter your feedback\n";

isAlert = true;

}else{

var s = strFeedback;

s = s.toString();    // Ensure that we are processing a string .

var i = 0;

var sLength = s.length;

if ((sLength > "5000")) {

toolong = ((sLength - "5000" ));

strAlert +="- This form only accepts feedback up to a length of 5000 characters.\nYour feedback is currently " + sLength + " characters long.\nPlease remove " + toolong + " characters and try again.";

isAlert = true;

}

}

if (isAlert == true){

strAlert += "\n\n______________________________________";

alert (strAlert);

return false;

}else{

return true;

}

}

function setRowColor(id, strColour){

// -- get element (the table), TBODY tag, children of (TR tags)

var r=document.getElementById(id).getElementsByTagName('tr');

 // - total number of TR tags

var l=r.length

for (i=0;i<l;i++){

if (i%2 != 0){r[i].style.backgroundColor=strColour;}

else {}

}

}

