function fnPastText(objName)
{
	try
	{
		var bCheckFeedbackTextSize=false;		
		if(fnCheckLanguagePast(window.clipboardData.getData("Text")) && document.getElementById(objName))
		{
			var strComments = document.getElementById(objName).value;
			bCheckFeedbackTextSize = fnCheckFeedbackTextSize(strComments + window.clipboardData.getData("Text"),document.getElementById(objName).maxlength);
		}
		if(!bCheckFeedbackTextSize)
		{
			window.clipboardData.setData("Text","");
			return false;
		}
	}
	catch (ex)
	{
		//do nothing 
	}
	return true ;
}


//check the language and size (on drop)
function fnCheckDropedText(objName)
{
	var bCheckDropedTextSize = false;
	if(fnCheckLanguagePast(event.dataTransfer.getData("Text")) && document.getElementById(objName))
	{	
		var strComments = document.getElementById(objName).value;
		bCheckDropedTextSize = fnCheckFeedbackTextSize(strComments+event.dataTransfer.getData("Text") , document.getElementById(objName).maxlength);		
	}
	if(!bCheckDropedTextSize)
	{
		event.dataTransfer.setData("Text","");
		return false;
	}
	return true ;
}



//this method checks if the length of the feedback text entered by visitor exceed the max length
function fnCheckFeedbackTextSize(feedbackText,maxSize)
{
//debugger;
	try
	{		
		if (feedbackText.length>maxSize)
		{
			alert ("الحد الأقصى للنص " + maxSize + " حرف");
			return false;
		}
		else
			return true;
	}
	catch (ex)
	{
		// do nothing 
	}
	
	return true ;
}


function fnCheckTextEntered(objName)
{
//debugger;
	var bCheckFeedbackTextSize = false;
	
	if(fnCheckLanguage() && document.getElementById(objName) )
	{
		var strComments = document.getElementById(objName).value;
		bCheckFeedbackTextSize = fnCheckFeedbackTextSize(strComments+1,document.getElementById(objName).maxlength);
	}
	if(!bCheckFeedbackTextSize)
	{
		return false;
	}
	return true ;
}



//check the language (key pressed)
function fnCheckLanguage()
{

	var strHexPressedKeyCode
	
		strHexPressedKeyCode = event.keyCode; 
	
	return CheckCharLanguage (strHexPressedKeyCode);
}
function keypress(e) 
{     
	return e.keyCode
}


//check if the passed character is allowed or not
function CheckCharLanguage (strHexPressedKeyCode)
{
	try
	{
		if (((strHexPressedKeyCode >= parseInt("0x600"))  && (strHexPressedKeyCode <= parseInt("0x6FF"))) || ((strHexPressedKeyCode >= parseInt("0x30")) && (strHexPressedKeyCode <= parseInt("0x39")))|| ((strHexPressedKeyCode >= parseInt("0x20"))  && (strHexPressedKeyCode <= parseInt("0x2F"))) || ((strHexPressedKeyCode >= parseInt("0x3A"))  && (strHexPressedKeyCode <= parseInt("0x40"))) || ((strHexPressedKeyCode >= parseInt("0x5B"))  && (strHexPressedKeyCode <= parseInt("0x60"))) || ((strHexPressedKeyCode >= parseInt("0x7B"))  && (strHexPressedKeyCode <= parseInt("0x7F")))|| ((strHexPressedKeyCode >= parseInt("0x0"))  && (strHexPressedKeyCode <= parseInt("0x1F"))) || (strHexPressedKeyCode == parseInt("0x2019")) || (strHexPressedKeyCode == parseInt("0xD")))	
				{return true;}
		else
		{
			
			alert ("الرجاء إدخال هذا الحقل باللغة العربية");
			
		return false;
		}
		
		
	}
	catch (eX)
	{
		// do nothing 
	}
	return true ;
}

// Take the whole text pasted and check if there is any not allowed charcters
function fnCheckLanguagePast (strText)
{
	try 
	{
		var bCheckCharLanguage;
		for (i =0; i < strText.length; i++)
		{
			bCheckCharLanguage = CheckCharLanguage (strText.charCodeAt(i));
			if (!(bCheckCharLanguage))
			{return false;}
		}
		return true;
	}
	catch (ex)
	{
		//do nothing
	}
	return true ;
}
