	function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


	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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		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;
}


	
	function initiate()
	{var objBody = document.getElementsByTagName("body").item(0);
	var arrayPageSize = getPageSize();
	
	// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	//objOverlay.onclick = function () {hideselector(); return false;}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = arrayPageSize[0] + 'px';
	objOverlay.style.height = '0px';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var selectorholder = document.createElement("div");
	
	selectorholder.setAttribute('id','selectorh');
	selectorholder.style.display = 'inline';
	selectorholder.style.position = 'absolute';
    selectorholder.style.width ='730px';
	selectorholder.style.height= '455px';
	selectorholder.style.left = (arrayPageSize[0]/2)-(730/2)+'px';	
	selectorholder.style.backgroundColor= '#FFF';
	objOverlay.insertBefore(selectorholder, objOverlay.firstChild);
	}
	

function genselect() {
	var url='genselector.php'
	req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest && !(window.ActiveXObject)) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
	if(req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}	

function processReqChange() {
    // only if req shows "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
			var arrayPageSize2 = getPageSize();
			var arrayPageScroll= getPageScroll();
			document.getElementById('overlay').style.display = 'inline';
			  document.getElementById('selectorh').style.top =arrayPageScroll[1] +((arrayPageSize2[3]-455 )/2)+ 'px';
			document.getElementById('overlay').style.height = arrayPageSize2[1] + 'px';
          document.getElementById('selectorh').innerHTML=req.responseText;
          
        } else {
            alert('There was a problem with the request.');
        }
    }
}

function hideselector(){
	document.getElementById('selectorh').innerHTML='';
	document.getElementById('overlay').style.display = 'none';
	}
