function getxmlhttp (){
  var xmlhttp = false;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

function showContent(param, pid, oid) {
	var xmlhttp = getxmlhttp();
	var serverPage = "http://www.actioncam.sk/product.php?param=" + param + "&id=" + pid;
	var obj = document.getElementById(oid);
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.send(null);
}

function showImage(imgsrc) {
	window.open("http://www.actioncam.sk/img.php?mode=showbig&src=" + imgsrc, null, "height=200,width=400,resizable=1,status=yes,toolbar=no,menubar=no,location=no");
}

function enableSubmit() {
	if (document.forms[0].accept.checked == true) {
		document.forms[0].ok.disabled = false;
	}
	else {
		document.forms[0].ok.disabled = true;
	}
}

function getFormValues(fobj) {
	var ret = "";
	error = false;
	for (var i = 0; i < fobj.elements.length; i++) {
		if (escape(fobj.elements[i].value) == "" && !error) {
			error = true;
			alert("Musíte vyplniť všetky polia");
		}
		ret += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
	}
	return ret;
}

function submitForm(fid, retid, pid) {
	var fobj = document.getElementById(fid);
	var str = "";
	str = getFormValues(fobj);
	if (!error) {
		proccessForm(str, "http://www.actioncam.sk/product.php?mode=add-comment&id=" + pid, retid);
	}
}

function proccessForm(str, serverPage, retid) {
	var xmlhttp = getxmlhttp();
	var obj = document.getElementById(retid);
	xmlhttp.open("POST", serverPage, true);
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			obj.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(str);
}

function checkForm(fobj) {
	var error = false;
	for (var i = 0; i < fobj.elements.length; i++) {
		if (escape(fobj.elements[i].value) == "" && !error && fobj.elements[i].readonly != "readonly") {
			error = true;
			alert("Musíte vyplniť všetky polia");
		}
	}
	return !error;
}