// +------------------------------------------------------------------------+
// |						Warez-M-Me  v 1.0                               |
// +------------------------------------------------------------------------+
// | Copyright (c) Yuksel Kurtbas 2002-2006. All rights reserved.           |
// | Version       1.0                                                      |
// | Last modified 26/09/2006                                               |
// | Email         pro@gnuturk.com                                          |
// | Web           http://www.gnuturk.com      							    |
// +------------------------------------------------------------------------+
AjaxPtt = function (Url, method) {
	this.url = Url;
	this.method = method;
	this.onStart = null;
	this.onComplete = null;
	this.xmlHttp = null;
	this.vars = '';
	this.resultel = null;
	this.type = 'H';
};
// -----------------------------------------------------------------
AjaxPtt.prototype.createXmlHttp = function (){	
  var xmlHttp;
  if(window.ActiveXObject)  {
    try {  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch (e) { xmlHttp = false; }
  } else {
    try  { xmlHttp = new XMLHttpRequest(); }
    catch (e) { xmlHttp = false; }
  }
  if (!xmlHttp) 
    alert("Error creating the XMLHttpRequest object");
  else 
    this.xmlHttp = xmlHttp;
};
// -----------------------------------------------------------------
AjaxPtt.prototype.Post = function () {
	var oThis = this;
	this.createXmlHttp();
	this.onStart();
	this.xmlHttp.open( this.method, this.url, true );  
	this.xmlHttp.setRequestHeader('Content-Type',
								 'application/x-www-form-urlencoded; charset=utf-8'
								  );
    this.xmlHttp.onreadystatechange = function() {
		if (oThis.xmlHttp.readyState == 4 && oThis.xmlHttp.status == 200){
			oThis.onComplete();
			if( oThis.type == 'X'){
				var XMLDOC	= oThis.xmlHttp.responseXML.documentElement;
				var Result	= XMLDOC.getElementsByTagName('result')[0].firstChild.data;
				var Message	= XMLDOC.getElementsByTagName('message')[0].firstChild.data;
				Message	= Message.replace(/%26/ig, '&');
				switch( Result )
				{
					case 'E': alert(Message); break;
					case 'H': document.getElementById( oThis.resultel ).innerHTML = Message; break;
					case 'J': eval(Message); break;
					case 'D': document.getElementById( oThis.resultel ).innerHTML = Message;break;
					default : alert('Unknown Handle Type'); break;
				}
			} else {
				var Message = oThis.xmlHttp.responseText.replace(/%26/ig, '&');
				document.getElementById( oThis.resultel ).innerHTML = Message;
			}
		}
	};
	this.xmlHttp.send(this.vars);
};	
// -----------------------------------------------------------------
AjaxPtt.prototype.setVariable = function (name, variable) {
	this[name]= variable;
};
// -----------------------------------------------------------------
AjaxPtt.prototype.getVars = function (vars){
	var RET = '';
	for(var i=0; i<vars.length; i++){
		if(i==0)	RET += vars[i] 		+ "=" + this.prePost(vars[i]);
		else 		RET += "&"+ vars[i] + "=" + this.prePost(vars[i]);
	}
	this.vars = RET;
};
// -----------------------------------------------------------------
AjaxPtt.prototype.prePost = function (el){ 
	ob = document.getElementById( el ).value;
	return ob.replace(/&/ig,"%26");
};
// -----------------------------------------------------------------
