// This function is used to check if a certain text is numeric or not function IsNumeric(sText) { var ValidChars = "0123456789."; var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } // This function is to be used in the show/hide row contents without img function ShowHideRow(Row) { if (Row.style.display == '') { Row.style.display = 'none'; }else{ Row.style.display = ''; } } /*-*-*-*-*-* This function is to be used in the show/hide row contents with img *-*-*-*-*-*/ function ToggleInfoRow(Row, Img) { if (Row.style.display == '') { Row.style.display = 'none'; Img.src = '../Images/arrowOffAr.gif'; }else{ Row.style.display = ''; Img.src = '../Images/arrowOn.gif'; } } // This function is used to open a popup window function openNewWindow(url,width,height) { var left = Math.floor(screen.width/2)-Math.floor(width/2); var top = Math.floor(screen.height/2)-Math.floor(height/2); popwindow = window.open(url, "popwindow", "toolbar=no,width="+width+",height="+height+",top="+top+",left="+left); popwindow.focus(); } // This function is used in the login process function login() { with (document.form) { if (txtUsername.value=="") { txtUsername.focus(); return false; } if (txtPassword.value=="") { txtPassword.focus(); return false; } useraction.value = "login"; action = "login.php"; submit(); } } // This function is used to submit form when the user press enter function submitEnter(myfield,myevent,myaction) { var keycode; if (window.event) keycode = window.event.keyCode; else if (myevent) keycode = myevent.which; else return true; //alert (keycode); if (keycode == 13) { if (myaction == "login") { login(); }else if (myaction == "search") { SearchForMaterials(); }else if (myaction == "subscribe") { SubscribeMe(); }else if (myaction == "unsubscribe") { UnSubscribeMe(); }else{ myfield.form.submit(); } return false; } else return true; } // This function is used to check if a certain email is valid function isValidMail(emailStr) { var checkTLD=1; var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; var emailPat=/^(.+)@(.+)$/; var specialChars= "\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; var validChars= "\[^\\s" + specialChars + "\]"; var quotedUser="(\"[^\"]*\")"; var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; var atom=validChars + '+'; var word="(" + atom + "|" + quotedUser + ")"; var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); var matchArray=emailStr.match(emailPat); if (matchArray==null) { return false; } var user=matchArray[1]; var domain=matchArray[2]; for (i=0; i127) { alert("Your email address contains invalid characters."); return false; } } for (i=0; i127) { alert("Your email domain name contains invalid characters."); return false; } } if (user.match(userPat)==null) { return false; } var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alert("Destination IP address is invalid!"); return false; } } return true; } var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i< len;i++) { if (domArr[i].search(atomPat)==-1) { alert("Your email address does not seem to be valid - check your spelling, including wrong use of commas, or a full point . at the end of the address."); return false; } } if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { alert("Your email address must end in a well-known domain or two letter " + "country."); return false; } if (len<2) { alert("Your email address is missing a hostname - check spelling."); return false; } return true; } // This function is used to check if the email is valid or not function checkEmail() { with (document.form) { if (txtEmail.value == "") { txtEmail.focus(); return false; }else if (txtEmail.value != "") { if (!isValidMail(txtEmail.value)) { txtEmail.focus(); return; } } return true; } } // This function is used to submit the form function submitForm() { document.forms[0].submit(); } function SubmitFormAction(sURL) { with (document.form) { action = sURL; submit(); } } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Material Types Page Scripts *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ // This function is used to check the required fields function CheckName() { with (document.form) { if (txtName.value == "") { txtName.focus(); return false; } useraction.value = "AddEdit"; submit(); } } // This function is used to confirm deletion function ConfirmDeletion(ID) { with (document.form) { if (!confirm("Confirm Deletion")) { return false; } useraction.value = "Delete"; id.value = ID; submit(); } } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Attachment Types Page Scripts *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ // This function is used to check the required fields function CheckNames() { with (document.form) { if (txtNameEn.value == "") { txtNameEn.focus(); return false; }else if (txtNameAr.value == "") { txtNameAr.focus(); return false; } useraction.value = "AddEdit"; AllowedExtensions.value = generateExtensionsStr(); submit(); } } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Used for lists *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ function AddItem(List1,List2) { if (List1.options.selectedIndex>=0 && List1.options[0].value != "-1") { // Add the selected item of List1 in List2 Element = new Option(List1.options[List1.options.selectedIndex].text,List1.options[List1.options.selectedIndex].value, false, true); if (List2.options[0].value != "-1") { List2.add(Element,List1.options[List1.options.selectedIndex].value); //List2.add(Element,List1.length); } else { List2.remove(0); List2.add(Element,0); } // Remove the selected item of List1 List1.remove(List1.options.selectedIndex); Element = new Option("----------------------------------------------","-1"); if (List1.options.length == 0) { List1.add(Element,0); } } } function SwapLists(List1,List2) { if (List1.options.length>0 && List1.options[0].value != "-1") { // Add items of List1 in List2 List2.remove(0); for(i=0;i< List1.options.length;i++) { Element = new Option(List1.options[i].text,List1.options[i].value); List2.add(Element,List1.options[i].value); // List2.add(Element,i); } // Remove items of List1 L = List1.options.length for(i=0;i< L;i++) { List1.remove(0); } Element = new Option("----------------------------------------------","-1"); List1.add(Element,0); } } function MultiDimensionalArray(iRows,iCols) { var i; var j; var a = new Array(iRows); for (i=0; i < iRows; i++) { a[i] = new Array(iCols); for (j=0; j < iCols; j++) { a[i][j] = ""; } } return(a); } //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-* function mySplit(whole, link) { if (whole.split) { return(whole.split(link)); } var parts = new makeArray(0); var d = 0; var p = 0; var q = whole.indexOf(link); while (q > -1) { parts[d++] = whole.substring(p, q); parts.length = d; p = q + 1; q = whole.indexOf(link, p); } parts[d++] = whole.substring(p); parts.length = d; return(parts); } //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-* function myJoin(parts, link) { if (parts.join) { return(parts.join(link)); } var whole = ""; var thisLink = ""; for(var d = 0; d < parts.length;d++) { if (parts[d] != "") { whole = whole + thisLink + parts[d]; thisLink = link; } } return(whole); } //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-* function generateExtensionsStr() { var extensions = new Array(); var extStr = ""; var extList = document.form.List2; for(var i=0; i< extList.options.length; i++) { extensions[i] = extList.options[i].text; } extStr = myJoin(extensions, ";"); // alert(extStr); return (extStr); } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Material Types Page Scripts *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ // This function is used to check the required fields function CheckUserInfo() { with (document.form) { if (txtName.value == "") { txtName.focus(); return false; } if (txtUsername.value == "") { txtUsername.focus(); return false; } if (!checkEmail()) { return false; } useraction.value = "AddEdit"; submit(); } } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * SiteMap Page Scripts *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ function AddNewItem() { with (document.form) { useraction.value = "Add"; submit(); } } function EditExistingItem() { with (document.form) { useraction.value = "Edit"; submit(); } } // This function is used to check the required fields and submit the form if all valid // If sAction = 'SaveAdd' then add new item // If sAction = 'SaveEdit' then update existing item function CheckSiteMapInfo(sAction) { with (document.form) { if (txtNameEn.value == "") { txtNameEn.focus(); return false; } else if (txtNameAr.value == "") { txtNameAr.focus(); return false; } useraction.value = sAction; submit(); } } // This function is used to confirm deletion function ConfirmDelete() { with (document.form) { { return false; } useraction.value = "Delete"; submit(); } } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Manage Material Page Scripts *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ // This function is used to make a copy of a certain combo-box function CopyCombo(cmbSrc, cmbDest, selectedValue) { for(i=0;i< cmbSrc.length;i++) { Element = new Option(cmbSrc.options[i].text, cmbSrc.options[i].value); cmbDest.add(Element,i); if ((selectedValue != -1) && (cmbSrc.options[i].value == selectedValue)) { cmbDest.options[i].selected = true; } } } // This function is used to check the duplicate values in the three location combo-boxes function CheckDuplicate() { with (document.form) { if ((cmbLocation1.value == cmbLocation2.value) && (cmbLocation1.value != -1)) { alert("Duplicate Locations"); cmbLocation2.focus(); return false; } if ((cmbLocation1.value == cmbLocation3.value) && (cmbLocation1.value != -1)) { alert("Duplicate Locations"); cmbLocation3.focus(); return false; } if ((cmbLocation2.value == cmbLocation3.value) && (cmbLocation2.value != -1)) { alert("Duplicate Locations"); cmbLocation3.focus(); return false; } return true; } } // This function is used to initialize the priority and enabled fields related to each location combo-box function InitializeFields(index) { with (document.form) { switch(index) { case 1: { if (cmbLocation1.options[cmbLocation1.options.selectedIndex].value != -1) { txtPriority1.value = 1; chkEnabled1.checked = true; } else { txtPriority1.value = ''; chkEnabled1.checked = false; } break; } case 2: { if (cmbLocation2.options[cmbLocation2.options.selectedIndex].value != -1) { txtPriority2.value = 1; chkEnabled2.checked = true; } else { txtPriority2.value = ''; chkEnabled2.checked = false; } break; } case 3: { if (cmbLocation3.options[cmbLocation3.options.selectedIndex].value != -1) { txtPriority3.value = 1; chkEnabled3.checked = true; } else { txtPriority3.value = ''; chkEnabled3.checked = false; } break; } } } } // This function is used to check the required fields in materials_manage page function CheckMaterialInfo() { with (document.form) { if (cmbMaterialType.value == "") { cmbMaterialType.focus(); return false; } if (cmbLanguage.value == "") { cmbLanguage.focus(); return false; } if (cmbLocation1.options[cmbLocation1.options.selectedIndex].value == -1) { cmbLocation1.focus(); return false; } useraction.value = "AddEdit"; submit(); } } // This function is used to reset the fields in the filtration search form function ResetSearchForm() { with (document.form) { txtFromDate.value = ""; txtToDate.value = ""; txtSource.value = ""; txtTitle.value = ""; cmbMaterialType.options.selectedIndex = 0; cmbLanguage.options.selectedIndex = 0; cmbSortField.options.selectedIndex = 1; rdSortType[1].checked = true; } } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Manage Attachment Page Scripts *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ // This function is used to check the required fields in attachments_manage page function CheckAttachmentInfo(id) { var materialID = id; with (document.form) { if (txtName.value == "") { txtName.focus(); return false; } if (txtFileName.value == "") { txtFileName.focus(); return false; } if (txtDate.value == "") { txtDate.focus(); return false; } var ext = txtFileName.value; ext = ext.substring(ext.length-3,ext.length); ext = ext.toLowerCase(); var allowedExtensions = txtAllowedExtensions.value; var pos = allowedExtensions.indexOf(ext); if (pos==-1) { txtFileName.focus(); return false; } txtMaterialID.value = materialID; useraction.value = "AddEdit"; submit(); } } // This function is used to confirm deletion function ConfirmAttachmentDeletion(AttachmentID, MaterialID) { with (document.form) { { return false; } useraction.value = "Delete"; txtAttachmentID.value = AttachmentID; txtMaterialID.value = MaterialID; submit(); } } //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-* // Remove both the leading and the trailing space/s of a given string //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-* function Trim(str) { // Remove leading spaces and carriage returns while (str.substring(0,1) == ' ') { str = str.substring(1,str.length); } // Remove trailing spaces and carriage returns while (str.substring(str.length-1,str.length) == ' ') { str = str.substring(0,str.length-1); } return str; } /*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* * Search Control *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/ function SearchForMaterials() { with (document.form) { if (Trim(txtSearch.value)=="") { return false; } action = "../Home/search_results.php"; submit(); } }