	//'<! -- Propriety, confidential and trade secret of Coldwater Technology, Incorporated.  This copyright protected work is licensed for use by the licensee.  Any unauthorized copy or dissemination of all, or part of this document is a violation of Federal Copyright laws. -->
	function roundNumbers () {
			var numberofRecords = document.forms[0].length
			for (var i = 0; i <numberofRecords; ++i) {
				var valueNumber;
				valueNumber = eval (document.forms[0].elements[i].value);
				document.forms[0].elements[i].value =  valueNumber.toFixed(2);
			}
	}	

			function AJAX_Client(URL, params, Async, f)
			{
			    var xmlHttp;
				var retValue;
			    try
				    {    // Firefox, Opera 8.0+, Safari
				    xmlHttp=new XMLHttpRequest();
				    }
			    catch (e)
			        {    // Internet Explorer
			        try
			            {
			            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			            }
			        catch (e)
			            {
			            try
				            {
				            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				            }
			            catch (e)
				            {
				            alert("Your browser does not support AJAX!");
				            return false;
				            }
				        }
			        }
			
			xmlHttp.onreadystatechange=function()
                    {
                    if(xmlHttp.readyState==4)

                    {

                    clearTimeout(requestTimer);     // Clear the timer that would abort this request

                    retValue=xmlHttp.responseText;
                    xmlHttp.abort();

   

                    }
                    }

                xmlHttp.open("POST",URL,Async);

                //Include header information along with the request
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-length", params.length);
                xmlHttp.setRequestHeader("Connection", "close");

                xmlHttp.send(params);

                var requestTimer = setTimeout(function() {
                    // Timeout this request if it out for more than 60 seconds
                    if (xmlHttp != null)
                    {
                        xmlHttp.abort();   
                    }
                   },60000);

                return retValue;
                }


			function AJAX_ClientXML(URL, params)
			{	var xmlHttp;
				var retValue;
			try
				{    // Firefox, Opera 8.0+, Safari
				xmlHttp=new XMLHttpRequest();
				}
			catch (e)
			{    // Internet Explorer
			try
			{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
			    try
				    {
				        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				    }
			    catch (e)
				    {
				        alert("Your browser does not support AJAX!");
				        return false;
				    }
				    }
			}

			xmlHttp.onreadystatechange=function()
			{
			    if(xmlHttp.readyState==4)
				    {
				        // document.myForm.time.value=xmlHttp.responseText;
				        //retValue=xmlHttp.responseText;
				        retValue=xmlHttp.responseXML.documentElement;
				        xmlHttp.abort();
				    }
			}

			    xmlHttp.open("POST",URL,true);

			    //Include header information along with the request
			    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			    xmlHttp.setRequestHeader("Content-length", params.length);
			    xmlHttp.setRequestHeader("Connection", "close");

			    xmlHttp.send(params);

			    return xmlHttp.responseXML.documentElement   //retValue;
			   
			}
			
			function GetXmlHttpObject()
			    {
			        var xmlHttp=null;

			        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

			        return xmlHttp;
			    }

			function xopenrecordset(sql,System)
			    {
			        var a;
			        xmlHttp=GetXmlHttpObject();

			        var URL = "ColdwaterProc.asp";
			        var params = "Action=GetXML&System=" + escape(System) + "&SQL=" + escape(sql);
			        xmlHttp.open("POST",URL,false);
			        
			        //Include header information along with the request
			        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			        xmlHttp.setRequestHeader("Content-length", params.length);
			        xmlHttp.setRequestHeader("Connection", "close");
			        
			        xmlHttp.send(params);

			        this.EndOFile = false;
			        this.RecNo = 0;
			       
			        this.xmlDoc=xmlHttp.responseXML.documentElement;
			        xmlHttp.abort();
			        if (this.xmlDoc.childNodes.length == 0)
			            {
			            this.EndOFile = true;
			            }
			    }


			xopenrecordset.prototype.EOF = function()
			        {
			            if (this.RecNo >= (this.xmlDoc.childNodes.length))
			            {
			                this.EndOFile = true;
			            }
			            else
			            {
			                this.EndOFile = false;
			            }
			            return this.EndOFile;
			        }

			xopenrecordset.prototype.MoveNext = function()
			        {
			            this.RecNo++;
			        }
			xopenrecordset.prototype.MoveFirst = function()
			        {
			            this.RecNo = 0;
			            //this.RecNo = this.xmlDoc.childNodes.length;
			        }
			xopenrecordset.prototype.MoveLast = function()
			        {
			            this.RecNo = this.xmlDoc.childNodes.length - 1;
			        }
            xopenrecordset.prototype.Fields = function(fldname)
                    {   
                        return this.xmlDoc.getElementsByTagName(fldname)[this.RecNo].childNodes[0].nodeValue;
                    }
                    
// number formatting function
// copyright Stephen Chapman 24th March 2006, 10th February 2007
// permission to use this function is granted provided
// that this copyright notice is retained intact
//num- value
//dec - number of decimal places 
//thou - The third parameter is the thousands separator.
//pnt - The fourth parameter is the decimal point. 
//      Either a period or comma is normal here. 
//The fifth and sixth parameters are used for monetary values 
//and one or other of them will contain the currency symbol 
//when required. If your location uses a currency symbol 
//hard against the left of numbers then place that symbol by 
//itself in the fifth parameter eg. '$'. 
//If you normally have a space after the currency symbol 
//then add it after the symbol in this '$ '. 
//If your currency symbol comes after the amount instead of 
//before then place it in the sixth parameter instead of the fifth parameter. 
//The seventh and eighth parameters define the symbols 
//to place around the number when the value is negative. 
//The usual values for these parameters would be '-','' 
//but you may have a situation where you want to use '(',')' or even '',' CR'. 

 //formatNumber(mynum,2,' ','.','','','-','') 
 //formatNumber(mynum,2,',','.','£ ','','',' CR') 

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2) 
{
    var x = Math.round(num * Math.pow(10,dec));
    if (x >= 0) n1=n2='';
    var y = (''+Math.abs(x)).split('');
    var z = y.length - dec; 
    if (z<0) z--; 
    for(var i = z; i < 0; i++) 
        y.unshift('0');y.splice(z, 0, pnt); 
        if(y[0] == pnt) y.unshift('0'); 
        while (z > 3) {z-=3; y.splice(z,0,thou);}
        var r = curr1+n1+y.join('')+n2+curr2;
        return r;
   }
   
   
   
/*
	Date Format 1.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT license
	With code by Scott Trenda (Z and o flags, and enhanced brevity)
*/

//var now = new Date();

//now.format("m/dd/yy");
// Returns, e.g., 6/09/07

// Can also be used as a standalone function
//dateFormat(now, "dddd, mmmm d, yyyy, h:MM:ss TT");
// Saturday, June 9, 2007, 5:46:21 PM

// You can use one of several named masks
//now.format("isoFullDateTime");
// 2007-06-09T17:46:21.431-0500

// ...Or add your own
//dateFormat.masks.hammerTime = 'HH:MM! "Can\'t touch this!"';
//now.format("hammerTime");
// 17:46! Can't touch this!

// When using the standalone dateFormat function,
// you can also provide the date as a string
//dateFormat("Jun 9 2007", "fullDate");
// Saturday, June 9, 2007

// Note that if you don't include the mask argument,
// dateFormat.masks.default is used
//now.format();
// Sat Jun 9 2007 17:46:21

// And if you don't include the date argument,
// the current date and time is used
//dateFormat();
// Sat Jun 9 2007 17:46:22

// Finally, you can skip the date argument (as long as your mask doesn't
// contain any numbers), in which case the current date/time is used
//dateFormat("longTime");
// 5:46:22 PM EST

/*** dateFormat
	Accepts a date, a mask, or a date and a mask.
	Returns a formatted version of the given date.
	The date defaults to the current date/time.
	The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}

//date add in Javascript
Date.prototype.add = function (sInterval, iNum){
  var dTemp = this;
  if (!sInterval || iNum == 0) return dTemp;
  switch (sInterval.toLowerCase()){
    case "ms":
      dTemp.setMilliseconds(dTemp.getMilliseconds() + iNum);
      break;
    case "s":
      dTemp.setSeconds(dTemp.getSeconds() + iNum);
      break;
    case "mi":
      dTemp.setMinutes(dTemp.getMinutes() + iNum);
      break;
    case "h":
      dTemp.setHours(dTemp.getHours() + iNum);
      break;
    case "d":
      dTemp.setDate(dTemp.getDate() + iNum);
      break;
    case "mo":
      dTemp.setMonth(dTemp.getMonth() + iNum);
      break;
    case "y":
      dTemp.setFullYear(dTemp.getFullYear() + iNum);
      break;
  }
  return dTemp;
}


function JStrim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function JSltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}
function JSrtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}
function JSReplaceBlank(stringtoReplace)
{
    var rep = /\s{1}/g;
    return stringtoReplace.replace(rep,"|");
}
function JSReplaceAll(stringtoReplace,replacechar,replacewithchar)
{
    return stringtoReplace.replace(replacechar,replacewithchar);
}
function JSIsDate(mystring)
{
    var mystring, myresult ;
    var mystring = new Date(mystring);
    isNaN(mystring)? myresult=false : myresult=true ;
    return myresult ;

}
function sgn(x){
  if(x>0)return 1;
  else if(x<0)return -1;
  else return 0;
}
function JSsqr(val) 
{ return val * val }

function JSPower3(val) 
{ return val * val * val }

function D2R(degrees)

{
    myresult = (Pi / 180) * degrees;
    return myresult ;

}
// convert from degrees to radians
function R2D(radians)
{

    myresult = (180 / Pi) * radians;
    return myresult;
}

// arc sine
// error if value is outside the range [-1,1]
function ASin(Value)
{

    if (Math.abs(Value) != 1) 
    {
        myresult = Math.atan(Value / Math.sqrt(1 - Value * Value));
    }
    else
    {
        myresult = 1.5707963267949 * sgn(Value);
   }
    return myresult;
}

// arc cosine
// error if NUMBER is outside the range [-1,1]
function ACos(number)
{

    if (Math.abs(number) != 1) 
    {
        myresult = 1.5707963267949 - Math.atan(number / Math.sqrt(1 - number * number));
    }
    else
    {
        if (number == -1) 
        {
            myresult = 3.14159265358979;
        }
    }
    return myresult;
    
    
}

// arc cotangent
// error if NUMBER is zero
function ACot(Value)
{

    myresult = Math.atan(1 / Value);
    return myresult;

}

// arc secant
// error if value is inside the range [-1,1]
function ASec(Value)
{
    // NOTE: the following lines can be replaced by a single call
   //           ASec = ACos(1 / value)
    if (Math.abs(Value) != 1)
    {
        myresult = 1.5707963267949 - Math.atan((1 / Value) / Math.sqrt(1 - 1 / (Value * Value)));
    }
    else
    {
        myresult = 3.14159265358979 * sgn(Value)
    }
    return myresult;
}

// arc cosecant
// error if value is inside the range [-1,1]
function ACsc(Value)
{

    // NOTE: the following lines can be replaced by a single call
    //           ACsc = ASin(1 / value)
    if (Math.abs(Value) != 1) 
    {
        myresult = Math.atan((1 / Value) / Math.sqrt(1 - 1 / (Value * Value)))
    }
    else
    {
        myresult = 1.5707963267949 * sgn(Value)
    }
    
}


//Operates like the if statement
function ssIF(testValue, trueValue,falseValue)
{
    if (testValue)
    {
        myresult = trueValue;
    }
    else
    {
        myresult = falseValue;
    }
     return myresult;
}

function JSOpenNewWindow(url,width,height,windowname) 
    {
     var width  = width;
     var height = height;
     var left   = (screen.width  - width)/2;
     var top    = (screen.height - height)/2;
     var params = 'width='+width+', height='+height;
     params += ', top='+top+', left='+left;
     params += ', directories=no';
     params += ', location=no';
     params += ', menubar=no';
     params += ', resizable=yes';
     params += ', scrollbars=no';
     params += ', status=no';
     params += ', toolbar=no';
     newwin=window.open(url,windowname, params);
     if (window.focus) {newwin.focus()}
     return false;
    }

function JSOpenNewWindowWithScroll(url,width,height,windowname) 
    {
     var width  = width;
     var height = height;
     var left   = (screen.width  - width)/2;
     var top    = (screen.height - height)/2;
     var params = 'width='+width+', height='+height;
     params += ', top='+top+', left='+left;
     params += ', directories=no';
     params += ', location=no';
     params += ', menubar=no';
     params += ', resizable=yes';
     params += ', scrollbars=yes';
     params += ', status=no';
     params += ', toolbar=no';
     newwin=window.open(url,windowname, params);
     if (window.focus) {newwin.focus()}
     return false;
    }

  
function CheckPlatePartOld (PartNo) {

var str=PartNo.replace(/X/gi,"x");
var xcount = 0;
var partokay="yes";
for (var j=0; j < str.length-1; ++j) {
	if (str.substring(j,j+1)=="x") {
		xcount=xcount + 1
	}
}

if (str.substring(0,4)!="RSPL" || xcount != 3  || str.indexOf("GR") == -1) {
	partokay="no";
	alert ("Needs RSPL, two dimensions(x) & GR"+'\n'+"Like this: RSPL9/16xWxLx572GR65"
	+'\n'+"Where W is width and L is Length");
	}
	else {
	var PType = str.substring(0,4);
	var Thick = str.slice(str.indexOf(PType)+4,str.indexOf("x"));
	var Length = str.substring(str.indexOf('x',str.indexOf('x')+1)+1,str.indexOf("GR")-4);
	var Width = str.slice(str.indexOf("x")+1,str.indexOf('x',str.indexOf('x')+1));
	var Grade = str.substring(str.length-2,str.length);
	var MType = str.substring(str.indexOf("GR")-3,str.indexOf("GR"));
	partokay = Length + ',' + Width + ',' + Thick;
	if (PartNo.length > 24)
	{
	    alert ("Plate number cannot be greater then 24 Characters.");
		partokay="no";
	}
	else if (Width.indexOf(".") != -1)
	{
	    alert ("Width has to be a Whole Number.");
		partokay="no";
	}
	else if (Length.indexOf(".") != -1)
	{
	    alert ("Length has to be a Whole Number.");
		partokay="no";
	}
	else
	{
	    if (Thick.length > 5) {
		    alert ("Thickness cannot be more than 2 significant digits");
		    partokay="no";
		    }
		    else {
		    var numerator=Thick.substring(0,Thick.indexOf("/"));
		    var denominator = Thick.substring(Thick.indexOf("/")+1);
			    if (isNaN(numerator)|| isNaN(denominator)) {
				    alert ("Fraction Not Numeric");
				    partokay="no";
			    }
			    else 
			    if (eval(numerator) > eval(denominator)) {
			    alert ("Numerator must be less than denominator");
			    partokay="no";
			    }
		    }
    }
	}
    return partokay;
}

function GetPlateThickness(PartNo)
{
    var str=PartNo.replace(/X/gi,"x");
    var PType = str.substring(0,4);
    var Thick = str.slice(str.indexOf(PType)+4,str.indexOf("x"));
    return Thick;
}

function CheckPlatePart (PartNo) {

var str=PartNo.replace(/X/gi,"x");
var xcount = 0;
var partokay="yes";
for (var j=0; j < str.length-1; ++j) {
	if (str.substring(j,j+1)=="x") {
		xcount=xcount + 1
	}
}

if (str.substring(0,4)!="RSPL" || xcount != 2) {
	partokay="no";
	alert ("Needs RSPL, two dimensions(x) & MaterialID"+'\n'+"Like this: RSPL9/16xWxLM"
	+'\n'+"Where W is width and L is Length and M is MaterialID");
	}
	else {
	var PType = str.substring(0,4);
	var Thick = str.slice(str.indexOf(PType)+4,str.indexOf("x"));
	var LengthLen = (str.indexOf('x',str.indexOf('x')+1)+1) + (str.length - (str.indexOf('x',str.indexOf('x')+1)+1)) - 1
	var Length = str.substring(str.indexOf('x',str.indexOf('x')+1)+1,LengthLen);
	var Width = str.slice(str.indexOf("x")+1,str.indexOf('x',str.indexOf('x')+1));
	var Grade = str.substring(str.length-2,str.length);
	var MType = str.substring(str.indexOf("GR")-3,str.indexOf("GR"));
	partokay = Length + ',' + Width + ',' + Thick;
	if (PartNo.length > 24)
	{
	    alert ("Plate number cannot be greater then 24 Characters.");
		partokay="no";
	}
	else if (Width.indexOf(".") != -1)
	{
	    alert ("Width has to be a Whole Number.");
		partokay="no";
	}
	else if (Length.indexOf(".") != -1)
	{
	    alert ("Length has to be a Whole Number.");
		partokay="no";
	}
	else
	{
	    if (Thick.length > 5) {
		    alert ("Thickness cannot be more than 2 significant digits");
		    partokay="no";
		    }
		    else {
		    var numerator=Thick.substring(0,Thick.indexOf("/"));
		    var denominator = Thick.substring(Thick.indexOf("/")+1);
			    if (isNaN(numerator)|| isNaN(denominator)) {
				    alert ("Fraction Not Numeric");
				    partokay="no";
			    }
			    else 
			    if (eval(numerator) > eval(denominator)) {
			    alert ("Numerator must be less than denominator");
			    partokay="no";
			    }
		    }
    }
	}
    return partokay;
}

function CheckGrade (Grade) {

var xcount = 0;
var Gradeokay="yes";
if (Grade.length < 7)
{
    Gradeokay="no"
	return Gradeokay;
}
var str=Grade.replace(/g/gi,"G");
var str=str.replace(/r/gi,"R");
for (var j=0; j < str.length-1; ++j) 
{
    if (j < 3 || j > 4)
    {
       if (isNaN(str.substring(j,j+1))) 
        {
		    Gradeokay="no"
		    break;
	    }
    }
	else
	{
	    if (j==3)
	    {
	        val = str.substring(j,j+1)
	        if (val != "G") 
	        {
	            Gradeokay="no"
		        break;
	        }
	   }
	   else
	   {
	      val = str.substring(j,j+1)
	        if (val != "R") 
	        {
	            Gradeokay="no"
		        break;
	        }
	   }
	    
	}
}

    
    return Gradeokay;
}


var STR_PAD_LEFT = 1;
var STR_PAD_RIGHT = 2;
var STR_PAD_BOTH = 3;

function pad(str, len, pad, dir) {

    if (typeof(len) == "undefined") { var len = 0; }
    if (typeof(pad) == "undefined") { var pad = ' '; }
    if (typeof(dir) == "undefined") { var dir = STR_PAD_RIGHT; }

    if (len + 1 >= str.length) {

        switch (dir){

            case STR_PAD_LEFT:
                str = Array(len + 1 - str.length).join(pad) + str;
            break;

            case STR_PAD_BOTH:
                var right = Math.ceil((padlen = len - str.length) / 2);
                var left = padlen - right;
                str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
            break;

            default:
                str = str + Array(len + 1 - str.length).join(pad);
            break;

        } // switch

    }

    return str;

}

function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

   function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

function isSignedInteger (s)

   {   if (isEmpty(s))
      if (isSignedInteger.arguments.length == 1) return false;
      else return (isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
         return (isInteger(s.substring(startPos, s.length), secondArg))
      }
   }

function isPositiveInteger (s)
   {   var secondArg = false;

       if (isPositiveInteger.arguments.length > 1)
          secondArg = isPositiveInteger.arguments[1];

       // The next line is a bit byzantine.  What it means is:
       // a) s must be a signed integer, AND
       // b) one of the following must be true:
       //    i)  s is empty and we are supposed to return true for
       //        empty strings
       //    ii) this is a positive, not negative, number

       return (isSignedInteger(s, secondArg)
          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
   }
// isIntegerInRange (STRING s, INTEGER a, INTEGER b)
   function isIntegerInRange (s, a, b)
   {   if (isEmpty(s))
         if (isIntegerInRange.arguments.length == 1) return false;
         else return (isIntegerInRange.arguments[1] == true);

      // Catch non-integer strings to avoid creating a NaN below,
      // which isn't available on JavaScript 1.0 for Windows.
      if (!isInteger(s, false)) return false;

      // Now, explicitly change the type to integer via parseInt
      // so that the comparison code below will work both on
      // JavaScript 1.2 (which typechecks in equality comparisons)
      // and JavaScript 1.1 and before (which doesn't).
      var num = parseInt (s);
      return ((num >= a) && (num <= b));
   }
   function JSLeft(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function JSRight(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function isDateJScript(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function validateDate(fieldVal)
{
  var isError = false
  fieldVal = JStrim(fieldVal);
  var datePat = /^(\d{1,2})(\/)(\d{1,2})\2(\d{4})$/;
  var datePatMonthDoubleDayDoubleYearDouble = /^(\d{1,2})(\/)(\d{1,2})\2(\d{2})$/;
  var datePatMonthDoubleDaySingleYearDouble = /^(\d{1,2})(\/)(\d{1,1})\2(\d{2})$/;
  var datePatMonthSingleDayDoubleYearDouble = /^(\d{1,1})(\/)(\d{1,2})\2(\d{2})$/;
  var datePatMonthDoubleDaySingleYearFour = /^(\d{1,2})(\/)(\d{1,1})\2(\d{4})$/;
  var datePatMonthSingleDayDoubleYearFour = /^(\d{1,1})(\/)(\d{1,2})\2(\d{4})$/;
  var datePatMonthSingleDaySingleYearFour = /^(\d{1,1})(\/)(\d{1,1})\2(\d{4})$/;
  var datePatMonthSingleDaySingle = /^(\d{1,1})(\/)(\d{1,1})$/;
  var datePatMonthDoubleDayDouble = /^(\d{1,2})(\/)(\d{1,2})$/;
  var datePatMonthDoubleDaySingle = /^(\d{1,2})(\/)(\d{1,1})$/;
  var datePatMonthSingleDayDouble = /^(\d{1,1})(\/)(\d{1,2})$/;
  var today = new Date();
  var matchArray = fieldVal.match(datePat); // is the format ok?
  if (matchArray == null) 
  {
    matchArray = fieldVal.match(datePatMonthSingleDaySingle)
    if (matchArray == null) 
    {
        matchArray = fieldVal.match(datePatMonthDoubleDayDouble)
        if (matchArray == null)
        {
            matchArray = fieldVal.match(datePatMonthDoubleDaySingle)
            if (matchArray == null)
            {
                matchArray = fieldVal.match(datePatMonthSingleDayDouble)
                if (matchArray == null)
                {
                    matchArray = fieldVal.match(datePatMonthDoubleDayDoubleYearDouble)
                    if (matchArray == null)
                    {
                        matchArray = fieldVal.match(datePatMonthDoubleDaySingleYearDouble)
                        if (matchArray == null)
                        {
                            matchArray = fieldVal.match(datePatMonthSingleDayDoubleYearDouble)
                            if (matchArray == null)
                            {
                                matchArray = fieldVal.match(datePatMonthDoubleDaySingleYearFour)
                                if (matchArray == null)
                                {
                                    matchArray = fieldVal.match(datePatMonthSingleDayDoubleYearFour)
                                    if (matchArray == null)
                                    {
                                        matchArray = fieldVal.match(datePatMonthSingleDaySingleYearFour)
                                        if (matchArray == null)
                                        {
                                            errMsg ='Date is not in a valid format.\nUse the mm/dd/yyyy format'
                                            isError=true
                                            fieldVal = "0"
                                            alert(errMsg)
                                            return fieldVal;
                                         }
                                    }
                                 }
                             }
                        }
                    }
                }
            }
            else
            {
                fieldVal = fieldVal + "\/"  + today.getFullYear();
            }
        }
        else
        {
           fieldVal = fieldVal + "\/"  + today.getFullYear(); 
        }
     }
     else
     {
        fieldVal = fieldVal + "\/"  + today.getFullYear();
     }
  }
 
  month = matchArray[1]; // parse date into variables
  day = matchArray[3];
  year = matchArray[4];
  if (month < 1 || month > 12)  // check month range
  { 
    errMsg ='Month must be between 1 and 12.'
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;

  }
  if (day < 1 || day > 31) 
  {
    errMsg ='Day must be between 1 and 31.'
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;

  }
  
  selectedDate = new Date(fieldVal)
  selectedDate = parseFloat(selectedDate.getMonth()) + 1 + "\/"  + selectedDate.getDate() + "\/" + selectedDate.getFullYear()
  selectedDate = new Date(selectedDate)
  if (selectedDate.getFullYear()  < 1950)
  {
     selectedDate = parseFloat(selectedDate.getMonth()) + 1 + "\/"  + selectedDate.getDate() + "\/" + (parseFloat(selectedDate.getFullYear()) + 100)
     selectedDate = new Date(selectedDate)
  }
  fieldVal = dateFormat(selectedDate,"mm/dd/yyyy");
  
  var matchArray = fieldVal.match(datePat)
  if (matchArray == null) 
  {
    errMsg = "Invalid date"
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;
  }
  month = matchArray[1]; // parse date into variables
  day = matchArray[3];
  year = matchArray[4];
  //alert(year);
  //alert(year.length);
  if (year.length == 4)
  {
    if (year < 1753)//dates less than January 1 1753 cause an exception in sql server
    {
    errMsg = "Year must be greater than 1752";
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;
    }
  }
  if (year.length == 3)
  {
    errMsg = "Year must two or four digits.";
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;

  }
  if (month < 1 || month > 12)  // check month range
  { 
    errMsg ='Month must be between 1 and 12.'
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;

  }
  if (day < 1 || day > 31) 
  {
    errMsg ='Day must be between 1 and 31.'
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;

  }
  if ((month==4 || month==6 || month==9 || month==11) && day==31) 
  {
    errMsg ="Month "+month+" doesn't have 31 days!"
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;

  }
  if (month == 2)  // check for february 29th
  {
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day>29 || (day==29 && !isleap)) {
    errMsg = "February " + year + " doesn't have " + day + " days!";
    isError=true
    fieldVal = "0"
    alert(errMsg)
    return fieldVal;
  }
  
}
if (isError == true)
{
    alert(errMsg)
}
return fieldVal;  // date is valid
} 
 function OpenIndexWindow()
        {
            window.location="index.shtml";
        }