
function checkUserPassword(val)
{var errors='';if(val.length<6){errors+='- Your new password must contain 6 or more characters\n';}
if(!val.match(/[A-Z]+/)||!val.match(/[a-z]+/)||!val.match(/[0-9]+/)){errors+='- Your new password must contain a mixture of lowercase and uppercase letters and numbers\n';}
if(errors!==''){return errors;}else{return true;}}
function checkEmail(email)
{var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;if(filter.test(email)){return true;}else{return false;}}
function trylogin()
{var f=document.forms['login-app'];var errorMsg=false;if(f.username.value===''&&f.password.value===''){errorMsg='Please enter your username and password';if(f.username.focus){f.username.focus();}}else if(f.username.value===''){errorMsg='Please enter your username';if(f.username.focus){f.username.focus();}}else if(f.password.value===''){errorMsg='Please enter your password';if(f.password.focus){f.password.focus();}}
if(errorMsg){alert(errorMsg);return false;}else{return true;}}
function getLostPassword()
{var f=document.forms['login-pass'];if(!checkEmail(f.lostpassword.value)){alert('The email address you entered appears to be invalid\nPlease try again');return false;}else{return true;}}
function checkChangePassword()
{var f=document.forms['password-update'];var errorMsg='';if(f.old_passwd.value===''){errorMsg+='- Please type in your current password\n';if(f.old_passwd.focus){f.old_passwd.focus();}}
if(checkUserPassword(f.new_passwd1.value)!==true){errorMsg+=checkUserPassword(f.new_passwd1.value);f.new_passwd1.value="";f.new_passwd2.value="";}
if(f.new_passwd1.value!==f.new_passwd2.value){errorMsg+='- Your two new passwords do not match\n';f.new_passwd1.value="";f.new_passwd2.value="";}
if(errorMsg===''){return true;}else{alert("Your password could not be changed for the following reason(s)\n\n"+errorMsg+"\nPlease try again");f.old_passwd.value="";f.new_passwd1.value="";f.new_passwd2.value="";return false;}}
function checkAddSchoolForm()
{var f=document.forms['school-user-add'];var errorMsg='';if(f.org_name.value===''){errorMsg+='- Please type in the name of the School\n';}
if(f.username.value===''){errorMsg+='- Please type in a username for the School user\n';}
if(f.email.value===''){errorMsg+='- Please type in an email address for the school user\n';}else{if(!checkEmail(f.email.value)){errorMsg+='- Please check the email address, it appears to be invalid\n';}}
if(errorMsg){alert("The new School could not be added for the following reason(s):\n\n"+errorMsg+"\nPlease try again");return false;}else{return true;}}
function checkOrgName()
{var f=document.forms["org-update"];if(f.org_name.value===''){alert("You must enter a name here");f.reset();return false;}else{return true;}}
function checkUserUpdateForm(idx)
{var f=document.forms['user-update'+idx];}
function confirmSchoolDeletion()
{var f=document.forms["org-update"];if(confirm("Are you sure?\nAll the Schools details will be permanently lost!")){f.form_action.value="delete_school";f.submit();}}
function confirmAdminResetPassword(form_name)
{var f=document.forms[form_name];if(confirm("This user will have their password reset and the\nnew password will be sent to their registered email address.\n\nContinue?")){f.form_action.value="reset_org_user_password";f.submit();}}
function confirmAdminDeleteUser(form_name)
{var f=document.forms[form_name];if(confirm("Are you sure?\nAll details for this user will be permanently lost!")){f.form_action.value="delete_org_user";f.submit();}}
function confirmInvoice(task,org_id)
{var msg="Are you sure?";var newdate=false;switch(task){case'cancel':msg+="\nThis will cancel the invoice ONLY\nYou still have to delete the school\nto prevent them from logging in...";break;case'paid':var now=new Date();var months=["January","February","March","April","May","June","July","August","Sepember","October","November","December"];var dateStr=now.getDate()+'/'+(now.getMonth()+1)+'/'+now.getFullYear();var date=prompt("Please confirm the date this invoice was paid",dateStr);if(date!==dateStr){newdate=new Date();var parts=date.split('/');newdate.setMonth((parseInt(parts[1])-1));newdate.setFullYear(parseInt(parts[2]));newdate.setDate(parseInt(parts[0]));msg="Invoice paid on "+newdate.getDate()+" "+months[newdate.getMonth()]+" "+newdate.getFullYear()+"?";}else{msg="Invoice paid on "+now.getDate()+" "+months[now.getMonth()]+" "+now.getFullYear()+"?";}
break;case'resend':break;case'remind':break;case'delete':msg+="\nAll the details for this school,\nuser and invoice will be deleted...";}
if(msg&&confirm(msg)){var f=document.forms.schoolsubs;f.task.value=task;f.org_id.value=org_id;if(newdate){f.newdate.value=newdate.getTime();}
f.submit();}}
function copyToClipboard()
{var cntnt=document.getElementById('textTable');cntnt.contentEditable='true';var controlRange;if(document.body.createControlRange){controlRange=document.body.createControlRange();controlRange.addElement(cntnt);controlRange.execCommand('Copy');}
cntnt.contentEditable='false';}
function requestLogin()
{var f=document.forms.contactus;var errorMsg='';if(f.fullname.value===""){errorMsg+=" - Please fill in your name\n";}
if(f.email.value===""){errorMsg+=" - Please fill in your email address\n";}else if(!checkEmail(f.email.value)){errorMsg+=" - Your email address appears to be invalid\n";}
if(f.org_name.value===""){errorMsg+=" - Please fill in the name of your Local Authority/PCT\n";}
if(f.school_name.value===""){errorMsg+=" - Please fill in the name of your Organisation/School\n";}
if(f.message.value===""){errorMsg+=" - Please tell us about your role in your Organisation.\n";}
if(errorMsg){alert("Sorry, some parts of this form are incomplete:\n"+errorMsg+"Please correct the error(s) and try again.");return false;}else{return true;}}
function checkSubscriptionForm()
{var f=document.forms.subscription;var errorMsg='';if($.trim(f.school_name.value)===""){errorMsg+=" - Please fill in the name of your school\n";}
if($.trim(f.first_name.value)===""){errorMsg+=" - Please fill in your first name\n";}
if($.trim(f.surname.value)===""){errorMsg+=" - Please fill in your surname\n";}
if($.trim(f.email.value)===""){errorMsg+=" - Please fill in your email address\n";}else if(!checkEmail(f.email.value)){errorMsg+=" - Your email address appears to be invalid\n";}
if(!f.tc.checked){errorMsg+=" - You must agree to the terms and conditions by checking the box\n";}
if(errorMsg){alert("Sorry, some parts of this form are incomplete:\n"+errorMsg+"Please correct the error(s) and try again.");return false;}else{return true;}}
var winIndex=1;var openNoteEditor=function()
{var actions=[];for(i=0;i<arguments.length;i++){actions[i]=escape(arguments[i]);}
var url="/users/notes/"+actions.join('/');var winHeight=700;var notesWin=window.open(url,"notesWindow"+winIndex,"width=500,height="+winHeight+",resizeable,menubar,scrollbars,left=0,top=0");if(notesWin.focus){notesWin.focus();}
winIndex++;}
var confirmDeleteNote=function(f)
{if(confirm("are you sure?")){f.form_action.value="delete";return true;}else{return false;}}
var hideNoteForm=function(form)
{var form_id=$(form).attr("id");$('#noteLink'+form_id).show();$('#noteForm'+form_id).slideUp('slow');return false;}
var maxSelected={"option-1-0":1,"option-1-0-1-0":3,"option-1-0-2-0":3,"option-1-1":3,"option-1-1-0-0":7,"option-1-1-0-1":4,"option-1-1-1-0":7,"option-1-1-2-0":3,"option-1-1-3-0":7,"option-1-1-4-0":3,"option-1-2":1,"option-1-2-0-0":3,"option-1-2-1-0":3,"option-1-3":1,"option-1-4":2,"option-2-3":1,"option-2-4":1,"option-3-3-0":6,"option-3-4-0":4,"option-4-4-0":3,"option-4-5":1,"option-4-5-0-0":3,"option-4-5-1-0":3,"option-4-5-0":3,"option-4-6-0":3,"option-4-7-0":3,"option-4-9-0":3,"option-4-10-0":3,"option-5-2-0":4,"option-6-3-0":4,"option-6-4-0":3,"option-6-5-0":4,"option-6-6-0":3,"option-6-8-0":3,"option-6-9-0":2,"option-7-2-0":3,"option-8-2-0":4,"option-8-3-0":4,"option-8-4-0":4,"option-8-5-0":3}
var selectOptions={'showAllLink':false,'showNoneLink':false,'maxSelected':maxSelected,'showConsoleLog':false,'endSeparatorSpecial':{'option-1-1-0-1':"and"}}
document.write('<style type="text/css">div#form-content {display:none;} .insert-text {display:none;}</style>');$(function(){if($(".sortable").length){$.getScript("/js/min/jquery.tablesorter.min.js",function(){$('.sortable').tablesorter({dateFormat:"uk"});});}
$('#form-content').show();$('#org_name_suggest').suggest({dataurl:'http://'+window.location.host+'/access/1'});$('a.helpButton').click(function(){$.fn.colorbox({href:$(this).attr('href').replace('help','help/iframe'),iframe:true,opacity:0.35,innerWidth:640,innerHeight:420,open:true});return false;});$('#preview-stickers').click(function(){$.fn.colorbox({href:'/stickers/preview/'+$('#sticker-format').val()+'/'+$('#sticker-design').val(),iframe:true,opacity:0.35,innerWidth:640,innerHeight:420,open:true});return false;});$('#preview-labels').click(function(){$.fn.colorbox({href:'/stickers/preview/'+$('#label-format').val()+'/'+$('#label-design').val(),iframe:true,opacity:0.35,innerWidth:640,innerHeight:420,open:true});return false;});if($('a.sticker-tooltip').length){$.getScript('/js/min/jquery.tooltip.min.js',function(){$('a.sticker-tooltip').tooltip({showURL:false,bodyHandler:function(){return $('<img/>').attr('src',$(this).attr('href'));}}).click(function(){return false;});});}
$('a.userStatsDetail').click(function(){$.fn.colorbox({href:$(this).attr('href'),opacity:0.35,innerWidth:640,innerHeight:420,open:true});return false;});$('#compareselected').click(function(){var numSelected=$('.comparecheckbox:checked').length;if(numSelected<2){alert("Please select two or more audits from the list");return false;}else if(numSelected>6){alert("The maximum number of audits which can be compared is six.\nPlease deselect "+(numSelected-6)+" and try again.");return false;}});if(document.forms.downloadForm){var f=document.forms.downloadForm;for(i=0;i<f.elements.length;i++){if(f.elements[i]&&f.elements[i].name){if(f.elements[i].name=="fill"||f.elements[i].name=="lang"||f.elements[i].name=="content"){f.elements[i].checked=false;if(f.elements[i].value=="col"||f.elements[i].value=="en"||f.elements[i].value=="full"){f.elements[i].checked=true;}}}}}
$('#pageHeading.inserts').after('<p>Click on the titles to view the newsletter inserts, or <a href="#" onclick="$(\'.insert-text\').show();return false;">click here to expand them all</a>.</p>');$(".insert-title").css({color:"#393",fontWeight:"bold",cursor:"pointer"}).hover(function(){$(this).css({'background-color':'#efe','color':'#090'});},function(){$(this).css({'background-color':'#fff','color':'#393'});});$(".insert-title").click(function(){$(".insert-text:visible").slideToggle('normal');$(this).next('.insert-text:hidden').slideToggle('normal');});if($('body').hasClass('notes')){$.getJSON('http://'+window.location.host+'/users/notes/tags','',function(data,textStatus){$('.newtag').suggest({datasource:data,showonfocus:true});});$('a.addtagLink').click(function(){var tagName=$(this).siblings(':text').val();if($.trim(tagName)!==""){var existingTags=[];$(this).parents('form').find(':hidden[name^=noteTags]').each(function(){existingTags.push(this.value.toLowerCase());});for(i=0;i<existingTags.length;i++){if(existingTags[i]==tagName.toLowerCase()){alert("this note is already tagged with this tag!");return false;}}
var newtag='<span class=\"tag\">'+tagName+' <a href=\"#\" onclick=\"removeTag(this);return false;\" title=\"remove this tag\"><img src=\"/images/bg/cross.gif\" width=\"12\" height=\"12\" title=\"remove this tag\" /></a><input type="hidden" name="noteTags[]" value="'+tagName+'" /></span>';$(this).parents('form').find('p.taglist').append(newtag);}else{alert("Please type in a name for the tag");}
return false;});$('#addNote').click(function(){$('#msg').hide();$('#noteFormnewNote').slideDown('slow');return false;});$('a.showNoteForm').click(function(){$(this).hide().next().slideDown('slow');return false;});$('#tagsfilter').inlinemultiselect({'showAllLink':false,'showNoneLink':false,'separator':'; ','endSeparator':'; ','triggerPopup':{'empty':"[Add a filter...]",'nonempty':"[Change...]",'disabled':"[Filtering disabled]"},'changeCallback':function(tags){var classStr='';for(i=0;i<tags.length;i++){if(tags[i].checked){classStr+='.tag'+tags[i].value+' ';}}
if(classStr!==''){$($.trim(classStr)).show();$('.note').not($.trim(classStr)).hide();}else{$('.note').show();}}});$('form.ajaxificated').ajaxForm({success:function(data,status,form){var form_id=$(form).attr("id");$('#noteForm'+form_id).slideUp('slow');if(data!=="noteDeleted"){$('#noteLink'+form_id).text(urlDecode(data)).show();}else{$('noteContainer'+form_id).remove();}}});}
$('#showsd, #showpl').bind("click change",function(){var showsd=$('#showsd')[0].checked;var showpl=$('#showpl')[0].checked;var set="tl";if(bardata&&bardata.pl){for(i=0;i<bardata.pl.length;i++){for(j=0;j<bardata.pl[i].length;j++){if(showsd&&showpl){$('#plbar_'+i+'_'+j).css({width:bardata.tlpl[i][j]+'px'});$('#sdbar_'+i+'_'+j).css({width:bardata.tlsd[i][j]+'px'});$('#pc_'+i+'_'+j).text(bardata.tlpc[i][j]);}else{$('#plbar_'+i+'_'+j).css({width:bardata.pl[i][j]+'px'});$('#sdbar_'+i+'_'+j).css({width:bardata.sd[i][j]+'px'});if(showpl){$('#pc_'+i+'_'+j).text(bardata.plpc[i][j]);}else if(showsd){$('#pc_'+i+'_'+j).text(bardata.sdpc[i][j]);}else{$('#pc_'+i+'_'+j).text('');}}}}
$('.sdbar').toggle(showsd);$('.plbar').toggle(showpl);}
if($('#chartPDFDownloadLink').length){var linkFrag="_"+(showsd?'s':'')+(showpl?'p':'')+'_';var linkRE=/_([^_])*_/;$('#chartPDFDownloadLink').attr("href",$('#chartPDFDownloadLink').attr("href").replace(linkRE,linkFrag));}});$('input[name=subscription_status]').each(function(){theID=$(this).attr("id");if(this.checked){switch($(this).attr("id")){case'status0':$('.trialfield .subfield').hide();break;case'status1':$('.subfield').hide();$('.trialfield').show();break;}}}).click(function(){if(this.checked){switch($(this).attr("id")){case'status0':$('.trialfield, .subfield').hide();break;case'status1':$('.subfield').hide();$('.trialfield').show();break;case'status2':$('.subfield').show();if($('#subscription_start').val()==""&&$('#subscription_end').val()==""){$('#subscription_start').val(new Date().asString()).trigger('change');$('#subscription_end').val(new Date().addDays(365).asString()).trigger('change');}}}});if($('#subscription_start').length){$.getScript('/js/min/jquery.datePicker.min-2.1.2.js',function(){var opts={startDate:'01/01/2006',clickInput:true,createButton:false};$('#subscription_start').datePicker(opts);$('#subscription_end').datePicker(opts);});}
$('#getNextInvoiceNumber').click(function(){$.post('/users/',{'ob':'invoiceNumber'},function(data,textstatus){$('#nextInvoiceNumber').append('<br />The invoice number <strong>'+data+'</strong> has been reserved.');});});if($('.scaleRadios').length){var slidercss=document.createElement("link");slidercss.setAttribute("rel","stylesheet");slidercss.setAttribute("type","text/css");slidercss.setAttribute("href","/css/slider.css");document.getElementsByTagName("head")[0].appendChild(slidercss)
$.getScript('/js/min/jquery.slider.min.js',function(){var imgCache=[]
for(i=1;i<6;i++){imgCache[i]=new Image(40,40);imgCache[i].src="/images/smilies/"+i+".png";}
$('.scaleRadios').each(function(idx){var s_input={'name':'','value':2};$('input:radio',this).each(function(){s_input['name']=$(this).attr("name");if($(this).attr("checked")=="checked"){s_input['value']=$(this).attr("value");}});$('.scale',this).remove();$('<input type="hidden" name="'+s_input['name']+'" value="'+s_input['value']+'" id="s_input'+idx+'" />').appendTo(this);$('<div class="smiley" id="smiley'+idx+'"/>').appendTo(this);$('<div class="slider" id="slider'+idx+'"/>').slider({value:50,slide:function(e,ui){var v=(Math.floor(ui.value/20))==5?5:(Math.floor(ui.value/20)+1);if($('#s_input'+$(this).attr("id").replace("slider","")).val()!=v){setSmiley(v,$(this).attr("id").replace("slider",""));}}}).appendTo(this);setSmiley(3,idx);});});function setSmiley(v,id)
{var smileyBg="#fff url(/images/smilies/"+v+".png) no-repeat 0 0";$("#s_input"+id).val(v);$("#smiley"+id).css("background",smileyBg);}}});var urlDecode=function(str)
{var histogram={};var ret=str.toString();var replacer=function(search,replace,str){var tmp_arr=[];tmp_arr=str.split(search);return tmp_arr.join(replace);};histogram["'"]='%27';histogram['(']='%28';histogram[')']='%29';histogram['*']='%2A';histogram['~']='%7E';histogram['!']='%21';histogram['%20']='+';for(replace in histogram){search=histogram[replace];ret=replacer(search,replace,ret)}
ret=decodeURIComponent(ret);return ret;}
var removeTag=function(linkEl)
{$(linkEl).parents('span.tag').remove();}
jQuery.fn.suggest=function(settings)
{return this.each(function()
{var textInput=$(this);textInput.attr("autocomplete","off");textInput.after('<input type="hidden" name="'+textInput.attr("name")+'_id" />');var valueInput=textInput.next();$("body").append('<ul class="suggestion_list"></ul>');var suggestionList=$("body ul:last");suggestionList.css({top:textInput.offset().top+textInput.outerHeight(),left:textInput.offset().left});var selected=0;var size=null;settings=jQuery.extend({datasource:null,dataurl:null,onupdate:null,showonfocus:false},settings);function makeList(data)
{var items='';size=data.length;if(data){for(i=0;i<data.length;i++){items+='<li value="'+data[i].id+'">'+data[i].name+'</li>';}
suggestionList.html(items);suggestionList.children().hover(function(){$(this).addClass("selected").siblings().removeClass("selected");},function(){$(this).removeClass("selected");}).click(function(){valueInput.val($(this).attr('value'));textInput.val($(this).text());if(typeof settings.onupdate=="function"){settings.onupdate(valueInput.val(),textInput.val());}
clear();});}else{suggestionList.empty();}}
function clear()
{suggestionList.hide();}
function checkMatch()
{var matchFound=false;if(textInput.val()!==""){suggestionList.children().removeClass("selected");suggestionList.children().each(function(){if($(this).text().toLowerCase().indexOf(textInput.val().toLowerCase())===0){matchFound=true;suggestionList.css({top:textInput.offset().top+textInput.outerHeight(),left:textInput.offset().left});suggestionList.show();$(this).addClass("selected");suggestionList.scrollTop(suggestionList.scrollTop()+($(this).offset().top-suggestionList.offset().top));return false;}});}
if(!matchFound){clear();}}
if(settings.dataurl){$.getJSON(settings.dataurl,'',function(data,textStatus){makeList(data);});}else if(settings.datasource&&settings.datasource.length){makeList(settings.datasource);}
textInput.keyup(function(e)
{if(e.which==27){clear();}else if(e.which==46||e.which==8||e.which>47){checkMatch();}});if(settings.showonfocus){textInput.focus(function(e){suggestionList.css({top:textInput.offset().top+textInput.outerHeight(),left:textInput.offset().left});suggestionList.show();});}});};jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}
var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}
expires='; expires='+date.toUTCString();}
var path=options.path?'; path='+(options.path):'';var domain=options.domain?'; domain='+(options.domain):'';var secure=options.secure?'; secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}
return cookieValue;}};