/////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateControl(oInput, sCheckType, oEvent){

	var sStatus;
	var bError = false;
	if(sCheckType == 'TEXT')
		sStatus = ValidateControlTypeText(oInput, oEvent);
	if(sCheckType == 'EMPTY')
		sStatus = ValidateControlTypeEmpty(oInput, oEvent);
	if(sCheckType == 'EMAIL')
		sStatus = ValidateControlTypeEMail(oInput, oEvent);
		
	if(sStatus == 'EMPTY'){
		var MessageBox = new CMessageBox(oInput.getAttribute('sErrorMessage_Empty'));
		bError = true;
	}
	if(sStatus == 'NOTVALID'){
		var MessageBox = new CMessageBox(oInput.getAttribute('sErrorMessage_NotValid'));
		bError = true;
	}
	
	if(bError){
		MessageBox.onShow = "document.getElementById('"+ oInput.id +"').blur(); ";
		MessageBox.onClose = "document.getElementById('"+ oInput.id +"').focus(); ";
		MessageBox.Show();
		//oInput.focus();
		//if(typeof(oInput._className) != 'undefined')
		//	oInput._className = oInput.className;
		//oInput.className += " InvalidValue";
	}else{
		//if(typeof(oInput._className) != 'undefined')
		//	oInput.className = oInput._className;
	}
	
	return bError;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateControlTypeText(oInput, oEvent){
	var oRegExp = new RegExp('[a-zA-Zà-ÿÀ-ß ]*');
	if(oInput.value.length == 0)
		return 'EMPTY';
	if(oInput.value.match(oRegExp).toString().length == oInput.value.length)
		return 'VALID';
	else
		return 'NOTVALID';
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateControlTypeEMail(oInput, oEvent){
	var oRegExp = new RegExp('\@');
	if(oInput.value.length == 0)
		return 'EMPTY';
	if(oInput.value.match(oRegExp) == null)
		return 'NOTVALID';
	else
		return 'VALID';
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function ValidateControlTypeEmpty(oInput, oEvent){
	if(oInput.value.length == 0)
		return 'EMPTY';
	else
		return 'VALID';
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function SubmitForm(oForm, oEvent){
	var arInputFields = new Array();
	arInputFields = oForm.getElementsByTagName('input');
	var bError = false;
	for(nIndex = 0; nIndex < arInputFields.length; nIndex++){
		if(arInputFields[nIndex].getAttribute('CheckType')){
			bElementError = ValidateControl(arInputFields[nIndex], arInputFields[nIndex].getAttribute('CheckType'), oEvent);
			if(bElementError && !bError){
				bError = true;
				break;
			}
		}
	}
	if(!bError){
		bError = ValidateControl(document.getElementById("MessageBox"), "EMPTY", oEvent);
	}
	
	if(bError)
		return false;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function ConcatArrays(arFirst, arSecond){
	for(nIndex = 0; nIndex < arSecond.length; nIndex++)
		arFirst.push(arSecond[nIndex]);
	return arFirst;
}

/////////////////////////////////////////////////////////////////////////////////////////////////
function GetKeyPressed(oEvent){
	var nKeyCode;
	if(oEvent.event)
		nKeyCode = oEvent.event;
	if(oEvent.keyCode)
		nKeyCode = oEvent.keyCode;
	if(oEvent.which)
		nKeyCode = oEvent.which;
	var sCharacter = String.fromCharCode(nKeyCode);
	return sCharacter;
}
