﻿/*
  xTrinal-Studio XMLHTTP Javascript - http://www.xtrinal.net
  Version 1.0 beta | Copyright 2007
*/
function XSAJAX(file) {
	this.xmlhttp = null;
  
	this.createAJAX = function() {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			try {
				this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				this.xmlhttp = null;
			}
		}

		if (! this.xmlhttp) {
			if (typeof XMLHttpRequest != "undefined") {
				this.xmlhttp = new XMLHttpRequest();
			} else {
				this.Failed = true;
			}
		}
	};
  
  this.checkDatas = function() {
    if (this.Failed) {
      return false;
    }
    if (! this.ContentID) {
      alert("Nem állítottad be a ContentID-t");
      return false;
    }
    if (! this.ErrorID) this.ErrorID = this.ConentID;
    if (! this.LoadingID) this.LoadingID = this.ContentID;
    if (! this.ErrorMSG) this.ErrorMSG = "A lekérés közben probléma merült fel. Hibakód: [ERROR]";
    if (! this.LoadingMSG) this.LoadingMSG = "Betöltés..";
    if (! this.Charset) this.Charset = "UTF-8";
    
    return true;
  };
 
  this.getQueryString = function(form) {
    var title, content;
    form = document.forms[form];
    for (i=0; form.elements[i]; i++) {
      if (form.elements[i].type != "checkbox") {
        title = form.elements[i].name;
        content = form.elements[i].value;
        if (qstr) qstr += "&"+title+"="+escape(content);
        else var qstr = title+"="+escape(content);
      }
      else {
        if (form.elements[i].checked == true) {
          title = form.elements[i].name;
          content = form.elements[i].value;
          if (! content) content = "on";
          if (qstr) qstr += "&"+title+"=on";
          else var qstr = title+"=on";
        }
      }
    }
    return qstr;
  };
 
  this.Get = function(method, url, form) {
    this.createAJAX();
    if (!this.checkDatas()) return false;
    if (form) {
      var data = this.getQueryString(form);
      if (method != "POST") url = url+"?"+data;
    }
    var self = this;
    this.xmlhttp.onreadystatechange = function() {
      if (self.xmlhttp.readyState == 4) { 
        if (self.xmlhttp.status == 200) {
          document.getElementById(self.ContentID).innerHTML = self.xmlhttp.responseText;
        }
        else if (self.xmlhttp.status != 0)
          self.getErrorContent(self.xmlhttp.status);
      }
      else if (self.xmlhttp.readyState > 0 && self.xmlhttp.readyState < 4) 
        self.getLoadingContent();
      return true;
    }
    this.xmlhttp.open(method, url, true);
    if (method == "POST") this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset="+this.Charset);
    this.xmlhttp.send(data);
  };
  
  this.getErrorContent = function(emsg) {
    document.getElementById(this.ErrorID).innerHTML = this.ErrorMSG.replace("[ERROR]", emsg);
  };
  
  this.getLoadingContent = function() {
    document.getElementById(this.LoadingID).innerHTML = this.LoadingMSG;
  };
  
  this.createAJAX();
}
function load(id){
  var site = new XSAJAX();
  site.ContentID = 'text';
  site.Get("GET", "index2.php?ajax=1&id="+id);
  return false;
}
function start() {
  document.write("Üdvözlöm!<br /><br />Ön Fekete György autószerelő oldalát látja. A fenti menük alapján navigálhatja az oldalt, balra lejjebb pedig az önéletrajzomat olvashatja.<br /><br />Üdvözlettel: Fekete György");
}