﻿// JScript File

function isInteger(field, alerttxt){
    var val = field.value;

    if(isBlank(val)){
        alert(alerttxt);
        field.focus();
        return false;
    }
    for(var i=0;i<val.length;i++){
        if(!isDigit(val.charAt(i))){
            alert(alerttxt);
            field.focus();
            return false;
        }
    }
  return true;  
}

function isBlank(val){if(val==null){return true;}for(var i=0;i<val.length;i++){if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}}return true;}

function isDigit(num){if(num.length>1){return false;}var string="1234567890";if(string.indexOf(num)!=-1){return true;}return false;}

   
function ValidateReq(field,alerttxt){
    with (field)
    {
        if (value==null||value=="") {
            alert(alerttxt);
            focus();
            return false;
        }
        else {return true;}
    }
}

function ValidateEmail(field, alerttxt){
    with (field)
    {
        var x = value;
	    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	    if (filter.test(x)) {
	        return true;
	        }
	    else{
	        alert(alerttxt);
	        focus();
	        return false;
	    }
    }
	
}

function textLimit(thisArea,maxLength) 
{
    // This function is not showing the text counter
	if (thisArea.value.length > maxLength) {
		//alert(maxLength + ' characters limit. \rExcessive data will be truncated.');
		alert('You have entered ' + thisArea.value.length + ' characters \rMaximum is ' + maxLength + ' characters limit.\rIncluding of HTML formatting text.');
		//thisArea.value = thisArea.value.substring(0, maxLength);
		//thisArea.focus();
		return false;
	}

}

function textLimitCheck(thisArea, showArea,maxLength) 
{
    // This function WILL showing the text counter
	if (thisArea.value.length > maxLength) {
        
		alert(maxLength + ' characters limit. \r Excessive data will be truncated.');
		thisArea.value = thisArea.value.substring(0, maxLength);
		thisArea.focus();
	}
	showArea.value = thisArea.value.length;
}

function showHideContent(id)
  {
    var elem = document.getElementById(id);
    if (elem) 
    {
      if (elem.style.visibility == 'hidden') 
      {
        elem.style.display = 'block';
        elem.style.visibility = 'visible';
      } 
      else
      {
        elem.style.display = 'none';
        elem.style.visibility = 'hidden';
      }
    }
  }  