/*
 * Functions showing and hiding elements on the site
 * changeContent( divID, shtml )
 * showDiv( divName, linkName, textDiv )
 * showHeight( )
 * showNews( divName, linkName )
 * revealHide( divName )
 * reveal( divName )
 * hide( divName )
 * newAward( this, i )
 * showSubmission( intSubmissionID, intTableTypeID, intArticleID )
 * showPlayersDetails ( divName, divBackground )
 * clubHoverOn( divName )
 * clubHoverOff( divName )
 * venueSelect( intVenueID )
 * cancelVenue( fgType )
 * editSignUp( intSignUpID )
 * myTimeout( divName, intTime )
 * revealNext( frm, intCond )
 */

function changeContent( divID, shtml ) {
        if (parent.document.getElementById || parent.document.all) {
                var el = parent.document.getElementById? parent.document.getElementById(divID): parent.document.all[divID];
        }
        if (el && typeof el.innerHTML != "undefined") el.innerHTML = shtml;
}

function showDiv( divName, linkName, textDiv ) {
  if( document.getElementById ) { // this is the way the standards work
    elem = document.getElementById( divName );
    textLayer = document.getElementById( textDiv );
  } else if( document.all ) { // this is the way old msie versions work
      elem = document.all[divName];
      textLayer = document.all[textDiv];
  } else if( document.layers ) { // this is the way nn4 works
    elem = document.layers[divName];
    textLayer = document.layers[textDiv];
  }

  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

  vis2 = textLayer.style;
  // if the style.display value is blank we try to figure it out here
  if(vis2.display==''&&textLayer.offsetWidth!=undefined&&textLayer.offsetHeight!=undefined)
    vis2.display = (textLayer.offsetWidth!=0&&textLayer.offsetHeight!=0)?'block':'none';

  if( vis.display==''||vis.display=='block') {
    vis.display = 'none';
    vis2.display = 'none';
    strLink = '-- more --'
    changeContent( linkName, strLink );
  } else {
    vis.display = 'block';
    vis2.display = 'block';
    textHeight = textLayer.offsetHeight;
    elem.style.height = textHeight+'px';

    NLBfadeBg( divName, '#99ff66', '#ffffff', '3000' );
    strLink = '-- less --'
    changeContent( linkName, strLink );
  }
}

function showHeight( form ) {
    switch( form.SelHeight.selectedIndex ) {
        case 0: document.getElementById('HeightFeet').style.display = "inline";
                document.getElementById('HeightCms').style.display = "none";
                break;
        case 1: document.getElementById('HeightFeet').style.display = "none";
                document.getElementById('HeightCms').style.display = "inline";
                break;
    }
}

function showNews( divName, linkName ) {
  if( document.getElementById ) { // this is the way the standards work
    elem = document.getElementById( divName );
  } else if( document.all ) { // this is the way old msie versions work
      elem = document.all[divName];
  } else if( document.layers ) { // this is the way nn4 works
    elem = document.layers[divName];
  }

  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

  if( vis.display==''||vis.display=='block') {
    vis.display = 'none';
    strLink = '-- more --'
    changeContent( linkName, strLink );
  } else {
    vis.display = 'block';
    strLink = ''
    changeContent( linkName, strLink );
  }
}

function revealHide( divName ) {
  if( document.getElementById ) { // this is the way the standards work
    elem = document.getElementById( divName );
  } else if( document.all ) { // this is the way old msie versions work
      elem = document.all[divName];
  } else if( document.layers ) { // this is the way nn4 works
    elem = document.layers[divName];
  }

  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

  if( vis.display==''||vis.display=='block') {
    vis.display = "none";
  } else {
    vis.display = 'block';
  }
}

function reveal( divName ) {
  if( document.getElementById ) { // this is the way the standards work
    elem = document.getElementById( divName );
  } else if( document.all ) { // this is the way old msie versions work
      elem = document.all[divName];
  } else if( document.layers ) { // this is the way nn4 works
    elem = document.layers[divName];
  }

  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

  vis.display = 'block';
}

function hide( divName ) {
  if( document.getElementById ) { // this is the way the standards work
    elem = document.getElementById( divName );
  } else if( document.all ) { // this is the way old msie versions work
      elem = document.all[divName];
  } else if( document.layers ) { // this is the way nn4 works
    elem = document.layers[divName];
  }

  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';

  vis.display = "none";
}

function newAward( award, i ) {
    if( award.options[award.selectedIndex].value == -1 ) {
        reveal( 'NewAward'+i );
    } else {
        hide( 'NewAward'+i );
    }
}

function selectDomInt( form ) {
    switch( form.DomInt.selectedIndex ) {
        case 1: reveal( "OnLineSignUp" );
                hide( "TournamentCountry" );
                form.Country.value = "";
                break;
        case 2: reveal( "TournamentCountry" );
                hide( "OnLineSignUp" );
                form.SignUp[0].checked = true;
                form.SignUpGender.options[0].selected = true;
                break;
        default: hide( "TournamentCountry" );
                hide( "OnLineSignUp" );
                break;
    }
}

function showSubmission( intSubmissionID, intTableTypeID, intArticleID ) {
    strDiv = "SubmissionListing"+intSubmissionID;
    strDiv2 = "SubmissionListingResult"+intSubmissionID;
    url = "../Submissions/submissionListing.php?ArticleID="+intArticleID+"&TypeID="+intTableTypeID+"&Approve=1&SubmissionID="+intSubmissionID;

    req.open('GET', url);
    req.onreadystatechange = function() { singleResponse(req, strDiv) };
    req.send(null);

    revealHide( strDiv );
    hide( strDiv2 );
}

function showPlayersDetails ( divName, divBackground, divParent, divExpand ) {
  if( document.getElementById ) { // this is the way the standards work
    thediv = document.getElementById( divName );
    backgroundDiv = document.getElementById( divBackground );
    parentDiv = document.getElementById( divParent );
  } else if( document.all ) { // this is the way old msie versions work
      thediv = document.all[divName];
      backgroundDiv = document.all[divBackground];
      parentDiv = document.all[divParent];
  } else if( document.layers ) { // this is the way nn4 works
    thediv = document.layers[divName];
    backgroundDiv = document.layers[divBackground];
    parentDiv = document.layers[divParent];
  }

    if(thediv.className == 'hiddenPlayers'){
        changeContent( divExpand, 'Hide' );
        thediv.className = 'displayPlayers';
        backgroundDiv.className = '';
        reveal( divName );
        reveal( divBackground );
        backgroundHeight = thediv.offsetHeight;
        backgroundDiv.style.height = backgroundHeight+'px';
        NLBfadeBg( divBackground, '#99ff66', '#ffffff', '3000' );
        parentDiv.onmouseover = function() { };
        parentDiv.onmouseout = function() { };
    } else{
        changeContent( divExpand, 'Expand' );
        thediv.className = 'hiddenPlayers';
        backgroundDiv.className = 'hide';
        hide( divName );
        hide( divBackground );
        parentDiv.onmouseover = function() { reveal( divName ) };
        parentDiv.onmouseout = function() { hide( divName ) };
    }
}

function clubHoverOn( divName ) {
  if( document.getElementById ) { // this is the way the standards work
    thediv = document.getElementById( divName );
  } else if( document.all ) { // this is the way old msie versions work
      thediv = document.all[divName];
  } else if( document.layers ) { // this is the way nn4 works
    thediv = document.layers[divName];
  }

    thediv.className = "pointer column2of4 clubHover PlayersBackground";
}

function clubHoverOff( divName ) {
  if( document.getElementById ) { // this is the way the standards work
    thediv = document.getElementById( divName );
  } else if( document.all ) { // this is the way old msie versions work
      thediv = document.all[divName];
  } else if( document.layers ) { // this is the way nn4 works
    thediv = document.layers[divName];
  }

    thediv.className = "pointer clubSelect column2of4";
}

function venueSelect( intVenueID ) {
    if( intVenueID == -1 ) {
        reveal( "NewVenue" );
    } else {
        hide( "NewVenue" );
    }
}

function cancelVenue( fgType ) {
    if( fgType == 0 ) {
        hide( "NewVenue" );
    } else {
        hide( "VenueEdit" );
    }
}

function editSignUp( intSignUpID ) {
    divSave = "signUpSave"+intSignUpID;
    divEdit = "signUpEdit"+intSignUpID;
    divNotes = "Notes"+intSignUpID;
    divNotesEdit = "NotesEdit"+intSignUpID;

    hide( divEdit );
    hide( divNotes );
    reveal( divSave );
    reveal( divNotesEdit );
}

function myTimeout( divName, intTime ) {
    var t=setTimeout("hide('"+divName+"')",intTime);
}

function revealNext( fldName, intCond, fgType ) {
    var elmTarget = ""
    var i=0
    while( i<fldName.form.elements.length && elmTarget == "" ) {
        if( fldName.form.elements[i].name == fldName.name ) {
            elmTarget = fldName.form.elements[i+1].id
        }
        i++
    }
    if( fldName.value != intCond ) {
        reveal( elmTarget )
    } else {
        hide( elmTarget )
    }
}