         function getElementId ( id )
         {

                 if ( document.getElementById && document.getElementById(id) )
                      return document.getElementById(id) ;

                 if ( document.all && document.all[id] )
                      return document.all[id] ;

                 if ( document.layers && document.layers[id] )
                      return document.layers[id] ;

                 return false ;

         }

         function addMoreAnswers()
         {

         var tableId = $( 'tablePollAnswers' ) ;

         var numRows = tableId.getElementsByTagName('tr').length;

         newRow = numRows+1 ;

         if ( newRow > 20 )
         {

              alert( 'Sorry you can add max 20 answers.') ;

              return false ;

         }

              inputEl = document.createElement( 'input' ) ;

              inputEl.setAttribute( 'type', 'text' ) ;
              inputEl.setAttribute( 'name', 'pollAnswers[]' ) ;
              inputEl.setAttribute( 'id', 'pollAnswers' + newRow ) ;
              inputEl.setAttribute( 'value', '' ) ;
              inputEl.setAttribute( 'size', '50' ) ;
              inputEl.setAttribute( 'maxlength', '200' ) ;

              oRow = tableId.insertRow(-1) ;
              oTd = oRow.insertCell(-1) ;
              oTd.innerHTML = '<label for="pollAnswers' + newRow + '" title="Answer ' + newRow + '">' + newRow + ':</label>';
              oTd = oRow.insertCell(-1) ;
              oTd.appendChild(inputEl) ;

         }

         function checkPollQuestion()
         {

                  var inputField = document.forms['createPoll'].pollQuestion ;

                  if ( inputField.value == '' )
                  {

                       alert('Please write your question.') ;

                       inputField.style.border = '1px solid red' ;
                       inputField.style.background = '#FEB4B4' ;

                       inputField.focus() ;

                       return false;

                  }

                  var docAns = document.getElementsByName('pollAnswers[]');

                  var m = 0;

                  for ( var i = 0; i < docAns.length; i++)
                  {

                        if ( docAns[i].value )
                             m++;

                  }

                  if ( m < 2 )
                  {

                  alert('Please write atleast two answers.');

                  return false;

                  }

         }

         function checkPollConfig()
         {

                  var doc = document.forms['createPoll'] ;

                  if ( doc.configDescription.value == '' )
                  {

                       alert('Please write a description.');

                       doc.configDescription.style.border = '1px solid red';
                       doc.configDescription.style.background = '#FEB4B4';

                       doc.configDescription.focus();

                       return false;

                  }

         }

         function changeBox( id )
         {


                  if ( id == 'comboBox' )
                  {

                       showDiv( 'comboBox' ) ;
                       hideDiv( 'radioButton' ) ;
                       hideDiv( 'checkBoxes' ) ;

                  }else
                  if ( id == 'radioButton' )
                  {

                       hideDiv( 'comboBox' ) ;
                       showDiv( 'radioButton' ) ;
                       hideDiv( 'checkBoxes' ) ;

                  }else
                  if ( id == 'checkBoxes' )
                  {

                       hideDiv( 'comboBox' ) ;
                       hideDiv( 'radioButton' ) ;
                       showDiv( 'checkBoxes' ) ;

                  }

         }

         function showDiv( id )
         {

                  divId = $(id) ;
                  divId.style.display = 'block' ;

         }

         function hideDiv( id )
         {

                  divId = $(id) ;
                  divId.style.display = 'none' ;

         }

         function selectCheckBox( id )
         {

                  var trId = $( 'tr_' + id ) ;

                  var inputId = $( 'id_' + id ) ;

                  if ( inputId.checked ) trId.style.background = '#f6f6f6' ;
                  else
                       trId.style.background = '#FFFFFF' ;

         }

         function updateMyPoll()
         {

         var el = document.getElementsByName('questionId[]');

         var m = 0;

         for ( var i = 0; i < el.length; i++ )
         {

               if ( el[i].checked == false )
                    m++;

         }

         if ( el.length == m )
         {

              alert( 'Please select at least one field.' ) ;

              return false ;

         }else
         {
              var actionValue = $( 'pollAction' ) ;

              if ( actionValue.value == 0 )
              {

                   alert( 'Please select action of the selected fields!' ) ;

                   actionValue.style.border = '1px solid red' ;
                   actionValue.style.background = '#FEB4B4' ;
                   actionValue.focus() ;

                   return false ;

              }
              else
                   return confirm( 'Are you sure you want to ' + actionValue.value + ' this polls?' ) ;

         }

         }
		 
		 var slides = false;
		 var lastEl = 'hor';
		 function changeGraph(el, id, vertical)
		 {
			 if ( lastEl == el && slides == true )
			 	return;
			 
			 if (  slides == true && t )
			 	clearTimeout(t);
			 
			 var tableId = $( 'resultsTableId' ) ;
			 var divId = tableId.getElementsByTagName( 'div' ) ;
			 
			 for ( var i = 0; i <= divId.length-1; i++ )
             {
                  curId = divId[i].getAttribute( 'id' ) ;
                  
				  if ( el == 'hor' )
				  	$(curId).show();
				  else
				  	$(curId).hide();
             }
			 
			 if ( el == 'ver' )
			 {
				 $('verticalGraph').show();	
				 $('horIcon').style.backgroundColor = '#ffffff';
				 $('verIcon').style.backgroundColor = '#b8d5ff';
			 }
			 else
			 {
				 $('verticalGraph').hide();
				 $('horIcon').style.backgroundColor = '#b8d5ff';
				 $('verIcon').style.backgroundColor = '#ffffff';
			 }
			 							
			 lastEl = el;
			 animVotes(id, vertical);
		 }
				
         function animVotes(id, vertical)
         {
                  var tableId = $( id ) ;

                  if ( vertical == true )
				  	var divId = tableId.getElementsByTagName( 'li' ) ;
				  else
				  	var divId = tableId.getElementsByTagName( 'div' ) ;

				  for ( var i = 0; i <= divId.length-1; i++ )
                  {
                        curId = divId[i].getAttribute( 'id' ) ;                        
						$(curId).show() ;						
                        slideVotes( curId, 0, vertical ) ;
                  }

         }
		 
         function slideVotes(pollId, currentPercent, vertical)
         {

			 var divIdWidth = pollId.split(':');
			
			 if ( divIdWidth[1] == 0 )
			 	return;
			 
			 currentPercent = ((currentPercent/1) + 1) ;	
			 var obj = $( pollId ) ;						 
			 var calc = Math.round( currentPercent / 100*divIdWidth[1] );

				 if ( vertical == true )
					obj.style.height = calc + 'px' ;
				 else
					obj.style.width = calc + 'px' ;
		
				 if ( currentPercent < 100 ) 
				 {
					slides = true; 
					t = setTimeout( 'slideVotes("' + pollId + '", ' + currentPercent + ', ' + vertical + ')', 20) ;					
				 }
				 else
				 {
					slides = false;
					clearTimeout(t);
				 }

         }
		 
		 function sendToFlash(color, name, colorValueDefault)
		 {
			 /*for ( counter = 0; counter < document.createPoll.poll_type.length; counter++ )
			 {				
				if ( document.createPoll.poll_type[counter].checked && counter == 0 )
				{					
					return;
				}
						
			}*/
			
			 $('loading').show();
			 
			 var questionId = $('tempQuestionId').value;
			 var theme = $('tempFlashTheme').value;
			 
			 if ( typeof colorValueDefault != 'undefined' )
			 {
				 new Ajax.Request('flash', {
									   parameters : {'ajax' : 'live', 'section' : 'default', 'questionId' : questionId, 'colorValue' : colorValueDefault},
									   onComplete : function()
									   {
										var so = new SWFObject("http://www.addpoll.com/flashPoll.swf", "flashpolls", "300", "300", "9");
										so.addVariable("questionId", questionId);										
										so.write("write_flash");
										$('loading').hide();
									   }
				 });			 
			 }
			 else
			 {
				 new Ajax.Request('flash', {
								  parameters : {'ajax' : 'live', 'section' : name, 'questionId' : questionId, 'color' : color, 'theme' : theme},
								  onComplete : function()
								  {
									var so = new SWFObject("http://www.addpoll.com/flashPoll.swf", "flashpolls", "300", "300", "9");
									so.addVariable("questionId", questionId);
									so.addVariable("theme", theme);
									so.write("write_flash");
									$('loading').hide();
								  }
				 });
			 }
		 }
		 		 		 
						 
         function changePollColors(id, section, color, name)
         {
                 if ( typeof name != 'undefined' )
				 	sendToFlash(color, name);
				  
				  if ( color && id )
                  {

                  divId = $(id);

                  if ( section == 'bg' )
                       divId.style.background = color;
                  else if ( section == 'border' )
                  {

                        divId.style.borderRight = '2px solid ' + color;
                        divId.style.borderBottom = '1px solid ' + color;

                  }
                  else
                       divId.style.color = color;

                  }

         }

         function changeCustomColors(value)
         {

              if ( value )
              {

                  $('tempFlashTheme').value = 0;
				  sendToFlash('', '', value);
				  				  
				  var colorValue = value.split('#');

                  changePollColors('tempConfigPollColorTitle', 'bg', '#' + colorValue[1]);
                  changePollColors('tempConfigPollColorTitle', 'text', '#' + colorValue[2]);
                  changePollColors('tempConfigPollColorAnswers', 'bg', '#' + colorValue[3]);
                  changePollColors('tempConfigPollColorAnswers', 'text', '#' + colorValue[4]);
                  changePollColors('tempConfigPollColorButton', 'bg', '#' + colorValue[5]);
                  changePollColors('tempConfigResultsColorBar', 'bg', '#' + colorValue[6]);
                  changePollColors('tempConfigResultsColorBar', 'border', '#' + colorValue[7]);
				  
              }
               else
                   showDiv( 'customColors' );

         }
		 
		 function changeAlign(align)
		 {
			sendToFlash(align, 'configPollAlign');
			$('tempConfigPollColorTitle').setStyle({textAlign : align});
			$('tempConfigPollColorAnswers').setStyle({textAlign : align});
			$('tempConfigPollSubmitButton').setStyle({textAlign : align});
		 }

         function checkContacts()
         {

                  var form = document.forms[0];

                  for ( var i = 0; i < form.length - 1; i++ )
                  {

                        if ( !form.elements[i].value )
                        {

                              alert('Please fill the field ' + form.elements[i].name);

                              actionValue = $(form.elements[i].id);

                              actionValue.style.border = '1px solid red' ;
                              actionValue.style.background = '#FEB4B4' ;
                              actionValue.focus() ;

                              return false;

                        }

                  }

                  return true;

         }
		 
		 function _demo(full)
		 {
			
			if ( full == 0 )
			{
				$('full_custom_demo').show(); 
				$('flash_demo').hide();
				$('flash_theme').hide();
			}else
			{
				$('full_custom_demo').hide(); 
				$('flash_demo').show();	
				$('flash_theme').show();
			}
		 }
		 
		 function _preview_flash(questionId, id)
		 {	
				$R(0, 14).each(function(value) {
					$('img_' + value).removeClassName('flashImgPreview');  
				});
				$('img_' + id).addClassName('flashImgPreview');	
				$('tempFlashTheme').value = id;
				
				var so = new SWFObject("http://www.addpoll.com/flashPoll.swf", "flashpolls", "300", "300", "9");
				so.addVariable("questionId", "" + questionId + "");				
				so.addVariable("theme", "" + id + "");
					
				so.write("write_flash");
		 }