﻿// JScript File


function IsSelect(txtControlID,lblErrorID,ErrorMessage)
{
    if(Trim(document.getElementById(txtControlID).value)=="0")
    {
        document.getElementById(lblErrorID).innerHTML= ErrorMessage;
        
    }
    else
    {
            document.getElementById(lblErrorID).innerHTML= "";
    }
}

// This function trims a string from the right edge 
function RTrim(StringToTrim)
{
	StringToTrim = new String(StringToTrim);
	for(i = StringToTrim.length - 1 ; i > -1 ; i--)
	{
		strchar = StringToTrim.charAt(i);
		if ( (strchar == " ") || (strchar == "\t") || (strchar == "\n") || (strchar == "\r") )
		{
			StringToTrim = StringToTrim.substr(0,i);
		}
		else
			break;
	}
	return StringToTrim;
}

// This function trims a string
// for triming a string it will call the LTrim and RTrim function
function Trim(StringToTrim)
{
    return LTrim(RTrim(StringToTrim)); 
}
// This function trims a string from the left edge
function LTrim(StringToTrim)
{
	StringToTrim = new String(StringToTrim);
	for(i = 0 ;i < StringToTrim.length; i++)
	{
		strchar = StringToTrim.charAt(i);
		if ( (strchar == " ") || (strchar == "\t") || (strchar == "\n") || (strchar == "\r") )
		{
			StringToTrim = StringToTrim.substr(i+1);
			i--;
		}
		else
			break;
	}
	return StringToTrim;
}
function Checkfiles(ControlID)
{

     var fup = ControlID;

     var fileName = fup.value;

     var ext = fileName.substring(fileName.lastIndexOf('.') + 1);

     if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "PNG" || ext == "png" || ext == "BMP" || ext == "bmp")

      {
                return true;
      }        

      else

      {
//                 fup.focus();
                return false;
       }

}
function IsRequiredAndValidImage(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)!="")
    {
//        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
//        document.getElementById(txtControlID).className= "errorTextBox";
//    }
//    else
//    {
         if(!Checkfiles(document.getElementById(txtControlID)))
         {
            document.getElementById(lblErrorID).innerHTML= "Please upload valid image";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
}
function IsRequiredAndNumeric(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
         if(!IsNumeric(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Enter Only Digits upto 4 decimal digit";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
}

function IsNumeric(text)
{
	var ValidChars = "0123456789.";                                        
    var Char;
    var count=0;
    var blnFlag=false;
    for (i = 0 ; i < text.length ; i++)
    {
		Char = text.charAt(i);
		
		if (ValidChars.indexOf(Char) == -1)
        {
			return false;
		}
		if(blnFlag==true)
		{
		    count=count+1;
		}
		if(count>4)
		{
		    return false;
		}
		if(Char==".")
		{
		   blnFlag=true;
		}
		
		
    }
    if(count==0 && blnFlag==true)
    {
        return false;
    }
	return true;
}

function IsMoneyNumeric(text)
{
	var ValidChars = "0123456789.";                                        
    var Char;
    var count=0;
    var blnFlag=false;
    for (i = 0 ; i < text.length ; i++)
    {
		Char = text.charAt(i);
		
		if (ValidChars.indexOf(Char) == -1)
        {
			return false;
		}
		if(blnFlag==true)
		{
		    count=count+1;
		}
		if(count>2)
		{
		    return false;
		}
		if(Char==".")
		{
		   blnFlag=true;
		}
		
		
    }
    if(count==0 && blnFlag==true)
    {
        return false;
    }
	return true;
}
function IsRequiredAndMoney(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
         if(!IsMoneyNumeric(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Enter valid Money upto 2 decimal digit";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
}


function IsRequiredAndAMountAndPercentage(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
         if(!IsNumeric(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Enter Only valid amount or Percentage";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
}


function IsMoney(txtControlID,lblErrorID)
{
     if(!IsMoneyNumeric(Trim(document.getElementById(txtControlID).value)))
     {
        document.getElementById(lblErrorID).innerHTML= "Enter valid Money upto 2 decimal digit";
        document.getElementById(txtControlID).className= "errorTextBox";
     }
     else
     {
        document.getElementById(lblErrorID).innerHTML= "";
        document.getElementById(txtControlID).className= "textbox";
     }
}

   function getkey(e)
    {
        if (window.event)
           return window.event.keyCode;
        else if (e)
           return e.which;
        else
           return null;
    }
    function Validate(e)
    {
        var key = getkey(e);
        if (key==46 || key==8) 
            return true;
        else
            return false;
    }
    
 function textboxMultilineMaxNumber(txt,maxLen,e)
 {
    try{
        
        if(txt.value.length > (maxLen-1))
        return Validate(e)
       }
       catch(e){
       }
 }
function IsPassAndConfirmPass(txtControlID,txtConfirmControlID,lblErrorID)
{ 
    if(Trim(document.getElementById(txtConfirmControlID).value)!="")
    {        
        if(document.getElementById(txtControlID).value!= document.getElementById(txtConfirmControlID).value)
         {
          document.getElementById(lblErrorID).innerHTML= "Password and ConfirmPassword do not match";
          document.getElementById(txtConfirmControlID).className= "errorTextBox";
         }              
        else
        {
           document.getElementById(lblErrorID).innerHTML= "";
           document.getElementById(txtConfirmControlID).className= "textbox";
        }
    }
    else
    {
          document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
          document.getElementById(txtConfirmControlID).className= "errorTextBox";
    }
}  
function isCharacter(text)
{
    return validateRegularExp(text,/^[a-zA-Z]+$/);
}

function isNumber(text)
{
    return validateRegularExp(text,/^[0-9]+$/);
}

function isEmailAdd(text)
{
    return validateRegularExp(text,/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/);
}
function isTimeF(text)
{
  return validateRegularExp(text,/^([0-1][0-9]\:[0-5][0-9]\:[0-5][0-9])|([2][0-3]\:[0-5][0-9]\:[0-5][0-9])$/);
}

function validateRegularExp(text,reg){
if(text == null || text == '')return true;		
	if(reg == null || reg =='')return true;		
var regex = new RegExp(reg);var value=text;
    var res= (regex.exec(text));
return (res != null && value == res[0]);}




function IsRequiredDate(txtControlID,lblErrorID)
{

    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "date-pick errorTextBox dp-applied";
        blnFlag =false;
    }
    else
    {
        document.getElementById(lblErrorID).innerHTML= "";
        document.getElementById(txtControlID).className= "date-pick textbox dp-applied";
    }
}
function IsRequired(txtControlID,lblErrorID)
{

    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
        blnFlag =false;
    }
    else
    {
        document.getElementById(lblErrorID).innerHTML= "";
        document.getElementById(txtControlID).className= "textbox";
    }
}

function IsNumberOnBlur(txtControlID,lblErrorID)
{
     if(!isNumber(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Enter Only Digits";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
}
function IsEmailOnBlur(txtControlID,lblErrorID)
{
     if(!isEmailAdd(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Email address seems incorrect";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
}

function IsCharacterOnBlur(txtControlID,lblErrorID)
{
    if(!isCharacter(Trim(document.getElementById(txtControlID).value)))
     {
        document.getElementById(lblErrorID).innerHTML= "Only letters are allowed";
        document.getElementById(txtControlID).className= "errorTextBox";
     }
    else
    {
        document.getElementById(lblErrorID).innerHTML= "";
        document.getElementById(txtControlID).className= "textbox";
    }
}
function IsRequiredAndNumber(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
         if(!isNumber(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Enter Only Digits";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
}
  function IsRequiredAndTime(ddlControlID,txtControlID,lblErrorID)
  {
     if(document.getElementById(ddlControlID).value=="0")
     {
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
        if(!isTimeF(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Please enter valid time";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
    }
    else
    {
       if(Trim(document.getElementById(txtControlID).value)!=="")
       {
          if(!isTimeF(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Please enter valid time";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
       }
     }
  
  }
  function IsRequiredAndDateT(ddlControlID,txtControlID,lblErrorID)
  {
     
    if(document.getElementById(ddlControlID).value=="0")
    {
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "date-pick errorTextBox dp-applied";
        blnFlag =false;
    }
    else
    {
        document.getElementById(lblErrorID).innerHTML= "";
        document.getElementById(txtControlID).className= "date-pick textbox dp-applied";
    }
    }
  }
  function IsRequiredAndBatch(ddlControlID,txtControlID,lblErrorID)
   {  
      if(Trim(document.getElementById(ddlControlID).value)=="0")
      {
        if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
        blnFlag =false;
    }
    else
    {
        document.getElementById(lblErrorID).innerHTML= "";
        document.getElementById(txtControlID).className= "textbox";
    }
    }
    else
    {
        if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
        if(!isEmailAdd(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Email address seems incorrect";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
    
    }    
      
   
   }
function IsRequiredAndEmail(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className= "errorTextBox";
    }
    else
    {
        if(!isEmailAdd(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Email address seems incorrect";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
         else
         {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className= "textbox";
         }
    }
}

function IsRequiredAndCharacters(txtControlID,lblErrorID)
{
    if(Trim(document.getElementById(txtControlID).value)=="")
    {
        document.getElementById(lblErrorID).innerHTML= "Required field cannot be left blank";
        document.getElementById(txtControlID).className="errorTextBox";
    }
    else
    {
         if(!isCharacter(Trim(document.getElementById(txtControlID).value)))
         {
            document.getElementById(lblErrorID).innerHTML= "Only letters are allowed";
            document.getElementById(txtControlID).className= "errorTextBox";
         }
        else
        {
            document.getElementById(lblErrorID).innerHTML= "";
            document.getElementById(txtControlID).className="textbox";
        }
    }
}
  
             
