// JavaScript Document
function jsCheckNum(obj,ret,allowBlank) {
	contents=obj.value
    if (((contents / contents) != 1) && (contents != 0)) {
			if (ret==true){
				return false
			}else{
				imeMsg("alert",'Please enter only a number into this text box')
				obj.focus();
			}
	}
	if(allowBlank==false){
		if(contents==""){
		return false;
		}
	}
}

//Return Currency Format 1,123,123,123.23
function outputMoney(number) {
   return outputDollars(Math.floor(number-0) + '') + outputCents(number - 0);
  
}

function outputDollars(number) {
    if (number.length <= 3)
        return (number == '' ? '0' : number);
    else {
        var mod = number.length%3;
        var output = (mod == 0 ? '' : (number.substring(0,mod)));
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod ==0) && (i ==0))
                output+= number.substring(mod+3*i,mod+3*i+3);
            else
                output+= ',' + number.substring(mod+3*i,mod+3*i+3);
        }
        return (output);
    }
}

function outputCents(amount) {
  //  amount = Math.round( ( (amount) - Math.floor(amount) ) *100);
   // return (amount < 10 ? '.0' + amount : '.' + amount);
	amount=amount+"";
	c=amount.indexOf(".")
	if (c>=0 )
		retVal=amount.substring(c,c+3) 
	else
		retVal=".00"
	return retVal;
	
}
//convert formated Currency to int 1,223,345.00 ->1223345.00
function getCurrency(str,eur) {
   isMoneyFormatAmount = 0.00;
   isMoneyFormatString = "0.00";
   if(!str) return false;
   str = "" + str; // force string
   for (var i=0; i<str.length;i++) {
      var ch = str.charAt(i);
      if (!isNum(ch) && ch!='.' && ch != ',' && ch !='-') return false
   }

   var sign = 1;
   var signChar = '';
   isMoneyFormatAmount = 0.00;
   isMoneyFormatString = "0.00";

   if (str.length > 1) {
      signChar = str.substring(0,1);
      if (signChar == '-' || signChar == '+' ) {
         if (signChar == '-') sign = -1;         
         str = str.substring(1);
      }
      else signChar = '';
   }
   var decimalPoint = '.';
   var thDelim = ',';
   if (eur) { 
      decimalPoint = ','
      thDelim = '.';
   }
   test1 = str.split(decimalPoint);
   if (test1.length == 2) { // Decimals found
      if (test1[1].length > 2) return false; // more than 2 decimals
      if (isNum(test1[1])) {
         if (test1[1] < 9 && test1[1].charAt(0) > 0) test1[1] = new String(test1[1]+"0");
      }
      else return false; 
   }
   else test1[1] = "00"; // force decimals
   if (test1[0] == '') test1[0] = 0;
   if (test1[0] && test1[0].indexOf(thDelim) != -1) {
      test2 = test1[0].split(thDelim);  
      if (test2.length >= 2) { // thousands found
         var thError = false;
         for (var i=0;i<test2.length;i++) {
            if (test2[i].length < 3 && i != 0) { thError = true; break; } // all thousands exept the first.
            if (!isNum(test2[i])) { thError = true; break; } // all numbers
         }
         if (thError) return false;
         test1[0] = test2.join('')
      }
   }
   isMoneyFormatAmount = (parseInt(test1[0]) + parseFloat('.'+test1[1]))*sign;
 //  isMoneyFormatString = new String(""+signChar+""+parseInt(test1[0])) +'.'+test1[1];
   return isMoneyFormatAmount;
} 
function getCurrWithDecimal(num,dec){
	var retVal=""
	b=num+""
	c=b.indexOf(".")
	if (dec==undefined){
		dec=3;
	}
	if (c>=0 )
		retVal=b.substring(0,c+dec) 
	else
		retVal=b
	return retVal;
}
function isNum(str) {
  if(!str) return false;
  for(var i=0; i<str.length; i++){
    var ch=str.charAt(i);
    if (".0123456789".indexOf(ch) ==-1) return false;

  }
  return true;
} 

function clearCombo(obj){
		for (i = obj.options.length; i >= 0; i--) 
		{
			obj.options[i] = null;
		}
}
function addOption1(obj,label,value){
		var myOption = new Option(label,value); 
		obj.add(myOption,obj.options.length); 
}
function addOption(obj,label,value,index){
		var myOption = new Option(label,value); 
		if(index==undefined){
			obj.add(myOption,obj.options.length); 
		}else{
			obj.add(myOption,index); 
		}
}
function selectByValue(obj,val){
	if(val!="" && val!=undefined && val!="NULL"){
		for (i =0;i< obj.options.length; i++){
				if(obj.options[i].value==val){
					obj.options[i].selected=true;
					return true
					break;
				}
			}
	}
	return false
}
function selectByLabel(obj,val){
	if(val!="" && val!=undefined && val!="NULL"){
		for (i =0;i< obj.options.length; i++){
				if(obj.options[i].text==val){
					obj.options[i].selected=true;
					return true
					break;
				}
			}
	}
	return false
}
function disableRight(){
	if(event.button==2){
		imeMsg("Alert","\nRight Click is prohibited!! ");
	}
}
function imeMsg(type,msg){
//window.showModalDialog("/js/msgbox.asp?msg="+msg+"&type="+type,"","dialogHeight: 210px; dialogWidth: 380px;  status: no; scroll:no;help: no");
	if(type=="Confirm"){
		if(confirm("Confirmation:\n_______________________________________\t\n\n"+msg+"\n_______________________________________\t")){
			return true
		}else{
			return false
		}
	}else{
		alert(type+"\n_______________________________________\t\n\n"+msg+"\n_______________________________________\t")
	}
}
function left(e) {
    if (navigator.appName == 'Netscape' && (e.modifiers & Event.SHIFT_MASK) && (e.which == 1)) return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && window.event.shiftKey && (event.button == 1)) {
        imeMsg("Alert:","\nShift Click not allowed");
	        return false;
    }else{
	disableRight()
	}
}
//document.onmousedown=disableRight;
//document.onmousedown=left;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
//window.onmousedown=left;

function load_asp(url,w,h){
	if(w==undefined || w==""){
		w=380;
	}
	if(h==undefined || h==""){
		h=210;
	}
	x=window.showModalDialog(url,"","dialogHeight: "+h+"px; dialogWidth: "+w+"px;  status: no;scroll:no; help: no");
	return x
}
function toolOver(x){
	 x.className='ToolBarMenuOver'
}
function toolOut(x){
	x.className='ToolBarMenu'
}
function getRadioValue(radioObj){
	j=radioObj.length;
	for (i=0; i<j; i++){
		if(radioObj[i].checked) var radiovalue = radioObj[i].value
	}
	return radiovalue
}
function isTel(str) {
  if(!str) return false;
  for(var i=0; i<str.length; i++){
    var ch=str.charAt(i);
    if ("-0123456789".indexOf(ch) ==-1) return false;

  }
  return true;
} 
function isEmail(str) {
  if(!str) return false;
    if (str.indexOf("@") ==-1) return false;
  return true;
}
function showStatus(x){
window.status=x;
}
