
	var targetDiv;
	var req;
	var curPage;
	// Global variables
	xMousePos = 0; // Horizontal position of the mouse on the screen
	yMousePos = 0; // Vertical position of the mouse on the screen
	xMousePosMax = 0; // Width of the page
	yMousePosMax = 0; // Height of the page
	
	window.onresize = fixLayout;

	if (document.layers) { // Netscape
	    document.captureEvents(Event.MOUSEMOVE);
	    document.onmousemove = captureMousePosition;
	} else if (document.all) { // Internet Explorer
	    document.onmousemove = captureMousePosition;
	} else if (document.getElementById) { // Netcsape 6
	    document.onmousemove = captureMousePosition;
	}	
	
	//////////////////////////////////////////////////////////////////////////
	//ADMIN EDITOR FUNCTIONS /////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
		
		
	function showEDiv (divname) {
		
		for (var i=1;i<=18;i++) {
			temp = getObj('ediv' + i);
			if (temp != undefined) {
		
				temp.style.display = 'none';		
				
			}
		}

		getObj(divname).style.display = 'block';
	}

	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	
	
	function select(fname, value, display) {
		//alert(fname.name);
		getObj(fname).value = value;
		getObj(fname + 'display').value = display;
	    hidePopup();
	} 	
	
	function refreshParent () {
		sendRequest(curPage, 'content');
	}
	
	
	function hidePopup() {
		getObj('toolpopup').style.display = 'none';
	
	}
	
	
	function togglePopup (url) {
		if (getObj('toolpopup').style.display == 'none') {
			sendRequest(url, 'toolpopup');
		} else {
			hidePopup();
		}
		
	
	}
	
	
	
	function fixLayout () {
	
		//CALLED ON WINDOW RESIZE
	
		//RECENTER THE SCREEN DIV
		//alert(xMousePosMax);
		captureMousePosition();
		
		
		if (getObj('screen').style.display == 'block') {
			centerDiv('screen');
			getObj('screen').style.top = 60;
		}
		
	
	}
	
	
	function centerDiv (tDiv) {
	
		var l = (xMousePosMax / 2) - (getObj(tDiv).offsetWidth / 2);					
		getObj(tDiv).style.left = parseInt(l);
		
		//var t = (yMousePosMax / 2) - (getObj(tDiv).offsetHeight / 2);					
		//getObj(tDiv).style.top = parseInt(t);		

	}
	
	
	function hidePopup() {
		getObj('toolpopup').style.display='none';
	}
	
	function hideScreen() {
		getObj('toolpopup').style.display='none';
		getObj('screen').style.display='none';
		getObj('screenfade').style.display='none';
	}	
	
	function captureMousePosition(e) {
	    if (document.layers) {

	        xMousePos = e.pageX;
	        yMousePos = e.pageY;
	        xMousePosMax = window.innerWidth+window.pageXOffset;
	        yMousePosMax = window.innerHeight+window.pageYOffset;
	    } else if (document.all) {

	        xMousePos = window.event.x+document.body.scrollLeft;
	        yMousePos = window.event.y+document.body.scrollTop;
	        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
	        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
	    } else if (document.getElementById) {

	        xMousePos = e.pageX;
	        yMousePos = e.pageY;
	        xMousePosMax = window.innerWidth+window.pageXOffset;
	        yMousePosMax = window.innerHeight+window.pageYOffset;
	    }
	}
	
	
	function getObj(strObjectName) {
		var temp;

			temp = "document.all." + strObjectName
			if (temp == undefined) {
				temp = "document." + strObjectName
				if (temp == undefined) {
					temp = "document.getElementById('" + strObjectName + "')"
				}
			}	
			
		return eval(temp);
	}		

	function createXMLHttp () {
		req = false;
	    // branch for native XMLHttpRequest object
	    if(window.XMLHttpRequest) {
	    	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;
	        	}
			}
	    }
	}
	
	function sendRequest(strURL, tDiv) {
	
		createXMLHttp ()

		targetDiv = tDiv;
		
		if (targetDiv == 'content') {
			curPage = strURL;
		}
		
		if (targetDiv != 'screen') {
			getObj(targetDiv).style.top = yMousePos;
			getObj(targetDiv).style.left = xMousePos + 10;
			getObj(targetDiv).style.display = 'block';
		} else {
			//FADE OUT THE BACKGROUND
			getObj('screenfade').style.display = 'block';
		}
		
		
	
		// POSTS DATA AND RETURNS DATA
		var refresh = Math.random();
		var str = "";
		
		if (strURL.lastIndexOf('?') != -1) {
			temp = "&";
		} else {
			temp = "?";
		}
	
		req.open('GET',strURL+temp+'r='+refresh);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		req.onreadystatechange = handleResponse;
		req.send(str);			
		
		return false;
	}	

	
	function sendPopupRequest(strURL, tDiv) {
	
		createXMLHttp ()

		targetDiv = tDiv;
		
		// POSTS DATA AND RETURNS DATA
		var refresh = Math.random();
		var str = "";
		
		if (strURL.lastIndexOf('?') != -1) {
			temp = "&";
		} else {
			temp = "?";
		}
	
		req.open('GET',strURL+temp+'r='+refresh);
		req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		
		req.onreadystatechange = handleResponse;
		req.send(str);			
		
		return false;
	}		
	
	
	
	function handleResponse () {
		if (req.readyState == 4) {		
			// RESPONSE LOADED
	        if (req.status == 200) {
	            // RESPONSE OK
			
				var response = req.responseText;
				
				//response = utf8decode(response);
				
				//alert(response.search(/!!!HIDESCREEN!!!/))
				
				if (response.search(/!!!HIDESCREEN!!!/) != -1) {
					// HIDE THE TARGET DIV - OCCURS AFTER SCREEN FORM SAVE
					hideScreen();
					
					//REFRESH THE PARENT SCREEN
					refreshParent();
				
				
				} else {
			
					getObj(targetDiv).innerHTML = response;
					
					if (targetDiv == 'screen') {
						getObj(targetDiv).style.display = 'block';		
						
						centerDiv(targetDiv);
						getObj(targetDiv).style.top = 60;
						
					}
				}
				
				//alert(xMousePosMax + ' ' + getObj(targetDiv).offsetWidth);
											
	        } else {
				// RESPONSE FAILED
	            alert("There was a problem contacting the server" +
	                req.statusText);
	        }		
		

		}
	}	
	
	
	
	function sendFormRequest(frm, file, tDiv) {
		// POSTS DATA AND RETURNS A FORM
		
		//disableButtons();
		
		targetDiv = tDiv;
		
		var refresh = Math.random();
		var str = "";
		//alert(frm);
		currentForm = frm.name;
				
			
		if (str = getForm(frm)) {
		
			//str = utf8encode(str);
			//str = encodeURI(str);
		
			//alert('running request!');
			//
			
			//alert(str);
			req.open('POST',file+'?'+'r='+refresh);
			req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			req.send(str);
			
			//alert(str);
			
			req.onreadystatechange = handleResponse;
			//req.send(null);
		}
		return false;
	}
	
	
	function getForm(fObj) {
		var str = "";
		var ft = "";
		var fv = "";
		var fn = "";
		var els = "";
		for (var i=0;i<fObj.elements.length;i++) {
	
			els = fObj.elements[i];
			ft = els.title;
			fv = els.value;
			fn = els.name;			
			
			//els.style.backgroundColor = 'EFDBDE';
			//els.className = 'fielddisabled';
			
			switch (els.type) {
				case "text":
				case "hidden":
				case "password":
				case "textarea":
					// CHECK MANDATORY
					if (encodeURI(ft) == "required" && encodeURI(fv).length < 1) {
						//alert('''+fn+'' is a required field, please complete.');
						alert(fn+' is a required field, please complete');
						els.focus();
						return false;
					}
					str += fn + "=" + encodeURI(fv) + "&";
					break;
				
				case "checkbox":
				case "radio":
					if (els.checked) {str += fn + "=" + encodeURI(fv) + "&"};
					break;
					
				case "select-one":
					str += fn + "=" + els.options[els.selectedIndex].value + "&";
					break;
			
			}		
		}
		str = str.substr(0,(str.length - 1));
		return str;
	}		
	
	
	function disableButtons () {
		eval(getDocObject('btn1')).disabled = true;
		eval(getDocObject('btn2')).disabled = true;
		if (eval(getDocObject('btn3')) != undefined) {
			eval(getDocObject('btn3')).disabled = true;
		}
		eval(getDocObject('dealid')).disabled = true;
		eval(getDocObject('Print')).disabled = true;
	}
	
	
	createXMLHttp();	

	
	