//JavaScript for the Sport Circle

function test_me()
{
alert("Hello World!!!");
}

/*--JavaScript for Table Invite Screen--*/

function add_table_user_row() {

    var add_table_user = document.getElementById('add_table_user');

    if (add_table_user.value == '') {
        alert("You must choose a contact to add them to the list of invitees.");
    } else {
  
      // i is used to label id's for DOM manipulation, don't change the id's, classes are okay though

      i = get_next_table_user_row();

      container = document.getElementById('add-table-user-row-container');
      container.innerHTML += '<div class="table-user-row" id="table-user-row-' + i + '"><strong>' + add_table_user.options[add_table_user.selectedIndex].text + '</strong><input type="hidden" name="add-user[' + i + ']" value="' + add_table_user.options[add_table_user.selectedIndex].value + '" /><a class="smallDelete" href="#" onclick="delete_table_user_row(' + i + ')"><img class="submitbutton" src="/media/delete_small_button.jpg" alt="Delete" value="Delete" /></a></div></div>';


      document.getElementById('add_table_user').value = "";
    }
}

function delete_table_user_row(rownumber) {
    var rowname = 'table-user-row-' + rownumber;
    document.getElementById('add-table-user-row-container').removeChild(document.getElementById(rowname));
}

function get_next_table_user_row() {
    i = 0;
    while (document.getElementById('table-user-row-' + i)) {
        i++;
    }
    return i;
}


/*---SOLUTION TO BROWSE FOR FILE/UPLOAD PROBLEM DISPLAY--*/

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'browseHolder';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='media/browse_small_button.jpg';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file filebutton-fix';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}


/*
--SIMPLE WAY- route all 'clicks' through to the real file upload field, (even though it is hidden)--
fakeField.onclick = function () {
	realField.click()
}
*/

/*
function ChangeText()
{
document.getElementById("p1").innerHTML="New text!";
}
*/



/*---LOUNGES PAGE---*/

function showtopic(topic_id, lounge_id, hide) { 
  if (hide == 1) {
    window.location.reload(true);
  }

  var querystring = '?topic_id=' + topic_id + '&lounge_id=' + lounge_id;

  var iframe = document.getElementById("messagepopup");
  var blocker = document.getElementById("blocker");

  frames['messagepopup'].location.href = "/lounges/message_forum.html" + querystring;

  var status = "block";
  
  if (iframe == null || blocker == null) {
    return;
  } else {
    iframe.style.top = "0px";
    iframe.style.display = status;
    blocker.style.display = status; 
  }
}

function newtopic(lounge_id, hide) { 
  if (hide == 1) {
    window.location.reload(true);
  }

  var querystring = '?lounge_id=' + lounge_id;

  var iframe = document.getElementById("messagepopup");
  var blocker = document.getElementById("blocker");

  frames['messagepopup'].location.href = "/lounges/message_forum_new.html" + querystring;

  var status = "block";
  
  if (iframe == null || blocker == null) {
    return;
  } else {
    iframe.style.top = "0px";
    iframe.style.display = status;
    blocker.style.display = status; 
  }
}

/*--END OF LOUNGES FUNCTIONALITY---*/


/*--JavaScript for Events Calendar--*/

function createQCObject() { 
   var req; 
   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      alert('Problem creating the XMLHttpRequest object'); 
   } 
   return req; 
} 

// Make the XMLHttpRequest object 
var http = createQCObject(); 

function displayQCalendar(m,y) {
  var ran_no=(Math.round((Math.random()*9999))); 
  http.open('get', '/ajax/qcal.php?m='+m+'&y='+y+'&ran='+ran_no);
    http.onreadystatechange = function() {
      if(http.readyState == 4 && http.status == 200) { 
          var response = http.responseText;
          if(response) { 
            document.getElementById("quickCalender").innerHTML = http.responseText; 
          } 
      } 
    } 
    http.send(null); 
}

/*--JavaScript for AJAX for Sport Circle on profile page--*/

function getSportCircleProfileFriends(page_no, profile_id) { 
  var xmlHttp;
  try {
    xmlHttp = new XMLHttpRequest();
  } 
  catch (e) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4) {
      if(xmlHttp.status == 200) {
        var output = xmlHttp.responseText;
      } else {
        var output = "There was a problem with the request - error " + xmlHttp.status;
      }

      var scHolder = document.getElementById("sportcircleandpagingholder");
      scHolder.innerHTML = output;
    } 
  }

  xmlHttp.open("GET", '/ajax/sportcirclepaging.php?pg=' + page_no + '&pid=' + profile_id, true);
  xmlHttp.send(null);
  return false;
}


/*--JavaScript for AJAX for User Lounges--*/

function getUserLounges(page_no, profile_id) { 
  var xmlHttp;
  try {
    xmlHttp = new XMLHttpRequest();
  } 
  catch (e) {
    try {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e) {
      try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  
  xmlHttp.onreadystatechange=function() {
    if(xmlHttp.readyState==4) {
      if(xmlHttp.status == 200) {
        var output = xmlHttp.responseText;
      } else {
        var output = "There was a problem with the request - error " + xmlHttp.status;
      }

      var ulHolder = document.getElementById("userloungesandpagingholder");
      ulHolder.innerHTML = output;
    } 
  }

  xmlHttp.open("GET", '/ajax/userloungespaging.php?pgl=' + page_no + '&pid=' + profile_id, true);
  xmlHttp.send(null);
  return false;
}
