sbseparator=',';
sbdecimal_point='.';
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 emailCheck (emailStr,isAdmin)
{
var sbmsgArr=new Array();
if(isAdmin == true)
{
sbmsgArr[0]="Email address seems incorrect (check @ and .'s)";
sbmsgArr[1]="The username doesn't seem to be valid";
sbmsgArr[2]="Destination IP address is invalid";
sbmsgArr[3]="The domain name doesn't seem to be valid";
sbmsgArr[4]="The address must end in a valid domain, or two letter country";
sbmsgArr[5]="This address is missing a hostname";
}
else
{
sbmsgArr[0]="Email address seems incorrect (check @ and .\'s)";
sbmsgArr[1]="The username doesn\'t seem to be valid";
sbmsgArr[2]="Destination IP address is invalid";
sbmsgArr[3]="The domain name doesn\'t seem to be valid";
sbmsgArr[4]="The address must end in a valid domain, or two letter country";
sbmsgArr[5]="This address is missing a hostname";
}
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) {
alert(sbmsgArr[0])
return false
}
var user=matchArray[1]
var domain=matchArray[2]
if (user.match(userPat)==null) {
alert(sbmsgArr[1])
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) {
alert(sbmsgArr[2])
return false
}
}
return true
}
var domainArray=domain.match(domainPat)
if (domainArray==null) {
alert(sbmsgArr[3])
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) {
alert(sbmsgArr[4])
return false
}
if (len<2) {
var errStr=sbmsgArr[5];
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 sbseo_stringJS(field_name,field_value,isAdmin)
{
var dirlist="admin,ckeditor,core,counterimages,images,include,ipn,jscolor,lang,sbclassified_icons,thumbs1,thumbs2,tinymce,uploadedimages";
var sbmsgArr=new Array();
if(isAdmin == true)
{
sbmsgArr[0]=''+field_name+' must not contain & /?.% characters (i.e '+sbBlockCharNamesJS+')';
sbmsgArr[1]='This value of '+field_name+' is not allowed. Try appending / removing some characters to the value';
}
else
{
sbmsgArr[0]=''+field_name+' must not contain & /?.% characters';
sbmsgArr[1]='This value of '+field_name+' is not allowed. Try appending / removing some characters to the value';
}
dir_pat=RegExp("^("+dirlist.replace(/,/g,"|")+")$","i");
// dir_str=dirlist.replace(/,/g,", ");
if(field_value.match(/[& \/\?\.%]/))
return (sbmsgArr[0]);
else if(field_value.match(dir_pat) )
return (sbmsgArr[1]);
else
return false;
}
function sbconvert_toseo(title,seo)
{
a=title.value.replace(/[& /?.%]+/g,"_");
seo.value=a;
}
function seo_dircompare(arr)
{
for(i=0;i < arr.length;i++)
{
str1=RegExp(arr[i],"i");
for(j=i+1;j < arr.length;j++)
{
str2=RegExp(arr[j],"i");
if(arr[i].match(str2) || arr[j].match(str1))
return ("Value must not be substring of other_"+j);
}
}
return false;
}
function sbreturn_2_point_decimal(t)
{
var a=new Number();
a=Math.round(t*100);
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());
}
t1=str.substr(0,(str.length-2))+"."+str.substr((str.length-2),2);
return t1;
}