// 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) {
      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 = alertContents;
      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() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
       //     document.getElementById('myspan').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;
   }

// Main Navigation

var intervals=15;
var num_links=17;
var total_links=30;
var move=0;	
function animate(id){
	var dc = document.getElementById('l'+id).style;
	var dl1 = document.getElementById('l'+(id-1));
	var dl2 = document.getElementById('l'+(id-2));
	var dl3 = document.getElementById('l'+(id-3));
	var dr1 = document.getElementById('l'+(id+1));
	var dr2 = document.getElementById('l'+(id+2));
	var dr3 = document.getElementById('l'+(id+3));

//	scroll animation controls
	var frame = document.getElementById('frame').style;	

	link_top=Math.round(((parseInt(frame.top)-(parseInt(frame.top)*2))/intervals),1);
	link_bot=(link_top+num_links);
	// move up

		if(id<(link_top+4)){
			if(move){
				clearInterval(move);
			}
			move = setInterval("move_pos('down')",60);		
		} else if(id>(link_bot-4)){
			if(move){
				clearInterval(move);
			}
			move = setInterval("move_pos('up')",60);		
		} else {
			if(move){
				clearInterval(move);
			}
		}
		

	
	dc.fontSize='30px';
	dc.paddingLeft='5px';

	if(dl1){
		dl1.style.fontSize='18px';
		dl1.style.paddingLeft='4px'

	}
	if(dl2){
		dl2.style.fontSize='16px';
		dl2.style.paddingLeft='2px';

	}
	if(dl3){
		dl3.style.fontSize='14px';
		dl3.style.paddingLeft='0px';

	}
	if(dr3){
		dr3.style.fontSize='14px';
		dr3.style.paddingLeft='0px';

	}	
	if(dr2){
		dr2.style.fontSize='16px';
		dr2.style.paddingLeft='2px';

	}

	if(dr1){
		dr1.style.fontSize='18px';
		dr1.style.paddingLeft='4px';

	}
	deanimate(id);//load_animation(id);
}
function deanimate(id){
var el, n = 1;
	while (el = document.getElementById('l' + n++)){
		if((n!=id)&&(n!=(id-1))&&(n!=(id-2))&&(n!=(id-3))&&(n!=(id+1))&&(n!=(id+2))&&(n!=(id+3)))
		{
			if(parseInt(el.style.fontSize)>12)
			{
				el.style.fontSize = '14px';
				el.style.paddingLeft = '0px';

			}
		}
	}
return false;
}

function move_pos(pos){
	var frame = document.getElementById('frame').style;	
	
	tpx=((intervals*total_links)-((intervals*total_links)*2));
	px=(num_links*intervals)+tpx;
	
	if(pos=='up'&&parseInt(frame.top)>px){
		frame.top = (parseInt(frame.top)-5)+'px';
	} else if(pos=='down'&&parseInt(frame.top)<0) {
		frame.top = (parseInt(frame.top)+5)+'px';
	} else {
		clearInterval(move);
	}
}

//-->