// JavaScript Document
<!--//
function Ajax_load_page(url, target) {
  document.getElementById(target).innerHTML = '';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {Ajax_load_page_Done(url, target);};
    req.open("GET", url, true);
    req.send("");
  }
}  

function Ajax_load_page_Done(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML=" AHAH Error:\n"+ req.status + "\n" +req.statusText;
    }
  }
}

function Ajax_page(name, div) {
    Ajax_load_page(name,div);
    return false;
}

//	AJAX FUNCTION TO GET VALUE FROM PAGE INTO STRING
function Ajax_load_value(url) {
if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  req.open("GET", url, false);
  req.send("");
  return req.responseText;	
}  





//	SUBMIT FORM VIA AJAX
   function makePOSTRequest(url, parameters,target) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }

      http_request.onreadystatechange = function(){alertContents(target);};
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);

   }

   function alertContents(div) {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById(div).innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj,objid) {
	   var message=document.getElementById("message"+objid).value;
      var poststr = "message=" + encodeURI( document.getElementById("message"+objid).value )
	  + "&toid=" + encodeURI( document.getElementById("toid"+objid).value )
	  + "&touser=" + encodeURI( document.getElementById("touser"+objid).value )
	  + "&fromuser=" + encodeURI( document.getElementById("fromuser"+objid).value )
	  + "&chatid=" + encodeURI( document.getElementById("chatid"+objid).value )
	  + "&fromid=" + encodeURI( document.getElementById("fromid"+objid).value );
      if(message)
	  makePOSTRequest('writer.php', poststr);
	  send(objid);
   }

function show(id){
	var div=document.getElementById(id);
	div.innerHTML=Ajax_load_value("sub_navigator.php?id="+id,id);
	var ids=Ajax_load_value("sub_navigator.php?id="+id+"&tree=true");
		id=ids.split("-");
		for(var obj in id){
			if(id[obj]){
				show(id[obj]);
			}
		}	
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

//	javascript functions
function replaceSubstring (inputString, badString, goodString, caseSensitive) {
  fixedReplace = "";
  UI = inputString;
  UB = badString;
  if ((caseSensitive != 1) && (caseSensitive != true)) {
  UI = inputString.toUpperCase();
     UB = badString.toUpperCase();
     }
  badEnd = -1;
  badLoc = UI.indexOf(UB);
  if (badLoc != -1) {
     for (x=1; (badLoc != -1); x++) {
        fixedReplace = fixedReplace + 
                       inputString.substring((badEnd +
                       1), badLoc) + goodString
        badEnd = badLoc + UB.length - 1;
        badLoc = UI.indexOf(UB, (badLoc + 1)); }
     fixedReplace = fixedReplace + 
                    inputString.substring((badEnd + 1),
                    inputString.length); }
     else { fixedReplace = inputString;    }
return fixedReplace;
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

//	PNG fIX

var dhmax=200;		//	Expanded Height
var dhmin=25;		// collapsed height
var dur=20;			// Duration of movement


//	position the div horizontally
var div1w=90;		// Center div Referenced to the center window
var div2w=370;		// Left Div Referenced to the center window
var div3w=-110;		// Right Div Referenced to the center window


if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
		var dtopmax_adjust=580;//325; 	// Default top margin expanded	 
		var dtopmin_adjust=755;	// Default top margin collapsed	
	} else {
		var dtopmax_adjust=602;//325; 	// Default top margin expanded	 
		var dtopmin_adjust=776;	// Default top margin collapsed		
	}
}

function positionDIV(res){
//	position the divs
	var divw=(get_dimension('w')/2);
	var check_divs= false;
	var div1=document.getElementById('div1').style
	var div2=document.getElementById('div2').style
	var div3=document.getElementById('div3').style

	if(!res){
		div1.left=(divw-div1w)+'px';
		div2.left=(divw-div2w)+'px';
		div3.left=(divw-div3w)+'px';
	
		div1.height=dhmin+'px';
		div2.height=dhmin+'px';
		div3.height=dhmin+'px';
		
		div1.top=(dtopmin_adjust)+'px';
		div2.top=(dtopmin_adjust)+'px';
		div3.top=(dtopmin_adjust)+'px';
	} else {
		if(parseInt(div1.top)==dtopmin_adjust){
			check_divs= true;
		}
	}
	//	IF div is enabled do resize
	if(check_divs){
		div1.left=(divw-div1w)+'px';
		div2.left=(divw-div2w)+'px';
		div3.left=(divw-div3w)+'px';
	
		div1.height=dhmin+'px';
		div2.height=dhmin+'px';
		div3.height=dhmin+'px';
	}
	if(!res){
		div1.top=(dtopmin_adjust)+'px';
		div2.top=(dtopmin_adjust)+'px';
		div3.top=(dtopmin_adjust)+'px';
	}

}

function intervalup(div){
	divs=document.getElementById(div).style.height;
	if(parseInt(divs)<dhmax){
		slideup=setInterval("moveup('"+div+"')",10);
	} else {
		slidedown=setInterval("movedown('"+div+"')",10);
	}	
}

function moveup(object){
var div=document.getElementById(object).style;
var distance=parseInt(div.top);
var height=parseInt(div.height);
//	SWAP IMAGE

//	MOVE DIV UP
 if(height<dhmax){
 div.top=distance-dur+'px';
 div.height=height+dur+'px';
 } else {
 div.top=(dtopmax_adjust)+'px';
 div.height=dhmax+'px'; 
 clearInterval(slideup);
 }
}
function movedown(object){
var div=document.getElementById(object).style;
var distance=parseInt(div.top);
var height=parseInt(div.height);
//	SWAP IMAGE

//	MOVE DIV UP
 if(height>dhmin){
 div.top=distance+dur+'px';
 div.height=height-dur+'px';
 } else {
 div.top=(dtopmin_adjust)+'px';
 div.height=dhmin+'px'; 
 clearInterval(slidedown);
 }
}

function get_dimension(object){
	if (parseInt(navigator.appVersion)>3) {
	 if (navigator.appName=="Netscape") {
		  if(object=="w"){
		  return winW = window.innerWidth-16;
		  }	else {
		 // return winH = window.innerHeight-16 + window.scrollMaxY;
		  }
	 }
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	 	if(object=="w"){
	  	return winW = document.body.offsetWidth-20;
	  	}	else {
	   //	return winH = document.body.offsetHeight-25;
	  	}
		
	 }
	}
}
function png_fix(){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	
	if ((version >= 5.5) && (document.body.filters)) 
	{
	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText 
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
}	
function send_appointment(target){
      var poststr = "message=" + encodeURI( document.getElementById("message").value )
	  + "&email=" + encodeURI( document.getElementById("email").value )
	  + "&name=" + encodeURI( document.getElementById("name").value )
	  + "&year=" + encodeURI( document.getElementById("year").value )
	  + "&month=" + encodeURI( document.getElementById("month").value )
	  + "&day=" + encodeURI( document.getElementById("day").value )
	  + "&id=" + encodeURI( document.getElementById("id").value )
	  + "&set=" + encodeURI( document.getElementById("set").value );
	  makePOSTRequest('process.php?LP=directory.appointment', poststr,target);
	}

//-->