
function checkTextArea_label(objTextArea, strFieldName, strFieldType, blnCheckIfEmpty, intMinLength, intMaxLength, strAllowedChars, strLblName)
{
	//Check if the keyup event is tab
	//var e = window.event;
	//var code = e.keyCode;
	//alert(code);
	//if(code != 9){return;}
	
	var strStatus = checkTextArea(objTextArea, strFieldName, strFieldType, blnCheckIfEmpty, intMinLength, intMaxLength, strAllowedChars)
	var objElement = document.getElementById(strLblName);
	objElement.innerHTML = strStatus;
	if(strStatus == '')
	{
		return true;
	}
	else
	{
		//alert(document.getElementById(strLblName).focus());
		//document.getElementById(strLblName).focus();
		return false;
	}
	
}

function checkTextArea(objTextArea, strFieldName, strFieldType, blnCheckIfEmpty, intMinLength, intMaxLength, strAllowedChars)
{
	//Check if empty
	if(blnCheckIfEmpty == 'true')
	{
		if(objTextArea.value === '')
		{
			return('Please fill in the ' + strFieldName);
		}
	}
	
	//Check minimum length
	if(intMinLength !== undefined)
	{
		if(objTextArea.value.length < intMinLength)
		{
			return('Please enter at least ' + intMinLength + ' characters in the ' + strFieldName + ' field');
		}
	}
	
	//Check maximum length
	if(intMaxLength !== undefined)
	{
		if(objTextArea.value.length > intMaxLength)
		{
			return('Please enter no more than ' + intMaxLength + ' characters in the ' + strFieldName + ' field');
		}
	}
	
	//Check allowed characters
	var charTemp;
	var strMsg;
	if(strAllowedChars !== undefined && strAllowedChars !== '')
	{
		switch(strAllowedChars)
		{
			case 'password':
				strAllowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-';
				strMsg = 'Please use only English characters and/or numbers with NO SPACES';
				break;
			case 'en':
				strAllowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-,.;:?!"()/\ ';
				strAllowedChars = strAllowedChars + '&apos;' //APOSTROPHE
				strAllowedChars = strAllowedChars + "'";
				strMsg = 'Please use only English characters, numbers and/or common punctuation marks';
				break;
			case 'email':
				strAllowedChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-,.@';
				strMsg = 'Please use only English characters, numbers, common punctuation marks and @';
				break;
			default:
				strMsg = 'Please use only ' + strAllowedChars + ' characters';
				break;
		}
		
		for (var intTextLength = 0; intTextLength < objTextArea.value.length; intTextLength++)
		{	
			//Get chat by char of the text
			//If the char is not in the allowed chars list
			charTemp = objTextArea.value.charAt(intTextLength);
			if(strAllowedChars.indexOf(charTemp) == -1)
			{
				//If it's not an enter key
				if(objTextArea.value.charCodeAt(intTextLength) !== 13 && objTextArea.value.charCodeAt(intTextLength)!== 10)
				{
					//alert(objTextArea.value.charCodeAt(intTextLength));
					return(strMsg + ' in the ' + strFieldName + ' field');
				}
			}
		}	
	}
	//Check fieldType
	if(strFieldType !== undefined && strFieldType !== '')
	{
		var regExp ;
		switch (strFieldType)
		{
			case 'email': //WORKS!!
				regExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
				if(objTextArea.value.search(regExp) == -1)
				{
					return('Please use an email format in the ' + strFieldName + ' field');
				}
				break;
				
			case 'url':
				if(objTextArea.value.search(regExp) == -1)
				{
					return('Please use a URL format in the ' + strFieldName + ' field');
				}
				break;
				
			case 'phone':
				regExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/;
				if(objTextArea.value.search(regExp) == -1)
				{
					return('Please use a phone format in the ' + strFieldName + ' field');
				}
				break;
				
			case 'digits':
				regExp = /^\d\$/;
				if(objTextArea.value.search(regExp) == -1)
				{
					return('Please use numbers only in the ' + strFieldName + ' field');
				}
				break;
			
			default:
				break;
		}
		
	}
	return '';
}

//======================FILE UPLOAD======================

function checkFileToUpload_label(objUpload, blnCheckIfEmpty, strMsg, strLblName)
{
	var strStatus = checkFileToUpload(objUpload, blnCheckIfEmpty, strMsg);
	var objElement = document.getElementById(strLblName);
	objElement.innerHTML = strStatus;
	if(strStatus == '')
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkFileToUpload(objUpload, blnCheckIfEmpty, strMsg)
{
	//Get file's path
	var strPath = objUpload.value;
	
	//Check if empty
	if(strPath == '')
	{
		if(blnCheckIfEmpty == 'true')
		{
			return(strMsg);
		}
		else
		{
			return '';
		}		
	}
	//Check if it's an image
	strPath = strPath.toLowerCase();
	var intPointLocation = strPath.lastIndexOf(".");
	if(intPointLocation == -1) //There is not .
	{
		return(strMsg);
	}
	var strFileType = strPath.slice(intPointLocation);
	if(strFileType == ".jpg" || strFileType == ".gif" ||
	   strFileType == ".jpeg" || strFileType == ".bmp" ||
	   strFileType == ".png" || strFileType == ".tiff" ||
	   strFileType == ".art")
	{
		return '';
	}
	else
	{
		return(strMsg);
	}
}

//======================DDL======================
function checkDDLChoice(ddl, msg, objBtn)
{
	//alert(ddl);
	if(ddl[ddl.selectedIndex].value === '')
	{
		disableButton(objBtn);
		alert(msg);
		return false;
	}
	else
	{
		enableButton(objBtn);
		return true;
	}
}

function checkDDL_label(ddl, strLblName)
{
	var strStatus = checkDDL(ddl);
	var objElement = document.getElementById(strLblName);
	objElement.innerHTML = strStatus;
	if(strStatus == '')
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkDDL(ddl)
{
	if(ddl[ddl.selectedIndex].value === '' || ddl[ddl.selectedIndex].value === '0')
	{
		return 'Please choose a value';
	}
	else
	{
		return '';
	}
}

//======================DISABLE/ENABLE BUTTON======================

function disableButton(objBtn)
{
	if(objBtn != undefined){objBtn.disabled = true;}
}

function enableButton(objBtn)
{
	if(objBtn != undefined){objBtn.disabled = false;}
}


//======================CHECK EQUAL VALUES IN TWO TEXT FIELDS======================
function checkTextAreaValuesEqual(textArea1, textArea2, msg)
{
	if(textArea1.value == textArea2.value)
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
}

function checkTextAreaValuesEqual_noAlert_label(txt1, strTxt1name, txt2, strTxt2name, strLblName)
{
	var strStatus = checkTextAreaValuesEqual_noAlert(txt1, strTxt1name, txt2, strTxt2name)
	var objElement = document.getElementById(strLblName);
	objElement.innerHTML = strStatus;
	if(strStatus == '')
	{
		return true;
	}
	else
	{
		return false;
	}
	
}

function checkTextAreaValuesEqual_noAlert(txt1, strTxt1name, txt2, strTxt2name)
{
	if(txt1.value == txt2.value)
	{
		return '';
	}
	else
	{
		return('The ' + strTxt1name + ' field is different than the ' + strTxt2name + ' field');
	}
}