
// JScript File

//For LTrim Function

function Ltrim_string(objID)
{			
var j = 0,k=0;
if(objID.length>0)
{
	for(var i=0;i<objID.length && k<objID.length;i++)
	{
		if(objID.charAt(i)==" ")
		{
		j++;
		}
		else
		{
		k = objID.length;
		}
	}
	objID =objID.substring(j,objID.length);
}
	return objID;
}


//Blank Check
function CheckBlank(objID,strControlName)
{
   if (Ltrim_string(objID.value)=="")
   {
		alert(strControlName+": Cannot be left blank");
		objID.focus();
		return false;
	}
	return true;
}

//Blank Check without setFocus
function CheckBlank1(objID,strControlName)
{
   if (Ltrim_string(objID.value)=="")
   {
		alert(strControlName+": Cannot be left blank");
		return false;
	}
	return true;
}

//function to check alphabets without space
function CheckAlphabets(objID,strControlName)
{
	var alpha=/[a-zA-Z]+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphabets only.")
			objID.focus();
 			objID.select();
			return false;
	    }
	return true;
}

//function to check alphabets with space
function CheckAlphabetsWithSpace(objID,strControlName)
{
	var alpha=/[a-zA-Z ]+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphabets only.")
			objID.focus();
 			objID.select();
			return false;
	}
	return true;
}

//function to check alphabets without space, allowing '
function CheckSurname(objID,strControlName)
{
	var alpha=/[a-zA-Z']+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphabets only.")
			objID.focus();
 			objID.select();
			return false;
	    }
	return true;
}

//Validation For Single EMail-Id
function CheckMail(objID,strControlName)
{
if (objID.value!="")
		{
		
	var email =/[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9]+\.[-a-zA-Z0-9\.]+/;
	var eflag = objID.value.match(email);
	if(eflag!=objID.value)
	{
		alert(strControlName+ ": should be in proper format")
		objID.focus();
		objID.select();
		return false;
		}
		else if(objID.value.indexOf(".")==0)
		{
		alert(strControlName +": should be valid Email")
		objID.focus();
		objID.select();
		return false;
		}
	}
	return true;
} 

//Allow only Numbers in TextBox
function CheckNumeric(objID,strControlName)
	{	
		if (objID.value!="")
		{
			var num=/[0-9.]+/
			numflag=objID.value.match(num);	
			if(numflag !=objID.value){
			alert(strControlName+ ": should be Numeric only.")
			objID.focus();
 			objID.select();
			return false;
		}
	}
	return true;
}


//Allow Numbers with () & - in TextBox of phone number
function CheckPhone(objID,strControlName)
{	
		if (objID.value!="")
		{
			//var num=/[0-9()-]+/
			var num=/\(?[0-9]{0,4}\)?[-]?[0-9]{8,9}/
			//{0,4}means digits can come for 0 times to 4 times (std code), ? means it can come 0 or 1 times
			//var num=/\(?\d{3}\)?[- ]?\d{3}/
			numflag=objID.value.match(num);	
			if(numflag !=objID.value)
			{
			    alert(strControlName+ ": should be Numeric and in proper format with minimum length 8")
			    objID.focus();
 			    objID.select();
			    return false;
		    }
		   
	    }
	    return true;
}

/*
//Allow Numbers with () & - in TextBox of phone number
function CheckPhone(objID,strControlName)
{	
    alert("in validation");
		if (objID.value!="")
		{
			var num=/[0-9()-]+/
			//var num=/\(?\d{3}\)?[- ]?\d{3}/
			numflag=objID.value.match(num);	
			if(numflag !=objID.value)
			{
			    alert(strControlName+ ": should be Numeric and in proper format with minimum length 8")
			    objID.focus();
 			    objID.select();
			    return false;
            }
            /*else
            {var arr[5];
                alert("in else");
                if(objID.value.contains("-"))
                {
                    arr=objID.value.split("-")
                    alert(arr[0].value);
                }//if contains -
            }
	    }*/
/*	    return true;
}
*/

//function to check alpha numeric with space
function checkAlphaNumSpace(fieldName,str)
{

if (fieldName.value!="")
    {
	var alphanum=/[a-zA-Z0-9 ]+/;
	alphaflag=fieldName.value.match(alphanum);	
        if(alphaflag != fieldName.value)
        {
                alert(str+ " should contain alphabets and/or numbers only.")
                fieldName.focus();
                fieldName.select();
                return false;
        }
	}
	return true;
}

//function to check alpha numeric with space & special charcters ' & -
function checkAlphaNumSpaceSpl(fieldName,str)
{

if (fieldName.value!="")
    {
	var alphanum=/[a-zA-Z0-9\s.'&,-]+/;
	alphaflag=fieldName.value.match(alphanum);	
        if(alphaflag != fieldName.value)
        {
                alert(str+ " should contain alphabets and/or numbers only.")
                fieldName.focus();
                fieldName.select();
                return false;
        }
	}
	return true;
}


//function to check alphanumeric without space
function CheckAlphaNumeric(objID,strControlName)
{
	var alpha=/[a-zA-Z0-9]+/;
	alphaflag=objID.value.match(alpha);	
		if(alphaflag != objID.value)
		{
			alert(strControlName+ ": should be Alphanumeric only.")
			objID.focus();
 			objID.select();
			return false;
	}
	return true;
}

//Allow Numbers with dot for currency in TextBox
function checkDotNumber(fieldName,str)
{

    if (fieldName.value!="")
    {
        var dnum=/(^\d+$)|(^\d+\.\d+$)/
        if (dnum.test(fieldName.value))
            return true;
        else
        {
             alert(str+ ": should be Numeric & in proper format.");
             fieldName.focus();
             fieldName.select();
             return false;
        }
       
    }
    
    
    return true;
}

//function to check if textfield contains only zero
function CheckZero(objID,strControlName)
{
  if (objID.value!="")
    {
	  if(objID.value==0)
		  {
			  alert(strControlName+ ": cannot be zero")
			  objID.focus();
 			  objID.select();
 			  
			  return false;
	      }
	   }
	   
	return true;
}

////function to check specified length-length can be pass by passing values to the parameter

function LengthCheck(objControl,strControlName,strlength)
{
    /*alert(objControl.value);
    alert(strControlName);
    alert(strlength);*/
    if (objControl.value!="")
    {
        if(objControl.value.length<strlength)
        {
            alert(strControlName+": should have minimum length "+strlength+"");
            objControl.focus();
            objControl.select();
            return false;
        } 
    }
    return true;
} 


//Validation For Drop-Down List
function CheckDropDown(objID,strControlName)
{
	   if(objID.options[0].selected=="true" || objID.selectedIndex == 0)
	   {
		alert(strControlName+ ": Select a proper option.");
		objID.focus();
		return false;
	}
	return true;
} 


//Validation for check box if neither check box is selected.
function CheckCheckBox(frm,objID)
{
alert(objID.value);
if(document.frm.objID.checked=="true")
{
	alert("Select at List one knowledge,Information & Educational Products!");
	//document.getElementById("objID").focus();
	return false;
}
return true;
}



//Validation for password and confirm password field
function ComparePassword(objID1,objID2,strControlName)
{
    if(objID1.value!=objID2.value)
    {
	    alert(strControlName+": doesn't match!");
	    objID2.focus();
	    return false;
    }
return true;
}

//Validation for listbox control
function CheckListBox(objID,strControlName)
{
    if(objID.value=="select one")
    {
        alert(strControlName+": select atleast one!");
        objID.focus();
        return false;
    }
return true;
}
