// JScript File

var strReferrerURL = "-";

// Registers click() as a function for non-IE browsers.
var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isSafari    = (navigator.appVersion.indexOf("Safari") != -1) ? true : false;
var isIE6 = (navigator.appVersion.indexOf('MSIE 6') != -1) ? true: false;
var isFF = (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) ? true: false;

if(!isIE)
{
    HTMLElement.prototype.click = function() {
        var evt = this.ownerDocument.createEvent('MouseEvents');
        evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
        this.dispatchEvent(evt);
    }
}


//  Function to create or update a cookie.
//    name - String object containing the cookie nname.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie(name, value, expires, path, domain, secure) {
    document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
function GetCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "; path=/") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-1976 00:00:01 GMT";
  }
}

function FinalizeContest(strId)
{
	var oHidFinalize = document.getElementById('hiddenFinalize');
	if (oHidFinalize)
	{
		if (confirm("Are you sure you want to finalize this Campaign?  You should only proceed if the moderation of the " + this.GetFlexTerm("lc_entries", false) + " is complete!"))
		{
			oHidFinalize.value = strId;
			document.forms[0].submit();
		}
	}
}

function DeleteContest(strId)
{
	var oHid = document.getElementById('hiddenDelete');
	if (oHid)
	{
		if (confirm("Are you sure you want to delete this Campaign?  Only proceed if there are NO SUBMISSIONS to this campaign!"))
		{
			oHid.value = strId;
			document.forms[0].submit();
		}
	}
}

function SetMood(strProfileName, ctrlPullDown)
{
	id = ctrlPullDown.options[ctrlPullDown.selectedIndex].value;
	window.location = "/Pages/MyProfileCorner/SetMood.aspx?profilename=" + strProfileName + "&mid=" + id;
}

function SetValue(ctrl, value)
{
	var oHidden = document.getElementById(ctrl);
	if (oHidden)
	{
		oHidden.value = value;
	}
}

function SetStars(ctrl, value)
{
	var oStars = document.getElementById(ctrl);
    if (oStars)
    {
	    //oStars.setAttribute("style", "width:10px;");
	    oStars.style.width = (value*20) + "px";
	}
}

function SetChecked(ctrl, value)
{
	var oCtrl = document.getElementById(ctrl);
	if (oCtrl)
	{
		oCtrl.checked = value;
	}
}


function SetMailIFrame(url)
{
	var oMailFrame = document.getElementById('mailframe');
	if (oMailFrame)
	{
		oMailFrame.src = url;
	}
}

function RefreshFolderList(url)
{
	window.parent.location=url;
}

function CheckUncheckAll(theElement) {
	var theForm = theElement.form, i = 0;
	for(i=0; i < theForm.length; i++)
	{
		if (theForm[i].type == 'checkbox' && theForm[i].name != theElement.name)
		{
		    if (!theForm[i].disabled)
		    {
			    theForm[i].checked = theElement.checked;
			}
		}
	}
}

function CheckUncheckAllExcept(theElement, except) {
	var theForm = theElement.form, i = 0;
	var theExceptionName = "";
	if (except.length > 0)
	{
		var theException = document.getElementById(except);
		if (theException)
		{
			theExceptionName = theException.name;
		}
	}
	for(i=0; i < theForm.length; i++)
	{
		if ((theForm[i].type == 'checkbox') && (theForm[i].name != theElement.name) && (theForm[i].name != theExceptionName))
		{
		    if (!theForm[i].disabled)
		    {
			    theForm[i].checked = theElement.checked;
			}
		}
	}
}

function CheckUncheckAllForMail(theElement) {
	var theForm = theElement.form, i = 0;
	for(i=0; i < theForm.length; i++)
	{
		if (theForm[i].type == 'checkbox' && theForm[i].name != theElement.name && theForm[i].name.search('chxSelectAllFriends') == -1 && theForm[i].name.search('chxSelectAllInnerCircle') == -1)
		{
			theForm[i].checked = theElement.checked;
		}
	}
}


function CheckUncheckInnerCircle(theElement) {
	var theForm = theElement.form, i = 0;
	for(i=0; i < theForm.length; i++)
	{
																					//keep this synchronized with the code that sets it!
		if (theForm[i].type == 'checkbox' && theForm[i].name != theElement.name &&	theForm[i].name.search('InnerCircle_') != -1) 
		{
			theForm[i].checked = theElement.checked;
		}
	}
}

function DeleteLayout()
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSure("the selected layout(s)"))
		{
			oHidDelete.value = "-1";
			document.forms[0].submit();
		}
	}
}

function DeleteBlogs()
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		var theForm = document.forms[0], i = 0, isOneChecked = false;
		for(i=0; i < theForm.length; i++)
		{
			if (theForm[i].type == 'checkbox')
			{
				if (theForm[i].checked)
				{
					isOneChecked = true;
					break;
				}
			}
		}
		if (!isOneChecked)
		{
			alert("Please select a blog before clicking the Delete Blog button.");
		}
		else if (AreYouSure("the selected blog(s)"))
		{
			oHidDelete.value = "-1";
			document.forms[0].submit();
		}
	}
}

function DeleteBlog(blogId, contentId)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSure("this blog"))
		{
			oHidDelete.value = "chkDelete" + blogId + "_" + contentId;
			document.forms[0].submit();
		}
	}
}

function DeleteSiteText(siteTextId)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSure("this Site Text Value"))
		{
			oHidDelete.value = siteTextId;
			document.forms[0].submit();
		}
	}
}

function DeleteSiteTextArea(siteTextAreaId)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSure("this Site Text Area"))
		{
			oHidDelete.value = siteTextAreaId;
			document.forms[0].submit();
		}
	}
}

function MailChangeFolder(ctrlPullDown)
{
	id = ctrlPullDown.options[ctrlPullDown.selectedIndex].value;

	var oHid = document.getElementById('hiddenFolderId');
	if (oHid)
	{
		if (confirm("Are you sure you want to move the checked items to the selected folder?"))
		{
			oHid.value = id;
			document.forms[0].submit();
		}
	}
}

function DeleteMailMessages()
{
	var bNothingChecked = true;
	var theForm = document.forms[0];
	for(i=0; i < theForm.length; i++)
	{
		if (theForm[i].type == 'checkbox')
		{
			if (theForm[i].checked)
			{
				bNothingChecked = false;
				break;
			}
		}
	}
	if (bNothingChecked)
	{
		alert("Please select the mail message(s) you'd like to delete");
	}
	else
	{
		var oHidDelete = document.getElementById('hiddenDelete');
		if (oHidDelete)
		{
			if (AreYouSure("the selected mail message(s)"))
			{
				oHidDelete.value = "-1";
				document.forms[0].submit();
			}
		}
	}
}

function DeleteMailMessage()
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSure("this mail message"))
		{
			oHidDelete.value = "1";
			document.forms[0].submit();
		}
	}
}

function DeleteMailFolder(iFolderId)
{
	var oHidDelete = document.getElementById('hiddenDeleteFolder');
	if (oHidDelete)
	{
		if (AreYouSure("this mail folder"))
		{
			oHidDelete.value = iFolderId;
			document.forms[0].submit();
		}
	}
}

function SaveMailMessage()
{
	var oHid = document.getElementById('hiddenSave');
	if (oHid)
	{
		if (confirm("Are you sure you want to save this mail message to the drafts folder?"))
		{
			oHid.value = "1";
			document.forms[0].submit();
		}
	}
}

function DeleteReviewByContentId(strMessage, specialId)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	var oHidDeletionComment = document.getElementById('hiddenDeletionComment');
	if (oHidDelete)
	{
		var msg = prompt(ST_DeleteReviewWarning(), '');
		if (msg)
		{
			oHidDelete.value = specialId;
			oHidDeletionComment.value = msg;
			document.forms[0].submit();
		}
	}
}

function DeleteContentItemById(strMessage, specialId)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSure(strMessage))
		{
			oHidDelete.value = specialId;
			document.forms[0].submit();
		}
	}
}

function ApproveContentItem(specialId)
{
	var oHidApprove = document.getElementById('hiddenApprove');
	if (oHidApprove)
	{
		oHidApprove.value = specialId;
		document.forms[0].submit();
	}
}

function AreYouSure(str)
{
	return confirm("Are you sure you want to delete " + str + "?");
}

function AreYouSureGeneric(str)
{
	return confirm(str);
}

function ConfirmItemAction(message, itemid)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (AreYouSureGeneric(message))
		{
			oHidDelete.value = itemid;
			document.forms[0].submit();
		}
	}
}

function AreYouSureAdminConfirm(message, actionType)
{
	if (confirm(message))
	{
		var oHidAdmin = document.getElementById(GetTxtAdminChangeId());
		var oHidAdminActionType = document.getElementById(GetTxtSiteAdminActionType());
		if (oHidAdmin && oHidAdminActionType)
		{
			oHidAdmin.value = actionType;
			oHidAdminActionType.value = actionType;
			document.forms[0].submit();
		}
	}
}

function AreYouSureAdminPrompt(message, actionType)
{
	var key = prompt(message, '');
	if ((key != null) && (key != ''))
	{
		var oHidAdmin = document.getElementById(GetTxtAdminChangeId());
		var oHidAdminActionType = document.getElementById(GetTxtSiteAdminActionType());
		if (oHidAdmin && oHidAdminActionType)
		{
			oHidAdmin.value = key;
			oHidAdminActionType.value = actionType;
			document.forms[0].submit();
		}
	}
}

function ChoosePictureCorner(strPath, pictureId)
{
	var oHidChoosePicture = document.getElementById('hidChoosePictureCorner');
	var oHidChoosePictureId = document.getElementById('hidChoosePictureIdCorner');
	if (oHidChoosePicture)
	{
		oHidChoosePicture.value = strPath;
		oHidChoosePictureId.value = pictureId;
		document.forms[0].submit();
	}
}

function ChoosePicture(strPath, pictureId)
{
	var oHidChoosePicture = parent.document.getElementById('hidChoosePicture');
	var oHidChoosePictureId = parent.document.getElementById('hidChoosePictureId');
	if (oHidChoosePicture)
	{
		oHidChoosePicture.value = strPath;
		oHidChoosePictureId.value = pictureId;
		SetImage(strPath); // whoever use ChoosePicutre.ascx should implement this method.
	}
}

function ChoosePictureForStyle(strPath, ctrlToBeStyledId, txtboxId, additionTag, width, height)
{
	var oHidChoosePicture = parent.document.getElementById('hidChoosePicture');
	if (oHidChoosePicture)
	{
		oHidChoosePicture.value = strPath;
		SetImage(strPath, ctrlToBeStyledId, txtboxId, additionTag, width, height); // Defined in SkinEditor.ascx
	}
}

function ClosePicturePopup()
{
	top.opener.document.forms[0].hidRefresh.value=1;
	top.opener.document.forms[0].submit();
	top.close();
}

function MakeDirty()
{
	var oIsDirtyField = document.getElementById( 'hiddenIsDirty' ) ;
	
	if (oIsDirtyField)
	{
		oIsDirtyField.Value = 1;
	}
}

function CheckIsEditorDirty()
{
	var editors = GetEditorsId(); // any page with editor should insert a js function to return an array of editor ids. 
	
	if(!editors) return false;
	
    for (var i=0; i < editors.length; i++)
    {
		if(CheckIsEditorDirtyById(editors[i]) == true)
			return true;
    }
    
    return false;
}

function CheckIsEditorDirtyById(strId)
{
	try
	{
		var oEditor = FCKeditorAPI.GetInstance(strId + '_ucEditorBase_fckEditor');
		if (oEditor)
		{
			return oEditor.IsDirty();
		}
	}
	catch(e) {}
	
	return false;
}

function GotoLinkCustom(url, msg)
{
	var loseEverything = true;

	if(SomethingIsDirty()){
		loseEverything = confirm(msg);
	}
	
	if (loseEverything)
	{
        if (window.location.href.indexOf("https") != -1)
		{
			var sDnsSafeHost = GetDnsSafeHost();
			url = "http://" + sDnsSafeHost + url;
		}
		if(!m_bRequirePBBRedirect || parent == window)
		{
			window.location = url;
		}
		else 
		{
			var strRelUrl = RemoveDomainFromUrl(url);;					
			window.top.location = GetPBBWrapper() + "=" + EncodeUrl(strRelUrl);
		}
	}
}

function GotoLink(url)
{
    var siteText = getSiteText('Are you sure you want to leave and lose all changes?');
    if (siteText && siteText.length > 0)
    {
	    GotoLinkCustom(url,siteText);
    }
    else
    {
	    GotoLinkCustom(url,'Are you sure you want to leave and lose all changes?');
	}
}

function ReceiveServerData(args, context)
{
    var strVals = args.split(strDelimeter);
    if (strVals.length > 0)
    {
        // This (strParentID) is the original object selected by the user
        var strParentID = strVals[0];
        var strElementValues = args;
        var objElement;
        var objElements = document.forms[0].elements;
        
        for (var i=0; i < objElements.length; i++)
        {
            if (objElements[i].id.indexOf(strParentID) > -1)
            {
                objElement = objElements[i];
            }
        }
        // Found the selected object, now find mapped children
        var intMaxIterations = 100;
        var intCount = 0;
        var bContinueLooping = true;
        while(bContinueLooping)
        {
            intCount++;
            // Safety check for endless loop
            if (intCount > intMaxIterations)
            {
                bContinueLooping = false;
                break;
            }
            // Safety check for null object
            if (objElement == null)
            {
                bContinueLooping = false;
                break;
            }
            else
            {
                // Check to see if this object has a child mapping
                var objChild = null;
                if (arObjectMapping == null || arObjectMapping.length == 0)
                {
                    bContinueLooping = false;
                }
                else
                {
                    // Find the parent and child from the mapping
                    var bHasChild = false;
                    var strDefaultOption = "Choose...";
                    for (var i=0; i < arObjectMapping.length; i++)
                    {
                        var strObject = arObjectMapping[i].split(strDelimeter);
                        if ((strObject != null) && (strObject.length > 2) && (objElement.id.indexOf(strObject[0]) > -1))
                        {
                            // This DDL has a child object
                            bHasChild = true;
                            // Set Child to objChild and break out
                            for (var i=0; i < objElements.length; i++)
                            {
                                if (objElements[i].id.indexOf(strObject[1]) > -1)
                                {
                                    objChild = objElements[i];
                                }
                            }
                            // Set the Default option for this object
                            strDefaultOption = strObject[2];
                            break;
                        }
                        else if (i+1 == arObjectMapping.length)
                        {
                            break;
                        }
                    }

                    if (!bHasChild || objChild == null)
                    {
                        // If this object has no child or it's null, then stop looping
                        bContinueLooping = false;
                    }
                    else
                    {
                        // ID Child Type
                        if (objChild.type == "select-one")
                        {
                            // clear the options from DDL object
                            ClearChildDDL(objChild);
                            // repopulate objChild
                            if (strElementValues == null || strElementValues.length == 0)
                            {
                                PopulateDDL(objChild, objChild.id + strDelimeter + strDefaultOption + strDelimeter + "0");
                            }
                            else
                            {
                                PopulateDDL(objChild, strElementValues);
                            }
                        }
                        else
                        {
                            // TODO: other object types
                        }
                    
                        // Set objElement to objChild and continue looping
                        objElement = objChild;
                        // Clear data from parent
                        strElementValues = "";
                    }
                }
            }
        }
    }
}

function ConfirmLeavePage()
{
	var loseEverything = true;
	var confirmMsg = 'Are you sure you want to leave and lose all changes?';
	
	if(SomethingIsDirty()){
		loseEverything = confirm(confirmMsg);
	}
	return loseEverything;
}

function SomethingIsDirty(){
	var isDirty = false;
	var oIsDirtyField = document.getElementById( 'hiddenIsDirty' ) ;
	var oIsDirtyFieldServer = document.getElementById( GetHiddenIsDirtyServerId() ) ;
	
	if ((oIsDirtyField && oIsDirtyField.Value == 1) || 
		(oIsDirtyFieldServer && oIsDirtyFieldServer.Value == 1) || 
		(oIsDirtyFieldServer && oIsDirtyFieldServer.value == 1) ||
		 CheckIsEditorDirty())
	{
		isDirty = true;
	}
	
	return isDirty;
}

// Use to make the height for two div to be the same
function setTall(colID1, colID2) {
	if (document.getElementById) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		var divs = new Array(document.getElementById(colID1), document.getElementById(colID2));
		
		// Let's determine the maximum height out of all columns specified
		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
		}
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			divs[i].style.height = maxHeight + 'px';
			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			if (divs[i].offsetHeight > maxHeight) {
				divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
			}
		}
	}
}

// do a colID1.height = colID2.height
function setTall_LeftEqualToRight(colID1, colID2) {
	if (document.getElementById) {
		if($(colID1) && $(colID2))
			Element.setStyle(colID1, {height: Element.getHeight(colID2) + 'px'});
	}
}



function setTall_CEonSubmit(colID2){
	var MAX_LEFT_H = 760;
	var MIN_RIGHT_H = 350;
	var DEFAULT_RIGHT_H = MAX_LEFT_H - MIN_RIGHT_H; // 310;
	if (document.getElementById) {
		var rightH = Element.getHeight(colID2);
		if(rightH < MIN_RIGHT_H){ // a very short CE
			Element.setStyle(colID2, {height: DEFAULT_RIGHT_H + 'px'});
		}
	}
}

function setTall_CE(colID1, colID2){
	var MAX_LEFT_H = 760;
	var MIN_RIGHT_H = 350;
	var DEFAULT_RIGHT_H = MAX_LEFT_H - MIN_RIGHT_H; // 310;
	var MAX_DIFF_TO_MATCH = 300; // if H(colID2) - H(colID1) <= 200, match the height
	
	if (document.getElementById) {
		if($(colID1) && $(colID2)) {
		
			var leftH  = Element.getHeight(colID1);
			var rightH = Element.getHeight(colID2);
			
			if( (leftH - rightH) <= MAX_DIFF_TO_MATCH || (leftH <= MAX_LEFT_H)){
				if(leftH > MIN_RIGHT_H || rightH > MIN_RIGHT_H)
				{
					setTall(colID1, colID2);
				}
				else {
					Element.setStyle(colID1, {height: DEFAULT_RIGHT_H + 'px'});
					Element.setStyle(colID2, {height: DEFAULT_RIGHT_H + 'px'});
				}
			}
			else { // big diff between two columns
				if(rightH < MIN_RIGHT_H){ // a very short CE
					Element.setStyle(colID2, {height: DEFAULT_RIGHT_H + 'px'});
				}
				else {
				
					// leave it
				}
			}
		}
	}
}

function openPopupWithScrollBars(strPath, strTitle, iWidth, iHeight)
{
	if (iWidth <= 0) iWidth = 530;
	if (iHeight <= 0) iHeight = 400;

	var newWindow = window.open(strPath, null, 'location=0, resizable=no,scrollbars=yes,width=' + iWidth + ',height=' + iHeight);
	check_popup_blocker(newWindow);
}

function openPopupWithScrollBarsSizable(strPath, strTitle, iWidth, iHeight)
{
	if (iWidth <= 0) iWidth = 530;
	if (iHeight <= 0) iHeight = 400;

	var newWindow = window.open(strPath, null, 'location=0, resizable=yes, scrollbars=yes, width=' + iWidth + ', height=' + iHeight);
	check_popup_blocker(newWindow);
}

function openNewWindow(strPath, strTitle, iWidth, iHeight)
{
	if (iWidth <= 0) iWidth = 530;
	if (iHeight <= 0) iHeight = 400;

	var newWindow = window.open(strPath, null, 'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes, width=' + iWidth + ', height=' + iHeight);
	check_popup_blocker(newWindow);	
}

function openPopupDynamicSize(strPath, strTitle, iWidth, iHeight)
{
	var bSizeChanged = false;
	if (iWidth > screen.availWidth)
	{
		iWidth = screen.availWidth;
		bSizeChanged = true;
	}
	if (iHeight > screen.availHeight)
	{
		iHeight = screen.availHeight;
		bSizeChanged = true;
	}

	if (bSizeChanged)
	{
		openPopupWithScrollBarsSizable(strPath, strTitle, iWidth, iHeight);
	}
	else
	{
		openpopup(strPath, strTitle, iWidth, iHeight);
	}
}

function openpopup(strPath, strTitle, iWidth, iHeight)
{
	if (iWidth <= 0) iWidth = 530;
	if (iHeight <= 0) iHeight = 400;

	var newWindow = window.open(strPath, null, 'location=0, resizable,width=' + iWidth + ',height=' + iHeight);
	check_popup_blocker(newWindow);
}

function openAndReturnPopup(strPath, strTitle, iWidth, iHeight)
{
	if (iWidth <= 0) iWidth = 530;
	if (iHeight <= 0) iHeight = 400;

	var newWindow = window.open(strPath, null, 'location=0, resizable,width=' + iWidth + ',height=' + iHeight);
	check_popup_blocker(newWindow);
	return newWindow;
}

function check_popup_blocker(newWindow){
	if(newWindow){
		newWindow.focus();
	}
	else {
		alert('A pop-up window was blocked.');
	}
}

function openmodaldialog(strPath, strTitle, iWidth, iHeight)
{
	if (iWidth <= 0) iWidth = 530;
	if (iHeight <= 0) iHeight = 400;
		
	if (window.showModalDialog)
	{
		iWidth = iWidth + 5;
		iHeight = iHeight + 33;
		// var oDialogInfo = new Object() ;
		// oDialogInfo.Title = strTitle ;
		// oDialogInfo.Page = strPath ;
		// oDialogInfo.Editor = window ;*/
		//oDialogInfo.CustomValue = customValue ;		// Optional
		window.showModalDialog(strPath, null, 'dialogWidth:' + iWidth + 'px;dialogHeight:' + iHeight + 'px;help:no;scroll:no;status:no');
	}
	else
	{
		var newWindow = window.open(strPath, null, 'location=0,modal=yes,resizable,width=' + iWidth + ',height=' + iHeight);
		newWindow.focus();
	}
}

function checkUploadFormForErrors()
{
	var bHasErrors = false;
	for (var i=0; i < Page_Validators.length; i++)
	{
		var obj = Page_Validators[i];
		var objToVal = document.getElementById(obj.controltovalidate);
		var strEvaluationFunction = obj.evaluationfunction + "";
		if ((strEvaluationFunction.indexOf("RequiredFieldValidatorEvaluateIsValid") > -1) && objToVal.value.length == 0)
		{
			bHasErrors = true;
			break;
		}
	}
	
	return bHasErrors;
}

function showHourglassOnUpload()
{
	var bFormHasErrors = checkUploadFormForErrors();
	if (!bFormHasErrors)
	{
		document.body.style.cursor = 'wait';
	}
}
function showWaitCursor()
{
	document.body.style.cursor = 'wait';
}
function showDefaultCursor()
{
	document.body.style.cursor = 'default';
}
function showprogress()
{
	var bFormHasErrors = checkUploadFormForErrors();
	if (!bFormHasErrors)
	{
		var progressimage = document.getElementById('imageprogress');
		progressimage.style.display = '';
	}
}

function showhide(id){
	var elem = document.getElementById(id); 
	if(elem){
		if ( elem.style.display != "none" ) {
			elem.style.display = 'none';
		}
		else {
			elem.style.display = '';
		}
	}
}             

function GetOffset(ctrl, property){

    var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;


	var iTotal = 0;
	var bustCtr = 0;
	
	var tempParent;
	tempParent = ctrl;
	
	if(property == 'offsetTop') {
		iTotal = iTotal + parseInt(tempParent.offsetTop);
	}
	else if(property == 'offsetLeft'){
		iTotal = iTotal + parseInt(tempParent.offsetLeft);
	}
	
	do {
		tempParent = tempParent.offsetParent;

		var iBorderWidth = 0;
			
		if(property == 'offsetTop'){
			iTotal = iTotal + parseInt(tempParent.offsetTop);
			
			if(isIE){
				if(tempParent.currentStyle.borderTopWidth.indexOf('px') > 0){
					iBorderWidth = tempParent.currentStyle.borderTopWidth.substring(0, tempParent.currentStyle.borderTopWidth.indexOf('px') );
				}
			}
			else{
				if(document.defaultView.getComputedStyle(tempParent, null).getPropertyValue("border-top-width").indexOf('px') > 0){
					iBorderWidth = document.defaultView.getComputedStyle(tempParent, null).getPropertyValue("border-top-width").substring(
						0, document.defaultView.getComputedStyle(tempParent, null).getPropertyValue("border-top-width").indexOf('px') );
				}
			}

			iTotal += parseInt(iBorderWidth);
		}
		else if(property == 'offsetLeft'){
			iTotal = iTotal + parseInt(tempParent.offsetLeft);

			// This is crazy. I spent 4 hours to find this bug.  You need to add border width for IE.  Come back later to make it look prettier....
			if(isIE){
				if(tempParent.currentStyle.borderLeftWidth.indexOf('px') > 0){
					iBorderWidth = tempParent.currentStyle.borderLeftWidth.substring(0, tempParent.currentStyle.borderLeftWidth.indexOf('px') );
				}
			}
			else{
				if(document.defaultView.getComputedStyle(tempParent, null).getPropertyValue("border-left-width").indexOf('px') > 0){
					iBorderWidth = document.defaultView.getComputedStyle(tempParent, null).getPropertyValue("border-left-width").substring(
						0, document.defaultView.getComputedStyle(tempParent, null).getPropertyValue("border-left-width").indexOf('px') );
				}
			}

			iTotal += parseInt(iBorderWidth);
		}
		
		bustCtr ++;
	} while (tempParent.id != 'mainpagestyle' && bustCtr < 20)
	
	return parseInt(iTotal);
}

function setFeatureControlBg(featureCtrlId, bgCtrlId, headerCtrlId, bgImageId, strStretch, strBackgroundImagePath,
							  decorFrameLeftId, decorFrameRightId, decorFrameTopId, decorFrameBottomId, decorBigIconId) {

	var headerCtrl	 = document.getElementById(headerCtrlId);
	var featureCtrl  = document.getElementById(featureCtrlId);
	var bgCtrl		 = document.getElementById(bgCtrlId);
	var bgimage		 = document.getElementById(bgImageId);	
	var decoreFrameL = document.getElementById(decorFrameLeftId);	
	var decoreFrameR = document.getElementById(decorFrameRightId);	
	var decoreFrameT = document.getElementById(decorFrameTopId);	
	var decoreFrameB = document.getElementById(decorFrameBottomId);	
	
	if(strBackgroundImagePath == 'undefined'){
		var hidBackgroundImagePath   = document.getElementById(GeHiddenBackgroundImagePath());
		if(!hidBackgroundImagePath) return;
		strBackgroundImagePath = hidBackgroundImagePath.value;
	}
	
	if(strStretch == 'undefined'){
		var oHidStretch = document.getElementById(GeHiddenStretchId());		
		strStretch = oHidStretch.value;
	}		
		

	if (document.getElementById) {
	
		var iBorderWidth = 0;
        var isIE    = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 
        if(isIE){
			iBorderWidth = featureCtrl.currentStyle.borderTopWidth.substring(0, featureCtrl.currentStyle.borderTopWidth.indexOf('px') );
		}
		else{
			iBorderWidth = document.defaultView.getComputedStyle(featureCtrl, null).getPropertyValue("border-top-width").substring(
				0, document.defaultView.getComputedStyle(featureCtrl, null).getPropertyValue("border-top-width").indexOf('px') );
		} 
		
		var maxHeightNoHeader = featureCtrl.offsetHeight - headerCtrl.offsetHeight - (2 * iBorderWidth);
		var maxHeight = featureCtrl.offsetHeight - (2 * iBorderWidth);
		
		if(maxHeightNoHeader <= 0) // this could happen if user sets display:none to pnlMain.
			return;			
		if(maxHeight <= 0) 
			return;	
		
		var iDecorPaneTop = parseInt(iBorderWidth) +  GetOffset(featureCtrl, 'offsetTop');
		
		var iDecorPaneLeft =  GetOffset(featureCtrl, 'offsetLeft') +  parseInt(iBorderWidth) - 
							  (parseInt(decoreFrameL.offsetWidth) * 7/8) + 'px';
							  
		var iDecorPaneWidth = parseInt(featureCtrl.offsetWidth) -
							  parseInt(iBorderWidth) * 2 +
							  ( parseInt(decoreFrameR.offsetWidth)* 14/8 ) + 'px';							  
			
		var iBgPaneLeft = GetOffset(featureCtrl, 'offsetLeft') + parseInt(iBorderWidth) +'px';		
		var iBgPaneWidth = (parseInt(featureCtrl.offsetWidth)) - iBorderWidth - iBorderWidth;
			
				 
		// Set bg <img> src path 
		//		FF	bgimage.style.MozOpacity=0.1;
		//		IE	bgimage.style.filter = 'alpha(opacity=50)';
		//		Both FF/IE <img src="ball.gif" style="filter:alpha(opacity=50); -moz-opacity:0.5" >
		if(strBackgroundImagePath != ''){
		
			strBackgroundImagePath = strBackgroundImagePath.replace('url("'  , '');
			strBackgroundImagePath = strBackgroundImagePath.replace('url(\'' , '');
			strBackgroundImagePath = strBackgroundImagePath.replace('url('   , '');
			strBackgroundImagePath = strBackgroundImagePath.replace('")'     , '');
			strBackgroundImagePath = strBackgroundImagePath.replace('\')'    , '');
			strBackgroundImagePath = strBackgroundImagePath.replace(')'      , '');
			
			bgimage.src = strBackgroundImagePath;
			bgCtrl.style.backgroundImage = 'url("' + strBackgroundImagePath + '")'; // need to set it again because it may be set to clear when a use select stretch.  now if the user set it back to tile, the bgctrl now need to reget the image path.
		}
			
	    // Stretch bg <img>
		if(strStretch == 'true'){
			bgimage.height = maxHeightNoHeader;
			bgimage.width = iBgPaneWidth;

			if(strBackgroundImagePath != ''){
				bgimage.style.display = '';
			}
			else{
				bgimage.style.display = 'none';
			}
			bgCtrl.style.backgroundImage = 'url("/Media/Images/clear.gif")';
		}
		else {
		
			bgimage.style.display = 'none';
		}	
		
		// Bg Control - it contains the Bg image
		bgCtrl.style.top = iDecorPaneTop + parseInt(headerCtrl.offsetHeight) + 'px';		
		bgCtrl.style.left = iBgPaneLeft;
		bgCtrl.style.height = maxHeightNoHeader + 'px';
		bgCtrl.style.width = iBgPaneWidth + 'px';
		
// bgCtrl.style.top = parseInt("asdasd") + 1 + 'px';		

		// Left				   						  	
        // decoreFrameL.style.top = iDecorPaneTop + 'px'; // I dont remember why I need it.
		decoreFrameL.style.left = iDecorPaneLeft;
		decoreFrameL.style.height = maxHeight + 'px';
		
		// Right	  
		decoreFrameR.style.left = GetOffset(featureCtrl, 'offsetLeft')  + 
								  parseInt(featureCtrl.offsetWidth) - 
								  parseInt(iBorderWidth) -
								  (parseInt(decoreFrameL.offsetWidth) * 1 / 8) + 'px'; 
		decoreFrameR.style.height = maxHeight + 'px';		
		
		// Top
		decoreFrameT.style.top   = parseInt(iDecorPaneTop) - (parseInt(decoreFrameT.offsetHeight)*7/8) + 'px';
		decoreFrameT.style.left  = iDecorPaneLeft;
		decoreFrameT.style.width = iDecorPaneWidth;								
		
		// Bottom
		decoreFrameB.style.top   = (parseInt(iDecorPaneTop) + parseInt(maxHeight)) - (parseInt(decoreFrameT.offsetHeight)*1/8) + 'px';
		decoreFrameB.style.left  = iDecorPaneLeft;
		decoreFrameB.style.width = iDecorPaneWidth;								   
		
		bgCtrl.style.display = ''; 
	}
}

function ChangeSearchPage(strAction)
{
    var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }
    theForm.action = strAction;
    theForm.submit();
}

//-----------------------------------------------------------
// TOOLTIP FUNCTION
//-----------------------------------------------------------
function doTooltip(e, msg, jscall) {
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	Tooltip.followMouse = true;
	Tooltip.offX = 10;  
	Tooltip.offY = 10;
	Tooltip.hideDelay = 000;
	Tooltip.offsetX = 0;
	Tooltip.forceRight = false;
	
	if(jscall) {
		Tooltip.jscall = jscall;
		Tooltip.showDelay = 500;
	}
	// A workaround for the More Entries panel on the content detail page to prevent the hover from stucking behind the viral map.
	if(
		(document.location.href.indexOf('PhotoView.aspx') > 0) || 
		(document.location.href.indexOf('AlbumView.aspx') > 0) || 
		(document.location.href.indexOf('BlogView.aspx') > 0) || 
		(document.location.href.indexOf('AudioView.aspx') > 0) || 
		(document.location.href.indexOf('VideoView.aspx') > 0)
	  )
	{
	}
	// workaround for the viral map tab's recent entries section in the CE panel.
	else if (document.location.href.indexOf('?tab=4') > 0 ||
				document.location.href.indexOf('?tab=viralmap') > 0
		){
		if(msg.indexOf('Sponsor')>0){
			Tooltip.forceRight = true;
		}
	}
	// workaround for watchlist manager
	else if (document.location.href.indexOf('WatchlistManage') > 0){
		Tooltip.forceLeft = true;
		Tooltip.offsetX = -81;
	}
	
	Tooltip.show(e, msg);
}

function hideTip() {
	if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
	Tooltip.hide();
}

		
function doTooltipMenu(e, msg) {
	  Tooltip.followMouse = false;  // must be turned off for hover-tip
	  Tooltip.showDelay = 0;
	  Tooltip.offX = 4;  
	  Tooltip.offY = 4;
	  Tooltip.hideDelay = 100;
	  
	  if(msg.length > 0) {
		  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
		  Tooltip.clearTimer();
		  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
		  if ( tip && tip.onmouseout == null ) {
			  tip.onmouseout = Tooltip.tipOutCheck;
			  tip.onmouseover = Tooltip.clearTimer;
		  }
		  Tooltip.show(e, msg);
	  }
}

function hideTipMenu() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.timerId = setTimeout("Tooltip.hide()", 100);
}

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}

//-----------------------------------------------------------
// END OF TOOLTIP FUNCTION
//-----------------------------------------------------------

function ClearHistory(alink){
	alink.firstChild.data = 'history cleared';
	hideTipMenu();
	var hidden = document.getElementById('hiddenBackButton');
	if(hidden)
		hidden.value = "1";
}

function ShowBackButton(e, msg){

	var hidden = document.getElementById('hiddenBackButton');
	if(hidden && hidden.value == ''){		
		doTooltipMenu(e, msg);
	}
	else {
		doTooltip(e, '<div style=\"padding:10px\">You have not recently visited any<br>profile or campaign leader pages.</div>');
	}
}

function GetCheckedItems(prefix){
    var theForm = document.forms[0];
    var checkedItems = document.getElementById('CheckedItems');
    
    checkedItems.value="";
    
    if(prefix == null) prefix = 'Campaign_';
    
    for(i=0; i < theForm.length; i++)
    {
	    if (theForm[i].type == 'checkbox' && theForm[i].name.indexOf(prefix) > 0)
	    {
	        var deleteBefore = theForm[i].name.indexOf(prefix) + prefix.length;
		    if (theForm[i].checked)
		    {
			    checkedItems.value += "," + theForm[i].id.slice(deleteBefore);
		    }
	    }
    }
    
}

var tooltipCalledJSArray = new Array();	
function ShowImage(p1, p2, p3, p4)
{
	
	if(!tooltipCalledJSArray) // fix this for Safari because even new Array() above still undefined.
		tooltipCalledJSArray = new Array();
	
	var strJSCall = 'showimage' + p1 + p2 + p3 + p4; // create a string representation of the js call and then store in an array
	
	// check if the call has be called bfore.
	var iCtr;
	var bCalledBefore = false;
	for(iCtr in tooltipCalledJSArray)
	{
		if(tooltipCalledJSArray[iCtr] == strJSCall)
		{
			bCalledBefore = true;
			break;
		}
	}

	// only do the ajax call if we have never called with the same params before.
	if (!bCalledBefore)
	{
		tooltipCalledJSArray[tooltipCalledJSArray.length] = strJSCall; // store to the array so we will not call again.

		AJAX.ShowImage(p1, p2, p3, p4, strReferrerURL, ShowImage_Callback);
	}
 }
 
 function ShowImage_Callback(response){
 }
 
 function setHoverBackImage(img){
	img.src = '/Media/Images/general/buttons/backbutton_hover.gif';
 }
 
 function setUnhoverBackImage(img){
	img.src = '/Media/Images/general/buttons/backbutton_unhover.gif';
 }
 
 function GetFriendsPage(PageNum, url){
    var hidPrevPageNum = document.getElementById('hidPrevPageNum');
    hidPrevPageNum.value = PageNum;
    
    ChangeSearchPage(url);
 }
 
 function SubmitMobileEntryReview(RecipientAccountProfileId, ContentId, ContentTypeLookupId, IsReview, GroupProfileId, txtCommentId, postedReviewId, AddcommentEditorBoxId, strCouponPath, strCouponText, SiteContestId)
 {

    if(!bConfirmedFlag) {
		return;
	}
	bConfirmedFlag = false;
	
	var text = '';
	
    text = document.getElementById(txtCommentId).value;
   	
    // check empty text or default text
    if(!text || text.lenght == 0 || (IsReview && (text.indexOf(GetLeaveConstructiveReview()) >= 0))){
	    document.getElementById('AddcommentErrorText').style.display = '';
		return;
	}
	
	// rating
	var hiddenRate = document.getElementById('hiddenRate');
	var iRatingValue = -1;
	if(hiddenRate){
		iRatingValue = parseInt(hiddenRate.value);
	}
	
	if(isNaN(iRatingValue))
		iRatingValue = -1;
    
    var editor = document.getElementById(AddcommentEditorBoxId);
    editor.style.display = 'none';
    
    
    // stars
    var stars = '';
    if(IsReview && iRatingValue>0) {
		stars = '<table cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\"><div style=\"background-image:url({1});background-repeat:repeat-x;width:{0}px;height:20px;\">&nbsp;</div></td></tr></table>';
		stars = stars.replace('{0}',iRatingValue * 20);
		stars = stars.replace('{1}', '/Media/Images/general/star_one.gif');
    }
    
	var newDiv = document.createElement('div');
	
	// Review or Comment
	var strReviewOrComment = '';
	var imgGuest = '';
	if(IsReview)
	{
		imgGuest = '<img id="imgPostedByGuest" style="border: 1px solid black;display:none" ALIGN=MIDDLE src="http://highedge.vo.llnwd.net/d1/3_prod/d1/Picture/02.jpg" width=40 height=40 />&nbsp;&nbsp;';
    
		strReviewOrComment = '<div class=\'mobiletext\' style=\'font-weight:bold;color:black;\'>' + ST_ThankYouForReview();
		
		strReviewOrComment += '</div>';
	}
	else
		strReviewOrComment = '<div class=\'mobiletext\' style=\'font-weight:bold\'>Thank You For Your Comment</div>';
		
	// Adding star and review/comment to the new div which will be inserted back to the page.
    newDiv.innerHTML = strReviewOrComment + '<br>' + stars + imgGuest + text;


    //Put the review text back to the page
    var postedReview = document.getElementById(postedReviewId);
    postedReview.appendChild(newDiv);
    
	AJAX.SaveMobileEntryComment(RecipientAccountProfileId, text, iRatingValue, ContentId, ContentTypeLookupId, IsReview, GroupProfileId, SiteContestId, SaveEntryComment_Callback, postedReviewId);
 }
 
 // Many related JS functions are in AddComment.ascx.  For review, this function is called from CheckReview()
 function SubmitEntryReview(RecipientAccountProfileId, ContentId, ContentTypeLookupId, IsReview, 
	GroupProfileId, txtCommentId, postedReviewId, AddcommentEditorBoxId, 
	strCouponPath, strCouponText, SiteContestId, iParentCommentId){

	if(!bConfirmedFlag) {
		return;
	}
	bConfirmedFlag = false;
	
	var text = '';
	var isGuest = false;
	
	var editors = GetEditorsId(); // any page with editor should insert a js function to return an array of editor ids. 
	
	if(!editors) return false;
	
    for (var i=0; i < editors.length; i++)
    {
		var oEditor = FCKeditorAPI.GetInstance(editors[i] + '_ucEditorBase_fckEditor');
		if (oEditor)
		{
			text = oEditor.GetHTML();
		}
    }
    
    if (text.length == 0 && txtCommentId.length > 0)
    {
		text = document.getElementById(txtCommentId).value;
		isGuest = true;
    }
    
	
    // check empty text or default text
    if(!text || text.length == 0 || (IsReview && (text.indexOf(GetLeaveConstructiveReview()) >= 0))){
	    document.getElementById('AddcommentErrorText').style.display = '';
		return;
	}
	
	// rating
	var hiddenRate = document.getElementById('hiddenRate');
	var iRatingValue = -1;
	if(hiddenRate){
		iRatingValue = parseInt(hiddenRate.value);
	}
	
	if(isNaN(iRatingValue))
		iRatingValue = -1;
    
    var editor = document.getElementById(AddcommentEditorBoxId);
    editor.style.display = 'none';
    
    
    // stars
    var stars = '';
    if(IsReview && iRatingValue>0) {
		stars = '<table cellspacing=\"0\" cellpadding=\"0\"><tr><td align=\"left\"><div style=\"background-image:url({1});background-repeat:repeat-x;width:{0}px;height:20px;\">&nbsp;</div></td></tr></table>';
		stars = stars.replace('{0}',iRatingValue * 20);
		stars = stars.replace('{1}', '/Media/Images/general/star_one.gif');
    }
    
	var newDiv = document.createElement('div');
	
	// Review or Comment
	var strReviewOrComment = '';
	var imgGuest = '';
	if(IsReview)
	{
		imgGuest = '<img id="imgPostedByGuest' + postedReviewId + '" style="border: 1px solid black;display:none" ALIGN=MIDDLE src="http://highedge.vo.llnwd.net/d1/3_prod/d1/Picture/02.jpg" width=40 height=40 />&nbsp;&nbsp;';
    
		strReviewOrComment = '<div class=\'plaintext_bold\'>' + ST_ThankYouForReview();
		if (strCouponPath && strCouponPath.length > 0)
		{
			var strText = 'Click here to receive a special incentive for this campaign.';
			if (strCouponText && strCouponText.length > 0)
			{
				strText = strCouponText
			}
			strReviewOrComment += '<br>' + '<a style=\'color:#003399\' href="javascript:openpopup(\'' + strCouponPath + '\', \'Coupon\', 800, 600)">' + strText + '</a>';
		}
		strReviewOrComment += '</div>';
	}
	else
		strReviewOrComment = '<div class=\'plaintext_bold\'>Thank You For Your Comment</div>';
		
	// Adding star and review/comment to the new div which will be inserted back to the page.
    newDiv.innerHTML = strReviewOrComment + '<br>' + stars + imgGuest + text;


	if(!IsReview)
		newDiv.innerHTML += '<div class=\'plaintext\'><br>(Note: Some users require comment approval before posting so your comment may not display on the profile page right away.)</div>'

    //Put the review text back to the page
    var postedReview = document.getElementById(postedReviewId);
    postedReview.appendChild(newDiv);
    
	// Reset the editor dirty state so clicking on something else won't trigger an error message
    for (var i=0; i < editors.length; i++)
    {
		var oEditor = FCKeditorAPI.GetInstance(editors[i] + '_ucEditorBase_fckEditor');
		if (oEditor)
		{
			oEditor.ResetIsDirty();
		}
    }

	AJAX.SaveEntryComment(RecipientAccountProfileId, text, iRatingValue, ContentId, ContentTypeLookupId, IsReview, GroupProfileId, SiteContestId, iParentCommentId, SaveEntryComment_Callback, postedReviewId);
 }
 
 function SaveEntryComment_Callback(response){
    var postedReviewId = response.context;
    var postedReview = document.getElementById(postedReviewId);
    postedReview.style.display = '';
    var bIsGuest = response.value;
    
    if(bIsGuest){
		document.getElementById('imgPostedByGuest' + postedReviewId).style.display = '';
    }
 }
 
 function Vote(SiteContestId, SiteContestSubmissionId, ContentId, ContentAuthorAccountProfileId, ContentTypeLookupId,
	divVoteId, divVotedReplyId, bIsFromPlayer){//, strCouponPath){
    
    // hide the button
    var divVote = document.getElementById(divVoteId);
    divVote.style.display = 'none';
    
	AJAX.Vote(SiteContestId, SiteContestSubmissionId, ContentId, ContentAuthorAccountProfileId, ContentTypeLookupId, bIsFromPlayer, Vote_Callback, divVotedReplyId);
}

function MobileVote(SiteContestId, SiteContestSubmissionId, ContentId, ContentAuthorAccountProfileId, ContentTypeLookupId,
	divVoteId, divVotedReplyId, bIsFromPlayer){//, strCouponPath){
    
    // hide the button
    var divVote = document.getElementById(divVoteId);
    divVote.style.display = 'none';
    
	AJAX.MobileVote(SiteContestId, SiteContestSubmissionId, ContentId, ContentAuthorAccountProfileId, ContentTypeLookupId, bIsFromPlayer, Vote_Callback, divVotedReplyId);
}

function Vote_Callback(response){
    var divVotedReplyId = response.context;
    var divVotedReply = document.getElementById(divVotedReplyId); // say thank you
  
	$(divVotedReplyId).show();

	if($('panelSubmittedBy') && $('panelContent'))
	{
		setTall('panelSubmittedBy','panelContent');
	}
 
    var bIsGuest = response.value;

    if(bIsGuest){
		document.getElementById('spanAsGuest').style.display = '';
    }
}

function GetTimeZone(txtTZFieldId)
{
	if (txtTZFieldId && txtTZFieldId.length > 0)
	{
		var txtTZField = document.getElementById(txtTZFieldId);
		if (txtTZField)
		{
			txtTZField.value = new Date().getTimezoneOffset();
		}
	}
}

function SetFocus(FocusElementId)
{
	if (FocusElementId)
	{
		var FocusElement = document.getElementById(FocusElementId);
		if (FocusElement)
		{
			FocusElement.focus();
		}
	}
}

function UpdateInnerText(element, sText)
{
	if (element)
	{
		if (typeof element.textContent != "undefined")
		{
			element.textContent = sText;
		}
		else
		{
			element.innerText = sText;
		}
	}
}
function CheckMaxLength(e,ctl,max) 
{
    switch(e.keyCode) {
        case 37: // left
        return true;
        case 38: // up
        return true;
        case 39: // right
        return true;
        case 40: // down
        return true;
        case 8: // backspace
        return true;
        case 46: // delete
        return true;
        case 27: // escape
        ctl.value='';
        return true;
    }
    return (ctl.value.length < max);
}

function MoveItemToTop(strItemId)
{
	var oHidMoveToTop = document.getElementById('hiddenMoveToTop');
	if (oHidMoveToTop)
	{
		oHidMoveToTop.value = strItemId;
		document.forms[0].submit();
	}
}

function LoginToVote(divVoteId, divVoteMessageId, divLogin2VoteMsgId )
{
    var divVote = document.getElementById(divVoteId);
    var divVoteMessage = document.getElementById(divVoteMessageId);
    var divLogin2VoteMsg = document.getElementById(divLogin2VoteMsgId);
    
    if (divVote && divVoteMessage && divLogin2VoteMsg)
    {
        ShowLogin();
        divVote.style.display = "none";
        divVoteMessage.style.display = "";
        divLogin2VoteMsg.style.display = "";
    }
}

function IsEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
		return true;
	else
	return false;
}

/* mseaman
*****************
** CheckForm() **
***********************************************************************************************************************************************
** Used for Email Opt in for a client. The following html usually goes into the Campaign Highlights field in the CC.
** Records go into the SiteContestEmail table. All fields are required by default.
**
** The following is the standard html that goes into the Campaign Highlights (BE SURE TO CHANGE THE txtUrl "scid" and "curl" VALUES!). 
** Notice that Age is hidden:
***********************************************************************************************************************************************
<table border="0">
    <tbody>
        <tr>
            <td>First Name:</td>
            <td><input name="fname" type="text" /></td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td><input name="lname" type="text" /></td>
        </tr>
        <tr>
            <td>
				Email:<input id="txtAge" type="hidden" value="99" />
				
				
				<!-- CHANGE THESE VALUES -->
				<input id="txtUrl" type="hidden" name="txtUrl" value="/Pages/Comps/EmailOptIn.aspx?scid=189&amp;curl=/politics/pawsconnect_vote" />
				
				
			</td>
            <td><input id="txtEmail" name="Email" type="text" />&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>{SubmitLinkBegin}<img alt="" src="/Media/Images/general/buttons/b_submit_1state.gif" />{SubmitLinkEnd}</td>
        </tr>
        <tr>
            <td colspan="2">
				&nbsp;<span id="invalidFname" style="display: none; margin-left: 5px; color: red">Please enter your first name.</span><br>
				<span id="invalidLname" style="display: none; margin-left: 5px; color: red">Please enter your last name.</span><br>
				<span id="invalidAge" style="display: none; margin-left: 5px; color: red">Please enter a valid age.</span>
				<span id="invalidEmail" style="display: none; margin-left: 5px; color: red">Please enter a valid email address. </span>
			</td>
        </tr>
    </tbody>
</table>
***********************************************************************************************************************************************
** The following example has first name (fname) acting as full name and last name is set as NOT REQUIRED (see the lnameReq field).
** This example also has Age as a hidden field with a default of 99 (this method is obsolete, but affective).
** This example also has multiple checkboxes for managing opt in to multiple lists
** If you wanted to SHOW Age, but make it optional, you could add <input id="txtAgeReq" type="hidden" value="0" /> 
** to allow the user to input age or not.  Similarly, you can use fnameReq, lnameReq, and emailReq to make the corresponding fields optional.
** Exercise: rewrite the following code to use txtAgeReq instead of defaulting to 99:
***********************************************************************************************************************************************
<table border="0">
    <tbody>
        <tr>
            <td>Full Name:</td>
            <td>
				<input name="fname" type="text" />
				<input type="hidden" name="lname" />
				<input id="lnameReq" type="hidden" value="0" />
			</td>
        </tr>
        <tr>
            <td>
				Email:<input id="txtAge" type="hidden" name="age" value="99" />


				<!-- CHANGE THESE VALUES -->
				<input id="txtUrl" type="hidden" name="txtUrl" value="/Pages/Comps/EmailOptIn.aspx?scid=245&amp;curl=/fashion/SaksTheory" />

				
			</td>
            <td><input id="txtEmail" name="Email" type="text" />&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2"><input id="chkListNum_1" type="checkbox" checked="checked" name="chkListNum_1" value="on" /> list number 1 <br />
            <input id="chkListNum_2" type="checkbox" checked="checked" name="chkListNum_2" value="on" /> list number 2</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>{SubmitLinkBegin}<img alt="" src="/Media/Images/general/buttons/b_submit_1state.gif" />{SubmitLinkEnd}</td>
        </tr>
        <tr>
            <td colspan="2">
				&nbsp;<span id="invalidFname" style="display: none; margin-left: 5px; color: red">Please enter your full name.</span><br>
				<span id="invalidLname" style="display: none; margin-left: 5px; color: red">&nbsp;</span>
				<span id="invalidAge" style="display: none; margin-left: 5px; color: red">Please enter a valid age.</span>
				<span id="invalidEmail" style="display: none; margin-left: 5px; color: red">Please enter a valid email address.</span>
				<span id="invalidListNumChks" style="display: none; margin-left: 5px; color: red">Please check at least one of the choices.</span>
			</td>
        </tr>
    </tbody>
</table>
***********************************************************************************************************************************************
** The following example has DOB as an optional field.
** This example also has Age as a hidden field with a default of 99.
***********************************************************************************************************************************************
<table border="0">
    <tbody>
        <tr>
            <td>First Name:</td>
            <td><input name="fname" type="text" size="30" /></td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td><input name="lname" type="text" size="30" /></td>
        </tr>
        <tr>
            <td>DOB:</td>
            <td>
				<input type="hidden" id="DOBReq" value="0" />
				<select id="ddMonth" name="ddMonth" onchange="CheckDate('ddMonth', 'ddDay', 'ddYear');">
					<option value="0">Month</option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<option value="8">8</option>
					<option value="9">9</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
				</select>
				<select id="ddDay" name="ddDay">
					<option value="0">Day</option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<option value="8">8</option>
					<option value="9">9</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
					<option value="13">13</option>
					<option value="14">14</option>
					<option value="15">15</option>
					<option value="16">16</option>
					<option value="17">17</option>
					<option value="18">18</option>
					<option value="19">19</option>
					<option value="20">20</option>
					<option value="21">21</option>
					<option value="22">22</option>
					<option value="23">23</option>
					<option value="24">24</option>
					<option value="25">25</option>
					<option value="26">26</option>
					<option value="27">27</option>
					<option value="28">28</option>
					<option value="29">29</option>
					<option value="30">30</option>
					<option value="31">31</option>
				</select>
				<select id="ddYear" name="ddYear">
					<option value="0">Year</option>
					<option value="2007">2007</option>
					<option value="2006">2006</option>
					<option value="2005">2005</option>
					<option value="2004">2004</option>
					<option value="2003">2003</option>
					<option value="2002">2002</option>
					<option value="2001">2001</option>
					<option value="2000">2000</option>
					<option value="1999">1999</option>
					<option value="1998">1998</option>
					<option value="1997">1997</option>
					<option value="1996">1996</option>
					<option value="1995">1995</option>
					<option value="1994">1994</option>
					<option value="1993">1993</option>
					<option value="1992">1992</option>
					<option value="1991">1991</option>
					<option value="1990">1990</option>
					<option value="1989">1989</option>
					<option value="1988">1988</option>
					<option value="1987">1987</option>
					<option value="1986">1986</option>
					<option value="1985">1985</option>
					<option value="1984">1984</option>
					<option value="1983">1983</option>
					<option value="1982">1982</option>
					<option value="1981">1981</option>
					<option value="1980">1980</option>
					<option value="1979">1979</option>
					<option value="1978">1978</option>
					<option value="1977">1977</option>
					<option value="1976">1976</option>
					<option value="1975">1975</option>
					<option value="1974">1974</option>
					<option value="1973">1973</option>
					<option value="1972">1972</option>
					<option value="1971">1971</option>
					<option value="1970">1970</option>
					<option value="1969">1969</option>
					<option value="1968">1968</option>
					<option value="1967">1967</option>
					<option value="1966">1966</option>
					<option value="1965">1965</option>
					<option value="1964">1964</option>
					<option value="1963">1963</option>
					<option value="1962">1962</option>
					<option value="1961">1961</option>
					<option value="1960">1960</option>
					<option value="1959">1959</option>
					<option value="1958">1958</option>
					<option value="1957">1957</option>
					<option value="1956">1956</option>
					<option value="1955">1955</option>
					<option value="1954">1954</option>
					<option value="1953">1953</option>
					<option value="1952">1952</option>
					<option value="1951">1951</option>
					<option value="1950">1950</option>
					<option value="1949">1949</option>
					<option value="1948">1948</option>
					<option value="1947">1947</option>
					<option value="1946">1946</option>
					<option value="1945">1945</option>
					<option value="1944">1944</option>
					<option value="1943">1943</option>
					<option value="1942">1942</option>
					<option value="1941">1941</option>
					<option value="1940">1940</option>
					<option value="1939">1939</option>
					<option value="1938">1938</option>
					<option value="1937">1937</option>
					<option value="1936">1936</option>
					<option value="1935">1935</option>
					<option value="1934">1934</option>
					<option value="1933">1933</option>
					<option value="1932">1932</option>
					<option value="1931">1931</option>
					<option value="1930">1930</option>
					<option value="1929">1929</option>
					<option value="1928">1928</option>
					<option value="1927">1927</option>
					<option value="1926">1926</option>
					<option value="1925">1925</option>
					<option value="1924">1924</option>
					<option value="1923">1923</option>
					<option value="1922">1922</option>
					<option value="1921">1921</option>
					<option value="1920">1920</option>
					<option value="1919">1919</option>
					<option value="1918">1918</option>
					<option value="1917">1917</option>
					<option value="1916">1916</option>
					<option value="1915">1915</option>
					<option value="1914">1914</option>
					<option value="1913">1913</option>
					<option value="1912">1912</option>
					<option value="1911">1911</option>
					<option value="1910">1910</option>
					<option value="1909">1909</option>
					<option value="1908">1908</option>
					<option value="1907">1907</option>
					<option value="1906">1906</option>
					<option value="1905">1905</option>
					<option value="1904">1904</option>
					<option value="1903">1903</option>
					<option value="1902">1902</option>
					<option value="1901">1901</option>
					<option value="1900">1900</option>
				</select><input id="txtAge" type="hidden" name="age" value="99" />
			</td>
        </tr>
        <tr>
            <td>Email:<input id="txtUrl" type="hidden" name="txtUrl" value="/Pages/Comps/EmailOptIn.aspx?scid=258&amp;curl=/sports/surfjunk" /></td>
            <td><input id="txtEmail" name="Email" type="text" size="30" />&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>{SubmitLinkBegin}<img alt="" src="/Media/Images/general/buttons/b_submit_1state.gif" />{SubmitLinkEnd}</td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;<span id="invalidFname" style="display: none; margin-left: 5px; color: red"> Please enter your first name.<br />
            </span><span id="invalidLname" style="display: none; margin-left: 5px; color: red">Please enter your last name.<br />
            </span><span id="invalidAge" style="display: none; margin-left: 5px; color: red">Please enter a valid age.<br />
            </span><span id="invalidDOB" style="display: none; margin-left: 5px; color: red">Please enter a valid Date of Birth.<br />
            </span><span id="invalidEmail" style="display: none; margin-left: 5px; color: red">Please enter a valid email address. </span></td>
        </tr>
    </tbody>
</table>
***********************************************************************************************************************************************
** If you have to put the Email-Opt-In in two places on the same page (for example, the Campaign Highlights and the Enhanced area),
** you can use CheckForm2() - see below for more info.
***********************************************************************************************************************************************
*/
function CheckForm()
{
	var aForm=document.forms[0];
	var strInvalidFname = "invalidFname";
	var strInvalidLname = "invalidLname";
	var strInvalidEmail = "invalidEmail";
	var strInvalidAge = "invalidAge";
	var strInvalidDOB = "invalidDOB";
	var strInvalidListNumChecks = "invalidListNumChks";
	
	var ctlfname = aForm.fname;
	var ctllname = aForm.lname;
	var ctltxtAge = aForm.txtAge;
	var ctlddMonth = aForm.ddMonth;
	var ctlddDay = aForm.ddDay;
	var ctlddYear = aForm.ddYear;
	var ctltxtEmail = aForm.txtEmail;
	var ctltxtUrl = aForm.txtUrl;
	
	var hidfnameReq = document.getElementById("fnameReq");
	var hidlnameReq = document.getElementById("lnameReq");
	var hidtxtEmailReq = document.getElementById("txtEmailReq");
	var hidtxtAgeReq = document.getElementById("txtAgeReq");
	var hidDOBReq = document.getElementById("DOBReq");
	
	var strChkListNum = "chkListNum_";
	
	CheckFormWithParams(strInvalidFname, strInvalidLname, strInvalidEmail, strInvalidAge, strInvalidDOB, strInvalidListNumChecks,
						ctlfname, ctllname, ctltxtAge, ctlddMonth, ctlddDay, ctlddYear, ctltxtEmail, ctltxtUrl, 
						hidfnameReq, hidlnameReq, hidtxtEmailReq, hidtxtAgeReq, hidDOBReq, strChkListNum);
}

function CheckFormWithParams(strInvalidFname, strInvalidLname, strInvalidEmail, strInvalidAge, strInvalidDOB, strInvalidListNumChecks,
						ctlfname, ctllname, ctltxtAge, ctlddMonth, ctlddDay, ctlddYear, ctltxtEmail, ctltxtUrl, 
						hidfnameReq, hidlnameReq, hidtxtEmailReq, hidtxtAgeReq, hidDOBReq, strChkListNum) 
{
	var bfnameReq = true;
	var blnameReq = true;
	var btxtEmailReq = true;
	var btxtAgeReq = true;
	var bDOBReq = true;

	if (hidfnameReq)
	{
		bfnameReq = hidfnameReq.value == "1";
	}
	if (hidlnameReq)
	{
		blnameReq = hidlnameReq.value == "1";
	}
	if (hidtxtEmailReq)
	{
		btxtEmailReq = hidtxtEmailReq.value == "1";
	}
	if (hidtxtAgeReq)
	{
		btxtAgeReq = hidtxtAgeReq.value == "1";
	}
	if (hidDOBReq)
	{
		bDOBReq = hidDOBReq.value == "1";
	}
	
	var hasError = false;

	if (ctltxtEmail.value.length == 0)
	{
		if (btxtEmailReq)
		{
			document.getElementById(strInvalidEmail).style.display = '';
			hasError = true;
		}
		else
		{
			document.getElementById(strInvalidEmail).style.display = 'none';
		}
	}
	else if (!IsEmail(ctltxtEmail.value))
	{
		document.getElementById(strInvalidEmail).style.display = '';
		hasError = true;
	}
	else 
	{
		document.getElementById(strInvalidEmail).style.display = 'none';
	}
	
	if ((ctlfname.value.length == 0 || ctlfname.value.replace(/\s/g, '').length == 0) && bfnameReq)
	{
		document.getElementById(strInvalidFname).style.display = '';	
		hasError = true;	
	}
	else 
	{
		document.getElementById(strInvalidFname).style.display = 'none';
	}
	if ((ctllname.value.length == 0 || ctllname.value.replace(/\s/g, '').length == 0) && blnameReq)
	{
		document.getElementById(strInvalidLname).style.display = '';	
		hasError = true;	
	}
	else 
	{
		document.getElementById(strInvalidLname).style.display = 'none';	
	}
		
		
	if (ctltxtAge.value.length > 0 && ctltxtAge.value.replace(/\s/g, '').length > 0)
	{
		if(isNaN(ctltxtAge.value))
		{
			document.getElementById(strInvalidAge).style.display = '';
			hasError = true;
		}
		else if(parseInt(ctltxtAge.value) < 1 || parseInt(ctltxtAge.value) > 120)
		{
			document.getElementById(strInvalidAge).style.display = '';
			hasError = true;
		}
		else 
		{
			document.getElementById(strInvalidAge).style.display = 'none';
		}
	}
	else 
	{
		if (btxtAgeReq)
		{
			document.getElementById(strInvalidAge).style.display = '';
			hasError = true;
		}
	}
	
	if (ctlddMonth && ctlddDay && ctlddYear)
	{
		alert(ctlddMonth);
		if (ctlddMonth.value == "0" || ctlddDay.value == "0" || ctlddYear.value == "0")
		{
			if (bDOBReq)
			{
				document.getElementById(strInvalidDOB).style.display = '';
				hasError = true;
			}
		}
		else
		{
			document.getElementById(strInvalidDOB).style.display = 'none';
		}
	}

	var numList = 1;
	var chk = document.getElementById(strChkListNum + numList);
	var strListNums = "";
	
	if (chk)
	{
		while(chk)
		{
			if (chk.checked)
			{
				if (strListNums.length > 0)
				{
					strListNums += "|";
				}
				
				strListNums = strListNums + numList;
			}

			numList++;
			chk = document.getElementById(strChkListNum + numList);
		}
	}
	else
	{
		strListNums = "1";
	}
	
	if (document.getElementById(strInvalidListNumChecks))
	{
		if (strListNums.length == 0)
		{
			document.getElementById(strInvalidListNumChecks).style.display = '';
			hasError = true;
		}
		else
		{
			document.getElementById(strInvalidListNumChecks).style.display = 'none';
		}
	}
	
	if (!hasError)
	{
		strAgeValues = '';
		if (ctlddMonth && ctlddDay && ctlddYear)
		{
			strAgeValues = '&m=' + ctlddMonth.value + '&d=' + ctlddDay.value + '&y=' + ctlddYear.value;
		}
		document.location = ctltxtUrl.value + '&fname=' + ctlfname.value + '&email=' + ctltxtEmail.value + '&age=' + ctltxtAge.value + strAgeValues + '&lname=' + ctllname.value + '&lnums=' + strListNums;
	}
}

/*
<table border="0">
    <tbody>
        <tr>
            <td>First Name:</td>
            <td><input name="fname2" type="text" /></td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td><input name="lname2" type="text" /></td>
        </tr>
        <tr>
            <td>
				Email:<input id="txtAge2" type="hidden" name="age" value="99" />
				
				
				<!-- CHANGE THESE VALUES -->
				<input id="txtUrl2" type="hidden" name="txtUrl2" value="/Pages/Comps/EmailOptIn.aspx?scid=189&amp;curl=/politics/pawsconnect_vote" />
				
				
			</td>
            <td><input id="txtEmail2" name="Email" type="text" />&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>{SubmitLinkBegin2}<img alt="" src="/Media/Images/general/buttons/b_submit_1state.gif" />{SubmitLinkEnd2}</td>
        </tr>
        <tr>
            <td colspan="2">
				&nbsp;<span id="invalidFname2" style="display: none; margin-left: 5px; color: red"> Please enter your first name.</span><br>
				<span id="invalidLname2" style="display: none; margin-left: 5px; color: red">Please enter your last name.</span><br>
				<span id="invalidAge2" style="display: none; margin-left: 5px; color: red">Please enter a valid age.</span>
				<span id="invalidEmail2" style="display: none; margin-left: 5px; color: red">Please enter a valid email address. </span>
			</td>
        </tr>
    </tbody>
</table>
***********************************************************************************************************************************************
** An example with DOB:
***********************************************************************************************************************************************
<table border="0">
    <tbody>
        <tr>
            <td>First Name:</td>
            <td><input size="30" name="fname2" type="text" /></td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td><input size="30" name="lname2" type="text" /></td>
        </tr>
        <tr>
            <td>DOB:</td>
            <td><input id="DOBReq2" type="hidden" value="0" /> <select id="ddMonth2" onchange="CheckDate('ddMonth2', 'ddDay2', 'ddYear2');" name="ddMonth2">
            <option value="0" selected="selected">Month</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            <option value="10">10</option>
            <option value="11">11</option>
            <option value="12">12</option>
            </select> <select id="ddDay2" name="ddDay2">
            <option value="0" selected="selected">Day</option>
            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="5">5</option>
            <option value="6">6</option>
            <option value="7">7</option>
            <option value="8">8</option>
            <option value="9">9</option>
            <option value="10">10</option>
            <option value="11">11</option>
            <option value="12">12</option>
            <option value="13">13</option>
            <option value="14">14</option>
            <option value="15">15</option>
            <option value="16">16</option>
            <option value="17">17</option>
            <option value="18">18</option>
            <option value="19">19</option>
            <option value="20">20</option>
            <option value="21">21</option>
            <option value="22">22</option>
            <option value="23">23</option>
            <option value="24">24</option>
            <option value="25">25</option>
            <option value="26">26</option>
            <option value="27">27</option>
            <option value="28">28</option>
            <option value="29">29</option>
            <option value="30">30</option>
            <option value="31">31</option>
            </select> <select id="ddYear2" name="ddYear2">
            <option value="0" selected="selected">Year</option>
            <option value="2007">2007</option>
            <option value="2006">2006</option>
            <option value="2005">2005</option>
            <option value="2004">2004</option>
            <option value="2003">2003</option>
            <option value="2002">2002</option>
            <option value="2001">2001</option>
            <option value="2000">2000</option>
            <option value="1999">1999</option>
            <option value="1998">1998</option>
            <option value="1997">1997</option>
            <option value="1996">1996</option>
            <option value="1995">1995</option>
            <option value="1994">1994</option>
            <option value="1993">1993</option>
            <option value="1992">1992</option>
            <option value="1991">1991</option>
            <option value="1990">1990</option>
            <option value="1989">1989</option>
            <option value="1988">1988</option>
            <option value="1987">1987</option>
            <option value="1986">1986</option>
            <option value="1985">1985</option>
            <option value="1984">1984</option>
            <option value="1983">1983</option>
            <option value="1982">1982</option>
            <option value="1981">1981</option>
            <option value="1980">1980</option>
            <option value="1979">1979</option>
            <option value="1978">1978</option>
            <option value="1977">1977</option>
            <option value="1976">1976</option>
            <option value="1975">1975</option>
            <option value="1974">1974</option>
            <option value="1973">1973</option>
            <option value="1972">1972</option>
            <option value="1971">1971</option>
            <option value="1970">1970</option>
            <option value="1969">1969</option>
            <option value="1968">1968</option>
            <option value="1967">1967</option>
            <option value="1966">1966</option>
            <option value="1965">1965</option>
            <option value="1964">1964</option>
            <option value="1963">1963</option>
            <option value="1962">1962</option>
            <option value="1961">1961</option>
            <option value="1960">1960</option>
            <option value="1959">1959</option>
            <option value="1958">1958</option>
            <option value="1957">1957</option>
            <option value="1956">1956</option>
            <option value="1955">1955</option>
            <option value="1954">1954</option>
            <option value="1953">1953</option>
            <option value="1952">1952</option>
            <option value="1951">1951</option>
            <option value="1950">1950</option>
            <option value="1949">1949</option>
            <option value="1948">1948</option>
            <option value="1947">1947</option>
            <option value="1946">1946</option>
            <option value="1945">1945</option>
            <option value="1944">1944</option>
            <option value="1943">1943</option>
            <option value="1942">1942</option>
            <option value="1941">1941</option>
            <option value="1940">1940</option>
            <option value="1939">1939</option>
            <option value="1938">1938</option>
            <option value="1937">1937</option>
            <option value="1936">1936</option>
            <option value="1935">1935</option>
            <option value="1934">1934</option>
            <option value="1933">1933</option>
            <option value="1932">1932</option>
            <option value="1931">1931</option>
            <option value="1930">1930</option>
            <option value="1929">1929</option>
            <option value="1928">1928</option>
            <option value="1927">1927</option>
            <option value="1926">1926</option>
            <option value="1925">1925</option>
            <option value="1924">1924</option>
            <option value="1923">1923</option>
            <option value="1922">1922</option>
            <option value="1921">1921</option>
            <option value="1920">1920</option>
            <option value="1919">1919</option>
            <option value="1918">1918</option>
            <option value="1917">1917</option>
            <option value="1916">1916</option>
            <option value="1915">1915</option>
            <option value="1914">1914</option>
            <option value="1913">1913</option>
            <option value="1912">1912</option>
            <option value="1911">1911</option>
            <option value="1910">1910</option>
            <option value="1909">1909</option>
            <option value="1908">1908</option>
            <option value="1907">1907</option>
            <option value="1906">1906</option>
            <option value="1905">1905</option>
            <option value="1904">1904</option>
            <option value="1903">1903</option>
            <option value="1902">1902</option>
            <option value="1901">1901</option>
            <option value="1900">1900</option>
            </select><input id="txtAge2" type="hidden" name="age2" value="99" /></td>
        </tr>
        <tr>
            <td>Email:<input id="txtUrl2" type="hidden" name="txtUrl2" value="/Pages/Comps/EmailOptIn.aspx?scid=258&amp;curl=/sports/surfjunk" /></td>
            <td><input id="txtEmail2" size="30" name="Email2" type="text" />&nbsp;&nbsp;</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>{SubmitLinkBegin2}<img alt="" src="/Media/Images/general/buttons/b_submit_1state.gif" />{SubmitLinkEnd2}</td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;<span id="invalidFname2" style="display: none; margin-left: 5px; color: red"> Please enter your first name.<br />
            </span><span id="invalidLname2" style="display: none; margin-left: 5px; color: red">Please enter your last name.<br />
            </span><span id="invalidAge2" style="display: none; margin-left: 5px; color: red">Please enter a valid age.<br />
            </span><span id="invalidDOB2" style="display: none; margin-left: 5px; color: red">Please enter a valid Date of Birth.<br />
            </span><span id="invalidEmail2" style="display: none; margin-left: 5px; color: red">Please enter a valid email address. </span></td>
        </tr>
    </tbody>
</table>
*/
function CheckForm2(){
	
	var aForm=document.forms[0];
	var strInvalidFname = "invalidFname2";
	var strInvalidLname = "invalidLname2";
	var strInvalidEmail = "invalidEmail2";
	var strInvalidAge = "invalidAge2";
	var strInvalidDOB = "invalidDOB2";
	var strInvalidListNumChecks = "invalidListNumChks2";
	
	var ctlfname = aForm.fname2;
	var ctllname = aForm.lname2;
	var ctltxtAge = aForm.txtAge2;
	var ctlddMonth = aForm.ddMonth2;
	var ctlddDay = aForm.ddDay2;
	var ctlddYear = aForm.ddYear2;
	var ctltxtEmail = aForm.txtEmail2;
	var ctltxtUrl = aForm.txtUrl2;
	
	var hidfnameReq = document.getElementById("fnameReq2");
	var hidlnameReq = document.getElementById("lnameReq2");
	var hidtxtEmailReq = document.getElementById("txtEmailReq2");
	var hidtxtAgeReq = document.getElementById("txtAgeReq2");
	var hidDOBReq = document.getElementById("DOBReq2");
	
	var strChkListNum = "chkListNum2_";

	CheckFormWithParams(strInvalidFname, strInvalidLname, strInvalidEmail, strInvalidAge, strInvalidDOB, strInvalidListNumChecks,
						ctlfname, ctllname, ctltxtAge, ctlddMonth, ctlddDay, ctlddYear, ctltxtEmail, ctltxtUrl, 
						hidfnameReq, hidlnameReq, hidtxtEmailReq, hidtxtAgeReq, hidDOBReq, strChkListNum);	
}

function CheckDate(strMonth, strDay, strYear)
{
	var ddlMonth;
	var ddlDay;
	var ddlYear;
	var iNumDays = 31;
	var iPreviousDay = 0;
	var month = 0;
	var year = 0;
	
	ddlMonth = document.getElementById(strMonth);
	ddlDay = document.getElementById(strDay);
	ddlYear = document.getElementById(strYear);

	if (ddlMonth) month = ddlMonth.value;
	if (ddlYear) year = ddlYear.value;
	if (ddlDay) iPreviousDay = ddlDay.value;
	
	if (month == 2)
	{
		iNumDays = 28;
		if (year != 0 && CheckForLeapYear(year))
		{
			iNumDays = 29;
		}
	}
	else if (month == 4 || month == 6 || month == 9 || month == 11)
	{
		iNumDays = 30;
	} 
	LoadDays(iNumDays, ddlDay, iPreviousDay);
}
function CheckForLeapYear(iYearToTest)
{
	var result = 0;
	if ( (iYearToTest % 4) == 0)
	{
		if ( (iYearToTest % 100) == 0)
		{
			result = ( (iYearToTest % 400) == 0);
		}
		else
		{
			result = 1;
		}
	}
	else
	{
		result = 0;
	}
	return (result);
}
function LoadDays(iDaysInMonth, ddlElement, iSelectedDay)
{
	if (ddlElement && iDaysInMonth > 0)
	{
		// Clear the DDL
		for (var count = ddlElement.options.length - 1; count > -1; count--)
		{
			ddlElement.options[count] = null;
		}
		// Add the new options
		for (var i=0; i <= iDaysInMonth; i++)
		{
			if (i == 0)
			{
				var listItem = new Option("Day", 0,  false, false);
				ddlElement.options[ddlElement.options.length] = listItem;
			}
			else
			{
				var listItem = new Option(i, i,  false, false);
				ddlElement.options[ddlElement.options.length] = listItem;
			}
		}
		if (iSelectedDay <= iDaysInMonth)
		{
			ddlElement.value = iSelectedDay;
		}
    }
}
function InsertSWF(bIsFlashEnabled, strSWFPath, strId, iWidth, iHeight, strDisabledImagePath)
{
	if (bIsFlashEnabled)
	{
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + iWidth + '" height="' + iHeight + '" id="' + strId + '" align="middle">');
		document.write('<param name="allowScriptAccess" value="sameDomain" />');
		document.write('<param name="allowFullScreen" value="false" />');
		document.write('<param name="movie" value="' + strSWFPath + '" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><param name="bgcolor" value="#000000" /><embed src="' + strSWFPath + '" quality="high" wmode="transparent" bgcolor="#000000" width="' + iWidth + '" height="' + iHeight + '" name="' + strId + '" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
	}
	else
	{
		document.write('<img src="' + strDisabledImagePath + '" />');
	}
}

//This is for PoweredByBrickfish
var bIsIFrameButNotPBB = false;
try {
	if(String(parent.location).indexOf('PropagationMain') > 0 || String(parent.location).indexOf('SelectGlobalTheme') > 0)
		bIsIFrameButNotPBB = true;
}
catch(err){}
try {
	if(String(window.location).indexOf('notpbb') > 0)
		bIsIFrameButNotPBB = true;
}
catch(err){}
				
var IsPowerByBF = false;
function SetIfInIFrame()
{
	var pbb = GetCookie('pbb');
	
	if (parent != window) // in a frame
	{
		if(bIsIFrameButNotPBB) // prop
		{
			if (pbb != null && pbb != 'false') // previously has a "true" Powered by BF cookie
			{
				SetCookie('pbb', 'false');
				SetCookie('pbblocation', '/');
				//window.location = window.location;
			}
		}
		else if (pbb == null || pbb != 'true')
		{
			SetCookie('pbb', 'true');
			
			//initial location (campaign landing) is the new home page for PBB
			var pbbinitloc = GetCookie('pbbinitloc');
			if (pbbinitloc == null)
			{
				SetCookie('pbbinitloc', window.location);
				SetCookie('pbblocation', window.location);
			}
			else
			{
				SetCookie('pbblocation', pbbinitloc);
			}
			//window.location = window.location;
			IsPowerByBF = true;
		}
		else
		{
			IsPowerByBF = true;
		}
	}
	else
	{
		var scpbbsid = GetCookie('scpbbsid');
		var isFF3 = (navigator.userAgent.indexOf('Firefox/3.0.') != -1);
		var isUsingClientTraffic = (scpbbsid != null);
		//This fixes a firefox 3.0 issue where the browser doesn't think it's in an iframe.  
		//This fix should be ok since all windows in FF share the same session.
		//The code below is for IE when switching between windows/sessions.
		if ((pbb == null || (!window.opener && pbb != 'false') || bIsIFrameButNotPBB) && !(isFF3 && isUsingClientTraffic))
		{
			SetCookie('pbb', 'false');
			SetCookie('pbblocation', '/');
			//window.location = window.location;
		}
	}
}

function OpenInParent(url){
	if(bOpenInParent){
		if(parent != null){
			parent.location = url; 
		}
		else {
			window.location = url;
		}
	}
	else {
		window.location = url;
	}
}

function addMonths(date, numMonths)
{
    var year = 0;
	var month = 0;
	var day = 0;
	
	if (date.length > 0)
	{
		var iSlash1 = date.indexOf("/");
		var iSlash2 = date.indexOf("/", iSlash1 + 1);
		month = date.substring(0, iSlash1);
		day = date.substring(iSlash1+1, iSlash2);
		year = date.substring(iSlash2+1);
	}
				
	var iMonth = parseInt(month) + numMonths;
	var iYear = parseInt(year);
	if (iMonth == 13)
	{
		iMonth = 1;
		iYear = iYear + 1;
	}
	return iMonth + "/" + day + "/" + iYear;
	
}

// This function will set the browser's size regardless of the present of toolbar	
function SetBrowserSizeByClientArea(clientAreaWidth, clientAreaHeight, aWindow){
	if(aWindow){
		if (aWindow.document.all){
			cW=aWindow.document.body.offsetWidth
			cH=aWindow.document.body.offsetHeight
			aWindow.resizeTo(500,500)
			barsW=500-aWindow.document.body.offsetWidth
			barsH=500-aWindow.document.body.offsetHeight
			wW=barsW+cW
			wH=barsH+cH
			aWindow.resizeTo(wW,wH)
		}
		else
		{
			wW=window.outerWidth
			wH=window.outerHeight
		}
		toolbarW = wW - aWindow.document.documentElement.clientWidth;
		toolbarH = wH - aWindow.document.documentElement.clientHeight;
		aWindow.resizeTo(toolbarW + clientAreaWidth, toolbarH + clientAreaHeight);		
	}
	else {
		if (document.all){
			cW=document.body.offsetWidth
			cH=document.body.offsetHeight
			window.resizeTo(500,500)
			barsW=500-document.body.offsetWidth
			barsH=500-document.body.offsetHeight
			wW=barsW+cW
			wH=barsH+cH
			window.resizeTo(wW,wH)
		}
		else
		{
			wW=window.outerWidth
			wH=window.outerHeight
		}
		toolbarW = wW - document.documentElement.clientWidth;
		toolbarH = wH - document.documentElement.clientHeight;
		resizeTo(toolbarW + clientAreaWidth, toolbarH + clientAreaHeight);		
	}
}

// Copy from http://www.bennadel.com/blog/695-Ask-Ben-Getting-Query-String-Values-In-JavaScript.htm
function FindQSFromCurrURL(QSKey){
	 var objURL = new Object();
	  
	 // Use the String::replace method to iterate over each
	 // name-value pair in the query string. Location.search
	 // gives us the query string (if it exists).
	 window.location.search.toLowerCase().replace(
	 new RegExp( "([^?=&]+)(=([^&]*))?", "g" ),
	  
	 // For each matched query string pair, add that
	 // pair to the URL struct using the pre-equals
	 // value as the key.
	 function( $0, $1, $2, $3 ){
	 objURL[ $1 ] = $3;
	 }
	 );
	 
	 return objURL[QSKey.toLowerCase()];
}

function OpenAppendQS(URL, QSKeyName)
{
	var qs = FindQSFromCurrURL(QSKeyName);
	
	if(qs && qs.length > 0){
		if(URL.indexOf("?") < 0)
		{
			URL = URL + "?" + QSKeyName + "=" + qs;
		}
		else {
			URL = URL + "&" + QSKeyName + "=" + qs;
		}
	}
	
	window.location = URL;
}

function EncodeUrl(url){
	return escape(url).replace(new RegExp(/\'/g), '%27').replace(new RegExp(/x/g), 'x78').replace(new RegExp(/\%/g), 'x25').replace(new RegExp(/\//g), 'x252f');  
}

// Remove the http://domain
function RemoveDomainFromUrl(url){
	var strRelUrl = '';
	if(url.indexOf('http') == 0)  // starts with http
	{
		var iSlash = url.indexOf('/', 8);
		if(iSlash > 0){
			strRelUrl = url.substring(iSlash);
		}
		else {
			strRelUrl = '/';
		}
	}
	else {
		strRelUrl = url;
	}
	return strRelUrl;
}

function NavTop(strLoc)
{
	window.top.location = strLoc;
}

var m_bRequirePBBRedirect = false;

function ByPassPBBRedirect(url){
	if(parent != null){
		parent.location = url;
	}
	else {
		window.location = url;
	}
}

function PBBRedirect(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	if (targ.href && targ.href.indexOf('Canvas.aspx') < 0 && targ.href.indexOf('.png') < 0 && targ.href.indexOf('.gif') < 0 && targ.href.indexOf('.jpg') < 0 && targ.href.toLowerCase().indexOf('image.aspx') < 0 && targ.href.toLowerCase().indexOf('ByPassPBBRedirect') < 0) 
	{
		if(targ.target && targ.target.length > 0){
			// don't do anything. let it popup.
		}
		else {
			if (parent != null && targ.href.toLowerCase().indexOf('javascript:') < 0)
			{
				var strRelUrl = RemoveDomainFromUrl(targ.href);;					
				parent.location = GetPBBWrapper() + "=" + EncodeUrl(strRelUrl);
			}
		}
	}
	else {
		var targParent = targ.parentNode;
		if(targParent){
			if (targParent.href && targParent.href.indexOf('Canvas.aspx') < 0 && targParent.href.indexOf('.png') < 0 && targParent.href.indexOf('.gif') < 0 && targParent.href.indexOf('.jpg') < 0 && targParent.href.toLowerCase().indexOf('ByPassPBBRedirect') < 0)
			{
				if(targParent.target && targParent.target.length > 0){
					// don't do anything. let it popup.
				}
				else {
					if (parent != null && targParent.href.toLowerCase().indexOf('javascript:') < 0)
					{
						var strRelUrl = RemoveDomainFromUrl(targParent.href);;
						parent.location = GetPBBWrapper() + "=" + EncodeUrl(strRelUrl);
					}
				}
			}
		}
	}
}

function InitPBBRedirect(){
	m_bRequirePBBRedirect = true;
	// Forces links to parent window (out of iframe), if applicable
	if (document.captureEvents) 
	{
		document.captureEvents(Event.CLICK);
		document.onclick = PBBRedirect;
	}
	else
	{
		document.onclick = PBBRedirect;
	}
}

function TrimString(str)
{  while(str.charAt(0) == (" ") )
  {  str = str.substring(1);
  }
  while(str.charAt(str.length-1) == " " )
  {  str = str.substring(0,str.length-1);
  }
  return str;
}


// called from ContentViewer.ascx and CompConfirmation.ascx
var strCompressed_AddThis = '', strCompressed_Twitter = '', strCompressed_Facebook = '';

function PostToAddThis(FromLink, LinkToContent, iSCID, iContentId, objSrc){
	if(strCompressed_AddThis.length == 0)
	{
		var response = AJAX.CompressURL(LinkToContent);
		var strCompressed = response.value;
		// AJAX.TrackPageClick(FromLink + '-BKK Clicked', 'Bookmark', iSCID, iContentId);
		
		strCompressed_AddThis = strCompressed;
	}
	
    addthis_url =  strCompressed_AddThis; 
    return addthis_click(objSrc);
}

function PostToTwitter(FromLink, LinkToContent, iSCID, iContentId, strHashMark){
	if(strCompressed_Twitter.length == 0)
	{
		var response = AJAX.CompressURL(LinkToContent); // don't use callback because opening a popup window in a callback method would be blocked by a popup blocker.
		var strCompressed = response.value;
		// AJAX.TrackPageClick(FromLink + '-TWITTER Clicked', 'Twitter', iSCID, iContentId);
		
		strCompressed_Twitter = strCompressed;
	}
	
    openpopup('http://twitter.com/home?status= ' + escape(strCompressed_Twitter) + '%20' + strHashMark,'',630,530);
}

function PostToFacebook(FromLink, LinkToContent, iSCID, iContentId) {
	if(strCompressed_Facebook.length == 0)
	{
		var response = AJAX.CompressURL(LinkToContent); // don't use callback because opening a popup window in a callback method would be blocked by a popup blocker.
		var strCompressed = response.value;																		
		// AJAX.TrackPageClick(FromLink + '- FBPOST Clicked', 'Facebook', iSCID, iContentId);	
		
		strCompressed_Facebook = strCompressed;
	}
	
	u=strCompressed_Facebook;t=document.title;window.open('http://www.facebook.com/share.php?u='+encodeURIComponent(u),'sharer','toolbar=0,status=0,resizable=yes,width=820,height=436');
	return false;
}


// Only return true if it is in an iframe **AND** cookie disable.
function IsCookieDisabledInIFrame(){
	document.cookie = "Enabled=true";   
	var cookieValid = document.cookie;      
	if (cookieValid.indexOf("Enabled=true") == -1)   
	{
		if (parent != window) // in a frame
		{
			return true;
		}
		else {
			return false;
		}
	}
}


function GetPendingPurgeEntriesCount(){
	AJAX.GetPendingPurgeEntriesCount(GetPendingPurgeEntriesCount_Callback);
}

function GetPendingPurgeEntriesCount_Callback(response){
	var s = response.value;
	var lblPendingPurge = document.getElementById('lblPendingPurge');
	
	var d = new Date();
	var curr_time = d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds();
	
	lblPendingPurge.innerHTML = s;
	
	var lblLastUpdated = document.getElementById('lblLastUpdated');
	if(lblLastUpdated){
		lblLastUpdated.innerHTML = '(last updated at ' + curr_time + ')';
	}
	
	setTimeout('GetPendingPurgeEntriesCount()',30000);
}

function StartGetPendingPurgeEntriesCount(){
	setTimeout('GetPendingPurgeEntriesCount()',0000);
}

//
//  Remote Auth
//
// Set form flag and submit
function RemoteAuthSubmit()
{
	try
	{
		document.forms[0].action = GetPostBackUrl(); 
	}
	catch(e) {}
	var oRemoteAuth = document.getElementById( 'hiddenRemoteAuth' ) ;
	if (oRemoteAuth)
	{
		oRemoteAuth.value = "1";
	}
	document.forms[0].submit();
}

//
//  Remote Auth
//
// Simply refresh main window
var raTimer;
var raPopup;
var raCounter = 0;
var raInterval = 1000;
function raSetTimer()
{
	raCounter = 0;
	SetCookie('raRefresh', '');
	SetCookie('raSubmit', '');
	SetCookie('raGoToSignup', '');
	SetCookie('raCancel', '');
	
	var cookieRefresh = GetCookie('raRefresh');
	var cookieSubmit = GetCookie('raSubmit');
	var cookieGoToSignup = GetCookie('raGoToSignup');
	var cookieCancel = GetCookie('raCancel');
	
	//alert('raRefresh=' + cookieRefresh + ' raSubmit=' + cookieSubmit + ' raGoToSignup=' + cookieGoToSignup + ' setting timer...');
	
	clearTimeout(raTimer);
	raTimer = setTimeout('raTimerCallback()', raInterval);
}
function raTimerCallback()
{
	var cookieRefresh = GetCookie('raRefresh');
	var cookieSubmit = GetCookie('raSubmit');
	var cookieGoToSignup = GetCookie('raGoToSignup');
	var cookieCancel = GetCookie('raCancel');
	
	if (cookieRefresh != null && cookieRefresh == 'true')
	{
		//alert('refresh');
		SetCookie('raRefresh', '');
		window.location.reload();
	}
	else if (cookieSubmit != null && cookieSubmit == 'true')
	{
		//alert('submit');
		SetCookie('raSubmit', '');
		parent.RemoteAuthSubmit();
	}
	else if (cookieGoToSignup != null && cookieGoToSignup == 'true')
	{
		//alert('signup');
		SetCookie('raGoToSignup', '');
		RemoteAuthGoToSignup();
	}
	else if (cookieCancel != null && cookieCancel == 'true')
	{
		//alert('cancel');
		SetCookie('raCancel', '');
	}
	else //if (raCounter < 12) //60 seconds
	{
		//alert('raRefresh=' + cookieRefresh + ' raSubmit=' + cookieSubmit + ' raGoToSignup=' + cookieGoToSignup + ' setting timer...');
		raTimer = setTimeout('raTimerCallback()', raInterval);
		raCounter++;
	}
	//else
	//{
	//	alert('RA Timeout - this is for testing.  No longer polling for events.');
	//}
	
	/*if (raPopup.location && raPopup.location.href && raPopup.location.href.length > 0)
	{
		alert(raPopup.location);
		raTimer = setTimeout('raTimerCallback()', raInterval)
	}
	else
	{
		alert('gone');
	}*/	
}
function RemoteAuthRefresh()
{
	window.location.reload();
}

function RemoteAuthGoToSignup()
{
	window.location = '/Pages/MyAccount/CreateAccount.aspx';
}

function RemoveRemoteAuthSimple(id)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (confirm("Are you sure you no longer want to log in via this account?"))
		{
			oHidDelete.value = id;
			document.forms[0].submit();
		}
	}
}
function RemoveRemoteAuth(id)
{
	var oHidDelete = document.getElementById('hiddenDelete');
	if (oHidDelete)
	{
		if (confirm("Are you sure you no longer want to log in via this account?"))
		{
			oHidDelete.value = id + "_send";
			document.forms[0].submit();
		}
	}
}

function OpenRemoteAuthWindowSignup()
{
	if (parent != window) //in a frame
	{
		raPopup = openAndReturnPopup('/pages/RemoteAuth.aspx?rasignup=1&rasfa=1', 'RemoteAuth', 1024, 600);
		raSetTimer();
	}
	else
	{
		raPopup = openAndReturnPopup('/pages/RemoteAuth.aspx?rasignup=1', 'RemoteAuth', 1024, 600);
		raSetTimer();
	}
}

function OpenRemoteAuthWindow(qs)
{
	raPopup = openAndReturnPopup('/pages/RemoteAuth.aspx' + qs, 'RemoteAuth', 1024, 600);
	raSetTimer();
}
		function ShowLogin()
		{
			SetCookie('Enabled', 'true');
			var c = GetCookie('Enabled')
			if (c == null)
			{
				window.location = '/Pages/BrickfishLogin.aspx';
				return;
			}
			
			var bRedirectLogin = false;
			if(isIE && bRedirectLogin && (window.location.href.indexOf("tab=3") != -1 ||  window.location.href.indexOf("tab=submit") != -1)){
				var sDnsSafeHost = GetDnsSafeHost();
				var url = "http://" + sDnsSafeHost + '/Pages/BrickfishLogin.aspx?ReturnURL=' + escape(window.location);			
				window.location = url;
			}
			else {
				var divLoginModule = document.getElementById('divLoginModule');
				if (divLoginModule)
				{
					if (divLoginModule.style.display == "none")
					{
						if (document.documentElement.scrollTop > 0)
						{
							divLoginModule.style.top = document.documentElement.scrollTop.toString() + "px";
						}
						
						new Effect.SlideDown(divLoginModule.id, {duration: .7});
					}
				}
			}
		}
		function HideLogin()
		{
			var divLoginModule = document.getElementById('divLoginModule');
			if (divLoginModule)
			{
				new Effect.SlideUp(divLoginModule.id, {duration: .7});
			}
		}
function ShowPopDownBox(elementId)
{
	var element = document.getElementById(elementId);
	if (element)
	{
		if (element.style.display == "none")
		{
			if (document.documentElement.scrollTop > 0)
			{
				element.style.top = document.documentElement.scrollTop.toString() + "px";
			}

		    new Effect.SlideDown(element.id, {duration: .7});
		}
	}
}
function HidePopDownBox(elementId)
{
	var element = document.getElementById(elementId);
	if (element)
	{
		new Effect.SlideUp(element.id, {duration: .7});
	}
}
//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  
  str += 'style="z-index:1">';
  
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
/*
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This is the integration file for JavaScript.
 *
 * It defines the FCKeditor class that can be used to create editor
 * instances in a HTML page in the client side. For server side
 * operations, use the specific integration system.
 */

// FCKeditor Class
var FCKeditor = function( instanceName, width, height, toolbarSet, value )
{
	// Properties
	this.InstanceName	= instanceName ;
	this.Width			= width			|| '100%' ;
	this.Height			= height		|| '200' ;
	this.ToolbarSet		= toolbarSet	|| 'Default' ;
	this.Value			= value			|| '' ;
	this.BasePath		= FCKeditor.BasePath ;
	this.CheckBrowser	= true ;
	this.DisplayErrors	= true ;

	this.Config			= new Object() ;

	// Events
	this.OnError		= null ;	// function( source, errorNumber, errorDescription )
}

/**
 * This is the default BasePath used by all editor instances.
 */
FCKeditor.BasePath = '/fckeditor/' ;

/**
 * The minimum height used when replacing textareas.
 */
FCKeditor.MinHeight = 200 ;

/**
 * The minimum width used when replacing textareas.
 */
FCKeditor.MinWidth = 750 ;

FCKeditor.prototype.Version			= '2.6' ;
FCKeditor.prototype.VersionBuild	= '18638' ;

FCKeditor.prototype.Create = function()
{
	document.write( this.CreateHtml() ) ;
}

FCKeditor.prototype.CreateHtml = function()
{
	// Check for errors
	if ( !this.InstanceName || this.InstanceName.length == 0 )
	{
		this._ThrowError( 701, 'You must specify an instance name.' ) ;
		return '' ;
	}

	var sHtml = '' ;

	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
	{
		sHtml += '<input type="hidden" id="' + this.InstanceName + '" name="' + this.InstanceName + '" value="' + this._HTMLEncode( this.Value ) + '" style="display:none" />' ;
		sHtml += this._GetConfigHtml() ;
		sHtml += this._GetIFrameHtml() ;
	}
	else
	{
		var sWidth  = this.Width.toString().indexOf('%')  > 0 ? this.Width  : this.Width  + 'px' ;
		var sHeight = this.Height.toString().indexOf('%') > 0 ? this.Height : this.Height + 'px' ;
		sHtml += '<textarea name="' + this.InstanceName + '" rows="4" cols="40" style="width:' + sWidth + ';height:' + sHeight + '">' + this._HTMLEncode( this.Value ) + '<\/textarea>' ;
	}

	return sHtml ;
}

FCKeditor.prototype.ReplaceTextarea = function()
{
	if ( !this.CheckBrowser || this._IsCompatibleBrowser() )
	{
		// We must check the elements firstly using the Id and then the name.
		var oTextarea = document.getElementById( this.InstanceName ) ;
		var colElementsByName = document.getElementsByName( this.InstanceName ) ;
		var i = 0;
		while ( oTextarea || i == 0 )
		{
			if ( oTextarea && oTextarea.tagName.toLowerCase() == 'textarea' )
				break ;
			oTextarea = colElementsByName[i++] ;
		}

		if ( !oTextarea )
		{
			alert( 'Error: The TEXTAREA with id or name set to "' + this.InstanceName + '" was not found' ) ;
			return ;
		}

		oTextarea.style.display = 'none' ;
		this._InsertHtmlBefore( this._GetConfigHtml(), oTextarea ) ;
		this._InsertHtmlBefore( this._GetIFrameHtml(), oTextarea ) ;
	}
}

FCKeditor.prototype._InsertHtmlBefore = function( html, element )
{
	if ( element.insertAdjacentHTML )	// IE
		element.insertAdjacentHTML( 'beforeBegin', html ) ;
	else								// Gecko
	{
		var oRange = document.createRange() ;
		oRange.setStartBefore( element ) ;
		var oFragment = oRange.createContextualFragment( html );
		element.parentNode.insertBefore( oFragment, element ) ;
	}
}

FCKeditor.prototype._GetConfigHtml = function()
{
	var sConfig = '' ;
	for ( var o in this.Config )
	{
		if ( sConfig.length > 0 ) sConfig += '&amp;' ;
		sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.Config[o] ) ;
	}

	return '<input type="hidden" id="' + this.InstanceName + '___Config" value="' + sConfig + '" style="display:none" />' ;
}

FCKeditor.prototype._GetIFrameHtml = function()
{
	var sFile = 'fckeditor.html' ;

	try
	{
		if ( (/fcksource=true/i).test( window.top.location.search ) )
			sFile = 'fckeditor.original.html' ;
	}
	catch (e) { /* Ignore it. Much probably we are inside a FRAME where the "top" is in another domain (security error). */ }

	var sLink = this.BasePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.InstanceName ) ;
	if (this.ToolbarSet) sLink += '&amp;Toolbar=' + this.ToolbarSet ;

	return '<iframe id="' + this.InstanceName + '___Frame" src="' + sLink + '" width="' + this.Width + '" height="' + this.Height + '" frameborder="0" scrolling="no"></iframe>' ;
}

FCKeditor.prototype._IsCompatibleBrowser = function()
{
	return FCKeditor_IsCompatibleBrowser() ;
}

FCKeditor.prototype._ThrowError = function( errorNumber, errorDescription )
{
	this.ErrorNumber		= errorNumber ;
	this.ErrorDescription	= errorDescription ;

	if ( this.DisplayErrors )
	{
		document.write( '<div style="COLOR: #ff0000">' ) ;
		document.write( '[ FCKeditor Error ' + this.ErrorNumber + ': ' + this.ErrorDescription + ' ]' ) ;
		document.write( '</div>' ) ;
	}

	if ( typeof( this.OnError ) == 'function' )
		this.OnError( this, errorNumber, errorDescription ) ;
}

FCKeditor.prototype._HTMLEncode = function( text )
{
	if ( typeof( text ) != "string" )
		text = text.toString() ;

	text = text.replace(
		/&/g, "&amp;").replace(
		/"/g, "&quot;").replace(
		/</g, "&lt;").replace(
		/>/g, "&gt;") ;

	return text ;
}

;(function()
{
	var textareaToEditor = function( textarea )
	{
		var editor = new FCKeditor( textarea.name ) ;

		editor.Width = Math.max( textarea.offsetWidth, FCKeditor.MinWidth ) ;
		editor.Height = Math.max( textarea.offsetHeight, FCKeditor.MinHeight ) ;

		return editor ;
	}

	/**
	 * Replace all <textarea> elements available in the document with FCKeditor
	 * instances.
	 *
	 *	// Replace all <textarea> elements in the page.
	 *	FCKeditor.ReplaceAllTextareas() ;
	 *
	 *	// Replace all <textarea class="myClassName"> elements in the page.
	 *	FCKeditor.ReplaceAllTextareas( 'myClassName' ) ;
	 *
	 *	// Selectively replace <textarea> elements, based on custom assertions.
	 *	FCKeditor.ReplaceAllTextareas( function( textarea, editor )
	 *		{
	 *			// Custom code to evaluate the replace, returning false if it
	 *			// must not be done.
	 *			// It also passes the "editor" parameter, so the developer can
	 *			// customize the instance.
	 *		} ) ;
	 */
	FCKeditor.ReplaceAllTextareas = function()
	{
		var textareas = document.getElementsByTagName( 'textarea' ) ;

		for ( var i = 0 ; i < textareas.length ; i++ )
		{
			var editor = null ;
			var textarea = textareas[i] ;
			var name = textarea.name ;

			// The "name" attribute must exist.
			if ( !name || name.length == 0 )
				continue ;

			if ( typeof arguments[0] == 'string' )
			{
				// The textarea class name could be passed as the function
				// parameter.

				var classRegex = new RegExp( '(?:^| )' + arguments[0] + '(?:$| )' ) ;

				if ( !classRegex.test( textarea.className ) )
					continue ;
			}
			else if ( typeof arguments[0] == 'function' )
			{
				// An assertion function could be passed as the function parameter.
				// It must explicitly return "false" to ignore a specific <textarea>.
				editor = textareaToEditor( textarea ) ;
				if ( arguments[0]( textarea, editor ) === false )
					continue ;
			}

			if ( !editor )
				editor = textareaToEditor( textarea ) ;

			editor.ReplaceTextarea() ;
		}
	}
})() ;

function FCKeditor_IsCompatibleBrowser()
{
	var sAgent = navigator.userAgent.toLowerCase() ;

	// Internet Explorer 5.5+
	if ( /*@cc_on!@*/false && sAgent.indexOf("mac") == -1 )
	{
		var sBrowserVersion = navigator.appVersion.match(/MSIE (.\..)/)[1] ;
		return ( sBrowserVersion >= 5.5 ) ;
	}

	// Gecko (Opera 9 tries to behave like Gecko at this point).
	if ( navigator.product == "Gecko" && navigator.productSub >= 20030210 && !( typeof(opera) == 'object' && opera.postError ) )
		return true ;

	// Opera 9.50+
	if ( window.opera && window.opera.version && parseFloat( window.opera.version() ) >= 9.5 )
		return true ;

	// Adobe AIR
	// Checked before Safari because AIR have the WebKit rich text editor
	// features from Safari 3.0.4, but the version reported is 420.
	if ( sAgent.indexOf( ' adobeair/' ) != -1 )
		return ( sAgent.match( / adobeair\/(\d+)/ )[1] >= 1 ) ;	// Build must be at least v1

	// Safari 3+
	if ( sAgent.indexOf( ' applewebkit/' ) != -1 )
		return ( sAgent.match( / applewebkit\/(\d+)/ )[1] >= 522 ) ;	// Build must be at least 522 (v3)

	return false ;
}
