// 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 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;
   }
	 
	 	 //FORUM EDITOR
function addtag(tag,single) {
	var txt = document.getElementById('txtarea');
	if(document.selection) {
		txt.focus();
		sel = document.selection.createRange();
		if(single == true) {
			sel.text = '[' + tag + ']';
		} else {
		    sel.text = '[' + tag + ']' + sel.text + '[/' + tag + ']';
		}
	} else if(txt.selectionStart || txt.selectionStart == '0') {
		if(single == true) {
			txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		} else {
			txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
		}
	} else {
		if(single) {
			txt.value = '[' + tag + ']';
		} else {
			txt.value = '[' + tag + '][/' + tag + ']';
		}
	}
	return true;
}
function addurltag() {
	var txt = document.getElementById('txtarea');
	var link = prompt("Type the address:", "http://");
	if(link.length == 0 || link == "http://") {
		return;
	} else {
		var link = "=" + link;
		var text;
		var sel2 = "";
		if(document.selection) {
			txt.focus();
			sel = document.selection.createRange();
			sel2 = sel.text;
		} else if(txt.selectionStart || txt.selectionStart == '0') {
			sel2 = (txt.value).substring(txt.selectionStart, txt.selectionEnd);
		}
		if(sel2.length > 0) {
			text = sel2;
		} else {
			text = prompt("Enter the link text:", "");
		}
	}
	if(document.selection) {
		txt.focus();
		sel = document.selection.createRange();
		sel.text = "[url" + link + "]" + text + "[/url]";
	} else {
		txt.value = (txt.value).substring(0, txt.selectionStart) + "[url" + link + "]" + text + "[/url]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
	}
	return;
}
function doImage()
{
var textarea = document.getElementById('txtarea');
var url = prompt('Enter the Image URL:','http://');

	if (document.selection) 
			{
				textarea.focus();
				var sel = document.selection.createRange();
				sel.text = '[img]' + url + '[/img]';
			}
   else 
    {
		var len = textarea.value.length;
	    var start = textarea.selectionStart;
		var end = textarea.selectionEnd;
		
        var sel = textarea.value.substring(start, end);
	    //alert(sel);
		var rep = '[img]' + url + '[/img]';
        textarea.value =  textarea.value.substring(0,start) + rep + textarea.value.substring(end,len);
	}

}
function addvaluetag(sValue,tag) {
	if(sValue=="") {
		return;
	}
	var txt = document.getElementById('txtarea');
	if(document.selection) {
		txt.focus();
		sel = document.selection.createRange();
		sel.text = '["+tag+"=' + sValue + ']' + sel.text + '[/"+tag+"]';
	} else if(txt.selectionStart || txt.selectionStart == '0') {	
		txt.value = (txt.value).substring(0, txt.selectionStart) + "["+tag+"="+sValue+"]" + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + "[/"+tag+"]" + (txt.value).substring(txt.selectionEnd, txt.textLength);
	} else {
		txt.value = '["+tag+"=' + sValue + '][/"+tag+"]';
	}
	return;
}

function open_window(id,set,pid,url){ 
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;	

	if (navigator.appName.indexOf("Microsoft")!=-1) {
	  	 winW = document.body.offsetWidth;
	   	 winH = document.body.scrollHeight;
	 }
	 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth+ window.scrollMaxX;;
		  winH = window.innerHeight+ window.scrollMaxY;
	 }

	w.height=winH+"px";
	w.width=winW+"px";
	document.bgColor='#333333';
	width=(winW/2)-200;
	height=(winH/2)-150;
	Ajax_page('process.php?LP=articles.email&id='+id+'&set='+set+'&pid='+pid+'&url='+url,'window2');
	w2.top=height+'px';
	w2.left=width+'px';
	w2.display='block';
	w.display='block';
}

function report_window(id,set,pid){ 
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;	

	if (navigator.appName.indexOf("Microsoft")!=-1) {
	  	 winW = document.body.offsetWidth;
	   	 winH = document.body.scrollHeight;
	 }
	 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth+ window.scrollMaxX;;
		  winH = window.innerHeight+ window.scrollMaxY;
	 }

	w.height=winH+"px";
	w.width=winW+"px";
	document.bgColor='#333333';
	width=(winW/2)-200;
	height=(winH/2)-150;
	Ajax_page('process.php?LP=articles.abuse&id='+id+'&set='+set+'&pid='+pid,'window2');
	w2.top=height+'px';
	w2.left=width+'px';
	w2.display='block';
	w.display='block';
}

function edit_question(id,set,pid){ 
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;	

	if (navigator.appName.indexOf("Microsoft")!=-1) {
	  	 winW = document.body.offsetWidth;
	   	 winH = document.body.scrollHeight;
	 }
	 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth+ window.scrollMaxX;;
		  winH = window.innerHeight+ window.scrollMaxY;
	 }

	w.height=winH+"px";
	w.width=winW+"px";
	document.bgColor='#333333';
	width=(winW/2)-200;
	height=(winH/2)-150;
	Ajax_page('process.php?LP=my_profile.questions_edit&id='+id+'&set='+set+'&pid='+pid,'window2');
	w2.top=height+'px';
	w2.left=width+'px';
	w2.display='block';
	w.display='block';
}

function cancel_appointment(id,set,pid){ 
	var stat = encodeURI( document.getElementById("stat").value ); 
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;	

	if (navigator.appName.indexOf("Microsoft")!=-1) {
	  	 winW = document.body.offsetWidth;
	   	 winH = document.body.scrollHeight;
	 }
	 if (navigator.appName=="Netscape") {
		  winW = window.innerWidth+ window.scrollMaxX;;
		  winH = window.innerHeight+ window.scrollMaxY;
	 }

	w.height=winH+"px";
	w.width=winW+"px";
	document.bgColor='#333333';
	width=(winW/2)-200;
	height=(winH/2)-150;
	Ajax_page('process.php?LP=my_profile.cancel_drappointment&id='+id+'&set='+set+'&pid='+pid+'&stat='+stat,'window2');
	w2.top=height+'px';
	w2.left=width+'px';
	w2.display='block';
	w.display='block';
}

function close_window(set){    	
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;
	document.bgColor='#CCCCCC';
	w.display='none';
	w2.display='none';
}

function close_window2(set){    	
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;
	document.bgColor='#CCCCCC';
	w.display='none';
	w2.display='none';
	window.location.reload();
}

function close_cancellation(set,mo,da,yr){
	var w=document.getElementById("window").style;
	var w2=document.getElementById("window2").style;
	document.bgColor='#CCCCCC';
	w.display='none';
	w2.display='none';
	window.location.href='module.php?LM=my_profile.calendar&month='+mo+'&day='+da+'&year='+yr;
}

function send_email(target){
 var poststr = "name=" + encodeURI( document.getElementById("name").value )
  + "&email=" + encodeURI( document.getElementById("email").value )
  + "&f_email=" + encodeURI( document.getElementById("f_email").value )
  + "&message=" + encodeURI( document.getElementById("message").value )
  + "&id=" + encodeURI( document.getElementById("id").value )
  + "&set=" + encodeURI( document.getElementById("set").value ) 
  + "&pid=" + encodeURI( document.getElementById("pid").value )
  + "&url=" + encodeURI( document.getElementById("url").value ); 
  
  makePOSTRequest('process.php?LP=articles.email', poststr,target);
}

function send_report(target){
 var poststr = "name=" + encodeURI( document.getElementById("name").value )
  + "&email=" + encodeURI( document.getElementById("email").value )
  + "&message=" + encodeURI( document.getElementById("message").value )
  + "&id=" + encodeURI( document.getElementById("id").value )
  + "&set=" + encodeURI( document.getElementById("set").value ) 
  + "&pid=" + encodeURI( document.getElementById("pid").value ); 
  
  makePOSTRequest('process.php?LP=articles.abuse', poststr,target);
}

function send_question(target){
 var poststr = "&message=" + encodeURI( document.getElementById("message").value )
  + "&categ=" + encodeURI( document.getElementById("categ").value )
  + "&id=" + encodeURI( document.getElementById("id").value )
  + "&set=" + encodeURI( document.getElementById("set").value ) 
  + "&pid=" + encodeURI( document.getElementById("pid").value ); 
  
  makePOSTRequest('process.php?LP=my_profile.questions_edit', poststr,target);
}

function send_cancel(target){
 var poststr = "&reason=" + encodeURI( document.getElementById("reason").value )
  + "&id=" + encodeURI( document.getElementById("id").value )
  + "&set=" + encodeURI( document.getElementById("set").value ) 
  + "&pid=" + encodeURI( document.getElementById("pid").value )
  + "&stat=" + encodeURI( document.getElementById("stat").value )
  + "&mode=" + encodeURI( document.getElementById("mode").value ); 
  
  makePOSTRequest('process.php?LP=my_profile.cancel_drappointment', poststr,target);
}


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.');
	 }
  }
}

//-->
