/* blank-TV.de
 * 
 * Revision: $Rev: 187 $
 * Last changed: $Date: 2006-08-14 02:19:17 +0200 (Mo, 14 Aug 2006) $
 * By: $Author: runner $
 */

// create dd menus
var myMenu1 = new ypSlideOutMenu("menu1", "down", -1000, 103, 170, 60);
var myMenu2 = new ypSlideOutMenu("menu2", "down", -1000, 103, 200, 130);
var myMenu3 = new ypSlideOutMenu("menu3", "down", -1000, 103, 200, 60);
var myMenu4 = new ypSlideOutMenu("menu4", "down", -1000, 103, 170, 60);
var myMenu5 = new ypSlideOutMenu("menu5", "down", -1000, 103, 170, 100);
var myMenu6 = new ypSlideOutMenu("menu6", "down", -1000, 103, 170, 130);
var myMenu7 = new ypSlideOutMenu("menu7", "down", -1000, 103, 130, 130);

// assign events to dd menus
myMenu1.onactivate = function() { repositionMenu(myMenu1, 295); }
myMenu2.onactivate = function() { repositionMenu(myMenu2, 391); }
myMenu3.onactivate = function() { repositionMenu(myMenu3, 487); }
myMenu4.onactivate = function() { repositionMenu(myMenu4, 583); }
myMenu5.onactivate = function() { repositionMenu(myMenu5, 679); }
myMenu6.onactivate = function() { repositionMenu(myMenu6, 775); }
myMenu7.onactivate = function() { repositionMenu(myMenu7, 871); }

// functions for the calculation of menus
function repositionMenu(menu, offset) {
	// the new left position should be the center of the window + the offset
	var newLeft = /*getWindowWidth() / 2 +*/ offset;
	
	// setting the left position in netscape is a little different than IE
	menu.container.style ? menu.container.style.left = newLeft + "px" : menu.container.left = newLeft;
}

// this function calculates the window's width - different for IE and netscape
function getWindowWidth() {
	return window.innerWidth ? window.innerWidth : document.body.offsetWidth;
}

// functions for the calculation of menus
function repositionMenu(menu, offset) {
	// the new left position should be the center of the window + the offset
	var newLeft = /*getWindowWidth() / 2 +*/ offset;
	
	// setting the left position in netscape is a little different than IE
	menu.container.style ? menu.container.style.left = newLeft + "px" : menu.container.left = newLeft;
}

// this function calculates the window's width - different for IE and netscape
function getWindowWidth() {
	return window.innerWidth ? window.innerWidth : document.body.offsetWidth;
}



ypSlideOutMenu.writeCSS();



/* Poll submit */
function submitPoll(votenum, pollid)
{
		Element.show('saving_poll');
		var url = '/backend/pollvote.php';
		var pars = 'no='+ votenum +'&pollid='+ pollid;
		var myAjax = new Ajax.Request(
					url,
					{method: 'post', parameters: pars, onComplete: parseData}
					);
		
	    function parseData(originalRequest)
	    {
	    	   var response = originalRequest.responseXML.documentElement;
	    	   var poll = response.getElementsByTagName('poll');



				var newUl = document.createElement("ul");
				newUl.style.marginLeft = "0";
				newUl.style.marginTop = "0";
				newUl.style.marginBottom = "0";
				newUl.style.padding = "0";
				newUl.style.listStyleType = "none";
				
				for(i = 0; i < poll.length; i++)
				{

					if(poll[i].getElementsByTagName("antwort")[0].hasChildNodes())
	                 	{
	                 	antwort = poll[i].getElementsByTagName("antwort")[0].firstChild.nodeValue;
	                 	}
					
					if(poll[i].getElementsByTagName("prozent")[0].hasChildNodes())
	                 	{
	                 	prozent = poll[i].getElementsByTagName("prozent")[0].firstChild.nodeValue;
	                 	}	                 	
					
					if(poll[i].getElementsByTagName("breite")[0].hasChildNodes())
	                 	{
	                 	breite = poll[i].getElementsByTagName("breite")[0].firstChild.nodeValue;
	                 	}
                        
                  		newLi = document.createElement("li");
                        
						newLi.innerHTML = antwort +'<br /><img src="/images/pollbalken/pollbar_end.jpg" width="1" height="9" alt="" /><img src="/images/pollbalken/pollbar.jpg" width="'+ breite +'" height="9" alt="" /><img src="/images/pollbalken/pollbar_end.jpg" width="1" height="9" alt="" /> ('+ prozent +'%)';
						newLi.style.fontSize = "11px";
						newUl.appendChild(newLi);
				}
			Element.hide('saving_poll');

			$('poll_data').innerHTML = '';
			$('poll_data').appendChild(newUl);
	    }
}

