/*browserName = navigator.appName;
var msie="Microsoft Internet Explorer";
browserVer = parseInt(navigator.appVersion);*/

/* Function to check empty or null values, string parameter expected */
function isEmpty(inputstr){
if (inputstr == null || inputstr == ""){
   return true;
  }
   else
 {
    return false;
  }
}

function isDecimal(inputVal)
 {
  var checkOK = "0123456789. ";
  var checkStr =  inputVal.toString();
  var allValid = true;
  for (i = 0;  i < checkStr.length; i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
    if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;	
}

/* Numeric parampeter expected */
function isPosInteger(inputVal) {
  var checkOK = "0123456789";
  var checkStr =  inputVal.toString();
  var allValid = true;
  for (i = 0;  i < checkStr.length; i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
    if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;	
}



/* Alphanumeric parampeter expected */
function isAlphanum(inputVal) {
  var checkOK = "0123456789 ()-_/\+";
  var checkStr =  inputVal.toString();
  var allValid = true;
  for (i = 0;  i < checkStr.length; i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
    if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  return allValid;	
}




function isPosIntegerd(inputVal) {
  var checkOK = "0123456789.";
  var checkStr =  inputVal.toString();
  var allValid = true;
  var dec = 0;
  var decptat;
  for (i = 0;  i < checkStr.length; i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
    if (ch == checkOK.charAt(j))
    {
      if(ch == ".")
      {
        decptat = i;
        dec++;
      }   
      break;
    }
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if(dec > 1)
    allValid = false;
  degaftdes = 0;
  if(dec == 1)
  {
   for(m=decptat++; m <=checkStr.length; m++)
    degaftdes++;

   if((degaftdes-2) > 2)
     allValid = false;  
  }
  return allValid;	
}

/* check for empty space */
function Verify(userentry) {
  achexists = false;
  entry = userentry;
  if(entry){
    for(var i = 0; i < entry.length; i++){
      if(entry.charAt(i) != " "){
       achexists = true;      }
    }
  }
  return achexists;
}

function ValidateLength(inputVal,minlength,maxlength){
 var checkStr =  inputVal.toString();
 var vallength = checkStr.length;
  
  if (vallength < minlength || vallength > maxlength){
   return false;
  }
  else
  {
  return true;
  }
}

function ValidateRange(inputVal,minVal,maxVal){
	if (inputVal < minval || inputVal > maxVal ){
	return false;
	}
	else
	{
	return true;
	}
}

function GoodEmail(inEmail)
{
	if (inEmail == " ")
	 {
		return(false);
	 }
	 else
	 {
		if (inEmail.indexOf("@") < 0 || inEmail.indexOf(".") < 0 || inEmail.length < 7) 
                 {
                     alert("Invalid Email Address...");

			return (false);
                 }
		 else
		 {
			return(true);
		 }
	 }
}

function chkext(pathname)
{
 var Img = pathname;
 var strlen = Img.length;
 if((Verify(Img)) && (strlen <= 4))
   return reterr(); 
 if((Verify(Img)) && (strlen > 4))
 {
   var descount = 0;
   for(var i=0;i<=strlen;i++)
   {
     desimal = Img.charAt(i);
     if(desimal == ".")
        descount++;
   }
   var extbgn = strlen -4;  
   if((descount == 1) && ((Img.substr(extbgn,4) == ".gif") || (Img.substr(extbgn,4) == ".jpg")))
     return true;
   else
     return reterr();
  } 
}

function reterr() 
{
  alert("Improper Image File. Only .jpg and .gif files are accepted");
  return false;
}

function errRetn(frm,box,param)
{

var txt;
if(param == 1)
 txt = 'can not be blank';
if(param == 2)
 txt = 'must be number';
if(param == 3)
 txt = 'must be numeric and currency';
if(param == 4)
 txt = 'is not a valid option. select one from the list box';

 var msgstr= "The field  '"+box+"'  "+txt;
 alert(msgstr);
 frm+'.'+box+'.focus()';
 return false;
}


function chkyr(D,M,Y)
{
 if(((M == 4) || (M == 6) || (M == 9) || (M == 11)) && (D == 31))
 {
  alert("The Day 31st is not a valid Option for the specified month");
  return false;
 }
 if((Y < 1970) || (Y > 9999))
 {
   alert("Please check the year, enter between 1995 and 9999");
   return false;
 }
 if(M == 2)   
 {
   if(D > 29)
   {
     alert("Month February can't exceed 29 days. Please verify the Day");
     return false;
   }
   if((D == 29) && (((Y %4 != 0) || (Y %100 == 0)) && (Y %400 != 0))) 
   {
     alert("Month February can't exceed 28 days for the non Leap Year. Please verify the Year");
     return false;
   }
  }
 else
  return true;
}

function chkyr(SD,SM,SY,ED,EM,EY)
{
 if(((SM == 4) || (SM == 6) || (SM == 9) || (SM == 11)) && (SD == 31))
 {
  alert("The Start day 31st is not a valid Option for the specified month");
  return false;
 }
 if((SY < 1970) || (SY > 9999))
 {
   alert("Please check the start year, enter between 1995 and 9999");
   return false;
 }
 if(SM == 2)   
 {
   if(SD > 29)
   {
     alert("Month February can't exceed 29 days. Please verify the Start day");
     return false;
   }
   if((SD == 29) && (((SY %4 != 0) || (SY %100 == 0)) && (SY %400 != 0))) 
   {
     alert("Month February can't exceed 28 days for the non Leap Year. Please verify the Start year");
     return false;
   }
  }
 
 if(((EM == 4) || (EM == 6) || (EM == 9) || (EM == 11)) && (ED == 31))
 {
  alert("The End day 31st is not a valid Option for the specified month");
  return false;
 }
 if((EY < 1970) || (EY > 9999))
 {
   alert("Please check the End year, enter between 1970 and 9999");
   return false;
 }
 if(EM == 2)   
 {
   if(ED > 29)
   {
     alert("Month February can't exceed 29 days. Please verify the End day");
     return false;
   }
   if((ED == 29) && (((EY %4 != 0) || (EY %100 == 0)) && (EY %400 != 0))) 
   {
     alert("Month February can't exceed 28 days for the non Leap Year. Please verify the End Year");
     return false;
   }
  }
 var sdateString = SY+'/'+SM+'/'+SD;
 var newsd = Date.parse(sdateString);
 var edateString = EY+'/'+EM+'/'+ED;
 var newed = Date.parse(edateString);
 var dd = newed-newsd;
 if(dd < 0)
 {
  alert("End Date should be after Start Date");
  return false;
 }
 else
  return true;
}
 