var prefs = new _IG_Prefs(); var currentPage = 1; //prefs.getInt('page'); var currentQuestion = 1; //prefs.getInt('question'); var tabs; var basePath = 'http://gpco2quickcheck-es.googlecode.com/svn/trunk/'; // Feed-Stuff var feedUrl = 'http://www.greenpeace.org/rss/espana/news/'; var maxFeedItems = 3; _IG_RegisterOnloadHandler(initGadget); function initGadget(){ tabs = new _IG_Tabs(moduleId, "Minitest de emisión de CO2 ", _gel("tab_div")); tabs.addTab("Minitest de emisión de CO2", "content_quick_check", _IG_AdjustIFrameHeight); tabs.addTab("Noticias", "content_aktuelles", _IG_AdjustIFrameHeight); tabs.alignTabs("left", 5); initFeedItems(); //goPage(4); _IG_AdjustIFrameHeight(); } function initFeedItems(){ _IG_FetchXmlContent(feedUrl, function (response) { if (response == null || typeof(response) != "object" || response.firstChild == null) { _gel("feedItems").innerHTML = "Invalid data."; return; } var compositeFeeds = {}; var feedItems = response.getElementsByTagName("item"); var itemCounter = 0; for (var i = 0; i < feedItems.length; i++) { var item = parseItem(feedItems.item(i)); if(!compositeFeeds[item.title]){ itemCounter++; if(itemCounter > maxFeedItems) break; item.thumbs = {}; item.thumbs[item.thumb] = item.thumb; item.images = {}; item.images[item.thumb] = item.image; compositeFeeds[item.title] = item; } else{ compositeFeeds[item.title].thumbs[item.thumb] = item.thumb; compositeFeeds[item.title].images[item.thumb] = item.image; } } var html = ""; var count = 0; for (var i in compositeFeeds) { item = compositeFeeds[i]; html += "
" + "
" + " " + "" + item.title + "" + "
"; html += "

" + crop(item.description) + " más...

"; html += "

"; for(var j in item.thumbs){ html += " "; } html += "

"; html += "
"; count++; } _gel("feedItems").innerHTML = html; toggleFeedSummary(0); }); } function goPage(nextPage){ _gel('p'+currentPage).style.display = 'none'; _gel('p'+nextPage).style.display = 'block'; _IG_AdjustIFrameHeight(); currentPage = nextPage; if(currentPage == 1){ _gel("tab_div").style.backgroundImage = "url('" + basePath + "img/00_start.jpg')"; } if(currentPage == 2){ currentQuestion = 0; goQuestion(currentQuestion); _gel("tab_div").style.backgroundImage = "url('" + basePath + "img/00_start.jpg')"; } if(currentPage == 3){ _gel('result').innerHTML = result(); _gel("tab_div").style.backgroundImage = "url('" + basePath + "img/08_auswertung.jpg')"; } if(currentPage == 4){ _gel('detail').innerHTML = detail(); _gel("tab_div").style.backgroundImage = "url('" + basePath + "img/08_auswertung.jpg')"; } prefs.set('page', currentPage); } function goQuestion(nextQuestion){ if(nextQuestion < question.length){ currentQuestion = nextQuestion; _gel("tab_div").style.backgroundImage = "url('" + basePath + "img/" + question[currentQuestion]['photo'] + "')"; _gel('question').innerHTML = printQuestion(currentQuestion); _IG_AdjustIFrameHeight(); } else { goPage(currentPage+1); } prefs.set('question', currentQuestion); } function printQuestion(q){ var out = ''; out += '

'+question[q]['headline']+'

'; out += ''; for(n in question[q]['questions']){ if(question[q]['questions'][n].length > 2 && question[q]['questions'][n][2] == 1){ value = '0'; if(prefs.getString('q'+q+'n'+n) > 0){ value = prefs.getString('q'+q+'n'+n); } out += ''; } else{ checked = ''; if(prefs.getString('q'+q+'n'+n) > 0){ checked = ' checked="checked"'; } out += ''; } } out += '

 

 
'; out += '


'; out += '
'; out += '
Siguiente
'; out += '
'; for(n = 1; n < question.length; n++){ cl = ' p0'; if(n <= q){ cl = ' p1'; } out += '
'; } return out; } function setPrefs(q, n, el){ if(el.type == 'checkbox'){ value = 0; if(el.checked){ value = el.value; } } else{ value = el.value; } prefs.set('q'+q+'n'+n, value); // _gel('debug').innerHTML = 'Debug: '+summarize()+' kg'; // For debugging only } function result(){ sum = summarize(); var out = ''; if(sum <= 3343){ out += '

' + resultTexts[0]['hl'] + '

'; out += '

' + resultTexts[0]['txt'] + '

'; } else if(sum > 3343 && sum <= 6686){ out += '

' + resultTexts[1]['hl'] + '

'; out += '

' + resultTexts[1]['txt'] + '

'; } else if(sum > 6686){ out += '

' + resultTexts[2]['hl'] + '

'; out += '

' + resultTexts[2]['txt'] + '

'; } return out; } function detail(){ var sum = 0; var out = ''; out += ''; out += ''; out += ''; zsum = 0; for(q in question){ if(question[q]['continue'] == 1){ zsum += summarize(q); } if(question[q]['continue'] == 0){ zsum += summarize(q); out += ''; sum += zsum; zsum = 0; } } out += ''; out += ''; out += '
Potencial de ahorro Kg. CO2
 
'+question[q]['category']+' '+zsum+' kg
 
Suma '+sum+' kg
'; return out; } function summarize(q){ var sum = 0; if(q){ for(n in question[q]['questions']){ if(question[q]['questions'][n].length > 2 && question[q]['questions'][n][2] == 1){ sum += Math.round(prefs.getInt('q'+q+'n'+n) * (question[q]['questions'][n][1] / 100)); } else{ sum += prefs.getInt('q'+q+'n'+n); } } } else{ for(q in question){ for(n in question[q]['questions']){ if(question[q]['questions'][n].length > 2 && question[q]['questions'][n][2] == 1){ sum += prefs.getInt('q'+q+'n'+n) * (question[q]['questions'][n][1] / 100); } else{ sum += prefs.getInt('q'+q+'n'+n); } } } } return sum; } function clearValues(){ for(q in question){ for(n in question[q]['questions']){ prefs.set('q'+q+'n'+n, 0); } } } function showLargeImage(hl, img){ var view = _gel("detailView"); var html = "

" + hl + "

"; html += "

"; html += "
Volver
"; view.innerHTML = html; view.style.display = "block"; _gel("feedItems").style.display = "none"; _IG_AdjustIFrameHeight(); } function backToFeed(){ _gel("detailView").style.display = "none"; _gel("feedItems").style.display = "block"; _IG_AdjustIFrameHeight(); } function toggleFeedSummary(i){ var feedIcon = _gel("feedIcon_" + i); var feedSummary = _gel("feedSummary_" + i); var feedImages = _gel("feedImages_" + i); if(feedIcon.className == "opened"){ feedIcon.className = "closed"; feedSummary.style.display = "none"; feedImages.style.display = "none"; } else{ feedIcon.className = "opened"; feedSummary.style.display = "block"; feedImages.style.display = "block"; } _IG_AdjustIFrameHeight(); } function parseItem(itemXml){ var item = {}; for (var i = 0; i < itemXml.childNodes.length ; i++) { var node = itemXml.childNodes.item(i); if(node.nodeName == "enclosure"){ item.thumb = node.getAttribute('url'); } if(node.nodeName == "title"){ item.title = node.firstChild.nodeValue; } if(node.nodeName == "link"){ item.link = node.firstChild.nodeValue; } if(node.nodeName == "description"){ item.description = node.firstChild.nodeValue; } if(node.nodeName == "guid"){ item.image = node.firstChild.nodeValue; } } return item; } function openReminder(){ var settings = '['; var totalCounter = 0; for(q in question){ var subString = ''; for(n in question[q]['questions']){ if(prefs.getInt('q'+q+'n'+n) != 0){ subString += n + ':' + prefs.getInt('q'+q+'n'+n); subString += ','; } } settings += '{' + subString.substr(0, subString.length - 1) + '}' if(totalCounter < question.length - 1){ settings += ','; } totalCounter++; } settings += ']'; launchWindow('http://gpco2gadget.googlepages.com/reminder_bogen_es.html#' + settings, 615, 800); } // utility functions function launchWindow(doct, popW, popH){ var w, h; var x, y; if(self.innerHeight){ // all except Explorer w = self.innerWidth; h = self.innerHeight; } else if(document.documentElement && document.documentElement.clientHeight){ // Explorer 6 Strict Mode w = document.documentElement.clientWidth; h = document.documentElement.clientHeight; } else if(document.body){ // other Explorers w = document.body.clientWidth; h = document.body.clientHeight; } var leftPos = (w-popW)/2, topPos = (h-popH)/2; window.open(doct, '', 'width='+popW+',height='+popH+',top='+topPos+',left='+leftPos+',menubar=no,locationbar=no,statusbar=no,resizable=yes,toolbar=no,dependent=yes,scrollbars=no').focus(); } function getWindowWidth(){ if (window.innerWidth) { return window.innerWidth; } else { if (window.document.documentElement && window.document.documentElement.clientWidth){ return window.document.documentElement.clientWidth; } return window.document.body.offsetWidth; } } function crop(text){ var cropPos = 200; for(var i = 200; i < 250; i++){ if(text[i] == " "){ cropPos = i; break; } } return text.substring(0, cropPos) + " ..."; } function printDebugMsg(debugMsg){ debugDiv = _gel("debug"); debugDiv.innerHTML = debugDiv.innerHTML + debugMsg + "

"; }