/* PURPOSE: Calendar functions IN: OUT: */ function y2k(number) { return (number < 1000) ? number + 1900 : number; } function format_date(adate) { return (adate.getMonth()+1) + '/' + adate.getDate() + '/' + y2k(adate.getYear()); } function Monday(yyyy,mm,dd) { mm -= 1; // JavaScript months start at 0 theDate = new Date(yyyy,mm,dd); daynumber = theDate.getDay(); // 0 = monday, 6 = sunday if (daynumber > 0) daynumber-=1; else daynumber += 6; // Previous week... adjust = daynumber*1000*60*60*24; theMonday = new Date(theDate.getTime() - adjust); return theMonday.toString(); } function jsDatePicker( szField, szDate, szAction){ var form = document.forms[0]; var field = form.elements[szField]; if(szAction == "1") { field.value=szDate; } field.focus(); return field.value; } /* PURPOSE: Opens people lookup dialog box. IN: strField - the field name where to set person selected */ function LoadPeopleLookup(strField, strAction, strMulti){ var db="/" + getCurrentDbPath(); if ( strMulti == "1" ) { window.open(db + "/dlgPeopleLookupMulti?OpenForm&NABfield=" + strField + "&NABaction=" + strAction,"Address","toolbar=no,width=300,height=460") } else { window.open(db + "/dlgPeopleLookup?OpenForm&NABfield=" + strField + "&NABaction=" + strAction,"Address","toolbar=no,width=300,height=460") } } /* PURPOSE: Remove leading blanks from our string. IN: str - the string we want to LTrim */ function LTrim(str){ var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(0)) != -1) { var j=0, i = s.length; while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++; s = s.substring(j, i); } return s; } /* PURPOSE: Remove trailing blanks from our string. IN: str - the string we want to RTrim */ function RTrim(str){ var whitespace = new String(" \t\n\r"); var s = new String(str); if (whitespace.indexOf(s.charAt(s.length-1)) != -1) { var i = s.length - 1; // Get length of string while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--; s = s.substring(0, i+1); } return s; } /* PURPOSE: Remove trailing and leading blanks from our string. IN: str - the string we want to Trim OUT: A Trimmed string! */ function Trim(str){ return RTrim(LTrim(str)); } /* PURPOSE: Validates numeric expressions IN: str - the number to validate OUT: boolean indicating if str is a number */ function IsNumeric(str){ var re=/[0-9, '.', '$', '%']/; var dec = 0; for(var i=0;i 1) return false; if (!chr.match(re)) return false; } return true; } /* PURPOSE: Displays/Hides document elements such as DIV, SPAN, etc. IN: toHide = Id element to hide, toShow= Id element to show OUT: */ function ShowHideSection(toHide, toShow){ if(toShow!=""){ eval("document.all." + toShow + ".style.display='block'"); } if(toHide!=""){ eval("document.all." + toHide + ".style.display='none'"); } } /* PURPOSE: Determines if the passed form object is empty IN: obj - the object to validate OUT: boolean indicating if obj is empty */ function IsEmpty(obj){ var strType=obj.type; if(strType=="select-one"){ if(!(obj.selectedIndex==-1 || obj.options[obj.selectedIndex].text=="")) return false; } if(strType=="radio" || strType=="checkbox"){ var objM=eval("document.forms[0]." + obj.name); for(i=0;i tag Out: True if the browser support DHTML, False otherwise */ function toggleMenu ( currMenu ) { if ( document.getElementById ) { thisMenu = document.getElementById ( currMenu ).style if ( thisMenu.display == "block" ) { thisMenu.display = "none" } else { thisMenu.display = "block" } return false } else { return true } } /* PURPOSE: Check if a string value is a valid date JMinata 07/25/2002 IN: Date value as string Out: True if the date is valid */ function checkdate( a ) { var err=0 if (a.length != 10) err=1 b = parseInt(a.substring(0, 2),10)// month c = a.substring(2, 3)// '/' d = parseInt(a.substring(3, 5),10)// day e = a.substring(5, 6)// '/' f = parseInt(a.substring(6, 10),10)// year if ((b<1 || b>12 || isNaN(a.substring(0, 2)) || a.substring(0, 2).indexOf('.') !=-1) ) err = 1 if (c != '/'&&c!='-') err = 1 if ((d<1 || d>31|| isNaN(a.substring(3, 5)) || a.substring(3, 5).indexOf('.') !=-1) ) err = 1; if (e != '/'&&e!='-') err = 1 if (f<0000 || f>9999 || isNaN(a.substring(6, 10)) || a.substring(6, 10).indexOf('.') !=-1) err = 1 //whatever years are acceptable to you can be put here if (b==4 || b==6 || b==9 || b==11){ if (d==31) err=1 } if (b==2){ var g=parseInt(f/4,10) if (isNaN(g)) { err=1 } if (d>29) err=1 if (d==29 && ((f/4)!=parseInt(f/4,10))) err=1 } if (err==1) { return false; } else { return true; } } /* PURPOSE: Format a date string to "mm/dd/yyyy" format JMinata 07/26/2002 IN: Date value as string. It accepts "mm/dd", "mm-dd", "mm/dd/yyyy", "mm-dd-yyyy" format Out: date string in "mm/dd/yyyy" format */ function formatDate ( strDate ) { var f = document.forms[0]; var now = new Date; var arrayOfDate; var d; var m; var y; if ( strDate.indexOf ( "/" ) != -1 ) { arrayOfDate = strDate.split ( "/" ) } else { if ( strDate.indexOf ( "-" ) != -1 ) { arrayOfDate = strDate.split ( "-" ) } else { return strDate } } switch ( arrayOfDate.length.toString() ) { case "2" : if ( IsNumeric ( arrayOfDate[0] ) ) { m = arrayOfDate[0] if ( m.length < 2 ) { m = "0" + arrayOfDate[0] } } else { return strDate } if ( IsNumeric ( arrayOfDate[1] ) ) { d = arrayOfDate[1] if ( d.length < 2 ) { d = "0" + arrayOfDate[1] } } else { return strDate } y = now.getFullYear(); break; case "3" : if ( IsNumeric ( arrayOfDate[0] ) ) { m = arrayOfDate[0] if ( m.length < 2 ) { m = "0" + arrayOfDate[0] } } else { return strDate } if ( IsNumeric ( arrayOfDate[1] ) ) { d = arrayOfDate[1] if ( d.length < 2 ) { d = "0" + arrayOfDate[1] } } else { return strDate } if ( IsNumeric ( arrayOfDate[2] ) ) { y = arrayOfDate[2] if ( y.length == 2 ) { y = "20" + arrayOfDate[2] } else if ( y.length == 4 ) { y = arrayOfDate[2] } else { return strDate } } else { return strDate } break; default : return strDate } return m + "/" + d + "/" + y; } /* PURPOSE: Opens people lookup dialog box. JMinata 10/9/02 IN: strField - the field name where to set person selected strAction - "Save" to save the opener form or "Refresh" to refresh the opener form strText - the id of the tag */ function CRMLoadPeopleLookup(strField, strAction, strText){ var db = "/" + getCurrentDbPath(); window.open(db + "/webDlgPeopleLookup?OpenForm&NABfield=" + strField + "&NABaction=" + strAction + "&NABtext=" + strText,"Address","toolbar=0,resizable=1,scrollbars=auto,width=500,height=460") } /* PURPOSE: Opens people lookup dialog box. JMinata 10/9/02 IN: strField - the field name where to set person selected strAction - "Save" to save the opener form or "Refresh" to refresh the opener form strText - the id of the tag */ function CRMLoadPeopleLookupSingle ( strField, strAction, strText ) { var db = "/" + getCurrentDbPath(); window.open(db + "/webDlgPeopleLookupSingle?OpenForm&NABfield=" + strField + "&NABaction=" + strAction + "&NABtext=" + strText,"Address","toolbar=no,width=300,height=460") } /* PURPOSE: Get profile field attributes from reference database JMinata 10/9/02 - Created function JMinata 4/1/03 - Added a new parameter for attributes lookup field value IN: strFieldNum - the field number strPos - the position of the attributes strAttr - the value of the attributes lookup field */ function CRMGetProfileAttributes ( strFieldNum, strPos, strAttr ) { var f = document.forms[0]; var re = / /gi; var retString = ""; var attrValue = ""; if ( f.SFProfileAttributesLookup ) { if ( strAttr ) { attrValue = strAttr } else { attrValue = f.SFProfileAttributesLookup.value } } else { return "" } var arrayOfValues = attrValue.split ( "@@" ); if ( arrayOfValues[strFieldNum - 1] ) { var fieldAttrib = arrayOfValues[strFieldNum - 1] } else { return "" } var aValue = fieldAttrib.split ( "~" ); if ( aValue[ strPos - 1] ) { var retValue = aValue[ strPos - 1] } if ( retValue.indexOf ( "$$" ) != -1 ) { arrayOfValues = retValue.split ( "$$" ); for ( i = 0; i < arrayOfValues.length; i++ ) { retString += arrayOfValues[i].replace(re, "+") + "," } return retString } else { return retValue.replace(re, "+") } } /* PURPOSE: Generic function to show reference lookup values in a dialog box JMinata 10/9/02 IN: */ function CRMSelectValues ( keyName, fieldName, dialogName, firstMatch, viewName, id, action ) { var db = "/" + getCurrentDbPath(); var refDb = getRefDbPath(); var width = "260"; var height = "260"; // JMinata 6/25/03 - If below conditions are met, open picklist dialog instead of the usual select if ( keyName == "*ALL" && viewName != "($VSYSCTLKWbyKey)" && ( dialogName == "webDlgSelectSingleNoTextInput" || dialogName == "webDlgSelectMultiNoTextInput" ) ) { if ( dialogName == "webDlgSelectSingleNoTextInput" ) { CRMPicklistSingle ( viewName, "", fieldName, id, "", refDb ); } else { CRMPicklistMultiNoListBox ( viewName, "", fieldName, id, "", refDb ) } } else { switch ( dialogName ) { case "webDlgSelectSingleWithTextInput": width = "260"; height = "320"; break; case "webDlgSelectMultiWithTextInput": width = "500"; height = "340"; break; case "webOppDlgSelectSingleNoTextInput": width = "600"; height = "260"; break; } window.open(db + "/" + dialogName + "?OpenForm&key=" + keyName + "&field=" + fieldName + "&first=" + firstMatch + "&view=" + viewName + "&id=" + id + "&action=" + action,"Selection","toolbar=0,resizable=1,scrollbars=auto,width=" + width + ",height=" + height) } } /* PURPOSE: Function to switch view in enTouch.List JMinata 10/11/02 IN: */ function CRMSwitchView ( viewType, viewSort ) { var f = document.forms[0]; var strURL = location.href.toString() var pos = strURL.indexOf ( "&viewtype=" ); window._doClick('$Refresh',this,null); if ( pos != -1 ) { location.href = strURL.substr ( 0, pos ) + "&viewtype=" + viewType + "&viewsort=" + viewSort; } else { location.href = strURL + "&viewtype=" + viewType + "&viewsort=" + viewSort; } } /* PURPOSE: Function to show addresses dialog box JMinata 10/12/02 IN: Form name and Address Keyword Name */ function CRMShowAddresses ( form, keyName ) { switch ( form ) { case "frmCompany": width = "600"; height = "320"; break; case "frmContact": width = "600"; height = "370"; break; } window.open( "/" + getCurrentDbPath() + "/webDlgAddresses?OpenForm&form=" + form + "&key=" + keyName, "Addresses", "toolbar=0,resizable=1,scrollbars=auto,width=" + width + ",height=" + height ) } /* PURPOSE: Function to show single value picklist JMinata 10/12/02 */ function CRMPicklistSingle ( view, category, fields, inners, refresh, dbpath ) { var db = getCurrentDbPath(); if ( dbpath != null && dbpath != '' ) { db = dbpath } window.open( "/" + db + "/webDlgPicklistSingle?OpenForm&view=" + view + "&category=" + category + "&fields=" + fields + "&inners=" + inners +"&refresh=" + refresh, "Picklist", "toolbar=0,resizable=1,scrollbars=1,width=660,height=480" ) } /* PURPOSE: Function to show multi-value picklist that sets a list box field on the opening form JMinata 10/12/02 */ function CRMPicklistMulti ( view, category, field1, field2, dbpath, refresh ) { var db = getCurrentDbPath(); if ( dbpath != null && dbpath != '' ) { db = dbpath } window.open( "/" + db + "/webDlgPicklistMulti?OpenForm&view=" + view + "&category=" + category + "&field1=" + field1 + "&field2=" + field2 + "&refresh=" + refresh, "", "toolbar=0,resizable=1,scrollbars=1,width=920,height=600" ) } /* PURPOSE: Function to show multi-value picklist that sets a multi value field on the opening form JMinata 6/25/03 */ function CRMPicklistMultiNoListBox ( view, category, field, id, refresh, dbpath ) { var db = getCurrentDbPath(); if ( dbpath != null && dbpath != '' ) { db = dbpath } window.open( "/" + db + "/webDlgPicklistMultiNoListBox?OpenForm&view=" + view + "&category=" + category + "&field=" + field + "&id=" + id + "&refresh=" + refresh, "", "toolbar=0,resizable=1,scrollbars=1,width=920,height=600" ) } /* PURPOSE: Function to show addresses dialog box JMinata 10/12/02 IN: Form name and Address Keyword Name */ function CRMOpenDocument ( docID, dbpath ) { var db = getCurrentDbPath(); if ( dbpath != null ) { db = dbpath } if ( docID != "" ) { location.href = "/" + db + "/vwDocID/" + docID + "?OpenDocument" } else { alert ( "Unable to locate the selected document" ) } } /* PURPOSE: Function to show addresses dialog box JMinata 10/12/02 IN: Form name and Address Keyword Name */ function CRMOpenSendMail( sourceUNID ) { window.open( "/" + getCurrentDbPath() + "/webDlgSendMailWithAttachments?OpenForm&sourceunid=" + sourceUNID, "", "toolbar=0,resizable=1,scrollbars=1,width=760,height=700" ) } /* PURPOSE: Function to open JMinata 5/1/03 IN: Form name and Address Keyword Name */ function CRMOpenProfileCompanyContact( action, fieldPos, valuePos, choicesField, docIDField ) { window.open( "/" + getCurrentDbPath() + "/webDlgProfileCompanyContact?OpenForm&Action=" + action + "&FieldPos=" + fieldPos + "&ValuePos=" + valuePos + "&ChoicesField=" + choicesField + "&DocIDField=" + docIDField, "", "toolbar=0,resizable=1,scrollbars=0,width=380,height=240" ) } /* PURPOSE: Generic function to show reference lookup values in a dialog box JMinata 10/9/02 IN: */ function CRMActivityNotification ( docID, action ) { var db = "/" + getCurrentDbPath(); var width = "500"; var height = "340"; window.open(db + "/webDlgActivityNotification?OpenForm&docid=" + docID + "&action=" + action,"Selection","toolbar=0,resizable=1,scrollbars=auto,width=" + width + ",height=" + height) } /* Purpose: Launch company website SBedathur: 04/03/03 */ function launchWebSite ( URL ) { if ( URL == '') { alert ( "No web address listed!"); return false } else { var url = URL.toLowerCase() ; if ( url.indexOf ("http://") != -1){ window.open ( URL ) } else { window.open ( 'http://' + URL ) } } } /* Purpose: Launch company website SBedathur: 04/03/03 */ function getStockInfo ( stockSite , stockSymbol ) { var url = '' ; if (stockSymbol == '') { alert ( 'No Stock Symbol specified!') ; return false }; switch (stockSite) { case "Google": url = "http://www.google.com/search?hl=en&prev=/search%3Fq%3Dibm%26hl%3Den%26sa%3DG&q=stocks:" + stockSymbol + "+" ; break; default: alert ( 'Unable to determine the website!') break; }; var goURL = url.split ( ' ' ).join ( '+'); if ( goURL != '') { window.open ( goURL ) } } /* PURPOSE: Validates numeric expressions IN: str - the number to validate OUT: boolean indicating if str is a number */ function IsNonZeroPositiveInteger (str){ var re=/[1-9]/; var dec = 0; for(var i=0;i 1) return false; if (!chr.match(re)) return false; } return true; } /* PURPOSE: Validates numeric expressions IN: str - the number to validate OUT: boolean indicating if str is a number */ function IsPositiveInteger (str){ var re=/[0-9]/; var dec = 0; for(var i=0;i 1) return false; if (!chr.match(re)) return false; } return true; } /* PURPOSE: Function to get reference db path JMinata 6/25/03 */ function getRefDbPath() { return "" } /* PURPOSE: Function to create new opp detail JMinata 7/1/03 IN: sourceDocID - the doc id of the opp doc category - the category of the opp detail */ function CreateOppDetail ( sourceDocID, category ) { var db = getCurrentDbPath(); window.open( "/" + db + "/frmOppDetail?OpenForm&SourceDocID=" + sourceDocID + "&Category=" + category, "", "toolbar=1,resizable=1,scrollbars=1,width=680,height=600" ) } /* PURPOSE: Function to edit an Opp Detail Doc JMinata 7/2/03 */ function EditOppDetail() { var db = getCurrentDbPath(); var docid = ""; var ff = document.ViewFrame.document.forms[0]; if ( ff.$$SelectDoc ) { if ( ff.$$SelectDoc.length ) { for ( i = 0; i < ff.$$SelectDoc.length; i++ ) { if ( ff.$$SelectDoc[i].checked ) { if ( docid != "" ) { alert ( "You can only edit one document at a time" ); return false; } docid = ff.$$SelectDoc[i].value; } } } } else { if ( ff.$$SelectDoc.checked ) { docid = ff.$$SelectDoc.value; } } if ( docid == "" ) { alert ( "Please select a document to be edited" ) } else { window.open ( "/" + getCurrentDbPath() + "/vwDocID/" + docid + "?EditDocument", "", "toolbar=1,resizable=1,scrollbars=1,width=680,height=600" ) } } /* PURPOSE: Function to delete selected docs JMinata 7/2/03 IN: docIDs - the doc ids of the selected docs */ function DeleteSelectedDocs() { var docids = ""; var ff = document.ViewFrame.document.forms[0]; var db = getCurrentDbPath(); if ( ff.$$SelectDoc ) { if ( ff.$$SelectDoc.length ) { for ( i = 0; i < ff.$$SelectDoc.length; i++ ) { if ( ff.$$SelectDoc[i].checked ) { if ( docids == "" ) { docids = ff.$$SelectDoc[i].value } else { docids += "," + ff.$$SelectDoc[i].value } } } } } else { if ( ff.$$SelectDoc.checked ) { docids = ff.$$SelectDoc.value; } } if ( docids == "" ) { alert ( "Please select documents to be deleted" ) } else { window.open ( "/" + getCurrentDbPath() + "/webDlgDeleteDocs?OpenForm&docids=" + docids, "", "toolbar=0,resizable=1,scrollbars=1,width=260,height=180" ) } }