  var separator = ",";  // use comma as 000's separator
  var decpoint = ".";  // use period as decimal point
  var percent = "%";
  var currency = "$";  // use dollar sign for currency

  function formatNumber(number, format) {  // use: formatNumber(number, "format")   
    if (number - 0 != number) return null;  // if number is NaN return null
    var useSeparator = format.indexOf(separator) != -1;  // use separators in number
    var usePercent = format.indexOf(percent) != -1;  // convert output to percentage
    var useCurrency = format.indexOf(currency) != -1;  // use currency format
    var isNegative = (number < 0);
    number = Math.abs (number);
    if (usePercent) number *= 100;
    format = strip(format, separator + percent + currency);  // remove key characters
    number = "" + number;  // convert number input to string

     // split input value into LHS and RHS using decpoint as divider
    var dec = number.indexOf(decpoint) != -1;
    var nleftEnd = (dec) ? number.substring(0, number.indexOf(".")) : number;
    var nrightEnd = (dec) ? number.substring(number.indexOf(".") + 1) : "";

     // split format string into LHS and RHS using decpoint as divider
    dec = format.indexOf(decpoint) != -1;
    var sleftEnd = (dec) ? format.substring(0, format.indexOf(".")) : format;
    var srightEnd = (dec) ? format.substring(format.indexOf(".") + 1) : "";

     // adjust decimal places by cropping or adding zeros to LHS of number
    if (srightEnd.length < nrightEnd.length) {
      var nextChar = nrightEnd.charAt(srightEnd.length) - 0;
      nrightEnd = nrightEnd.substring(0, srightEnd.length);
      if (nextChar >= 5) nrightEnd = "" + ((nrightEnd - 0) + 1);  // round up

      while (srightEnd.length > nrightEnd.length) {
        nrightEnd = "0" + nrightEnd;
      }

      if (srightEnd.length < nrightEnd.length) {
        nrightEnd = nrightEnd.substring(1);
        nleftEnd = (nleftEnd - 0) + 1;
      }
    } else {
      for (var i=nrightEnd.length; srightEnd.length > nrightEnd.length; i++) {
        if (srightEnd.charAt(i) == "0") nrightEnd += "0";  // append zero to RHS of number
        else break;
      }
    }

     // adjust leading zeros
    sleftEnd = strip(sleftEnd, "#");  // remove hashes from LHS of format
    while (sleftEnd.length > nleftEnd.length) {
      nleftEnd = "0" + nleftEnd;  // prepend zero to LHS of number
    }

    if (useSeparator) nleftEnd = separate(nleftEnd, separator);  // add separator
    var output = nleftEnd + ((nrightEnd != "") ? "." + nrightEnd : "");  // combine parts
    output = ((useCurrency) ? currency : "") + output + ((usePercent) ? percent : "");
    if (isNegative) {
      // patch suggested by Tom Denn 25/4/2001
      output = (useCurrency) ? "(" + output + ")" : "-" + output;
    }
    return output;
  }

  function strip(input, chars) {  // strip all characters in 'chars' from input
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++)
      if (chars.indexOf(input.charAt(i)) == -1)
        output += input.charAt(i);
    return output;
  }

  function separate(input, separator) {  // format input using 'separator' to mark 000's
    input = "" + input;
    var output = "";  // initialise output string
    for (var i=0; i < input.length; i++) {
      if (i != 0 && (input.length - i) % 3 == 0) output += separator;
      output += input.charAt(i);
    }
    return output;
  }
  
function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^(.+@.+\\.[a-zA-Z]+)$");
  return (!r1.test(str) && r2.test(str));
}  
  
function isNum(argvalue) {

 var argvalue = argvalue.toString();

 if (argvalue.length == 0) {
  return false;
 }
 
 for (var n = 0; n < argvalue.length; n++) {
  if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9") {
   return false;
  }
  return true;
 }
}

function IsInt(objStr,sign,zero) {

    var reg;    

    var bolzero;  
    
    if(Trim(objStr)=="") {

        return false;

    } else {

        objStr=objStr.toString();

    }    


    if((sign==null)||(Trim(sign)=="")) {

        sign="+-";

    }

    if((zero==null)||(Trim(zero)=="")) {

        bolzero=false;

    } else {

        zero=zero.toString();

        bolzero=true;

    }

    switch(sign) {

        case "+-":

            reg=/(^-?|^\+?)\d+$/;            

            break;

        case "+": 

            if(!bolzero) {
                reg=/^\+?[0-9]*[1-9][0-9]*$/;

            } else {

                reg=/^\+?[0-9]*[0-9][0-9]*$/;

            }

            break;

        case "-":

            if(!bolzero) {

                reg=/^-[0-9]*[1-9][0-9]*$/;

            } else {

                reg=/^-[0-9]*[0-9][0-9]*$/;

            }            

            break;

        default:

            return false;

            break;

    }

    var r=objStr.match(reg);

    if(r==null) {

        return false;

    } else {        

        return true;     

    }

}





function IsFloat(objStr,sign,zero) {

    var reg;
    var bolzero;    

    if(Trim(objStr)=="") {

        return false;

    } else {

        objStr=objStr.toString();

    }    

    

    if((sign==null)||(Trim(sign)=="")) {

        sign="+-";

    }

    if((zero==null)||(Trim(zero)=="")) {

        bolzero=false;

    } else {

        zero=zero.toString();

        bolzero=true;

    }

    switch(sign) {

        case "+-":

            reg=/^((-?|\+?)\d+)(\.\d+)?$/;

            break;

        case "+": 

            if(!bolzero) {

                reg=/^\+?(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;

            } else {

                reg=/^\+?\d+(\.\d+)?$/;

            }

            break;

        case "-":

            if(!bolzero) {

                reg=/^-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;

            } else {

                reg=/^((-\d+(\.\d+)?)|(0+(\.0+)?))$/;

            }            

            break;

        default:

            return false;

            break;

    }

    

    var r=objStr.match(reg);

    if(r==null) {

        return false;

    } else {        

        return true;     

    }

}


function LTrim(str) {

	if(str) {
		str = str.replace(/^\s+/,"");
	} else {
		str = '';
	}
	
	return str;
}

function RTrim(str) {

	if(str) {
		str = str.replace(/\s+$/,"");
	} else {
		str = '';
	}
	
	return str;
}

function Trim(str) {
	return RTrim(LTrim(str));
}

function formHandler(formObj, strMessageText, escapeStrings, setcursor, dontValidate, aryIgnoreFields, bIgnoreCheck){
	if(formObj.oCNForm){
		var bReturn = formObj.oCNForm.handleSubmit(formObj, strMessageText, escapeStrings, setcursor, dontValidate, aryIgnoreFields, bIgnoreCheck);
		return bReturn;
	}
}

function PopupWindow (myLocation, scroll, width, height, windowName) {
	var oWin;
	
	//window.showModalDialog(myLocation,'','dialogHeight:'+height+'px;dialogWidth:'+width+'px;center:yes;resizeable:yes;help:no;status:no');
	if (!windowName) {
		windowName = '';
	}
	oWin = window.open(myLocation, windowName,'menubar=0,toolbar=0,location=0,directories=0,status=0,scrollbars=' + scroll + ',resizable=yes,width=' + width + ',height=' + height);
	oWin.focus();
	
}

function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   //alert(inputString.length);
   if (inputString.length != 0) {
   
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      
      //alert(fromString);
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
   
   }
} 


function validate() {
	try {	
		var args = validate.arguments;		
		var bIsCNForm = (args[0].getValue)? true : false;
		if(bIsCNForm){	//called from CNForm object
			var oCNForm = args[0];
			var regExpText = args[1];
			var sName = args[2];
			var errorMsg  = args[3];
			var value = oCNForm.getValue(sName); 
			var regExpObj = new RegExp(regExpText,'');
			if (!regExpObj.test(Trim(value))) {

				// displays an error message
				alert('CHANNELNET FIELD VALIDATION ERROR\nThe current field contains an invalid value:\n' + errorMsg);
				return false;
			} else {
				return true;
			}		
		} else {	//called from Form object
			var formElement = args[0];
			var regExpText = args[1];
			var errorMsg = args[2];
			
			
			var regExpObj = new RegExp(regExpText,'');
			if (previousFieldName!=formElement.name) {
				// checks to see if the field value matches the regular expression
				if (!regExpObj.test(Trim(formElement.value))) {

					// displays an error message
					alert('CHANNELNET FIELD VALIDATION ERROR\nThe current field contains an invalid value:\n' + errorMsg);

					// sets the field value to ""
					/*
					if (formElement.type=="text" 
						|| formElement.type=="textarea" 
						|| formElement.type=="password" 
						|| formElement.type=="file" 
						|| formElement.type=="hidden") {
							formElement.value = "";
					}
					*/
					// selects the field value
					if (formElement.focus) formElement.focus();
					if (formElement.select) formElement.select();
					
				
					previousFieldName = formElement.name;
					return false;
				} else {
					return true;
				}
			}

			return true;		
		}
		
	}
	catch(e){
	}
}

function loadForm(sFormName){
	var oForm = document.forms[sFormName];
	var oCNForm = new CNForm();
	oCNForm.fromForm(oForm);
}

function loadFormObj(oForm){
	var oCNForm = new CNForm();
	oCNForm.fromForm(oForm);
}

function GetRightNow() {

	var RightNow = new Date();

	var todaydatum =  RightNow.getDate();
	
	
	var todaymonad =  RightNow.getMonth() + 1;
	
	var todayar =  RightNow.getFullYear();
	
	var sHour = RightNow.getHours();
	
	var sMinute = RightNow.getMinutes();
	
	var sSecond = RightNow.getSeconds();
	
	if (todaydatum < 10) {
	
		todaydatum = "0" + todaydatum;
	
	}
	
	if (todaymonad < 10) {
	
		todaymonad = "0" + todaymonad;
	
	}	
	
	if (sHour < 10) {
	
		sHour = "0" + sHour;
	
	}
	
	if (sMinute < 10) {
	
		sMinute = "0" + sMinute;
	
	}
	
	if (sSecond < 10) {
	
		sSecond = "0" + sSecond;
	
	}	
	
	
	
	var sRightnow = todaymonad + "-" + todaydatum + "-" + todayar + " " + sHour + ":" + sMinute + ":" + sSecond;
	
	return(sRightnow);
}

function removecomma(input)
{
    var dec = input.indexOf(",") != -1;
    var ireturn;
    if(dec){
        var nleftEnd  = input.substring(0, input.indexOf(","));
        var nrightEnd = input.substring(input.indexOf(",") + 1);
        ireturn = nleftEnd+nrightEnd;
    }else
        ireturn = input;
    return eval(ireturn);    
}
