var zoomImagesURI   = '/img/';

var myWidth = 0, myHeight = 0, myScroll = 0; myScrollWidth = 0; myScrollHeight = 0;
var zoomOpen = false, preloadFrame = 1, preloadFrame2 = 1, preloadActive = false, preloadTime = 0, imgPreload = new Image();
var preloadAnimTimer = 0;

function insertPreloadHTML() {
   var inBody = document.getElementsByTagName("body").item(0);
   var inSpinbox = document.createElement("div");
    inSpinbox.setAttribute('id', 'ZoomSpin');
	inSpinbox.style.position = 'absolute';
	inSpinbox.style.left = '10px';
	inSpinbox.style.top = '10px';
	inSpinbox.style.display = 'none';
	inSpinbox.style.zIndex = '525';
	inBody.insertBefore(inSpinbox, inBody.firstChild);

   var inSpinImage = document.createElement("img");
	 inSpinImage.setAttribute('id', 'SpinImage');
	 inSpinImage.setAttribute('src', '');
	 inSpinbox.appendChild(inSpinImage);
   var inZoombox = document.createElement("div");
	inZoombox.setAttribute('id', 'ZoomBox');

	inZoombox.style.position = 'absolute';
	inZoombox.style.left = '10px';
	inZoombox.style.top = '10px';
	inZoombox.style.visibility = 'hidden';
	inZoombox.style.zIndex = '499';

	inBody.insertBefore(inZoombox, inSpinbox.nextSibling);
}

function preloadAnimStart() {
	document.getElementById("ZoomSpin").style.left = (myWidth / 2) + 'px';
	document.getElementById("ZoomSpin").style.top = ((myHeight / 2) + myScroll) + 'px';
	document.getElementById("ZoomSpin").style.display = "block";
	document.getElementById("SpinImage").src = zoomImagesURI+'zoom.gif';
}

function preloadAnimStop() {
	document.getElementById("ZoomSpin").style.display = "none";
}

function getSize() {

	// Window Size

	if (self.innerHeight) { // Everyone but IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) { // Other IE, such as IE7
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}

	// Page size w/offscreen areas

	if (window.innerHeight && window.scrollMaxY) {
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	}
}

function sendRequestAjax(params) {
	url  = AjaxUrl+params+'&rnd='+Math.random();
	getSize();
	preloadAnimStart();
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processRequestAjax;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processRequestAjax;
            req.open("GET", url, true);
            req.send();
        }
    }
}


function processRequestAjax()
{
    if (req.readyState == 4) {
        if (req.status == 200) {        	 parseRequestAjax(req.responseXML,req.responseText);
             preloadAnimStop();
           }
    }
}

function parseRequestAjax(data,txtdata) {
 if(data.documentElement == null){
    data.loadXML(txtdata)
}
 items = data.getElementsByTagName('item');
 if (items) {
  for(i=0;items[i];i++) {
   if (items[i].getAttribute('isvalue')==1) aplyValue(items[i].getAttribute('id'), items[i].firstChild.data);
   else {
    if (items[i].getAttribute('isjava')==1) aplyJava(items[i].firstChild.data);
    else aplyData(items[i].getAttribute('id'), items[i].firstChild.data);
   }
  }
}
}

function aplyData(id, data) { elem = document.getElementById(id);
 if (elem) {  elem.innerHTML = data;
 }
}

function aplyValue(id, data) {
 elem = document.getElementById(id);
 if (elem) elem.value = data;
}

function aplyJava(data) {  try{   window.eval(data);
  }
  catch(e) {//  	alert(e.name);  }
}
