
var UT_cool_IMG = '/images/cool.gif';
var UT_cool_IMG_HOVER = '/images/cool_removed.gif';
var UT_cool_IMG_HALF = '/images/cool_hover.gif';
var UT_cool_IMG_BG = '/images/cool_removed.gif';
var UT_cool_IMG_REMOVED = '/images/cool_removed.gif';
var i;

function UTcool(coolElementId, maxcool, objectName, formName, coolMessageId, componentSuffix, size)
{
	this.coolElementId = coolElementId;
	this.maxcool = maxcool;
	this.objectName = objectName;
	this.formName = formName;
	this.coolMessageId = coolMessageId
	this.componentSuffix = componentSuffix

	this.coolTimer = null;
	this.coolCount = 0;

	if(size=='S') {
		UT_cool_IMG      = '/images/cool.gif'
		UT_cool_IMG_HALF = '/images/cool.gif'
		UT_cool_IMG_BG   = '/images/cool_removed.gif'
	}
	
	// pre-fetch image
	(new Image()).src = UT_cool_IMG;
	(new Image()).src = UT_cool_IMG_HALF;

	function showcool(coolNum, skipMessageUpdate) {
		this.clearcoolTimer();
		this.greycool();
		this.colorcool(coolNum);
		if(!skipMessageUpdate)
			this.setMessagecool(coolNum);
	}

	function setMessagecool(coolNum) {
		messages = new Array("Ulubione", "Ulubione!", "Nada de especial");
		document.getElementById(this.coolMessageId).innerHTML = messages[coolNum];
	}

	function colorcool(coolNum) {
		for (var i=0; i < coolNum; i++)
			document.getElementById('cool_'  + this.componentSuffix + "_" + (i+1)).src = UT_cool_IMG;
	}

	function greycool() {
		for (var i=0; i < this.maxcool; i++)
			if (i <= this.coolCount)
				document.getElementById('cool_' + this.componentSuffix + "_"  + (i+1)).src = UT_cool_IMG_BG; // UT_cool_IMG_REMOVED;
			else
				document.getElementById('cool_' + this.componentSuffix + "_"  + (i+1)).src = UT_cool_IMG_BG;
	}

	function setcool(coolNum) {
		this.coolCount = coolNum;
		this.drawcool(coolNum);
		document.forms[this.formName]['cool'].value = this.coolCount;
		var coolElementId = this.coolElementId;
		postForm(this.formName, true, function (req) { replaceDivContents(req, coolElementId); });
	}


	function drawcool(coolNum, skipMessageUpdate) {
		this.coolCount=coolNum;
		this.showcool(coolNum, skipMessageUpdate);
	}

	function clearcool() {
		this.coolTimer = setTimeout(this.objectName + ".resetcool()", 300);
	}

	function resetcool() {
		this.clearcoolTimer();
		if (this.coolCount)
			this.drawcool(this.coolCount);
		else
			this.greycool();
		this.setMessagecool(0);
	}

	function clearcoolTimer() {
		if (this.coolTimer) {
			clearTimeout(this.coolTimer);
			this.coolTimer = null;
		}
	}

	this.clearcool = clearcool;
	this.clearcoolTimer = clearcoolTimer;
	this.greycool = greycool;
	this.colorcool = colorcool;
	this.resetcool = resetcool;
	this.setcool = setcool;
	this.drawcool = drawcool;
	this.showcool = showcool;
	this.setMessagecool = setMessagecool;

}

   var http_request = false;

   function makeRequestcool(url, parameters, idcool) {
      http_request = false;
	this.idcool = idcool;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      http_request.onreadystatechange = alertContents;

      http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
			//alert(idcool);
            document.getElementById('favorite'+idcool).innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
      makeRequest('get.asp', getstr);
   }
