/**************************************************************************************************** Purpose: This js file contains all common javascript functions used by common components Author: Seema Joshi (Persistent Systems Pvt. Ltd.) Version: 1.0 Version History: --------------------------------------------------------------- Date User Comments 04/18/2007 Seema Joshi Initial Creation ****************************************************************************************************/ /************************************************************************************************** Purpose: This function will hide advance fields as well as simple search link. This will display advance search link **************************************************************************************************/ function hideAdvanceFields(fieldsetname, advdivname, simpledivname){ var fieldset=document.getElementsByTagName(fieldsetname); if ( fieldset.length > 0 ){ for (var iLoop=0 *1; iLoop < fieldset.length; iLoop++){ fieldset[iLoop].style.display='none'; } }else{ fieldset=document.getElementById(fieldsetname); fieldset.style.display='none'; } var advdiv=document.getElementById(advdivname); advdiv.style.display=''; var simplediv=document.getElementById(simpledivname); simplediv.style.display='none'; } /************************************************************************************************** Purpose: This function will show advance fields as well as simple search link. This will hide advance search link **************************************************************************************************/ function showAdvanceFields(fieldsetname, advdivname, simpledivname){ var fieldset=document.getElementsByTagName(fieldsetname); if ( fieldset.length > 0 ){ for (var iLoop=0 *1; iLoop < fieldset.length; iLoop++){ fieldset[iLoop].style.display=''; } }else{ fieldset=document.getElementById(fieldsetname); fieldset.style.display=''; } var advdiv=document.getElementById(advdivname) advdiv.style.display='none'; var simplediv=document.getElementById(simpledivname) simplediv.style.display=''; } /************************************************************************************************** Purpose: This function will start upload window by passing required parameters **************************************************************************************************/ function startUpload(fieldname,valueseparator,acceptfileextension){ var features = "width=450,height=200,resizable=yes,scrollbars=yes"; theURL = "displayUpload.do?fieldName=" + fieldname + "&valueseparator" + valueseparator "&acceptfileextension" + acceptfileextension; window.open(theURL,"Upload",features); } /************************************************************************************************** Purpose: This function will end/close upload window after setting required attributes on opener window **************************************************************************************************/ function endUpload(fieldname, fieldvalue){ var doc = window.opener.document; var ele = doc.getElementById(fieldname); var uploadData = fieldvalue; ele.value = uploadData; window.close(); } /************************************************************************************************** Purpose: This function will disable radio button. **************************************************************************************************/ function disableRadioButton(radioObj){ if(!radioObj) return; var radioLength = radioObj.length; if(radioLength == undefined) radioObj.disabled = true; for(var i = 0 ; i < radioLength; i++) { radioObj[i].disabled = true; } } /************************************************************************************************** Purpose: This function will enable radio button. **************************************************************************************************/ function enableRadioButton(radioObj){ if(!radioObj) return; var radioLength = radioObj.length; if(radioLength == undefined) radioObj.disabled = false; for(var i = 0; i < radioLength; i++) { radioObj[i].disabled = false; } } /************************************************************************************************** Purpose: This function will value of check radio button. **************************************************************************************************/ function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } /************************************************************************************************** Purpose: This function will set value of check radio button. **************************************************************************************************/ function setCheckedValue(radioObj, newValue) { if(!radioObj) return; var radioLength = radioObj.length; if(radioLength == undefined) { radioObj.checked = (radioObj.value == newValue.toString()); return; } for(var i = 0; i < radioLength; i++) { radioObj[i].checked = false; if(radioObj[i].value == newValue.toString()) { radioObj[i].checked = true; } } } /************************************************************************************************** Purpose: This function will return value of given element. **************************************************************************************************/ function getElementValue(elementName) { var ele = document.forms[0].elements[elementName]; if (ele) return ele.value; else return ""; } /************************************************************************************************** Purpose: This function will set value of given element. **************************************************************************************************/ function setElementValue(elementName,elementValue) { var ele = document.forms[0].elements[elementName]; if (ele) ele.value = elementValue; } /************************************************************************************************** Purpose: This function will hide div from page. **************************************************************************************************/ function hideDiv(divName) { var elementName = "document.all[\"" + divName + "\"]"; document.poppedLayer = eval(elementName); if (document.poppedLayer) document.poppedLayer.style.visibility = "hidden"; } /************************************************************************************************** Purpose: This function will show div from page. **************************************************************************************************/ function showDiv(divName) { var elementName = "document.all[\"" + divName + "\"]"; document.poppedLayer = eval(elementName); if (document.poppedLayer) document.poppedLayer.style.visibility = "visible"; } /************************************************************************************************** Purpose: This function will convert value to integer. **************************************************************************************************/ function convertToInt (val) { var number = val; var rlength = 0; // The number of decimal places to round to var newnumber = Math.round(number * Math.pow(10,rlength))/Math.pow(10,rlength); number = newnumber; return number; } /************************************************************************************************** Purpose: This function will convert value to round number. **************************************************************************************************/ function roundNumber(val) { var number = val; var rlength = 2; // The number of decimal places to round to var newnumber = Math.round(number * Math.pow(10,rlength))/Math.pow(10,rlength); number = newnumber; return number; } /************************************************************************************************** setValidate(valtype, tb) Here all valid characters for particular TYPE are set in vExpr variable. for ex, for Numbers its 0 to 9 only. Returns true if value is valid as per the 'type' **************************************************************************************************/ vType = "description"; vtIni = ""; vExpr = new RegExp("[^';\\r]"); function setValidate(valtype, obj) { vType = valtype; switch (vType.toLowerCase()) { case "numeric": vExpr = new RegExp("[0-9\b.]"); break; case "integer": vExpr = new RegExp("[0-9\b]"); break; case "alphanumeric": vExpr = new RegExp("[A-Za-z0-9-_.\b]"); break; case "alphabets": vExpr = new RegExp("[A-Za-z]"); break; case "name": vExpr = new RegExp("[A-Za-z0-9-' ]"); break; case "password": vExpr = new RegExp("[A-Za-z0-9]"); break; case "alphanumericwithspace": vExpr = new RegExp("[A-Za-z0-9-_.\b ]"); break; case "date": vExpr = new RegExp("[0-9/\b]"); break; case "dynamic": vExpr = new RegExp("[A-Za-z0-9-_;:$.\b ]"); break; case "url": vExpr = new RegExp("[A-Za-z0-9-_:.//\b ]"); break; case "address": vExpr = new RegExp("[A-Za-z0-9-_.,//#\b ]"); break; case "companyname": vExpr = new RegExp("[A-Za-z0-9-_<>?~`+=$!%^@&*().,//#\b ]"); break; case "extension": vExpr = new RegExp("[0-9-*]"); break; case "phonenum": vExpr = new RegExp("[0-9-]"); break; case "sequence": vExpr = new RegExp("([ATGC]{1,60}|[\<_\>])"); break; case "telephonenum": vExpr = new RegExp("[A-Za-z0-9- ]"); break; default: break; } var val = obj.value; var len = val.length; for(var i=0;i=0; i--) { if (from.options[i].selected) { selectedText[selectedCount] = from.options[i].text; selectedValues[selectedCount] = from.options[i].value; deleteOption(from, i); selectedCount++; } } // Add the selected text/values in reverse order. This will add the Options to the 'to' Select // in the same order as they were in the 'from' Select. for (i=selectedCount-1; i>=0; i--) { addOption(to, selectedText[i], selectedValues[i]); } if(NS4) history.go(0); } function addOption(to, text, value) { var newOption = new Option(text, value); var toLength = to.length; to.options[toLength] = newOption; } function deleteOption(from, index) { var fromLength = from.length; if (fromLength > 0) { from.options[index] = null; } } function selectAllOptions(selectControl) { var nOptions = selectControl.length; for (i=0; i 64 && charCode < 91) || (charCode > 96 && charCode <123)) return true; openAlertDialog("error",resourceBundle.alphabetsOnly); return false; } /*********************************************************** Purspoe: This function would allow user to only enter Alphabets,backspace and delete in a textfield. ************************************************************/ function onlyNumbers(evt) { var e = evt || window.event; // for trans-browser compatibility var charCode = e.which || e.keyCode; if(charCode == 8 || charCode ==46) return true; if (charCode > 47 && charCode < 58){ return true; } openAlertDialog("error",resourceBundle.numbersOnly); return false; } /*********************************************************** Purspoe: This function opens download popup for the download with servlet functionality. ************************************************************/ function openDownloadWindow(pathUrl, sessionAttribute) { var contextpath = ''; //if (dojo.isIE) { contextpath = getElementHTML('hiddenContextPath'); //} else { // contextpath = ".." //} var width = 600; var height = 400; var left = (screen.width - width)/2; var top = (screen.height - height)/2; var params = 'width='+width+', height='+height; params = params + ', top='+top+', left='+left; params = params + ', menubar=no'; params = params + ', resizable=yes'; params = params + ', scrollbars=no'; params = params + ', status=yes'; params = params + ', toolbar=no'; var downloadUrl = contextpath + "/pages/probe/plsWait.jsp?url=" + encodeURIComponent(pathUrl); downloadUrl = downloadUrl + "&sessionAttribute="+ sessionAttribute; var myWindow=window.open(downloadUrl, "", params); return myWindow; } function showDialog(elementId){ var dlgProg = dijit.byId(elementId); dlgProg.show() } function isDigit(num) { if (num.length>1){ return false; } var string="1234567890"; if (string.indexOf(num)!=-1){ return true; } return false; } function isInteger(val) { for(var i=0;i'+quesion+''; dialogContent = dialogContent+''; dialogContent = dialogContent+''; if(cancelButtonLabel != ''){ dialogContent = dialogContent+''; } dialogContent = dialogContent+''; dialog.attr("content", dialogContent); dialog.show(); }catch(exception){ openAlertDialog("error","Error:" + exception); } } function closeConfirmDialog(){ var dlgProg = dijit.byId("confirmationDialog"); dlgProg.hide(); } function createDialogWithNoTitle(dialogContent) { createDialogWithNoTitleAndCustomWidth(dialogContent, "250px"); } function createDialogWithNoTitleAndCustomWidth(dialogContent,width) { try{ dojo.require("dijit.Dialog"); var customHeight_Width = "height:auto; width:"+width+";"; var dialog = dijit.byId("dialogWithNoTitle"); if(! dialog){ dialog = new dijit.Dialog({ id:"dialogWithNoTitle", title:"", bgColor:"white", style: customHeight_Width, bgColor:"white", bgOpacity:"0.5", toggle:"fade", toggleDuration:"5000", ioArgs:"{timeout: 5000}", closeOnBackgroundClick:"false" }); } dialog.style = customHeight_Width; dialog.attr("content", dialogContent); dialog.show(); }catch(exception){ alert("error","Error:" + exception); } } function hideDialogWithNoTitle() { try{ dojo.require("dijit.Dialog"); var dialog = dijit.byId("dialogWithNoTitle"); if(dialog){ dialog.hide(); } }catch(exception){ openAlertDialog("error","Error:" + exception); } } //Create drop down list from Json obj function createDropDownList(element, list, numberOfElemnts, selectedItem){ element.innerHTML = ""; var str=" "; for(var i = 0; i < numberOfElemnts; i++){ var elOptNew = document.createElement('option'); elOptNew.text = list[i].name; elOptNew.value = list[i].id; if(list[i].id == selectedItem){ elOptNew.selected = 'selected'; } element.options.add ( elOptNew ); } } //Select radio button from radio button group function selectRadioButton(radioGroup, selectedItem){ for(var j=0;j"; if(type == 'info'){ header = infoMessageLabel imageIcon = "+header+"; }else if(type == 'warning'){ header = warningMessageLabel imageIcon = "+header+"; } var dialogContent='
'+imageIcon+''+message+'
' dialogContent = dialogContent+ "
"; showDialog('alertDlg', header, dialogContent); } function openInfoMessageDialog(id,header, message) { var imageIcon = "+header+"; var dialogContent='
'+imageIcon+''+message+'
' dialogContent = dialogContent+ "
"; showDialog(id, header, dialogContent); } function showDialog( header, value) { showDialog('tempDlg',header,value); } function showDialog(dlgId, header, value) { if(!dlgId){ dlgId = 'tempDlg'; } dojo.require("dijit.Dialog"); var secondDlg = dijit.byId(dlgId); if(! secondDlg){ secondDlg = new dijit.Dialog({ id:dlgId, style: "width: 400px" }); } secondDlg.attr("title", header); secondDlg.attr("content", value); secondDlg.show(); } function showCommonLoadingDiv(){ var dlg1 = dijit.byId("commonLoadingDiv"); if (dlg1){ dlg1.show(); } } function hideCommonLoadingDiv(){ var dlg1 = dijit.byId("commonLoadingDiv"); if (dlg1){ dlg1.hide(); } } /************************************************************************** Forgot password and request for registration redirection **************************************************************************/ function openDialogForSureDesignRedirect(dialogMessage, extendedPath) { try{ var hostName = location.hostname; var protocol = location.protocol; var port = location.port; var linkToRedirect = protocol+'//'+hostName+':'+port+'/'+extendedPath; dojo.require("dijit.Dialog"); dojo.require("dijit.form.Button"); var style="height:auto; width:400px;"; var dialog = dijit.byId("dialogWithCloseAndLink"); if(! dialog){ dialog = new dijit.Dialog({ id:"dialogWithCloseAndLink", title:"Information", style: style, bgColor:"white", bgOpacity:"0.5", toggle:"fade", toggleDuration:"5000", closeOnBackgroundClick:"false" }); } var dialogContent = '
'; dialogContent = dialogContent+''; dialogContent = dialogContent+'
'+dialogMessage+'Please click here to continue.

'; dialogContent = dialogContent+''; dialogContent = dialogContent+'
'; dialog.attr("content", dialogContent); dialog.show(); }catch(exception){ openAlertDialog("error","Error:" + exception); } } function hideDialogWithCloseAndLink() { try{ dojo.require("dijit.Dialog"); var dialog = dijit.byId("dialogWithCloseAndLink"); if(dialog){ dialog.hide(); } }catch(exception){ openAlertDialog("error","Error:" + exception); } }