(function($){$.fn.doubleSelect=function(doubleid,values,options){options=$.extend({preselectFirst:null,preselectSecond:null,emptyOption:false,emptyKey:-1,emptyValue:'Choose ...'},options||{});var $first=this;var $secondid="#"+doubleid;var $second=$($secondid);var setValue=function(value){$second.val(value).change();}
var removeValues=function(){$($secondid+" option").remove();};$(this).change(function(){removeValues();
$current=this.options[this.selectedIndex].value;
//if($current=='10'){document.getElementById('box').style.visibility='hidden';};
//alert($current);

if($current!='Magazine Advertisement' && $current!='nothing'){document.getElementById('box').style.visibility='visible'}else {document.getElementById('box').style.visibility='hidden';};
if($current!=''){$.each(values,function(k,v){var bestk;if($current==v.key){$.each(v.values,function(k,v2){if(!bestk&&(v.defaultvalue!=null&&v2==v.defaultvalue)){bestk=k;}
if(options.preselectSecond!=null&&v2==options.preselectSecond){bestk=k;}});
$.each(v.values,function(k,v2){var o=$("<option>").html(k).attr('value',v2);if(k===bestk)o.html(k).attr("selected","selected");o.appendTo($second);});}});}else{setValue(options.emptyValue);}});return this.each(function(){$first.children().remove();$second.children().remove();if(options.emptyOption){var oe=$("<option>").html(options.emptyValue).attr('value',options.emptyKey);oe.appendTo($first);}
$.each(values,function(k,v){var of=$("<option>").html(k).attr('value',v.key);if(options.preselectFirst!=null&&v.key==options.preselectFirst){of.html(k).attr("selected","selected");}
of.appendTo($first);});if(options.preselectFirst==null){$current=this.options[this.selectedIndex].value;if($current!=''){$.each(values,function(k,v){var bestk;if($current==v.key){$.each(v.values,function(k,v2){if(!bestk&&(v.defaultvalue!=null&&v2==v.defaultvalue)){bestk=k;}

if(options.preselectSecond!=null&&v2==options.preselectSecond){bestk=k;}});$.each(v.values,function(k,v2){var o=$("<option>").html(k).attr('value',v2);if(k===bestk)o.html(k).attr("selected","selected");o.appendTo($second);});}});}else{setValue(options.emptyValue);}}else{$first.change();}});};})(jQuery);