function CheckPostal() {
    // var country = $get("txtCountry").value;
    var sPost = '07940';
    MWorld.ListProvider.CheckZipCode(sPost, OnWSRequestComplete);
}

function OnWSRequestComplete(results) {
    // var searchResults = $get("searchResults"); 
    //searchResults.control.set_data(results);
    alert(results);
} 

var CheckZipInProgress = false;
var CheckZipCodeParams;
function CheckZipCode(sValue,sCountry,UpdateSpanId,ErrorSpanId) 
{    
    CheckZipCodeParams = Array(UpdateSpanId,ErrorSpanId);
    if (sCountry) 
    {
        if (sCountry != 'us') 
        {
            CheckZipCodeComplete('ok');
            return true;
        }
        
    }
    if (sValue == null || sValue == "") 
    { 
        CheckZipCodeComplete('ok');
        return true; 
    }
    
    CheckZipInProgress = true;    
    
    MWorld.ListProvider.CheckZipCode(sValue, CheckZipCodeComplete);    
}

function CheckZipCodeComplete(results) {
   var ErrorSpan = $get(CheckZipCodeParams[1]);
   var UpdateSpan = $get(CheckZipCodeParams[0]);
   if (results == 'none') {
        // no matching zipcode
        ErrorSpan.style.display = "inline";
        UpdateSpan.style.display = 'none';
   } else {
        ErrorSpan.style.display = "none";
   }
   
   CheckZipInProgress = false;
} 

function CheckUserNameConfirmReg(sZoneCode, sValue, UpdateSpanId, ErrorSpanId, sOriginalUserName) 
{
  if (sValue == null || sValue == "") 
      return true; 
  
  if (sValue == sOriginalUserName)
  {
      var UpdateSpan = $get(UpdateSpanId);
      var ErrorSpan = $get(ErrorSpanId);
      ErrorSpan.style.display = "none";
      UpdateSpan.style.display = "inline";   
      return true;
  }
      
  CheckUserName(sZoneCode, sValue, UpdateSpanId, ErrorSpanId);
}

var CheckUserNameInProgress = false;
var CheckUserNameParams;
function CheckUserName(sZoneCode, sValue,UpdateSpanId,ErrorSpanId) 
{
    if (sValue == null || sValue == "") { return true; }
    
    CheckUserNameParams = Array(UpdateSpanId,ErrorSpanId);
    
    CheckUserNameInProgress = true;
    MWorld.ListProvider.CheckUserName(sZoneCode, sValue, CheckUserNameComplete);    
}

function CheckUserNameComplete(results) 
{
   var UpdateSpan = $get(CheckUserNameParams[0]);
   var ErrorSpan = $get(CheckUserNameParams[1]);
   if (results == 'none') {
        /* no matching user name so there is no error*/
        ErrorSpan.style.display = "none";
        UpdateSpan.style.display = 'inline';
   } else {
        ErrorSpan.style.display = "inline";
        UpdateSpan.style.display = 'none';
   }
   
   CheckUserNameInProgress = false;
} 

var CheckEmailAddressParams;
function CheckEmailAddress(sZoneCode, sValue,UpdateSpanId,ErrorSpanId) 
{
    if (sValue == null || sValue == "") { return true; }
    CheckEmailAddressParams = Array(UpdateSpanId,ErrorSpanId);
    MWorld.ListProvider.CheckEmailAddress(sZoneCode, sValue, CheckEmailAddressComplete);
    
}

function CheckEmailAddress2(sZoneCode, sValue, UpdateSpanId, ErrorSpanId, sOriginalEmail) 
{    
    if (sValue == null || sValue == "")     
        return true;     
  
    if (sOriginalEmail != null && sValue == sOriginalEmail)
    {
        var UpdateSpan = $get(UpdateSpanId);
        var ErrorSpan = $get(ErrorSpanId);
        ErrorSpan.style.display = "none";
        UpdateSpan.style.display = 'inline';    
        return true;
    }
    
    CheckEmailAddressParams = Array(UpdateSpanId,ErrorSpanId);
    MWorld.ListProvider.CheckEmailAddress(sZoneCode, sValue, CheckEmailAddressComplete);    
}

function CheckEmailAddressComplete(results) 
{
   var UpdateSpan = $get(CheckEmailAddressParams[0]);
   var ErrorSpan = $get(CheckEmailAddressParams[1]);
   if (results == 'none') {
        /* no matching email */
        /* no matching user name so there is no error*/
        ErrorSpan.style.display = "none";
        UpdateSpan.style.display = 'inline';
   } else {
        ErrorSpan.style.display = "inline";
        UpdateSpan.style.display = 'none';
   }
} 

var CheckGroupNameParams;
function CheckGroupName(sValue,UpdateSpanId,ErrorSpanId) 
{
    if (sValue == null || sValue == "") { return true; }
    CheckGroupNameParams = Array(UpdateSpanId,ErrorSpanId);
    MWorld.ListProvider.CheckGroupName(sValue, CheckGroupNameComplete);
    
}

function CheckGroupNameComplete(results) 
{
   var UpdateSpan = $get(CheckGroupNameParams[0]);
   var ErrorSpan = $get(CheckGroupNameParams[1]);
   if (results == 'none') {
        /* no matching group name so there is no error*/
        ErrorSpan.style.display = "none";
        UpdateSpan.style.display = 'inline';
   } else {
        ErrorSpan.style.display = "inline";
        UpdateSpan.style.display = 'none';
   }
} 

var CheckGroupUrlParams;
function CheckGroupUrl(sValue,UpdateSpanId,ErrorSpanId) 
{
    if (sValue == null || sValue == "") { return true; }
    CheckGroupUrlParams = Array(UpdateSpanId,ErrorSpanId);
    MWorld.ListProvider.CheckGroupUrl(sValue, CheckGroupUrlComplete);
    
}

function CheckGroupUrlComplete(results) 
{
   var UpdateSpan = $get(CheckGroupUrlParams[0]);
   var ErrorSpan = $get(CheckGroupUrlParams[1]);
   if (results == 'none') {
        /* no matching email */
        /* no matching group url, so there is no error*/
        ErrorSpan.style.display = "none";
        UpdateSpan.style.display = 'inline';
   } else {
        ErrorSpan.style.display = "inline";
        UpdateSpan.style.display = 'none';
   }
} 

var NormalizeEmailListParams;
function NormalizeEmailList(sValue,UpdateSpanId,ErrorSpanId) 
{
    NormalizeEmailListParams = Array(UpdateSpanId,ErrorSpanId);
    MWorld.ListProvider.NormalizeEmail(sValue,NormalizeEmailListComplete);
}

function NormalizeEmailListComplete(results) {
   var ErrorSpan = $get(NormalizeEmailListParams[1]);
   var UpdateSpan = $get(NormalizeEmailListParams[0]);
   UpdateSpan.value = results;
   // Now span the check for vailid emails 
   CheckEmailList(results,UpdateSpan.id,ErrorSpan.id);
} 


var CheckEmailListParams;
function CheckEmailList(sValue,UpdateSpanId,ErrorSpanId) 
{
    CheckEmailListParams= Array(UpdateSpanId,ErrorSpanId);
    MWorld.ListProvider.CheckEmailList(sValue,CheckEmailListComplete);
}

function CheckEmailListComplete(results) {
   var ErrorSpan = $get(CheckEmailListParams[1]);
   var UpdateSpan = $get(CheckEmailListParams[0]);
   if (results == '') {
        ErrorSpan.style.display = "none";
   } else {
        ErrorSpan.style.display = "inline";
        ErrorSpan.innerHTML = "<br />" + results;
   }
} 

function ValidateCheckBox(control,UpdateSpanId,ErrorSpanId) 
{
    var UpdateSpan = $get(UpdateSpanId);
    var ErrorSpan = $get(ErrorSpanId);
    if (control != null) 
    {
        if (control.checked) 
        {
            ErrorSpan.style.display = "none";
            UpdateSpan.style.display = 'inline';
            return true;
        }
        else 
        {        
            ErrorSpan.style.display = "inline";
            UpdateSpan.style.display = 'none';
            return false;
        }
    }
    else 
    {
        return true;
    }
    
}

function ValidateAgeOver13(cDay,cMonth,cYear,UpdateSpanId,ErrorSpanId) 
{
    var UpdateSpan = $get(UpdateSpanId);
    var ErrorSpan = $get(ErrorSpanId);
    if (cYear != null && cMonth != null && cDay != null ) 
    {
        
        var uDate = new Date(cYear.value,cMonth.value-1,cDay.value);
        var now = new Date();
        var aYear = 1000*60*60*24*365.25;
        var YearDiff = (now.getTime() - uDate.getTime())/aYear;
        if (YearDiff > 13.0) 
        {
            ErrorSpan.style.display = "none";
            UpdateSpan.style.display = 'inline';
            return true;
        }
        else 
        {        
            ErrorSpan.style.display = "inline";
            UpdateSpan.style.display = 'none';
            return false;
        }
    }
    else 
    {
        return true;
    }
    
}

function ValidateEmailConfirm(cEmail,cConfirm,UpdateSpanId,ErrorSpanId) 
{
    var UpdateSpan = $get(UpdateSpanId);
    var ErrorSpan = $get(ErrorSpanId);
    if (cEmail != null && cConfirm != null) 
    {
        if (cEmail.value == cConfirm.value) 
        {
            ErrorSpan.style.display = "none";
            UpdateSpan.style.display = 'inline';
            return true;
        }
        else 
        {
            ErrorSpan.style.display = "inline";
            UpdateSpan.style.display = 'none';
            mjASPX.EmailAddress().focus();
            return false;
        }
    }
    else 
    {
        return true;
    }
}

function ValidateDOBOK(cDay,cMonth,cYear,UpdateSpanId,ErrorSpanId) 
{
    var UpdateSpan = $get(UpdateSpanId);
    var ErrorSpan = $get(ErrorSpanId);
    if (cYear != null && cMonth != null && cDay != null ) 
    {
        if (isDate(cYear.value.toString()+'/'+(cMonth.value)+'/'+cDay.value,'yyyy/M/d')) 
        {
            ErrorSpan.style.display = "none";
            UpdateSpan.style.display = 'inline';
            return true;
        } else 
        {
            ErrorSpan.style.display = "inline";
            UpdateSpan.style.display = 'none';
            return false;
        }
    }
    else 
    {
        return true;
    }
    
}




function FinalCheckEmailandGroupName()
{    
    if (mjASPX._EmailList().value=='')
    {
        alert ("You must enter at least one invitee!"); 
        return false;
    }

    if (document.getElementById("EmailListError").style.display == 'inline')      
    {       
        alert ("Please correct the email addresses!"); 
        return false;
    }     
    
    var gnelement = document.getElementById("GroupNameError");
    if((gnelement != null) && (gnelement.style.display == 'inline'))
    {
        alert("The group name you entered is already being used by another group, try a different name.");
        return false;
    }
    
}    

function CheckVerifyRegEmail()
    
        {      
            if( EmailError.style.display == 'inline')
                {
                    alert(EmailError.innerText);
                    return false;
                }            
        }      
   
function RegStep1_PostalCode_Email_Check()
{    
         
   if (document.getElementById("PostalCodeError").style.display == 'inline')      
    {       
        alert ("That ZIP Code doesn't look valid. Please try again.");             
        return false;
    }  

   if (document.getElementById("EmailError") != null)
	{
	   if (document.getElementById("EmailError").style.display == 'inline')      
		{       
			alert ("That email address is already registered, please change it!"); 
			return false;
		}   
		else
		{
			return ValidateEmail();    
		}
    }
         
}     

function ValidateEmail()
    {
      //Declare regular expression
      var re = new RegExp('^.+@[^\.].*\.[a-z]{2,}$');

      if (mjASPX.EmailAddress().value.match(re))
      {
        //allow postback to continue
        return true;
      }
      else
      {
        //inform user that the email address is not valid
        alert("You must enter a valid email address like name@internet.com!");
       
        //Set the focus on non-compliant field
        mjASPX.EmailAddress().focus();
       
        //Prevent the postback
        return false;
      }
    }

function ClearFields_InvitePage()
{    
    mjASPX._EmailList().value='';
    return false;
}     

function ClearFields_Step4()
{    
    mjASPX.BirthDateText().value='';
    mjASPX.HomeTown().value='';
    mjASPX.KidName_1().value='';
    mjASPX.KidBirthDateText_1().value='';
    mjASPX.KidName_2().value='';
    mjASPX.KidBirthDateText_2().value='';
    mjASPX.KidName_3().value='';
    mjASPX.KidBirthDateText_3().value='';
    mjASPX.KidName_4().value='';
    mjASPX.KidBirthDateText_4().value='';
    mjASPX.KidName_5().value='';
    mjASPX.KidBirthDateText_5().value='';
    mjASPX.Vacation().value='';
    mjASPX.KidActivity().value='';
    mjASPX.Hobby().value='';
    
    return false;
}     


function ShowLocal(bShow) {
    var _local,_localLabel, _localHelp;
    try {
        _local = mjASPX._localGroup();
        _localLabel = mjASPX._localGroupLabel();
        _localHelp = mjASPX._helpLocalGroup();
        }
        catch (a) 
        {
        }
    
    if (_local == null) {
        return;
    }
        
    if (bShow) {
        try {
            _local.style.visibility = 'visible';
            _localLabel.style.visibility = 'visible';
            _localLabel.style.visibility = 'visible';
            _localHelp.style.visibility = 'visible';
        } catch (a) {}
        document.getElementById('passwordDiv').style.display = 'none';
        document.getElementById('passwordDivLabel').style.display = 'none';
    } else {
        _local.style.visibility = 'hidden';
        _localLabel.style.visibility = 'hidden';
        _localHelp.style.visibility = 'hidden';
        _local.checked = false; 
        document.getElementById('passwordDiv').style.display = 'block';
        document.getElementById('passwordDivLabel').style.display = 'block';
        document.getElementById('helpLocal').style.display = 'none';
    }
}


// Functions for GroupSettings.aspx and GuestRegStep2.aspx
function SetFriendlyUrl() {
    var url = mjASPX.FriendlyUrl();
    var gname = mjASPX.GroupName();
    var portal  = mjASPX._portal;
    url.value = gname.value.replace(/[\+?&=\.\#\%\<\> ,\/\\\(\)"']/g, '');
    updateUrl(url.value, true);
}

function updateUrl(sUrl,bUpdate) 
{
    var cur = document.getElementById('curUrl');
    if (cur == null) {
        return;
    }
    sUrl = sUrl.replace(/[\+\.\#\%\<\> ,\/\\\(\)"']/g,'');
    cur.innerHTML = sUrl + cur.innerHTML.substring(cur.innerHTML.indexOf("?pwd="));
    if (bUpdate) {                     
        var url = mjASPX.FriendlyUrl();
        url.value = sUrl;
    }

}

function updatePassword(sPwd,bUpdate) 
{
    var cur = document.getElementById('curUrl');
    if (cur == null) {
        return;
    }
    sPwd = sPwd.replace(/[\+\. ,\/\\\(\)"']/g,'');
    cur.innerHTML = cur.innerHTML.substring(0, cur.innerHTML.indexOf("?pwd=")) + "?pwd=" + escape(sPwd);
    if (bUpdate) {                     
        var pwd = mjASPX.Password();
        pwd.value = sPwd;
    }

}

function updateMessageText(sGroupName) 
{
        // var subject = mjASPX.InviteSubject().value;
        // subject = subject.substring(0,subject.lastIndexOf(':')+1);
        // mjASPX.InviteSubject().value = subject + ' ' + sGroupName;

        var oEditor = FCKeditorAPI.GetInstance( mjASPX.InvitationBody().id ) ; 
        var sBody = oEditor.GetXHTML( true );
        sBody = sBody.replace(/\{GROUPNAME\}/g,sGroupName);
        // <b>"{GROUPNAME}"</b>
        // <strong>&quot;test0518 Group&quot;</strong>
        sBody = sBody.replace(/\<strong\>&quot;[^\"]+&quot;\<\/strong\>/i,'\<b\>\"' + sGroupName + '\"\<\/b\>');
        oEditor.SetHTML( sBody )
}


function ShowHelpDiv(sDivId,bShow) {
    var ctl = document.getElementById(sDivId);
    if (ctl != null) {
        if (bShow) {
            ctl.style.display = 'block';
        } else {
            ctl.style.display = 'none';
        }
    }
}

function ToggleHelpDiv(sDivId) {
    var ctl = document.getElementById(sDivId);
    if (ctl != null) {
        if (ctl.style.display == 'none') {
            ctl.style.display = 'block';
        } else {
            ctl.style.display = 'none';
        }
    }
}

function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}

function ShowHelpDivHideLink(sDivId,bShow,obj)
{
    var ctl = document.getElementById(sDivId);
    var id = document.getElementById(obj);
    if (ctl != null) {
        if (bShow) {
            ctl.style.display = 'block';
            id.style.display = 'none';
        } else {
            ctl.style.display = 'hidden';
        }
    }    
}


function GetUrlParamValue(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}



function FindParent(idMatch,node,maxlevel) 
{
    // walk up the dom tree to find the container with an id like Kid_1
    if (maxlevel == 0) 
    {
        return null;
    }
    if (node) 
    {
        if (node.id) 
        {
            if (node.id.match(idMatch))
            {
                return node;
            } 
            else 
            {
                return FindParent(idMatch,node.parentNode,maxlevel-1);
            }
        }
        else 
        {
            return FindParent(idMatch,node.parentNode,maxlevel-1);
        }
    } 
    else 
    {
        return FindParent(idMatch,node.parentNode,maxlevel-1);
    }
}

var KidCount = 1;
function AddKidNode(node) 
{
    var kid = node.parentNode;
    // walk up the dom tree to find the container with an id like Kid_1
    kid = FindParent(/[Kk]id/,node.parentNode,10);
    var kidlist = FindParent(/[Kk]id/,kid.parentNode,10);
     
    KidCount++;
    var newkid = kid.cloneNode(true);
    ChangeIdNumber(newkid,KidCount);
    kidlist.appendChild(newkid);
}

function ChangeIdNumber(node,sNum)
{
    if (node) {
        for (var i = 0; i < node.childNodes.length; i++) 
        {
             ChangeIdNumber(node.childNodes[i],sNum);
        }
        if (node.id) {
            if (node.id.match(/_[0-9]+(_[0-9]+)$/))
            {
                // Radio list style name_X_0, name_X_1
                node.id = node.id.replace(/_[0-9]+(_[0-9]+)$/,"_" + sNum + '$1');
                
            } else if (node.id.match(/_[0-9]+$/)) 
            {
                node.id = node.id.replace(/_[0-9]+$/,"_" + sNum);
            }
            
        }
        
        if (node.name) 
        {
            if (node.tagName == "INPUT" && node.type == "radio" && node.name.match(/_[0-9]+$/)) 
            {
                node.name = node.name.replace(/_[0-9]+$/,"_" + sNum);
            }
        }
    }  // there is a non-null node
}

var oPreviousPic = null;

function UpdateAvatarPick(sNewValue) 
{
    if (oPreviousPic) 
    { 
        oPreviousPic.style.border = 'black 2px solid'; 
        oPreviousPic.style.padding = '2px 2px 2px 2px'; 
        if ( (mjASPX.imgAvatar != undefined) && (mjASPX.imgAvatar() != null) )
        {
            mjASPX.imgAvatar().style.display = 'none';
        }
    } 
    if (document.getElementById(sNewValue) != null)
    { 
        document.getElementById(sNewValue).style.border='red 2px dotted';  
        document.getElementById(sNewValue).style.padding ='2px 2px 2px 2px';
        mjASPX.AvatarFile().value = sNewValue; 
        oPreviousPic = document.getElementById(sNewValue);
    }
    return false;
}


function ShowDiv(e) 
{
    e.style.visibility = 'visible';
    e.style.display = 'block';
}

function HideDiv(e)
{
    e.style.visibility = 'hidden';
    e.style.display = 'none';
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

// HISTORY
// ------------------------------------------------------------------
// May 17, 2003: Fixed bug in parseDate() for dates <1970
// March 11, 2003: Added parseDate() function
// March 11, 2003: Added "NNN" formatting option. Doesn't match up
//                 perfectly with SimpleDateFormat formats, but 
//                 backwards-compatability was required.

// ------------------------------------------------------------------
// These functions use the same 'format' strings as the 
// java.text.SimpleDateFormat class, with minor exceptions.
// The format string consists of the following abbreviations:
// 
// Field        | Full Form          | Short Form
// -------------+--------------------+-----------------------
// Year         | yyyy (4 digits)    | yy (2 digits), y (2 or 4 digits)
// Month        | MMM (name or abbr.)| MM (2 digits), M (1 or 2 digits)
//              | NNN (abbr.)        |
// Day of Month | dd (2 digits)      | d (1 or 2 digits)
// Day of Week  | EE (name)          | E (abbr)
// Hour (1-12)  | hh (2 digits)      | h (1 or 2 digits)
// Hour (0-23)  | HH (2 digits)      | H (1 or 2 digits)
// Hour (0-11)  | KK (2 digits)      | K (1 or 2 digits)
// Hour (1-24)  | kk (2 digits)      | k (1 or 2 digits)
// Minute       | mm (2 digits)      | m (1 or 2 digits)
// Second       | ss (2 digits)      | s (1 or 2 digits)
// AM/PM        | a                  |
//
// NOTE THE DIFFERENCE BETWEEN MM and mm! Month=MM, not mm!
// Examples:
//  "MMM d, y" matches: January 01, 2000
//                      Dec 1, 1900
//                      Nov 20, 00
//  "M/d/yy"   matches: 01/20/00
//                      9/2/00
//  "MMM dd, yyyy hh:mm:ssa" matches: "January 01, 2000 12:30:45AM"
// ------------------------------------------------------------------

var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x) {return(x<0||x>9?"":"0")+x}

// ------------------------------------------------------------------
// isDate ( date_string, format_string )
// Returns true if date string matches format of format string and
// is a valid date. Else returns false.
// It is recommended that you trim whitespace around the value before
// passing it to this function, as whitespace is NOT ignored!
// ------------------------------------------------------------------
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}

// -------------------------------------------------------------------
// compareDates(date1,date1format,date2,date2format)
//   Compare two date strings to see which is greater.
//   Returns:
//   1 if date1 is greater than date2
//   0 if date2 is greater than date1 of if they are the same
//  -1 if either of the dates is in an invalid format
// -------------------------------------------------------------------
function compareDates(date1,dateformat1,date2,dateformat2) {
	var d1=getDateFromFormat(date1,dateformat1);
	var d2=getDateFromFormat(date2,dateformat2);
	if (d1==0 || d2==0) {
		return -1;
		}
	else if (d1 > d2) {
		return 1;
		}
	return 0;
	}

// ------------------------------------------------------------------
// formatDate (date_object, format)
// Returns a date in the output format specified.
// The format string uses the same abbreviations as in getDateFromFormat()
// ------------------------------------------------------------------
function formatDate(date,format) {
	format=format+"";
	var result="";
	var i_format=0;
	var c="";
	var token="";
	var y=date.getYear()+"";
	var M=date.getMonth()+1;
	var d=date.getDate();
	var E=date.getDay();
	var H=date.getHours();
	var m=date.getMinutes();
	var s=date.getSeconds();
	var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
	// Convert real date parts into formatted versions
	var value=new Object();
	if (y.length < 4) {y=""+(y-0+1900);}
	value["y"]=""+y;
	value["yyyy"]=y;
	value["yy"]=y.substring(2,4);
	value["M"]=M;
	value["MM"]=LZ(M);
	value["MMM"]=MONTH_NAMES[M-1];
	value["NNN"]=MONTH_NAMES[M+11];
	value["d"]=d;
	value["dd"]=LZ(d);
	value["E"]=DAY_NAMES[E+7];
	value["EE"]=DAY_NAMES[E];
	value["H"]=H;
	value["HH"]=LZ(H);
	if (H==0){value["h"]=12;}
	else if (H>12){value["h"]=H-12;}
	else {value["h"]=H;}
	value["hh"]=LZ(value["h"]);
	if (H>11){value["K"]=H-12;} else {value["K"]=H;}
	value["k"]=H+1;
	value["KK"]=LZ(value["K"]);
	value["kk"]=LZ(value["k"]);
	if (H > 11) { value["a"]="PM"; }
	else { value["a"]="AM"; }
	value["m"]=m;
	value["mm"]=LZ(m);
	value["s"]=s;
	value["ss"]=LZ(s);
	while (i_format < format.length) {
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		if (value[token] != null) { result=result + value[token]; }
		else { result=result + token; }
		}
	return result;
	}
	
// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
	}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
	}
	
// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 20) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	return newdate.getTime();
	}

// ------------------------------------------------------------------
// parseDate( date_string [, prefer_euro_format] )
//
// This function takes a date string and tries to match it to a
// number of possible date formats to get the value. It will try to
// match against the following international formats, in this order:
// y-M-d   MMM d, y   MMM d,y   y-MMM-d   d-MMM-y  MMM d
// M/d/y   M-d-y      M.d.y     MMM-d     M/d      M-d
// d/M/y   d-M-y      d.M.y     d-MMM     d/M      d-M
// A second argument may be passed to instruct the method to search
// for formats like d/M/y (european format) before M/d/y (American).
// Returns a Date object or null if no patterns match.
// ------------------------------------------------------------------
function parseDate(val) {
	var preferEuro=(arguments.length==2)?arguments[1]:false;
	generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','MMM d y','y-MMM-d','d-MMM-y','MMM dd','MMM d');
	monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','MM-d','MM/d','MM-dd','MM/dd','M-d');
	dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M','d MMM');
	var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');
	var d=null;
	for (var i=0; i<checkList.length; i++) {
		var l=window[checkList[i]];
		for (var j=0; j<l.length; j++) {
			d=getDateFromFormat(val,l[j]);
			if (d!=0) { return new Date(d); }
			}
		}
	return null;
	}
	

 function VaidateCategory() {
    var gcat = mjASPX.GroupCategoryId();
    if (gcat.value == 0) {
        alert('Please Select Category for your Group');
        gcat.focus();
        return false;
    }
    return true;
  }

function ValidateDate(e,errorDivId) 
{
    var s = e.value;
    if (s == null || s == '') {
        return '';
    }
    var err = document.getElementById(errorDivId);
    var sFormat = '';
    if (parseDate(s)) 
    {
        var dd = parseDate(s);
        if (getDateFromFormat(s,'M-d') != 0 
            || getDateFromFormat(s,'MMM d') != 0 
            || getDateFromFormat(s,'MM/dd') != 0 
            || getDateFromFormat(s,'M/d') != 0 
            || getDateFromFormat(s,'M-d') != 0 
            || getDateFromFormat(s,'MM-dd') != 0 
            || getDateFromFormat(s,'MMM-d') != 0 
            || getDateFromFormat(s,'d MMM') !=0 
            || getDateFromFormat(s,'dd MMM') !=0 
            || getDateFromFormat(s,'dd-MMM') !=0 
            || getDateFromFormat('d-MMM') != 0
            )
        {
            // IE doesn't do this the same as firefox with the year is omitted so fix it to Firefox standard javascript
            dd = new Date(-1793,dd.getMonth(),dd.getDate());
        }
        if (dd.getYear() < 0) 
        {
            e.value = formatDate(dd,'MMM d');
        } 
        else 
        {
            e.value = formatDate(dd,'MM/dd/yyyy');
        }
        err.style.display = 'none';
    }
    else 
    {
        err.style.display = 'block';
    }
}

function createRipplePop(url,groupid,messageid) 
{
    var lastchar = url.substring(url.length-1);
    var qsexists = url.indexOf("?") >= 0;
    var addchar = ( (lastchar == "?") || (lastchar == "&") ) ? "" : qsexists ? '&' : '?';
    window.open(url + addchar + "g=" + groupid + "&m=" + messageid, "PopupPage", "height=415,width=590,scrollbars=yes,resizable=no");
}

function createRipplePopWithParam(url,groupid,messageid,field) {
    dialogArguments = field;
    createRipplePop(url,groupid,messageid) ;
}

function createUploadAndCropPopup(urlfield, cropxfield, cropyfield, cropwidthfield, cropheightfield, previewfield)
{
    dialogArguments = new Array();
    dialogArguments["url"] = urlfield;
    dialogArguments["cropx"] = cropxfield;
    dialogArguments["cropy"] = cropyfield;
    dialogArguments["cropwidth"] = cropwidthfield;
    dialogArguments["cropheight"] = cropheightfield;
    dialogArguments["preview"] = previewfield;

    window.open('../Image/uploadncropstep1.castle', '_blank', 'height=600,width=800,scrollbars=yes,resizable=no');
}

function doScrollNav(anchor,pi) 
{
    var xx = WebForm_GetScrollX();
    var yy = WebForm_GetScrollY();
    var sUrl = window.location.href;
    if (! sUrl.match(/\.aspx\?$/)) 
    {
        sUrl = sUrl + "?";
    }
    sUrl = sUrl.replace(/\?x=[^&]+\&*/,"?&");
    sUrl = sUrl.replace(/\&x=[^&]+\&*/,"&");
    sUrl = sUrl.replace(/\&si=[^&]+\&*/,"&");
    sUrl = sUrl.replace(/\&y=[^&]+\&*/,"&");
    // sUrl = sUrl.replace(/\&pi_.+=[^&]+\&*/,"&");
    // look for only the current anchor pi leave any others
    sUrl = sUrl.replace(anchor,"Xieruw3393X");  // magic value
    sUrl = sUrl.replace(/\&pi_Xieruw3393X=[^&]+\&*/,"&");
    sUrl = sUrl.replace("Xieruw3393X",anchor);
    
    sUrl = sUrl + "&x=" + xx + "&y=" + yy + "&pi_" + anchor + "=" + pi + "&si=" + anchor;
    sUrl = sUrl.replace(/\&&/,"&");
    sUrl = sUrl.replace(/\.aspx\?&/,".aspx?");
    sUrl = sUrl.replace(/\?&/,"&");
    window.location.href = sUrl;
}
// &scrollx=<script type='text/javascript'>document.write(WebForm_GetScrollX());document.write('&scrolly='); document.write(WebForm_GetScrollY());

function popup(page) 
{     
    window.open(page,'RippleDemo','resizable=no, location=no, width=645, height=425, menubar=no, status=no, scrollbars=no, menubar=no')
}


function GotoMapIt() {
    var s = window.document.getElementById("searchtext");
    if (s) {
        var url = "http://maps.google.com/?q=" + s.value;
        window.open(url, "map", "width=1024,height=730,menubar=no,scrollbars=yes,resizable=yes")
    }
}

var dialogArguments;

function ShowWindowWithParam(sUrl,field) {
    dialogArguments = field;
    open (sUrl, "" , 
       'width=800,height=500,scrollbars=1,resize=1'); 
}



function createGenericPop(url) {
    window.open(url, "", "width=1024,height=730,menubar=no,scrollbars=no,resizable=no")
}


function CheckBoxValidatorDisableButton(chkId, mustBeChecked, btnId)
{
    var button = document.getElementById(btnId);
    var chkbox = document.getElementById(chkId);
    
    if (button && chkbox)
    {
        button.disabled = (chkbox.checked != mustBeChecked);
    }
}

function CheckBoxValidatorEvaluateIsValid(val)
{
    var control = document.getElementById(val.controltovalidate);
    var mustBeChecked = Boolean(val.mustBeChecked == 'true');

    return control.checked == mustBeChecked;
}

function CheckBoxListValidatorEvaluateIsValid(val)
{
    var control = document.getElementById(val.controltovalidate);
    var minimumNumberOfSelectedCheckBoxes = parseInt(val.minimumNumberOfSelectedCheckBoxes);

    var selectedItemCount = 0;
    var liIndex = 0;
    var currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    while (currentListItem != null)
    {
        if (currentListItem.checked) selectedItemCount++;
        liIndex++;
        currentListItem = document.getElementById(control.id + '_' + liIndex.toString());
    }
    
    return selectedItemCount >= minimumNumberOfSelectedCheckBoxes;
}

// Tabbing related code for mouse over and mouse out, based on the following conventions:
//
// Bitmap names are:
//  [prefix].[extension] for regular tabs
//  [prefix]_on.[extension] when the tab is selected
//  [prefix]_over.[extension] when the mouse is over the tab
//
// Tab elements ids are:
//  [prefix]_lt - the id of the left graphics for the tab
//  [prefix]_mid - the id of the middle graphics for the tab
//  [prefix]_rt - the id of the right graphics for the tab

var _gTabState = "";

function tabOver(el) 
{
    var tab = el.id;
    tab = tab.replace(/(^.*)_.*$/,"$1");
    var elem1 = document.getElementById(tab+"_lt");
    var elem2 = document.getElementById(tab+"_mid");
    var elem3 = document.getElementById(tab+"_rt");
    
    _gTabState = (elem2.style.backgroundImage.match(/_on\./)) ? "_on" : "";
    elem1.firstChild.src = elem1.firstChild.src.replace(/(_on)\./,".");
    elem2.style.backgroundImage = elem2.style.backgroundImage.replace(/(_on)\./,".");
    elem3.firstChild.src = elem3.firstChild.src.replace(/(_on)\./,".");

    elem1.firstChild.src = elem1.firstChild.src.replace(/(^.*)\.(.*)$/,"$1" + "_over." + "$2");
    elem2.style.backgroundImage = elem2.style.backgroundImage.replace(/(^.*)\.(.*)$/,"$1" + "_over." + "$2");
    elem3.firstChild.src = elem3.firstChild.src.replace(/(^.*)\.(.*)$/,"$1" + "_over." + "$2");
    
}

function tabOut(el) 
{
    var tab = el.id;
    tab = tab.replace(/(^.*)_.*$/,"$1");
    var elem1 = document.getElementById(tab+"_lt");
    var elem2 = document.getElementById(tab+"_mid");
    var elem3 = document.getElementById(tab+"_rt");

    elem1.firstChild.src = elem1.firstChild.src.replace(/(_over)\./,".");
    elem2.style.backgroundImage = elem2.style.backgroundImage.replace(/(_over)\./,".");
    elem3.firstChild.src = elem3.firstChild.src.replace(/(_over)\./,".");
    
    elem1.firstChild.src = elem1.firstChild.src.replace(/(^.*)\.(.*)?$/,"$1" + _gTabState + ".$2");
    elem2.style.backgroundImage = elem2.style.backgroundImage.replace(/(^.*)\.(.*)?$/,"$1" + _gTabState + ".$2");
    elem3.firstChild.src = elem3.firstChild.src.replace(/(^.*)\.(.*)?$/,"$1" + _gTabState + ".$2");
   
}

// Seems to control how enter key is handled in multiline text boxes
var catchkeypress = false;
function keypress(button) { 
    if (event.keyCode == 13) {  aspnetForm[button].click(); } 
}

function donothing() { 
 if (event.keyCode == 13) { return true; } 
}

function enablekeypress() { catchkeypress = false; }
function disablekeypress() { catchkeypress = true; }

function kH(e) {
    if (catchkeypress) 
    {
        var pK = e ? e.which : window.event.keyCode;
        return pK != 13;
    }
}

function getBlank (form, stdValue){
    if (form.value == stdValue) {
        form.value = '';
    }
    return true;
}

function FixFCKUrl(url)
{
    // Modify the URL to be based on UserImage.aspx
    var token = "/userfiles/";
    var startpos = url.indexOf(token);
    if (startpos < 0)
        return url;
    startpos += token.length;
    var len = url.substring(startpos).indexOf('/');
    var memberid = url.substring(startpos, startpos + len);
    var filename = url.substring(startpos + len + 1);
	return "/UserImage.aspx?f=" + escape(filename) + "&mbr=" + memberid ;
}

document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);

function DefaultLinkButtonKeyPress(evt, linkButtonId)
{
    if(evt.which || evt.keyCode)
    {
        if((evt.which == 13) || (evt.keyCode == 13))
        {
          location = document.getElementById(linkButtonId).href;
          return false;   
    }
        return true;
    }
}


var currentSlideNumber = 1;
var nextSlideNumber = 1;
var nextSlideThread;
var selectedCarousel;
var portalCode;
var delay = 90000000000;
function DisplayNextCarouselSlide(bDelay)
{
    nextSlideNumber = (currentSlideNumber % 4) + 1;
    if (bDelay)
        nextSlideThread = setTimeout("DisplaySlide(" + nextSlideNumber + ")", delay);
    else
        DisplaySlide(nextSlideNumber);
}

function DisplayPreviousCarouselSide()
{
    nextSlideNumber = currentSlideNumber - 1;

    if (nextSlideNumber <= 0)
        nextSlideNumber = 4;

    DisplaySlide(nextSlideNumber);
}  
    
function DisplaySlide(slideNumber)
{
    window.clearTimeout(nextSlideThread);
    var divName = "slide" + slideNumber;

    if ($(divName).innerHTML == "") 
    {
        var ajUpdate = new Ajax.Updater(divName, '/admin/widget/HomePageGetCarouselPage.castle',
		{ parameters: 'slideNumber=' + slideNumber + '&portalPropertyId=' + selectedCarousel + '&portalCode=' + portalCode,
		    onComplete: function(request) { DisplayNextCarouselSlide(true); ShowHideSlides(slideNumber); }, asynchronous: true, evalScripts: true
		});
    }
    else 
    {
        DisplayNextCarouselSlide(true);
        ShowHideSlides(slideNumber);
    }

    currentSlideNumber = slideNumber;			
}

function ShowHideSlides(slideNumber)
{
    for (var i = 1; i < 5; i++) 
    {
        var divName = "slide" + i;
        $(divName).style.display = (i == slideNumber) ? "block" : "none";
    }
}

function resizeImage(img, maxW, maxH)
{
    if(typeof document.body.style.maxWidth != "undefined")
        return;

	var width = img.width;
	var height = img.height;
	
	if (width > height)
	{
	    if (width > maxW)
	    {
	        if ((maxW / (width / height)) <= maxH)
	            width = maxW;
	        else
	            width = maxH*(width/height);
	    }
	    else
	    {
	        if (height > maxH)
	            width = maxH*(width/height);
	    }
	}
	else
	{
        if (height > maxH)
            width = maxH*(width/height);
	}
	
	img.width = width;
}

function ScheduleChatterUpdate()
{
    setTimeout("CallAjaxChatterPanel()", 60000);
}

function UpdateChatterPanel(transport)
{
   var chatterPanel = $('ctlChatterUpdatePanel');
      
   if (transport.responseText != "")
   {
       chatterPanel.update(transport.responseText);           
       ScheduleChatterUpdate();
   }
}
 
function CallAjaxChatterPanel()
{
    var ajUpdate = new Ajax.Request("/members/UpdatePanelPage.aspx", 
            {
                method: "get",
                parameters: "control=~/include/ctlChatterNew.ascx",
                onComplete: function(transport) { UpdateChatterPanel(transport); },                
		        asynchronous: true, 
		        evalScripts: true
		    } );
}

function MomToMomWidgetClick(tabName, widgetMode, rightRail, groupId) 
{
    var divName = "MomToMomPanel";
    var requestParams = { "control": "~/include/ctlMomtoMomLoggedIn.ascx", "si": tabName, "WidgetMode": widgetMode, "RightRail": rightRail, "GroupId":  groupId };
    GetDivContentsAjax(requestParams, divName);
}

function MomToMomFavouriteNotification(butName,messageid,groupId) 
{
    var divName = "NotificationBtn";    
    switch(butName)
    {
     case "Posts":
        alert("The Post has been added to your favorites");
        break;
     case "Poll":
        alert("This Poll has been added to your favorites");
        break;
     case "Photo":
        alert("The Photo has been added to your favorites");
        break;
     case "Blogs":
        alert("The Blog has been added to your favorites");
        break;
     case "Calendar":     
        alert("The event has been added to your calendar.");
        break;
     case "IWillAttend":     
        alert("The event has been added to your calendar and have noted that you will attend.");
        break;
     case "Delete":     
        alert("The notification has been deleted.");
        break;        
    }
    var requestParams = { "control": "~/include/ctlNotification.ascx","bn": butName, "MessageId":  messageid ,"GroupId":  groupId };
    GetDivContentsAjax(requestParams, divName);
}

function addFriendAjax(groupid, memberid, username, addFriendLinkId, lblMessageId) 
{
    var requestParams = { "control": "~/include/ctlFindFriendsMyStuff.ascx", "action": "addFriend", "memberid": memberid, "g": groupid};
    var ajUpdate = new Ajax.Request("/members/UpdatePanelPage.aspx",
            {
                method: "get",
                parameters: requestParams,
                onComplete: function(transport) { },
                asynchronous: true,
                evalScripts: true
            });

    $(addFriendLinkId).hide();
    $(lblMessageId).show();
    $(lblMessageId).update("Pending friend request.");

    var messagePrefix = "<div class='lb_title' style='margin:0px 0px 4px 0px;'>Success!</div>";
    var sucessMessage = messagePrefix + username + " has been sent a friend request.";

    var url = "/members/ConfirmOk.aspx?message=" + sucessMessage;
    var w = 400;
    var h = 192;
    showPopup(url, w, h);
}


function MomToMomPostsClick(tabName) 
{
    var divName = "MomToMomPanel";
    var requestParams = { "control": "~/include/ctlMomtoMomPosts.ascx", "si": tabName };
    GetDivContentsAjax(requestParams, divName);
}

function RefreshActivityFeedMember(maxRows, userName, bAppend) 
{
    var divName = "ActivityFeedMember";
    var requestParams = { "control": "~/include/ctlActivityFeedMember.ascx", "u": userName, "maxrows": maxRows };

    if (bAppend) 
    {
        $("lnkSeeMore").hide();
        new Insertion.Bottom(divName, "<div style='float:left;margin-left:136px;margin-top:40px'>" + $("loading").innerHTML + "</div>");
    }
    else 
    {
        $(divName).update("<div style='margin-left:136px;margin-top:40px'>" + $("loading").innerHTML + "</div>");
    }
    
    GetDivContentsAjax(requestParams, divName);
}


function RefreshActivityFeedGroup(maxRows, groupId, cbName, bAppend, source) 
{
    if (source == "mt") 
    {
        var tags = GetSelectedTags(cbName);
        if (tags != "" && ($("cbPolls").checked || $("cbEvents").checked || $("cbPhotos").checked))
            UncheckTags(cbName);
    }
    else if (source == "tag") 
    {
        $("cbPolls").checked = false;
        $("cbEvents").checked = false;
        $("cbPhotos").checked = false;
        $("cbNewMembers").checked = false;
        $("cbDiscussions").checked = true;
    }

    var divName = "ActivityFeedGroup";
    var requestParams = {
        "control": "~/include/ctlActivityFeedGroup.ascx", "g": groupId, "cbDiscussions": $("cbDiscussions").checked, "cbPolls": $("cbPolls").checked,
        "cbEvents": $("cbEvents").checked, "cbPhotos": $("cbPhotos").checked, "cbNewMembers": $("cbNewMembers").checked, "maxrows": maxRows, "tags": GetSelectedTags(cbName)
    };

    if (bAppend) 
    {
        $("lnkSeeMore").hide();
        new Insertion.Bottom(divName, "<div style='float:left;margin-left:136px;margin-top:40px'>" + $("loading").innerHTML + "</div>");
    }
    else 
    {
        $(divName).update("<div style='margin-left:136px;margin-top:40px'>" + $("loading").innerHTML + "</div>");
    }
    
    GetDivContentsAjax(requestParams, divName);
}

function UncheckTags(cbName) 
{
    var chkBoxList = document.getElementById(cbName);

    if (chkBoxList == null || typeof chkBoxList == "undefined")
        return;

    var chkBoxCount = chkBoxList.getElementsByTagName("input");
    for (var i = 0; i < chkBoxCount.length; i++)
        chkBoxCount[i].checked = false;
}

function GetSelectedTags(cbName) 
{
    var chkBoxList = document.getElementById(cbName);

    if (chkBoxList == null || typeof chkBoxList == "undefined")
        return "";
    
    var chkBoxCount = chkBoxList.getElementsByTagName("input");

    var aTags = new Array();
    var tagCount = 0;


    for (var i = 0; i < chkBoxCount.length; i++) 
    {
        if (chkBoxCount[i].checked) 
        {
            aTags[tagCount++] = chkBoxCount[i].value;
        }
    }

    return aTags.join(",");
}


function RefreshActivityFeed(maxRows, isGuest, bAppend, linkId) 
{
    if (isGuest) 
    {
        showPopupTransparent("/members/UpdatePanelPage.aspx?control=" + escape("~/include/ctlActivityFeedPopup.ascx"), 403, 165);
        //$("rbAll").checked = true;
        $("cbDiscussions").checked = true;
        $("cbEvents").checked = true;
        $("cbPhotos").checked = true;
        $("cbPolls").checked = true;
        return;
    }

    $("hlAllActivity").className = "tabOff";
    $("hlMyGroups").className = "tabOff";
    $("hlMyFriends").className = "tabOff";
    $("hlMyPosts").className = "tabOff";
    $("hlMyInnerCircle").className = "tabOff";
    $(linkId).className = "tabOn";

    var divName = "ActivityFeedHome";
    var requestParams = {
        "control": "~/include/ctlActivityFeedHome.ascx", "rbAll": linkId == "hlAllActivity", "rbMyGroups": linkId == "hlMyGroups",
        "rbMyFriends": linkId == "hlMyFriends", "rbMyPosts": linkId == "hlMyPosts", "rbMyInnerCircle": linkId == "hlMyInnerCircle","cbDiscussions": $("cbDiscussions").checked,
        "cbEvents": $("cbEvents").checked, "cbPhotos": $("cbPhotos").checked, "cbPolls": $("cbPolls").checked, "maxrows": maxRows
    };

    //alert($("loading").innerHTML);
    //$("loading").style.display = "block";

    if (bAppend) 
    {
        $("lnkSeeMore").hide();
        new Insertion.Bottom('feedItemsHome', "<div style='margin-left:240px;margin-top:40px'>" + $("loading").innerHTML + "</div>");
    }
    else 
    {
        $("feedItemsHome").update("<div style='margin-left:240px;margin-top:40px'>" + $("loading").innerHTML + "</div>");
    }

    GetDivContentsAjax(requestParams, divName);
}

function GetDivContentsAjax(requestParams, divName) 
{
    var ajUpdate = new Ajax.Request("/members/UpdatePanelPage.aspx",
            {
                method: "get",
                parameters: requestParams,
                onComplete: function(transport) { UpdateDiv(transport, divName); },
                asynchronous: true,
                evalScripts: true
            });
}

function UpdateDiv(transport, divName) 
{
    var divObj = $(divName);
    if (transport.responseText != "") 
    {
        divObj.update(transport.responseText);
    }

    if ($("loading"))
        $("loading").style.display = "none";
}

function selectAll(cbName, isChecked, lblName, lblSingular, lblPlural, startIndex) 
{
    var chkBoxList = document.getElementById(cbName);
    var chkBoxCount = chkBoxList.getElementsByTagName("input");

    for (var i = 1; i < chkBoxCount.length; i++) 
    {
        chkBoxCount[i].checked = isChecked;
    }

    setCbSelectedCountLabel(cbName, lblName, lblSingular, lblPlural, startIndex);
}

function getSelectedCbCount(cbName, startIndex) 
{
    var chkBoxList = document.getElementById(cbName);
    var chkBoxCount = chkBoxList.getElementsByTagName("input");
    var selectedCount = 0;

    for (var i = startIndex; i < chkBoxCount.length; i++) 
    {
        if (chkBoxCount[i].checked)
            selectedCount++
    }

    return selectedCount;
}

function setCbSelectedCountLabel(cbName, lblName, lblSingular, lblPlural, startIndex) 
{
    var selectedCount = getSelectedCbCount(cbName, startIndex);
    var lblSelectCount = document.getElementById(lblName);

    if (selectedCount == 1)
        lblSelectCount.innerHTML = "<strong>" + selectedCount + "</strong> " + lblSingular;
    else
        lblSelectCount.innerHTML = "<strong>" + selectedCount + "</strong> " + lblPlural;
}

function showPopupTransparent(url, w, h) 
{
    if (myLightWindow == null)
        lightwindowInit();

    myLightWindow.activateWindow({ href: url, title: "", height: h, width: w, left: document.documentElement.clientWidth / 2, showModal: true, allowTransparency: true });
}


function showPopup(url, w, h) 
{
    if (myLightWindow == null)
        lightwindowInit();

    myLightWindow.activateWindow({ href: url, title: "", height: h, width: w, left: document.documentElement.clientWidth / 2, showModal: true });
}

function showShareDiv() {
    var e = document.getElementById("dropMenu");
    var g = document.getElementById("share");
    var imagepath = g.src.substring(0, g.src.lastIndexOf("/"));
    if (e.style.display == 'block') {
        e.style.display = 'none';
        g.src = imagepath + "/sharePlus.gif";
    }
    else {
        e.style.display = 'block';
        g.src = imagepath + "/shareMinus.gif";
    }
}

function showSponsorDiv() {
    var e = document.getElementById("sponsorBlurb");
    if (e.style.display == 'block') {
        e.style.display = 'none';
    }
    else {
        e.style.display = 'block';
    }
}

function showMoreDiv(el) {
    var e = document.getElementById(el);
    if (e.style.display == 'block') {
        e.style.display = 'none';
    }
    else {
        e.style.display = 'block';
    }
}

function fbShare()
{
    showShareDiv();
    return fbs_click();
}

function newDateWithSeconds() {
    var d = new Date();
    var date;

    date = (d.getMonth() + 1) + "/" + d.getDate() + "/" + d.getFullYear();
    if (d.getHours() > 11)
        date += " " + makeHour(d.getHours()) + ":" + makeMinute(d.getMinutes()) + ":" + makeSeconds(d.getSeconds()) + " PM";
    else
        date += " " + makeHour(d.getHours()) + ":" + makeMinute(d.getMinutes()) + ":" + makeSeconds(d.getSeconds()) + " AM";

    return date;
}

function makeHour(hours) {
    var hour = parseInt(hours) % 12;
    if (hour == 0)
        hour = 12;
    if (hour < 10)
        hour = "0" + hour;

    return hour;
}

function makeMinute(minutes) {
    var temp = parseInt(minutes);
    if (temp < 10)
        temp = "0" + temp;

    return temp;
}

function makeSeconds(seconds) {
    var temp = parseInt(seconds);
    if (temp < 10)
        temp = "0" + temp;

    return temp;
}

//force groups front center column always longer than first column
function fixedHeight() {
    var myLeftColumn = document.getElementById("left_column");
    var myRightColumn = document.getElementById("right_column"); 
    var myMainColumn = document.getElementById("main_column");
    var myLeftHeight = myLeftColumn.offsetHeight;
    var myRightHeight = myRightColumn.offsetHeight;
    if (myLeftHeight > myRightHeight) {
        myRightColumn.style.height = (myLeftHeight + 50) + "px";
    }
    else {
        myRightColumn.style.height = (myRightHeight) + "px"; 
        myMainColumn.style.height = (myRightHeight + 120) + "px";
    }
}

function addLoadListener(fn) {
    if (typeof window.addEventListener != 'undefined') {
        window.addEventListener('load', fn, false);
    }
    else if (typeof document.addEventListener != 'undefined') {
        document.addEventListener('load', fn, false);
    }
    else if (typeof window.attachEvent != 'undefined') {
        window.attachEvent('onload', fn);
    }
    else {
        var oldfn = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = fn;
        }
        else {
            window.onload = function() {
                oldfn();
                fn();
            };
        }
    }
}
//  END force groups front center column always longer than first column