
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
	}
	return[scrOfX,scrOfY];
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

var ToArray = {
  version: '1.0',
 
  str2array: function (string, separator) {
        var temp = new Array();
        temp = string.split(separator);
        return temp;
    },
  
  isOnlyWhiteString: function (value) {
    var re = new RegExp("^[\n\r\t ]{1,}");
    var whitespaces = re.test(value);
    re = new RegExp("[^\n\r\t ]{1,}");
    var otherMarks = re.test(value);
    result = (whitespaces && !otherMarks) ? true : false;
    return result;
  },
 
  xml2array: function (xml, byId) {
    if (xml.hasChildNodes() == true) {
      var nrChildren = xml.childNodes.length;
      var result = new Array();
      for(var i=0; i<nrChildren; i++) {
        var node = xml.childNodes[i];
        if(node.nodeName != '#text') {
          var key = node.nodeName;
          if(key!='xml') { // in view of IE
            if (byId == true && node.getAttribute('id')) {
              key = node.getAttribute('id');
            }
            result[key] = this.xml2array(node, byId);
          }
        } else {
          if (nrChildren > 1) {
            if(this.isOnlyWhiteString(node.nodeValue) == false) {
              result.push(node.nodeValue);
            }
          } else {
            var result = node.nodeValue;
          }
        }
      }
    }
    return result;
  }
}




function AjaxConnection() 
{
   this.setOptions=setOptions;
   this.getOptions=getOptions;
   this.connect=connect;
   this.uri="server.php";
} 


function setOptions(opt)
{
   for(i=0;i<opt.length;i++)  
   {
      this.options += "&"+opt[i];
   }
}


function getOptions()
{
   return this.options;
}

function init_object() 
{
    var http_request = false;

    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    
    return http_request;
}

function connect(return_func)
{
    with(this)
    {
        x=init_object();
        x.open("POST", uri,true);
        x.onreadystatechange = function() 
        {           
                if (x.readyState != 4)  return;
                eval(return_func + '(x.responseXML,x.responseText)');
        }
        
        x.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        x.setRequestHeader('Cache-Control','no-cache');
        x.send(options);
    }
}
