﻿//E-mail  Validation 
function Validemail(str,obj)
		{
			var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str==""){
			return true;
		}
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		    obj.focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   obj.focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    obj.focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    obj.focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    obj.focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    obj.focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    obj.focus();
		    return false
		 }

 		 return true	
		}
//Confirm Deletion
 function chk_del()
        {
            var str;
            str="Are you sure to delete?";
            
            if (window.confirm(str))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}

//on Focus
 function on_focus(ctrln)
        {
            if(document.getElementById(ctrln).value=="0.00")
            {
                document.getElementById(ctrln).value="";    
            }
        }
        
// Check All checkbox        
  function chk_all(aspCheckBoxID, checkVal)
       {
        alert(aspCheckBoxID);   
            re = new RegExp('_'+aspCheckBoxID);
            for(i = 0; i < document.forms[0].elements.length; i++)
            {
                elm = document.forms[0].elements[i];
                
                 if (elm.type == 'checkbox')
                 {
                    if (re.test(elm.id))
                     {
                      elm.checked=checkVal;
                       
                     }
                 }
            }
       }
       
// Allow characters only
function chkchr(e)
{
    var key;
	key=e.keyCode;
	//alert(e.keyCode);
	if((key>=65 && key<=90) ||(key>=97 && key<=122) || key==32 ||key==8 ||key==46)
	{
	    return true;
	}
	return false;
}

function Chkdate(str)
		{
	      var arr=str.split("/");
            
           if(arr[0]>31)
        {
            alert("Invalid date");
            
            return false;
        }
    if (arr[1]>12)
        {
            alert("Invalid Month");
            
            return false;
        }
    if (arr[2]<1900)
        {
            alert("Invalid Year");
            
            return false;
        }
        return true;
		}
		
		
function textboxMultilineMaxNumber(txt,maxLen)
      { 
      try
      { 
      if(txt.value.length > (maxLen-1))
      return false; 
      }
      catch(e)
      { }
       }
