var repos_caption_count = 0;

function InitTaShare()
{
    if ($('#ta_share').val() == 'What\'s on your mind?')
    {
        $('#ta_share').val('');
    }
}

function ReInitTaShare()
{
    if ($('#ta_share').val() == '')
    {
        $('#ta_share').val('What\'s on your mind?');
    }
}

function ToggleRemoveLink(sw, id)
{
    $('.wpremovebtn').each(function() {
        $('#wpremovebtn'+id).hide();
    });
    
    if (sw==1)
    {
        $('#wpremovebtn'+id).show();
    }
    else
    {
        $('#wpremovebtn'+id).hide();
    }
}

function profileShare(toUID, fromUID)
{
    var strShare = $('#ta_share').val();
    strShare = trim(strShare);
    
    if (strShare.length <= 1 || strShare == 'What\'s on your mind?')
    {
        return;
    }
    $('#ta_share').val('');
    
    var currentTime = new Date();
    
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=profile_share&comment="+escape(strShare)+"&toUID="+toUID+"&fromUID="+fromUID+"&offset="+ (currentTime.getTimezoneOffset()/60),
        success: function(data) 
        {
            UpdateWall(toUID);
        }
    });     
}

function ActivateTab(category)
{
	$('#asmsi_tab').removeClass('a_tab_active');
	$('#cavite_tab').removeClass('a_tab_active');
	$('#cebu_tab').removeClass('a_tab_active');
	$('#international_tab').removeClass('a_tab_active');
	
	$('#asmsi_tab').addClass('a_tab');
	$('#cavite_tab').addClass('a_tab');
	$('#cebu_tab').addClass('a_tab');
	$('#international_tab').addClass('a_tab');
	
	if (category == 0)
	{
		$('#asmsi_tab').removeClass('a_tab');
		$('#asmsi_tab').addClass('a_tab_active');
	}
	else if (category == 1)
	{
		$('#cavite_tab').removeClass('a_tab');
		$('#cavite_tab').addClass('a_tab_active');
	}
	else if (category == 2)
	{
		$('#cebu_tab').removeClass('a_tab');
		$('#cebu_tab').addClass('a_tab_active');
	}
	else if (category == 3)
	{
		$('#international_tab').removeClass('a_tab');
		$('#international_tab').addClass('a_tab_active');
	}
	
	$('#a_container').html('<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loading... please wait.<br /><br /><br /><br />');
	
	// get announcements
	$.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=get_announcements&category="+category,
        success: function(data) 
        {
            $('#a_container').html(data);
        }
    }); 
}

function UpdateWall(toUID)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=update_wall&toUID="+toUID,
        success: function(data) 
        {
            var wallHtml = $('#wall').html();
            var newWallHtml = data + wallHtml;
            $('#wall').html(newWallHtml);
        }
    }); 
}

function ShowPage(page)
{
    alert('See this page soon!');
    return false;
}

function commentForComment(boxId, commentId, toUID, fromUID)
{
    var strComment = $('#'+boxId).val();
    strComment = trim(strComment);
    
    if (strComment.length <= 1)
    {
        return;
    }
    $('#'+boxId).val('');
    
    var currentTime = new Date();
    
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=comment_for_comment&comment="+escape(strComment)+"&post_id="+commentId+"&toUID="+toUID+"&fromUID="+fromUID+"&offset="+ (currentTime.getTimezoneOffset()/60),
        success: function(data) 
        {
            UpdatePostComments(commentId);
        }
    });     
}

function UpdatePostComments(commentId)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=update_post_comments&post_id="+commentId,
        success: function(data) 
        {
            var wallHtml = $('#wallpost'+commentId).html();
            var newWallHtml = wallHtml + data;
            $('#wallpost'+commentId).html(newWallHtml);
        }
    }); 
}

function LikePost(likeBox, id)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=like_post&id="+id,
        success: function(data) 
        {
            UpdateLikes(likeBox, id);
        }
    }); 
    
    return false;
}

function UnLikePost(likeBox, id)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=unlike_post&id="+id,
        success: function(data) 
        {
            UpdateLikes(likeBox, id);
        }
    }); 
    
    return false;
}

function UpdateLikes(likeBox, id)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=update_likes&id="+id,
        success: function(data) 
        {
            var html_arr = data.split("|||SEP|||");
            $('#'+likeBox).html(html_arr[0]);
            
            if (trim(html_arr[1]) != "")
            {
                $('#postlikes'+id).show();
                $('#postlikes'+id).html(html_arr[1]);
            }
            else
            {
                $('#postlikes'+id).html("");
                $('#postlikes'+id).hide();
            }
        }
    });
}

function popupRestOfLikes(id)
{
    alert('See this page soon!');
    return false;
}

function SharePost(id)
{
    return false;
}

function RemoveWallPost(id)
{
    if (confirm("This post will be removed permanently. Continue?"))
    {
        $.ajax({
            type: "POST",
            url: 'actions.php',
            data: "action=admin_remove_post&id="+id,
            success: function(data) 
            {
                $('#wp'+id).remove();
            }
        }); 
    }
    
    return false;
}

function HideHtmlElem(elemId)
{
	$('#'+elemId).hide();
}

function ShowHtmlElem(elemId)
{
	$('#'+elemId).show();
}

function hideShowReferrals()
{
    if (document.getElementById('signups_list').style.display == 'none')
    {
        ShowHtmlElem('signups_list');
    }
    else
    {
        HideHtmlElem('signups_list');
    }
}

function popupLoginResolutions(elemId)
{
    ShowHtmlElem(elemId);
    var nTop = GetTop('frm_asmsi_login');
    var nLeft = GetLeft('frm_asmsi_login');
    var o = document.getElementById(elemId);
    o.style.top = nTop + 'px';
    o.style.left = (nLeft-600) + 'px';
}

function regenerateCalendar(dir, m, y)
{
    HideHtmlElem('event_info_box_parent');

    if (dir == 'PREV')
    {
        if (m==1)
        {
            m = 12;
            y = y - 1;
        }
        else
        {
            m = m-1;
        }

    }
    else
    {
        if (m == 12)
        {
            m = 1;
            y = y + 1;
        }
        else
        {
            m = m+1;
        }
    }

    var xmlHttpObj = getNewHttp();
   
    var url = "generate_calendar.php";
    var myDate = new Date();

    var params = "do=REGENERATE_CALENDAR&m=" + m + "&y=" + y + "&dummy_param="+myDate;

    xmlHttpObj.open("POST", url, true);
    
    //Send the proper header information along with the request
    xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpObj.setRequestHeader("Content-length", params.length);
    xmlHttpObj.setRequestHeader("Connection", "close");
    
    xmlHttpObj.onreadystatechange = function()
    {//Call a function when the state changes.
    
        if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
        {      
              var sArrResponse;
              var sHTTPresponse = trim(xmlHttpObj.responseText);
              var calContainer = document.getElementById('asmsi_calendar_box');
              calContainer.innerHTML = sHTTPresponse;
        }  
    }

    xmlHttpObj.send(params);
}

function AddComment(commentBoxId, displayBox, section, rID, uID)
{
    var strComment = $('#'+commentBoxId).val();
    var strFormKey = $('#form_key').val();
    
    if (strFormKey.toLowerCase() != 'poor')
    {
        alert('Sorry, your answer is not correct');
        return;
    }
    
    if (strComment.length > 5)
    {
        var currentTime = new Date();
        
        $.ajax({
            type: "POST",
            url: 'actions.php',
            data: "action=add_comment&comment="+escape(strComment)+"&rID="+rID+"&uID="+uID+"&section="+section+"&offset="+ (currentTime.getTimezoneOffset()/60),
            success: function(data) 
            {
                $('#'+commentBoxId).val("");
                RetrieveComments(displayBox, section, rID);
            }
        }); 
    }
    else
    {
        alert('Your comment is too short');
    }
}

function DeleteComment(cID, displayBox, section, rID)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=delete_comment&cID="+cID,
        success: function(data) 
        {
            RetrieveComments(displayBox, section, rID);
        }
    }); 
    
    return false;
}

function RetrieveComments(displayBox, section, rID)
{
    $.ajax({
        type: "POST",
        url: 'actions.php',
        data: "action=get_comments&rID="+rID+"&section="+section+"&displayBox="+displayBox,
        success: function(data) 
        {
            $('#'+displayBox).html(data);
        }
    }); 
}

function postProfileText()
{
    var sUpdate = document.getElementById('text_update').value;
    if (trim(sUpdate) != '' && trim(sUpdate) != 'What\'s on your mind?')
    {
        while ( sUpdate.indexOf('&') >= 0)
        {
            sUpdate = sUpdate.replace("&","_AMPERSAND_");
        }

        // clear it immediately to avoid double posting
        document.getElementById('text_update').value = '';

        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";
        var myDate = new Date();

        var nMonth = myDate.getMonth();
        nMonth = parseInt(nMonth)+1;

        var post_date = myDate.getFullYear();

        post_date = post_date + '-' + nMonth;
        post_date = post_date + '-' + myDate.getDate();
        post_date = post_date + ' ' + myDate.getHours();
        post_date = post_date + ':' + myDate.getMinutes();
        post_date = post_date + ':' + myDate.getSeconds();

        var params = "do=POST_UPDATE&post_date=" + post_date + "&text_update="+sUpdate;

        //alert(params);

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  moreUpdates();

                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);

                  var udbox = document.getElementById('last_update_date');
                  var utbox = document.getElementById('last_update_text');
                  var entryid = document.getElementById('entry_id');

                  if (sHTTPresponse != '')
                  {
                      var arr = sHTTPresponse.split("_|||_");

                      //alert(sHTTPresponse);

                      if (arr && arr.length == 3)
                      {
                          //alert(arr[0]);
                          if (utbox)
                          {
                              utbox.style.display='block';
                              utbox.innerHTML = trim(arr[0]) + '&nbsp;&nbsp;<span style="font-size:11px;">[<a href="javascript:clearText(\'\')" class="asmsi_profile_link">Delete</a>]</span>';
                          }

                          //alert(arr[1]);
                          if (udbox)
                          {
                              udbox.style.display='block';
                              udbox.innerHTML = trim(arr[1]);
                          }

                          //alert(arr[2]);
                          if (entryid)
                          {
                              entryid.value = trim(arr[2]);
                          }
                      }
                      else
                      {
                          alert(sHTTPresponse + ' ' + arr.length);
                      }
                  }

                  getPosts();
            }  
        }

        xmlHttpObj.send(params);
    }
}

var profile_map_zoom = 10;

function profileMapZoom(zoom_dir)
{
    var xmlHttpObj = getNewHttp();
       
    var url = "ajax_profile_map_zoom.php";
    var myDate = new Date();

    var nLAT = document.getElementById('LAT').value;
    var nLON = document.getElementById('LON').value;
    var nZoom = (zoom_dir == 'IN') ? profile_map_zoom += 1 : profile_map_zoom -= 1;

    var params = "dummy_param = " + myDate + "&lat=" + nLAT + "&lon=" + nLON + "&zoom=" + nZoom;

    xmlHttpObj.open("POST", url, true);
    
    //Send the proper header information along with the request
    xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpObj.setRequestHeader("Content-length", params.length);
    xmlHttpObj.setRequestHeader("Connection", "close");
    
    xmlHttpObj.onreadystatechange = function()
    {//Call a function when the state changes.
    
        if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
        {
          var sArrResponse;
          var sHTTPresponse = trim(xmlHttpObj.responseText);

          document.getElementById('profile_map_box').innerHTML = sHTTPresponse;
        }
    }

    xmlHttpObj.send(params);
}

function clearText(entryId)
{
    if (entryId=='')
    {
        entryId = document.getElementById('entry_id').value;
    }

    var answer = confirm("Delete this text?");

    if (trim(entryId) != '' && answer)
    {
        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";
        var myDate = new Date();

        var params = "do=REMOVE_LATEST_POST&dummy_param=" + myDate + "&entry_id="+entryId;

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  moreUpdates();

                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);
                  var udbox = document.getElementById('last_update_date');
                  var utbox = document.getElementById('last_update_text');
                  var entryid = document.getElementById('entry_id');

                  if (sHTTPresponse == "EMPTY")
                  {
                      if (udbox)
                      {
                          udbox.style.display='none';
                      }

                      if (utbox)
                      {
                          utbox.style.display='none';
                      }

                      if (entryid)
                      {
                          entryid.value = "";
                      }
                  }
                  else
                  {
                      var arr = sHTTPresponse.split("_|||_");

                      if (arr && arr.length == 3)
                      {
                          if (utbox)
                          {
                              utbox.style.display='block';
                              utbox.innerHTML = arr[0] + '&nbsp;&nbsp;<span style="font-size:11px;">[<a href="javascript:clearText(\'\')" class="asmsi_profile_link">Delete</a>]</span>';
                          }

                          if (udbox)
                          {
                              udbox.style.display='block'
                              udbox.innerHTML = arr[1];
                          }

                          if (entryid)
                          {
                              entryid.value = arr[2];
                          }
                      }
                      else
                      {
                          alert(sHTTPresponse + ' ' + arr.length);
                      }
                  }

                  getPosts();
            }  
        }

        xmlHttpObj.send(params);
    }
}

function getPosts()
{
    var xmlHttpObj = getNewHttp();
       
    var url = "ajax_profile_text_update.php";
    var myDate = new Date();

    var by_user_id = document.getElementById('old_updates_by_user_id').value;
    var params = "do=GET_POSTS&dummy_param=" + myDate + "&by_user_id="+by_user_id;

    //alert(params);

    xmlHttpObj.open("POST", url, true);

    //Send the proper header information along with the request
    xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpObj.setRequestHeader("Content-length", params.length);
    xmlHttpObj.setRequestHeader("Connection", "close");
        
    xmlHttpObj.onreadystatechange = function()
    {//Call a function when the state changes.
        
        if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
        {
              var sArrResponse;
              var sHTTPresponse = trim(xmlHttpObj.responseText);
              var oubox = document.getElementById('old_updates_box');
              var mubox = document.getElementById('more_updates_box');
              var mplbox = document.getElementById('more_posts_link');
              var wcbox = document.getElementById('write_comment_box');

              //alert(sHTTPresponse);

              if (sHTTPresponse == "")
              {
                  if (oubox)
                  {
                      oubox.innerHTML = "";
                  }

                  if (mubox)
                  {
                      mubox.style.display = 'none';
                  }

                  if (wcbox)
                  {
                      wcbox.style.display = 'block';
                  }

                  if (mplbox)
                  {
                      mplbox.innerHTML = '';
                  }
              }
              else
              {
                  if (oubox)
                  {
                      oubox.innerHTML = sHTTPresponse;
                  }

                  if (mubox)
                  {
                      mubox.style.display = 'block';
                  }

                  if (wcbox)
                  {
                      wcbox.style.display = 'none';
                  }

                  if (mplbox)
                  {
                      mplbox.innerHTML = '&nbsp;&nbsp;<a href="javascript:moreUpdates()" class="asmsi_profile_link" title="More Posts..." ><img src="images/more_posts_button.png" style="vertical-align:middle;border:0px;" alt="More Posts..." /></a>';
                  }
              }
        }
    }

    xmlHttpObj.send(params);
}

function getComments()
{
    var xmlHttpObj = getNewHttp();
       
    var url = "ajax_profile_text_update.php";
    var myDate = new Date();

    var by_user_id = document.getElementById('old_updates_by_user_id').value;
    var params = "do=GET_COMMENTS&dummy_param=" + myDate + "&by_user_id="+by_user_id;

    xmlHttpObj.open("POST", url, true);
        
    //Send the proper header information along with the request
    xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpObj.setRequestHeader("Content-length", params.length);
    xmlHttpObj.setRequestHeader("Connection", "close");
        
    xmlHttpObj.onreadystatechange = function()
    {//Call a function when the state changes.
        
        if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
        {
              var sArrResponse;
              var sHTTPresponse = trim(xmlHttpObj.responseText);

              var cbox = document.getElementById('profile_comments_box');
              if (cbox)
              {
                  cbox.innerHTML = sHTTPresponse;
              }
        }
    }

    xmlHttpObj.send(params);
}

var bClearComment = 0;

function clearText3(entryId)
{
    bClearComment = 1;
    clearText2(entryId);
}

function clearDefault(id, sDefault)
{
    var box = document.getElementById(id);
    if (box && trim(box.value) == trim(sDefault))
    {
        box.value = '';
    }
}

function resetDefault(id, sDefault)
{
    var box = document.getElementById(id);
    if (box && trim(box.value) == '')
    {
      box.value = sDefault;
    }
}

function clearText2(entryId)
{
    if (entryId=='')
    {
        entryId = document.getElementById('entry_id').value;
    }

    var answer = confirm("Delete this text?");

    if (trim(entryId) != '' && answer)
    {
        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";
        var myDate = new Date();

        var by_user_id = document.getElementById('old_updates_by_user_id').value;

        var params = "";
        if (bClearComment == 1)
        {
            params = "do=DELETE_COMMENT&dummy_param=" + myDate + "&clear_profile_comments=1&entry_id="+entryId+"&by_user_id="+by_user_id;
        }
        else
        {
            params = "do=DELETE_POST&dummy_param=" + myDate + "&clear_old_updates=1&entry_id="+entryId+"&by_user_id="+by_user_id;
        }

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  if (bClearComment==1)
                  {
                      getComments();
                  }
                  else
                  {
                      getPosts();
                  }
                  bClearComment = 0;
            }  
        }

        xmlHttpObj.send(params);
    }
}

var sdebug_user_id = "";

function postComment()
{
    var sComment = document.getElementById('text_comment').value;
    var sForUser = document.getElementById('for_user_id').value;
    if (trim(sComment) != '' && trim(sComment) != 'Write comment and press Entry key')
    {
        while ( sComment.indexOf('&') >= 0)
        {
            sComment = sComment.replace("&","_AMPERSAND_");
        }

        // clear right away to avoid double posting
        document.getElementById('text_comment').value = '';

        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";
        var myDate = new Date();

        var nMonth = myDate.getMonth();
        nMonth = parseInt(nMonth)+1;

        var post_date = myDate.getFullYear();

        post_date = post_date + '-' + nMonth;
        post_date = post_date + '-' + myDate.getDate();
        post_date = post_date + ' ' + myDate.getHours();
        post_date = post_date + ':' + myDate.getMinutes();
        post_date = post_date + ':' + myDate.getSeconds();

        var params = "do=POST_COMMENT&post_date=" + post_date + "&text_comment="+sComment+"&for_user_id="+sForUser;

        if (sForUser=="44415" || sForUser=="58945" )
        {
            sdebug_user_id = sForUser;
            //alert(params);
        }

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  if (sdebug_user_id == "44415" || sdebug_user_id=="58945" )
                  {
                      //alert(xmlHttpObj.responseText);
                  }
                  getComments();
            }  
        }

        xmlHttpObj.send(params);
    }
}

function writeComment()
{
  var wcbox = document.getElementById('write_comment_box');
  var mubox = document.getElementById('more_updates_box');

  if (wcbox && wcbox.style.display == 'none')
  {
      if (mubox)
      {
          mubox.style.display = 'none';
      }
      wcbox.style.display = 'block';
  }

  if (wcbox)
  {
      getComments();
  }
}

function moreUpdates()
{
  var mubox = document.getElementById('more_updates_box');
  var wcbox = document.getElementById('write_comment_box');

  if (mubox)
  {
      mubox.style.display = 'block';
      if (wcbox)
      {
          wcbox.style.display = 'none';
      }

      getPosts();
  }
}

function expandCommentsBox(boxId)
{
  ShowHtmlElem(boxId);
  var mcl = document.getElementById('show_all_comments_link');
  if (mcl)
  {
      mcl.innerHTML = '<a href="javascript:collapseCommentsBox(\'allcommentsbox\')" title="Hide" class="asmsi_profile_link"><img src="images/collapse_box.jpg" alt="Collapse" border="0" /></a>&nbsp;';
  }
}

function collapseCommentsBox(boxId)
{
  HideHtmlElem(boxId);
  var mcl = document.getElementById('show_all_comments_link');
  if (mcl)
  {
      mcl.innerHTML = '<a href="javascript:expandCommentsBox(\'allcommentsbox\')" title="Show All" class="asmsi_profile_link"><img src="images/expand_box.jpg" alt="Expand" border="0" /></a>&nbsp;';
  }
}

function constructCountryFlagAsMapMark(lat,lng,img)
{
  var country_map = new GIcon();
  country_map.image = img;
  country_map.iconSize = new GSize(30, 18); // width, height
  country_map.iconAnchor = new GPoint(30, 0); //x,y
  var point = new GLatLng(lat,lng);
  var marker = new GMarker(point, country_map);
  return marker;
}

var nCall = 0;

function SendReport(email_subject, report_text_container, reply_to_email_address)
{
    var email_address = document.getElementById(reply_to_email_address).value;
    var sCPNumber = document.getElementById('RESPONSE_MOBILE_NUMBER').value;

    if ( trim(email_address)=="" )
    {
        alert("Please provide Email Address where the response to this report will be sent");
    }
    else
    {
        var date_today = new Date();
        var sMo = parseInt(date_today.getMonth()) + 1;

        document.getElementById('report_response_box').style.display = "none";

        var sEmailSubject = email_subject + " - " + document.getElementById('FIRST_NAME').innerHTML + " " + document.getElementById('LAST_NAME').innerHTML;
        sEmailSubject = sEmailSubject + " " + sMo + "/" + date_today.getDate() + "/" + date_today.getFullYear();
        sEmailSubject = sEmailSubject + " " + date_today.getHours() + ":" + date_today.getMinutes();
            
        var sEmailBody = document.getElementById(report_text_container).innerHTML;

        if (trim(sCPNumber) != "")
        {
            sCPNumber = "Mobile Number <b>" + sCPNumber + "</b>";
        }
        else
        {
            sCPNumber = "Mobile Number <b>Not Provided</b>";
        }

        sEmailBody = sEmailBody + "<br /><br />" + sCPNumber;

        var sAdmin = document.getElementById('admin_link').innerHTML;
        sEmailBody = sEmailBody + "<br /><br />" + sAdmin;

        var sReplyTo = email_address;

        var xmlHttpObj = getNewHttp();

        var url = "asmsi_error_reporter.php";
        var params = "do=SEND_ERROR_REPORT";
        params = params + "&EMAIL_SUBJECT="+sEmailSubject+"&EMAIL_BODY="+sEmailBody+"&REPLY_TO="+sReplyTo;  

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                var ajaxResponse = xmlHttpObj.responseText;
                if (trim(ajaxResponse)=="1")
                {
                    alert("This report has been sent to the ASMSI Web Team. Expect a reply within 48 hours.");
                    window.location='index.php';
                }
                else
                {
                    alert("Sending this report has failed. Make sure your email address is valid. Please try Again.");
                    document.getElementById('report_response_box').style.display = "block";
                }
            }  
        }
        
        xmlHttpObj.send(params);
    }
}

function IsUsernameAvailable()
{
    var sUsername = document.getElementById('USERNAME').value;
    document.getElementById('username_msg').innerHTML = "";
    if (!sUsername.match(/^[a-zA-Z0-9._]+$/))
    {
        document.getElementById('username_msg').innerHTML = '<span style="color:#FF0000;">Can only contain a-z, A-Z, 0-9, .(<i>dot</i>) and _ (<i>underscore</i>)</span>';
        frm = document.forms['activate2_form'];
        frm.update_profile_button.disabled = true;
        document.getElementById('form_error_message').innerHTML = 'Form error exists.';
    }
    else if (trim(sUsername) != "")
    {
        var xmlHttpObj = getNewHttp();
   
        var url = "asmsi_process.php";
        
        var params = "do=check_username";
        params = params + "&username="+sUsername;
        
        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                var ajaxResponse = xmlHttpObj.responseText;
                document.getElementById('username_msg').innerHTML = ajaxResponse;

                var sResponse = trim(ajaxResponse);
                if (sResponse.indexOf("Username is NOT available")>=0)
                {
                    frm = document.forms['activate2_form'];
                    frm.update_profile_button.disabled = true;
                    document.getElementById('form_error_message').innerHTML = 'Form error exists.';
                }
                else
                {
                    frm = document.forms['activate2_form'];
                    frm.update_profile_button.disabled = false;
					EnableDisableContinueButton();
                    document.getElementById('form_error_message').innerHTML = '';
                }
            }  
        }
        
        xmlHttpObj.send(params);
    }
}

function getNewHttp()
{
  var xmlHttp;
  try
  {  // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {  // Internet Explorer
    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;
      }
    }
  }
  return xmlHttp;
}

function trim(s)
{
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}

function GetTop(elmId)
{
  var y = 0;

  var elm = document.getElementById(elmId);
  
  if (elm)
  {
      y = elm.offsetTop;

      elm = elm.offsetParent;

      while(elm != null)
      {
        y = parseInt(y) + parseInt(elm.offsetTop);
        elm = elm.offsetParent;
      }
  }

  return y;
}

function GetLeft(elmId)
{
  var x = 0;

  var elm = document.getElementById(elmId);

  if (elm)
  {
      x = elm.offsetLeft;

      elm = elm.offsetParent;

      while(elm != null)
      {

        x = parseInt(x) + parseInt(elm.offsetLeft);
        elm = elm.offsetParent;
      }
  }

  return x;
}

function HideCommonMsgContainer(nTime)
{
    setTimeout("HideHtmlElem('message_to_user_container')",nTime);
}

// strMessage - message to user
// htmlElemId - element to which the message container is to be positioned with
// bHideMsgAfter - no of seconds for the message to stay visible
function displayCustomMessageToUser(strMessage,htmlElemId,bHideMsgAfter)
{
    var commonMsgContainer = document.getElementById('message_to_user_container');
    if (commonMsgContainer)
    {
        // position commonMsgContainer into the top left of frm_asmsi_login
        var nTop = GetTop(htmlElemId);
        var nLeft = GetLeft(htmlElemId);
    
        commonMsgContainer.style.top = (nTop + 5) + 'px';
        commonMsgContainer.style.left = nLeft + 'px';
                
        // set the message
        commonMsgContainer.innerHTML = strMessage;
                
        // the box is hidden, show it
        commonMsgContainer.style.display = 'block';
                
        // need to hide this error message only if bHideMsgAfter is non-zero
        if (bHideMsgAfter > 0)
        {
            HideCommonMsgContainer(bHideMsgAfter);
        }    
    }    
}

function ClearText(containerId)
{
    setTimeout("DoClearText()",10000); // clear message after 10seconds
}

function DoClearText(containerId)
{
    document.getElementById('required_msg').innerHTML = "";
}

function popupUploadForm()
{
    var wWidth = $(window).width();
	var wHeight = $(window).height();
	var oWidth = $('#avatar_upload_form').width();
	var oHeight = $('#avatar_upload_form').height();
	$('#avatar_upload_form').css({'top':((wHeight/2)-(oHeight/2))+'px', 'left':((wWidth/2)-(oWidth/2))+'px','display':'block'});
	return false;
}

function popupRememberMeHelp()
{
    var popupFrm = document.getElementById('remember_me_info');
    var nTop = GetTop('sign_in_button');
    var nLeft = GetLeft('sign_in_button');

    popupFrm.style.position = 'absolute';
    popupFrm.style.top = (nTop+20) + 'px';
    popupFrm.style.left = (nLeft-70) + 'px';

    ShowHtmlElem('remember_me_info');
}

function popupUploadForm2()
{
    popupUploadForm();
}

function ShowSearchHelp()
{
    var oHlp = document.getElementById('search_help');
    if (oHlp.style.display=="none")
    {
        oHlp.style.display="block";
    }
    else
    {
        oHlp.style.display="none";
    }
}

// functions below take care of the default search keywords
var sDefKeyword = '';

function RemoveDefaultKeyword()
{
    var q = document.getElementById('search_q');
    if (trim(q.value) == sDefKeyword)
    {
        q.value = "";
    }
}

function ResetKeywordIfEmpty()
{
    var q = document.getElementById('search_q');
    if (trim(q.value) == "")
    {
        q.value = sDefKeyword;
    }
}

function setRandomSearchKeyword()
{
    var sKeywords=new Array();
    sKeywords[0] = "ASMSI";
    sKeywords[1] = "Msgr. Aloysius Schwartz";
    sKeywords[2] = "Sisters Of Mary";
    sKeywords[3] = "Virgin Of the Poor";
    sKeywords[4] = "Philippines";
    sKeywords[5] = "Korea";
    sKeywords[6] = "Brazil";
    sKeywords[7] = "Mexico";
    sKeywords[8] = "Guatemala";

    var idx = Math.ceil(9*Math.random())
    if (idx > 0)
    {
        idx = idx-1;
    }

    sDefKeyword = sKeywords[idx];
    ResetKeywordIfEmpty();
}

function positionSlideShowNote()
{
    var bg = document.getElementById('slideshow_note_bg');
    var o = document.getElementById('slideshow_note');
    var nTop = GetTop('slideshow_images_div');
    var nLeft = GetLeft('slideshow_images_div');

    bg.style.position = "absolute";
    o.style.position = "absolute";

    bg.style.top = nTop + 'px';
    o.style.left = nLeft + 'px';

    o.innerHTML = 'Mouse-over here to pause';
}

function RunThisQuery()
{
    var mys = document.getElementById('mysql').value;
    if (trim(mys)=="")
    {
        alert('Type your query');
    }
    else
    {
        window.location.href = 'admin_home.php?tag=admin_record_not_found&sql=3&mysql='+mys;
    }
}

function openGalleryPhoto(imgId, galId, galUid)
{
    var xmlHttpObj = getNewHttp();
   
    var url = "gallery_ajax_open_image.php";
    var myDate = new Date();

    var params = "do=GET_IMAGE&id=" + imgId + "&gid=" + galId + "&uid=" + galUid + "&dummy_param="+myDate;

    xmlHttpObj.open("POST", url, true);
    
    //Send the proper header information along with the request
    xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpObj.setRequestHeader("Content-length", params.length);
    xmlHttpObj.setRequestHeader("Connection", "close");
    
    xmlHttpObj.onreadystatechange = function()
    {//Call a function when the state changes.
    
        if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
        {      
              var sArrResponse;
              var sHTTPresponse = trim(xmlHttpObj.responseText);
              var imgContainer = document.getElementById('photo_viewer');
              imgContainer.innerHTML = sHTTPresponse;

              // this should reposition the image caption
              moveImageCaption();
        }  
    }
    
    xmlHttpObj.send(params);
}

function pullEvent(tdId, day, month, year)
{
    var xmlHttpObj = getNewHttp();
   
    var url = "ajax_get_calendar_event.php";
    var myDate = new Date();

    var params = "do=GET_EVENT&d=" + day + "&m=" + month + "&y=" + year + "&dummy_param="+myDate;

    xmlHttpObj.open("POST", url, true);
    
    //Send the proper header information along with the request
    xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttpObj.setRequestHeader("Content-length", params.length);
    xmlHttpObj.setRequestHeader("Connection", "close");
    
    xmlHttpObj.onreadystatechange = function()
    {//Call a function when the state changes.
    
        if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
        {      
              var sArrResponse;
              var sHTTPresponse = trim(xmlHttpObj.responseText);
              var evtContainer = document.getElementById('event_info_box');
              evtContainer.innerHTML = sHTTPresponse;

              // reposition event_info_box to the box of the date
              var nTop = GetTop(tdId);
              var nLeft = GetLeft(tdId);

              // move this div to the date selected
              var evtBoxContainer = document.getElementById('event_info_box_parent');
              if (evtBoxContainer)
              {
                  evtBoxContainer.style.position = '';
                  evtBoxContainer.style.top = '';
                  evtBoxContainer.style.left = '';
                  evtBoxContainer.style.display = '';

                  evtBoxContainer.style.top = (nTop + 20) + 'px';
                  evtBoxContainer.style.left = (nLeft + 70) + 'px';
                  evtBoxContainer.style.position = 'absolute';
                  evtBoxContainer.style.display = 'block';
              }
        }  
    }

    xmlHttpObj.send(params);
}

function moveImageCaption()
{
    var gih = document.getElementById('gal_img_height');
    if (gih)
    {
        var nTop = GetTop('gallery_big_image');
        // add the height of the image
        nTop = nTop + parseInt(gih.value);
        // deduct 30 from nTop to accommodate the height of image caption
        nTop = parseInt(nTop) - 30;

        var nLeft = GetLeft('gallery_big_image');

        //alert('ntop = ' + nTop + ', nleft = ' + nLeft)

        var oCaptionBg = document.getElementById('gallery_big_image_caption_bg');
        var oCaption = document.getElementById('gallery_big_image_caption');

        if (oCaption && oCaptionBg)
        {
            oCaptionBg.style.position = '';
            oCaptionBg.style.top = '';
            oCaptionBg.style.left = '';
            oCaptionBg.style.display = '';

            oCaptionBg.style.position = "absolute";
            oCaptionBg.style.top = nTop + 'px';
            oCaptionBg.style.left = nLeft + 'px';

            oCaption.style.position = '';
            oCaption.style.top = '';
            oCaption.style.left = '';
            oCaption.style.display = '';

            oCaption.style.position = "absolute";
            oCaption.style.top = nTop + 'px';
            oCaption.style.left = nLeft + 'px';

            // kludge, it's trying to put the image caption on the right position
            // while the image is loading...
            if (repos_caption_count < 10)
            {
                oCaptionBg.style.display = "none";
                oCaption.style.display = "none";
                repos_caption_count++;
                setTimeout("moveImageCaption()",300);
            }
            else
            {
                oCaptionBg.style.display = "block";
                oCaption.style.display = "block";
                repos_caption_count = 0;
            }
        }
    }
}

function hideGalleryMngr()
{
    var mngr = document.getElementById('gallery_mngr');
    if (mngr)
    {
        mngr.style.display='none';
        var s = document.getElementById('gallery_mngr_switch');
        if (s)
        {
            s.innerHTML = '<a href="#" onclick="showGalleryMngr();" class="asmsi_general_link_style2">Show Gallery Manager</a>';
        }
    }
}

function showGalleryMngr()
{
    var mngr = document.getElementById('gallery_mngr');
    if (mngr)
    {
        mngr.style.display='block';
        var s = document.getElementById('gallery_mngr_switch');
        if (s)
        {
            s.innerHTML = '<a href="#" onclick="hideGalleryMngr();" class="asmsi_general_link_style2">Hide Gallery Manager</a>';
        }
    }
}

function deleteGallery(url)
{
    answer = confirm("Do you really want to delete this gallery?")
    if (answer !=0)
    {
      window.location.href = url;
    }
}

window.onresize = function ()
{
    moveImageCaption();
    getWidthAndHeight();
    getScrollXY();
}

window.onscroll = function ()
{
    getWidthAndHeight();
    getScrollXY();
}

function commentOnPost(postId, cboxid)
{
    var obj = null;
    // hide all of other comment boxes
    for (i=0; i<15; i++)
    {
        obj = document.getElementById('comment_box_'+i);
        if (obj)
        {
            obj.style.display='none';
        }
    }

    obj = document.getElementById(cboxid)
    {
        obj.style.display = 'block';
        getCommentsForPost(postId);
    }
}

function submitCommentOnPost(postId, commentField)
{
    var sComment = document.getElementById('text_comment_'+commentField).value;
    var sForUser = document.getElementById('for_user_id').value;
    var sForPost = postId;

    if (trim(sComment) != '' && trim(sComment) != 'Write comment and press Entry key')
    {
        while ( sComment.indexOf('&') >= 0)
        {
            sComment = sComment.replace("&","_AMPERSAND_");
        }

        // clear right away to avoid double posting
        document.getElementById('text_comment_'+commentField).value="";

        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";
        var myDate = new Date();

        var nMonth = myDate.getMonth();
        nMonth = parseInt(nMonth)+1;

        var post_date = myDate.getFullYear();

        post_date = post_date + '-' + nMonth;
        post_date = post_date + '-' + myDate.getDate();
        post_date = post_date + ' ' + myDate.getHours();
        post_date = post_date + ':' + myDate.getMinutes();
        post_date = post_date + ':' + myDate.getSeconds();

        var params = "do=POST_COMMENT_FOR_POST&post_date=" + post_date + "&text_comment="+sComment+"&for_user_id="+sForUser+"&for_post_id="+sForPost+"&text_comment_index="+commentField;

        //alert(params);

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);
                  if (sHTTPresponse == "1") // success
                  {
                      getCommentsForPost(postId);
                  }
            }  
        }

        xmlHttpObj.send(params);
    }
}

function getCommentsForPost(postId)
{
    if (trim(postId) != '')
    {
        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";

        var params = "do=GET_COMMENT_FOR_POST&for_post_id="+postId;

        //alert(params);

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);
                  if (sHTTPresponse != "") // success
                  {
                      var pcbox = document.getElementById('post_comment_box_'+postId);
                      if (pcbox)
                      {
                          pcbox.style.display = 'block';
                          pcbox.innerHTML = '';
                          pcbox.innerHTML = sHTTPresponse;
                      }
                  }
            }  
        }

        xmlHttpObj.send(params);
    }
}

function clearText4(entryId, forPostId)
{
    var answer = confirm("Delete this comment?");

    if (trim(entryId) != '' && answer)
    {
        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_profile_text_update.php";
        var myDate = new Date();

        var params = "do=REMOVE_POST_COMMENT&dummy_param=" + myDate + "&entry_id="+entryId;

        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);

                  if (sHTTPresponse == "1")
                  {
                      getCommentsForPost(forPostId);
                  }
            }  
        }

        xmlHttpObj.send(params);
    }
}

function GetBlogSubCategories()
{
    var selObj = document.getElementById("CATEGORY");
    var CAT_ID = selObj.options[selObj.selectedIndex].value;

    if (trim(CAT_ID) != '')
    {
        var subcatdiv = document.getElementById('subcategories');
        if (subcatdiv)
        {
            subcatdiv.innerHTML = "Loading subcategories...";
        }

        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_asmsi_blog.php";
        var myDate = new Date();

        var params = "do=GET_SUB_CATEGORIES&dummy_param=" + myDate + "&CAT_ID="+CAT_ID;
        
        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);

                  var subcatdiv = document.getElementById('subcategories');
                  if (subcatdiv)
                  {
                      subcatdiv.innerHTML = sHTTPresponse;
                  }
            }  
        }

        xmlHttpObj.send(params);
    }
}

var BLOG_ENTRY_ID = "";

function postBlogComment(ENTRY_ID)
{
    var strComments = document.getElementById('comment').value;

    if (trim(ENTRY_ID) != '' && trim(strComments) != '')
    {
        BLOG_ENTRY_ID = ENTRY_ID; // preserve id of this topic for use in getting comments
        document.getElementById('comment').value = ''; // clear comment box
        
        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_asmsi_blog.php";
        var myDate = new Date();

        while ( strComments.indexOf('&') >= 0)
        {
            strComments = strComments.replace("&","_AMPERSAND_");
        }
        var params = "do=POST_BLOG_COMMENT&dummy_param=" + myDate + "&ENTRY_ID="+ENTRY_ID+"&COMMENT="+strComments;

        //alert(params);
        
        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);

                  if (sHTTPresponse != "ERROR")
                  {
                      GetBlogComments(BLOG_ENTRY_ID);
                  }
                  else
                  {
                      alert('Database error occurred');
                  }
            }  
        }

        xmlHttpObj.send(params);
    }
}

function GetBlogComments(ENTRY_ID)
{
    if (trim(ENTRY_ID) != '')
    {
        var xmlHttpObj = getNewHttp();
       
        var url = "ajax_asmsi_blog.php";
        var myDate = new Date();
        
        var params = "do=GET_BLOG_COMMENT&dummy_param=" + myDate + "&ENTRY_ID="+ENTRY_ID;
        
        //alert(params);
        
        xmlHttpObj.open("POST", url, true);
        
        //Send the proper header information along with the request
        xmlHttpObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttpObj.setRequestHeader("Content-length", params.length);
        xmlHttpObj.setRequestHeader("Connection", "close");
        
        xmlHttpObj.onreadystatechange = function()
        {//Call a function when the state changes.
        
            if(xmlHttpObj.readyState == 4 && xmlHttpObj.status == 200)
            {      
                  var sArrResponse;
                  var sHTTPresponse = trim(xmlHttpObj.responseText);

                  if (sHTTPresponse != "ERROR")
                  {
                      var cbox = document.getElementById('comments_box');
                      if (cbox)
                      {
                          cbox.innerHTML = sHTTPresponse;
                          //alert(sHTTPresponse);
                      }
                  }
                  else
                  {
                      alert('Database error occurred');
                  }
            }  
        }

        xmlHttpObj.send(params);
    }
}

// getting browser width and height
var winWidth;
var winHeight;
var scrOfX;
var scrOfY;

function getWidthAndHeight()
{
    if (self.innerHeight) // all except Explorer
    {
        winWidth = self.innerWidth;
        winHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
        // Explorer 6 Strict Mode
    {
        winWidth = document.documentElement.clientWidth;
        winHeight = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        winWidth = document.body.clientWidth;
        winHeight = document.body.clientHeight;
    }
}

function getScrollXY() 
{
  
  if( typeof( window.pageYOffset ) == 'number' ) 
  {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
  {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } 
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
  {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
}

function likeForumPost(id)
{
	$.ajax({
        type: "POST",
        url: '/actions.php',
        data: "action=like_forum_post&postId="+id,
        success: function(data) 
        {
			$('#post'+id+'likes').css({'display':'block'});
            $('#post'+id+'likes').html(data);
        }
    });
	
	return false;
}

function getLikes(id)
{
	$.ajax({
        type: "POST",
        url: '/actions.php',
        data: "action=get_forum_post_likes&postId="+id,
        success: function(data) 
        {
			if (trim(data) != "")
			{
				$('#post'+id+'likes').html(data);
			}
			else
			{
				$('#post'+id+'likes').css({'display':'none'});
			}
        }
    });
}

function EnableDisableContinueButton()
{
	var pwd1 = trim($('#PASSWORD1').val());
	var pwd2 = trim($('#PASSWORD2').val());
	var email = trim($('#EMAIL').val());
	
	var bPwdOk = true;
	
	if ((pwd1.length < 6) || (pwd1.length > 30) || (pwd1 != pwd2))
	{
		$('#update_profile_button').attr('disabled','disabled');
		bPwdOk = false;
	}
	else
	{
		$('#update_profile_button').removeAttr('disabled');
	}
	
	if (email.length == 0)
	{
		$('#update_profile_button').attr('disabled','disabled');
	}
	else
	{
		var url = "action=validate_email&email="+escape(email);
		
		$.ajax({
			type: "POST",
			url: '/actions.php',
			data: url,
			success: function(strReturn) 
			{
				var sData = trim(strReturn);
				if (sData == "1")
				{
					if (bPwdOk)
					{
						$('#update_profile_button').removeAttr('disabled');
					}
				}
				else
				{
					alert(sData);
					$('#update_profile_button').attr('disabled','disabled');
				}
			}
		});
	}
}

function EnableDisableResetPwdButton()
{
	var uname = trim($('#USERNAME').val());
	var email = trim($('#EMAIL').val());
	
	if ((uname.length == 0) || email.length == 0)
	{
		$('#send_reset_link_btn').attr('disabled','disabled');
	}
	else
	{
		$('#send_reset_link_btn').removeAttr('disabled');
	}
}

function SendResetPwdLink()
{
	var uname = trim($('#USERNAME').val());
	var email = trim($('#EMAIL').val());
	
	var url = "action=send_reset_pwd_link&email="+escape(email)+"&username="+escape(uname);
	
	$('#send_reset_link_btn').attr('disabled','disabled');
	
	$.ajax({
		type: "POST",
		url: '/actions.php',
		data: url,
		success: function(strReturn) 
		{
			var sData = trim(strReturn);
			if (sData == "1")
			{
				alert(uname+", the password reset link has been sent to " + email);
				//$('#send_reset_link_btn').removeAttr('disabled');
			}
			else
			{
				alert(sData);
				$('#send_reset_link_btn').removeAttr('disabled');
			}
		}
	});
}

function UpdateProfileInfo(fld)
{
	var bDoneUpdate = false;
	var strField = fld.toUpperCase();
	var strValue = "";
	
	// no update if field is empty
	if (trim($('#'+fld).val()) == "")
	{
		return;
	}
	
	if (strField == 'PASSWORD1' || strField == 'PASSWORD2')
	{
		strField = 'PASSWORD';
		var pwd1 = trim($('#password1').val());
		var pwd2 = trim($('#password2').val());
		
		if (pwd1 == "" && pwd2 == "")
		{
			return;
		}
		else if (pwd1.length < 6 || pwd1.length > 30 || pwd2.length < 6 || pwd2.length > 30)
		{
			alert('Password must be minimum of 6 and maximum of 30 characters');
			return;
		}
		else if (pwd1 != pwd2)
		{
			alert('Passwords do not match');
			return;
		}
		strValue = pwd1;
	}
	if (strField == 'STATUS_SINGLE' || strField == 'STATUS_MARRIED')
	{
		strField = 'STATUS';
		strValue = (strField == 'STATUS_SINGLE') ? 'Single' : 'Married';
	}
	if (strField == 'EMPLOYMENT_STATUS_STUDY' || 
	    strField == 'EMPLOYMENT_STATUS_WORK' ||
		strField == 'EMPLOYMENT_STATUS_BUSINESS' ||
		strField == 'EMPLOYMENT_STATUS_UNEMPLOYED')
	{
		strField = 'EMPLOYMENT_STATUS';
		if (strField == 'EMPLOYMENT_STATUS_STUDY')
			strValue = 'Studying';
	    if (strField == 'EMPLOYMENT_STATUS_WORK')
			strValue = 'Working';
		if (strField == 'EMPLOYMENT_STATUS_BUSINESS')
			strValue = 'Self-employed';
		if (strField == 'EMPLOYMENT_STATUS_UNEMPLOYED')
			strValue = 'Unemployed';
	}
	else if (strField == 'EMAIL')
	{
		bDoneUpdate = true;
		
		strValue = trim($('#'+fld).val());
		
		// no need to proceed if email did not change
		if ($('#email_prev').val() == strValue.toLowerCase())
		{
			return;
		}
		
		var url = "action=validate_email&email="+escape(strValue)+"&exclude_owner=1";
		
		$.ajax({
			type: "POST",
			url: '/actions.php',
			data: url,
			success: function(strReturn) 
			{
				var sData = trim(strReturn);
				if (sData == "1")
				{
					// email valid, proceed with update
					var url = "action=update_profile&field="+strField + "&value="+escape(strValue);
					
					$.ajax({
						type: "POST",
						url: '/actions.php',
						data: url,
						success: function(strReturn) 
						{
							var sData = trim(strReturn);
							if (sData != "1")
							{
								alert(sData);
							}
							else
							{
								var profile_url = '../profile_edit.php';
								window.location = 'http://asmsi.org.ph/discussion/ucp.php?mode=update_email&email='+escape(strValue)+'&user_id='+$('#forum_user_id').val()+'&redirect='+profile_url;
							}
						}
					});					
				}
				else
				{
					alert(sData);
				}
			}
		});		
	}
	else
	{
		strValue = trim($('#'+fld).val());
	}

	if (!bDoneUpdate)
	{
		var url = "action=update_profile&field="+strField + "&value="+escape(strValue);
		
		$.ajax({
			type: "POST",
			url: '/actions.php',
			data: url,
			success: function(strReturn) 
			{
				var sData = trim(strReturn);
				if (sData != "1")
				{
					alert(sData);
				}
				else
				{
					if (strField == 'PASSWORD')
					{
						// update forum password
						var profile_url = '../profile_edit.php';
						window.location = 'http://asmsi.org.ph/discussion/ucp.php?mode=update_password&pw='+escape(strValue)+'&user_id='+$('#forum_user_id').val()+'&redirect='+profile_url;
					}
				}
			}
		});
	}
}

