function PrintThisPage() 
{ 
	var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
	sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 
	var sWinHTML = document.getElementById('contentstart').innerHTML; 
	var winprint=window.open("","",sOption); 
	winprint.document.open(); 
	winprint.document.write('<html><head>'); 
	winprint.document.write('<link rel="stylesheet" type="text/css" href="/util/style.css"><body>'); 
	sWinHTML = sWinHTML.replace(/bgcolor="#[0-9a-f]{6}"/gi,"");
	sWinHTML = sWinHTML.replace(/class=["|']sortable;["|']/gi,"");
	sWinHTML = sWinHTML.replace(/background-color:(\s+)rgb(.+);/gi,"");
	sWinHTML = sWinHTML.replace(/background-color:(\s+)\$settings\[(.+);(.+)>/gi,"");
	winprint.document.write(sWinHTML);          
	winprint.document.write('</body></html>'); 
	winprint.document.close(); 
	winprint.focus(); 
}



//////////////
var fieldTarget;
var pageTarget;
var fields; 
var opMode;
var fcount='1';
var tmp;


// page to use, 'extract' or 'process', div to update, fields to extract
function ajaxHandler(strURL, opMode, xtarget, fields) {
	fieldTarget = xtarget;
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatePage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getQueryString(fieldTarget, opMode, fields));
}
//////////////
function getQueryString(fieldTarget, opMode, fieldSources) {
	if(opMode=='extract'){

		// use list of form field IDs
		var sourceArray=fieldSources.split(":"); 
		for (var i in sourceArray ){
			tmp = document.getElementById(sourceArray[i]).value;

			if(fcount=='1'){
				var qstr = sourceArray[i] + '=' + escape(tmp); 
				fcount=2;
			}else{
				qstr = qstr + '&' + sourceArray[i] + '=' + escape(tmp); 
			}
		} 
	
	}else{
		// 	use supplied query string
		var qstr = fieldSources;
	}

	// reset counter
	fcount=1; 
    return qstr;

}
//////////////
function updatePage(str){
	// test for textarea/text or div/span/etc
	var ss = document.getElementById(fieldTarget).type;
	if(ss == 'textarea' || ss == 'text'){
		document.getElementById(fieldTarget).value = str;
	}else{
		document.getElementById(fieldTarget).innerHTML = str;
	}
}
//////////////


// ajhandler.js 
function xmlhttpPost(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}


// for Tracker Note field (month view) 
function xmlhttpPost_notes(strURL) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage_notes(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring_notes());
}



function getSelectedIndex(list){
   for(i=0; i<list.length; i++){
      if(list[ i].selected){
         return list[ i].value;
      }
   }
}

function setSelectedIndex(list, value){
   for(i=0; i<list.length; i++){
      if(list[ i].value == value){
         list.selectedIndex = i;
         break;
      }
   }
}

function getRadio(radio){   
   for(i=0; i<radio.length; i++){
      if(radio[i].checked){
         return(radio[i].value);
         break;
      }
   }
}

function setRadio(radio, value){
   for(i=0; i<radio.length; i++){
      if(radio[i].value == value){
         radio[i].checked = true;
      } else {
         radio[i].checked = false;
      }
   }
}


function SearchAndReplace(Content, SearchFor, ReplaceWith) {

   var tmpContent = Content;
   var tmpBefore = new String();   
   var tmpAfter = new String();
   var tmpOutput = new String();
   var intBefore = 0;
   var intAfter = 0;

   if (SearchFor.length == 0){
      return;
	}

   while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {
   
      // Get all content before the match
      intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
      tmpBefore = tmpContent.substring(0, intBefore);
      tmpOutput = tmpOutput + tmpBefore;

      // Get the string to replace
      tmpOutput = tmpOutput + ReplaceWith;


      // Get the rest of the content after the match until
      // the next match or the end of the content
      intAfter = tmpContent.length - SearchFor.length + 1;
      tmpContent = tmpContent.substring(intBefore + SearchFor.length);

   }

   return tmpOutput + tmpContent;

}