function replace1(string,text,by)
 {
 // Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0))
		return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength)))
		return string;
    if (i == -1)
		return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
		newstr += replace1(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}


function y2k(number)
{
//Returns a 4 digit year 
  var t_year = parseInt(number, 10);
    if(t_year >= 1000 && t_year < 2000)
      	{
	 return t_year;
	} else if(t_year >= 100 && t_year < 1000) {
		t_year = 1900 + t_year;
	  } else {
	 	t_year = "" + ((t_year < 10) ? "200" + t_year : ((t_year >= 2000) ? t_year : (((t_year >= 50 && t_year < 100) ? "19" : "20") + t_year)));
		   }
   return (parseInt(t_year, 10));
}


function twoDigFixer(number) {
//fixes dates, etc.  if number passed is 1 digit, it cleans it up,& returns a 2 digit string 
//good for months, days, etc.


	(number<10)?number="0"+number.toString():number=number.toString();

	
	return number;
}

function jsPrintCurrYear(){
    thisday = new Date();
   document.write( thisday.getFullYear());
}

//CREATE DATE OBJECT PROTOTYPES
Date.prototype.getFullYear = getFullYear;
Date.prototype.getActualMonth = getActualMonth;
Date.prototype.getActualDay = getActualDay;
Date.prototype.getCalendarDay = getCalendarDay;
Date.prototype.getCalendarMonth = getCalendarMonth;

function getFullYear() {
	var n = y2k(this.getYear());
	return n;
	}

function getActualMonth() {
	var n = this.getMonth();
	n += 1;
	return n;
	}

function getActualDay() {
	var n = this.getDay();
	n += 1;
	return n;
	}

function getCalendarDay() {
	var n = this.getDay();
	var dow = new Array(7);
	dow[0] = "Sunday";
	dow[1] = "Monday";
	dow[2] = "Tuesday";
	dow[3] = "Wednesday";
	dow[4] = "Thursday";
	dow[5] = "Friday";
	dow[6] = "Saturday";
	return dow[n];
	}

function getCalendarMonth() {
	var n = this.getMonth();
	var moy = new Array(12);
	moy[0] = "January";
	moy[1] = "February";
	moy[2] = "March";
	moy[3] = "April";
	moy[4] = "May";
	moy[5] = "June";
	moy[6] = "July";
	moy[7] = "August";
	moy[8] = "September";
	moy[9] = "October";
	moy[10] = "November";
	moy[11] = "December";
	return moy[n];
	}
//END DATE OBJECT PROTOTYPES

function openNewWindow (url, name, width, height, toolbar, menubar, scrollbars, resizable, status, location, alwaysRaised, top, left) {

        var defaultWidth = 600;
        var defaultHeight = 400;
        var defaultTop = 50;
        var defaultLeft = 50;

//for (i = 0; i < openNewWindow.arguments.length; i++ ) {strn += openNewWindow.arguments[i] +'\n';}
//for (r in document.all) {strn += 'I: '+r+' VAL: '+document.all[r].name+'     ';}
 strn =  "width="+width+",height="+ height+",toolbar="+ toolbar+",menubar="+ menubar+",scrollbars="+ scrollbars +",resizable="+ resizable+",status="+ status+",location="+ location+",alwaysRaised="+ alwaysRaised+",top="+top+",left="+ left;
//alert("BEF: "+strn);

//set values to default, if value is undefined

	for (i in openNewWindow) {
	   if (openNewWindow[i] != '0') {
       		 if ((i == 'height') && (!openNewWindow[i])) {openNewWindow[i] = defaultHeight;}
       		 if ((i == 'width') && (!openNewWindow[i])) {openNewWindow[i] = defaultWidth;}
       		 if ((i == 'top') && (!openNewWindow[i])) {openNewWindow[i] = defaultTop;}
       		 if ((i == 'left') && (!openNewWindow[i])) {openNewWindow[i] = defaultLeft;}
       		 if ((i == 'alwaysRaised') && (!openNewWindow[i])) {openNewWindow[i] = '0';}
       		 if (!openNewWindow[i]) {openNewWindow[i] = '1';}
	  }//if (openNew...
	}//end for(i in ....

 strWin =  "width="+width+",height="+ height+",toolbar="+ toolbar+",menubar="+ menubar+",scrollbars="+ scrollbars +",resizable="+ resizable+",status="+ status+",location="+ location+",alwaysRaised="+ alwaysRaised+",top="+top+",left="+ left;
//alert(strn);
//alert("WIN: "+strWin);

newWindow= window.open (url, name, strWin)

}//end openNewWindow


function blankNull(str)
{
  if (str==null) { return ''; }
    else if (str=='null') { return ''; }
    else if (str=='Null') { return ''; }
    else if (str=='NULL') { return ''; }
  return str;
}


function WindowClose(){
    window.close();
}



//loads a css or js file if needed, programatically
function loadjscssfile(filename, filetype) {
    if (filetype == "js") { //if filename is a external JavaScript file
        var fileref = document.createElement('script')
        fileref.setAttribute("type", "text/javascript")
        fileref.setAttribute("src", filename)
    }
    else if (filetype == "css") { //if filename is an external CSS file
        var fileref = document.createElement("link")
        fileref.setAttribute("rel", "stylesheet")
        fileref.setAttribute("type", "text/css")
        fileref.setAttribute("href", filename)
    }
    if (typeof fileref != "undefined")
        document.getElementsByTagName("head")[0].appendChild(fileref)
}



function goback() {
    history.go(-1);
}

function printit() {
    parent.acsframe.focus();
    parent.acsframe.print();
}
