// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function checkNumber(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 46 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

function cust1(id, stdId){
	
	var custObj = document.getElementById(id);
	var stdObj = document.getElementById("standard"+stdId);

	var st1 = custObj.value;
	
	var find1 = st1.indexOf(".");

	var temp = new Array();
	temp = st1.split('.');

	//var secval=temp[1];
	
	var le = temp[0].length;
	
	if(le >2 || temp[0] == "0" || temp[0] == "00"){
		alert("Please enter a custom length in whole or half inch increments.");
		custObj.focus();
		setTimeout(function(){custObj.focus();},10);
		return false;
	}
	if(custObj.value == ""){
		stdObj.value = "NA";
	}
	if(custObj.value == "" && stdObj.value == "Custom" || custObj.value == "." || temp[0] == "0" || temp[0] == "00"){
		alert("Please enter a custom length in whole or half inch increments.");
		setTimeout(function(){custObj.focus();},10);
		return false;
	}
	else{
	 if(find1 != -1){
			if(st1==""){
				st1 ="";
			}
			if(temp[1] == ""){
				custObj.value = st1 + '0'+'\"';
				
			}else if(temp[1] == "0"){
				custObj.value = st1 + '\"';
			}else if(temp[1] > 5 || temp[1] < 5 ){
					alert("Please enter a custom length in whole or half inch increments.");
					setTimeout(function(){custObj.focus();},10);
					return false;
			}
			else{
				var secq = st1.indexOf('\"');

					if(secq != -1){
						custObj.value = (st1);
					}else{
						custObj.value = (st1 + '\"');
					}
					
			}
		}else{
			if(st1==""){
				st1 ="";
			}else{
				 custObj.value = (st1 + '.0' +'\"');
			}		

		}
	}

	if(custObj.value != "" && stdObj.value == "NA"){
		stdObj.value = "Custom";
	}
	
	
}

function reflactcustom1(stid, custid){
	var stdObj = document.getElementById(stid);
	var cusObj = document.getElementById("custom"+custid);

	var x=stdObj.value;
	if(x=="Custom"){
		cusObj.value = "";
		cusObj.disabled = false;
		cusObj.focus();
	}
	else if(x=="NA"){
		cusObj.value = "";
		cusObj.disabled = false;
	}

	if(x=="7" || x=="8" || x=="9" || x=="10" || x=="16" || x=="17" || x=="18" || x=="20" || x=="22" || x=="24" || x=="30"){
		cusObj.value = "NA";
		cusObj.disabled = true;
	}
}