var http_request = false;
var browserType;

if (document.layers) {
	browserType = "nn4"
}
if (document.all) {
	browserType = "ie"
}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
 browserType= "gecko"
}

function showit(link_id, $) {
  $('#div_id' + link_id).animate({
    opacity: 'toggle',
    height: 'toggle'
  }, 350);
}

function get(link_id) {
	var getstr = "?" +
		"txtCaptcha=" + encodeURI( document.getElementById("txtCaptcha_id" + link_id).value) +
		"&linkid=" + link_id;
	makeRequest('/index_files/captcha/get.php', getstr, link_id);
}

function makeRequest(url, parameters, link_id) {  
	http_request = false;
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		http_request=new XMLHttpRequest();
	} else {
		// code for IE6, IE5
		http_request=new ActiveXObject("Microsoft.XMLHTTP");
	}
	http_request.onreadystatechange=function() {
		if (http_request.readyState==4 && http_request.status==200) {
			document.getElementById('span_id' + link_id).innerHTML = http_request.responseText;
		}
	}
	http_request.open('GET', url + parameters, true);
	http_request.send();
}
	
function refreshimg(id, code) {
	//Get a reference to CAPTCHA image
	img = document.getElementById('imgCaptcha_id' + id); 
	//Change the image
	img.src = '/index_files/captcha/create_image.php?code=' + code + '&id=' + id + '&rand=' + Math.random();
	ReplaceContentInContainer('span_id' + id, '');
	ResetForm('form_id' + id)
}

function ReplaceContentInContainer(id, content) {
	var container = document.getElementById(id);
	container.innerHTML = content;
}

function ResetForm(id) {
	var thisform = document.getElementById(id);
	thisform.reset();
}

function download(id) {
	refreshimg(id, false);
	get(document.getElementById('form_id' + id), 'link_id' + id, '1')
}

