sbseparator=','; sbdecimal_point='.'; /////////////email function function emailCheck (emailStr,sbwhere) ///////sbwhere=1 for front end,sbwhere=2 for back end { 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) { if(sbwhere==1) alert("Email address seems incorrect (check @ and .'s)") else alert("Email address seems incorrect (check @ and .'s)") return false } var user=matchArray[1] var domain=matchArray[2] if (user.match(userPat)==null) { if(sbwhere==1) alert("The username doesn't seem to be valid.") else alert("The username doesn't seem to be valid.") return false } var IPArray=domain.match(ipDomainPat) if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { if(sbwhere==1) alert("Destination IP address is invalid!") else alert("Destination IP address is invalid!") return false } } return true } var domainArray=domain.match(domainPat) if (domainArray==null) { if(sbwhere==1) alert("The domain name doesn't seem to be valid.") else alert("The domain name doesn't seem to be valid.") return false } var atomPat=new RegExp(atom,"g") var domArr=domain.match(atomPat) var len=domArr.length if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) { if(sbwhere==1) alert("The address must end in a valid domain, or two letter country.") else alert("The address must end in a valid domain, or two letter country.") return false } if (len < 2) { if(sbwhere==1) var errStr="This address is missing a hostname!" else var errStr="This address is missing a hostname!" alert(errStr) return false } return true; } function sbis_empty(sbstr) { sbnew_str=sbstr.replace(/^\s+|\s+$/g,""); if(sbnew_str.length>0) return (false); else return (true); } function sbcurrency_display_format(amount) { amount=amount.toString().replace(/\./,sbdecimal_point); return(amount); } function sbcurrency_calculation_format(value) { var pattern_sp=/,/g; var pattern_pt=/\./g; value=value.toString().replace(pattern_sp,""); //remove thousand separator if any value=value.toString().replace(pattern_pt,"."); //restore decimal point return value; } function seo_string(field_name,str,dirlist) { dir_pat=RegExp("^("+dirlist.replace(/,/g,"|")+")$","i"); dir_str=dirlist.replace(/,/g,", "); if(str.match(/[\.\/\?& ]/)) return (field_name+" must not contain \.\/\?& characters"); else if(str.match(dir_pat) ) return ("This value of "+field_name+" is not allowed. Try appending /removing some characters to the value"); else return false; } function sbconvert_toseo(title,seo) { //a=title.value.replace(/^[^a-zA-Z]+/,""); //a=a.replace(/[^a-zA-Z0-9_\-]+/g,"_"); //a=a.replace(/[^a-zA-Z]+$/,""); a=title.value.replace(/[\.\/\?& ]+/g,"_"); seo.value=a.toLowerCase(); } function deci(t) { var a=new Number(); a=Math.round(t*100); //alert(a); if(a==0) var str='000'; if(a < 10) var str= '00'+String(a.toString()); else { if((a >= 10) && (a < 100)) var str= '0'+String(a.toString()); else var str=new String(a.toString()); } ///alert(str); t1=str.substr(0,(str.length-2))+"."+str.substr((str.length-2),2); return t1; } function changetime(extime) { date_str=""; cur=new Date(); curtime=cur.getTime(); curtime=Math.floor(curtime/1000); timediffer=extime-curtime; if(timediffer > 86400) { days=Math.floor(timediffer/86400); //converting to days timediffer=timediffer%86400; if(days < 10) days = "0"+days; date_str=days+"d "; } if(timediffer>3600) { hours=Math.floor(timediffer/3600);// convering to hours timediffer=timediffer%3600; if(hours < 10) hours = "0"+hours; date_str += hours+"h "; } if(timediffer>60) { minutes=Math.floor(timediffer/60);// convering to hours timediffer=timediffer%60; if(minutes < 10) minutes = "0"+minutes; date_str += minutes+"m "; } if(timediffer<=60 && timediffer>0) { if(timediffer < 10) timediffer = "0"+timediffer; date_str += timediffer+"s "; } if(date_str=="") date_str = "Expired"; else date_str += " left"; return(date_str) }