function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
				// Implementar manejo de excepciones
			}
		}
		if ( !success ) {
			// Implementar manejo de excepciones, mientras alerta.
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("GET",urlget,false);
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return document.getElementById('ratingtext').innerHTML = this._xh.responseText;
		}
		
	}
	return false;
}


// Este es un acceso rapido, le paso la url y el div a cambiar
function _gr(reqseccion,divcont) {
	remotos = new datosServidor;
	nt = remotos.enviar(reqseccion,"");
	document.getElementById(divcont).innerHTML = nt;
}

function addView(productID) {
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?view=1&productID='+productID);
}

function addComment(productID) {
		text = document.getElementById('commenttext').value; 
		remotos = new datosServidor;
		nt = remotos.enviar('update.php?comment='+text+'&productID='+productID);
		document.getElementById('newcomment').innerHTML = nt; 
		document.getElementById('commentform').style.display  = 'none'; 
}

function rateProduct(rating,productID)  {

		remotos = new datosServidor;
		nt = remotos.enviar('update.php?rating='+rating+'&productID='+productID);
		rating = (rating * 25) - 8;
		document.getElementById('current-rating').style.width = rating+'px';
}

function disableFinish(obj) {
	obj.form.butFinish.style.display='none';
}

function doFinish(obj, rewrite) {
	if (rewrite=='on') {
		obj.form.action='index.php?id=cetelem-finish';
	}
	obj.form.method='post';
	obj.form.submit();
}

function prepocitat(obj){
   function work(http_request, container, resize)
	{
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				//alert(http_request.responseText);
				//ukazKalkulacku();
			  document.getElementById("calc").innerHTML = http_request.responseText;
      }
			else
			{
				alert("Chyba dat!");
			}
		}
	}
			
	if (window.XMLHttpRequest)
	{
		http_request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		try
		{
		  http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (eror)
		{
		  http_request = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	http_request.onreadystatechange = function()
	{
		work(http_request);
	}

  var elements = "";	

//   for (var i=0;i< obj.form.elements.length-1;i++)
//   {
//       if(i==0)  elements +=obj.form.elements[i].name +"=" +obj.form.elements[i].value;
//       else elements +="&"+obj.form.elements[i].name +"=" +obj.form.elements[i].value;
//   }
  
  elements="kodBaremu="+obj.form.kodBaremu.value+"&kodPojisteni="+obj.form.kodPojisteni.value;
  elements+="&primaPlatba="+obj.form.primaPlatba.value+"&pocetSplatek="+obj.form.pocetSplatek.value;
  
	
  http_request.open("POST", "set_cetelem.php?prepocti", true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	http_request.send(elements);
         
}


function setPlatba(id){  // změna platby pro neregistrovanou objednávku
   f3.platba.value = id;      
}          


