/*
    
Author              : R Muruganandhan
    
Created Date        : 30/01/2006
    
*/

var pattern_null='^ *$';
var reg_null = new RegExp(pattern_null);
var reg_email=/^ *\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+ *$/;




//Validating Null values
function fnCheckNull(frm,name,message)
{  
     //alert(frm);
     // alert(name);
     // alert(message);
      //alert(eval("document."+frm+"."+name+".value")));
     // var bb ="document."+frm+"."+name+".value";
      //alert(bb);
     
   if(reg_null.test(eval("document."+frm+"."+name+".value")))  
     //if(bb!="")
      {    
     
          alert("Please enter the "+message);    
          //eval("document."+frm+"."+name+".focus()")    
          bb.focus();
          return false;  
      }
  
   return true;
}
//**********************************************

//Only for Browse file
function fnCheckBrowseNull(frm,name,message)
{  
      if(reg_null.test(eval("document."+frm+"."+name+".value")))  
      {    
          alert("Please select file Name "+message);    
          eval("document."+frm+"."+name+".focus()")    
          return false;  
      }
  
   return true;
}
//**********************************************

//Validating the combo boxes whether it's null.
//Parameter 3
function fnCheckCmbNull(frm,name,message)

{	
	 //var myindex=document.forms[0].cmbState.selectedIndex;
	 var myindex=eval("document."+frm+"."+name+".selectedIndex")
     if  (myindex==0)
  
     {
    
           alert("Please select the "+message);
    
           eval("document."+frm+"."+name+".focus()")
    
           return false;
  
     }
  return true;

}//**********************************************

//Validating the combo boxes whether it's null.
//Parameter 2
function fnCheckCmbNull(frm,name)

{	
	 //Parameter is for 
	 //var myindex=document.forms[0].cmbState.selectedIndex;
	 var myindex=eval("document."+frm+"."+name+".selectedIndex")
     if  (myindex==0)
  
     {
    
           //alert("Please select the "+message);
    
           //eval("document."+frm+"."+name+".focus()")
           return false;
  
     }
  return true;

}//**********************************************


//Validating the email entered
function fnCheckEmail(frm,name,message)

{
  
if(!reg_email.test(eval("document."+frm+"."+name+".value")))
        {
    
              alert("Please enter the "+message);
    
              eval("document."+frm+"."+name+".focus()")
    
              return false;
  
        }
  return true;

}
//**********************************************





/* Display Max Length can be typed Start*/

function checkchars(txtArea,txtLength)
{
txtArea.value = txtArea.value.slice(0, txtLength);
if(txtArea.value.length>=20)
{
	alert('Only 20 Characters are Allowed');
}
	//Display Remaining characters can type in TextBox
	document.getElementById('txtDisplay').value =txtLength - txtArea.value.length
}

/* Setting Max Length  End*/
//**********************************************




// Validation for Numeric START
 function fnNumeric(frm,name,message)
 {	if (IsNumeric(eval("document."+frm+"."+name+".value")) == false && eval("document."+frm+"."+name+".value.length")!="") 
	{
		alert("Please check - non numeric value!");
		eval("document."+frm+"."+name+".value=''");
		eval("document."+frm+"."+name+".focus()");
		return false;
	}
	return true;
 }

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;
	
   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
	  {
	  strChar = strString.charAt(i);
	  if (strValidChars.indexOf(strChar) == -1)
		 {
		 blnResult = false;
		 }
	  }
   return blnResult;
   }
// Validation for Numeric END
//**********************************************



//No of Max Selection in Multiple ComboBox START
var r = new Array();

function k(frm,name,MinValue,MaxValue)
{
	//var k=item;
	var k=eval("document."+frm+"."+name)

	var min=MinValue;
	var max=MaxValue;

	var t=0;

	for(i=0;i<k.options.length;i++)
	{
		if(k.options[i].selected==true)
		{
		t++;
		}
	}

	if(t<min)
	{
		alert("Minimum Selection is " + min);

		for(o=0;o<k.options.length;o++)
		{
			k.options[o].selected=false;
		}

		for(y=0;y<r.length;y++)
		{
		k.options[r[y]].selected=true;
		}
		k.options[0].selected=true;
		return false;
	}

	if(t>max)
	{
		alert("Maximum Selection is " + max);

		for(o=0;o<k.options.length;o++)
		{
			k.options[o].selected=false;
		}

		for(y=0;y<r.length;y++)
		{
		k.options[r[y]].selected=true;
		}
		k.options[0].selected=true;
		return false;
	}
	else
	{
		return true;
	}
}

//No of Max Selection in Multiple ComboBox End
//********************************************




//Checking firstletter should be Character,Invalid charcter
function isAlphabetic(frm,name,strMinLength,strMaxLength)
{
	ObjName=eval("document."+frm+"."+name)
	s=eval("document."+frm+"."+name+".value")
	var str_len,msg;
	str_len=0;
	var c = s.charAt(str_len);
	if (!isLetter(c))
	{
			alert("First Letter Should be Character" )
			ObjName.value = ""
			ObjName.focus()
			return false;
	}
	for (i=0;i<s.length;i++)
	{
	var c = s.charAt(i);
	if (!isLetterDigit(c))
		{   
		alert("Invalid characters typed " )
		ObjName.value = ""
		ObjName.focus()
		return false;
		}	
	}
	return true;
}

//Check AlphaNumeric
function isLetterDigit(c)
{
		//return ((isLetter(c) || isDigit(c)) && (c != " "))
		return ((isLetter(c) || isDigit(c)))
}
	
//Check Numeric
function isDigit(c)
{
   return ((c >= "0") && (c <= "9")) 
}

//Check Alphabets
function isLetter(c)
{
 // Don't Delete
 //return ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == " ") || (c == "&") || (c == "-") || (c == "_") || (c == ".") || (c == ",") || (c == ";") || (c == ":") || (c == "/") || (c == "+") || (c == "(") || (c == ")")
 return ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z"))
}
//**********************************************

//Check Special char Letter by Letter
function isSpecialChar(c)
{
 // Don't Delete
 //return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || (c == "-") || (c == "_") || (c == " ") || ((c >= "0") && (c <= "9")))
 return ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || ((c >= "0") && (c <= "9")) || (c == " ") || (c == "&") || (c == "-") || (c == "_") || (c == ".") || (c == ";") || (c == ":") || (c == "/") || (c == "+") || (c == "#") || (c == "$") || (c == "@") || (c == "!") || (c == "%") || (c == "")
}


//Check Special char for Company only
function isSpecialCharCompany(c)
{
 // Don't Delete
 return ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) || ((c >= "0") && (c <= "9")) || (c == " ") || (c == "&") || (c == "-") || (c == "_") || (c == ".") || (c == ";") || (c == ":") || (c == "/") || (c == "+") || (c == "#") || (c == "$") || (c == "@") || (c == "!") || (c == "%") || (c == "")
}


//Setting Upper and Lower Bound limitation START
function fnSetMinMax(frm,name,strMinLength,strMaxLength,Message)
{	ObjName=eval("document."+frm+"."+name)
	objValue=eval("document."+frm+"."+name+".value")
	if (strMinLength!=0)
	{
		//Length is Greater than
		if(objValue.length<strMinLength)
		{
			alert("The " + Message + " must be Minimum " + strMinLength + " Characters")
			ObjName.value = ""
			ObjName.focus()
			return false;
		}

		if(objValue.length>strMaxLength)
		{
			alert("The " + Message + " Exceed Maximum Characters " + strMaxLength  )
			//ObjName.value = substring(ObjName.value,1,strMaxLength)
			ObjName.value = ""
			ObjName.focus()
			return false;
		}
	}
	return true;
	
}
//Setting Upper and Lower Bound limitation END

//Checking Special Character
function fnSpecialCharacter(frm,name)
{
	ObjName=eval("document."+frm+"."+name)
	s=eval("document."+frm+"."+name+".value")
	var str_len,msg;
	str_len=0;
	var c = s.charAt(str_len);

	for (i=0;i<s.length;i++)
	{
	var c = s.charAt(i);
	
		if (name=="txtCompany")
		{
			if (!isSpecialCharCompany(c))
			{   
			alert("Invalid characters typed " )
			ObjName.value = ""
			ObjName.focus()
			return false;
			}
		}
		else
		{
			if (!isSpecialChar(c))
			{   
			alert("Invalid characters typed " )
			ObjName.value = ""
			ObjName.focus()
			return false;
			}	
		}
	}
	
	
	
	return true;
}
