var synchronize = true; var isNetscape = (navigator.appName=='Netscape');//check browser variable /************************ Function : adjustBracket Purpose : Replace ( and ) by " & " in a string Param : str: the string that use to find ( and ) return : string that is replaced ( and ) by " & " ********************/ function adjustBracket(str){ var fpos1 = str.indexOf("("); var fpos2 = str.indexOf(")"); if (fpos1 == 0 ) str = str.substring(1, str.length); if (fpos2 == 0 ) str = str.substring(1, str.length); var lpos1 = str.lastIndexOf("("); var lpos2 = str.lastIndexOf(")"); if (lpos1 !=-1 && lpos1 == str.length-1) str = str.substring(0, lpos1); if (lpos2 !=-1 && lpos2 == str.length-1) str = str.substring(0, lpos2); var mpos1 = str.indexOf(")"); var mpos2 = str.indexOf("("); if ((mpos2 - mpos1) <=2 && (mpos2 - mpos1) > 0){ var str1 = trim(str.substring(mpos1 +1,mpos2)); if(str1 =="") str = str.substring(0, mpos1) + " & " +str.substring(mpos2+1,str.length); } var pos1 = str.indexOf("(",0); if(pos1 !=-1) str = str.replace(/\(/g," & "); var pos2 = str.indexOf(")",0); if( pos2 != -1) str = str.replace(/\)/g," & "); return trim(str); } function adjustSpecialChar(str){ var posdot = str.indexOf(".",0); var posdash = str.indexOf("-",0); if (posdot != -1 || posdash != -1) return true else return false } /************************ Function : treatSearchAsterix Purpose : Replace * in a string that has the * stand alone (does not attach with a word. Ex: "me * or.*-or/*)or'*or not me") by ' sentence ' before search Param : strSearch: the string that user enter to search return : string that is replaced * by ' sentence ' ********************/ function treatSearchAsterix (strSearch) { var strQuery = " "+strSearch+" "; var pos = strQuery.indexOf('*'); if (pos > -1) { preChar=strQuery.charAt(pos-1); sufChar=strQuery.charAt(pos+1); re = /[A-Za-z0-9_,]/g; if ( !re.test(preChar) && !re.test(sufChar) ) { if (pos == 1) // remove the * at the first character strSearch = strSearch.substr(1); else if (pos == strQuery.length-2) // remove the * at the last character strSearch = strSearch.substring(0, strSearch.length-1); else // replace * by ' sentence ' strSearch = strSearch.replace('*', ' sentence '); } } return trim(strSearch); } /************************ Function : trim Purpose : Cut beginning and ending spaces, reduce number of middle spaces to 1 Param : str: string to be trimmed return : the processed string ********************/ function trim(str) { var middleSpacer = RegExp("\\s{2}","g"); var trimmer = RegExp("^\\s+|\\s+$","g"); var oldValue = "" while ( oldValue != str ) { oldValue = str; str = str.replace(middleSpacer," "); } return str.replace(trimmer,""); } /******************* Function : str2arr Purpose : cut the input string into an array Param : str: string to be cut, and the separator return : the array ********************/ function str2arr(strInput,strSeparator) { var arrResult = new Array(); arrResult[0] = ''; var count = 0; //add guard item if ((strInput.lastIndexOf(strSeparator) + strSeparator.length) < strInput.length) strInput += strSeparator; while (strInput.indexOf(strSeparator)>-1) { arrResult[count] = subStrLeft(strInput, strSeparator); strInput = subStrRight(strInput, strSeparator); count += 1; } return arrResult; } /******************* Function : arr2str Purpose : merge the input array to a string Param : arr: string to be merged, and the separator return : the result string ********************/ function arr2str(arrInput,strSeparator) { var strResult = ""; for (i=0; i < arrInput.length; i++) strResult += arrInput[i]+strSeparator; return strResult; } /******************* Function : subStrLeft Purpose : get the sub string of the input string which is on the left of strSeparator Param : strInput, strSeparator return : the result string ********************/ function subStrLeft(strInput, strSeparator) { return strInput.substring(0, strInput.indexOf(strSeparator)); } /******************* Function : subStrRight Purpose : get the sub string of the input string which is on the right of strSeparator Param : strInput, strSeparator return : the result string ********************/ function subStrRight(strInput, strSeparator) { return strInput.substring(strInput.indexOf(strSeparator) + strSeparator.length, strInput.length); } /******************* Function : strOrarr Purpose : distinguish the inpObj is an array or a string Param : inpObj return : the string "String" or "Array" accordingly ********************/ function strOrarr(inpObj) { var oldValue = inpObj[0]; inpObj[0] += "a"; if (oldValue == inpObj[0]) { return "String";} else { inpObj[0] = oldValue; return "Array"; } } /************************ function escapeValue purpose : escapes some special characters which are used as separators, and symptom of escaped str ************************/ function escapeValue(inpStr) { if (inpStr=="") return ""; var oldStr; oldStr = ""; while (inpStr.indexOf("~")>-1) { oldStr += subStrLeft(inpStr,"~") + "~nga"; inpStr = subStrRight(inpStr,"~"); } inpStr = oldStr + inpStr; oldStr = ""; while (oldStr != inpStr) { oldStr = inpStr; inpStr = inpStr.replace(",","~phay"); inpStr = inpStr.replace(";","~semi"); } return inpStr; } /************************ function: unescapeValue purpose : restore the escaped string ************************/ function unescapeValue(inpStr) { if (inpStr=="") return ""; var oldStr; oldStr=""; while (oldStr != inpStr) { oldStr = inpStr; inpStr = inpStr.replace("~phay",","); inpStr = inpStr.replace("~semi",";"); } oldStr=""; while (inpStr.indexOf("~nga")>-1) { oldStr += subStrLeft(inpStr,"~nga") + "~"; inpStr = subStrRight(inpStr,"~nga"); } inpStr = oldStr + inpStr; return inpStr; } /************************ Function : newWindow Purpose : Use to pop a window up and center the window Param : - strURL : URL of file - strWindowName : window name - intWidth : window width - intHeight : window height - blnScroll : scrollbar visibility ********************/ var newWindowtobeOpened = null;//reference to the popup window object function newWindow(strURL,strWindowName,intWidth,intHeight,blnScroll){ if ((newWindowtobeOpened != null) && (!newWindowtobeOpened.closed)) newWindowtobeOpened.close(); //To protect no more than 1 window at a time var intLeftPosition = (screen.width) ? (screen.width-intWidth)/2 : 0; var intTopPosition = (screen.height) ? (screen.height-intHeight)/2 : 0; var strSettings = 'dependent=yes,height=' + intHeight+ ',width=' + intWidth+ ',top=' + intTopPosition+ ',left=' + intLeftPosition+ ',scrollbars=' + blnScroll.toString(); newWindowtobeOpened = window.open(strURL,strWindowName,strSettings); return newWindowtobeOpened; }//newWindow /******************* Function : pushValuetoField Purpose : whatever the field type is, this function will try to push a value to that field (or field group) Param : objField, value ********************/ function pushValuetoField(objField, objValue) { if ((objField.type == "radio")|(objField.type == "checkbox")) { objField.checked = true; return; } if ((objField.type == "password")|(objField.type == "text")|(objField.type == "hidden")|(objField.type == "textarea")) { objField.value = objValue; return; } if (objField.type == "select-one") { objField.selectedIndex = -1; for (var i=0; i-1)) { return objField.options[objField.selectedIndex].value; } if (objField.type == "select-multiple") { var count = 0; var arrObjValue = new Array(); for (var i=0; i < objField.length; i++) if (objField.options[i].selected) { arrObjValue[count] = objField.options[i].value; count += 1; } return arrObjValue; }//if return ""; }//pullvalue /******************* Function : getField Purpose : Return : return instance of the given field name ********************/ function getField(fieldname) { field = eval("document.forms[0]."+fieldname); return field; } /******************* NamD: Rename getValue to getValueData to avoid conflict with getValue method of CKEditor Function : getValue Purpose : whatever the field type is, this function will try to get the value(s) of that field (or fields group) the differences between this function and pullValuefromField are: - this function has a more friendly interface than that of pullValuefromField, because this function receives field name as parameter while pullValuefromField accepts object Param : fieldname (string, for multiple values use array or string consists of names which are separated by ",") Return : value (arr (for multiple values) or string for single value) ********************/ function getValueData(fieldname,flag) { //text, hidden, textarea, password, radio, select-one, select-multiple (only 1 name is needed) if ((strOrarr(fieldname) == "String")&&(fieldname.indexOf(",")==-1)) { var objField = document.forms[0].elements[fieldname]; if ((objField[0])&&(objField[0].type=="radio")) { for (var i=0; i < objField.length; i++) if (objField[i].checked) //return pullValuefromField(objField[i]); //for faster but do not keep the strict flow return objField[i].value; }//radio if ((objField[0])&&(objField[0].type=="checkbox")) { var arrObjValue = new Array(); var count = 0; for (var i=0; i < objField.length; i++) if (objField[i].checked) { arrObjValue[count] = objField[i].value; count += 1; } return arrObjValue; }//checkboxes array if(!flag){ return pullValuefromField(objField);//other type } if(flag){ return pullAllfromField(fieldname);//other type } }//1 name else { //many names, checkboxes var arrObjField = new Array(); if (strOrarr(fieldname)=="String") arrObjField = str2arr(fieldname,","); else arrObjField = fieldname; var arrObjValue = new Array(); var count = 0; for (var i=0; i < arrObjField.length; i++) if (document.forms[0].elements[arrObjField[i]].checked) { //arrObjValue[count] = pullValuefromField(document.forms[0].elements[arrObjField[i]]); //for faster but do not keep the strict flow arrObjValue[count] = document.forms[0].elements[arrObjField[i]].value; count += 1; } return arrObjValue; } }//getValue /******************* Function : setValue Purpose : whatever the field type is, this function will try to set the value(s) of that field (or fields group) the differences between this function and pushValuefromField are: - this function has a more friendly interface than that of pushValuefromField, because this function receives field name as parameter while pushValuefromField accepts object - this function fires onchange event of the field while pushValuefromField doesn't Param : fieldname (string, for multiple values use array or string consists of names which are separated by ",") fieldvalue (string, for multiple values use array or string consists of names which are separated by ",") ********************/ function setValue(fieldname, fieldvalue,flag) { if ((strOrarr(fieldname) == "String")&&(fieldname.indexOf(",")==-1)) { var objField = document.forms[0].elements[fieldname]; if ((objField[0])&&(objField[0].type=="radio")) { for (var i=0; i < objField.length; i++) if (objField[i].value == fieldvalue) { var changed = objField[i].checked; objField[i].checked = true; changed = (changed != objField[i].checked) if ((objField[i].onchange != null)&&(changed))objField[i].onchange(); } if (synchronize) { obsoleteIt(fieldname,fieldvalue); } }//radio if ((objField[0])&&(objField[0].type=="checkbox")) { var arrObjValue = new Array(); if (strOrarr(fieldvalue)=="String") arrObjValue = str2arr(fieldvalue,","); else arrObjValue = fieldvalue; var setted = 0; for (var j=setted; j < arrObjValue.length; j++) for (var i=0; i < objField.length; i++) if (objField[i].value == arrObjValue[j]) { var changed = objField[i].checked; objField[i].checked = true; changed = (changed != objField[i].checked); setted += 1; if ((objField[i].onchange != null)&&(changed)) objField[i].onchange(); break; } if (synchronize) { obsoleteIt(fieldname,fieldvalue); } }//checkboxes var changed = pullValuefromField(objField); pushValuetoField(objField, fieldvalue);//other type changed = (changed != pullValuefromField(objField)); if ((objField.onchange != null)&&(changed)) objField.onchange(); if (synchronize) { obsoleteIt(fieldname,fieldvalue); } } else { //many names, checkboxes var arrObjField = new Array(); if (strOrarr(fieldname)=="String") arrObjField = str2arr(fieldname,","); else arrObjField = fieldname; var arrObjValue = new Array(); if (strOrarr(fieldvalue)=="String") arrObjValue = str2arr(fieldvalue,","); else arrObjValue = fieldvalue; var setted=0; for (var j=setted; j < arrObjValue.length; j++) { for (var i=0; i < arrObjField.length; i++) { var objField = document.forms[0].elements[arrObjField[i]]; if (objField.value == arrObjValue[j]) { var changed = objField.checked; //pushValuetoField(document.forms[0].elements[arrObjField[i]]); //for faster performance objField.checked = true; changed = (changed != objField.checked) setted += 1; if ((objField.onchange != null)&&(changed)) objField.onchange(); } } } if (synchronize) { if(!flag){ obsoleteIt(fieldname,fieldvalue); }else{ //obsoleteIt1(fieldname,fieldvalue); addValue(fieldname,fieldvalue); } } } }//setValue /******************* Function : clearValue Purpose : whatever the field type is, this function will try to clear its value Param : fieldname (string, for multiple values use array or string consists of names which are separated by ",") ********************/ function clearValue(fieldname) { if ((strOrarr(fieldname) == "String")&&(fieldname.indexOf(",")==-1)) { var objField = document.forms[0].elements[fieldname]; if ((objField[0])&&(objField[0].type=="radio")) { for (var i=0; i < objField.length; i++) { if (objField[i].checked) { objField[i].checked = false; if (objField[i].onchange != null) objField[i].onchange(); break; } } }//radiobuton if ((objField[0])&&(objField[0].type=="checkbox")) {//checkboxes array for (var i=0; i < objField.length; i++) { if (objField[i].checked==true) { objField[i].checked = false; if (objField[i].onchange != null) objField[i].onchange(); } } }//checkboxes array if ((objField.type == "password")|(objField.type == "text")|(objField.type == "hidden")|(objField.type == "textarea")) { var changed = objField.value; objField.value = ''; changed = (changed != ''); if ((objField.onchange != null)&&(changed)) objField.onchange(); } if (objField.type == "select-one") { var changed = (objField.selectedIndex != -1) objField.selectedIndex = 0;//for Netscape 6 objField.selectedIndex = -1; if ((objField.onchange != null)&&(changed)) objField.onchange(); } if (objField.type == "select-multiple") { var changed = (pullValuefromField(objField)!=null) for (i=0; i < objField.length; i++) objField.options[i].selected = false; if ((objField.onchange != null)&&(changed)) objField.onchange(); } } else { //many names, checkboxes var arrObjField = new Array(); if (strOrarr(fieldname)=="String") arrObjField = str2arr(fieldname,","); else arrObjField = fieldname; for (var i=0; i < arrObjField.length; i++) { objField = document.forms[0].elements[arrObjField[i]]; if (objField.checked==true) { objField.checked = false; if (objField.onchange != null) objField.onchange(); } } } }//clearValue /******************* Function : clearValue Purpose : whatever the field type is, this function will try to clear its value Param : fieldname (string, for multiple values use array or string consists of names which are separated by ",") ********************/ function obsoleteIt(fieldname,fieldvalue) { var strValue = ''; if (strOrarr(fieldvalue)=="String") strValue = fieldvalue; else strValue = arr2str(fieldvalue,","); if ((strOrarr(fieldname) == "String")&&(fieldname.indexOf(",")==-1)) { var objField = document.forms[0].elements[fieldname]; if ((objField[0])&&(objField[0].type=="radio")) { for (var i=0; i < objField.length; i++) { if ((objField[i].checked)&&(strValue.indexOf(objField[i].value)==-1)) { objField[i].checked = false; if (objField[i].onchange != null) objField[i].onchange(); break; } } }//radiobuton if ((objField[0])&&(objField[0].type=="checkbox")) {//checkboxes array for (var i=0; i < objField.length; i++) { if ((objField[i].checked==true)&&(strValue.indexOf(objField[i].value)==-1)) { objField[i].checked = false; if (objField[i].onchange != null) objField[i].onchange(); } } }//checkboxes array if ((objField.type == "password")|(objField.type == "text")|(objField.type == "hidden")|(objField.type == "textarea")) { if (strValue.indexOf(objField.value)==-1) { var changed = objField.value; objField.value = ''; changed = (changed != ''); if ((objField.onchange != null)&&(changed)) objField.onchange(); } } if (objField.type == "select-one") { if (strValue.indexOf(objField.options[objField.selectedIndex].value)==-1) { objField.selectedIndex = -1; if ((objField.onchange != null)&&(changed)) objField.onchange(); } } if (objField.type == "select-multiple") { var changed = false; for (i=0; i < objField.length; i++) { if ((objField.options[i].selected)&&(strValue.indexOf(objField.options[i].value)==-1)) { changed = true; objField.options[i].selected = false; } } if ((objField.onchange != null)&&(changed)) objField.onchange(); } } else { //many names, checkboxes var arrObjField = new Array(); if (strOrarr(fieldname)=="String") arrObjField = str2arr(fieldname,","); else arrObjField = fieldname; for (var i=0; i < arrObjField.length; i++) { objField = document.forms[0].elements[arrObjField[i]]; if ((objField.checked==true)&&(strValue.indexOf(objField.value)==-1)) { objField.checked = false; if (objField.onchange != null) objField.onchange(); } } } }//clearValue function getDuplicatedValue(fieldname,value){ var field=document.all[fieldname]; var arrValue=new Array(); if(value=='' || value==null){ return null; } value=""+value; arrValue=value.split(","); if(field.length<=0) return null; else{ for(var i=0;i