// JavaScript Document
//This is form vaildation for any type of data that is sumitted,
//Div items will need to be created  next to text box
//so item messages can be displayed correctly
//created by Deon Pheiffer and the Technical Department
//company: Paradigm Pixel

//Show alert = 1 to show message boxes
//All settings to go here
var showAlert = false;
//Set the general setting here
var GeneralMessage = "* Not all fields have been supplied";

//**********************************************************
//**********************************************************
//DO NOT EDIT BELOW THIS LINE
//**********************************************************
function showMessage(DivItem, DivMessage, Effect, BooPass){
	
	
	if(showAlert){//Return back a messga of error on the form}
		alert (DivItem + " Returned " + BooPass +" = "+ DivMessage);}
	

	if(BooPass){ 
		//document.getElementById(DivItem).style.filter = "alpha(opacity=50)";
		document.getElementById(DivItem).style.backgroundColor = "#FFFFFF";//change opacity
		}
	else{
		document.getElementById(DivItem).style.filter = "alpha(opacity=100)";
		document.getElementById(DivItem).style.backgroundColor = "#9b9d43";//change opacity
		 }
}

	//This validates the infomation when key is left from text box
	function validate(Input, datType, other, minLength, maxlength, required, effect)
	{
	var pass = true;
	var Value = document.getElementById(Input).value

	
	//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");
		//loop throught the items
		for (x in numArr){
			if (Value.indexOf(numArr[x]) != -1){
					pass = false;
					strMessage = "Invalid data";
					break;
				}
			}
	}

	//****************************************
	//If submitted value needs to be an number
	//****************************************
	if (datType == "int"){
		
		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){
					pass = false;
					strMessage = "Value is not number";
					break;
					}
		} 
	}
	
	
	
	//alert(Value.length)
	if (Value.length > maxlength || Value.length < minLength){
		pass = false;
		strMessage = "Incorrect data length";
		}
	
	
	//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){ 
					pass = false;
					strMessage = "Incorrect Email";
					break;
				}
				if (Value.indexOf(".") == -1){ 
					pass = false;
					strMessage = "Incorrect Email";
					break;
				}
			
			break;
			
			//This is for a general number
			case "tel":
					if (Value.length != maxlength){
						pass = false;
						strMessage = "Incorrect number";
						break;
					}
			break;
			//Default selection
			default:
					strMessage = "Option not supplied";	
					break;
		}
	
	}
	
	//Check for Data Integrety
	var arrBadInfo = new Array(">", "<", "|", "<script>", "</script>",";","#","(",")","/","javascript","language","*", "script");
	for (z in arrBadInfo){
		if (Value.indexOf(arrBadInfo[z]) != -1) {
			pass = false;
			strMessage = "Input error";
			break;}
	}

	//check if the field is required or not
	if (required == "yes"){
			if (Value == "" || Value == " "){
				pass = false;
				strMessage = "Field Required";
				}
		}

	//Return pass back
	if (pass){
		showMessage(Input, '', effect, pass);
		return pass;
		}
	else{
		showMessage(Input, strMessage, effect, pass);
		return pass;
	}
}

