var choiceType="radio";var sampleStyles=[["#E7F6F8","#FA6B3E","#3A555C","#65C3E0",null],["#FFFFFF","#008DC2","#3A555C","#CCCCCC",null],["#F8E7F7","#A87AFA","#3A555C","#F87CE1",null],["#6BCFEE","#1049BD","#09265F","#0F78E0","/poll/img/designs/blue_bubble.png"],["#FBFFB2","#FF7C00","#3A555C","#DBDC30","/poll/img/designs/yellow_star.png"],["#4A4A4A","#82BFFF","#FFFFFF","#000000",null],["#FA876C","#FFFFFF","#000000","#FA3527","/poll/img/designs/red_diagonal_up_stripe.png"]];var currentImageChoice=null;var currentQuestion=null;function EscapeHTML(c){var d="";for(var a=0;a<c.length;++a){var b=c.charAt(a);if(b=="&"){b="&amp;"}else{if(b=="<"){b="&lt;"}else{if(b=='"'){b="&quot;"}else{if(b==">"){b="&gt;"}}}}d+=b}return d}function finishedUploadingImage(d,c){$.fn.fancybox.close();if(currentImageChoice!=null){var b=currentImageChoice;b.find('input[name="choice_image_urls[]"]').val(c);b.find('input[name="choice_images[]"]').val(d);b.find("img").attr("src","/poll/img/create/image_delete.png");b.find("a").unbind("click");b.find("a").click(function(){b.find('input[name="choice_image_urls[]"]').val("");b.find('input[name="choice_images[]"]').val("");b.find("img").attr("src","/poll/img/create/image_add.png");updatePreviewChoices();fancybox(b.find("a"));b.find("a").click(function(){currentImageChoice=b;currentQuestion=null});return false});updatePreviewChoices()}else{var a=currentQuestion;a.find('input[name="question_image_url"]').val(c);a.find('input[name="question_image"]').val(d);a.find("img").attr("src","/poll/img/create/image_delete.png");a.find("a").unbind("click");a.find("a").click(function(){a.find('input[name="question_image_url"]').val("");a.find('input[name="question_image"]').val("");a.find("img").attr("src","/poll/img/create/image_add.png");updatePreviewTitle();fancybox(a.find("a"));a.find("a").click(function(){currentImageChoice=null;currentQuestion=a});return false});updatePreviewTitle()}}function updatePreviewTitle(){var b=$("#question");var d=$("#poll_question").val();var c=b.find('input[name="question_image_url"]').val();if(c!==""){var a='<img src="'+c+'" />';if(d!==""){a="<br />"+a}d+=a}$("#title").html(d)}function addNextChoiceIfNeeded(){var b=$("#choices li").filter(function(){return $(this).find('input[name="choices[]"]').val()===""&&$(this).find('input[name="choice_images[]"]').val()===""}).size();if(b==0){var a=$("#choices li").size()-1;addNewChoice(a)}}function updatePreviewChoices(){var b="";var a=0;$("#choices li").each(function(){var d=$(this).find('input[name="choices[]"]').val();var c=$(this).find('input[name="choice_image_urls[]"]').val();if(d!==""||c!==""){if(c!==""){c='<img src="'+c+'" />';if(d!==""){c="<br />"+c}}if(c!==""){$(this).find("img").attr("src","/poll/img/create/image_delete.png")}b+='<div class="preview_choice"><div class="preview_radio"><input type="'+choiceType+'" class="preview_radio" name="preview" id="preview_choice_'+a+'" /></div><div class="preview_text"><p><label for="preview_choice_'+a+'">'+d+c+"</label></p></div></div>"}a++});$("#answers").html(b);addNextChoiceIfNeeded()}function bindQuestionUpdates(){$("#poll_question").keyup(updatePreviewTitle).blur(updatePreviewTitle)}function bindChoiceUpdates(){$("#choices :text").keyup(updatePreviewChoices).blur(updatePreviewChoices)}function addNewChoice(c){var a='<li id="choice'+(c+1)+'"><p><input class="answer text" name="choices[]" type="text" /></a><input name="choice_images[]" type="hidden" style="display: none;" /><input name="choice_image_urls[]" type="hidden" style="display: none;" disabled="disabled" /></p></li>';$("#choices ol").append(a);var b=$("#choice"+(c+1));setupImageLink(b);setupChoice(b);bindChoiceUpdates()}function setupImageLink(a){a.find(":text").after(' <a href="/poll/images/new" class="image_link iframe"><img class="add_image" src="/poll/img/create/image_add.png" />');fancybox(a.find("a"));a.find("a").click(function(){currentImageChoice=a;currentQuestion=null})}function setupQuestionImageLink(){var a=$("#question");a.find(":text").after(' <a href="/poll/images/new" class="image_link iframe"><img class="add_image" src="/poll/img/create/image_add.png" /></a>');fancybox(a.find("a"));a.find("a").click(function(){currentImageChoice=null;currentQuestion=a})}function fancybox(a){a.fancybox({frameWidth:420,frameHeight:350})}function setupChoices(){$("#choices li").each(function(a){if($(this).find(":text").val()!==""){setupChoice($(this));setupImageLink($(this))}else{if(a!=0){$(this).remove()}}});if($("#choices li").size()==1){$("#choices li:first").each(function(){setupChoice($(this));setupImageLink($(this))})}else{addNextChoiceIfNeeded()}}function setupChoice(a){a.find(":text").focus(highlight).focus(addNextChoiceIfNeeded).blur(removeHighlight).blur(addNextChoiceIfNeeded)}function setPreviewBackgroundColor(a){$("#poll_background_color").val(a);$("#poll_background_color_image").css("background-color",a);$("#preview").css("backgroundColor",a)}function setPreviewQuestionColor(a){$("#poll_title_color").val(a);$("#poll_title_color_image").css("background-color",a);$("#title").css("color",a)}function setPreviewChoiceColor(a){$("#poll_choice_color").val(a);$("#poll_choice_color_image").css("background-color",a);$(".preview_choice").css("color",a)}function setPreviewBorderColor(a){$("#poll_border_color").val(a);$("#poll_border_color_image").css("background-color",a);$("#preview").css("border","1px solid "+a)}function setPreviewBackgroundImage(b){if(b!=null){$("#preview").css("backgroundImage","url("+b+")");$("#design_swatch").css("backgroundImage","url("+b+")");var a=b.split("/");$("#poll_style").val(a[a.length-1])}else{$("#preview").css("backgroundImage","");$("#design_swatch").css("backgroundImage","");$("#poll_style").val("")}}function setupStyleButtons(){$("#styles input:button").each(function(a){$(this).click(function(){setPreviewBackgroundColor(sampleStyles[a][0]);setPreviewQuestionColor(sampleStyles[a][1]);setPreviewChoiceColor(sampleStyles[a][2]);setPreviewBorderColor(sampleStyles[a][3]);setPreviewBackgroundImage(sampleStyles[a][4])})})}function highlight(){$(this).addClass("selected")}function removeHighlight(){$(this).removeClass("selected")}function setupFocusBackgrounds(){$(":text").focus(highlight).blur(removeHighlight)}function setupSubmit(){$("#create_form").submit(function(){$("#create_button").attr("disabled","disabled")})}function setupAllowsMultipleChoicesOption(){$("#poll_allows_multiple_choices").click(function(){if($(this).is(":checked")){choiceType="checkbox"}else{choiceType="radio"}updatePreviewChoices()})}function updateColors(){setPreviewBackgroundColor($("#poll_background_color").val());setPreviewQuestionColor($("#poll_title_color").val());setPreviewChoiceColor($("#poll_choice_color").val());setPreviewBorderColor($("#poll_border_color").val());if($("#poll_style").val()!=""){setPreviewBackgroundImage("/poll/img/designs/"+$("#poll_style").val())}}function setupColorPickers(){$("#colors tr:not(:last)").each(function(){$(this).prepend('<td style="width: 20px; height: 24px;"><img src="/poll/img/create/swatch.gif" width="24" height="20" id="'+$(this).find("input").attr("id")+'_image" /></td>');var b=$(this).find("input").get(0);var a=$(this).find("img").get(0);var c=new jscolor.color(a,{valueElement:b,styleElement:a,hash:true});c.visible=false;c.oldExport=c.exportColor;c.exportColor=function(d){c.oldExport(d);updateColors()};$(this).find("img").click(function(){if(c.visible){c.hidePicker()}else{c.importColor();c.showPicker()}c.visible=!c.visible});$(this).find("input").focus(updateColors).blur(updateColors).change(updateColors)})}function setupDesignPicker(){var d=[["blue_horizontal_stripe.png","green_horizontal_stripe.png","pink_horizontal_stripe.png","purple_horizontal_stripe.png","red_horizontal_stripe.png","yellow_horizontal_stripe.png"],["yellow_vertical_stripe.png","red_vertical_stripe.png","purple_vertical_stripe.png","pink_vertical_stripe.png","green_vertical_stripe.png","blue_vertical_stripe.png"],["blue_diagonal_up_stripe.png","green_diagonal_up_stripe.png","pink_diagonal_up_stripe.png","purple_diagonal_up_stripe.png","red_diagonal_up_stripe.png","yellow_diagonal_up_stripe.png"],["yellow_diagonal_down_stripe.png","red_diagonal_down_stripe.png","purple_diagonal_down_stripe.png","pink_diagonal_down_stripe.png","green_diagonal_down_stripe.png","blue_diagonal_down_stripe.png"],["blue_bubble.png","green_bubble.png","pink_bubble.png","purple_bubble.png","red_bubble.png","yellow_bubble.png"],["yellow_star.png","red_star.png","purple_star.png","pink_star.png","green_star.png","blue_star.png"]];$("#colors tr:last").prepend('<td style="width: 20px; height: 24px;"><img src="/poll/img/create/swatch.gif" width="24" height="20" id="design_swatch" /></td><td><label>Pattern</label></td>');var a=$("#colors tr:last img");var c='<table id="design_images" style="display: none; border: 1px solid #838383; background-color: #EEE; border-spacing: 2px; position: absolute;">';for(var e in d){c+='<tr style="margin: 0; padding: 0;">';for(var b in d[e]){c+='<td style="padding: 0; margin: 0; border:1px solid #838383; width:20px; height: 20px;"><img width="20" height="20" style="vertical-align: bottom;" src="/poll/img/designs/'+d[e][b]+'" /></td>'}c+="</tr>"}c+='<tr><td colspan="6"><input style="width: 100%;" type="button" value="None" /></td></tr>';c+="</table>";$("body").append(c);$("#design_images input").click(function(){$("#design_images").hide();setPreviewBackgroundImage(null)});$("#design_images img").each(function(){$(this).click(function(){$("#design_images").hide();setPreviewBackgroundImage($(this).attr("src"))}).hover(function(){$(this).parent().attr("style","padding: 0; margin: 0; border: 1px solid blue;")},function(){$(this).parent().attr("style","padding: 0; margin: 0; border: 1px solid #838383")})});a.click(function(){if($("#design_images:visible").size()){$("#design_images").hide()}else{var f=$(this).position().left;var g=$(this).position().top+$(this).height()+1;$("#design_images").css({top:g,left:f});$("#design_images").show()}})}$(document).ready(function(){bindQuestionUpdates();bindChoiceUpdates();setupFocusBackgrounds();setupChoices();setupQuestionImageLink();setupStyleButtons();setupColorPickers();setupDesignPicker();setupSubmit();setupAllowsMultipleChoicesOption();updatePreviewChoices();updatePreviewTitle();updateColors();setInterval("addNextChoiceIfNeeded()",1000)});
