//validate v6 cust num
// Remove leading and trailing whitespace from a string
function trimWhiteSpace(string) {
	var newString  = '';
	var substring  = '';
	beginningFound = false;

	// copy characters over to a new string
	// retain whitespace characters if they are between other characters
	for (var i = 0; i < string.length; i++) {

		// copy non-whitespace characters
		if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {

			// if the temporary string contains some whitespace characters, copy them first
			if (substring != '') {
				newString += substring;
				substring = '';
			}
			newString += string.charAt(i);
			if (beginningFound == false) beginningFound = true;
		}

		// hold whitespace characters in a temporary string if they follow a non-whitespace character
		else if (beginningFound == true) substring += string.charAt(i);
	}
	return newString;
}

function validate_customer_number(num) {
  var s=new String(num);
  var i,x=0,y=0,v=0;

  v = false;

  s = trimWhiteSpace(s);

  //check for a few numbers that we don't allow upgrades for
  if (s == "71-111-111-17") {
    v=false;
    return(v);  //return true or false
  }
  if (s == "62-222-222-26") {
    v=false;
    return(v);  //return true or false
  }
  if (s == "51-111-111-15") {
    v=false;
    return(v);  //return true or false
  }
  if (s == "45-555-555-54") {
    v=false;
    return(v);  //return true or false
  }
  if (s == "35-555-555-53") {
    v=false;
    return(v);  //return true or false
  }

  //check for a few that do get upgrades
  if (s == "6B-412-924-31" || s == "6B-412-924-51" || s == "6B-412-924-32" || s == "6B-412-924-52") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "6D-492-024-21" || s == "6D-492-024-81" || s == "6D-492-024-22" || s == "6D-492-024-82") {
    v=true;
    return(v);  //return true or false
  }

  //check for a few that do get upgrades
  if (s == "5B-412-924-31" || s == "5B-412-924-51" || s == "5B-412-924-32" || s == "5B-412-924-52") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "5D-492-024-21" || s == "5D-492-024-81" || s == "5D-492-024-22" || s == "5D-492-024-82") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "5B-412-925-32" || s == "5B-412-925-52" || s == "5B-412-925-33" || s == "5B-412-925-53") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "5B-412-926-33" || s == "5B-412-926-53" || s == "5B-412-926-34" || s == "5B-412-926-54") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "5D-492-026-23" || s == "5D-492-026-83" || s == "5D-492-026-24" || s == "5D-492-026-84") {
    v=true;
    return(v);  //return true or false
  }

  //check for a few that do get upgrades
  if (s == "4B-412-924-31" || s == "4B-412-924-51" || s == "4B-412-924-32" || s == "4B-412-924-52") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "4D-492-024-21" || s == "4D-492-024-81" || s == "4D-492-024-22" || s == "4D-492-024-82") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "4B-412-925-32" || s == "4B-412-925-52" || s == "4B-412-925-33" || s == "4B-412-925-53") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "4B-412-926-33" || s == "4B-412-926-53" || s == "4B-412-926-34" || s == "4B-412-926-54") {
    v=true;
    return(v);  //return true or false
  }
  if (s == "4D-492-026-23" || s == "4D-492-026-83" || s == "4D-492-026-24" || s == "4D-492-026-84") {
    v=true;
    return(v);  //return true or false
  }



  if(s.length==13) {
    if ((s.charAt(0)=="6")) {
      if ((s.charAt(0)!="6") || ((s.charAt(3)!="6") && (s.charAt(3)!="D")) || (s.charAt(2)!="-") || (s.charAt(6)!="-") || (s.charAt(10)!="-")) {
        v=false;
      } else {
        // sum first number
        if(isNaN(s.charAt(1))) {
          v=false;
          i=0;
        } else {
          y=y+(s.charAt(1)-'0');
        }
        //alert("A y=" + y.toString());
        for(i=4; i<6; i++) {
          if(isNaN(s.charAt(i))) {
            v=false;
            i=0;
            break;
          } else {
            y=y+(s.charAt(i)-'0');
          }
        }
        //alert("B y=" + y.toString());
        if (i>0) {
          for(i=7; i<10; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            } else {
              y=y+(s.charAt(i)-'0');
            }
          }
        }
        // sum last two numbers
        if (i>0) {
          for(i=11; i<13; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            }
          }
          if (i>0) {
          	if (s.charAt(11)=='0') {
  	          x=parseInt(s.charAt(12));
          	} else {
  	          x=parseInt(s.charAt(11)+s.charAt(12));
            }
          }
        }
        //alert("C y=" + y.toString());
        if (i>0) {
          if ((y+14)==x) {
          	v=true;
          }
        }
      }
    } else if ((s.charAt(0)=="5")) {
      if ((s.charAt(0)!="5") || (s.charAt(2)!="-") || (s.charAt(6)!="-") || (s.charAt(10)!="-")) {
        v=false;
      } else {
        // sum first number
        if(isNaN(s.charAt(1))) {
          v=false;
          i=0;
        } else {
          y=y+(s.charAt(1)-'0');
        }
        //alert("A y=" + y.toString());
        for(i=4; i<6; i++) {
          if(isNaN(s.charAt(i))) {
            v=false;
            i=0;
            break;
          } else {
            y=y+(s.charAt(i)-'0');
          }
        }
        //alert("B y=" + y.toString());
        if (i>0) {
          for(i=7; i<10; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            } else {
              y=y+(s.charAt(i)-'0');
            }
          }
        }
        // sum last two numbers
        if (i>0) {
          for(i=11; i<13; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            }
          }
          if (i>0) {
          	if (s.charAt(11)=='0') {
  	          x=parseInt(s.charAt(12));
          	} else {
  	          x=parseInt(s.charAt(11)+s.charAt(12));
            }
          }
        }
        //alert("C y=" + y.toString());
        if (i>0) {
          if ((y+9)==x) {
          	v=true;
          }
        }
      }
    } else if ((s.charAt(0)=="4")) {
      if ((s.charAt(0)!="4") || (s.charAt(2)!="-") || (s.charAt(6)!="-") || (s.charAt(10)!="-")) {
        v=false;
      } else {
        // sum first number
        if(isNaN(s.charAt(1))) {
          v=false;
          i=0;
        } else {
          y=y+(s.charAt(1)-'0');
        }
        //alert("A y=" + y.toString());
        for(i=4; i<6; i++) {
          if(isNaN(s.charAt(i))) {
            v=false;
            i=0;
            break;
          } else {
            y=y+(s.charAt(i)-'0');
          }
        }
        //alert("B y=" + y.toString());
        if (i>0) {
          for(i=7; i<10; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            } else {
              y=y+(s.charAt(i)-'0');
            }
          }
        }
        // sum last two numbers
        if (i>0) {
          for(i=11; i<13; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            }
          }
          if (i>0) {
          	if (s.charAt(11)=='0') {
  	          x=parseInt(s.charAt(12));
          	} else {
  	          x=parseInt(s.charAt(11)+s.charAt(12));
            }
          }
        }
        //alert("C y=" + y.toString());
        if (i>0) {
          if ((y+24)==x) {
          	v=true;
          }
        }
      }
    } else if ((s.charAt(0)=="3")) {
      if ((s.charAt(0)!="3") || (s.charAt(2)!="-") || (s.charAt(6)!="-") || (s.charAt(10)!="-")) {
        v=false;
      } else {
        // sum first number
        if(isNaN(s.charAt(1))) {
          v=false;
          i=0;
        } else {
          y=y+(s.charAt(1)-'0');
        }
        //alert("A y=" + y.toString());
        for(i=4; i<6; i++) {
          if(isNaN(s.charAt(i))) {
            v=false;
            i=0;
            break;
          } else {
            y=y+(s.charAt(i)-'0');
          }
        }
        //alert("B y=" + y.toString());
        if (i>0) {
          for(i=7; i<10; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            } else {
              y=y+(s.charAt(i)-'0');
            }
          }
        }
        // sum last two numbers
        if (i>0) {
          for(i=11; i<13; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            }
          }
          if (i>0) {
          	if (s.charAt(11)=='0') {
  	          x=parseInt(s.charAt(12));
          	} else {
  	          x=parseInt(s.charAt(11)+s.charAt(12));
            }
          }
        }
        //alert("C y=" + y.toString());
        if (i>0) {
          if ((y+23)==x) {
          	v=true;
          }
        }
      }
    } else {
      v=false;
    }
  } else if (s.length==12) {
    if ((s.charAt(0)=="3")) {
      //'3-500-163-27
      //'012345678901
      if ((s.charAt(1)!="-") || (s.charAt(5)!="-") || (s.charAt(9)!="-")) {
        v=false;
      } else {
       	v=true;
      }
    } else {
      v=false;
    }
  } else if (s.length==14) {
    if ((s.charAt(0)=="9") || (s.charAt(0)=="D")) {
      //'97#-###-###-nn
      //'01234567890123
      if ((s.charAt(3)!="-") || (s.charAt(7)!="-") || (s.charAt(11)!="-")) {
        v=false;
      } else {
        //alert("A y=" + y.toString());
        for(i=1; i<3; i++) {
          if(isNaN(s.charAt(i))) {
            v=false;
            i=0;
            break;
          } else {
            y=y+(s.charAt(i)-'0');
          }
        }
        //alert("A y=" + y.toString());
        if (i>0) {
          for(i=4; i<7; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            } else {
              y=y+(s.charAt(i)-'0');
            }
          }
        }
        //alert("B y=" + y.toString());
        if (i>0) {
          for(i=8; i<11; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            } else {
              y=y+(s.charAt(i)-'0');
            }
          }
        }
        // sum last two numbers
        if (i>0) {
          for(i=12; i<14; i++) {
            if(isNaN(s.charAt(i))) {
              v=false;
              i=0;
              break;
            }
          }
          if (i>0) {
          	if (s.charAt(12)=='0') {
  	          x=parseInt(s.charAt(13));
          	} else {
  	          x=parseInt(s.charAt(12)+s.charAt(13));
            }
          }
        }
        //alert("C y=" + y.toString());
        if (i>0) {
          if ((y+0)==x) {
          	v=true;
          }
        }
      }
    } else {
      v=false;
    }
  } else {
    v=false;
  }
  return(v);  //return true or false
}
