var repos_caption_count = 0;

function HideHtmlElem(elemId)
{
    var htmlElem = document.getElementById(elemId);
    if (htmlElem)
    {
        htmlElem.style.display = 'none';
    }
}

function ShowHtmlElem(elemId)
{
    var htmlElem = document.getElementById(elemId);
    if (htmlElem)
    {
        htmlElem.style.display = 'block';
    }
}

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 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;
                    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()
{
	getWidthAndHeight();
	getScrollXY();
	
	var bgO = document.getElementById('avatar_upload_bg_div');
    ShowHtmlElem('avatar_upload_bg_div');
	bgO.style.width = '100%';
	bgO.style.height = '100%';
	bgO.style.top = scrOfY + 'px';
	bgO.style.left = scrOfX + 'px';
	
	var uploadBoxO = document.getElementById('avatar_upload_form');
	ShowHtmlElem('avatar_upload_form');
	var nBoxHeight = uploadBoxO.style.height;
	if (!nBoxHeight)
	{
		nBoxHeight = 400;
	}
	
	uploadBoxO.style.top = (((winHeight/2)+scrOfY) - (nBoxHeight/2)) + 'px';
	uploadBoxO.style.left = (((winWidth/2)+scrOfX) - 150) + 'px';
}

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()
{
    //var popupFrm = document.getElementById('avatar_upload_form');
    //var nTop = GetTop('account_avatar_box');
    //var nLeft = GetLeft('account_avatar_box');

    //popupFrm.style.position = 'absolute';
    //popupFrm.style.top = (nTop+10) + 'px';
    //popupFrm.style.left = (nLeft+10) + 'px';

    //ShowHtmlElem('avatar_upload_form');
	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();
	var oUpload = document.getElementById('avatar_upload_bg_div');
	if (oUpload && oUpload.style.display == "block")
	{
		popupUploadForm();
	}
}

window.onscroll = function ()
{
	getWidthAndHeight();
	getScrollXY();
	var oUpload = document.getElementById('avatar_upload_bg_div');
	if (oUpload && oUpload.style.display == "block")
	{
		popupUploadForm();
	}
}

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;
  }
}