/* This function will finds the length of the given string and if it exceeds
   length then it displays an appropriate message. 
   data = string to be checked for length.
   upperLeng = specified string upper length.
   lowerLeng = specified string lower length.

*/
function checkoption(data)
{
 if(data.selectedIndex==0)
 {
   alert("Please Select "+FieldName);
   data.focus();
   return false;
 }
  else return true;
}

function checkLength(data, upperLeng, lowerLeng)
{	
	if(data.value.length > upperLeng )
	{			
		alert("Length Of "+FieldName+" Should Not Be More Than "+upperLeng);		
		data.focus();
		return false
	}
	else if (data.value.length < lowerLeng)
	{	
		if (lowerLeng==1)			
			alert(FieldName+" Should Not Be Empty");
		else if (lowerLeng >1 && lowerLeng<11)
			alert(FieldName+" Atlest "+lowerLeng+" Character Long");
		data.focus();
		return false
	}
	else
		 return true
}

/*
	it checks the number words have been entered in the given field
*/
function checkWordCount(data, upperLeng, lowerLeng)
{
	strValue = data.value
	wordCount = strValue.split(" ")

	if (wordCount.length > upperLeng)
	{
		alert("number of words should not be more than  "+upperLeng +" in the "+data.name)
	data.focus()
		return false
	}
	else if(wordCount.length <= lowerLeng)
	{
		alert("number of words should be more than  "+lowerLeng +" in the "+data.name)
	data.focus()
		return false
	}
	else
	 return true
}

/*
  This function checks whether the data has been sent is numeric or string
  if data is not numeric then it displays an appropriate error message.
*/

function checkPhone(data, leng)
{	//40,41,45,32,44 for (,),-," ",, characters respectively
	var num,i
	result=true
	num=data.value;	
	if(num.length > leng)
	{
		alert(FieldName+"  should not exceed "+leng+" digits");
		data.focus()
		return false
	}
	else
	{
		for(i=0; i<num.length ; i++)
		{
			if((num.charCodeAt(i)!= 44 && num.charCodeAt(i)!= 32 && num.charCodeAt(i)!= 40 && num.charCodeAt(i)!= 41 && num.charCodeAt(i)!= 45 )&&( num.charCodeAt(i)<48 || num.charCodeAt(i)>57 ))
			{
				alert(FieldName+" is invalid")
				data.focus()
				result = false		
				break;
			}
			else
			{
				result = true
			}
		}
		return result
	}
	
}

/*
  This function checks whether the data has been sent is numeric or string
  if data is not numeric then it displays an appropriate error message.
*/

function checkNumeric(data,leng)
{	
	var num,i
	num=data.value;
	result = true

	if(num.length > leng)
	{
		alert("Block should not exceed "+leng+" digits")
		return false
	}
	else
	{
		for(i=0; i<num.length ; i++)
		{
			if( (num.charCodeAt(i)<48 || num.charCodeAt(i)>57) )
			{
				alert(FieldName+" Should Be Numeric Only")
				data.focus()
				result = false
				break;
			}
			else
			{
				result = true
			}
		}
		return result
	}
}


function checkEmail(data)
 {
		strEmailId	=  data.value;
		//HERE EMAIL ID IS AN OPTIONAL FIELD IF NO DATA THEN NO VALIDATION.
		if (strEmailId == "")
		{
			return true // DONT VALIDATE EMAIL FIELD
		}

		 if(strEmailId.indexOf("@") > 0 && strEmailId.indexOf(".") > 1)
             {
		    //checks that last character is not "."
		    if( strEmailId.lastIndexOf(".") == data.value.length - 1)
                {  
			alert("Please correct "+FieldName)
			data.focus()
			return false
		    }
		    else
		 	return true     
             }
             else
             {
                alert("Please correct "+FieldName)
		    data.focus()	
		    return false	

             }
             
          }

//FOLLOWING FUNCTION IS USED TO CHECK THE MULTIPLE EMAIL ID WITH COMMA SAPARATED.
		  
function checkEmail1(data)
 {
		strEmailId	=  data;
		//HERE EMAIL ID IS AN OPTIONAL FIELD IF NO DATA THEN NO VALIDATION.
		if (strEmailId == "")
		{
			return true // DONT VALIDATE EMAIL FIELD
		}

		 if(strEmailId.indexOf("@") > 0 && strEmailId.indexOf(".") > 1)
             {
		    //checks that last character is not "."
		    if( strEmailId.lastIndexOf(".") == data.length - 1)
                {  
			alert("Please correct "+FieldName)
			data.focus()
			return false
		    }
		    else
		 	return true     
             }
             else
             {
                alert("Please correct "+FieldName)
		    //data.focus()	
		    return false	

             }
             
          }
		  

/************************************************************
function : CheckEmailReturn(strMail)
usage    : To check Validity Of Email
inputs   : string containing mail address
output   : returns true if email is valid; otherwise returns false
e.g      : abc@xyz.com is valid Email Address.

************************************************************/

function CheckEmailReturn(strMail)
{
		
	if (strMail.value=="")
	{		
		return false
	}
	var intLen=strMail.value.length
	var blnFlag=0
	if (strMail.value.charAt(0)=="@" || strMail.value.charAt(0)==".")
	{		
		return false
	}
	if (strMail.value.charAt(intLen-1)=="@" || strMail.value.charAt(intLen-1)==".")
	{		
		return false
	}
	for (var i=0;i<intLen;i++)
	{
		if (strMail.value.charAt(i)=="@")
		{
			blnFlag=blnFlag+1
		}
	}
	if (blnFlag>=0 && blnFlag<1 || blnFlag>1)
	{		
		return false
	}
	strSplit=(strMail.value).split("@")
	intSptLen=strSplit[1].length
	var intCnt=0
	for(var j=0;j<intSptLen;j++)
	{
		if (strSplit[1].charAt(j)==".")
		{
			intCnt=intCnt+1
		}
	}
	if (intCnt<=0)
	{		
		return false
	}
	return true
}

function SpecialCharEmail(str)
{	
  var chk1 = ",!#$%^*()-+=|\~`{}[]:'<>?/ ";
  
  for(var i=0;i<str.length;i++)

   {

    var ch=str.charAt(i);

    var rtn1=chk1.indexOf(ch);

    if (rtn1 != -1)

          {
                return false;
          }

   }
   return true;
}


function IsDigit1(strNum)
{
	var i;	
	var flag;
	flag=true;
	if(strNum=="")
		return false;
	for(i=0;i<strNum.length;i++)
	{		
		if(strNum.charCodeAt(i)>48 && strNum.charCodeAt(i)<57)
		{
			flag=false;
			break;
		}		
	}
	if (flag == false)
	{
		return false
	}
	else
	{
		return true;
	}
	
	//return true;
}  



function checkSpace(data){
	var Mystring=new String(data.value)
	var Idx=Mystring.search(" ") 
	if (Idx==-1){
	 return true}
	 else{
	 alert ("Please Remove The Space")
	 data.focus()
	 return false
	 }
}

function checkURL(data)
 {
		strEmailId	=  data.value;
		//HERE EMAIL ID IS AN OPTIONAL FIELD IF NO DATA THEN NO VALIDATION.
		if (strEmailId == "")
		{
			return true // DONT VALIDATE EMAIL FIELD
		}

		 if(strEmailId.indexOf(".") > 1)
             {
		    //checks that last character is not "."
		    if( strEmailId.lastIndexOf(".") == data.value.length - 1)
                {  
			alert("Please correct URL")
			data.focus()
			return false
		    }
		    else
		 	return true     
             }
             else
             {
                alert("Please correct URL")
		    data.focus()	
		    return false	

             }
             
          }
          
          
function checkZip(data, leng)
{	//40,41,45,32,44 for " " characters respectively
	var num,i
	result=true
	num=data.value;	
	if(num.length > leng)
	{
		alert(FieldName+" Should Not Be Exceed "+leng+" Digits");
		data.focus()
		return false
	}
	else
	{
		for(i=0; i<num.length ; i++)
		{
			if(num.charCodeAt(i)!= 32&&( num.charCodeAt(i)<48 || num.charCodeAt(i)>57 ))
			{
				alert(FieldName+" is invalid")
				data.focus()
				result = false		
				break;
			}
			else
			{
				result = true
			}
		}
		return result
	}
	
}

