
function textCounter(field, countfield, maxlimit)
{
   if (field.value.length > maxlimit)
       field.value = field.value.substring(0, maxlimit);   
   else 
       countfield.value = maxlimit - field.value.length;
}

function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { return false; }
}

function IsEmptyOption(aTextField) {
   if (aTextField.selectedIndex == 0) {
      return true;
   }
   else { return false; }
}

function IsNumeric(aTextField)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < aTextField.value.length && IsNumber == true; i++) 
      { 
      Char = aTextField.value.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

//----------------
// Spinner
//----------------

function spinner_validation_non_mandatory(page, question, prompt)
{
   // And Logic   
   var validated = 1;
   for(var i=1; i<=prompt; i++)
   {
     if (!IsEmpty(document.getElementById("q_"+page+"_"+question+"_-"+i)) 
      && !IsNumeric(document.getElementById("q_"+page+"_"+question+"_-"+i)))
     {   validated = 0;
         break;
     }       
   }
   
  if (validated == 0)
  {   
     document.getElementById("q_"+page+"_"+question+ "_msg").innerHTML = "请填入正确的数字";     
     document.getElementById("q_"+page+"_"+question+ "_msg").className = "required";     
     return false;
  }
  
  return true;
}

//----------------
// Constant_sum
//----------------

function constant_sum_validation_non_mandatory(page, question, prompt, total)
{
   // And Logic   
   var validated = 1;
   var total_number = 0
   for(var i=1; i<=prompt; i++)
   {
     if (!IsEmpty(document.getElementById("q_"+page+"_"+question+"_-"+i)) 
      && !IsNumeric(document.getElementById("q_"+page+"_"+question+"_-"+i)))
     {   validated = 0;
         break;
     }
   }  
  
  if (validated == 0)
  {   
     document.getElementById("q_"+page+"_"+question+ "_msg").innerHTML = "请填入正确的数字";     
     document.getElementById("q_"+page+"_"+question+ "_msg").className = "required";     
     return false;
  }
  
  return true;
   
}

//----------------------
// Single_choice_matrix
//----------------------


//----------------------
// Date
//----------------------
function date_validation_non_mandatory(page, question, prompt)
{
  // And Logic
  var validated =1;
  for(var i=1; i<=prompt; i++)
  {      
    var box = document.getElementById("q_"+page+"_"+question+"_-"+i+"_month");
    var month = box.options[box.selectedIndex].value;
    box = document.getElementById("q_"+page+"_"+question+"_-"+i+"_day");
    var day = box.options[box.selectedIndex].value;
    box = document.getElementById("q_"+page+"_"+question+"_-"+i+"_year");
    var year = box.options[box.selectedIndex].value;

    if (year != "" || month != "" || day != "")
    {
        if (!isDate(month+"/" + day + "/" + year))	
	    {            
            validated = 0;
            break;
        }  
    }
  }
  
  if (validated == 0)
  {
      document.getElementById("q_"+page+"_"+question+ "_msg").innerHTML = "请填入正确的时间";     
      document.getElementById("q_"+page+"_"+question+ "_msg").className = "required";     
      return false;
  }
  
  return true;
  
}

//----------------
// single_choice
//----------------

function single_choice_validation_non_mandatory(page,question,prompt)
{        
    if (document.getElementById("q_"+page+"_"+question+"_"+prompt).value < 0
     && IsEmpty(document.getElementById("q_"+page+"_"+question+"_open_ended")) )
    {
       document.getElementById("q_"+page+"_"+question+ "_msg").innerHTML = "请填入相应的文字";     
       document.getElementById("q_"+page+"_"+question+ "_msg").className = "required";     
       return false;
    }  
    
    return true;
}

//----------------
// Multi_choice
//----------------
function multi_choice_validation_non_mandatory(page, question, prompt)
{
  if (document.getElementById("q_"+page+"_"+question+"_-1") != null)
  {
     if (!IsEmpty(document.getElementById("q_"+page+"_"+question+"_-1"))
       && IsEmpty(document.getElementById("q_"+page+"_"+question+"_open_ended")))
     {
         document.getElementById("q_"+page+"_"+question+ "_msg").innerHTML = "请填入相应的文字";     
         document.getElementById("q_"+page+"_"+question+ "_msg").className = "required";     
         return false;
     }         
  }    
  
  return true;   
  
}

//----------------
// dropdownlist
//----------------

//----------------
// comments
//----------------

//----------------
// Single_Line
//----------------


//--------------------
// Multi_choice_matrix
//--------------------


