String.prototype.substitute=function(was,becomes){return this.split(was).join(becomes)};String.prototype.titleCase=function(){var text=this.split("");text[0]=text[0].toUpperCase();return text.join("")};String.prototype.escape=function(){var text=URLDecode(this),__specials__="\"'()[]{}\\".split(""),__sre__=new RegExp("(\\"+__specials__.join("|\\")+")","g"),newText=text.replace(__sre__,"\\$1");newText=newText.substitute("<","&lt;").substitute(">","&gt;");newText=newText.substitute("'","").substitute('"',"");return newText};function URLDecode(psEncodeString){var lsRegExp=/\+/g;return unescape(String(psEncodeString).replace(lsRegExp," "))}String.prototype.cleanTitle=function(){return URLDecode(this).replace(new RegExp("[\\r\\n\"'/?!@#;|%^&*(){}]","g"),"")};var token,entitiesString,evalCode="",appMask="<tr id=\"{0}\" onmouseover=\"showControls(this);\" onmouseout=\"hideControls(this);\"><td><span class=\"appButtons\"><span class='appButton editApp' onclick=\"createPopup('edit_app_{0}', 450, null, getLocalApp({0}).name.cleanTitle());\"></span><span class='appButton deleteApp' onclick=\"createPopup('delete_app_{0}', 300, null, getLocalApp({0}).name.cleanTitle());\"></span><span class='appButton permApp' onclick=\"createPopup('edit_security_{0}', 450, null, getLocalApp({0}).name.cleanTitle());\"></span></span><div class=\"appLinks\" onclick=\"showEntities(this);\">{1}</div><span id='{0}_details' style=\"display:none;\"><p>{2}</p><div class=\"listHeader\"><span id='{0}_EntityListRefresh' class='edit-refresh spriteImages' onclick='populateEntityList({0})' style='right:13px; top:4px' ></span>Tables<div class=\"newEntity\" onclick=\"createPopup('new_entity_{0}', 450, {0}, 'In ' + getLocalApp({0}).name.cleanTitle());\">New</div></div><ul class='listBody' id=\"{0}_EntitiesList\"></ul><div class='appBottom'></div></span></td></tr>",favMask="<span class='appButton favApp' onclick=\"favoriteApp({0});\"></span>",unfavMask="<span class='appButton unfavApp' onclick=\"createPopup('delete_favorite_{0}', 300, null, getLocalApp({0}).name.cleanTitle());\"></span>",favAppMask='<tr id="{1}" onmouseover="showControls(this);" onmouseout="hideControls(this);"><td><span class="appButtons"><span class=\'appButton editApp\' onclick="createPopup(\'edit_app_{0}\', 450, null, getLocalApp({0}).name.cleanTitle());"></span>{4}</span><div class="appLinks" onclick="showEntities(this);">{2}</div><span id=\'{1}_details\' style="display:none;"><p>{3}</p><div class="listHeader"><span id=\'{1}_EntityListRefresh\' class=\'edit-refresh spriteImages\' onclick="populateEntityList(\'{1}\')" style=\'right:13px; top:4px\' ></span>Entities<div class="newEntity" onclick="createPopup(\'new_entity_{0}\', 450, {0}, getLocalApp({0}).name.cleanTitle());">New</div></div><ul class=\'listBody\' id="{1}_EntitiesList"></ul><div class=\'appBottom\'></div></span></td></tr>',entityMask="<li id='{0}' onmouseover='showControls(this);' onmouseout='hideControls(this);'><span class='entityButtons'><span class='entityButton editEntity' onclick=\"createPopup('edit_entity_{0}', 450, '{3}', '{1}');\"></span><span class='entityButton deleteEntity' onclick=\"createPopup('delete_entity_{0}', 300, {3}, '{1}');\"></span><span class='entityButton permEntity' onclick=\"createPopup('edit_security_{0}', 450, {3}, '{1}');\"></span></span><div class='appLinks smallList' onclick=\"createPopup('view_entity_{0}', 450, {3}, '{1}');\">{2}</div></li>",colMask="<li id='{0}' onmouseover='showControls(this);' onmouseout='hideControls(this);' class='colLiHeight'><span class='entityButtons' style=''><span class='entityButton editEntity' onclick=\"createPopup('edit_column_{0}', 450, '{2}_{3}', '{1}');\"></span><span class='entityButton deleteEntity' onclick=\"createPopup('delete_column_{0}', 300, '{2}_{3}', '{1}');\"></span><span class='entityButton permEntity' onclick=\"createPopup('edit_security_{0}', 450, '{2}_{3}', '{1}');\"></span></span><span class='entityButtons'><div class='moveUp' onClick='moveColumn({2},{3},{0}, -1);'></div><div class='moveDown' onClick='moveColumn({2},{3},{0}, 1);'></div></span><div class='appLinks smallList' style='cursor:default; white-space:nowrap;'>{1}</div></li>",inviteMask="<li id='{0}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px;'><span class='entityButtons' style='position:absolute; right:20px;'><span class='entityButton deleteEntity' onclick=\"uninviteUser('{1}');\"></span><span class='entityButton resendInvite' onclick=\"reinviteUser('{1}');\"></span></span><div class='appLinks' style='cursor:default; width:1px; left:20px; right:50px; position:absolute;white-space:nowrap;'>{1}</div></li>",servicesListMask="<li id='{0}{3}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px;'><span class=\"entityButtons\"><span class='entityButton deleteEntity' onclick=\"createPopup('delete_webservices_{0}x{3}', 425, '{0}x{3}', '{1}');\"></span></span><div class='appLinks' style='cursor:default; white-space:nowrap;'>{0}<a href=\"{2}\" target=\"_blank\">{1}</a></div></li>",tablesMask="<li id='{0}_{3}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px;'><div class='appLinks' style='cursor:default; width:1px; left:8px; right:50px; white-space:nowrap;'><input id='importTable_{0}_{3}' type='checkbox' onClick=\"importTableClick(this, {3})\" style='margin-left:8px; margin-right:30px; ' /><input style='margin-right:20px;' disabled='disabled' id='importData_{0}_{3}' type='checkbox' /> {1} ({2})</div></li>",tablesMaskNoData="<li id='{0}_{3}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px;'><div class='appLinks' style='cursor:default; width:1px; left:8px; right:50px; white-space:nowrap;'><input id='importTable_{0}_{3}' type='checkbox' onClick=\"importTableClick(this, {3})\" style='margin-left:8px; margin-right:30px; ' />N/A &nbsp; &nbsp;&nbsp; {1} ({2})</div></li>",roleMask="<li id='{0}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px; cursor:pointer'><span class='entityButtons' style=''><span class='entityButton deleteEntity' onclick=\"createPopup('delete_role_{0}', 300, '{1}', '{2}');\"></span></span><div class='appLinks' onClick=\"show_users_for_role({1}, {0}, '{2}'); \" style='width:90%; white-space:nowrap;'>{2}</div></li>",roleMemberMask="<li id='{1}{2}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px; cursor:pointer'><span class='entityButtons' style='position:absolute; right:20px;'><span class='entityButton deleteEntity' onclick=\"createPopup('delete_rolemember_{1}{2}', 300, '{0}_{1}_{2}', '{3}');\"></span></span><div class='appLinks' style='width:1px; left:20px; right:50px; white-space:nowrap;'>{3}</div></li>",appliedRoleMask="<li id='{0}_{1}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px; cursor:pointer'><div class='appLinks' onClick=\"show_permissions_for_principal('{0}', {1}, {2}, '{4}');\" style='width:90%; white-space:nowrap;'>{3}</div></li>",appliedRoleMaskWithDelete="<li id='{0}_{1}' onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px; cursor:pointer'><span class='entityButtons' style=''><span class='entityButton deleteEntity' onclick=\"createPopup('delete_security_{0}', 300, '{1}_{2}_{4}', '{3}');\"></span></span><div class='appLinks' onClick=\"show_permissions_for_principal('{0}', {1}, {2}, '{4}');\" style='width:90%; white-space:nowrap;'>{3}</div></li>",appliedPermMask="<li onmouseover='showControls(this);' onmouseout='hideControls(this);' style='height:23px; cursor:pointer; width:100%;'><span class='entityButtons' style=''><input class='entityButton deleteEntity' type='checkBox' style='margin-right:20px; background-image: none;' id='deny_{0}_{1}_{2}'{5} /><input class='entityButton deleteEntity' type='checkBox' style='margin-right:45px; background-image: none;' id='allow_{0}_{1}_{2}'{4} /></span><div class='appLinks' style='width:90%; white-space:nowrap;'>{3}</div></li>",apps=[];function uninviteUser(email){if(confirm("Are you sure you want to cancel the invitation you sent to "+email)){var user={};user.email=email;CloudDB.Web.Services.CDBridge.UninviteUser(token,user,uninviteUserComplete)}}function uninviteUserComplete(resp){if(resp.Succeeded==true){var exdate=new Date;exdate.setDate(exdate.getDate()+14);exp=exdate.toGMTString();var mask="{0}={1};expires={2}";document.cookie=String.format(mask,"invites",resp.NumInvites,exp);CloudDB.Web.Services.CDBridge.ListInvites(token,listInvitesComplete,showError)}else showError(resp.Outcome.Message)}function reinviteUser(email){if(confirm("This action will make the current invitation to "+email+" invalid. To continue, click OK, enter a new message, and click Invite. To keep the existing invite active, click Cancel.")){var user={};user.email=email;CloudDB.Web.Services.CDBridge.UninviteUser(token,user,uninviteUserComplete);$get("InviteEmail").value=email;$get("InviteMessage").focus()}}function getCrumbValue(crumbName){chunks=document.cookie.split("; ");if(chunks.length>1)for(i=0;i<chunks.length;++i){idx=chunks[i].indexOf("=");curCrumbName=chunks[i].substring(0,idx);if(curCrumbName==crumbName)return chunks[i].substring(idx+1)}}function inviteUser(email,msg){var user={};if(email.indexOf(";")>=0||email.indexOf(",")>=0){var context={},sSplit=email.split(";"),emails=[];for(var i in sSplit){var cSplit=sSplit[i].split(",");for(var j in cSplit)cSplit[j]!=""&&cSplit[j]!=" "&&emails.push(cSplit[j])}user.email=emails[emails.length-1];context.emails=emails;context.message=msg;context.errors=[];var numInvites=getCrumbValue("invites");numInvites<emails.length&&alert("You are trying to invite "+emails.length+" people, but you only have "+numInvites+" invites left!");CloudDB.Web.Services.CDBridge.InviteUser(token,user,{},0,msg,inviteUsersWithArray,showError,context)}else{user.email=email;CloudDB.Web.Services.CDBridge.InviteUser(token,user,{},0,msg,inviteUserComplete,showError)}}function inviteUsersWithArray(resp,context){!resp.Outcome.Succeeded&&context.errors.push(context.emails[context.emails.length-1]);context.emails.pop();if(context.emails.length==0){context.errors.length>0&&alert("These users were not succesfully invited: "+context.errors.toString());$get("InviteEmail").value=$get("InviteMessage").value="";var exdate=new Date;exdate.setDate(exdate.getDate()+14);exp=exdate.toGMTString();var mask="{0}={1};expires={2}";document.cookie=String.format(mask,"invites",resp.NumInvites,exp);CloudDB.Web.Services.CDBridge.ListInvites(token,listInvitesComplete,showError)}else{var user={};user.email=context.emails[context.emails.length-1];CloudDB.Web.Services.CDBridge.InviteUser(token,user,{},0,context.message,inviteUsersWithArray,showError,context)}}function inviteUserComplete(resp){if(resp.Outcome.Succeeded==true){$get("InviteEmail").value=$get("InviteMessage").value="";var exdate=new Date;exdate.setDate(exdate.getDate()+14);exp=exdate.toGMTString();var mask="{0}={1};expires={2}";document.cookie=String.format(mask,"invites",resp.NumInvites,exp);CloudDB.Web.Services.CDBridge.ListInvites(token,listInvitesComplete,showError)}else showError(resp.Outcome.Message)}function listInvitesComplete(resp){var pendingList="";for(i in resp.Results)pendingList+=String.format(inviteMask,resp.Results[i].toUser,resp.Results[i].email);$get("pendingInvites").innerHTML=pendingList;var numInvites=getCrumbValue("invites");if(numInvites==1)numInvites+=" Invite";else numInvites+=" Invites";$get("InvitePanelLink").innerHTML=numInvites}function registerUser(email,code,notes){CloudDB.Web.Services.Internal.RegisterForBeta(email,code,notes,registerUserComplete,showError)}function registerUserComplete(){alert("Thank you. We will be in touch with you shortly.");tabClick({target:$get("RegisterPanelLink")});$get("RegNotes").value="";$get("RegCode").value="";$get("RegEmail").value=""}function Login(email,pwd){CloudDB.Web.Services.CDBridge.LogIn(email,pwd,loginComplete,showError)}function Logout(runOnComplete){CloudDB.Web.Services.CDBridge.LogOut(token,logoutComplete,showError,runOnComplete)}function checkForCookie(){chunks=document.cookie.split("; ");var noCookie=chunks.length<3;if(chunks.length>2){token={};for(i=0;i<chunks.length;++i){idx=chunks[i].indexOf("=");crumbName=chunks[i].substring(0,idx);crumb=chunks[i].substring(idx+1);if(crumb=="")noCookie=true;switch(crumbName){case "sessionID":if(crumb||crumb!=undefined){token.SessID=crumb;break}else{noCookie=true;break}case "priRole":token.PriRole=crumb;break;case "primaryServer":token.PriSrv=crumb;break;case "userID":token.UserID=crumb;break;case "handle":token.Handle=crumb;break;case "signature":token.Signature=crumb}}}if(noCookie){var newAppButton=$get("newAppButton");$clearHandlers(newAppButton);$addHandler(newAppButton,"click",showLoginTab);AppPopup.style.left="-360px";AppExpand.style.left="51px";AppIcon.style.backgroundPosition="0px 1620px";isAppCollapsed=true;var settingsTab=$get("SettingsPanelLink");settingsTab.style.visibility="hidden";settingsTab.style.display="none"}else loginPopulate(false,getCrumbValue("invites"))}function logoutComplete(result,runOnComplete){$get("AppContent").innerHTML='<table cellpadding="0" width=\'100%\' cellspacing="0" class="appsList" id="searchResultsTable"><tbody><tr><td><input style="width: 70%" type="text" id="searchKeywords" onkeydown="if(event.keyCode==13){ searchApps($get(\'searchKeywords\').value); return false;}" /><input type="button" value="Search" onclick="searchApps($get(\'searchKeywords\').value)" /></td></tr></table>';setTimeout(sizeAppPanel,0);appClose();var settingsTab=$get("SettingsPanelLink");settingsTab.style.visibility="hidden";settingsTab.style.display="none";var registerTab=$get("RegisterPanelLink");registerTab.style.visibility="visible";registerTab.style.display="block";var inviteTab=$get("InvitePanelLink");inviteTab.style.display="none";var loginTab=$get("LoginPanelLink");loginTab.innerHTML="Login";$get("loggedInText").innerHTML="";var newAppButton=$get("newAppButton");$clearHandlers(newAppButton);$addHandler(newAppButton,"click",showLoginTab);activeTab&&tabClick({target:activeTab});$clearHandlers(loginTab);$addHandler(loginTab,"click",tabClick);var exdate=new Date;exdate.setDate(exdate.getDate()+14);document.cookie="sessionID=; expires="+exdate.getDate();document.cookie="priRole=; expires="+exdate.getDate();document.cookie="primaryServer=; expires="+exdate.getDate();document.cookie="userID=; expires="+exdate.getDate();document.cookie="handle=; expires="+exdate.getDate();document.cookie="signature=; expires="+exdate.getDate();document.cookie="invites=; expires="+exdate.getDate();YAHOO.example.container.manager.hideAll();if(runOnComplete)eval(runOnComplete)}function loginComplete(resp){if(resp.Outcome.Succeeded==false)alert("Please Try again!");else{token=resp.Result;$get("bg").style.display="none";$get("tbPassword").value=$get("tbEmail").value="";loginPopulate(true,resp.NumInvites)}}function loginPopulate(populateCookie,NumInvites){var registerTab=$get("RegisterPanelLink");registerTab.style.visibility="hidden";registerTab.style.display="none";var settingsTab=$get("SettingsPanelLink");settingsTab.style.visibility="visible";settingsTab.style.display="block";var inviteTab=$get("InvitePanelLink");inviteTab.style.visibility="visible";var loginTab=$get("LoginPanelLink");doAnimation(loginTab,-308,true);loginTab.innerHTML="Logout";$clearHandlers(loginTab);$addHandler(loginTab,"click",Logout);var newAppButton=$get("newAppButton");$clearHandlers(newAppButton);$addHandler(newAppButton,"click",showNewAppPopup);$get("userHandle").value=token.Handle;$get("loggedInText").innerHTML="Logged In As: "+token.Handle;if(NumInvites>0){$get("InvitePanelLink").style.display="block";CloudDB.Web.Services.CDBridge.ListInvites(token,listInvitesComplete,showError)}else $get("InvitePanelLink").style.display="none";appExpand();if(populateCookie){var exp;if($get("remeberMe").checked){var exdate=new Date;exdate.setDate(exdate.getDate()+14);exp=exdate.toGMTString()}else exp="";var mask="{0}={1};expires={2}";document.cookie=String.format(mask,"sessionID",token.SessID,exp);document.cookie=String.format(mask,"priRole",token.PriRole,exp);document.cookie=String.format(mask,"primaryServer",token.PriSrv,exp);document.cookie=String.format(mask,"userID",token.UserID,exp);document.cookie=String.format(mask,"handle",token.Handle.replace("|",""),exp);document.cookie=String.format(mask,"signature",token.Signature,exp);document.cookie=String.format(mask,"invites",NumInvites,exp)}refreshApps();if(popupToCallAfterLogin!=""){eval(popupToCallAfterLogin);popupToCallAfterLogin=""}}function saveUser(){var newHandle=$get("userHandle").value,user={};user.ID=token.UserID;user.Handle=newHandle;var curPwd=$get("currentPassword").value,newPassword=$get("newPassword").value;if(newPassword!=""){var confirmNewPassword=$get("confirmNewPassword").value;if(newPassword==confirmNewPassword)user.Password=newPassword;else alert("Invalid New (or blank) password, Handle will still be updated!")}CloudDB.Web.Services.CDBridge.SaveUser(token,curPwd,user,saveUserComplete,showError)}function saveUserComplete(resp){$get("currentPassword").value=$get("newPassword").value=$get("confirmNewPassword").value="";if(resp.Outcome.Succeeded){var exdate=new Date;exdate.setDate(exdate.getDate()+14);var exp=exdate.toGMTString(),mask="{0}={1};expires={2}";$get("loggedInText").innerHTML="Logged In As: "+resp.Result.Handle;document.cookie=String.format(mask,"handle",resp.Result.Handle.replace("|",""),exp);var settingsTab=$get("SettingsPanelLink");$get("bg").style.display="none";doAnimation(settingsTab,-308,true)}else alert(resp.Outcome.Message)}function refreshApps(){CloudDB.Web.Services.CDBridge.GetApplications(token,true,true,appsComplete,showError)}function appsComplete(resp){var needFavList=false;myAppsHTML='<table id=\'myAppsList\' cellpadding="0" width=\'100%\' cellspacing="0" class="appsList" id="appsListTable"><tbody>';favAppsHTML='<table id=\'myFavList\' cellpadding="0" width=\'100%\' cellspacing="0" class="appsList" id="appsListTable"><tbody>';for(i in resp.Results){app=resp.Results[i];if(app.ownerID==token.UserID)myAppsHTML+=String.format(appMask,app.id,app.name,app.description!=""?"<p>"+app.description+"</p>":"");else{needFavList=true;favAppsHTML+=String.format(favAppMask,app.id,app.id,app.name,app.description!=""?"<p>"+app.description+"</p>":"",String.format(unfavMask,app.id))}apps.push(app)}favAppsHTML+="</tbody></table>";myAppsHTML+="</tbody></table>";var appsListHTML=new String;appsListHTML+=myAppsHTML;if(needFavList)appsListHTML+="<div class='appListHeader' onclick=\"toggleVisibility('myFavList')\"><span class='favIcon spriteImages'></span><span style='padding-left:5px;'>Favorites</span></div>"+favAppsHTML;appsListHTML+="<div class='appListHeader' onclick=\"toggleVisibility('searchResultsTable')\"><span class='searchIcon spriteImages'></span><span style='padding-left:3px;'>Search</span></div>";appsListHTML+=$get("searchResultsTable").outerHTML;var appC=$get("AppContent");appC.innerHTML=appsListHTML;setTimeout(sizeAppPanel,0)}function sizeAppPanel(noRepeat){var appC=$get("AppContent");appC.style.width=eval(appC.style.width.substring(0,appC.style.width.length-2))+100+"px";appC.style.width=eval(appC.style.width.substring(0,appC.style.width.length-2))-100+"px";appC.scrollLeft++;appC.scrollTop++;var d=0;if(appC.scrollLeft>0&&appC.scrollTop>0)d=3;else if(appC.scrollLeft>0)d=1;else if(appC.scrollTop>0)d=2;appC.scrollLeft--;appC.scrollTop--;d==0&&noRepeat!=true&&sizeAppPanel(true)}function toggleVisibility(elementID){var elementStyle=$get(elementID).style;if(elementStyle.display=="none"){if(document.all)elementStyle.display="block";else elementStyle.display="table";elementID=="searchResultsTable"&&$get("searchKeywords").focus()}else elementStyle.display="none";setTimeout(sizeAppPanel,0)}function showEntities(div){entitiesString=null;var appRow=div.parentNode.parentNode,thisApp=$get(appRow.id+"_details"),divStyle=thisApp.style;if($get(appRow.id+"_EntitiesList").childNodes.length==0){appRow.className="selectedRowBackground";div.className="appGradient";divStyle.display="block";populateEntityList(appRow.id)}else{if(divStyle.display=="none"){appRow.className="selectedRowBackground";div.className="appGradient";divStyle.display="block"}else{appRow.className="";div.className="appLinks";divStyle.display="none"}setTimeout(sizeAppPanel,0)}}function searchApps(keywordString){if(keywordString!=""){for(var inPhrase=false,keywords=[],phrase=new String,c=0;c<keywordString.length;c++){var curChar=keywordString.charAt(c);if(curChar!='"'&&curChar!=" ")phrase+=curChar;else if(curChar=='"')inPhrase=!inPhrase;if(curChar==" ")if(!inPhrase){keywords.push(phrase);phrase=""}else phrase+=curChar;c==keywordString.length-1&&keywords.push(phrase)}CloudDB.Web.Services.CDBridge.SearchApplications(token,keywords,false,false,searchAppsComplete,showError)}else alert("Please enter at least one keyword")}function searchAppsComplete(resp){var searchTerm=$get("searchKeywords").value,searchResultsTable=$get("searchResultsTable");searchResultsTable.parentNode.removeChild(searchResultsTable);var searchResultsHTML=new String;searchResultsHTML+='<table cellpadding="0" width=\'100%\' cellspacing="0" class="appsList" id="searchResultsTable"><tbody><tr><td><input style="width: 70%" type="text" id="searchKeywords" onkeydown="if(event.keyCode==13){ searchApps($get(\'searchKeywords\').value); return false;}" /><input type="button" value="Search" onclick="searchApps($get(\'searchKeywords\').value)" /></td></tr>';if(resp.Results.length>0)for(var r=0;r<resp.Results.length;r++){var curApp=resp.Results[r];apps.push(curApp);searchResultsHTML+=String.format(favAppMask,curApp.id,curApp.id,curApp.name,curApp.description!=""?"<p>"+curApp.description+"</p>":"",String.format(favMask,curApp.id))}else searchResultsHTML+='<tr id="{1}" onmouseover="showControls(this);" onmouseout="hideControls(this);"><td><div class="appLinks">No Results</div></td></tr>';searchResultsHTML+="</table>";$get("AppContent").innerHTML+=searchResultsHTML;setTimeout(sizeAppPanel,0);var searchTerm=$get("searchKeywords");searchTerm.focus();searchTerm.focus()}function favoriteApp(appID){CloudDB.Web.Services.CDBridge.AddFavoriteApplication(token,{id:appID},favoriteApp_complete,showError,appID)}function favoriteApp_complete(resp,appID){refreshApps();$get(appID.toString()).parentNode.removeChild($get(appID.toString()))}function moveColumn(appID,entID,colID,offset){$get("edit_entity_"+entID+"_refreshIcon").className="edit-refresh-spinning";var context={appID:appID,entID:entID};CloudDB.Web.Services.CDBridge.MoveColumn(token,{id:appID},{id:entID},{id:colID},offset,moveColumnComplete,showError,context)}function moveColumnComplete(resp,context){populateColList(context.appID,context.entID)}function populateColList(appID,entID,updateAlias){var context=[appID,entID,updateAlias];CloudDB.Web.Services.CDBridge.GetColumns(token,{id:appID},{id:entID},getColsComplete,showError,context)}function getColsComplete(resp,context){var appID=context[0],entID=context[1],colsTable=$get(entID+"_Columns");if($get("edit_entity_"+entID)){var colString,newColMask,noColumnsLI=$get(entID+"_noColumns"),noColumnsLIHTML=noColumnsLI.outerHTML;if(resp.Result.length==0){noColumnsLI.style.display="block";noColumnsLI.innerHTML="Click to add a column";colsTable.innerHTML=$get(entID+"_noColumns").outerHTML;$get(entID+"_EntAliasRow").style.visibility="hidden"}else{colString="";for(i in resp.Result)colString+=String.format(colMask,resp.Result[i].id,resp.Result[i].name,appID,entID);colString+=noColumnsLIHTML;colsTable.innerHTML=colString;$get(entID+"_noColumns").style.display="none";$get(entID+"_EntAliasRow").style.visibility="visible"}if(context[2])eval("refresh_edit_entity("+entID+", "+appID+", true)");$get("edit_entity_"+entID+"_refreshIcon").className="edit-refresh";sizePanelToScreen("edit_entity_"+entID)}}!document.all&&HTMLElement.prototype.__defineGetter__("outerHTML",function(){for(var attrs=this.attributes,str="<"+this.tagName,i=0;i<attrs.length;i++)str+=" "+attrs[i].name+'="'+attrs[i].value+'"';return str+">"+this.innerHTML+"</"+this.tagName+">"});function populateEntityList(appID){$get(appID+"_EntityListRefresh").className="edit-refresh-spinning";try{CloudDB.Web.Services.CDBridge.GetEntities(token,{id:appID},getEntitiesComplete,showError,{appID:appID})}catch(e){showError(e)}}function getEntitiesComplete(resp,context){var appID=context.appID,entitiesString="";if(resp.Results.length>0)for(i in resp.Results)entitiesString+=String.format(entityMask,resp.Results[i].id,resp.Results[i].name.escape(),resp.Results[i].name,appID);else{var app=getLocalApp(appID);entitiesString="<li><div class=\"appLinks\" onClick=\"createPopup('new_entity_{0}', 450, {0}, 'Create a new table in {1}')\">Click to create a new table</div></li>";entitiesString=String.format(entitiesString,appID,app.name.escape())}$get(appID.toString()+"_EntitiesList").innerHTML=entitiesString;$get(appID.toString()+"_EntityListRefresh").className="edit-refresh spriteImages";setTimeout(sizeAppPanel,0)}function getLocalApp(appID){var app;for(i in apps)if(apps[i].id==appID)app=apps[i];return app}function saveFormBuilderRow(appID,entID,rowID,cols,callback,withPopup){var ds={};ds.Name="CloudDB_"+entID;ds.Columns=[];ds.Rows=[];var fieldArray=[];for(var c in cols){var cellID=cols[c].InputName,newColumn={};newColumn.id=parseContext(cellID)[3];newColumn.entityID=entID;ds.Columns.push(newColumn);var cellKind=cols[c].Kind,cell=$get(cellID);if(cell!=null&&typeof cell=="object"){cellValue=cell.value;if(cellKind==6)cellValue=cell.checked;if(cellKind==64&&cellValue=="")cellValue=null;if(cellKind==2&&cellValue=="")cellValue=0;if(cellKind==3&&cellValue=="")cellValue=null}else cellValue=null;fieldArray.push(cellValue)}var pkCol={};pkCol.kind="rowID";pkCol.entityID=entID;ds.Columns.push(pkCol);fieldArray.push(rowID);var row={};row.Fields=fieldArray;ds.Rows.push(row);CloudDB.Web.Services.CDBridge.SaveRows(token,{id:appID},ds,callback,showError,withPopup)}function showError(error){if(typeof error=="string")alert(error);else alert(error._message)}function getTemplate(name,panel,templateContext){var panelInt=parsePanelID(panel.id);if(panelInt.action=="new"&&panelInt.objectType=="row")panelInt.objectID=0;var context={};context.panel=panel;if(templateContext==null)templateContext=new String;context.templateContext=templateContext;var tempToken=token;if(getCrumbValue("invites")==undefined||getCrumbValue("invites")=="")tempToken={};CloudDB.Web.Services.Internal.GetTemplate(tempToken,name,panelInt.objectID,templateContext.toString(),onGetTemplateComplete,showError,context)}function onGetTemplateComplete(result,context){var panel=context.panel;result[0]=String.format(popupBodyMask,result[0],panel.id);panel.setBody(result[0]);sizePanelToScreen(panel.id);var scriptID=panel.id+"_script";if(result[1]&&!document.getElementsByTagName("script")[scriptID]){var panelIDParts=parsePanelID(panel.id),headID=document.getElementsByTagName("head")[0],newScript=document.createElement("script");newScript.id=scriptID;newScript.text=result[1];headID.appendChild(newScript)}populatePopup(panel.id,context)}function importTableClick(checkbox,appID){checkbox.nextSibling.disabled=!checkbox.checked;if(checkbox.checked)checkbox.nextSibling.checked=$get("checkAllData"+appID).checked}function getTablesList(appID){for(var t in publicTablesArray)if(publicTablesArray[t].appID==appID)return publicTablesArray[t].tablesList}function checkAllImports(checkboxAll,appID){tablesList=getTablesList(appID);for(t in tablesList){var importCheckbox=$get("importTable_"+t+"_"+appID);importCheckbox.checked=checkboxAll.checked;if(checkboxAll.checked){if(importCheckbox.nextSibling.tagName=="INPUT")importCheckbox.nextSibling.disabled=false}else importCheckbox.nextSibling.disabled=true}}function checkAllData(checkboxAll,appID){tablesList=getTablesList(appID);var isEnabled=false;for(t in tablesList){var dataCheckbox=$get("importData_"+t+"_"+appID);if(dataCheckbox){dataCheckbox.checked=checkboxAll.checked;isEnabled=true}}if(!isEnabled)return false}function parsePanelID(panelID){var panelIDParts={},optionsArray=panelID.toString().split("_");panelIDParts.action=optionsArray[0].toLowerCase();panelIDParts.objectType=optionsArray[1].toLowerCase();panelIDParts.objectID=optionsArray[2].toLowerCase();return panelIDParts}function parseContext(context){return context.toString().split("_")}function viewSubgridData(appID,entID,pageNumber,popupID,parentElement,predColID,predValue,linkElement){var parent=$get(parentElement);if(parent.innerHTML==""){linkElement.parentNode.childNodes[0].childNodes[0].className+=" collapseEntity";linkElement.parentNode.childNodes[1].style.display="block";linkElement.parentNode.className+=" childLabelExpanded";viewData(appID,entID,pageNumber,popupID,parentElement,predColID,predValue)}else if(parent.style.display=="block"||parent.style.display==""){removeClass(linkElement.parentNode.childNodes[0].childNodes[0],"collapseEntity");removeClass(linkElement.parentNode,"childLabelExpanded");parent.style.display=linkElement.parentNode.childNodes[1].style.display="none"}else{linkElement.parentNode.childNodes[0].childNodes[0].className+=" collapseEntity";linkElement.parentNode.className+=" childLabelExpanded";parent.style.display=linkElement.parentNode.childNodes[1].style.display="block"}}function viewData(appID,entID,pageNumber,popupID,parentElement,predColID,predValue){var newRowButton,rowsPerPage=25;if(pageNumber==undefined){var currentPage=$get("view_entity_"+entID+"_pager").currentPage;if($get("view_entity_"+entID+"_pager").currentPage)pageNumber=currentPage;else pageNumber=0;newRowButton=$get("NewRowButton_"+entID)}else newRowButton=$get("NewRowButton_"+entID+"_"+parentElement);if(newRowButton)newRowButton.style.display="none";if(parentElement==null||!parentElement)$get("view_entity_"+entID+"_refreshIcon").className="view-refresh-spinning";else $get(popupID+"_"+parentElement+"_refreshIcon").className+=" refreshSubgrid-spinning";if(token==null){var resp={};resp.Outcome={};resp.Outcome.Succeeded=true;resp.Outcome.Message="Must be logged in with permission to view this data.<br /><br />If you have recently changed your login, please use the refresh icon on this panel.";var context={};context.entID=entID;context.appID=appID;context.showError=true;viewDataComplete(resp,context)}else{var preds=[],pred={};if(predColID){pred.col={};pred.col.id=predColID,pred.col.entityID=entID;pred.value=predValue;preds.push(pred)}else pred=null;var filtersRowID=appID+"_"+entID+"_"+popupID;if(parentElement==undefined)filtersRowID+="_filters";else filtersRowID+="_"+parentElement+"_filters";var filtersRow=$get(filtersRowID),inputs=null,selects=null;if(filtersRow){inputs=filtersRow.getElementsByTagName("input");selects=filtersRow.getElementsByTagName("select");for(var s=0;s<selects.length;s++){var select={};select.id=selects[s].id;$get(select.id).disabled=true;select.value=selects[s].value;inputs[inputs.length+s]=select}for(var i=0;i<inputs.length+selects.length;i++){var input=inputs[i];$get(input.id).disabled=true;var idParts=parseContext(input.id);if(input.value!="")switch(idParts[3]){case "1":for(var words=input.value.split(" "),j=0;j<words.length;j++)words[j]!=""&&preds.push(buildPredicate(entID,parseContext(input.id)[2],3,words[j]));break;case "2":preds.push(buildPredicate(entID,parseContext(input.id)[2],3,input.value));break;case "3":var date;try{morningDate=new Date(input.value);nightDate=new Date(input.value);if(!isNaN(morningDate)&&!isNaN(nightDate)){morningDate.setHours(0);morningDate.setMinutes(0);morningDate.setSeconds(0);nightDate.setHours(23);nightDate.setMinutes(59);nightDate.setSeconds(59);preds.push(buildPredicate(entID,parseContext(input.id)[2],5,morningDate.format("dd/MM/yyyy"),idParts[3]));preds.push(buildPredicate(entID,parseContext(input.id)[2],7,nightDate.format("dd/MM/yyyy"),idParts[3]))}}catch(e){}break;case "6":input.value>=0&&preds.push(buildPredicate(entID,parseContext(input.id)[2],1,input.value));break;case "7":preds.push(buildPredicate(entID,parseContext(input.id)[2],3,input.value));break;case "64":for(var words=input.value.split(" "),j=0;j<words.length;j++)if(words[j]!=""){var fkPred={};fkPred.col={};fkPred.col.entityID=idParts[idParts.length-2];fkPred.col.kind=-2;fkPred.value=input.value;fkPred.compareType=3;preds.push(fkPred)}}}}CloudDB.Web.Services.CDBridge.SearchEntity(token,{id:appID},{id:entID},preds,0,0,rowsPerPage*pageNumber,rowsPerPage,viewDataComplete,showError,{entID:entID,appID:appID,pageNumber:pageNumber,parentElement:parentElement,predColID:predColID,predValue:predValue,popupID:popupID,inputs:inputs,selects:selects})}}function viewDataComplete(resp,context){if(!resp.Outcome.Succeeded)alert(resp.Outcome.Message);else{tableHTML='<table width="100%" class="viewDataTable viewDataTableFontSize" cellpadding="0" cellspacing="0"><tr><td width="0" class=\'dataButtons\'>&nbsp;</td>';if(resp.Results.Data.Columns.length>4){if($get("NewRowButton_"+context.entID))$get("NewRowButton_"+context.entID).style.display="block";if(context.showError)tableHTML="</tr><tr><td>"+resp.Outcome.Message+"</td></tr></table>";else{tableHTML+=generateRowHTML(resp,context);tableHTML+="</table>"}var pagerHTML="";if(resp.Pager.PageCount>1)pagerHTML=generatePagerHTML(resp,context);else pagerHTML=" ";if(context.parentElement==null&&!context.parentElement){$get("view_entity_"+context.entID+"_SM").innerHTML=tableHTML+"<br />";if(pagerHTML!=""){var pager=$get("view_entity_"+context.entID+"_pager");if(pagerHTML!=" ")pager.style.display="block";pager.innerHTML=pagerHTML;pager.currentPage=context.pageNumber}$get("view_entity_"+context.entID+"_refreshIcon").className="view-refresh"}else{if(pagerHTML!=""&&pagerHTML!=" ")$get(context.parentElement).innerHTML=tableHTML+'<div class="subPager">'+pagerHTML+"</div><br />";else $get(context.parentElement).innerHTML=tableHTML+"<br />";removeClass($get(context.popupID+"_"+context.parentElement+"_refreshIcon"),"refreshSubgrid-spinning")}}else{var title=$get("TitleBarText_"+context.entID).innerText;$get("view_entity_"+context.entID+"_SM").innerHTML="<div style='padding:8px;'>There are no columns to display. <br /> To add some columns <a href='#' onclick=\"createPopup('edit_entity_"+context.entID+"', 450, '"+context.appID+"', 'Edit "+title+"');\">edit this entity</a>, <br />and then <a href='#' onclick='viewData("+context.appID+", "+context.entID+")'>refresh this window</a>.</div>";$get("view_entity_"+context.entID+"_refreshIcon").className="view-refresh"}sizePanelToScreen(context.popupID);if(focusedInput!=null){var myinput=$get(focusedInput.id);if(myinput!=null){try{myinput.focus();myinput.focus()}catch(e){}setCaretPosition(myinput.id,myinput.value.length)}}if(evalCode!=""){eval(evalCode);evalCode=""}}}function generateRowHTML(resp,context){var entID=context.entID,appID=context.appID,output="";re=resp.Results.Data;var fkCols=[],colHeadersHTML="",filtersRowID=appID+"_"+entID+"_"+context.popupID;if(context.parentElement==undefined)filtersRowID+="_filters";else filtersRowID+="_"+context.parentElement+"_filters";var filtersHTML='<tr id="'+filtersRowID+'"><td>&nbsp;</td>';for(i=0;i<re.Columns.length;++i)if(re.Columns[i].kind>0){col=re.Columns[i];var inputID=appID+"_"+entID+"_"+col.id+"_"+col.kind,nextInputID=appID+"_"+entID+"_"+(i==re.Columns.length-1?re.Columns[3].id:re.Columns[i+1].id)+"_"+col.kind,prevInputID=appID+"_"+entID+"_"+(i==0?re.Columns[0].id:re.Columns[i-1].id)+"_"+col.kind;if(context.parentElement){inputID+="_"+context.predValue;nextInputID+="_"+context.predValue;prevInputID+="_"+context.predValue}var alreadySeenFK=false;for(var j in fkCols)if(col.foreignKeyEntityID==re.Columns[fkCols[j]].foreignKeyEntityID){alreadySeenFK=true;break}if(col.kind==64){fkCols.push(i);inputID+="_"+col.foreignKeyEntityID}inputID+="_filter";nextInputID+="_filter";prevInputID+="_filter";if(!context.predColID||context.predColID!=re.Columns[i].id){colHeadersHTML+="<th>"+col.name+"</th>";filtersHTML+="<td>";if(!alreadySeenFK){var selected,valueHTML=' value="';if(context.inputs!=null)for(var j=0;j<context.inputs.length+context.selects.length;j++)if(context.inputs[j].id==inputID){selected=context.inputs[j].value;valueHTML+=selected+" "}valueHTML=valueHTML.trim();valueHTML+='"';var parentID=context.parentElement==undefined?"undefined":"'"+context.parentElement+"'";switch(col.kind){case 6:filtersHTML+='<select  id="'+inputID+"\" OnChange=\"focusedInput = this; focusedInputLastValue = ''; executeFilter(this.value, "+parentID+", '"+context.popupID+"', "+context.predColID+", "+context.predValue+')">';filtersHTML+='<option value="-1"'+(selected==-1?' selected="true"':"")+">Any</option>";filtersHTML+='<option value="1"'+(selected==1?' selected="true"':"")+">Yes</option>";filtersHTML+='<option value="0"'+(selected==0?' selected="true"':"")+">No</option></select>";break;default:filtersHTML+="<input "+valueHTML+' style="background-color:#F2F2F2; width:80%; margin: 2px 4px;" OnKeyDown="onTextBoxKeyPress(event, this.value, '+parentID+", '"+context.popupID+"', "+context.predColID+", '"+context.predValue+"', "+col.kind+", '"+nextInputID+"', '"+prevInputID+'\');" id="'+inputID+'" type="text" OnFocus="focusedInput=this;focusedInputLastValue=this.value;" OnKeyUp="filterGrid(event, this, '+parentID+", '"+context.popupID+"', "+context.predColID+", "+context.predValue+')" />'}}else filtersHTML+="&nbsp;";filtersHTML+="</td>"}}output+=colHeadersHTML;output+="</tr>";output+=filtersHTML;output+="</tr>";for(r=0;r<re.Rows.length;++r){var rowClass;if(r%2)rowClass="oddRow";else{rowClass="evenRow";if(r==0)rowClass+=" topBorder"}var rowID=re.Rows[r].Fields[0],rowTitle=re.Rows[r].Fields[1].toString().cleanTitle();output+='<tr style="border-right:none;" id="'+context.popupID+"_"+entID+"_"+appID+"_"+rowID+'_Row" onmouseover="this.className += \' hilight\';" onmouseout="removeClass(this, \'hilight\')" class="'+rowClass+"\"><td class='dataButtons'><table style='margin-left:5px;' cellpadding='0' cellspacing='0'><tr><td style='border-right:none;'><span class='entityButton editEntity' onclick=\"createPopup('edit_row_"+rowID+"x"+entID+"', 450, '"+entID+"_"+appID+"', '"+rowTitle+"');\"></span></td><td style='border-right:none;'><span class='entityButton deleteEntity' onclick=\"createPopup('delete_row_"+rowID+"x"+entID+"', 300, '"+entID+"_"+appID+"', '"+rowTitle+"');\"></span></td><td style='border-right:none;'><span class='entityButton permEntity' onclick=\"createPopup('edit_security_"+rowID+"x"+entID+"', 400, '"+entID+"_"+appID+"_"+rowID+"', '"+rowTitle+"');\"></span></td><td style='border-right:none;'><span style='font-size: 12px;' class='entityButton expandEntity' onclick=\"showChildren("+entID+","+appID+","+rowID+","+re.Columns.length+", '"+context.popupID+"', this);\"></span></td></td></tr></table></td>";for(i=0;i<re.Rows[r].Fields.length;++i){cellData=re.Rows[r].Fields[i];if(re.Columns[i].kind>0)if(re.Columns[i].kind==6){output+='<td class="Cell" id="'+re.Rows[r].Lookup[i]+"\"><span><input type='checkbox' disabled='true' ";if(cellData)output+="checked='checked' ";output+="/></span></td>"}else{var noWrapClass="nowrap ";if(!context.predColID||context.predColID!=re.Columns[i].id){if(cellData=="")cellData="&nbsp;";else if(cellData!=null)if(cellData.length>50){noWrapClass="";cellData='<table cellpadding="0" cellspacing="0" class="viewDataTableFontSize" width="100%"><tr><td style="border:none;"><div class="nowrap" onclick="this.nextSibling.style.display = \'block\'; this.parentNode.removeChild(this);">'+cellData.substring(0,50)+'...</div><div style="white-space: normal; overflow: auto; height:100px; display:none;">'+cellData+"</div></td></tr></table>"}output+='<td class="'+noWrapClass+'Cell" id="'+re.Rows[r].Lookup[i]+'"><span>'+cellData+"</span></td>"}}}output+="</tr>"}return output}function generatePagerHTML(resp,context){var entID=context.entID,appID=context.appID,pagerHTML="",subGridExtras="";if(context.parentElement!=null)subGridExtras=", '"+context.popupID+"', '"+context.parentElement+"', "+context.predColID+", "+context.predValue;if(resp.Pager.PageCount<=10)for(var p=0;p<resp.Pager.PageCount;p++)if(p!=context.pageNumber)pagerHTML+=createPagerLink(p,p+1,appID,entID,subGridExtras,context.popupID);else pagerHTML+=" "+(p+1)+" ";else{if(context.pageNumber==0)pagerHTML+="<< First &nbsp; < Prev ";else{pagerHTML+=createPagerLink(0,"<< First ",appID,entID,subGridExtras,context.popupID);pagerHTML+=createPagerLink(context.pageNumber-1," < Prev ",appID,entID,subGridExtras,context.popupID)}pagerHTML+=createPagerDropDown(context.pageNumber,resp.Pager.PageCount,appID,entID,subGridExtras,context.popupID);if(context.pageNumber==resp.Pager.PageCount-1)pagerHTML+=" Next > &nbsp; Last >>";else{pagerHTML+=createPagerLink(context.pageNumber+1," Next > ",appID,entID,subGridExtras,context.popupID);pagerHTML+=createPagerLink(resp.Pager.PageCount-1," Last >> ",appID,entID,subGridExtras,context.popupID)}}return pagerHTML}function createPagerLink(pageNumber,linkText,appID,entID,subGridExtras,popupID){if(subGridExtras=="")return "&nbsp;<a href='#' onClick=\"viewData("+appID+","+entID+","+pageNumber+", '"+popupID+"');\">"+linkText+"</a>&nbsp;";else return "&nbsp;<a href='#' onClick=\"viewData("+appID+","+entID+","+pageNumber+subGridExtras+');">'+linkText+"</a>&nbsp;"}function createPagerDropDown(pageNumber,numberOfPages,appID,entID,subGridExtras){var ddlHTML="";if(subGridExtras=="")ddlHTML="<select onchange='viewData("+appID+","+entID+", this.selectedIndex)'>";else ddlHTML='<select onchange="viewData('+appID+","+entID+", this.selectedIndex"+subGridExtras+')">';for(var p=0;p<numberOfPages;p++)if(p==pageNumber)ddlHTML+="<option value='"+p+"' selected='selected'>"+(p+1)+"</option>";else ddlHTML+="<option>"+(p+1)+"</option>";ddlHTML+="</select>";return ddlHTML}function showChildren(entID,appID,rowID,numOfCols,popupID,button){if(!checkForClass(button,"loadingChildren")){var rowChildren=$get(popupID+"_"+entID+"_"+appID+"_"+rowID+"_expandedRow");if(!rowChildren){button.className+=" loadingChildren";CloudDB.Web.Services.CDBridge.GetRelationships(token,{id:appID},{id:entID},getRelationshipsComplete,showError,{appID:appID,entID:entID,rowID:rowID,numOfCols:numOfCols,button:button,popupID:popupID})}else if(rowChildren.style.display=="block"||rowChildren.style.display==""){for(var recordTr=$get(popupID+"_"+entID+"_"+appID+"_"+rowID+"_Row"),i=0;i<recordTr.childNodes.length;i++){removeClass(recordTr.childNodes[i],"topBorder");removeClass(recordTr.childNodes[i],"bottomBorder")}removeClass(button,"collapseEntity");removeClass(button.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode,"expandedRow");rowChildren.style.display="none"}else{for(var recordTr=$get(popupID+"_"+entID+"_"+appID+"_"+rowID+"_Row"),i=0;i<recordTr.childNodes.length;i++)recordTr.childNodes[i].className+=" topBorder bottomBorder";button.className+=" collapseEntity";button.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=" expandedRow";rowChildren.style.display=""}}}function getRelationshipsComplete(resp,context){removeClass(context.button,"loadingChildren");for(var childrenRels=[],i=0;i<resp.Results.length;i++)resp.Results[i].fk.foreignKeyEntityID==context.entID&&childrenRels.push(resp.Results[i]);if(childrenRels.length>0&&context.button){context.button.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.className+=" expandedRow";context.button.className+=" collapseEntity";for(var recordTr=$get(context.popupID+"_"+context.entID+"_"+context.appID+"_"+context.rowID+"_Row"),i=0;i<recordTr.childNodes.length;i++)recordTr.childNodes[i].className+=" topBorder bottomBorder";recordTr.className+=" bottomBorder topBorder";var tableTr=document.createElement("TR");tableTr.className="expandedRow";tableTr.id=context.popupID+"_"+context.entID+"_"+context.appID+"_"+context.rowID+"_expandedRow";var newTd=document.createElement("TD");newTd.style.padding="10px 10px 0 20px";newTd.colSpan=context.numOfCols+1;newTd.innerHTML='<table width="100%" cellspacing="0"><tbody id="'+context.popupID+"_"+context.entID+"_"+context.appID+"_"+context.rowID+'_RowChildren"></tbody></table>';tableTr.appendChild(newTd);if(recordTr.nextSibling)recordTr.parentNode.insertBefore(tableTr,recordTr.nextSibling);else recordTr.parentNode.appendChild(tableTr);for(var thisTable=$get(context.popupID+"_"+context.entID+"_"+context.appID+"_"+context.rowID+"_RowChildren"),i=0;i<childrenRels.length;i++){var labelTr=document.createElement("TR"),labelTd=document.createElement("TD");labelTd.colSpan=context.numOfCols+1;labelTd.style.border="none";labelTd.style.whiteSpace="nowrap";labelTd.style.padding="4px 0 0 4px";var subGridLabel;if(childrenRels[i].fk.name.toLowerCase()==childrenRels[i].primaryEntity.name.toLowerCase())subGridLabel=childrenRels[i].foreignEntity.name;else subGridLabel=childrenRels[i].foreignEntity.name+" ("+childrenRels[i].fk.name+")";var parentElementID=String.format("{0}_{1}_{2}_{3}_SubGrid_{4}",context.popupID,context.entID,context.appID,context.rowID,childrenRels[i].fk.id),LabelMask='<div class="childLabel" onclick="viewSubgridData({0}, {1}, 0, \'{6}\', \'{2}\', {5}, {3}, this)" style="float:left;"><div class="entityButton expandEntity" style="float:left"></div>{4}</div><span style="float:right; display:none;"><div class="closeSubgrid spriteImages" onclick="viewSubgridData({0}, {1}, 0, \'{6}\', \'{2}\', {5}, {3}, this.parentNode)"></div><div id="{6}_{2}_refreshIcon" class="refreshSubgrid spriteImages" onclick="viewData({0}, {1}, 0, \'{6}\', \'{2}\', {5}, {3})"></div><a style="" href="#" onclick="createPopup(\'new_row_{1}\', 450, \'{1}_{0}\', \'{4}\');"><div style="float:right; margin-right:5px; margin-left:-5px;">New</div><div id="NewRowButton_'+context.entID+"_"+parentElementID+'" class="newSubgrid spriteImages"></div></a></span>';labelTd.innerHTML=String.format(LabelMask,context.appID,childrenRels[i].foreignEntity.id,parentElementID,context.rowID,subGridLabel,childrenRels[i].fk.id,context.popupID);labelTr.appendChild(labelTd);thisTable.appendChild(labelTr);var subGridTr=document.createElement("TR"),subGridTd=document.createElement("TD");subGridTd.style.border="none";subGridTd.id=parentElementID;subGridTr.appendChild(subGridTd);thisTable.appendChild(subGridTr);childrenRels.length==1&&viewSubgridData(context.appID,childrenRels[i].foreignEntity.id,0,context.popupID,context.popupID+"_"+context.entID+"_"+context.appID+"_"+context.rowID+"_SubGrid_"+childrenRels[i].fk.id,childrenRels[i].fk.id,context.rowID,labelTd.childNodes[0])}}else if(resp.Results.length>0)alert("There are no children tables to display for table '"+resp.Results[0].foreignEntity.name+"'");else alert("There are no children tables to display for this table")}function makeNewGuidComplete(resp,context){context.cell.value=resp}function removeClass(element,nameOfClass){while(element.className.indexOf(nameOfClass)>0)element.className=element.className.replace(element.className.indexOf(" "+nameOfClass)>=0?" "+nameOfClass:nameOfClass,"")}function checkForClass(element,nameOfClass){return element.className.indexOf(nameOfClass)>0}var focusedInputLastValue,focusedInput;function filterGrid(event,input,parentElement,popupID,predColID,predValue){if(isValidKey(event.keyCode,1))if(focusedInput.id==input.id){var parentID=parentElement==undefined?"undefined":'"'+parentElement+'"';setTimeout('executeFilter("'+input.value+'", '+parentID+",'"+popupID+"', "+predColID+", "+predValue+")",750)}}function onTextBoxKeyPress(event,inputValue,parentID,popupID,predColID,predValue,colKind,nextID,prevID){if(!isValidKey(event.keyCode,colKind))event.returnValue=false;else if(event.keyCode==9){eval('executeFilter("'+inputValue+"\", '"+parentID+"','"+popupID+"', "+predColID+", "+predValue+")");var mask="var focusedElement = $get('{0}'); if(focusedElement != null){{focusedElement.focus();setCaretPosition('{0}', focusedElement.value.length);}}";if(event.shiftKey||event.shiftLeft)evalCode=String.format(mask,prevID);else evalCode=String.format(mask,nextID)}}function executeFilter(oldValue,parentElement,popupID,predColID,predValue){if(focusedInput.value==oldValue&&focusedInputLastValue.trim()!=oldValue.trim()){focusedInputLastValue=oldValue;var parts=parseContext(focusedInput.id);if(parentElement=="undefined"||parentElement==undefined||parentElement==null)viewData(parts[0],parts[1],0,popupID,null,null,null);else viewData(parts[0],parts[1],0,popupID,parentElement,predColID,predValue)}}function setCaretPosition(elemId,caretPos){var elem=document.getElementById(elemId);if(elem!=null)if(elem.createTextRange){var range=elem.createTextRange();range.move("character",caretPos);range.select()}else if(elem.selectionStart){elem.focus();elem.setSelectionRange(caretPos,caretPos)}else elem.focus()}function isValidKey(code,kind){if(code==8||code==9||code==46||code>=37&&code<=40)return true;switch(kind){case 1:case 64:return code==32||code>=48&&code<=90||code>=96&&code<=111||code>=186&&code<=222;break;case 2:return code==189||code==109||code==110||code==190||code>=48&&code<=57||code>=96&&code<=105;break;case 3:return code==109||code==189||code==191||code==111||code>=48&&code<=57||code>=96&&code<=105;break;case 7:return code==189||code==109||code>=48&&code<=90||code>=96&&code<=105}}function buildPredicate(entID,colID,compareType,value,colKind){pred={};pred.col={};pred.col.id=colID;pred.col.entityID=entID;if(colKind!=undefined)pred.col.kind=colKind;pred.value=value+"";pred.compareType=compareType;return pred}String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")};