﻿


// For Allowing Only Numbers
function numbersonly(e)
{
  var unicode=e.charCode? e.charCode : e.keyCode
 
  if (unicode<=47||unicode>57) 
 
     return false; 
    
}

// For Allowing Only Alphabets
function alphabetsonly(e)
{

   var unicode=e.charCode? e.charCode : e.keyCode
    if (unicode!=8 && unicode!=46 && unicode!=37 && unicode!=39 && unicode!=40 && unicode!=38)
   
    {
    
        if (unicode<65||unicode>90 )  
            if (unicode<97||unicode>122)
            if (unicode!=32)
                   {
                      return false;
                    }  
    }     
 }
 
 //For Allowing Only AlphaNumeric
 function alphanumeric(e)
{
    var unicode=e.charCode? e.charCode : e.keyCode
   
    if (unicode!=32 && unicode!=46 )
    
    { //if the key isn't the backspace key (which we should allow)
        if (unicode<65||unicode>90) //if not a number
            if (unicode<97||unicode>122)
                 if (unicode<48||unicode>57) 
                   {
                    return false //disable key press
                    }       
    }
}

function openPopupwindow(page,title,height,width,scrollable)
{
    newwindow=window.open(page,'','height='+height+',width='+width+',scrollable='+scrollable+'');
	if (window.focus) 
	{newwindow.focus()}
	return false;
}

function validateTextbox(obj,alertName,focus)
{
   
    if(obj != null)
    {
        if(obj.value == "")
        {
            alert("Please Enter Your "+alertName+"");
            if(focus=="y")
            {
                obj.focus();
            }
            return false;
        }
    }
    else
    {
        alert("Wrong ID Declared For TextBox '"+alertName+"'. Please Check");
        return false;
    }
    return true;
}


function validateDropdown(obj,alertName,focus)
{
    if(obj != null)
    {
        if(obj.value == "-")
        {
            alert("Please Select "+alertName+"");
            if(focus=="y")
            {
                obj.focus();
            }
            return false;
        }
    }
    else
    {
        alert(" Wrong ID Declared For  Dropdown '"+alertName+"'. Please Check");
        return false;
    }
    return true;
}

function validateRadioButton(obj,alertName)
{
    var objChk = false;
    
    if(obj != null)
    {
        
        for(i = 0;i<obj.length;i++)
        {
           if(obj[i].checked)
           {
            objChk = true;
            break;
           } 
        }
        
        if(objChk==false)
        {
            alert("Please Select "+alertName+"");
            return false;
        }
    }
    else
    {
        alert(" Wrong ID Declared For  RadioButton '"+alertName+"'. Please Check");
        return false;
    }
    return true;
}



function validateCheckBox(obj,alertName)
{
    var objChk = false;
    
    if(obj != null)
    {
        alert(obj.length);
        for(i = 0;i<obj.length;i++)
        {
           if(obj[i].checked)
           {
            objChk = true;
            break;
           } 
        }
        
        if(objChk==false)
        {
            alert("Please Select "+alertName+"");
            return false;
        }
    }
    else
    {
        alert(" Wrong ID Declared For  CheckBox '"+alertName+"'. Please Check");
        return false;
    }
    return true;
}

function confirmMsg()
{
    if(confirm("Are You Sure Do You Want to Delete?"))
    {
        return true;
    }
    else
    {
        return false;
    }
}


function search()
{
    if(document.getElementById('hiddenButton') != null)
    {
        document.getElementById('hiddenButton').click();
        return true;
     }
     else
     {
        alert("HiddenButton Does not Exist");
        return false;
     }   
}


function checkEmail(str,obj,focus) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please Enter Valid E-mail ID")
		   if(focus=="y")
            {
                obj.focus();
            }
		   	                        
		  return false
		  }

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please Enter Valid E-mail ID")
		   	if(focus=="y")
            {
                obj.focus();
            }	   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please Enter Valid E-mail ID")
		    if(focus=="y")
            {
                obj.focus();
            }		   		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please Enter Valid E-mail ID")
		    if(focus=="y")
            {
                obj.focus();
            }
		   		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please Enter Valid E-mail ID")
		    if(focus=="y")
            {
                obj.focus();
            }
		   	   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please Enter Valid E-mail ID")
		    if(focus=="y")
            {
                obj.focus();
            }		   	   
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please Enter Valid E-mail ID")
		    if(focus=="y")
            {
                obj.focus();
            }
		    return false
		 }
            
 		 return true					
	}






