function replaceText(oldStr,newStr,str) {
   var convertStr='';
   for (i=0; i < str.length ; i++) {
      if (str.substr(i,1)==oldStr) {
         convertStr = convertStr + newStr;
      } else {
         convertStr = convertStr + str.substr(i,1);
      }
   }
   return convertStr;
}

function printScreen() {
   window.print();
}

function calculate(thisform) {
   var con;
   total=0;
   var value;
   len = thisform.elements.length;
   for(var i=0; i<len; i++) {
      if (thisform.elements[i].name == 'amt') {
	 value = replaceText('','X',thisform.elements[i].value);
         thisform.elements[i].value=value;
         if (thisform.elements[i].value.length==0) {
	    thisform.elements[i].value=0;
	 }
	 if (isNaN(thisform.elements[i].value)) {
	    thisform.elements[i].value=0;
         }
         total = (total*1) + parseFloat((thisform.elements[i].value*1));
      } 
   }
   thisform.totalamt.value=total;
}

function isDigit(validDigit)
{
  var thisobject=validDigit;
  nr1=thisobject.value;
  flg=0;
  str="";
  spc=""
  arw="";
  if (nr1.length > 0){
    for (var i=0 ; i<nr1.length ; i++){
      cmp="0123456789"
      tst=nr1.substring(i,i+1)
      if (cmp.indexOf(tst)<0){
        flg++;
        str+=" "+tst;
        spc+=tst;
        arw+="^";
      }
        else{
	  arw+="_";
	}
    }
    if (flg!=0){
      if (spc.indexOf(" ")>-1) {
        str+=" and a space";
      }
    alert("Value must be integer");
//    thisobject.focus();
    thisobject.value="0";
    return false;
    }
  } else {
    thisobject.value="0";
  }
  return true;
}


function isDecimal(validDecimal)
{
   thisobj=validDecimal;
   value = replaceText(' ','',thisobj.value);
   thisobj.value=value;
   if (isNaN(value)){
      alert("Value must be decimal");
//      thisobj.focus();
      thisobj.value="";
      return false;
   } else {
        return true;
   }
}


function valDate(dd,mm,yyyy)
    {
	var tf=true;
	switch(dd){
	  case 29:
	    if(mm==2){
	      if(yyyy%4!=0){    //is not leap year
	  	alert("The date you insert is not valid!\n" +
		      "There is no 29th in Feb in the year " +yyyy);
		tf=false;
	      }
	    }			
	  break;
	  case 30:
	    if(mm==2){	
	      alert("The date you insert is not valid!\n" +
		    "There is no 30th in month " +mm);
		tf=false;				
	    }
	  break;
	  case 31:
	    if ((mm==2)||(mm==4)||(mm==6)||(mm==9)||(mm==11)){				
	      alert("The date you insert is not valid!\n" +
		    "There is no 31st in month " +mm);
	       tf=false;
   	    }
 	  break;
	}
	return tf;
}

function dateOK(validDate)
    {
    var value;	
    var thisobj = validDate;	
    var dd = thisobj.value.substring(0,2);
    var mm = thisobj.value.substring(3,5);
    var yyyy = thisobj.value.substring(6,10);
    value = replaceText('.','/',thisobj.value);
    thisobj.value=value;
    if (thisobj.value.length != 10 && thisobj.value.length != 0)
        {
        alert("You must fill in the appropriate date (dd/mm/yyyy)");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    if (isNaN(dd) || isNaN(mm) || isNaN(yyyy))
        {
	alert("Date should be numeric (dd/mm/yyyy)");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    var Day = parseInt(dd, 10);
    if (Day < 1 || 31 < Day)
        {
        alert("Day is out of range");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    var Month = parseInt(mm, 10);
    var Year = parseInt(yyyy, 10);
    if (Month < 1 || 12 < Month)
        {
        alert("Month is out of range");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    if (!valDate(Day, Month, Year)) {
//	thisobj.focus();
	thisobj.value="";
        return false;
	}
    }

function timeOK(validTime)
    {
    var thisobj = validTime;	
    var hh = thisobj.value.substring(0,2);
    var mm = thisobj.value.substring(2,4);
    var ss = thisobj.value.substring(4,6);
    if (thisobj.value.length != 6 && thisobj.value.length != 0)
        {
        alert("You must fill in the appropriate date (hhmmss)");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    if (isNaN(hh) || isNaN(mm) || isNaN(ss))
        {
        alert("Time should be numeric (hhmmss)");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    var hour = parseInt(hh, 10);
    if (hour < 0 || 23 < hour)
        {
        alert("Hour is out of range");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    var minutes = parseInt(mm, 10);
    if (minutes < 0 || 59 < minutes)
        {
        alert("Minutes is out of range");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    var seconds = parseInt(ss, 10);
    if (seconds < 0 || 59 < seconds)
        {
        alert("Seconds is out of range");
//	thisobj.focus();
	thisobj.value="";
        return false;
        }
    }

function goPage(httpadd) {
//   location.href=httpadd;
location.replace(httpadd);
}

function saveData(thisform,message) {
   alert(message);
   thisform.submit();
}

function newWindow(add) {
     newWin = window.open(add,'','resizable=no,toolsbar=no,width=500,height=300,scrollbars=yes');
     newWin.focus();
}


