function checkSpecialChars()
{	
	var arrTextArea;
	var arrInput;
	var txtAreaHasSplChar;
	var inputHasSplChar;
	var inputHasSplChar1;

	arrTextArea = document.getElementsByTagName("textarea");
	arrInput = document.getElementsByTagName("input");
	
	txtAreaLen = arrTextArea.length;
	inputLen = arrInput.length;

	//alert("Text Area Length : "+ txtAreaLen);
	//alert("Input Length : "+ inputLen);
	
	for (var i=0; i < txtAreaLen; i++)
	{
		eleName = arrTextArea[i].name;
		eleClass = arrTextArea[i].className;

				
		if(removeSplChar4Text(arrTextArea[i]) == false)
		{
			txtAreaHasSplChar = false;
		}
		else if(removeSplChar4Text(arrTextArea[i]) == null)
		{
			txtAreaHasSplChar = null;
		}
		/*else
		{
			txtAreaHasSplChar = true;
		}*/
	}
	
	for (j=0; j < inputLen; j++)
	{
		//alert(arrInput[i].type);
		if(arrInput[j].type == "text")
		{
			if(arrInput[j].className == "textBoxStyleForLocal" || arrInput[j].className == "textBoxStyle")
			{
				eleName = arrInput[j].name;
				eleClass = arrInput[j].className;

				if(removeSplChar4Text(arrInput[j]) == false)
				{
					inputHasSplChar = false;
				}
				if(removeSplChar4Text(arrInput[j]) == null)
				{
					inputHasSplChar = null;
				}
				/*else
				{
					inputHasSplChar = true;
				}*/

			}
			else
			{
				if(detechFieldType(arrInput[j]) == false)
				{
					inputHasSplChar = false;
				}
				if(detechFieldType(arrInput[j]) == null)
				{
					inputHasSplChar = null;
				}
				/*else
				{
					inputHasSplChar = true;
				}*/
				
			}
			
		}
		if(arrInput[j].type == "password")
		{
			/*if(removeSplChar4Password(arrInput[j]) == false)
			{
				inputHasSplChar = false;
			}
			if(removeSplChar4Password(arrInput[j]) == null)
			{
				inputHasSplChar = null;
			}*/
			removeSplChar4Password(arrInput[j]);
		}
	}
	
	//alert("txtAreaHasSplChar : "+txtAreaHasSplChar);
	//alert("inputHasSplChar : "+inputHasSplChar);


	if(txtAreaHasSplChar == false || inputHasSplChar == false)
	{
		alert("Some special characters were found and were removed from the data you have entered. Please review and resubmit the form.\nYou can visit Learning Center for details on Special Characters and Restrictions");
		return false;
	}
	if(txtAreaHasSplChar == "null" || inputHasSplChar == "null")
	{
		alert("Some technical issues have happenend while checking for Special Characters");
		return false;
	}
	else
	{
		return true;
	}
}

function detechFieldType(fieldObj)
{
	//alert("Field Name  "+fieldObj.name);
	//alert("Field Object: "+fieldObj.className);

	var inputHasSplChar;

	try
	{
	
		if(fieldObj.className == "passwordStyle")
		{
			// check validation for password
			//alert("check validation for password");

			inputHasSplChar = removeSplChar4Password(fieldObj);

		}
		else if(fieldObj.className == "emailStyle")
		{
			// check validation for email
			//alert("check validation for email");

			inputHasSplChar = removeSplChar4Email(fieldObj);

		}
		else if(fieldObj.className == "urlStyle")
		{
			// check validation for URL
			//alert("check validation for URL");
			
			inputHasSplChar = removeSplChar4URL(fieldObj);
		}
		else
		{		
			//alert("Field Name  "+fieldObj.name);
			//alert("check validation for text box.");

			inputHasSplChar = removeSplChar4Text(fieldObj);
		}

	}
	catch (error)
	{
		//alert("arror while detecting field type");
		inputHasSplChar = null;
	}

	return inputHasSplChar;
	

}

function removeSplChar4Text(fieldObj)
{
	var count = 0;
	var str1 = fieldObj.value;
	var str2 = "";
	var hasSplChar = false;
	
	//alert("String Value : "+ str1);
	try
	{	
		
		for(i = 0; i < str1.length; i++)
		{
			//alert("Char Value : "+ str1.charCodeAt(i));

			if((str1.charCodeAt(i) >= 44 && str1.charCodeAt(i) <= 58) || (str1.charCodeAt(i) >= 64 && str1.charCodeAt(i) <= 91) || 
				(str1.charCodeAt(i) >= 97 && str1.charCodeAt(i) <= 122) || str1.charCodeAt(i) == 32 || str1.charCodeAt(i) == 93 || str1.charCodeAt(i) == 95)
			{
				str2 = str2 + str1.charAt(i);
			}
			else if(str1.charCodeAt(i) == 10 || str1.charCodeAt(i)==13)
			{ 
				//alert("Enter Deteched");
				//throw "splCharError"
				str2 = str2 + "   ";
				hasSplChar = true;
			}
			else
			{
				//alert("Some Restricted Special Character Deteched");
				//throw "splCharError"
				str2 = str2 + "  ";
				hasSplChar = true;
			}
		}
		  
		fieldObj.value = str2;

		if(hasSplChar)
		{
			//alert("Some special characters were removed from "+textName+" due to some technical reasons.\nPlease go to learning center link for special character list.");
			//count = 0;
			return false;
		}
	}
	catch(error)
	{
		//alert("Some technical issues have happenend while checking for Special Characters");
		return null;
	}
    
	return true;
}


function removeSplChar4URL(fieldObj)
{
	//alert("Checking URL for Special Character");
	var count = 0;
	var str1 = fieldObj.value;
	var str2 = "";
	var hasSplChar = false;
	
	//alert("String Value : "+ str1);
	try
	{
		for(i = 0; i < str1.length; i++)
		{
			if((str1.charCodeAt(i) >= 45 && str1.charCodeAt(i) <= 58) || (str1.charCodeAt(i) >= 65 && str1.charCodeAt(i) <= 90) || (str1.charCodeAt(i) >= 97 && str1.charCodeAt(i) <= 122))
			{
				str2 = str2 + str1.charAt(i);
			}
			else if(str1.charCodeAt(i) == 10 || str1.charCodeAt(i)==13)
			{ 
				//alert("Enter Deteched");
				str2 = str2 + "  ";
				hasSplChar = true;
			}
			else
			{
				//alert("Some Restricted Special Character Deteched");
				//str2 = str2 + "  ";				
				hasSplChar = true;
			}
		}
		  
		fieldObj.value = str2;

		if(hasSplChar)
		{
			return false;
		}
	}
	catch(error)
	{
		//alert("Some technical issues have happenend while checking for Special Characters");
		return null;
	}
    
	return true;
}


function removeSplChar4Email(fieldObj)
{
	//alert("Checking URL for Special Character");
	var count = 0;
	var str1 = fieldObj.value;
	var str2 = "";
	var hasSplChar = false;
	
	//alert("String Value : "+ str1);

	try
	{
		for(i = 0; i < str1.length; i++)
		{
			if((str1.charCodeAt(i) >= 48 && str1.charCodeAt(i) <= 57) || (str1.charCodeAt(i) >= 65 && str1.charCodeAt(i) <= 90) || (str1.charCodeAt(i) >= 97 && str1.charCodeAt(i) <= 122) || str1.charCodeAt(i) == 45 || str1.charCodeAt(i) == 46 || str1.charCodeAt(i) == 64 || str1.charCodeAt(i) == 95)
			{
				str2 = str2 + str1.charAt(i);
			}
			else if(str1.charCodeAt(i) == 10 || str1.charCodeAt(i)==13)
			{ 
				//alert("Enter Deteched");
				str2 = str2 + "";
				hasSplChar = true;
			}
			else
			{
				//alert("Some Restricted Special Character Deteched");
				//str2 = str2 + "  ";
				hasSplChar = true;
			}
		}
		  
		fieldObj.value = str2;

		if(hasSplChar)
		{
			return false;
		}
	}
	catch(error)
	{
		//alert("Some technical issues have happenend while checking for Special Characters");
		return null;
	}
	
	return true;
}


function removeSplChar4Password(fieldObj)
{
	var count = 0;
	var str1 = fieldObj.value;
	var str2 = "";
	var hasSplChar = false;
	
	//alert("String Value : "+ str1);
	try
	{			
		for(i = 0; i < str1.length; i++)
		{
			if((str1.charCodeAt(i) >= 48 && str1.charCodeAt(i) <= 57) || (str1.charCodeAt(i) >= 65 && str1.charCodeAt(i) <= 90) || (str1.charCodeAt(i) >= 97 && str1.charCodeAt(i) <= 122) || str1.charCodeAt(i) == 32 || str1.charCodeAt(i) == 95)
			{
				str2 = str2 + str1.charAt(i);
			}
			else if(str1.charCodeAt(i) == 10 || str1.charCodeAt(i)==13)
			{ 
				//alert("Enter Deteched");				
				str2 = str2 + "";
				hasSplChar = true;
			}
			else
			{
				//alert("Some Restricted Special Character Deteched");
				str2 = str2 + str1.charAt(i);
				hasSplChar = true;
			}
		}
		  
		fieldObj.value = str2;

		if(hasSplChar)
		{
			return false;
		}
	}
	catch(error)
	{
		//alert("Some technical issues have happenend while checking for Special Characters");
		return null;
	}
    
	return true;
}





function removeSpecialChars(str1)
{
	var str2;var i;
	str2='';
	for(i=0;i<str1.length;i++)
	{
		//alert(str1.charCodeAt(i))
		if(str1.charCodeAt(i)!=10 && str1.charCodeAt(i)!=13){str2=str2 + str1.charAt(i);}
	}
	alert(str2);
	return str2;
}

