 function add_commas(nStr)
      { 
      nStr += '';
      x = nStr.split('.');
      x1 = x[0];
      x2 = x.length > 1 ? '.' + x[1] : '';
      var rgx = /(\d+)(\d{3})/;
      while (rgx.test(x1)) {
      x1 = x1.replace(rgx, '$1' + ',' + '$2');
      }
      return x1 + x2;
      }



function bcheck(fd,msg){
//alert(msg);
if(fd.value=='') {
if(msg!=''){ 
alert(msg);
fd.focus();
}
return true;              
}else{ 
return false;
}

}


function isdomain(dm){

var str=dm.value;	
if(str!=''){
s=str.indexOf('http');

if(s>=0){
alert("Only domain name should be entered as Site Url\nPlease do not put http://");
dm.focus();
return true;
}

}


}


function chkstr(fd,fn){

j=fd.value.length;
        ok = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of a-z, A-Z\n';
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}


function chkalpha(fd,fn){

j=fd.value.length;
        ok = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,:;!@#$%^&*().&~\n\r-_$?><=/\ ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of alpha numeric characters\n';
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}


function chknum(fd,fn){

j=fd.value.length;
        ok = '1234567890.-)(+ ';
        for(i=0; i<j; i++){
        if (ok.indexOf(fd.value.charAt(i))<0){
                msg = fn+' can only consist of numeric characters\n';
                alert(msg);
				fd.focus();  
				return true;  
                i=99;
        }
        }

}


function DropDownSelect(obj, val)
	{
		var i;
		var len = obj.options.length;
		for (i=0; i<len; i++)
		{
			if (obj.options[i].value == val)
			{
				obj.selectedIndex = i;
				break;
			}
		}
	}


function isEmail (s) {
        //if (isEmpty(s))
    //   if (isEmail.arguments.length == 1) return defaultEmptyOK;
    //   else return (isEmail.arguments[1] == true);
   
    // is s whitespace?
    //if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i;
    var ok;
    var sLength = s.length;
    
//  ok = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_@.';
//      for(i=0; i<sLength; i++){
//      if (ok.indexOf(s.value.charAt(i))<0){
//              return false;
//      }
//      }
    i=1;
    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }
    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;
    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }
    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}




function checkEmailValid(emailStr,msg)
{
	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 errMsg="";   
	var matchArray=emailStr.match(emailPat)

	if (matchArray==null) 
	{
	   errMsg=errMsg+"The "+msg+" Email Address seems incorrect!";
	   return errMsg;
	}
	else
	{
	  var user=matchArray[1]
	  var domain=matchArray[2]
	  if (user.match(userPat)==null) 
	  {
		errMsg=errMsg+"The "+msg+" Email Address seems incorrect 111!";
		return errMsg;       
	  }
	  var IPArray=domain.match(ipDomainPat)
	  if (IPArray!=null) 
	  {
		  for (var i=1;i<=4;i++) 
			  {
			if (IPArray[i]>255) 
				{
				errMsg=errMsg+"The "+msg+" Email Address seems incorrect 222!";
				return errMsg;
				}//IF
			  }//for
	   }//IP Array
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) 
	   {
		 errMsg=errMsg+"The "+msg+" Email Address seems incorrect 333!";
		 return errMsg;
	   }
	   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>6) 
	   {
		 errMsg=errMsg+"The "+msg+" Email Address seems incorrect 444!";
		 return errMsg;	
	   } 
	   if (len<2) 
	   {
		 errMsg=errMsg+"The "+msg+" Email Address seems incorrect 555!";
		 return errMsg;	 
	   } 
	 }//End  Match
	return "0";
}

function goUrl(loc)
	{
	document.location.href=loc;
	}
	
function notYet()
	{
	alert("Sorry this item is not available!")
	}


function WholeNumberOnly(opt,msg)
{
	var pos=opt.value.indexOf(".")
	if  (pos>0)
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }	 
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }
}

function WholeNumberOnlyEmpty(opt,msg)
{
	var pos=opt.value.indexOf(".")
	if  (pos>0)
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value="";
		opt.focus();
	  }	 
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be whole numbers!"); 
		opt.value="";
		opt.focus();
	  }
}

function TinyIntOnly(opt,msg)
{
	if(opt.value>255)
	{
		alert("The "+msg+" can not be greater than 255!");
		opt.value="";
		opt.focus();
	}
}

function NumericOnly(opt,msg)
{
	if  (isNaN(opt.value))
	  {
		alert("The "+msg+" can only be numbers!"); 
		opt.value=opt.value.substr(0,opt.value.length-1);
		opt.focus();
	  }
}

function SetZero(opt)
{
	if  (opt.value=="")
	  {
		opt.value=0;
	  }
}

function SetBlank(opt)
{
	if  (opt.value=="0")
	  {
		opt.value="";
	  }
}
	
