var Comments = Class.create({ initialize: function(options) { options = options || {}; this.options = Object.extend({ listContainer: $('comments'), itemID: null, url: document.getElementsByTagName('base')[0].href, page: 1 }, options || {}); this.getComments(); }, getComments: function() { if(this.options.url) { new Ajax.Request(this.options.url, { method:'post', parameters: {'itemID': this.options.itemID, 'pageID': this.options.page}, onSuccess: this.writeComments, onFailure: this.failure }); } else { // no url defined } }, writeComments: function(transport) { var rXML = transport.responseXML; if(document.all) { root = rXML.childNodes[1]; } else { root = rXML.childNodes[0]; } var comments = root.getElementsByTagName('comentarii')[0]; var sysMessage = root.getElementsByTagName('sysMessage')[0]; if(comments.hasChildNodes()) { var items = comments.childNodes; for(var i = 0; i < items.length; i++) { var commentScore = items[i].getElementsByTagName('score')[0].firstChild.nodeValue; } } }, failure: function(a,s,d,f) { // console.log('failure: ',a,s,d,f) } }) // ##########comments########### function getComments(itemType, itemID, page, showRating) { var baseHref = document.getElementsByTagName('base')[0].href; switch(itemType){ case 'product': var ajaxTo = baseHref + 'index.html' + '/products|productComments'; break; case 'biketrip': var ajaxTo = baseHref + 'index.html' + '/biketrips|tripComments'; break; default: alert('Eroare: Tip de comentariu nerecunoscut !'); } new Ajax.Request(ajaxTo, { method:'post', parameters: {'itemID': itemID, 'pageID': page}, onSuccess: function(transport){ var response = transport.responseXML; writeComments(response, showRating, itemType); }, onFailure: function(){ alert('Eroare: Va rugam incercati mai tarziu !'); } }); } function writeComments(rXML, showRating, itemType) { $('commentsListing').innerHTML = ''; if(document.all) { root = rXML.childNodes[1]; } else { root = rXML.childNodes[0]; } var pagingInfo = root.getElementsByTagName('detalii')[0]; var comments = root.getElementsByTagName('comentarii')[0]; var sysMessage = root.getElementsByTagName('sysMessage')[0]; if(comments.hasChildNodes()) { var items = comments.childNodes; for(var i = 0; i < items.length; i++) { //adapt to junk comments var commentScore = items[i].getElementsByTagName('commentScore')[0].firstChild.nodeValue; if(commentScore < 3){ var classTitle = 'titluRewNegativ'; var classBody = 'textNegativ'; var mainBody = 'display: none;'; } else { var classTitle = 'titluRew'; var classBody = 'text'; var mainBody = 'display: block;'; } // container for each comment var divReviews = new Element('div', {'class':'reviews'}); //comment rating paragraph var pNotaComentariu = new Element('p', {'class':'notaComentariu'}); //link to report the comment // var aReportComment = new Element('a', {'href':'www.google.com'}).update('raporteaza comentariu'); // pNotaComentariu.appendChild(aReportComment); //insert break var nl = new Element('br'); pNotaComentariu.appendChild(nl); var spanNota = new Element('span').update('Gasesti util acest comentariu?  |  '); pNotaComentariu.appendChild(spanNota); //em container for up/down rating a comment var emRating = new Element('em', {'id':'rating4_' + items[i].getElementsByTagName('feedbackID')[0].firstChild.nodeValue}); //link for down rating & image for it var aMinus = new Element('a', {'href':'#', 'onClick':'rateComment("' + itemType + '", ' + items[i].getElementsByTagName('feedbackID')[0].firstChild.nodeValue + ', "-", ' + showRating + '); return false;'}); var imgMinus = new Element('img', {'src':'images/icons/ico_scade.gif'}); aMinus.appendChild(imgMinus); //link for up rating & image for it var aPlus = new Element('a', {'href':'#', 'onClick':'rateComment("' + itemType + '", ' + items[i].getElementsByTagName('feedbackID')[0].firstChild.nodeValue + ', "+", ' + showRating + '); return false;'}); var imgPlus = new Element('img', {'src':'images/icons/ico_adauga.gif'}); aPlus.appendChild(imgPlus); //append up/down rating to em container emRating.appendChild(aMinus); var spanSpacer = new Element('span').update(' '); //just a spacer emRating.appendChild(spanSpacer); emRating.appendChild(aPlus); //append em up/down rating to rating container pNotaComentariu.appendChild(emRating); //append entire rating container to comment divReviews.appendChild(pNotaComentariu); //container for title, username and date var pTitluRew = new Element('p', {'class':classTitle}); //strong title/username var strongTitle = new Element('strong', {'style':'cursor: pointer;', 'onClick':'myToggle("commentNo_' + i + '")'}).update(items[i].getElementsByTagName('PersonName')[0].firstChild.nodeValue); pTitluRew.appendChild(strongTitle); //insert break var nl = new Element('br'); pTitluRew.appendChild(nl); //date var spanName = new Element('span', {'class':'name'}).update(items[i].getElementsByTagName('postDate')[0].firstChild.nodeValue); pTitluRew.appendChild(spanName); //append for title, username and date to comment divReviews.appendChild(pTitluRew); //main bady container var divMainBody = new Element('div', {'id': 'commentNo_' + i, 'style': mainBody}); //comment body var pText = new Element('p', {'class':classBody}).update(items[i].getElementsByTagName('body')[0].firstChild.nodeValue); //divReviews.appendChild(pText); divMainBody.appendChild(pText); if (showRating != '0' && (items[i].getElementsByTagName('rating')[0].firstChild.nodeValue > 0)){ var pRating = new Element('p', {'class':'rating'}); var pos = 90 - (parseInt(items[i].getElementsByTagName('rating')[0].firstChild.nodeValue) * 18); var pRank = new Element('div', {'style':'background-image: url(images/backgrounds/rating.png); background-position: -' + pos + 'px 0px; background-repeat: no-repeat; border: none; height: 17px; width: 90px; float: left;'}); pRating.appendChild(pRank); var spanRank = new Element('span').update( 'Nota produs: ' + parseInt(items[i].getElementsByTagName('rating')[0].firstChild.nodeValue) + ' din 5 stele'); //var rankno = document.createTextNode(parseInt(items[i].getElementsByTagName('rank')[0].firstChild.nodeValue)); pRating.appendChild(spanRank); //divReviews.appendChild(pRating); divMainBody.appendChild(pRating); } divReviews.appendChild(divMainBody); $('commentsListing').appendChild(divReviews); } } else { //var noRev = document.createTextNode('Be the first to write a review for this product.'); $('commentsListing').innerHTML = '

Fii primul sa scrii un comentariu.

'; } if(pagingInfo && pagingInfo.hasChildNodes) { var pageID = pagingInfo.getElementsByTagName('pagina')[0].firstChild.nodeValue; var nPages = pagingInfo.getElementsByTagName('totalpagini')[0].firstChild.nodeValue; var nElements = pagingInfo.getElementsByTagName('totalcomentarii')[0].firstChild.nodeValue; var elementID = pagingInfo.getElementsByTagName('ID')[0].firstChild.nodeValue; if(nPages && nPages > 1) { var cleaner = $(document.createElement('div')); cleaner.addClassName('cleaner'); $('commentsListing').appendChild(cleaner); var ppage = $(document.createElement('p')); ppage.id = 'paginare'; ppage.addClassName('paginare'); var paginare = document.createTextNode('Pagina: '); ppage.appendChild(paginare); if (pageID>1){ var prev = $(document.createElement('a')); prev.href = 'javascript: void(0);' prev.onclick = new Function('getComments("' + itemType + '", ' + elementID + ', ' + (pageID-1) + ')'); } else { var prev = $(document.createElement('span')); } var prevBtn = $(document.createElement('img')); prevBtn.src = 'images/butoane/paginare_inapoi.gif'; prev.appendChild(prevBtn); ppage.appendChild(prev); for(var i = 1; i <= nPages; i++) { if(i == pageID) { var pageTag = $(document.createElement('a')); pageTag.addClassName('paginaActiva'); } else { // var sp = document.createTextNode(' '); // ppage.appendChild(sp); var pageTag = $(document.createElement('a')); pageTag.addClassName('pagina'); pageTag.href = 'javascript: void(0);' pageTag.onclick = new Function('getComments("' + itemType + '", ' + elementID + ', ' + i + ')'); } // var sp = document.createTextNode(' '); // ppage.appendChild(sp); var pageText = document.createTextNode(i); pageTag.appendChild(pageText); ppage.appendChild(pageTag); } if(pageID"); else return str; } //COMMENTS function displayCommentForm(formID, userID, fieldToFocus, message) { //return false; if(parseInt(userID)) { Effect.toggle($(formID).addClassName('reviews'),'slide'); setTimeout('$(\''+fieldToFocus+'\').focus();', 1000); } else { // showToolTipFader(message, $('comenteazaSiTuID')); if(!$('commentGoToLogin')) { var commentGoToLogin = $(document.createElement('div')); commentGoToLogin.id = 'commentGoToLogin'; commentGoToLogin.setStyle({'display':'none'}); var div = $(document.createElement('div')).addClassName('reviews'); var br = document.createElement('br'); div.appendChild(br); var msg = document.createTextNode(message); div.appendChild(msg); var br = document.createElement('br'); div.appendChild(br); msg = document.createTextNode('Te poti autentifica dand click '); div.appendChild(msg); var loginLink = $(document.createElement('a')); loginLink.href = document.getElementsByTagName('base')[0].href + 'index.html/account|login'; msg = document.createTextNode('aici'); loginLink.appendChild(msg); div.appendChild(loginLink); commentGoToLogin.appendChild(div); $('comenteazaSiTuID').parentNode.appendChild(commentGoToLogin); new Effect.SlideDown(commentGoToLogin); } } } function validateComment(fieldsToBeValidated) { var ok = true; if(fieldsToBeValidated.length) { for(i = 0; i < fieldsToBeValidated.length; i++) { if(!$(fieldsToBeValidated[i]).value.trim().length) { ok = false; showToolTipFader('Completeaza campul...',$(fieldsToBeValidated[i])); } } } return ok; } function postComment(formID, itemID, fieldsToBeValidated, showRating, itemType){ var baseHref = document.getElementsByTagName('base')[0].href; switch(itemType){ case 'product': var ajaxTo = baseHref + 'index.html' + '/products|productComments'; break; case 'biketrip': var ajaxTo = baseHref + 'index.html' + '/biketrips|tripComments'; break; default: alert('Eroare: Tip de comentariu nerecunoscut !'); } if(validateComment(fieldsToBeValidated)) { Effect.toggle($(formID),'slide'); new Ajax.Request(ajaxTo, { method:'post', parameters: {'itemID': itemID, comment: $('comment').value, 'rank':$('rank').value, postComment: '1' }, onSuccess: function(transport){ $('comment').value =''; $('rank').value =''; $('ranking').style.backgroundPosition = '-90px 0px'; var response = transport.responseXML; writeComments(response, showRating, itemType); }, onFailure: function(){ } }); } } function buildRanking() { var ratingSelector = $('ranking'); function mouseOver() { this.parentNode.style.backgroundPosition = -(90 - (this.firstChild.nodeValue * 18)) + "px 0px"; } function mouseOut() { this.parentNode.style.backgroundPosition = -(90 - (this.parentNode.firstChild.value * 18)) + "px 0px"; } function mouseClick() { this.parentNode.firstChild.value = this.firstChild.nodeValue; return false; } for (var i = 1; i <= 5; i++) { var star = document.createElement("a"); star.href = "#"; star.title = i + "/5"; star.appendChild(document.createTextNode(i)); star.onmouseover = mouseOver; star.onmouseout = mouseOut; star.onclick = mouseClick; ratingSelector.appendChild(star); } } function rateComment(itemType, itemID, score, showRating){ var baseHref = document.getElementsByTagName('base')[0].href; switch(itemType){ case 'product': var ajaxTo = baseHref + 'index.html' + '/products|rateComments'; break; case 'biketrip': var ajaxTo = baseHref + 'index.html' + '/biketrips|rateComments'; break; default: alert('Eroare: Tip de comentariu nerecunoscut !'); } new Ajax.Request(ajaxTo, { method:'post', parameters: {'itemID': itemID, 'score': score, 'postComment': '1' }, onSuccess: function(transport){ var response = transport.responseXML; //alert(transport.responseText); //writeComments(response, showRating, itemType); if(document.all) { root = response.childNodes[1]; } else { root = response.childNodes[0]; } var pagingInfo = root.getElementsByTagName('detalii')[0]; var comments = root.getElementsByTagName('comentarii')[0]; var sysMessage = root.getElementsByTagName('sysMessage')[0]; showToolTipFader(sysMessage.firstChild.nodeValue, $('rating4_' + itemID)); }, onFailure: function(){ alert('Eroare !'); } }); } // tooltip //end browser user var globalTimeout = ""; function showToolTipFader(texty,obj,doNotCloseAfter) { if($('tooltipX')) { document.body.removeChild($('tooltipX')); window.clearTimeout(globalTimeout); } var newdiv = document.createElement('div'); newdiv.id="tooltipX"; newdiv.style.display = "none"; //generating table inside div if(document.all) { var tbl = document.createElement(''); var tbb = document.createElement("tbody"); } else { var tbl = document.createElement('table'); var tbb = document.createElement("tbody"); tbl.setAttribute('cellpadding','0'); tbl.setAttribute('cellspacing','0'); tbl.setAttribute('border','0'); } // create up arrow td var row = document.createElement('tr'); if(document.all) var cell = document.createElement('
'); else var cell = document.createElement('td'); cell.setAttribute('colspan','3'); //create img var nimg = document.createElement('img'); if(document.all) nimg.src="images/pop-up/sageata_sus.gif"; else nimg.src="images/pop-up/sageata_sus.png"; nimg.className="tooltipUpArrow"; nimg.id = "toolArrowU"; cell.appendChild(nimg); row.appendChild(cell); tbb.appendChild(row); //end create up arrow td //create top tooltip var row = document.createElement('tr'); var cell = document.createElement('td'); cell.className="tooltipCorner_ul"; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipBar_u"; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipCorner_ur"; row.appendChild(cell); tbb.appendChild(row); //end create top tooltip if(doNotCloseAfter) { var imgClose = "Detaliu utilizator"; //create close tooltip var row = document.createElement('tr'); var cell = document.createElement('td'); cell.className="tooltipBar_l"; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipText"; cell.innerHTML=imgClose; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipBar_r"; row.appendChild(cell); tbb.appendChild(row); //end close tooltip } //create middle tooltip var row = document.createElement('tr'); var cell = document.createElement('td'); cell.className="tooltipBar_l"; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipText"; cell.innerHTML=texty; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipBar_r"; row.appendChild(cell); tbb.appendChild(row); //end middle tooltip //create bottom tooltip var row = document.createElement('tr'); var cell = document.createElement('td'); cell.className="tooltipCorner_bl"; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipBar_b"; row.appendChild(cell); var cell = document.createElement('td'); cell.className="tooltipCorner_br"; row.appendChild(cell); tbb.appendChild(row); //end create bottom tooltip // create down arrow td var row = document.createElement('tr'); if(document.all) var cell = document.createElement(''); else var cell = document.createElement('td'); cell.setAttribute('colspan','3'); //create img var nimg = document.createElement('img'); if(document.all) nimg.src="images/pop-up/sageata_jos.gif"; else nimg.src="images/pop-up/sageata_jos.png"; nimg.className="tooltipDownArrow"; nimg.id = "toolArrowD"; cell.appendChild(nimg); row.appendChild(cell); tbb.appendChild(row); //end create down arrow td tbl.appendChild(tbb); newdiv.appendChild(tbl); newdiv.className ="tooltipDiv"; //add tooltip to document document.body.appendChild(newdiv); //position tooltip setPopupPosition(obj,newdiv); Effect.Appear(newdiv.id,{duration:.2}); //set fade out if(!doNotCloseAfter) globalTimeout = window.setTimeout('Effect.Fade(\'tooltipX\', {duration:.3,from:1.0, to:0.0})',2500); //======================================== } function setPopupPosition(el, x) { var direction = "up"; var position = Position.cumulativeOffset(el); var scrollY = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop; var viewHeight = (navigator.userAgent.toLowerCase().indexOf("safari") != -1 && window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight; x.style.left = position[0]-40 + "px"; var popupTop = position[1] + Element.getHeight(el); if((popupTop + x.offsetHeight > scrollY + viewHeight) && (position[1] - x.offsetHeight > scrollY)) { popupTop = position[1] - x.offsetHeight ; } if(popupTop > (scrollY + Element.getHeight(x) + 40 + Element.getHeight(el))) { direction="down"; $('toolArrowD').style.visibility = "visible"; } else { $('toolArrowU').style.visibility = "visible"; } if(direction == "up") x.style.top = (popupTop+30) + "px"; else x.style.top = (popupTop - Element.getHeight(x) - (document.all ? 15 : 25) - Element.getHeight(el)) + "px"; } function hidePopup() { if($('tooltipX')) { document.body.removeChild($('tooltipX')); window.clearTimeout(globalTimeout); } }