window.onload = OnLoad;
var eventListener = new Array();
var callbackList = new Array();
var attachfunction = new Array();
//setup form method constants
var PostAction = new Object();
PostAction.Save = 1;
PostAction.SaveAsDraft = 2;
PostAction.CancelEntry = 3;
PostAction.CancelEntryDeleteImage = 4;
PostAction.CancelEntryDeleteImageAndPost = 5;
// This function call Individual Part's Init function
function OnLoad()
{
 var i;
 for (i=0; i < attachfunction.length; i++)
 {
 eval(attachfunction[i] + "()");
 }
 if ( document.getElementsByName("ratingimage").length != 0 )
 {
 SetupRatings();
 }
}
//Register the event that you intend to fire
function RegisterEventType(eventType)
{
 if(eventListener[eventType] == null)
 {
 eventListener[eventType] = new Array();
 callbackList[eventType] = new Array();
 }
}
//Attach interested event to call callback function
function AttachToEvent(source, eventType, callbackFunction)
{
 if(eventListener[eventType] != null)
 {
 eventListener[eventType][eventListener[eventType].length] = source;
 callbackList[eventType][callbackList[eventType].length] = callbackFunction;
 }
}
// This function will call the callback function of the parts that are interested in given event type
function DispatchHelper(eventType, value, partInfo, title)
{
 if (eventListener[eventType].length == 0)
 {
 OnLoad();
 }
 if(typeof(eventListener[eventType]) == 'object')
 {
 for(var i=0;i<eventListener[eventType].length;i++)
 {
 eval(callbackList[eventType][i] + "(\"" + value + "\", partInfo, title)");
 }
 }
}
function WriteHandlerCookie(handle, domain)
{
 document.cookie = "DeleteHandle=" + handle + ";path=/;domain=" + domain + ";";
}
function ClearHandlerCookie(handle, domain)
{
 document.cookie = "DeleteHandle=null;path=/;domain=" + domain + ";";
}
String.prototype.lTrim = function () {
 return this.replace(/^\s*/, "");
}
// remove trailing whitespace
String.prototype.rTrim = function () {
 return this.replace(/\s*$/, "");
}
// remove leading and trailing whitespace
String.prototype.trim = function () {
 return this.rTrim().lTrim();
}
function ValidateName(src)
{
 src = src.trim();
 if (src.length == 0)
 {
 return false;
 }
 else
 {
 return true;
 }
}
function ValidateEmail(src)
{
 //make sure that any changes to this validation still match Storage's validation.
 //make sure changes to this also get in web/sharedutil/Utility/StorageUtility.cs.
 var emailReg = /^([a-zA-Z0-9_\-\.\+]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/
 return emailReg.test(src);
}
function ValidateEmailEx(src)
{
 var emailReg = /^[\w\.\+\-]+@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
 return emailReg.test(src);
}
function ValidateAlphaNumeric(src)
{
 var alphaReg = /[^a-zA-Z0-9]/g
 return !alphaReg.test(src);
}
function encodeURI(strUrl)
{
 var returnString;
 returnString = escape( strUrl )
 returnString = returnString.replace(/\+/g,"%2B");
 return returnString
}
function decodeURI(strUrl)
{
 return unescape(strUrl)
}
function IsIE()
{
 if (navigator.userAgent.indexOf('MSIE')>-1)
 {
 if (navigator.userAgent.indexOf("Opera") == (-1))
 {
 return true;
 }
 }
 return false;
}
function IsWin()
{
 if (navigator.userAgent.toLowerCase().indexOf("windows") > 0)
 {
 return true;
 }
 return false;
}
function UseShowModalDialog()
{
 if(IsWin() && window.showModalDialog)
 {
 return true;
 }
 return false;
}
function IsRich()
{
 if (IsIE())
 {
 var appVer = navigator.appVersion.toLowerCase();
 var iePos = appVer.indexOf('msie');
 minorVer = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
 majorVer = parseInt(minorVer);
 if (majorVer >= 6)
 return true;
 }
 return false;
}
function GShowHide(shObj, imgObj)
{
 if (shObj != null && imgObj != null)
 {
 if (shObj.style.display == 'none' || shObj.style.display == '')
 {
 shObj.style.display = 'block';
 imgObj.src = 'images/icon_less.gif';
 }
 else
 {
 shObj.style.display = 'none';
 imgObj.src = 'images/icon_more.gif';
 }
 }
}
function GetXmlHttpObject()
{
 var xmlHttp;
 if (!window.XMLHttpRequest) {
 try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0"); return xmlHttp; } catch (ex) {}
 try { xmlHttp = new ActiveXObject("MSXML2.XMLHTTP"); return xmlHttp; } catch (ex){}
 try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); return xmlHttp; } catch (ex) {}
 return null;
 }
 else
 {
 try {xmlHttp = new XMLHttpRequest(); return xmlHttp;} catch(ex) {}
 return null;
 }
}
function XMLHttp(formFields, strUrl, httpGET)
{
 var strText = "";
 var getorpost=(typeof(httpGET)!="undefined" && httpGET==true)? "GET" : "POST";
 xmlhttp = GetXmlHttpObject();
 try {
 if (xmlhttp != null)
 {
 xmlhttp.open(getorpost, strUrl, false);
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 xmlhttp.send(formFields);
 strText = xmlhttp.responseText;
 }
 }catch(ex){}
 return strText;
}
var photoControlWin;
function LoadPhotoUploadcontrol(spudurl)
{
 if (photoControlWin == null || photoControlWin.closed)
 {
 var ah = screen.availHeight;
 var height = 515;
 var y = (ah - height) / 2;
 var aw = screen.availWidth;
 var width = 700;
 x = (aw - width)/2;
 photoControlWin = window.open(spudurl,"spud","top=" + y + ",left=" + x + ",width=" + width + ",height="+height +",directories=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0");
 photoControlWin.focus();
 }
 else
 {
 photoControlWin.focus();
 }
 return null;
}
//The following functions are internal spaces part specific.
//Initializing Global Variables. This variables are set in the ascx or aspx pages if it's
//being used.
var gblMultipleDelStr = "";
var gblEntryDelItemStr = "";
var gblCommentDelItemStr = "";
var gblTrackbackDelItemStr = "";
var gblDownlevelMultipleConfirmStr = "";
var gblDownlevelEntryConfirmStr ="";
var gblDownlevelCommentfConfirmStr = "";
var gblDownlevelTrackbackConfirmStr = "";
var gblpage = "";
var gblCategoryDelItemStr = "";
var gblDownlevelCategoryConfirmStr = "";
var gblHandle = "";
var gblNoBtn = "";
var gblYesBtn = "";
/*BlogMgmt-specific functions to deal with delete checkboxes*/
function ManageDeleteLink(deleteLink){
 var checkboxes = GetCheckboxes(); //defined on page with checkboxes
 var bLinkDisabled = true;
 for(var i = 0; i < checkboxes.length; i++){
 if(checkboxes[i].checked){
 bLinkDisabled = false;
 break;
 }
 }
 if(bLinkDisabled && (deleteLink.oldHtml == null)){
 deleteLink.oldHtml = deleteLink.innerHTML;
 deleteLink.innerHTML = deleteLink.innerText;
 deleteLink.className = "disabledModHead";
 }else if(!bLinkDisabled && (deleteLink.oldHtml != null)){
 deleteLink.innerHTML = deleteLink.oldHtml;
 deleteLink.className = "";
 deleteLink.oldHtml = null;
 }
}
function ManageCheckboxes(clickedBox){
 var checkboxes = GetCheckboxes(); //defined on page with checkboxes
 var entryNum = clickedBox.getAttribute("entry");
 var disable = clickedBox.checked;
 var elCheckbox;
 for(var i = 0; i < checkboxes.length; i++){
 elCheckbox = checkboxes[i];
 if((elCheckbox.getAttribute("entry") == entryNum) &&
 (elCheckbox.getAttribute("checktype") != "entry"))
 {
 elCheckbox.disabled = disable;
 }
 }
}
function DeleteMultipleBlogItems(sourceFrm){
 //create string.
 var firstItem = true;
 var strItemTypes = "";
 var strHandles = "";
 var sep = "|";
 var htEntryByNum = new Object();
 var children = new Array();
 var checkboxes = GetCheckboxes(); //defined on page with checkboxes
 for(var i = 0; i < checkboxes.length; i++){
 switch(checkboxes[i].getAttribute("checktype")){
 case "entry":
 if(checkboxes[i].checked == true){
 var entryNum = checkboxes[i].getAttribute("entry");
 if(!firstItem){
 strItemTypes += sep;
 strHandles += sep;
 }
 strItemTypes += "entry";
 strHandles += checkboxes[i].getAttribute("handle");
 htEntryByNum[entryNum] = true;
 firstItem = false;
 }
 break;
 case "trackback":
 case "comment":
 //process after entries have been processed
 children.push(checkboxes[i]);
 break;
 }
 }
 for(var j = 0; j < children.length; j++){
 if(children[j].checked == true){
 var entryNum = children[j].getAttribute("entry")
 if(htEntryByNum[entryNum] != true){
 if(!firstItem){
 strItemTypes += sep;
 strHandles += sep;
 }
 strItemTypes += children[j].getAttribute("checktype");
 strHandles += children[j].getAttribute("handle");
 firstItem = false;
 }
 }
 }
 //prompt for and delete
 var actionType = "DeletePart";
 if(strHandles){
 ClearHandlerCookie();
 if (UseShowModalDialog())
 {
 var DialogHeight = 185;
 var strDelItem = gblMultipleDelStr;
 var dataArray = new SimpleDialogData(null, null, null, null, strDelItem, gblYesbtn, gblNobtn);
 var returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=" + actionType, dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if(returnValObj != null && returnValObj.Action != null && returnValObj.Action == "OK")
 {
 WriteHandlerCookie(strHandles, window.location.hostname);
 document.getElementById("DeleteItem").innerHTML = "<iframe id='DeleteItemIframe' src='DeleteBlogItem.aspx?handle=" + strHandles +"&item=" + strItemTypes +"&delete=true' height=1 width=1></iframe>";
 }
 }
 else
 {
 var bConfirm = false;
 bConfirm = confirm(gblDownlevelMultipleConfirmStr);
 if (bConfirm)
 {
 WriteHandlerCookie(strHandles, window.location.hostname);
 sourceFrm.handle.value = strHandles;
 sourceFrm.item.value = strItemTypes;
 sourceFrm.submit();
 }
 }
 }
}
/*Share between MySpace, BlogEntry and BlogSettings*/
function DeleteCommonBlogItem(item, handle, sourceFrm, name)
{
 var actionType = "DeletePart";
 gblHandle = handle;
 ClearHandlerCookie();
 if (UseShowModalDialog())
 {
 var strDelItem = "";
 var DialogHeight = 185;
 switch(item)
 {
 case "entry":
 strDelItem = gblEntryDelItemStr;
 break;
 case "comment":
 strDelItem = gblCommentDelItemStr;
 break;
 case "trackback":
 strDelItem = gblTrackbackDelItemStr;
 break;
 case "category":
 gblHandle = handle;
 strDelItem = gblCategoryDelItemStr;
 actionType = "DeleteListItem";
 break;
 }
 var dataArray = new SimpleDialogData(name, null, null, null, strDelItem, gblYesbtn, gblNobtn);
 var returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=" + actionType, dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if(returnValObj != null && returnValObj.Action != null && returnValObj.Action == "OK")
 {
 WriteHandlerCookie(handle, window.location.hostname);
 document.getElementById("DeleteItem").innerHTML = "<iframe id='DeleteItemIframe' src='DeleteBlogItem.aspx?handle=" +handle +"&item=" + item +"&delete=true' height=1 width=1></iframe>";
 }
 }
 else
 {
 fConfirm = false;
 if (item == "entry")
 {
 fConfirm = confirm(gblDownlevelEntryConfirmStr);
 }
 else if (item == "comment")
 {
 fConfirm = confirm(gblDownlevelCommentConfirmStr);
 }
 else if (item == "category")
 {
 fConfirm = confirm(gblDownlevelCategoryConfirmStr);
 }
 else
 {
 fConfirm = confirm(gblDownlevelTrackbackConfirmStr);
 }
 if (fConfirm)
 {
 WriteHandlerCookie(handle, window.location.hostname);
 sourceFrm.handle.value = handle;
 sourceFrm.item.value = item;
 sourceFrm.submit();
 }
 }
}
function DisplayError()
{
 alert(gblErrorOccurred);
 document.getElementById("DeleteItemIframe").src = "";
 return false;
}
function UpdateEntries()
{
 switch(gblpage)
 {
 case "myspace":
 location.reload();
 break;
 case "blogmgmt":
 location.reload();
 break;
 case "blogentry":
 document.getElementById("DeleteItemIframe").src = "";
 UpdateBlogEntries();
 break;
 case "blogsettings":
 document.getElementById("DeleteItemIframe").src = "";
 UpdateCategories();
 break;
 }
}
function sh(showhideitem, id, iEntry)
{
 if(document.getElementById(showhideitem + id).innerHTML == "")
 {
 GetBlogManagementItem(showhideitem, id, iEntry, "");
 }
 else
 {
 slinkObj = document.getElementById("sPN" + id);
 if (slinkObj != null)
 {
 document.getElementById("PN" + id).innerHTML = slinkObj.innerHTML;
 }
 }
 shObj = document.getElementById(showhideitem + id);
 imgObj = document.getElementById('arrow' + showhideitem + id);
 linkObj = document.getElementById('PN' + id);
 if ((showhideitem == "commentlist") && shObj != null && linkObj != null)
 {
 if (shObj.style.display == 'none' || shObj.style.display == '')
 {
 linkObj.style.display = 'block';
 }
 else
 {
 linkObj.style.display = 'none';
 }
 }
 GShowHide(shObj, imgObj);
}
function GetULBlogManagementItem(showhideitem, id, iEntry, otherFormFields)
{
 strUrl = gblUrl;
 if (showhideitem == "commentlist")
 {
 strItem = "authcomment";
 }
 else
 {
 strItem = "authtrackback";
 }
 var formFields = "handle="+ id;
 formFields += "&iEntry=" + iEntry;
 formFields += "&blogitem=" + strItem;
 formFields += "&blogpart=blogmgmt";
 formFields += "&_c=blogpart";
 formFields += otherFormFields;
 strText = XMLHttp(formFields, strUrl);
 if (strText.toLowerCase() != "error" && strText.length > 0)
 {
 var showHideItem = document.getElementById(showhideitem + id);
 showHideItem.innerHTML = strText;
 linkObj = document.getElementById("sPN" + id);
 if (linkObj != null)
 {
 document.getElementById("PN" + id).innerHTML = linkObj.innerHTML;
 linkObj.style.display = "none";
 }
 ManageCheckboxes(document.getElementById("entrycheck" + iEntry));
 }
 else
 {
 alert(gblErrContent);
 }
}
function GetDLBlogManagementItem(showhideitem, id, iEntry,formFields)
{
 window.location = gblPersistedBlogMgmtUrl + "&entryhandle=" + id + formFields;
}
function GetBlogManagementItem(showhideitem, id, iEntry, otherFormFields)
{
 if (IsIE())
 {
 GetULBlogManagementItem(showhideitem, id, iEntry,otherFormFields);
 }
 else
 {
 GetDLBlogManagementItem(showhideitem, id, iEntry,otherFormFields);
 }
}
/*Archive Part*/
var gblArchiveLink = "";
function InitializeArchives()
{
 if (gblArchiveLink.length > 0)
 {
 document.getElementById(gblArchiveLink).style.fontWeight = 'normal';
 }
}
function BoldArchives(atag)
{
 if (gblArchiveLink.length > 0)
 {
 document.getElementById(gblArchiveLink).style.fontWeight = 'normal';
 }
 document.getElementById("archive" + atag).style.fontWeight = 'bold';
 gblArchiveLink = "archive" + atag;
}
/*BlogSearch and BlogSearchResults*/
var gblSearchResultNoQuery;
var gblInput;
function CheckSearchValue()
{
 if (document.searchpart.inputtext.value == "")
 {
 alert (gblSearchResultNoQuery);
 document.searchpart.inputtext.focus();
 return false;
 }
 else
 {
 document.searchpart.submit();
 }
}
function CheckInputText()
{
 if (document.searchfrm.inputtext.value == "")
 {
 alert (gblSearchResultNoQuery);
 document.searchfrm.inputtext.value = gblInput;
 return false;
 }
 else
 {
 document.searchfrm.submit();
 }
}
function GotoPage(startPage, iPage)
{
 document.searchfrm.sp.value = startPage;
 document.searchfrm.cp.value = iPage;
 document.searchfrm.inputtext.value = gblInput;
 document.searchfrm.submit();
}
/*CategoryList*/
var gblCatLink = "";
function InitializeCategory()
{
 if (gblCatLink.length > 0)
 {
 document.getElementById(gblCatLink).style.fontWeight = 'normal';
 }
}
function BoldCategory(atag)
{
 if (gblCatLink.length > 0)
 {
 document.getElementById(gblCatLink).style.fontWeight = 'normal';
 }
 document.getElementById("cat" + atag).style.fontWeight = 'bold';
 gblCatLink = "cat" + atag;
}
/*BlogEntry*/
var c_MaxTrackback, c_MaxTitleLength,c_MaxDescLength;
var gblRedirectUrl,gblMessageText,gblBEConfirm,gblBETrackbackErr,gblBETitleErr;
var gblBEImageErr, gblBEActionUrl;
var gblPhoto = 0;
var gblUploadPhotText, gblAddPhotos;
var gblDraft;
var gblSpaceUrl;
function shTB()
{
 var tbinfo = document.getElementById("tbinfo");
 var tbicon = document.getElementById("tbicon");
 GShowHide(tbinfo, tbicon);
}
function SwitchToPreview()
{
 document.getElementById("rtebox").style.display = 'none';
 document.getElementById("previewbox").style.display = "block";
 document.getElementById("previewbox").style.fontSize = "100%";
 document.getElementById("previewentry").className = "bePreviewSelectedTab";
 document.getElementById("beleftborder").className= "beborderleftdarkbg";
 document.getElementById("blogentry").className = "beBlogNormalTab";
 document.getElementById("beTopRow").style.display = 'none';
 document.getElementById("bePicRow").style.display = 'none';
 document.getElementById("beSecondSpacer").style.display = 'none';
 document.getElementById("beTBRow").style.display = 'none';
 var elBox = document.getElementById("DLEditBox");
 RecopyRTE(elBox);
 document.getElementById("previewbox").innerHTML = elBox.value;
 window.focus();
}
function SwitchToEdit()
{
 document.getElementById("rtebox").style.display = 'block';
 document.getElementById("previewentry").className = "beNormalTab";
 document.getElementById("beleftborder").className= "beborderleft";
 document.getElementById("blogentry").className = "beSelectedTab";
 document.getElementById("beTopRow").style.display = 'block';
 document.getElementById("bePicRow").style.display = 'block';
 document.getElementById("beSecondSpacer").style.display = 'block';
 document.getElementById("beTBRow").style.display = 'block';
 document.getElementById("previewbox").style.display = "none";
 document.getElementById("DLEditBox").focus();
}
function SubmitFrm(frmOption)
{
 if((typeof(event) != 'undefined') && (event) && (event.srcElement) && (event.srcElement.disabled)){
 return false;
 }
 if (frmOption == PostAction.CancelEntry)
 {
 location.href = gblRedirectUrl;
 }
 else
 {
 if (frmOption == PostAction.SaveAsDraft && document.frmEntry.draft.value == "False")
 {
 if(UseShowModalDialog())
 {
 var DialogHeight = 185;
 var dataArray = new SimpleDialogData(null, null, null, null, gblMessageText, null, null);
 var returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=DeletePart", dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if(returnValObj == null || returnValObj.Action == null || returnValObj.Action != "OK")
 {
 return false;
 }
 }
 else
 {
 fConfirm = confirm(gblBEConfirm);
 if (!fConfirm)
 {
 return false;
 }
 }
 }
 else if ( frmOption != PostAction.CancelEntryDeleteImage && frmOption != PostAction.CancelEntryDeleteImageAndPost )
 {
 if (document.frmEntry.trackbackurl.value != "")
 {
 tUrl = document.frmEntry.trackbackurl.value.split(";");
 if (tUrl.length > c_MaxTrackback)
 {
 alert(gblBETrackbackErr);
 document.frmEntry.trackbackurl.focus();
 return false;
 }
 }
 title = document.frmEntry.title.value.trim();
 if (title.length > c_MaxTitleLength)
 {
 alert(gblBETitleErr);
 document.frmEntry.title.focus();
 return false;
 }
 var elBox = document.getElementById("DLEditBox");
 RecopyRTE(elBox);
 document.frmEntry.txtDesc.value = elBox.value;
 if (document.frmEntry.txtDesc.value.length > c_MaxDescLength)
 {
 alert(gblBESchemaErr);
 return false;
 }
 for (i =1; i <= gblPhoto; i++)
 {
 if (document.getElementById("filectrl"+i) != null)
 {
 strFileName = document.getElementById("filectrl"+i).value;
 if (strFileName.length > 0)
 {
 nExtension = strFileName.lastIndexOf(".");
 strExtension = strFileName.substring(nExtension+1).toLowerCase();
 if (strExtension != "gif" &&
 strExtension != "jpg" &&
 strExtension != "jpeg" &&
 strExtension != "jpe" &&
 strExtension != "jfif" &&
 strExtension != "tif" &&
 strExtension != "tiff" &&
 strExtension != "png" &&
 strExtension != "bmp")
 {
 alert(gblBEImageErr);
 return false;
 }
 }
 }
 }
 }
 document.frmEntry.btn1.disabled = true;
 document.frmEntry.btn2.disabled = true;
 document.frmEntry.cancel.disabled = true;
 document.frmEntry.frmoption.value = frmOption;
 document.frmEntry.action = gblBEActionUrl;
 document.frmEntry.submit();
 }
}
function RecopyRTE(elRTE){
 if(elRTE && elRTE.RichEdit){
 elRTE.value = elRTE.RichEdit.GetValue();
 }
}
function AddNewCategory(inCategoryName, maxCategoryLength)
{
 var fCategoryFound = false;
 fCancel = false;
 categoryName = "";
 totalCategory = gblTotalCategory;
 if (inCategoryName == null)
 {
 inCategoryName = "";
 }
 if (UseShowModalDialog())
 {
 DialogHeight = 200;
 var dataArray = new ComplexDialogData(null, new Array(inCategoryName), gblAddNewCategory, null, null, [maxCategoryLength]);
 var returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=AddCategory", dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if(returnValObj != null && returnValObj.Action != null && returnValObj.Action == "NameValueReturn")
 {
 categoryName = returnValObj.ReturnValues[0];
 }
 else
 {
 fCancel = true;
 }
 }
 else
 {
 categoryName = window.prompt(gblAddNewCategory, inCategoryName);
 }
 if(categoryName){
 categoryName = categoryName.trim();
 }else{
 //categoryName should be a string so the code below won't break.
 //Differentiate between null and empty string: null means the prompt was canceled.
 if(categoryName != ""){
 fCancel = true;
 categoryName = "";
 }
 }
 if(categoryName.length > maxCategoryLength)
 {
 alert(gblCategoryTooLong);
 }
 if ((categoryName.length == 0) && (fCancel == false))
 {
 alert(gblInvalidCategory);
 }
 if ((fCancel == false) &&
 (categoryName.length > 0) &&
 (categoryName.length <= maxCategoryLength))
 {
 for (i=0; i < document.frmEntry.category.length; i++)
 {
 if (document.frmEntry.category.options[i].value.toLowerCase() == categoryName.toLowerCase())
 {
 fCategoryFound = true;
 break;
 }
 }
 if (fCategoryFound)
 {
 document.frmEntry.category.options[i].selected = true;
 }
 else
 {
 var newOption = new Option(categoryName);
 newOption.value = categoryName;
 document.frmEntry.category.options[totalCategory] = newOption;
 newOption.selected = true;
 }
 }else if((fCancel == false) && (UseShowModalDialog() == false)){
 AddNewCategory(categoryName, maxCategoryLength);
 }
}
function UpdateBlogEntries()
{
 var itemObj = document.getElementById(gblitem + gblhandle);
 if (itemObj != null)
 {
 itemObj.style.display = "none";
 }
 var comment_trackback_Count = parseInt(document.getElementById(gblitem + "count").innerText) - 1;
 if (comment_trackback_Count == 0)
 {
 document.getElementById(gblitem + "body").style.display = "none";
 }
 if (document.getElementById(gblitem + "count") != null)
 {
 document.getElementById(gblitem + "count").innerText = comment_trackback_Count;
 }
}
var photosAdded = "";
var photoHidden = "";
var totalPhotosFromUploadControl = 0;
function AddBlogPhotos(returnObj)
{
 for(i=0; i < returnObj.length; i++)
 {
 if (totalPhotosFromUploadControl > 0)
 {
 photoHidden += "|";
 }
 photoHidden += returnObj[i].GUID;
 photosAdded += "<a href='" + returnObj[i].MiniSource + "' target='_blank'><strong>" + returnObj[i].Caption + "</strong></a>&nbsp;<br>";
 totalPhotosFromUploadControl++;
 }
 if (photoHidden.length > 0)
 {
 document.getElementById("UploadPhotos").value = photoHidden;
 document.frmEntry.btn1.disabled = false;
 document.frmEntry.btn2.disabled = false;
 //This is for new entry
 if (document.getElementById("AttachedPhotosTxt") != null)
 {
 document.getElementById("AttachedPhotosTxt").innerHTML = "<p/>" + gblPhotosAddStr + "&nbsp;";
 document.getElementById("AttachedPhotos").innerHTML = "<p/>" + photosAdded;
 }
 //This is for existing entry with no photos attached
 else if (document.getElementById("NoPhotosAdded") != null)
 {
 document.getElementById("NoPhotosAdded").innerHTML = photosAdded;
 }
 //This is for existing entry with photos attached.
 else if(document.getElementById("NewPhotosAdded") != null)
 {
 document.getElementById("NewPhotosAdded").innerHTML = photosAdded;
 }
 }
}
function SetParentHandle(handle)
{
 if ( handle && document.getElementById("entryid"))
 {
 document.getElementById("entryid").value = handle;
 }
}
function AddPhotos()
{
 if (IsRich())
 {
 if ( document.frmEntry.Cancel.newPost == "1" )
 {
 document.frmEntry.Cancel._onclick = Function("SubmitFrm(PostAction.CancelEntryDeleteImageAndPost);");
 }
 else
 {
 document.frmEntry.Cancel._onclick = Function("SubmitFrm(PostAction.CancelEntryDeleteImage);");
 }
 LoadPhotoUploadcontrol("/SPUD.aspx?postId=" + document.getElementById("entryid").value);
 }
 else
 {
 gblPhoto = maxPhotoInput;
 var photoInput = "<p/>";
 for (i=1; i <= maxPhotoInput; i++)
 photoInput += '<input type="file" id="filectrl' + i+ '" size="50" name="filectrl' + i+ '" onkeyup="ValidateBlogEntryInput()" onchange="ValidateBlogEntryInput()" onclick="ValidateBlogEntryInput()"><br>';
 document.getElementById("ImageUploadCell").innerHTML = photoInput;
 document.getElementById("DlUploadTbl").style.display = "block";
 document.getElementById("ImageTypeText").style.visibility = "visible";
 document.getElementById("ImageTypeText").innerHTML = "<p/>" + gblImageWarning;
 document.getElementById("PhotoId").innerHTML = "&nbsp;<span class=\"grayText\">" + gblAddPhotos + "</span>";
 document.getElementById("PhotoImg").innerHTML = "<img src='images/addpic_dl.png' width='14' alt='" + gblAddPhotos + "'>";
 }
}
function ValidateBlogEntryInput()
{
 fPhoto = false;
 for (i =1; i <= gblPhoto; i++)
 {
 if (document.getElementById("filectrl"+i) != null)
 {
 strFileName = document.getElementById("filectrl"+i).value;
 if (strFileName.length > 0)
 {
 fPhoto = true;
 break;
 }
 }
 }
 if (document.frmEntry.title.value.trim().length > 0 || fPhoto)
 {
 document.frmEntry.btn1.disabled = false;
 document.frmEntry.btn2.disabled = false;
 }
 else
 {
 document.frmEntry.btn1.disabled = true;
 if (gblDraft)
 {
 document.frmEntry.btn2.disabled = true;
 }
 }
}
function GetULBlogEntryItem(item, handle, otherFormFields)
{
 var qs= "handle="+ handle;
 qs += "&blogitem=" + item;
 qs += "&partresponseonly=true";
 qs += otherFormFields;
 strText = XMLHttp(qs, gblSpaceUrl);
 if (strText.toLowerCase() != "error" && strText.length > 0)
 {
 document.getElementById("commentbody").innerHTML = strText;
 }
 else
 {
 alert(gblBEErrContent);
 }
}
function GetDLBlogEntryItem(item, handle, otherFormFields)
{
 var qs = "handle="+ handle;
 qs += otherFormFields;
 window.location = (gblSpaceUrl + "?" + qs + "#commentbody");
}
function GetBlogEntryItem(item, handle, otherFormFields)
{
 if (IsIE())
 {
 GetULBlogEntryItem(item, handle, otherFormFields);
 }
 else
 {
 GetDLBlogEntryItem(item, handle, otherFormFields);
 }
}
/* BlogSettings*/
function UpdateCategories()
{
 document.getElementById("row1_" + gblHandle).style.display = "none";
}
/* MobileSettings Only*/
function doMobile()
{
 var serverUrl = window.location.protocol + "//" + window.location.hostname + "/";
 var bluePillBGImage = "url(" + serverUrl + "images/pill_blue.gif" + ")";
 var grayPillBGImage = "url(" + serverUrl + "images/pill_gray.gif" + ")";
 if(document.forms.SUForm.EnableMobile.checked)
 {
 document.getElementById("Num2").className = "";
 document.getElementById("Num3").className = "";
 document.getElementById("Num4").className = "";
 document.getElementById("Num5").className = "";
 document.getElementById("Img2").style.backgroundImage = bluePillBGImage;
 document.getElementById("Img3").style.backgroundImage = bluePillBGImage;
 document.getElementById("Img4").style.backgroundImage = bluePillBGImage;
 document.getElementById("Img5").style.backgroundImage = bluePillBGImage;
 document.forms.SUForm.MobileEmail1.disabled = false;
 document.forms.SUForm.MobileEmail2.disabled = false;
 document.forms.SUForm.MobileEmail3.disabled = false;
 document.forms.SUForm.SecretWord.disabled = false;
 document.forms.SUForm.rDraft.disabled = false;
 document.forms.SUForm.rInstant.disabled = false;
 document.getElementById("combinedAddress").style.display = "";
 //udpate error messages
 updateCombined(document.getElementById("SecretWord").value);
 checkMail("MobileEmail1");
 checkMail("MobileEmail2");
 checkMail("MobileEmail3");
 }
 else
 {
 document.getElementById("Num2").className = "disabledText";
 document.getElementById("Num3").className = "disabledText";
 document.getElementById("Num4").className = "disabledText";
 document.getElementById("Num5").className = "disabledText";
 document.getElementById("Img2").style.backgroundImage = grayPillBGImage ;
 document.getElementById("Img3").style.backgroundImage = grayPillBGImage ;
 document.getElementById("Img4").style.backgroundImage = grayPillBGImage ;
 document.getElementById("Img5").style.backgroundImage = grayPillBGImage ;
 document.forms.SUForm.MobileEmail1.disabled = true;
 document.forms.SUForm.MobileEmail2.disabled = true;
 document.forms.SUForm.MobileEmail3.disabled = true;
 document.forms.SUForm.SecretWord.disabled = true;
 document.forms.SUForm.rDraft.disabled = true;
 document.forms.SUForm.rInstant.disabled = true;
 document.getElementById("ValidPreview").style.display = "none";
 document.getElementById("combinedAddress").style.display = "none";
 document.getElementById("MobileEmail1Error").style.display = "none";
 document.getElementById("MobileEmail2Error").style.display = "none";
 document.getElementById("MobileEmail3Error").style.display = "none";
 document.forms.SUForm.subButton.disabled = false;
 }
}
function updateCombined(sValue)
{
 if(checkWord(sValue))
 {
 showPreview();
 }
 else
 {
 disablePreview();
 }
}
function checkWord(sSrc)
{
 document.getElementById("SecretWordPart").innerText = document.getElementById("SecretWordPart").textContent = sSrc;
 if(ValidateAlphaNumeric(sSrc) == true)
 {
 if((sSrc.length >= 5) && (sSrc.length <= 10))
 {
 return true;
 }
 else
 {
 return false;
 }
 }
 else
 {
 return false;
 }
}
function disablePreview()
{
 document.getElementById("ValidPreview").style.display = "";
 document.getElementById("combinedAddress").style.display = "none";
 document.forms.SUForm.subButton.disabled = true;
}
function showPreview()
{
 var text = document.getElementById("SecretWordPart").innerText;
 if(!text)
 text = document.getElementById("SecretWordPart").textContent;
 if( checkWord(text) )
 {
 document.getElementById("ValidPreview").style.display = "none";
 document.getElementById("combinedAddress").style.display = "";
 document.forms.SUForm.subButton.disabled = false;
 }
 else
 {
 disablePreview();
 }
}
var gblMobileErrStr;
function checkMail(sID)
{
 var sValue = document.forms.SUForm[sID].value;
 var errorText = document.getElementById(sID + "Error");
 if((sValue.length != 0) && !ValidateEmailEx(sValue))
 {
 errorText.style.display = "";
 return false;
 }else{
 errorText.style.display = "none";
 return true;
 }
}
function checkSecretWord(sValue)
{
 if (!document.forms.SUForm.SecretWord.disabled)
 {
 if(!ValidateAlphaNumeric(sValue))
 {
 disablePreview(); //also displays secret word error message
 document.forms.SUForm.SecretWord.focus();
 return false;
 }
 }
 return true;
}
function validateMobileSettingsInput()
{
 var result = true;
 if(!document.forms.SUForm.MobileEmail1.disabled){
 //check all the email addresses, and make sure there is at least 1 non-empty email address
 var haveNonEmptyEmail = false;
 //checkNonEmptyEmail is defined below and changes haveNonEmptyEmail and result
 checkNonEmptyEmail("MobileEmail1");
 checkNonEmptyEmail("MobileEmail2");
 checkNonEmptyEmail("MobileEmail3");
 if(!haveNonEmptyEmail || !result){
 alert(gblMobileErrStr);
 result = false;
 }
 if (!checkSecretWord(document.forms.SUForm.SecretWord.value)) result = false;
 }
 return result;
 function checkNonEmptyEmail(sID)
 {
 if(document.forms.SUForm[sID].value.length > 0)
 {
 haveNonEmptyEmail = true;
 if(!checkMail(sID)) result = false;
 }
 }
}
/* End MobileSettings Only */
function ComplexDialogData(LabelArray, DefaultsArray, DialogItemDetails, Btn1, Btn2, LimitsArray, LabelsHtmlSafe)
{
 if ( LabelsHtmlSafe == null ) LabelsHtmlSafe = false;
 this.LabelArray = LabelArray;
 this.DefaultsArray = DefaultsArray;
 this.DialogItemDetails = DialogItemDetails;
 this.Btn1 = Btn1;
 this.Btn2 = Btn2;
 this.LimitsArray = LimitsArray;
 this.LabelsHtmlSafe = LabelsHtmlSafe;
}
function SimpleDialogData(NameLabel, NameDefault, ValueLabel, ValueDefault, DialogItemDetails, Btn1, Btn2)
{
 return new ComplexDialogData(new Array(NameLabel, ValueLabel), new Array(NameDefault, ValueDefault), DialogItemDetails, Btn1, Btn2);
}
function BlogIt(entryid)
{
 var subj = document.getElementById("subj" + entryid);
 var msg = document.getElementById("msg" + entryid);
 if (subj!=null && msg!=null) {
 url = BlogJSBlogEntryUrl;
 var f = document.createElement("form");
 f.action = url;
 f.method = "post";
 f.id= "doTrackback";
 f.style.display = "none";
 var elSubject = document.createElement("textarea");
 elSubject.name = "Title";
 elSubject.value = subj.innerText;
 f.appendChild(elSubject);
 var elBody = document.createElement("textarea");
 elBody.name = "Description";
 elBody.value = msg.innerHTML;
 f.appendChild(elBody);
 var elSubject = document.createElement("textarea");
 elSubject.name = "SourceURL";
 elSubject.value = BlogJSPersonalSpaceurl + "blog/" + entryid + ".entry";
 f.appendChild(elSubject);
 var elTrackback = document.createElement("textarea");
 elTrackback.name = "Trackback";
 elTrackback.value = BlogJSPersonalSpaceurl + "blog/" + entryid + ".trak";
 f.appendChild(elTrackback);
 var elBlogIt = document.createElement("textarea");
 elBlogIt.name = "BlogIt";
 elBlogIt.value = "true";
 f.appendChild(elBlogIt);
 if (document.all["doTrackback"]!=null)
 document.all.doTrackback.outerHTML = "";
 var elF = document.body.appendChild(f);
 elF.submit();
 }
}
function DisplayPopup(el)
{
 var elPop = el.nextSibling;
 while (elPop.nodeType==3)
 elPop = elPop.nextSibling;
 if (elPop.style.display=="block")
 elPop.style.display = "none";
 else
 {
 // put the popup a little down
 elPop.style.top = el.offsetHeight + 4 + "px";
 elPop.style.right = el.offsetLeft + "px";
 elPop.style.display = "block";
 }
}
function SwitchAssistanceTab(Selected, fVisitor, helpUrl)
{
 if("Help" == Selected.id)
 {
 document.getElementById("LearnContainer").style.display = "none";
 document.getElementById("HelpContainer").style.display = "";
 document.getElementById("LearnTab").className = "mainsel";
 document.getElementById("HelpTab").className = "mainseltab";
 }
 else if("Learn" == Selected.id)
 {
 document.getElementById("HelpContainer").style.display = "none";
 document.getElementById("LearnContainer").style.display = "";
 document.getElementById("LearnTab").className = "mainseltab";
 document.getElementById("HelpTab").className = "mainsel";
 }
 else if("CloseAssistance" == Selected.id)
 {
 document.getElementById("AssistanceContainer").style.display = "none";
 }
 else if("OpenAssistance" == Selected.id)
 {
 document.getElementById("AssistanceContainer").style.display = "";
 }
 if("True" == fVisitor)
 {
 document.cookie = "VisitorAssistanceState=" + Selected.id;
 }
 else if(("Help" == Selected.id) || ("Learn" == Selected.id))
 {
 document.cookie = "AssistanceState=" + Selected.id;
 }
 else
 {
 var d = new Date();
 d.setFullYear(d.getFullYear() + 1)
 document.cookie = "AssistanceState=" + Selected.id + "; expires=" + d.toGMTString();
 }
}
function BindMAPControlsToAssistanceContainer(baseUrl,control,helpContext,market,divId)
{
 document.getElementById(divId).innerHTML = GetHelpControlAsync(baseUrl,control,helpContext,market );
}
function GetHelpControlAsync(baseUrl,control,helpContext,market)
{
 return XMLHttp('', baseUrl + "helpasync.aspx?control=" + control + "&context=" + helpContext + "&market=" + market, true);
}
function ScaleImageContactImage(img)
{
 window.setTimeout(function() { ScaleImageContactImageCb(img); }, 1);
}
function ScaleImageContactImageCb(img)
{
 if (null != img)
 {
 var unscaledImage = new Image();
 unscaledImage.src = img.src;
 if (null == unscaledImage.width || 0 == unscaledImage.width || null == unscaledImage.height || 0 == unscaledImage.height || 0 == img.width || 0 == img.height)
 {
 // unscaled image has 0 or undefined for width and/or height, return to avoid div by 0 and 0 dimensioned images
 return;
 }
 var scale = Math.min( (img.width / unscaledImage.width),
 (img.height / unscaledImage.height) );
 // calculate the new width and height
 var newWidth = (scale * unscaledImage.width);
 var newHeight = (scale * unscaledImage.height);
 // calculate how far we need to bump the image to the left or from the top to get a "centered" look
 var leftInc = (img.width - newWidth) / 2;
 var topInc = (img.height - newHeight) / 2;
 // The following code changes style attributes applied to the image. Changing the image attributes itself does not
 // alter the image because CSS overrides it.
 // Place all of this in a try...catch so script errors don't propagate (since this is a late change in the cycle).
 // In case of exception, the image may be distorted
 try
 {
 // set the scaled width and height
 img.style.width = newWidth + "px";
 img.style.height = newHeight + "px";
 // set the top and left padding for "centered" appearance
 var par = img.parentNode;
 var num;
 if (null != par)
 {
 num = parseInt(par.style.paddingTop);
 par.style.paddingTop = (isNaN(num) ? 0 : num) + topInc + "px";
 num = parseInt(par.style.paddingLeft);
 par.style.paddingLeft = (isNaN(num) ? 0 : num) + leftInc + "px";
 }
 }
 catch(e)
 {
 }
 }
}
