// This Hide function helps prevent a form submission cancelation by hiding the form before it's submited
function Hide(ID){setTimeout("document.getElementById('"+ID+"').style.display='none'",200)}

// This Show function makes idems visible after the hide function is done
function Show(ID){setTimeout("document.getElementById('"+ID+"').style.display=''",300)}

var req;
function Load_XMLHttpRequest(url, Div, Frame, Parent) {

   // Internet Explorer
   try { req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { req = null; }
   }

   // Mozailla/Safari
   if (!req && typeof XMLHttpRequest != "undefined") { req = new XMLHttpRequest(); }

   // Call the processChange() function when the page has loaded
   if (req != null) {
   		// Load data into the requested div
		req.onreadystatechange = function processChange() {

			// The page has loaded and the HTTP status code is 200 OK
			if (req.readyState == 4 && req.status == 200) {

				// Write the contents of this URL to the parent.frame/div
				if(Parent){
					if(Parent.length>0){
						parent.frames['Frame_'+Div].document.getElementById('Div_'+Div).innerHTML = req.responseText;
					}
				}

				// Write the contents of this URL to the frame/div
				else if(Frame){
					//frames[Frame].document.getElementById('Div_'+Div).innerHTML = req.responseText;
					frames['Frame_'+Div].document.getElementById('Div_'+Div).innerHTML = req.responseText;
				}

				// Write the contents of this URL to the div
				else{
				getObject(Div).innerHTML = req.responseText; }
			document.body.style.cursor='default'; }
		}
      req.open("GET", url, true);
      req.send(null);
   }
}

// getElementById for IE
function getObject(name) {
   var ns4 = (document.layers) ? true : false;
   var w3c = (document.getElementById) ? true : false;
   var ie4 = (document.all) ? true : false;

   if (ns4) return eval('document.' + name);
   if (w3c) return document.getElementById(name);
   if (ie4) return eval('document.all.' + name);
   return false;
}

// The Add_Delimiter and Add_Value functions
// work with the PHP Select_AJAX function
// They will populate a form input with either one
// value or a comma delimited set of values
function Add_Delimiter(Form, Field, Add, Form_ID){
	
	if(document.forms[Form].elements[Field].value==''){
	document.forms[Form].elements[Field].value=Add;
	}

	else{
	var Value;
	Value=document.forms[Form].elements[Field].value;
	document.forms[Form].elements[Field].value=Value+', '+Add;
	}
return true;
}

function Add_Value(Form, Field, Add, Form_ID){
document.forms[Form].elements[Field].value=Add;
return true;
}

function Add_Delimiter_Blur(Form, Field, Form_ID){
/*	if(document.forms["Form_"+Field].elements["Field_"+Field].value!=''){
	var Add;
	Add=document.forms["Form_"+Field].elements["Field_"+Field].value;
		if(document.forms[Form].elements[Field].value==''){
		document.forms[Form].elements[Field].value=Add;}

		else{
		var Value;
		Value=document.forms[Form].elements[Field].value;
		document.forms[Form].elements[Field].value=Value+', '+Add;}
	}
return true;*/
}

function Add_Value_Blur(Form, Field, Form_ID){
	if(Form_ID){
		if(document.forms["Form_"+Field+"_"+Form_ID].elements["Field_"+Field].value!=''){
		var Add;
		Add=document.forms["Form_"+Field+"_"+Form_ID].elements["Field_"+Field].value;
		document.forms[Form].elements[Field].value=Add;}
	}
	else{
		if(document.forms["Form_"+Field].elements["Field_"+Field].value!=''){
		var Add;
		Add=document.forms["Form_"+Field].elements["Field_"+Field].value;
		document.forms[Form].elements[Field].value=Add;}
	}
return true;
}

function copy(text2copy) {
	if (window.clipboardData) {
	window.clipboardData.setData("Text",text2copy);}
	
	else {
	var flashcopier = 'flashcopier';
	  if(!document.getElementById(flashcopier)) {
	  var divholder = document.createElement('div');
	  divholder.id = flashcopier;
	  document.body.appendChild(divholder);}
	
	document.getElementById(flashcopier).innerHTML = '';
	var divinfo = '<embed src="/includes/00_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	document.getElementById(flashcopier).innerHTML = divinfo;}
}

function Clear(){
var i;
	for (i=0; (i<document.forms.length); i++){
		for (j=0; (j<document.forms[i].elements.length); j++){
		document.forms[i].elements[j].value='';}
	}
}

function Clear_Field(Relationship, Form, Field, Timer){
	if(Relationship){
	setTimeout(Relationship+'.document.forms[Form].elements[Field].value=\'\'', Timer);}
	else{
	setTimeout('document.forms[Form].elements[Field].value=\'\'', Timer);}
}

function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;}


function CheckIsIE(){
	if(navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER'){return true;}
	else{return false;}
}

function Print_iFrame(Target_iFrame){
	if(CheckIsIE() == true){
	document.Target_iFrame.focus();
	document.Target_iFrame.print();}

	else{
	window.frames[Target_iFrame].focus();
	window.frames[Target_iFrame].print();} 
}

// This code is a drag feature of the Chat module

//Checking browser
var isIE = document.all?true:false;

function Chat_Move(){document.getElementById('Div_Chat').active=true;}
function Chat_Stop(){document.getElementById('Div_Chat').active=false;
	document.getElementById('Div_Dim_Screen').style.display='none';}
function Chat_Drag(e){
	if(document.getElementById('Div_Chat').active){
	document.getElementById('Div_Dim_Screen').style.display='';
	var _x; var _y;

		//IEEE position
		if(!isIE){
		_x = e.screenX-285;
		_y = e.screenY-130;}

		//IE position
		if(isIE){
		_x = window.event.clientX;
		_y = window.event.clientY;}

	parent.document.getElementById('Div_Chat').style.left=_x+'px';
	parent.document.getElementById('Div_Chat').style.top=_y+'px';

	return true;}
}

var NULL; NULL="";

// Grow the textarea field as the content wraps
function Adjust_Size(oTextArea, Rows){
	if(navigator.appName.indexOf("Microsoft Internet Explorer")==0){
		return;
	}

	if(oTextArea.rows<Rows){
		while(oTextArea.scrollHeight > oTextArea.offsetHeight){
			oTextArea.rows++;
		}
	}
	else{
		document.Form_Expand_2.Details.style.overflow='visible';
	}
}
