var flashvars={};var params={};params.play="true";params.loop="true";params.wmode="transparent";var attributes={};attributes.id="logo-flash";swfobject.embedSWF("/media/flash/logo.swf","logo","795","82","9.0.0",false,flashvars,params,attributes);function fixFooter()
{var contentHeight=$("#content").height();var minHeight=0-$('#header-wrap').outerHeight();var viewportHeight=(window.innerHeight||document.documentElement&&document.documentElement.clientHeight||document.body.clientHeight)-$('#header-wrap').outerHeight()-$('#footer-wrap').outerHeight();if(minHeight>viewportHeight&&minHeight>contentHeight)
{$('#content-wrap').height(minHeight);}
else if(viewportHeight>contentHeight)
{$('#content-wrap').height(viewportHeight);}
else
{$('#content-wrap').height(contentHeight);}}
$(window).bind('resize',function()
{fixFooter();});$(window).bind('load',function()
{fixFooter();});$(document).ready(function()
{var progressKey=$("#progress_key").val();$('.m-nav').fadingLinks({color:'#ffffff',duration:500});$('.g-nav').fadingLinks({color:'#999999',duration:500});$('.a-nav').fadingLinks({color:'#666666',duration:500});$('input:not(".radius"),textarea,select').focus(function()
{$(this).css('background','#FFFFDB');});$('input:not(".radius"),textarea,select').blur(function()
{$(this).css('background','#ffffff');});$('.forms').find('.required').append(' <em>*</em>');$('.grid-view img').mouseover(function(){$(this).css('border','1px solid #666666');});$('.grid-view img').mouseout(function(){$(this).css('border','1px solid #cccccc');});$('.wg1-trigger').click(function(){$('.warehouse-gallery').fancybox({'showNavArrows':true,'title':'Click left or right for next image'}).trigger('click');});$('.image-upload').parent().append(' <a class="add-upload">Add</a>');$('.add-upload').live('click',function(){last=$('.image-upload:last').attr('id');newId=parseInt(last.substring(6))+1;if(newId<10)
{elementId='image-'+newId;$('.add-upload').before('<input type="file" name="image[]" id="'+elementId+'" class="image-upload" />');fixFooter();if(newId==9)
{$('.add-upload').css('display','none');}}});$(".forms #name").autocomplete({'source':'/flyers/autocomplete/event','minLength':3});$(".forms #venue").autocomplete({'source':'/flyers/autocomplete/venue','minLength':2});$(".forms #location").autocomplete({'source':'/flyers/autocomplete/location','minLength':2});$(".forms #organiser").autocomplete({'source':'/flyers/autocomplete/organiser','minLength':2});$(".forms #designer").autocomplete({'source':'/flyers/autocomplete/designer','minLength':2});$(".event-gallery").fancybox();$('.eg1-trigger').click(function(){$('.event-gallery').fancybox().trigger('click');});$(".press-image").fancybox();$("#dialog").dialog({autoOpen:false,resizable:false,modal:true});$("#upload-form").submit(function(e){v=new ValidateUploadForm();if(v.hasErrors())
{return false;}
else
{$("#dialog").dialog({title:"Please wait"});var i=setInterval(function(){var url="/flyers/progress?id="+progressKey+"&rand="+Math.random();$.getJSON(url,function(data){if(data==null){$("#dialog").dialog("close");clearInterval(i);location.reload(true);return;}
var percentage=Math.floor(100*parseInt(data.current)/parseInt(data.total));$(".upload-data").width(parseInt(percentage)+"%");$("#dialog").dialog("open");if(data.current!=data.total)
{$("#dialog").html('<div class="upload-progress"><p><b>Upload in progress</b></p><div class="upload-bar"><div style="background-color: #ccc; height: 22px; width:'+percentage+'% ;"> </div></div><p><b>Total data : </b>'+Math.round(data.total/1024)+'kb    <b>Completed : </b>'+percentage+'%</p></div>');}
else
{$("#dialog").html('<div class="upload-progress"><p>Processing images, this could take a couple of minutes please wait</p></div>');}});},750);}});});function ValidateUploadForm()
{$(".errors").remove();var hasErrors=false;this.hasErrors=function()
{this._validateGenre();this._validateName();this._validateVenue();this._validateLocation();this._validateOrganiser();this._validateDesigner();return hasErrors;}
this._validateGenre=function()
{var item="#genre";if(this._isNull(item))
{this._setFormError(item,"Genre is empty");hasErrors=true;}}
this._validateName=function()
{var item="#name";if(this._isNull(item))
{this._setFormError(item,"Name is empty");hasErrors=true;}
else if(this._isLengthOk(item))
{this._setFormError(item,"Event name needs to be between 3-60 chars");hasErrors=true;}
else if(this._isClean(item))
{this._setFormError(item,"Event name contains illegal characters");hasErrors=true;}}
this._validateVenue=function()
{var item="#venue";if(this._isLengthOk(item))
{this._setFormError(item,"Venue needs to be between 3-60 chars");hasErrors=true;}
else if(this._isClean(item))
{this._setFormError(item,"Venue contains illegal characters");hasErrors=true;}}
this._validateLocation=function()
{var item="#location";if(this._isLengthOk(item))
{this._setFormError(item,"Location needs to be between 3-60 chars");hasErrors=true;}
else if(this._isClean(item))
{this._setFormError(item,"Location contains illegal characters");hasErrors=true;}}
this._validateOrganiser=function()
{var item="#organiser";if(this._isLengthOk(item))
{this._setFormError(item,"Organiser needs to be between 3-60 chars");hasErrors=true;}
else if(this._isClean(item))
{this._setFormError(item,"Organiser contains illegal characters");hasErrors=true;}}
this._validateDesigner=function()
{var item="#designer";if(this._isLengthOk(item))
{this._setFormError(item,"Designer needs to be between 3-60 chars");hasErrors=true;}
else if(this._isClean(item))
{this._setFormError(item,"Designer contains illegal characters");hasErrors=true;}}
this._isLengthOk=function(item)
{var val=$(item).val();if(val!="")
{if(val.length<3||val.length>60)
{return true;}}
return false;}
this._isClean=function(item)
{var re=new RegExp("^[a-zA-Z0-9\/()?!.&,; ]*$");var val=$(item).val();if(!re.test(val))
{return true;}
return false;}
this._isNull=function(item)
{if($(item).val()=="")
{return true;}
return false;}
this._setFormError=function(item,msg)
{var element=item+"-element";var html='<ul class="errors"><li>'+msg+'</li></ul>'
$(element+"> .errors").remove();$(element).append(html);}}
