
var utilsFunctions={infoSlider:function(selector,content,wrapper){$(content,wrapper).hide();$(selector).bind('click',function(e){if(!$('*:animated').length){var $context=$(e.target).parents(wrapper);if($(content,$context).is(':visible')){$context.removeClass('open');$(content,$context).slideUp(250,function(){$(this).hide();});return false;}
else
if($('li.open').length){$(content,'li.open').slideUp(250,function(){$(content,$context).slideDown(250,function(){$('li.open').removeClass('open');$context.addClass('open');});});}
else{$context.addClass('open');$(content,$context).slideDown(250);}}
return false;});},scrollTo:function(selector,callback){if($(selector).is('input:hidden')){selector=$(selector).parent();}
var targetOffset=$(selector).offset().top-5;var callback=callback||function(){};$('body,html').animate({scrollTop:targetOffset},500,null,callback($(selector)));},populateSelect:function(params){$.ajax({url:params.url,dataType:'json',data:params.data||null,type:params.type||'POST',beforeSend:function(XMLHttpRequest){params.before(XMLHttpRequest);},error:function(XMLHttpRequest,textStatus,errorThrown){},success:function(response){response=response.data;if(response.status){$('#'+params.target).empty().removeAttr('disabled');var content=response.content;for(i=0;i<content.length;i++){var select=document.getElementById(params.target);var option=document.createElement('option');option.text=content[i].state_name;option.value=content[i].state_id;try{select.add(option,null);}
catch(ex){select.add(option);}}
if(params.callback){params.callback();}}}});}}
var t=null;var counter;function timer(context){counter=$('#timer',context).html();if(counter>0){counter=counter-1;if(counter<1){counter=$('#timer',context).html('0');}
else{counter=$('#timer',context).html(counter);}
t=setTimeout(function(){timer(context);},500);}else{$('#error-bar').remove();$('.close').trigger('click');}}
function newWindow(linkClass,id){$('a.'+linkClass+'').unbind().bind('click',function(event){var address=$(event.target).attr('href');window.open(address);return false;});};function messageSuccess(msg){var successH1=helpers.h1(msg.msg+' to '+
msg.email_return.association_count+' association(s) - '+
helpers.link('View Log',{href:msg.email_return.url}));$('#warning-success h1').empty().append($(successH1).html());$('#warning-success').show().removeClass('hidden');options.resetForm();$('#added-groups').find('a').remove();$('#added-groups').find('input:hidden').remove();$('#added-groups').hide();$('#send_email_contact').val('').removeAttr('disabled');}
var utils={parseQueryString:function(obj){var queryString='/';for(key in obj){queryString+=key+'/'+obj[key]+'/';}
return queryString;},objToArray:function(obj){var arrEls=[];for(var loop in obj){arrEls[arrEls.length]=obj[loop];}
return arrEls;},htmlAttrib:function(attribs){if(typeof attribs=='object'){var arrAttribs=[];for(var attrib in attribs){arrAttribs[arrAttribs.length]=attrib+'="'+attribs[attrib]+'"';}
return arrAttribs.join(' ');}}}
var helpers={hidden:function(attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<input type="hidden" '+attribs+' />';},div:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<div'+attribs+'>'+content+'</div>';},dd:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<dd'+attribs+'>'+content+'</dd>';},ul:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<ul'+attribs+'>'+content+'</ul>';},li:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<li'+attribs+'>'+content+'</li>';},h1:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<h1'+attribs+'>'+content+'</h1>';},p:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<p'+attribs+'>'+content+'</p>';},link:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<a'+attribs+'>'+content+'</a>';},list:function(itens,separator){var aux='';var list='';for(var i=0;i<itens.length;i++){i==itens.length-1?aux='':aux=separator;list+=itens[i]+aux;}
return list;},span:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
return'<span'+attribs+'>'+content+'</span>';},groupsAdded:function(content,attr){var attribs='';if(typeof attr=='object'){attribs=' '+utils.htmlAttrib(attr);}
var inputHidden=helpers.hidden(attr);return'<a class="remove" title="'+content+'" href="#">'+'<img alt="Remove Icon" title="Remove" src="'+paths.img+'remove_icon.png"/>'+content+'</a>'
+inputHidden;},loadingDiv:function(){var loadingDiv=helpers.div('Loading, please wait...',{id:'loading-bar'});return $('body').prepend(loadingDiv);},errorDiv:function(){var errorDiv=helpers.div('<p>An unexpected error occured in the System.<br/>This warning will be closed in:<span id="timer">10</span></p>',{id:'error-bar'});$('body').prepend(errorDiv);var id='timer';if(t){clearTimeout(t);}
setTimeout("timer('#error-bar')",1000);},systemContainer:function(id){var container=helpers.div('',{id:'system-message','class':'grid_12'});$(id).prepend(container);},warningDiv:function(content,attr,id){var $div=$('<div id="'+id+'" class="highlight"><p>'+content+'</p></div>');switch(id){case'error':$div.append('<ul id="ul-error" class="list"></ul>');return $div;break;}}}
var validateOptions={errorElement:'li',onfocusout:false,onkeyup:false,onclick:false,errorPlacement:function(error,element){if(!$('#error').length){$('#content > *:first-child').after(helpers.warningDiv('Please enter or amend the following'+' information',null,'error'));}
var id=element.attr('id');var name=element.attr('name');if(!id)
id=name;var $errorli=error.appendTo('#ul-error');if(!$('#generated-'+id).length){$errorli.append(' | <a href="#'+id+'" id="generated-'+id+'" title="Show me">Show me</a>');}
else{$errorli.remove();}
$('#generated-'+id).bind('click',function(event){event.stopPropagation();utilsFunctions.scrollTo('#'+id,function(element){$(element).focus();});return false;});$(element).not('select').addClass('error');$(element.form).find("label[for="+id+"]").addClass('error');},unhighlight:function(){}};var ajaxOptions={url:'default',dataType:'json',data:null,type:'POST',beforeSend:function(XMLHttpRequest){},error:function(XMLHttpRequest,textStatus,errorThrown){},success:function(response){}}
