
/* - danceMagic.js - */
// http://www.dancechampions.org/portal_javascripts/danceMagic.js?original=1
function replaceTextWithHTML(text){text="<p>"+text+"</p>";var i=text.indexOf("\n");while(i>=0){text=text.replace("\n","<br />");i=text.indexOf("\n")}
text=text.replace("http://","");text=text.replace("www.","http://www.");var exp=/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;return text.replace(exp,"<a href='$1'>$1</a>")}
jQuery.noConflict();jQuery(document).ready(function(){homeContentHeight=jQuery("#home-content").height();if(homeContentHeight!=null){var xtop=homeContentHeight-200;jQuery("#home-ajax").css("top",xtop+"px")}
jQuery(".twitterbox").hide();jQuery("#imgtwitter").click(function(){jQuery(".twitterbox").slideToggle(500)
return false});jQuery(".question > a").click(function(e){jQuery(".question > p").hide();thisId=jQuery(this).attr("id");jQuery("#"+thisId+"-ans").show();return false});jQuery("#errorpostcode").addClass("hiddenss");jQuery.get("media_ajax",{req:"news"},
function(data){a=data.split("|")
if(a[1]==''){img=''}
else{img='<div id="media-ajax-img">'+a[1]+'</div>'}
jQuery("#media-ajax-block").html(img+a[0]+'<div class="clear-all"></div>')});jQuery(".media-ajax-box > li").click(function(){jQuery(".select").removeClass("select");jQuery(this).addClass("select");ids=jQuery(this).attr("id");jQuery.get("media_ajax",{req:ids},
function(data){a=data.split("|")
if(a[1]==''){img=''}
else{img='<div id="media-ajax-img">'+a[1]+'</div>'}
jQuery("#media-ajax-block").html(img+a[0]+'<div class="clear-all"></div>')})});jQuery.get("media_ajax",{req:"news"},
function(data){jQuery("#media-ajax-imgtop").html(data)});jQuery(".ajax-box > li").click(function(){jQuery(".select").removeClass("select");jQuery(this).addClass("select");ids=jQuery(this).attr("id");jQuery.get("home_ajax",{req:ids},
function(data){jQuery("#ajax-block").html(data)})});jQuery("a[rel^='prettyPhoto']").prettyPhoto();jQuery(".loginbtn").click(function(e){e.preventDefault();jQuery.get("loginpop", function(data){jQuery(data).modal({overlayClose:true,opacity:80,overlayCss:{backgroundColor:"#000"},onOpen: function(dialog){dialog.overlay.fadeIn('fast', function(){dialog.data.hide();dialog.container.fadeIn('fast', function(){dialog.data.fadeIn('fast');jQuery("#__ac_name").focus()})})},onClose: function(dialog){dialog.data.fadeOut('fast', function(){dialog.container.hide('fast', function(){dialog.overlay.fadeOut('fast', function(){jQuery.modal.close()})})})}})})});jQuery(".partsignup").click(function(e){e.preventDefault();jQuery.get("joindance_form",{type:'participant'}, function(data){dialog(data)})});jQuery(".teasignup").click(function(e){e.preventDefault();jQuery.get("joindance_form",{type:'teacher'}, function(data){dialog(data)})});jQuery(".orgsignup").click(function(e){e.preventDefault();jQuery.get("joindance_form", function(data){dialog(data)})});jQuery(".joinbtn").click(function(e){e.preventDefault();jQuery.get("joindance_form", function(data){dialog(data)})});jQuery(".classform").click(function(e){e.preventDefault();jQuery.get("addclass_form", function(data){dialog(data)})});jQuery(".editclass").click(function(e){e.preventDefault();classID=jQuery(this).attr("id")
jQuery.get("addclass_form",{action:'EDIT',classid:classID}, function(data){dialog(data)})});jQuery(".addimage").click(function(e){e.preventDefault();jQuery.get("addimage_form", function(data){dialog(data)})});jQuery("#addclassbutton").live("click",function(){var chk=0;
function validateField(field){if(field=='class_type'){var fieldname=jQuery("."+field).val()}
else{var fieldname=jQuery("#"+field).val()}
if(fieldname==''){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");chk=1}else{jQuery("#r"+field).hide()}}
validateField("address1");validateField("town");validateField("county");validateField("postcode");validateField("region");validateField("class_name");validateField("intensity");validateField("age");validateField("class_type");validateField("class_day");validateField("class_time");if(chk==0){jQuery("#addclass").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show()}});jQuery.fn.fadeToggle=function(speed,easing,callback){return this.animate({opacity:'toggle'},speed,easing,callback)};jQuery("#addmore").live("click",function(){jQuery("#addmoregroup").css({"left":jQuery("#addmore").position().left,"top":jQuery("#addmore").position().top+143}).fadeToggle("fast");jQuery(this).toggleClass("border");return false});jQuery("#addmoregroup > a").live("click",function(){jQuery("#addmoregroup").css({"left":jQuery("#addmore").position().left,"top":jQuery("#addmore").position().top+143}).fadeToggle("fast");jQuery("#addmore").toggleClass("border");return false});jQuery(".leftpeople > .iconblock > span").live("click",function(){jQuery(".leftpeople > .iconblock > img ").removeClass("peoplenotactive");jQuery(".leftpeople > .iconblock > img ").removeClass("peopleactive");jQuery(".people-desc").fadeOut().hide();jQuery(".people-body").fadeOut().hide();jQuery("#people-description").hide();thisId=jQuery(this).attr("id");jQuery.get("getPersonal",{req:thisId},
function(data){a=data.split("|")
if(a[1]==''){b='<br/>'}
else{b="<br/><center>"+a[1]+"</center><br/>"}
jQuery("#people-title").html(a[0]);jQuery("#people-description").html(b+a[2]);jQuery("#people-description").fadeIn().show()});jQuery(".leftpeople > .iconblock > img ").addClass("peoplenotactive");jQuery("img#"+thisId).addClass("peopleactive")});jQuery(document).ready(function(){jQuery(".btext").hide()});jQuery("#more-about-us").live("click",function(){jQuery("#more-about-us > .people-detail").slideDown();jQuery("#more-about-us > .people-detail > .btext").show();jQuery("#related-links > .people-detail").slideUp();jQuery("#sponsorship > .people-detail").show();jQuery("#sponsorship > .people-detail > .btext").hide()});jQuery("#related-links").live("click",function(){jQuery("#related-links > .people-detail").slideDown();jQuery("#related-links > .people-detail > .btext").show();jQuery("#sponsorship > .people-detail").slideUp();jQuery("#more-about-us > .people-detail").slideUp();jQuery("#sponsorship > .people-detail").show();jQuery("#sponsorship > .people-detail > .btext").hide()});jQuery("#sponsorship").live("click",function(){jQuery("#sponsorship > .people-detail").slideDown();jQuery("#sponsorship > .people-detail > .btext").show();jQuery("#more-about-us > .people-detail").slideUp();jQuery("#related-links > .people-detail").slideUp()});jQuery(".addteacher").click(function(e){e.preventDefault();jQuery.get("add_teacher_form", function(data){dialog(data)})});jQuery(".editprofile").click(function(e){e.preventDefault();jQuery.get("personal_popup", function(data){dialog(data)})});jQuery(".editparticipant").click(function(e){e.preventDefault();jQuery.get("participant_popup", function(data){dialog(data)})});jQuery("#saveprofile").live("click",function(){var chk=0;
function validateField(field){var fieldname=jQuery("#personalprofile > #"+field).val();if(fieldname==''){jQuery("#personalprofile > #r"+field).hide();jQuery("#personalprofile > #r"+field).fadeIn("slow");chk=1}else{jQuery("#personalprofile > #r"+field).hide()}}
validateField("address1");validateField("town");validateField("county");validateField("postcode");validateField("telno");validateField("region");validateField("class_gender");if(chk==0){jQuery("#personalprofile").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show()}});jQuery(".newsform").click(function(e){e.preventDefault();jQuery.get("addnews_item", function(data){dialog(data)})});jQuery(".editnewsitem").click(function(e){e.preventDefault();newsID=jQuery(this).attr("id");jQuery.get("addnews_item",{action:'EDIT',newsid:newsID}, function(data){dialog(data)})});jQuery(".eventsform").click(function(e){e.preventDefault();jQuery.get("addevents_item", function(data){dialog(data)})});jQuery(".editeventsform").click(function(e){e.preventDefault();eventID=jQuery(this).attr("id");jQuery.get("addevents_item",{action:'EDIT',eventid:eventID}, function(data){dialog(data)})});jQuery(".videoform").click(function(e){e.preventDefault();jQuery.get("addvideo", function(data){dialog(data)})});jQuery(".editvideo").click(function(e){e.preventDefault();vdoID=jQuery(this).attr("id");jQuery.get("addvideo",{action:'EDIT',vdoid:vdoID},function(data){dialog(data)})});jQuery(".addvdo").live("click",function(){var chk=0;
function validateField(field){var fieldname=jQuery("#"+field).val();jQuery(".formerror").removeClass("formerror");if(field=="youtubeId"&&fieldname!=''){chkyoutube=fieldname.split("v=");if(chkyoutube.length<=1){jQuery("#r"+field).hide();jQuery("#r"+field).html("Please enter a valid youtube URL eg www.youtube.com/watch?v=sfMP9EPK5cM").fadeIn("slow");jQuery("#youtube_area").addClass("formerror");chk=1}else{jQuery("#r"+field).hide();jQuery(".formerror").removeClass("formerror")}}else if(fieldname==''){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");jQuery("#title_area").addClass("formerror");jQuery("#youtube_area").addClass("formerror");chk=1}else{jQuery("#r"+field).hide();jQuery(".formerror").removeClass("formerror")}}
validateField("title");validateField("youtubeId");if(chk==0){jQuery(".formerror").removeClass("formerror");jQuery("#video-base-edit").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show()}});jQuery(".gobutton").live("click",function(){validate=true;if(jQuery("#searchGadget").val()=='Postcode'){jQuery("#searchGadget").val('')}
if(jQuery("#searchGadget").val()==''&&jQuery("#class_type").val()==''){jQuery("#errorpostcode").removeClass("hiddenss");jQuery("#errorpostcode").hide();jQuery("#errorpostcode").slideDown();validate=false;return false}
if(validate){jQuery("#searchbox").submit()
w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show()}});jQuery(".editclass").click(function(e){e.preventDefault();classID=jQuery(this).attr("id")
jQuery.get("addclass_form",{action:'EDIT',classid:classID}, function(data){dialog(data)})});jQuery(".deleteclass").live("click",function(e){e.preventDefault();classID=jQuery(this).attr("id")
jQuery.get("confirm_delete_form",{classid:classID}, function(data){dialog(data)})});jQuery(".deleteteacher").live("click",function(e){e.preventDefault();teacherID=jQuery(this).attr("id")
jQuery.get("confirm_delete_form",{teacherid:teacherID}, function(data){dialog(data)})});jQuery(".deleteeventsform").live("click",function(e){e.preventDefault();eventID=jQuery(this).attr("id")
jQuery.get("confirm_delete_form",{eventid:eventID}, function(data){dialog(data)})});jQuery(".deletevideo").live("click",function(e){e.preventDefault();videoID=jQuery(this).attr("id")
jQuery.get("confirm_delete_plone",{videoid:videoID}, function(data){dialog(data)})});jQuery(".deletenews").live("click",function(e){e.preventDefault();newsID=jQuery(this).attr("id")
jQuery.get("confirm_delete_plone",{newsid:newsID}, function(data){dialog(data)})});jQuery("#editprofilebtn").live("click",function(){var role=jQuery("#role").val();var email=jQuery("#email").val();var postcode=jQuery("#postcode").val();jQuery("#require-orgname").hide();jQuery("#require-email").hide();jQuery("#require-postcode").hide();validate=true;if(postcode==''){jQuery("#require-postcode").hide();jQuery("#require-postcode").html("This field is required").fadeIn("slow");jQuery("#postcode").focus();validate=false}
if(email==0){jQuery("#require-email").html("Please insert email address.").fadeIn("slow");jQuery("#email").focus();validate=false}
if(email!=0){if(isValidEmailAddress(email)){jQuery("#require-email").hide()} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");validate=false}}
if(role=='Organisation'){var orgname=jQuery("#org_name").val();if(orgname==''){jQuery("#require-orgname").hide();jQuery("#require-orgname").html("This field is required").fadeIn("slow");jQuery("#org_name").focus();validate=false}
if((orgname!='')&&(email!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide()} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#email").focus();validate=false}}}
if(role=='Teacher'){var forename=jQuery("#forename").val();var surname=jQuery("#surname").val();if(forename==''){jQuery("#require-forename").hide();jQuery("#require-forename").html("This field is required").fadeIn("slow");jQuery("#forename").focus();validate=false}
if(surname==''){jQuery("#require-surname").hide();jQuery("#require-surname").html("This field is required").fadeIn("slow");jQuery("#surname").focus();validate=false}
if((forename!='')&&(surname!='')&&(email!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide()} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#email").focus();validate=false}}}
if(validate){w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else{return false}})});
function dialog(data){jQuery(data).modal({overlayClose:true,opacity:80,minWidth:648,overlayCss:{backgroundColor:"#000"},onOpen: function(dialog){dialog.overlay.fadeIn('fast', function(){dialog.data.hide();dialog.container.fadeIn('fast', function(){dialog.data.fadeIn('fast')})})},onClose: function(dialog){dialog.data.fadeOut('fast', function(){dialog.container.hide('fast', function(){dialog.overlay.fadeOut('fast', function(){jQuery.modal.close()})})})}})}
function setagree(accname){jQuery.ajaxSetup({async:false});jQuery.get("http://www.dancechampions.org/setAgree",{username:accname},function(data){if(data=='true'){login_function_submit=true;jQuery("#joinform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}})}
function removeUser(accname){jQuery.ajaxSetup({async:false});jQuery.get("http://www.dancechampions.org/removeUser",{username:accname},function(data){if(data=='true'){login_function_submit=true;jQuery("#removeform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}})}
function showdisagree(){jQuery("#register-body-agree").hide();jQuery("#disagree-form").show()}
function showterms(){jQuery("#disagree-form").hide();jQuery("#register-body-agree").show()}
var loginform_submitted=false;var login_function_submit=false;
function check_login(){if(loginform_submitted){if(login_function_submit){login_function_submit=false}else{alert("Your form has already been submitted. Please wait...")}
return false}
else{loginform_submitted=true;var accname=jQuery("#__ac_name").val();var accpass=jQuery("#__ac_password").val();if(accname!=''){jQuery("#require-username").hide();jQuery("#require-password").hide();jQuery.ajaxSetup({async:false});jQuery.get("http://www.dancechampions.org/validate_members",{chkstate:"login",username:accname,password:accpass}, function(data){var result=data;if(data=='success'){login_function_submit=true;jQuery("#joinform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else if(data=='invalid password'){loginform_submitted=false;jQuery("#require-password").html(data).fadeIn("slow");jQuery(".login-detailbox").addClass("formerror");return false}else if(data=='invalid username'){loginform_submitted=false;jQuery("#require-username").html(data).fadeIn("slow");jQuery(".login-detailbox").addClass("formerror");return false}else if(data=='need agree'){loginform_submitted=false;jQuery("#register-body").hide();jQuery("#register-body-agree").show();return false}});return false}
if(accname==''){jQuery("#require-username").hide();jQuery("#require-username").fadeIn("slow");jQuery(".login-detailbox").addClass("formerror");loginform_submitted=false;return false}}}
var joinform_submitted=false;var join_function_submit=false
function check_join(){if(joinform_submitted){if(join_function_submit){join_function_submit=false}else{alert("Your form has already been submitted. Please wait...")}
return false}
else{joinform_submitted=true;var organisation=jQuery("#organisation").attr("checked");var participant=jQuery("#participant").attr("checked");var org_name=jQuery("#org_name").val();var username=jQuery("#username").val();var postcode=jQuery("#postcode").val();var email=jQuery("#email").val();var confirmemail=jQuery("#confirmemail").val();jQuery("#require-orgname").hide();jQuery("#require-username").hide();jQuery("#require-email").hide();jQuery("#require-confirmemail").hide();jQuery("#require-postcode").hide();jQuery(".formerror").removeClass("formerror");if(organisation==true){if(org_name==''){jQuery("#require-orgname").hide();jQuery("#require-orgname").fadeIn("slow");jQuery("#org_name_area").addClass("formerror");joinform_submitted=false;return false}}
if(confirmemail==0){jQuery("#require-confirmemail").html("Please insert confirm email address.").fadeIn("slow");jQuery("#require_confirmemail_area").addClass("formerror");joinform_submitted=false;return false}
if(email==0){jQuery("#require-email").html("Please insert email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");joinform_submitted=false;return false}
if(email!=0){if(isValidEmailAddress(email)){jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror")} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");joinform_submitted=false;return false}}
if(confirmemail!=0){if(confirmemail==email){jQuery("#require-confirmemail").hide();jQuery(".formerror").removeClass("formerror")} else{jQuery("#require-confirmemail").hide();jQuery("#require-confirmemail").html("Invalid confirm email address.").fadeIn("slow");jQuery("#require_confirmemail_area").addClass("formerror");joinform_submitted=false;return false}}
if(username==''){jQuery("#require-username").hide();jQuery("#require-username").html("Please insert username").fadeIn("slow");jQuery("#require_username_area").addClass("formerror");joinform_submitted=false;return false}
if(participant==true){if(postcode==''){jQuery("#require-postcode").hide();jQuery("#require-postcode").fadeIn("slow");jQuery("#postcode_area").addClass("formerror");joinform_submitted=false;return false}}
if((username!='')&&(email!=0)&&(confirmemail!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror");jQuery.ajaxSetup({async:false});jQuery.get("http://www.dancechampions.org/validate_members",{chkstate:"join",username:username}, function(data){var result=data;if(data=='success'){jQuery(".formerror").removeClass("formerror");join_function_submit=true;jQuery("#joinform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else if(data=='invalid username'){jQuery("#require-username").html("validate username exists.").fadeIn("slow");jQuery("#require_username_area").addClass("formerror");joinform_submitted=false;return false}})} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");joinform_submitted=false;return false}}
joinform_submitted=false;return false}}
function check_addimage(){var chk=0;
function validateField(field){var fieldname=jQuery("#"+field).val();if(fieldname==''){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");if(field=='title'){jQuery("#title_area").addClass("formerror")}else if(field=='image_file'){jQuery("#file_area").addClass("formerror")}
chk=1}else{jQuery("#r"+field).hide();jQuery(".formerror").removeClass("formerror")}}
validateField("title");validateField("image_file");if(chk==0){jQuery(".formerror").removeClass("formerror");w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else{return false}}
var teacherform_submitted=false;teacher_function_submit=false;
function check_addteacher(){if(teacherform_submitted){if(teacher_function_submit){teacher_function_submit=false}else{alert("Your form has already been submitted. Please wait...")}
return false}
else{teacherform_submitted=true;var username=jQuery("#username").val();var email=jQuery("#email").val();jQuery("#require-username").hide();jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror");if(email==0){jQuery("#require-email").html("Please insert email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror")}
if(email!=0){if(isValidEmailAddress(email)){jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror")} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");teacherform_submitted=false;return false}}
if(username==''){jQuery("#require-username").hide();jQuery("#require-username").html("Please insert username").fadeIn("slow");jQuery("#require_username_area").addClass("formerror");teacherform_submitted=false;return false}
if((username!='')&&(email!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror");jQuery.get("http://www.dancechampions.org/validate_members",{chkstate:"join",username:username}, function(data){var result=data;if(data=='success'){teacher_function_submit=true;jQuery("#joinform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else if(data=='invalid username'){jQuery("#require-username").html("validate username exists.").fadeIn("slow");jQuery("#require_username_area").addClass("formerror");teacherform_submitted=false;return false}})} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");teacherform_submitted=false;return false}}
teacherform_submitted=false;return false}}
function check_participant(){var forename=jQuery("#first_name").val();var surname=jQuery("#last_name").val();var email=jQuery("#email").val();var postcode=jQuery("#postcode").val();jQuery("#require-email").hide();jQuery("#require-postcode").hide();jQuery("#require-forename").hide();jQuery("#require-surname").hide();jQuery(".formerror").removeClass("formerror");validate=true;if(email==0){jQuery("#require-email").html("Please insert email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");jQuery("#email").focus();validate=false}
if(email!=0){if(isValidEmailAddress(email)){jQuery("#require-email").hide()} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");validate=false}}
if(forename==''){jQuery("#require-forename").hide();jQuery("#require-forename").html("This field is required").fadeIn("slow");jQuery("#require_forename_area").addClass("formerror");jQuery("#forename").focus();validate=false}
if(postcode==''){jQuery("#require-postcode").hide();jQuery("#require-postcode").html("This field is required").fadeIn("slow");jQuery("#require_postcode_area").addClass("formerror");jQuery("#postcode").focus();validate=false}
if(surname==''){jQuery("#require-surname").hide();jQuery("#require-surname").html("This field is required").fadeIn("slow");jQuery("#require_surname_area").addClass("formerror");jQuery("#surname").focus();validate=false}
if((forename!='')&&(surname!='')&&(email!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide()} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");jQuery("#email").focus();validate=false}}
if(validate){jQuery(".formerror").removeClass("formerror");jQuery("#personform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else{return false}}
validated=0;
function check_personal(){var role=jQuery("#role").val();var email=jQuery("#email").val();var postcode=jQuery("#postcode").val();jQuery("#require-orgname").hide();jQuery("#require-email").hide();jQuery("#require-town").hide();jQuery("#require-county").hide();jQuery("#require-postcode").hide();jQuery(".formerror").removeClass("formerror");validate=true;if(email==0){jQuery("#require-email").html("Please insert email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");jQuery("#email").focus();validate=false}
if(email!=0){if(isValidEmailAddress(email)){jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror")} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");validate=false}}
if(role=='Organisation'){var orgname=jQuery("#org_name").val();if(orgname==''){jQuery("#require-orgname").hide();jQuery("#require-orgname").html("This field is required").fadeIn("slow");jQuery("#require_orgname_area").addClass("formerror");jQuery("#org_name").focus();validate=false}
if((orgname!='')&&(email!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide();jQuery(".formerror").removeClass("formerror")} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");jQuery("#email").focus();validate=false}}}
if(role=='Teacher'){var forename=jQuery("#forename").val();var surname=jQuery("#surname").val();var town=jQuery("#town").val();var county=jQuery("#county").val();if(forename==''){jQuery("#require-forename").hide();jQuery("#require-forename").html("This field is required").fadeIn("slow");jQuery("#require_forename_area").addClass("formerror");jQuery("#forename").focus();validate=false}
if(town==''){jQuery("#require-town").hide();jQuery("#require-town").html("This field is required").fadeIn("slow");jQuery("#require_town_area").addClass("formerror");jQuery("#town").focus();validate=false}
if(county==''){jQuery("#require-county").hide();jQuery("#require-county").html("This field is required").fadeIn("slow");jQuery("#require_county_area").addClass("formerror");jQuery("#county").focus();validate=false}
if(postcode==''){jQuery("#require-postcode").hide();jQuery("#require-postcode").html("This field is required").fadeIn("slow");jQuery("#require_postcode_area").addClass("formerror");jQuery("#postcode").focus();validate=false}
if(surname==''){jQuery("#require-surname").hide();jQuery("#require-surname").html("This field is required").fadeIn("slow");jQuery("#require_surname_area").addClass("formerror");jQuery("#surname").focus();validate=false}
if((forename!='')&&(surname!='')&&(email!=0)){if(isValidEmailAddress(email)){jQuery("#require-email").hide()} else{jQuery("#require-email").hide();jQuery("#require-email").html("Invalid email address.").fadeIn("slow");jQuery("#require_email_area").addClass("formerror");jQuery("#email").focus();validate=false}}}
if(validated==0){if(validate){validated=1;jQuery(".formerror").removeClass("formerror");jQuery("#personform").submit();w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();return true}else{return false}}}
function IsNumeric(input){return(input-0)==input&&input.length>0}
var classform_submitted=false;var class_function_submit=false;
function check_addclass(){if(classform_submitted){if(class_function_submit){class_function_submit=false}else{alert("Your form has already been submitted. Please wait...")}
return false}
else{classform_submitted=true;var chk=0;
function validateField(field){if(field=='class_type'){var fieldname=jQuery("."+field).val()} else{var fieldname=jQuery("#"+field).val()}
jQuery("#r"+field+"_area").removeClass("formerror");if(fieldname==''){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");jQuery("#r"+field+"_area").addClass("formerror");chk=1}else if(field=='classCost'){if(!IsNumeric(fieldname)){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");jQuery("#r"+field+"_area").addClass("formerror");chk=1}else{jQuery("#r"+field).hide()}}else{jQuery("#r"+field).hide()}}
validateField("address1");validateField("town");validateField("county");validateField("classCost");validateField("postcode");validateField("region");validateField("class_name");validateField("intensity");validateField("age");validateField("class_type");validateField("class_day");validateField("class_time");if(chk==0){class_function_submit=true;w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show();jQuery(".formerror").removeClass("formerror");return true}else{classform_submitted=false;return false}}}
var addnews_submitted=false;var addnews_function_submit=false;
function check_addnews(){if(addnews_submitted){if(addnews_function_submit){addnews_function_submit=false}else{alert("Your form has already been submitted. Please wait...")}
return false}
else{jQuery(".formerror").removeClass("formerror");addnews_submitted=true;var chk=0;
function validateField(field){var fieldname=jQuery("#"+field).val();if(fieldname==''){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");jQuery("#title_area").addClass("formerror");chk=1}else{jQuery("#r"+field).hide()}}
validateField("title");validateField("youtubeid");if(chk==0){addnews_function_submit=true;text=jQuery("#text").val();text=replaceTextWithHTML(text);jQuery("#text").val(text);w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show()}else{addnews_submitted=false;return false}}}
var addevent_submitted=false;var addevent_function_submit=false;
function check_addevent(){if(addevent_submitted){if(addevent_function_submit){addevent_function_submit=false}else{alert("Your form has already been submitted. Please wait...")}
return false}
else{addevent_submitted=true;var chk=0;
function validateField(field){var fieldname=jQuery("#"+field).val();if(fieldname==''){jQuery("#r"+field).hide();jQuery("#r"+field).fadeIn("slow");jQuery("#r"+field+"_area").addClass("formerror");chk=1}else{jQuery("#r"+field).hide();jQuery(".formerror").removeClass("formerror")}}
validateField("eventName");validateField("eventDate");if(chk==0){jQuery(".formerror").removeClass("formerror");addevent_function_submit=true;var text=jQuery("#eventDetail").val();text=replaceTextWithHTML(text);jQuery("#eventDetail").val(text);text=jQuery("#howToBook").val();text=replaceTextWithHTML(text);jQuery("#howToBook").val(text);w=jQuery(".popupborder").width();h=jQuery(".popupborder").height();jQuery(".submitOverlay").css({'width':w,'height':h}).show();jQuery("#loading").css({'left':w-40});jQuery("#loading").show()}else{addevent_submitted=false;return false}}}
function isValidEmailAddress(email){var RegExp=/^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
if(RegExp.test(email)){return true}else{return false}}


