/***************************************Sleep function**********************************************/ function sleep(millisSeconds) { var startTime = new Date().getTime(); while(new Date().getTime() < startTime + millisSeconds); } /***************************************Login page**********************************************/ function loginSubmit() { document.getElementById("action").value = "userLogin"; document.getElementById("actionCode").value = "login"; document.loginForm.submit(); } function fillBox() { if(document.getElementById("passwordEmail").value == '') { document.getElementById("passwordEmail").value = "Enter your User Id"; } } function clearBox() { if(document.getElementById("passwordEmail").value == "Enter your User Id") { document.getElementById("passwordEmail").value = ""; } } function forgotPassword() { document.getElementById("action").value = "userLogin"; document.getElementById("actionCode").value = "forgotPassword"; document.loginForm.submit(); } function toUserRegistrationPage() { document.getElementById("action").value = "userLogin"; document.getElementById("actionCode").value = "userRegistration"; document.loginForm.submit(); } /**********************************User registration page *************************************/ function validateUserRegistration(registerOrUpdate) { var userIdReg = document.getElementById("userId").value; var flag = true; if(userIdReg == "") { document.getElementById("userIdError1").value = "Email id cannot be blank"; flag = false; } else if((userIdReg.indexOf("@") == -1) || (userIdReg.indexOf("@") == 0) || (userIdReg.indexOf("@") == userIdReg.length - 1) ) { document.getElementById("userIdError1").value = "Your email address will be used as your user id."; document.getElementById("userIdError2").value = "Please enter a valid email address."; flag = false; } else if((userIdReg.indexOf(".") == -1) || (userIdReg.indexOf(".") == 0) || (userIdReg.indexOf(".") == userIdReg.length - 1) ) { document.getElementById("userIdError1").value = "Your email address will be used as your user id."; document.getElementById("userIdError2").value = "Please enter a valid email address."; flag = false; } else if((userIdReg.indexOf("@.") > -1)) { document.getElementById("userIdError1").value = "Your email address will be used as your user id."; document.getElementById("userIdError2").value = "Please enter a valid email address."; flag = false; } else { document.getElementById("userIdError1").value = ""; } var userNameFirst = document.getElementById("userNameFirst").value; if(userNameFirst == "") { document.getElementById("userNameFirstError").value = "First name cannot be blank"; flag = false; } else if(checkOnlyForAlpha(userNameFirst) == false) { document.getElementById("userNameFirstError").value = "First name can contain only characters."; flag = false; } else { document.getElementById("userNameFirstError").value = ""; } var userNameLast = document.getElementById("userNameLast").value; if(userNameLast == "") { document.getElementById("userNameLastError").value = "Last name cannot be blank"; flag = false; } else if(checkOnlyForAlpha(userNameLast) == false) { document.getElementById("userNameLastError").value = "Last name can contain only characters."; flag = false; } else { document.getElementById("userNameLastError").value = ""; } var password = document.getElementById("password").value; if(password == "") { document.getElementById("passwordError").value = "Password cannot be blank"; flag = false; } else if(password.length < 6) { document.getElementById("passwordError").value = "Password must be 6 or more characters long."; flag = false; } else { document.getElementById("passwordError").value = ""; } var affiliation = document.getElementById("affiliation").value; if(affiliation == "") { document.getElementById("affiliationError").value = "Affiliation cannot be blank"; flag = false; } else { document.getElementById("affiliationError").value = ""; } if(flag ==true) { document.getElementById("action").value = "userRegistration"; if(registerOrUpdate == "register") { document.getElementById("actionCode").value = "register"; } else { document.getElementById("actionCode").value = "update"; } document.forms[0].submit(); } else { return; } } /***************************************Profile page***************************/ function deleteUser() { document.getElementById("action").value = "userRegistration"; document.getElementById("actionCode").value = "delete"; document.forms[0].submit(); } /***************************************Welcome page***************************/ function logout() { document.getElementById("action").value = "userLogin"; document.getElementById("actionCode").value = "logout"; document.forms[0].submit(); } function toWelcomePage() { document.getElementById("action").value = "userWelcome"; document.getElementById("actionCode").value = "home"; document.forms[0].submit(); } function deleteThread(threadNoToBeDeleted) { document.getElementById("action").value = "userWelcome"; document.getElementById("actionCode").value = "deleteThread"; document.getElementById("threadNoToBeDeleted").value = threadNoToBeDeleted; document.forms[0].submit(); } function toProfilePage() { document.getElementById("action").value = "userWelcome"; document.getElementById("actionCode").value = "profile"; document.forms[0].submit(); } function toManageUsersPage() { document.getElementById("action").value = "userWelcome"; document.getElementById("actionCode").value = "users"; document.forms[0].submit(); } function toSendEmailPage() { document.getElementById("action").value = "userWelcome"; document.getElementById("actionCode").value = "mailUsers"; document.forms[0].submit(); } function loadThread(threadNo) { document.getElementById("threadNo").value = threadNo; document.getElementById("action").value = "threadConversation"; document.getElementById("actionCode").value = "loadThread"; document.forms[0].submit(); } /***************************************Thread conversation page***************************/ function threadReplyPopup() { window.open("threadReplyPopup.jsp", "threadReplyPopup", 'width=700,height=470,scrollbars=1,left=50,top=100,location=0,resizable=0,menubar=0,locationbar=0'); } function createNewThreadPopup() { window.open("createNewThread.jsp", "createNewThreadPopup", 'width=700,height=470,scrollbars=1,left=50,top=100,location=0,resizable=0,menubar=0,locationbar=0'); } /***************************************Send email page***************************/ function loadEmailIdsOfUsersTo() { window.open("APProject.do?action=emailDispatch&actionCode=loadEmailIds&listToBePopulated=To", "emailIdListTo", 'width=675,height=510,left=50,top=100,location=0,resizable=0,scrollbars=1,menubar=0,locationbar=0'); } function loadEmailIdsOfUsersCC() { window.open("APProject.do?action=emailDispatch&actionCode=loadEmailIds&listToBePopulated=CC", "emailIdListCC", 'width=675,height=510,left=50,top=100,location=0,resizable=0,menubar=0,scrollbars=1,locationbar=0'); } function populateParentToList() { opener.document.manageUsersForm.mailToList.value += buildEmailList(); window.close(); } function populateParentCCList() { opener.document.manageUsersForm.mailCCList.value += buildEmailList(); window.close(); } function buildEmailList() { var checkboxList = document.forms[0].emailIds; if(document.forms[0].emailIdsUpd != undefined) { var checkboxListUpd = document.forms[0].emailIdsUpd; } var emailList = ""; for (var x=0; x < checkboxList.length; x++) { if (checkboxList[x].checked) { emailList = emailList + checkboxList[x].value + ","; } } if(document.forms[0].emailIdsUpd != undefined) { if(checkboxListUpd.length == undefined) { emailList = emailList + checkboxListUpd.value + ","; } else { for (var y=0; y < checkboxListUpd.length; y++) { if (checkboxListUpd[y].checked) { emailList = emailList + checkboxListUpd[y].value + ","; } } } } return emailList.substring(0, emailList.length - 1) ; } function sendEmail() { if(document.getElementById("mailToList").value == '') { document.getElementById("messageBox").value = "To list cannot be empty"; return; } if(document.getElementById("mailSubject").value == '') { document.getElementById("messageBox").value = "Subject cannot be blank"; return; } if(document.getElementById("mailMessage").value == '') { document.getElementById("messageBox").value = "Message cannot be blank"; return; } document.getElementById("action").value = "emailDispatch"; document.getElementById("actionCode").value = "sendEmail"; document.forms[0].submit(); } /*************************************** Mailing list popup***************************/ function sortEmailIdList(strField) { document.getElementById("action").value = "emailDispatch"; document.getElementById("actionCode").value = "sortEmailIdList"; if(document.getElementById("strSortOrder").value == "descending") document.getElementById("strSortOrder").value = "ascending"; else document.getElementById("strSortOrder").value = "descending"; document.getElementById("sortEmailIdListByField").value = strField; document.forms[0].submit(); } function selectAllRows() { var checkboxList = document.forms[0].emailIds; var checkboxListUpd = document.forms[0].emailIdsUpd; for (i = 0; i < checkboxList.length; i++) checkboxList[i].checked = true ; if(checkboxListUpd.length == undefined) { document.forms[0].emailIdsUpd.checked = true; } else { for (j = 0; j < checkboxListUpd.length; j++) checkboxListUpd[j].checked = true ; } } function deselectAllRows() { var checkboxList = document.forms[0].emailIds; var checkboxListUpd = document.forms[0].emailIdsUpd; for (k = 0; k < checkboxList.length; k++) checkboxList[k].checked = false ; if(checkboxListUpd.length == undefined) { document.forms[0].emailIdsUpd.checked = false; } else { for (j = 0; j < checkboxListUpd.length; j++) checkboxListUpd[j].checked = false ; } } function selectAllUpdRows() { var checkboxListUpd = document.forms[0].emailIdsUpd; if(checkboxListUpd.length == undefined) { document.forms[0].emailIdsUpd.checked = true; } else { for (j = 0; j < checkboxListUpd.length; j++) checkboxListUpd[j].checked = true ; } } /*************************************** Create new thread popup***************************/ function createNewThread() { document.getElementById("action").value = "threadConversation"; document.getElementById("actionCode").value = "createNewThread"; document.forms[0].submit(); //window.opener.location.reload(); window.close(); sleep(1000); parent.window.opener.document.getElementById("action").value = "userWelcome"; parent.window.opener.document.getElementById("actionCode").value = "home"; parent.window.opener.document.forms[0].submit(); } /*************************************** Thread reply popup *******************************/ function appendThreadReply(threadNo) { document.getElementById("action").value = "threadConversation"; document.getElementById("actionCode").value = "appendThreadReply"; document.forms[0].submit(); //window.opener.location.href = "threadConversation.jsp"; //parent.window.location = parent.window.location; //window.opener.forms[0].submit(); //parent.window.opener.location.href = "welcome.jsp"; //parent.window.opener.document.getElementById("action").value = "userWelcome"; //parent.window.opener.document.getElementById("actionCode").value = "home"; //parent.window.opener.document.forms[0].submit(); //window.location.reload(); window.close(); sleep(1000); parent.window.opener.document.getElementById("threadNo").value = threadNo; parent.window.opener.document.getElementById("action").value = "threadConversation"; parent.window.opener.document.getElementById("actionCode").value = "loadThread"; parent.window.opener.document.forms[0].submit(); } function deleteThreadReply(strReplyToDelete) { document.getElementById("action").value = "threadConversation"; document.getElementById("actionCode").value = "deleteThreadReply"; document.getElementById("strReplyToDelete").value = strReplyToDelete; document.forms[0].submit(); } /*************************************** Manage users page ***************************/ function loadUserProfile(strUserId) { document.getElementById("action").value = "userProfile"; document.getElementById("actionCode").value = "loadUserProfile"; document.getElementById("userId").value = strUserId; document.forms[0].submit(); } var req; function populateMatchingUsers() { var userSearchInput = document.getElementById("userSearchInput"); var url = "APProject.do?userSearchInput=" + encodeURIComponent(userSearchInput.value); if (typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } req.open("GET", url, true); req.onreadystatechange = callback; req.send(null); } function sortUsersListByField(strField) { document.getElementById("action").value = "userProfile"; document.getElementById("actionCode").value = "sortUsersListByName"; document.getElementById("strFieldToBeSortedOn").value = strField; if(document.getElementById("strSortOrder").value == "descending") document.getElementById("strSortOrder").value = "ascending"; else document.getElementById("strSortOrder").value = "descending"; document.forms[0].submit(); } /***************************************Common javascript methods***************************/ function checkOnlyForAlpha(strInput) { var flag = true; for(i = 0; i < strInput.length; i++) { if((strInput.charAt(i) >= 'a' && strInput.charAt(i) <= 'z') || (strInput.charAt(i) >= 'A' && strInput.charAt(i) <= 'Z') || (strInput.charAt(i) >= '0' && strInput.charAt(i) <= '9')) { } else { flag = false; } } return flag; }