/********************************************************************************* ** The contents of this file are subject to the vtiger CRM Public License Version 1.0 * ("License"); You may not use this file except in compliance with the License * The Original Code is: vtiger CRM Open Source * The Initial Developer of the Original Code is vtiger. * Portions created by vtiger are Copyright (C) vtiger. * All Rights Reserved. ********************************************************************************/ //Utility Functions if (document.all) var browser_ie=true else if (document.layers) var browser_nn4=true else if (document.layers || (!document.all && document.getElementById)) var browser_nn6=true function getObj(n,d) { var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); } if(!(x=d[n])&&d.all) x=d.all[n]; for(i=0;!x&&i=0) datesep="-" else if (dateval.indexOf(".")>=0) datesep="." else if (dateval.indexOf("/")>=0) datesep="/" switch (userDateFormat) { case "yyyy-mm-dd" : dateelements[0]=dateval.substr(dateval.lastIndexOf(datesep)+1,dateval.length) //dd dateelements[1]=dateval.substring(dateval.indexOf(datesep)+1,dateval.lastIndexOf(datesep)) //mm dateelements[2]=dateval.substring(0,dateval.indexOf(datesep)) //yyyyy break; case "mm-dd-yyyy" : dateelements[0]=dateval.substring(dateval.indexOf(datesep)+1,dateval.lastIndexOf(datesep)) dateelements[1]=dateval.substring(0,dateval.indexOf(datesep)) dateelements[2]=dateval.substr(dateval.lastIndexOf(datesep)+1,dateval.length) break; case "dd-mm-yyyy" : dateelements[0]=dateval.substring(0,dateval.indexOf(datesep)) dateelements[1]=dateval.substring(dateval.indexOf(datesep)+1,dateval.lastIndexOf(datesep)) dateelements[2]=dateval.substr(dateval.lastIndexOf(datesep)+1,dateval.length) } return dateelements; } function compareDates(date1,fldLabel1,date2,fldLabel2,type) { var ret=true switch (type) { case 'L' : if (date1>=date2) {//DATE1 VALUE LESS THAN DATE2 alert(fldLabel1+" should be less than "+fldLabel2) ret=false } break; case 'LE' : if (date1>date2) {//DATE1 VALUE LESS THAN OR EQUAL TO DATE2 alert(fldLabel1+" should be less than or equal to "+fldLabel2) ret=false } break; case 'E' : if (date1!=date2) {//DATE1 VALUE EQUAL TO DATE alert(fldLabel1+" should be equal to "+fldLabel2) ret=false } break; case 'G' : if (date1<=date2) {//DATE1 VALUE GREATER THAN DATE2 alert(fldLabel1+" should be greater than "+fldLabel2) ret=false } break; case 'GE' : if (date131 || mm<1 || mm>12 || yyyy<1 || yyyy<1000) { alert("Please enter a valid "+fldLabel) getObj(dateFldName).focus() return false } if ((mm==2) && (dd>29)) {//checking of no. of days in february month alert("Please enter a valid "+fldLabel) getObj(dateFldName).focus() return false } if ((mm==2) && (dd>28) && ((yyyy%4)!=0)) {//leap year checking alert("Please enter a valid "+fldLabel) getObj(dateFldName).focus() return false } switch (parseInt(mm)) { case 2 : case 4 : case 6 : case 9 : case 11 : if (dd>30) { alert("Please enter a valid "+fldLabel) getObj(dateFldName).focus() return false } } if (patternValidate(timeFldName,fldLabel,"TIME")==false) return false var timeval=getObj(timeFldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var hourval=parseInt(timeval.substring(0,timeval.indexOf(":"))) var minval=parseInt(timeval.substring(timeval.indexOf(":")+1,timeval.length)) var currObj=getObj(timeFldName) if (hourval>23 || minval>59) { alert("Please enter a valid "+fldLabel) currObj.focus() return false } var currdate=new Date() var chkdate=new Date() chkdate.setYear(yyyy) chkdate.setMonth(mm-1) chkdate.setDate(dd) chkdate.setHours(hourval) chkdate.setMinutes(minval) if (type!="OTH") { if (!compareDates(chkdate,fldLabel,currdate,"current date & time",type)) { getObj(dateFldName).focus() return false } else return true; } else return true; } function dateTimeComparison(dateFldName1,timeFldName1,fldLabel1,dateFldName2,timeFldName2,fldLabel2,type) { var dateval1=getObj(dateFldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var dateval2=getObj(dateFldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var dateelements1=splitDateVal(dateval1) var dateelements2=splitDateVal(dateval2) dd1=dateelements1[0] mm1=dateelements1[1] yyyy1=dateelements1[2] dd2=dateelements2[0] mm2=dateelements2[1] yyyy2=dateelements2[2] var timeval1=getObj(timeFldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var timeval2=getObj(timeFldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var hh1=timeval1.substring(0,timeval1.indexOf(":")) var min1=timeval1.substring(timeval1.indexOf(":")+1,timeval1.length) var hh2=timeval2.substring(0,timeval2.indexOf(":")) var min2=timeval2.substring(timeval2.indexOf(":")+1,timeval2.length) var date1=new Date() var date2=new Date() date1.setYear(yyyy1) date1.setMonth(mm1-1) date1.setDate(dd1) date1.setHours(hh1) date1.setMinutes(min1) date2.setYear(yyyy2) date2.setMonth(mm2-1) date2.setDate(dd2) date2.setHours(hh2) date2.setMinutes(min2) if (type!="OTH") { if (!compareDates(date1,fldLabel1,date2,fldLabel2,type)) { getObj(dateFldName1).focus() return false } else return true; } else return true; } function dateValidate(fldName,fldLabel,type) { if(patternValidate(fldName,fldLabel,"DATE")==false) return false; dateval=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var dateelements=splitDateVal(dateval) dd=dateelements[0] mm=dateelements[1] yyyy=dateelements[2] if (dd<1 || dd>31 || mm<1 || mm>12 || yyyy<1 || yyyy<1000) { alert("Please enter a valid "+fldLabel) getObj(fldName).focus() return false } if ((mm==2) && (dd>29)) {//checking of no. of days in february month alert("Please enter a valid "+fldLabel) getObj(fldName).focus() return false } if ((mm==2) && (dd>28) && ((yyyy%4)!=0)) {//leap year checking alert("Please enter a valid "+fldLabel) getObj(fldName).focus() return false } switch (parseInt(mm)) { case 2 : case 4 : case 6 : case 9 : case 11 : if (dd>30) { alert("Please enter a valid "+fldLabel) getObj(fldName).focus() return false } } var currdate=new Date() var chkdate=new Date() chkdate.setYear(yyyy) chkdate.setMonth(mm-1) chkdate.setDate(dd) if (type!="OTH") { if (!compareDates(chkdate,fldLabel,currdate,"current date",type)) { getObj(fldName).focus() return false } else return true; } else return true; } function dateComparison(fldName1,fldLabel1,fldName2,fldLabel2,type) { var dateval1=getObj(fldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var dateval2=getObj(fldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var dateelements1=splitDateVal(dateval1) var dateelements2=splitDateVal(dateval2) dd1=dateelements1[0] mm1=dateelements1[1] yyyy1=dateelements1[2] dd2=dateelements2[0] mm2=dateelements2[1] yyyy2=dateelements2[2] var date1=new Date() var date2=new Date() date1.setYear(yyyy1) date1.setMonth(mm1-1) date1.setDate(dd1) date2.setYear(yyyy2) date2.setMonth(mm2-1) date2.setDate(dd2) if (type!="OTH") { if (!compareDates(date1,fldLabel1,date2,fldLabel2,type)) { getObj(fldName1).focus() return false } else return true; } else return true } function timeValidate(fldName,fldLabel,type) { if (patternValidate(fldName,fldLabel,"TIME")==false) return false var timeval=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var hourval=parseInt(timeval.substring(0,timeval.indexOf(":"))) var minval=parseInt(timeval.substring(timeval.indexOf(":")+1,timeval.length)) var currObj=getObj(fldName) if (hourval>23 || minval>59) { alert("Please enter a valid "+fldLabel) currObj.focus() return false } var currtime=new Date() var chktime=new Date() chktime.setHours(hourval) chktime.setMinutes(minval) if (type!="OTH") { if (!compareDates(chktime,fldLabel1,currtime,"current time",type)) { getObj(fldName).focus() return false } else return true; } else return true } function timeComparison(fldName1,fldLabel1,fldName2,fldLabel2,type) { var timeval1=getObj(fldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var timeval2=getObj(fldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '') var hh1=timeval1.substring(0,timeval1.indexOf(":")) var min1=timeval1.substring(timeval1.indexOf(":")+1,timeval1.length) var hh2=timeval2.substring(0,timeval2.indexOf(":")) var min2=timeval2.substring(timeval2.indexOf(":")+1,timeval2.length) var time1=new Date() var time2=new Date() time1.setHours(hh1) time1.setMinutes(min1) time2.setHours(hh2) time2.setMinutes(min2) if (type!="OTH") { if (!compareDates(time1,fldLabel1,time2,fldLabel2,type)) { getObj(fldName1).focus() return false } else return true; } else return true; } function numValidate(fldName,fldLabel,format,neg) { var val=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '') if (format!="any") { if (isNaN(val)) { var invalid=true } else { var format=format.split(",") var splitval=val.split(".") if (neg==true) { if (splitval[0].indexOf("-")>=0) { if (splitval[0].length-1>format[0]) invalid=true } else { if (splitval[0].length>format[0]) invalid=true } } else { if (val<0) invalid=true else if (splitval[0].length>format[0]) invalid=true } if (splitval[1]) if (splitval[1].length>format[1]) invalid=true } if (invalid==true) { alert("Invalid "+fldLabel) getObj(fldName).focus() return false } else return true } else { if (neg==true) var re=/^(-|)\d+(\.\d\d*)*$/ else var re=/^\d+(\.\d\d*)*$/ } if (!re.test(val)) { alert("Invalid "+fldLabel) getObj(fldName).focus() return false } else return true } function intValidate(fldName,fldLabel) { var val=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '') if (isNaN(val) || val.indexOf(".")!=-1) { alert("Invalid "+fldLabel) getObj(fldName).focus() return false } else return true } function numConstComp(fldName,fldLabel,type,constval) { var val=parseFloat(getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')) constval=parseFloat(constval) var ret=true switch (type) { case "L" : if (val>=constval) { alert(fldLabel+" should be less than "+constval) ret=false } break; case "LE" : if (val>constval) { alert(fldLabel+" should be less than or equal to "+constval) ret=false } break; case "E" : if (val!=constval) { alert(fldLabel+" should be equal to "+constval) ret=false } break; case "NE" : if (val==constval) { alert(fldLabel+" should not be equal to "+constval) ret=false } break; case "G" : if (val<=constval) { alert(fldLabel+" should be greater than "+constval) ret=false } break; case "GE" : if (valwindow.screen.height) top=findPosY(currObj)+window.screenTop-height-30 //30 is a constant to avoid positioning issue if (left+width>window.screen.width) left=findPosX(currObj)+window.screenLeft-width } else if (browser_nn4 || browser_nn6) { top+=(scrY-pgeY) left+=(scrX-pgeX) if (top+height+30>window.screen.height) top=findPosY(currObj)+(scrY-pgeY)-height-30 if (left+width>window.screen.width) left=findPosX(currObj)+(scrX-pgeX)-width } features="width="+width+",height="+height+",top="+top+",left="+left+";"+features eval(winInst+'=window.open("'+baseURL+'","'+winName+'","'+features+'")') } var scrX=0,scrY=0,pgeX=0,pgeY=0; if (browser_nn4 || browser_nn6) { document.addEventListener("click",popUpListener,true) } function popUpListener(ev) { if (browser_nn4 || browser_nn6) { scrX=ev.screenX scrY=ev.screenY pgeX=ev.pageX pgeY=ev.pageY } } function toggleSelect(state,relCheckName) { if (getObj(relCheckName)) { if (typeof(getObj(relCheckName).length)=="undefined") { getObj(relCheckName).checked=state } else { for (var i=0;i