// JavaScript Document
//This validates the infomation when key is left from text box
function validate(Input, datType, other, minLength, maxlength, required){
	
	var pass = true;
	var Value = document.getElementById(Input).value
	//alert(Input);
	//If submitted value needs to be an string
	if (datType == "str"){
		//var numArr = new Array("1","2","3","4","5","6","7","8","9","0");
		var numArr = new Array("`");
		//loop throught the items
		for (x in numArr){
			if (Value.indexOf(numArr[x]) != -1){
					showMessage(Input, "Invalid data");
					document.getElementById(Input).focus();
					pass = false;
					break;
				}
			else{
				//showMessage(Input, "");	
				}
			}
	}
	
	//If submitted value needs to be an number
	if (datType == "int"){
		
			var CheckNum = parseFloat(Value);
			//alert(isNaN(CheckNum));
			if((required == "yes")&&(isNaN(CheckNum))){
						//showMessage(Input, "Value is not number");	
						pass = false;
						//break;
			}else if((required == "no")&&(isNaN(CheckNum))){
				document.getElementById(Input).Value = "";
				//pass = true;
					//showMessage(Input, "");	
			}
				/*
alert(pass);
		var VarArr = new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
		for (y in VarArr){
			if (Value.indexOf(VarArr[y]) != -1){
					//showMessage(Input, "Value is not number");	
					pass = false;
					//break;
				}
			else{
				//showMessage(Input, "");	
				}
		*/
			
		//} 
		
		/*
		*/
	}
	//This checks the length of thge object
	if(required == "yes"){
		if (Value.length > maxlength || Value.length < minLength){
			//alert(Value.length+": "+minLength);
			showMessage(Input, "Incorrect data length");	
			pass = false;
		}
	}
	
	if (Value.length > maxlength){
			//alert(Value.length+": "+minLength);
			showMessage(Input, "Incorrect data length");	
			pass = false;
		}
	
	//If the "Other" Value is specified, then check what it needs to
	if (other != ""){
	
		switch (other){
			
			//Validate email address
			case "email":
				if (Value.indexOf("@") == -1){ 
					showMessage(Input, "Incorrect Email");	
					pass = false;
				}
				if (Value.indexOf(".") == -1){ 
					showMessage(Input, "Incorrect Email");	
					pass = false;
				}
				break;
			
			//Validate ID Number
			case "id":
				//Find script to validate ID number other than length
				pass = false;
				break;
			
			
			//Default selection
			default:
				showMessage(Input, "Invalid selection");
				pass = false;
				break;
		}
	}
	
	////Check for Data Integrety
	var arrBadInfo = new Array( ">", "<", "|", "<script", "</script>",";","javascript","*");
	for (z in arrBadInfo){
		if (Value.indexOf(arrBadInfo[z]) != -1) {
			showMessage(Input, "Input error");
			document.getElementById(Input).focus();
			pass = false;
			break;
			}
	}

	//check if the field is required or not
	if (required == "yes"){
			if (Value == "" || Value == " "){
				showMessage(Input, "Field Required");
				document.getElementById(Input).focus();
				pass = false;
				
				}
		}else{
		
			}

	//Return pass back
//	alert(pass);
	return pass;

}
function showMessage(Input, Message){	
	//alert(Input+": "+Message);	
}
//var vailid = validate(document.getElementById('').value, "str", '', 0, 20, 'yes');