

function new_req() {
	var xml_http_req;
	try {
		xml_http_req=new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xml_http_req=new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) { 
			try {
				xml_http_req = new XMLHttpRequest();
						 } catch (e) {	}
		}
	}
	return xml_http_req;
}

function submit_comment(dest) {
	var xml_http_req = new_req();
	xml_http_req.onreadystatechange=function() {

		if (xml_http_req.readyState == 4) {
			if (xml_http_req.status == 200) {
				result = xml_http_req.responseText;
				lines = result.split('|')
				document.getElementById('error').innerHTML = lines[0];
				document.getElementById('comment_count').innerHTML = lines[1];
				if (! lines[0]) {
					tb_remove();
					document.getElementById('name').value = '';
					document.getElementById('email').value = '';
					document.getElementById('comment').value = '';
				}
			} else {
				alert('There was a problem with the request.');
			}
		}		
	}


	if (! document.getElementById('name').value) {
		document.getElementById('error').innerHTML = 'please enter your name.';
		return;
	}
	if (! document.getElementById('email').value) {
		document.getElementById('error').innerHTML = 'please enter your email address.';
		return;
	}

	if (! document.getElementById('comment').value) {
		document.getElementById('error').innerHTML = "you didn't enter a comment!";
		return;
	}

	name = document.getElementById('name').value;
	email = document.getElementById('email').value;
	private = document.getElementById('private').checked;
	comment = document.getElementById('comment').value;

	args = "name=" + escape(name);
	args = args + "&email=" + escape(email);
	if (private) {
		args = args + "&private=" + escape(private);
	}
	args = args + "&comment=" + escape(comment);
	send_ajax_request(xml_http_req,dest,args);
}


function get_default_sizes(dest) {
	var xml_http_req = new_req();
	xml_http_req.onreadystatechange=function() {
		if (xml_http_req.readyState == 4) {
			if (xml_http_req.status == 200) {
				result = xml_http_req.responseText;
				document.getElementById('sizelist').innerHTML = result;
			}
		}		
	}
	args = "imgres=1";
	args = args + "&cwidth=" + screen.width;
	args = args + "&cheight=" + screen.height;
	send_ajax_request(xml_http_req,dest,args);
}


function get_comments(dest) {
	var xml_http_req = new_req();
	xml_http_req.onreadystatechange=function() {
		if (xml_http_req.readyState == 4) {
			if (xml_http_req.status == 200) {
				result = xml_http_req.responseText;
				document.getElementById('comment_container').innerHTML = result;
			}
		}		
	}
	args = 'view_comments=1';
	send_ajax_request(xml_http_req,dest,args)
}


function send_ajax_request(xml_http_req,dest,args) {
	xml_http_req.open("POST", dest, true);
	xml_http_req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xml_http_req.setRequestHeader("Content-length", args.length);
	xml_http_req.setRequestHeader("Connection", "close");
	xml_http_req.send(args);
}
