function spawnPopUp(url, w, h, nameW) {
    nameW = typeof(nameW) != 'undefined' ? nameW : "popup";
    t = 0;
    o = 0;
    x4 = screen.width/2 - (w/2);
    y4 = screen.height/2 - (h/2);
    if (!o) { o=1 }
    if (!t) { t=0 }
    var win = window.open(url, nameW, 'height='+h+', width='+w+', scrollbars=yes, resizable=0, menubar='+t+', toolbar=0, status=0, location=0, directories=0, left=' + x4 + ',top=' + y4 + '');
    win.opener = self;
    win.focus();
    return false;
}

function changeInnerHTML(elementId, content) {
  var elementobj = document.getElementById(elementId);
  if(elementobj) {
    elementobj.innerHTML = content;
  } else {
    return false;
  }  
  return true;
}

/*--EDIT PROFILE JAVASCRIPT--*/
//--FOR 'personal_status_text' input
function statusFocus() {
  //Find the element:
  var status_input = document.getElementById("personal_status_text");
  if(status_input.value == 'Enter text to describe your status') 
  {
   status_input.value = '';
  }
}

/*--FOR #personal_status_text input ---*/
function statusBlur() {
  //Find the element:
  var status_input = document.getElementById("personal_status_text");
  if(status_input.value == '') {
   status_input.value = 'Enter text to describe your status';
  }  
}

//Available status shown by icons:

//AVAILABLE status:
function swapAvail() {  
//Make sure the others do not appear 'selected':
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("suspendedLink").style.backgroundImage    = 'url(/media/suspended_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)'; 

  //Now set the one that matters!
  document.getElementById("availableLink").style.backgroundImage = 'url(/media/available_sm.jpg)';
 
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'available';
  // alert("Status Changed to 'Available'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Available - (Remember to submit the form to save this.)';
}

//DIY status:
function swapDIY() {  
  //Make sure the others do not appear 'selected':
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("suspendedLink").style.backgroundImage    = 'url(/media/suspended_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)';  
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  
  //Now set the one that matters!
  document.getElementById("DIYLink").style.backgroundImage = 'url(/media/doingDIY_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'diy';
  //alert("Status Changed to 'Doing DIY'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Doing DIY - (Remember to submit the form to save this.)';
}

//INJURED status:
function swapInjured() { 
  //Make sure the others do not appear 'selected':
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("suspendedLink").style.backgroundImage    = 'url(/media/suspended_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)';
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';

  //Now set the one that matters!
  document.getElementById("injuryLink").style.backgroundImage = 'url(/media/injured_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'injured';
  //alert("Status Changed to 'Injured'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Injured - (Remember to submit the form to save this.)';
}

//ON HOLIDAY status:
function swapHoliday() {
  //Make sure the others do not appear 'selected':
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("suspendedLink").style.backgroundImage    = 'url(/media/suspended_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)'; 

  //Now set the one that matters!
  document.getElementById("holidayLink").style.backgroundImage = 'url(/media/onHoliday_sm.jpg)';  

  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'on-holiday';
  //alert("Status Changed to 'On Holiday'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: On Holiday - (Remember to submit the form to save this.)';
}


//ON THE ALE status:
function swapAle() { 
  //Make sure the others do not appear 'selected':
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("suspendedLink").style.backgroundImage    = 'url(/media/suspended_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)';
  
  //Now set the one that matters! 
  document.getElementById("aleLink").style.backgroundImage = 'url(/media/onTheAle_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'on-the-ale';
  //alert("Status Changed to 'On the Ale'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: On the Ale - (Remember to submit the form to save this.)';
}

//SUSPENDED status:
function swapSuspended() { 
  //Make sure the others do not appear 'selected':
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)';
 
  //Now set the one that matters!  
  document.getElementById("suspendedLink").style.backgroundImage = 'url(/media/suspended_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'suspended';
  //alert("Status Changed to 'Suspended'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Suspended - (Remember to submit the form to save this.)';
}

//UNAVAILABLE status:
function swapUnavail() { 
  //Make sure the others do not appear 'selected':
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)';
  document.getElementById("suspendedLink").style.backgroundImage    = 'url(/media/suspended_sm_faded.jpg)';
  
  //Now set the one that matters!   
  document.getElementById("unavailableLink").style.backgroundImage = 'url(/media/unavailable_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'unavailable';
  //alert("Status Changed to 'Unavailable'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Unavailable - (Remember to submit the form to save this.)';
}

//UNDER THE THUMB status:
function swapUnderThumb() { 
  //Make sure the others do not appear 'selected':
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("workingLink").style.backgroundImage      = 'url(/media/working_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  
  //Now set the one that matters!    
  document.getElementById("underThumbLink").style.backgroundImage = 'url(/media/underTheThumb_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'under-the-thumb';
  //alert("Status Changed to 'Under the Thumb'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Under the Thumb - (Remember to submit the form to save this.)';
}

//WORKING status:
function swapWorking() { 
  //Make sure the others do not appear 'selected':
  document.getElementById("holidayLink").style.backgroundImage      = 'url(/media/onHoliday_sm_faded.jpg)';
  document.getElementById("availableLink").style.backgroundImage    = 'url(/media/available_sm_faded.jpg)';
  document.getElementById("DIYLink").style.backgroundImage          = 'url(/media/doingDIY_sm_faded.jpg)';
  document.getElementById("injuryLink").style.backgroundImage       = 'url(/media/injured_sm_faded.jpg)';
  document.getElementById("aleLink").style.backgroundImage          = 'url(/media/onTheAle_sm_faded.jpg)';
  document.getElementById("unavailableLink").style.backgroundImage  = 'url(/media/unavailable_sm_faded.jpg)';
  document.getElementById("underThumbLink").style.backgroundImage   = 'url(/media/underTheThumb_sm_faded.jpg)';
    
  //Now set the one that matters!   
  document.getElementById("workingLink").style.backgroundImage = 'url(/media/working_sm.jpg)';
  
  //Now set the attribute for hidden field in order to submit this with the rest of the form:
  document.getElementById("personal_status").value = 'working';
  //alert("Status Changed to 'Working'- Remember to submit the form to save.");
  document.getElementById("status-alert-box").innerHTML = 'Status: Working - (Remember to submit the form to save this.)';
}

/*--help section for editing club pages---*/
function showHelp(a) {
  //Find the target element for help to go in:
  document.getElementById("help-text-box").style.visibility = 'visible';

  //Find relevant help text:
  //fixtures page:
  if(a == 'fixtures') {
    var helpContent = "Use this page to add a fixture, edit a fixture, or input the result. You can also select your team for an upcoming fixture and add a match report and related photos to a played fixture by clicking the links.";
  }

  //details page:
  if(a == 'details') {
    var helpContent = "Use this page to set your club's basic details.  These details-including the contact information- will be viewable by everyone who visits your site.";
  }

  //email page:
  if(a == 'email') {
    var helpContent = "Use this page to email club members.  Select the indivduals you want to email by clicking the checkbox next to their name, then type your message below.";
  }

  //teams page:
  if(a == 'teams') {
    var helpContent = "All the information here will be diaplayed on a team's page.  Use this admin to add or delete teams, name them correctly, set their league, captain and coach and give a desciption of the team.";
  }

  //members page:
  if(a == 'members') {
    var helpContent = "Use this page to viewall members of your club, set their role and set which team they currently play for.";
  }

  //media page:
  if(a == 'media') {
    var helpContent = "Add photos or videos stored on your computer by clicking browse.  To edit or delete a photo, its title and caption, click on the picture in question.";
  }

  //news page:
  if(a == 'news') {
    var helpContent = "Use this page to add news stories and edit existing ones.  You can add photos to a story and you can set which pages the stories appear on.  All new stories appear on the site's front page by default.";
  }
  
  //team selection page:
  if(a == 'teamSelection') {
    var helpContent = "Use this page to choose your starting XV and replacements for forthcoming games.  You can then email the selected players to inform them";
  }

  //join request page:
  if(a == 'join-requests') {
    var helpContent = "This page will display any incoming requests for approval as club members.";
  }

  //add image page:
  if(a == 'add-image') {
    var helpContent =
    "Browse to find the file you wish to add, then simply give the file a label and caption. You can choose to untick the checkbox iof you wish the file to remain hidden from the wider community.";
  }
  
  //edit image page:
  if(a == 'edit-image') {
    var helpContent = "Here you can amend what label and caption is displayed.  You can also make the file viewable by your club only.";
  }
  
  //add video page:
  if(a == 'add-video') {
    var helpContent = "Click browse to find your file, then fill in a label and caption.  Untick the checkbox if you wish the file to remain hidden from the wider community.";
  }
  
  //edit video page:
  if(a == 'edit-video') {
    var helpContent = "Here you can amend the file's details, such as what label and caption is displayed.  You can also choose to make the file viewable by your club only, by unticking the checkbox.";
  }
  
  //edit video page:
  if(a == 'submitted') {
    var helpContent = "You have successfully submitted, use the links below to navigate to your required page.";
  }
  
  //Now put the help text into the target area:
  document.getElementById("help-text-box").innerHTML = helpContent;

  //put extra space at bottom of page to prevent 'div overlap'
  var spacingBottom = '<br /><br /><br /><br />';
  
  if(document.getElementById("clearingBox")) {
    //Now put the help text into the target area:
    document.getElementById("clearingBox").innerHTML = spacingBottom;
    
    //Now make the box display:
    document.getElementById("clearingBox").style.display = 'block';
  }
}
//End of function

/*
 Function to show hidden div- when an admin user selects 'played' from edit fixture,
the div below appears, allowing them to add a match report and
associate media to the fixture before submitting.
*/

//Get the select itself:
var selectBox = document.getElementById('match-status');


//'x' references any div ID passed in by the calling function:

/*
function showHiddenDiv(x) {
document.getElementById('x').style.display="block";
}
*/

function showHiddenDiv() {
  /* //Get the select itself:
  var selectBox = document.getElementById('match-status');
  
  //Get the option that has been selected:
  var selectedOption = options[selectBox.selectedIndex].value;
  
  //If its the correct one, change the target div's style property:
  if (selectedOption == 'pl') {
    document.getElementById(post-match-report).style.display = "block";
 
  }
  */

  if (this.options[this.selectedIndex].value == 'pl') {
    //document.getElementById(post-match-report).style.display = "block";
    alert('changed');
  }
}

/*
onChange="javascript:document.forms['editfixture'].post-match-report.style = this.options[this.selectedIndex].value;"
onChange="javascript:if(document.forms['editfixture'].this.selectedIndex.value == 'pl'){document.post-match-report.style.display = 'block'};"
*/

function displayDiv() {
  if(document.getElementById('match-status').selectedIndex.value == 'pl') {
    document.getElementById('post-match-report').style.display = 'block';
  }
}

/*FUNCTION to display the hidden div on edit fixture page;
 To get around Firefox's shoddy reaction, extra style rules are also applied:
*/
function showAndClear() {
  getElementById('post-match-report').style.display='block';
  getElementById('footer').style.cssFloat='right';
  getElementById('fileUpload').style.marginBottom='20px';
  alert('hello');
}