<!--

var currentReceta = '';

// --------------------------------------------------------------------------

function MD_Void() {
	return;
}

// --------------------------------------------------------------------------

function MD_GetHttpObj(textMode) {
	try {	
		var returnObj;
		if(window.XMLHttpRequest) { 
			returnObj = new XMLHttpRequest();
			if (returnObj.overrideMimeType) {
				if(textMode) {
					returnObj.overrideMimeType('text/plain');
				} else {
					returnObj.overrideMimeType('text/xml');
				}
			}
		} else if(window.ActiveXObject) {
			try {
				returnObj = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					returnObj = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	} catch(e) {
		returnObj = false;
	}	
	return returnObj;
}

// --------------------------------------------------------------------------

function loadRecetasInfo(recetaId) {

	currentReceta = recetaId;
	MD_Rating(0, 'reset');
	MD_Rating(0, 'load_on');

/*	var commentsHtml = '';
	commentsHtml += '<div id="comment-list-item-message">';
	commentsHtml += '<div id="comment-list-item-text"><img src="/serve/img/rating/star_load_anim.gif" width="18" height="18" align="absmiddle" /> Cargando comentarios...</div>';
	commentsHtml += '</div>';
	document.getElementById('comments-list').innerHTML = commentsHtml;*/

	var ImageHttp = MD_GetHttpObj(false);
	var ImageHttpUrl = '';
	ImageHttpUrl = '/serve/';
	ImageHttpUrl += 'xml/';	
	ImageHttpUrl += 'receta.aspx?receta=' + escape(recetaId);
	ImageHttpUrl += '&t=' + escape(new Date().toString());

	if(ImageHttp) {
		ImageHttp.onreadystatechange = function() { loadRecetasInfoHttpRs(ImageHttp); };
		ImageHttp.open('GET', ImageHttpUrl, true);
		ImageHttp.send(null);
	}
	
}

function loadRecetasInfoHttpRs(ImageHttp) {

	var ImgResponseXml;
	var ImgResponseText;
		
	if (ImageHttp.readyState == 4) {
		if (ImageHttp.status == 200) {	
			ImgResponseXml = ImageHttp.responseXML;	
			ImgResponseText = ImageHttp.responseText;
		}
	}
	
	if(ImgResponseXml && ImgResponseText.length > 0) {
	
		MD_Rating(0, 'load_off');
		
		var ImgDataXml = ImgResponseXml.documentElement;
		var Img_Rating;
		var Img_Comments = 0;
		
		try {
			Img_Rating = ImgDataXml.getElementsByTagName('rating')[0].firstChild.data;
			Img_Comments = ImgDataXml.getElementsByTagName('commentcount')[0].firstChild.data;
		} catch (e) { }

		MD_Rating(Img_Rating, 'set');
		MD_Rating_VoteComplete = false;
		
		if(Img_Comments != 0) {

			var i;
			var commentsHtml = '';
			var commentsArr = ImgDataXml.getElementsByTagName('comment');

			//
			
			var pages = Math.ceil(commentsArr.length/5);
			var pagesHtml = '';
			
			for(i=1;i<=pages;i++) {
				pagesHtml += '<a href="javascript:recetasCommentsPage(' + i + ');">' + i + '</a>'
				if (i != pages) {
					pagesHtml += ' | ';
				}
			}

			//
			
			//commentsHtml += '<div id="comment-list-pageslinks">';
			//commentsHtml += '<b>P&aacute;ginas:</b> ' + pagesHtml;
			//commentsHtml += '</div>';
							
			//
			
			var styleType = 'a';

			for(i=0;i<commentsArr.length;i++) {
				
				commentsHtml += '<div id="recetaComment' + i + '" name="recetaComment' + i + '" style="display:none;">';
				commentsHtml += '<div id="comment-list-item-' + styleType + '">';
				
				commentsHtml += '<div id="comment-list-item-block1">';
				commentsHtml += (i+1);
				commentsHtml += '</div>';
				
				commentsHtml += '<div id="comment-list-item-block2">';				
				commentsHtml += '<div id="comment-list-item-title">'+commentsArr[i].childNodes[0].firstChild.data+':</div>';
				commentsHtml += '<div id="comment-list-item-place">De: '+commentsArr[i].childNodes[1].firstChild.data+'</div>';
				commentsHtml += '<div id="comment-list-item-date">'+commentsArr[i].childNodes[2].firstChild.data+'</div>';
				commentsHtml += '</div>';
				
				commentsHtml += '<div id="comment-list-item-block3">';
				commentsHtml += '<div id="comment-list-item-text">'+commentsArr[i].childNodes[3].firstChild.data+'</div>';
				commentsHtml += '</div>';
				
				commentsHtml += '</div>';
				commentsHtml += '</div>';
				
				if(styleType == 'a') {
					styleType = 'b';
				} else {
					styleType = 'a';
				}
				
			}

			//

			commentsHtml += '<div id="comment-list-pageslinks">';
			commentsHtml += '<b>P&aacute;ginas:</b> ' + pagesHtml;
			commentsHtml += '</div>';
			
			//

			document.getElementById('comments-list').innerHTML = commentsHtml;

			commentsArr = null;
			
			recetasCommentsPage(1);

		} else {
		
			var commentsHtml = '';
			commentsHtml += '<div id="comment-list-item-message">';
			commentsHtml += '<div id="comment-list-item-text">A&uacute;n no hay comentarios en esta receta, &iquest;por qu&eacute; no escribes el primero?</div>';
			commentsHtml += '</div>';
			document.getElementById('comments-list').innerHTML = commentsHtml;
		
		}
		
		ImgResponseXml = null;
		ImgResponseText = null;
		ImageHttp = null;
	
	}
	
}


function recetasCommentsPage(page) {
	
	var i = 0;
	var startI = (page-1) * 5;
	var endI = (page) * 5;

	while(document.getElementById('recetaComment' + i)) {
				
		if(i >= startI && i < endI) {
			document.getElementById('recetaComment' + i).style.display = 'block';
		} else {
			document.getElementById('recetaComment' + i).style.display = 'none';
		}

		i++;
	}
	
}

// --------------------------------------------------------------------------

var MD_Rating_VoteComplete = false;
var MD_Rating_S1 = new Image();
var MD_Rating_S2 = new Image();
MD_Rating_S1.src = '/serve/img/rating/star_ov_on.gif';
MD_Rating_S2.src = '/serve/img/rating/star_ov_off.gif';

function MD_Rating(starNum, act, httpRsp) {

	var i;

	if(act == 'ov') {
		for(i=0;i<=5;i++) {
			if(document.getElementById('MD_Rating_StarDiv_'+i)) {
				if(i<=starNum) {
					document.getElementById('MD_Rating_StarDiv_'+i).style.backgroundImage = 'url(/serve/img/rating/star_ov_on.gif)';
				} else {
					document.getElementById('MD_Rating_StarDiv_'+i).style.backgroundImage = 'url(/serve/img/rating/star_ov_off.gif)';
				}
			}
		}
	}
	
	if(act == 'ou') {
		for(i=0;i<=5;i++) {
			if(document.getElementById('MD_Rating_StarDiv_'+i)) {
				document.getElementById('MD_Rating_StarDiv_'+i).style.backgroundImage = '';
			}
		}
	}
	
	if(act == 'reset') {
		for(i=0;i<=5;i++) {
			if(document.getElementById('MD_Rating_StarDiv_'+i)) {
				document.getElementById('MD_Rating_StarDiv_'+i).className = 'rating-star-off';
			}
		}
	}
	
	if(act == 'load_on') {
		document.getElementById('MD_Rating_LoadImgDiv').innerHTML = '<img src="/serve/img/rating/star_load_anim.gif" width="18" height="18" />';
	}
	
	if(act == 'load_off') {
		document.getElementById('MD_Rating_LoadImgDiv').innerHTML = '';
	}
	
	if(act == 'set') {
		for(i=0;i<=5;i++) {
			if(document.getElementById('MD_Rating_StarDiv_'+i)) {
				if(i <= starNum) {
					document.getElementById('MD_Rating_StarDiv_'+i).className = 'rating-star-on';
				} else {
					document.getElementById('MD_Rating_StarDiv_'+i).className = 'rating-star-off';
				}
			}
		}
	}
	
	if(act == 'ck') {
		if(MD_Rating_VoteComplete) {
			alert('No puede volver a votar para la misma receta.');
			return false;
		}
		var RatingHttp = MD_GetHttpObj(true);
		var RatingUrl = '';
		RatingUrl = '/serve/';
		RatingUrl += 'xml/';	
		RatingUrl += 'recetarating.aspx';
		RatingUrl += '?item_id=' + escape(currentReceta);
		RatingUrl += '&score=' + escape(starNum);
		RatingUrl += '&t=' + escape(new Date().toString());
		if(RatingHttp) {
			RatingHttp.onreadystatechange = function() { MD_Rating(0, 'httprsp', RatingHttp); };
			RatingHttp.open('GET', RatingUrl, true);
			RatingHttp.send(null);
			MD_Rating(0, 'load_on');
			MD_Rating(starNum, 'set');
		}
	}

	if(act == 'httprsp') {
		if (httpRsp.readyState == 4) {
			if (httpRsp.status == 200) {		
				MD_Rating_VoteComplete = true;
				MD_Rating(0, 'load_off');
				alert(httpRsp.responseText);
				httpRsp = null;
			} else {
				MD_Rating(0, 'load_off');
				MD_Rating(0, 'reset');
				alert('Su voto no pudo ser registrado.');
				httpRsp = null;
			}
		}
	}

}

// --------------------------------------------------------------------------

function MD_Comment(act, httpRsp) {
	
	if(act == 'load_off') {
		document.getElementById('MD_Comments_LoadImgDiv').innerHTML = '';
	}
	
	if(act == 'load_on') {
		document.getElementById('MD_Comments_LoadImgDiv').innerHTML = '<img src="/serve/img/rating/star_load_anim.gif" width="18" height="18" />';
	}
	
	if(act == 'post') {

		var t_Name = document.getElementById('txtName').value;
		var t_Email = document.getElementById('txtEmail').value;
		var t_Location = document.getElementById('txtLocation').value;
		var t_Text = document.getElementById('txtText').value;

		if(t_Name == '') { alert('Por favor digite su nombre.'); return; }
		if(t_Email == '') { alert('Por favor digite su email.'); return; }
		if(t_Location == '') { alert('Por favor digite el lugar donde se encuentra.'); return; }
		if(t_Text == '') { alert('Por favor digite el texto del comentario.'); return; }

		var CommentHttp = MD_GetHttpObj(true);
		var CommentUrl = '';
		CommentUrl = '/serve/';
		CommentUrl += 'xml/';	
		CommentUrl += 'comments.aspx';
		CommentUrl += '?item_type=receta&item_id=' + escape(currentReceta);
		CommentUrl += '&name=' + escape(t_Name);
		CommentUrl += '&email=' + escape(t_Email);
		CommentUrl += '&location=' + escape(t_Location);
		CommentUrl += '&text=' + escape(t_Text);
		CommentUrl += '&t=' + escape(new Date().toString());

		if(CommentHttp) {
			CommentHttp.onreadystatechange = function() { MD_Comment('httprsp', CommentHttp); };
			CommentHttp.open('GET', CommentUrl, true);
			CommentHttp.send(null);
			MD_Comment('load_on');
		}
		
	}

	if(act == 'httprsp') {
		if (httpRsp.readyState == 4) {
			if (httpRsp.status == 200) {		
				MD_Comment('load_off');
				alert(httpRsp.responseText)
				if(httpRsp.responseText.indexOf('Gracias') != -1) {
					document.getElementById('txtName').value = '';
					document.getElementById('txtEmail').value = '';
					document.getElementById('txtLocation').value = '';
					document.getElementById('txtText').value = '';
				}
				httpRsp = null;
				loadRecetasInfo(currentReceta);
			} else {
				MD_Comment('load_off');
				alert('Su comentario no pudo ser registrado.');
				httpRsp = null;
			}
		}
	}

}

// --------------------------------------------------------------------------

function MD_SendRecipie(act, httpRsp) {
	
	if(act == 'load_off') {
		document.getElementById('MD_SendRecipie_LoadImgDiv').innerHTML = '';
	}
	
	if(act == 'load_on') {
		document.getElementById('MD_SendRecipie_LoadImgDiv').innerHTML = '<img src="/serve/img/rating/star_load_anim.gif" width="18" height="18" />';
	}
	
	if(act == 'post') {

		var t_Name = document.getElementById('txtName').value;
		var t_SurName = document.getElementById('txtSurName').value;
		var t_Email = document.getElementById('txtEmail').value;
		var t_Location = document.getElementById('txtLocation').value;
		var t_Ingredients = document.getElementById('txtIngredients').value;
		var t_Preparation = document.getElementById('txtPreparation').value;

		if(t_Name == '') { alert('Por favor digite su nombre.'); return; }
		if(t_SurName == '') { alert('Por favor digite su apellido.'); return; }
		if(t_Email == '') { alert('Por favor digite su email.'); return; }
		if(t_Location == '') { alert('Por favor digite el lugar donde se encuentra.'); return; }
		if(t_Ingredients == '') { alert('Por favor digite los ingredientes de la receta.'); return; }
		if(t_Preparation == '') { alert('Por favor digite las instrucciones de preparacion.'); return; }

		var CommentHttp = MD_GetHttpObj(true);
		var CommentUrl = '';
		CommentUrl = '/serve/';
		CommentUrl += 'xml/';	
		CommentUrl += 'sendrecipie.aspx';
		CommentUrl += '?name=' + escape(t_Name);
		CommentUrl += '&surname=' + escape(t_SurName);
		CommentUrl += '&email=' + escape(t_Email);
		CommentUrl += '&location=' + escape(t_Location);
		CommentUrl += '&ingredients=' + escape(t_Ingredients);
		CommentUrl += '&preparation=' + escape(t_Preparation);
		CommentUrl += '&t=' + escape(new Date().toString());

		if(CommentHttp) {
			CommentHttp.onreadystatechange = function() { MD_SendRecipie('httprsp', CommentHttp); };
			CommentHttp.open('GET', CommentUrl, true);
			CommentHttp.send(null);
			MD_SendRecipie('load_on');
		}
		
	}

	if(act == 'httprsp') {
		if (httpRsp.readyState == 4) {
			if (httpRsp.status == 200) {		
				MD_SendRecipie('load_off');
				alert(httpRsp.responseText)
				if(httpRsp.responseText.indexOf('Gracias') != -1) {
					document.getElementById('txtName').value = '';
					document.getElementById('txtSurName').value = '';					
					document.getElementById('txtEmail').value = '';
					document.getElementById('txtLocation').value = '';
					document.getElementById('txtIngredients').value = '';
					document.getElementById('txtPreparation').value = '';
				}
				httpRsp = null;
			} else {
				MD_SendRecipie('load_off');
				alert('Su receta no pudo ser registrada.');
				httpRsp = null;
			}
		}
	}

}

// --------------------------------------------------------------------------

-->