var xmlHttp;

function getXMLHTTP() {
	var A = null;
	try {
		A = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e) {
		try {
			A = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc) {
			A = null;
		}
	}
	if (!A && typeof XMLHttpRequest != "undefined") {
		A = new XMLHttpRequest();
	}
  return A;
}


function doQuery(e, queryString, senddata) {
	Loading(e);
	searching = true;
	if (xmlHttp && xmlHttp.readyState != 0) {
		xmlHttp.abort()
	}	  
	xmlHttp=getXMLHTTP();
	if (xmlHttp) {
		xmlHttp.open("POST", queryString, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4 && xmlHttp.responseText && searching) {
	      		try {
	      			eval(xmlHttp.responseText);
	      		}
	      		catch(e) {
					errorWindow=window.open("", "", "height=500, width=600,toolbar=no,scrollbars=yes,menubar=no,resizable=yes");
	      			errorWindow.document.write(xmlHttp.responseText);
	      		}
	      		searching = false;
			}
		}
		if (senddata) {
			senddata = senddata.split(' ')
			stub = '';
			for (var i=0;i < senddata.length;i++) {
				var fld = senddata[i];
				stub += fld + '=' + encodeURIComponent(document.getElementById(fld).value) + '&';
			}
			xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
			xmlHttp.send(stub);
		}
		else xmlHttp.send(null);
	}
}


function Loading(e) {
	if (e) {
		d = document.getElementById('loading');
		x = findPosX(e)+15;
		y = findPosY(e)+5;
		d.style.left =  x+'px';
		d.style.top =  y+'px';
		d.style.visibility = 'visible';
	}
}


function findPosX(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX) 	posx = e.pageX;
	else if (e.clientX) posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	return posx;
}

function findPosY(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageY) posy = e.pageY;
	else if (e.clientY) posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	return posy;
}



function findPosX(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageX) 	posx = e.pageX;
	else if (e.clientX) posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	return posx;
}

function findPosY(e) {
	var posx = 0;
	if (!e) var e = window.event;
	if (e.pageY) posy = e.pageY;
	else if (e.clientY) posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	return posy;
}

function URLencode(sStr) {
    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
  }

  function Reposition() {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winW = document.documentElement.clientWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.documentElement.clientWidth;
			winH = document.documentElement.clientHeight;
		}
	}
	d = document.getElementById('ajaxpop');
	LI = d.getElementsByTagName('div');
	maxwidth = 100;
	for(i=0; i < LI.length; i++) {
		w = parseFloat(LI[i].style.width);
		if (w > maxwidth) maxwidth = w;
	}
	h = document.getElementById('reposimg').offsetTop-10;
	if (h < 0) h = 50;
	d.style.width = maxwidth+'px';
	d.style.height = h+'px';
	d.style.left = parseInt((winW-maxwidth)/2) + 'px';
	if (window.scrollY) scr = window.scrollY;
	else if (document.documentElement.scrollTop) scr = document.documentElement.scrollTop;
	else scr = 0;
	stub = parseInt((winH-h)/2+scr);
	d.style.top =  stub + 'px';
}


function HideAjax() {
	document.getElementById('ajaxpop').style.visibility='hidden';
}

function DoRate(fldname, val) {
	for (i=1; i<=10; i++) {
		if (i<=val) cl = 'full';
		else cl = 'empty';
		document.getElementById(fldname+'.'+i).className = cl;
	}
	document.getElementById(fldname).value = val;
}


function TrackRate(fldname, val) {
	for (i=1; i<=10; i++) {
		if (i<=val) cl = 'full';
		else cl = 'empty';
		document.getElementById(fldname+'.'+i).className = cl;
	}
}

function RestoreRate(fldname, val) {
	for (i=1; i<=10; i++) {
		if (i<=val) cl = 'preview';
		else cl = 'empty';
		document.getElementById(fldname+'.'+i).className = cl;
	}
}


function ScrollToElement(el) {
	if (!document.getElementById(el)) return ;
	if (document.all) y = document.getElementById(el).offsetParent.offsetTop;
	else y = document.getElementById(el).offsetTop;
	window.scrollTo(0, y);
}
