﻿// JScript File
     function getParameterByName( name ) 
            { 
              name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
              var regexS = "[\\?&]"+name+"=([^&#]*)"; 
              var regex = new RegExp( regexS ); 
              var results = regex.exec( window.location.href ); 
              if( results == null ) 
                return ""; 
              else 
                return results[1]; 
            } 
function trimAll(sString) 
{
 return sString.replace(/^\s*/, "").replace(/\s*$/, ""); 
}



function validate_required(field,alerttxt)
{
with (field)
  {
   if (trimAll(value)==null|| trimAll(value)=="" )
    {
    alert(alerttxt);return false;
    }
  else
    {
    return true;
    }
  }
}
function validate_email(field,alerttxt)
{
 
with (field)
  {
  apos=value.indexOf("@");
  dotpos=value.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {alert(alerttxt);return false;}
  else {return true;}
  }
}

function GetSelectedIndex (objectid)
{

var myindex  = document.getElementById(objectid).selectedIndex;
return myindex;
}
function fn_NA(dropdownid1,dropdownid2,FromTo)
{
 
var dropdownid1val=GetSelectedIndex(dropdownid1);
var dropdownid2val=GetSelectedIndex(dropdownid2);
if (dropdownid1val==0 && dropdownid2val!=0)
     document.getElementById(dropdownid2).options[0].selected = true;
else if (dropdownid1val!=0 && dropdownid2val==0)
     document.getElementById(dropdownid2).options[dropdownid1val].selected = true;
else if (FromTo=="F" && (dropdownid1val > dropdownid2val))
     document.getElementById(dropdownid2).options[dropdownid1val].selected = true;
else if (FromTo=="T" && (dropdownid1val < dropdownid2val))
     document.getElementById(dropdownid2).options[dropdownid1val].selected = true;
}

function fn_ALL(dropdownid)
{
 
 if (document.getElementById(dropdownid).options[0].selected == true)
 {
    document.getElementById(dropdownid).selectedIndex=-1;
    document.getElementById(dropdownid).options[0].selected = true;
 }
 
}


function isNumeric(sText,decimals,negatives) {
	var isNumber=true;
	var numDecimals = 0;
	var validChars = "0123456789";
	if (decimals)  validChars += ".";
	if (negatives) validChars += "-";
	var thisChar;
	for (i = 0; i < sText.length && isNumber == true; i++) {  
		thisChar = sText.charAt(i); 
		if (negatives && thisChar == "-" && i > 0) isNumber = false;
		if (decimals && thisChar == "."){
			numDecimals = numDecimals + 1;
			if (i==0 || i == sText.length-1) isNumber = false;
			if (numDecimals > 1) isNumber = false;
		}
		if (validChars.indexOf(thisChar) == -1) isNumber = false;
	}
	return isNumber;
}
// check date JavaScript function
// if date is valid then function returns true, otherwise returns false
function isDate(txtDate){
  var objDate;  // date object initialized from the txtDate string
  var mSeconds; // milliseconds from txtDate

	// date length should be 10 characters - no more, no less
  if (txtDate.length != 10) return false;

	// extract day, month and year from the txtDate string
	// expected format is mm/dd/yyyy
	// subtraction will cast variables to integer implicitly
  var day   = txtDate.substring(0,2)  - 0;
  var month = txtDate.substring(3,5)  - 1; // because months in JS start with 0
  var year  = txtDate.substring(6,10) - 0;

	// third and sixth character should be /
	if (txtDate.substring(2,3) != '/') return false;
	if (txtDate.substring(5,6) != '/') return false;

  // test year range
  if (year < 999 || year > 3000) return false;

  // convert txtDate to the milliseconds
  mSeconds = (new Date(year, month, day)).getTime();

  // set the date object from milliseconds
  objDate = new Date();
  objDate.setTime(mSeconds);

  // if there exists difference then date isn't valid
  if (objDate.getFullYear() != year)  return false;
  if (objDate.getMonth()    != month) return false;
  if (objDate.getDate()     != day)   return false;

	// otherwise return true
  return true;
}


