function send_form(p_form)
{
	var data = "";
	
	for (i in p_form.elements) {
		if (data.length > 0 && p_form.elements[i].name && p_form.elements[i].value) data += "&";
		if (p_form.elements[i].name && p_form.elements[i].value) {
			data += escape(p_form.elements[i].name) + "=" + escape(p_form.elements[i].value);
		}
	}

	senddata_ajax(p_form.action, data, function (response) {
		alert(response);
	});
	
	return false;
}

function senddata_ajax(p_url, p_data, p_callback)
{
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) { http_request.overrideMimeType('text/html'); }
	} else if (window.ActiveXObject) {
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	
	if (!http_request) { return true; }
	
	http_request.onreadystatechange = function checkforresults () {
		if (this.readyState == 4 && this.status == 200) {
			p_callback(this.responseText);
		}
	};
	
	/*
	if (p_form && document.getElementById(p_form.name + "_loadicon")) {
		document.getElementById(p_form.name + "_loadicon").style.display = "inline";
	}
	*/
	/*
	var boundary = '---------------------------';
	boundary += Math.floor(Math.random()*32768);
	boundary += Math.floor(Math.random()*32768);
	boundary += Math.floor(Math.random()*32768);
	
	var body = '';
	body += 'Content-Type: multipart/form-data; boundary=' + boundary;
	//body += '\r\nContent-length: '+body.length;
	body += '\r\n\r\n--' + boundary + '\r\n' + 'Content-Disposition: form-data; name="';
	body += 'myfile"; filename="'+file.fileName+'" \r\n';
	body += "Content-Type: "+file.type;
	body += '\r\n\r\n';
	body += file.getAsBinary();
	body += '\r\n';
	body += '--' + boundary + '\r\n' + 'Content-Disposition: form-data; name="submitBtn"\r\n\r\nUpload\r\n';
	body += '--' + boundary + '--';
	*/
	http_request.open('POST', p_url, true);
	//http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	//http_request.setRequestHeader("Content-type", "multipart/form-data; boundary=" + boundary);
	//http_request.setRequestHeader('Content-length', body.length);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.send(p_data);

	return true;
}

function inserTextAreaAt(myField, myValue) {
	if (document.selection) {
		sel = document.selection.createRange();
		sel.text = myValue;
	} else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
		myField.selectionStart = startPos + myValue.length;
		myField.selectionEnd = startPos + myValue.length;
	} else {
		myField.value += myValue;
	}
}

if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
    var len = this.length >>> 0;

    var from = Number(arguments[1]) || 0;
    from = (from < 0)
         ? Math.ceil(from)
         : Math.floor(from);
    if (from < 0)
      from += len;

    for (; from < len; from++)
    {
      if (from in this &&
          this[from] === elt)
        return from;
    }
    return -1;
  };
}

/*
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
};
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
};
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
};
*/
function trim(p_string) {
	alert(p_string);
	return p_string.replace(/^\s+|\s+$/g,"");
}

function removenod(p_nod) {
	if (typeof p_nod == "object") {
		for (i in p_nod) {
			try {
				p_nod[i].parentNode.removeChild(p_nod[i]);
			} catch(e) {}
		}
	} else {
		p_nod.parentNode.removeChild(p_nod);
	}
}
