// JavaScript Document
//check field value
function checkNull(obj){
   if(obj.value.trim()==""){
        markInvalid(obj);
    alert("Please enter a value in the highlighted field");
        return false;
   }
   obj.style.color="#ffffff";
    obj.style.backgroundColor = "#303030";
    return true;
}
 
 
function checkRange(obj, field, min){
   if(obj.value.trim()!=""){
     if((obj.value)<min || isNaN(obj.value))
     {
        markInvalid(obj);
    if( min == 1)
        alert(field + " must be greater than or equal to 1");
    else
        alert(field + " must be equal or greater than or equal to 1");
        return false;
     }
     else//valide
     {
        obj.style.color="#ffffff";
        obj.style.backgroundColor = "#303030";
        return true;
     }
   }
}
//focus and style change for indicating error
function markInvalid(obj){
        obj.style.color="#ff0000";
        obj.style.backgroundColor = "#ffffff";       
        obj.focus();
        obj.select();
}
//trim function for string
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,"");}
 
function ConfirmSubmit()
{
    
  
    txtamountDesired=document.getElementById("Viewsavecalc_amountDesired");
    txtnrOfYears=document.getElementById("Viewsavecalc_nrOfYears"); 
    txtinterestRate=document.getElementById("Viewsavecalc_interestRate");    
    txtinitialDeposit=document.getElementById("Viewsavecalc_initialDeposit"); 
    
    if(checkNull(txtamountDesired,"Total Amount")!=true)return false;
    if(checkNull(txtnrOfYears,"Number of years")!=true)return false;
    if(checkNull(txtinterestRate,"Interest rate")!=true)return false;
    if(checkNull(txtinitialDeposit,"Initial Deposit")!=true)return false;
    
    if(checkRange(txtamountDesired,"Amount to Save",1)!=true)return false;
    if(checkRange(txtnrOfYears,"Number of years",1)!=true)return false;
    if(checkRange(txtinterestRate,"Interest rate",0)!=true)return false;
    if(checkRange(txtinitialDeposit,"First deposit",1)!=true)return false;
    return true;
}