
var siteurl='http://www.cbes.org.nz';var secureurl='https://www.cbes.org.nz';function confirmdelete(){if(confirm("Are you sure you want to delete this?")==true){return true;}else{return false;}}
function xyz(c,a,b,s){var s=(s==null)?true:s;var o='';var m='';var m2=':otliam';for(i=0;i<=b.length;i++){o=b.charAt(i)+o;}
b=o;for(i=0;i<=m2.length;i++){m=m2.charAt(i)+m;}
if(!s){m='';}
return m+a+unescape('%'+'4'+'0')+b+'.'+c;}
function validate(val,type){if(type=='email'){return val.match(/^(?:^[A-Z0-9._%-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|org|net|biz|info|name|aero|biz|info|jobs|museum|name)$)$/i);}else if(type=='url'){return val.match(/^(?:\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])$/i);}else if(type=='integer'){return val.match(/^-?[0-9]+$/i);}}
function validateEmail(str){var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if(str.indexOf(at)==-1){return false}
if(str.indexOf(at)==-1||str.indexOf(at)==0||str.indexOf(at)==lstr){return false}
if(str.indexOf(dot)==-1||str.indexOf(dot)==0||str.indexOf(dot)==lstr){return false}
if(str.indexOf(at,(lat+1))!=-1){return false}
if(str.substring(lat-1,lat)==dot||str.substring(lat+1,lat+2)==dot){return false}
if(str.indexOf(dot,(lat+2))==-1){return false}
if(str.indexOf(" ")!=-1){return false}
return true}
function showhide(region){if(document.getElementById){if(document.getElementById(region).style.display=='none'){document.getElementById(region).style.display='block';}else{document.getElementById(region).style.display='none';}}else{alert('Sorry, your browser doesn\'t support this');}}
function showregion(region){if(document.getElementById){document.getElementById(region).style.display='block';}else{alert('Sorry, your browser doesn\'t support this');}}
function hideregion(region){if(document.getElementById){document.getElementById(region).style.display='none';}else{alert('Sorry, your browser doesn\'t support this');}}
function setCookie(name,value,expires,path,domain,secure){document.cookie=name+"="+escape(value)+
((expires)?"; expires="+expires.toGMTString():"")+
((path)?"; path="+path:"")+
((domain)?"; domain="+domain:"")+
((secure)?"; secure":"");}
function getCookie(name){var dc=document.cookie;var prefix=name+"=";var begin=dc.indexOf("; "+prefix);if(begin==-1){begin=dc.indexOf(prefix);if(begin!=0)return null;}else{begin+=2;}
var end=document.cookie.indexOf(";",begin);if(end==-1){end=dc.length;}
return unescape(dc.substring(begin+prefix.length,end));}
function deleteCookie(name,path,domain){if(getCookie(name)){document.cookie=name+"="+
((path)?"; path="+path:"")+
((domain)?"; domain="+domain:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT";}}
function isNull(a){return typeof a=='object'&&!a;}
function nl2br(myString){return myString.replace(/\n/g,'<br />\n');}
$(document).ready(function(){$('input.post_redirect_submit').mouseover(function(){window.status=this.title;return true;});$('input.post_redirect_submit').mouseout(function(){window.status='Done';return true;});});function frajax(action,a,b,c,d,e,f,g,h,i,j){var url=siteurl;var r=/(http|https):\/\/.*/;var m=r.exec(window.location);if(m!=null&&m.length>1){if(m[1]=='https'){url=secureurl;}}
url+='/actions/'+action+'.php?';if(a){url+='arg1='+encodeURIComponent(a);}
if(b){url+='&arg2='+encodeURIComponent(b);}
if(c){url+='&arg3='+encodeURIComponent(c);}
if(d){url+='&arg4='+encodeURIComponent(d);}
if(e){url+='&arg5='+encodeURIComponent(e);}
if(f){url+='&arg6='+encodeURIComponent(f);}
if(g){url+='&arg7='+encodeURIComponent(g);}
if(h){url+='&arg8='+encodeURIComponent(h);}
if(i){url+='&arg9='+encodeURIComponent(i);}
if(j){url+='&arg10='+encodeURIComponent(j);}
document.getElementById('frajax-iframe').src=url;return false;}
function convert_currency(){if(!$('#convert_currency_from').val()||!$('#convert_currency_to').val()){return;}
$('#convert_currency_result').html('<img src="images/ajax-loader.gif" alt="Loading"/>');$.getJSON('json/convertcurrency.php',{'from':$('#convert_currency_from').val(),'to':$('#convert_currency_to').val(),'amount':$('#convert_currency_amount').val()},function(data){$('#convert_currency_result').html(data);});}
function updateCountry(country,section){if(!country){return;}
$.getJSON(siteurl+'/json/jojo_cart_country_hasstates.php',{c:country},function(data){if(data){updateCountryStates(country,section);}else{updateCountryCities(country,section);$('#'+section+'_state').attr('disabled',true);}});}
function updateCountryCities(country,section){$.getJSON(siteurl+'/json/jojo_cart_country_cities.php',{c:country},function(data){target=$('#'+section+'_city');if(!data.length){var textbox=document.createElement('input');$(textbox).attr('id',target.attr('id'));$(textbox).attr('name',target.attr('name'));if(target.val()){$(textbox).val(target.val());}
target.replaceWith(textbox);}else{var selectbox=document.createElement('select');$(selectbox).attr('id',target.attr('id'));$(selectbox).attr('name',target.attr('name'));option=new Option('','');selectbox.options.add(option);for(i=0;i<data.length;i++){option=new Option(data[i],data[i]);selectbox.options.add(option);}
if(target.val()){$(selectbox).val(target.val());}
target.replaceWith(selectbox);}});}
function updateStateCities(country,state,section){if(!country||!state){return;}
$.getJSON(siteurl+'/json/jojo_cart_state_cities.php',{c:country,s:state},function(data){target=$('#'+section+'_city');if(!data.length){var textbox=document.createElement('input');$(textbox).attr('id',target.attr('id'));$(textbox).attr('name',target.attr('name'));if(target.val()){$(textbox).val(target.val());}
target.replaceWith(textbox);}else{var selectbox=document.createElement('select');$(selectbox).attr('id',target.attr('id'));$(selectbox).attr('name',target.attr('name'));option=new Option('','');selectbox.options.add(option);for(i=0;i<data.length;i++){option=new Option(data[i],data[i]);selectbox.options.add(option);}
if(target.val()){$(selectbox).val(target.val());}
target.replaceWith(selectbox);}});}
function updateCountryStates(country,section){$.getJSON(siteurl+'/json/jojo_cart_country_states.php',{c:country},function(data){target=$('#'+section+'_state');if(!data.length){var textbox=document.createElement('input');$(textbox).attr('id',target.attr('id'));$(textbox).attr('name',target.attr('name'));if(target[0].tagName=='INPUT'&&target.val()){$(textbox).val(target.val());}
target.replaceWith(textbox);}else{var selectbox=document.createElement('select');$(selectbox).attr('id',target.attr('id'));$(selectbox).attr('name',target.attr('name'));option=new Option('','');selectbox.options.add(option);for(i=0;i<data.length;i++){option=new Option(data[i]['state'],data[i]['statecode']);selectbox.options.add(option);}
$(selectbox).bind('change',function(){updateStateCities(country,$(this).val(),section);});if(target.val()){$(selectbox).val(target.val());}
target.replaceWith(selectbox);updateStateCities(country,$(selectbox).val(),section)}
target=$('#'+section+'_city');var textbox=document.createElement('input');$(textbox).attr('id',target.attr('id'));$(textbox).attr('name',target.attr('name'));if(target.val()){$(textbox).val(target.val());}
target.replaceWith(textbox);});}
function checkArticleComment(emailrequired){if(emailrequired==undefined){var emailrequired=true;}
var i=0;var errors=new Array();if(document.getElementById('name').value==''){errors[i++]='Name is a required field';}
if(emailrequired&&(document.getElementById('email').value=='')){errors[i++]='Email is a required field';}
else if(emailrequired&&!validateEmail(document.getElementById('email').value)){errors[i++]='Email is not a valid email format';}
if(document.getElementById('comment').value==''){errors[i++]='Please enter a comment';}
if(document.getElementById('captchacode')&&(document.getElementById('captchacode').value=='')){errors[i++]='Please enter the CAPTCHA code (required to prevent spam)';}
if(errors.length==0){return(true);}else{alert(errors.join("\n"));return(false);}}
var slidedelay=6000;var fadedelay=2000;$(document).ready(function(){if($('#imageContainer').children().length>1){$('#imageContainer').children(':first-child').addClass("showbanner");setTimeout(nextSlide,slidedelay);}});function nextSlide(){var images=$('#imageContainer').children();$(images).each(function(i){if($(this).hasClass("showbanner")){$(this).fadeOut(fadedelay).removeClass("showbanner");var nextIndex=(i==(images.length-1))?0:i+1;$(images[nextIndex]).fadeIn(fadedelay).addClass("showbanner");$('#caption').html($(images[nextIndex]).attr("title"));setTimeout(nextSlide,slidedelay);return false}});}
function jojo_slideshow(id,delay,speed){var selector='#'+id;var spantitle=$(selector+' span:first').attr('title');$(selector+' span:first').before('<img src="'+$(selector+' span:first').attr('rel')+'" alt="" title="'+spantitle+'" />').remove();if($(selector+' div').size()==0){$(selector).append("<div></div>");}
if(!delay){var delay=5000;}
if(!speed){var speed=1000;}
var current=$(selector+' img.current');var next=$(selector+' img.current + img:hidden').size()?$(selector+' img.current + img:hidden'):$(selector+' img:first');var currenttitle=current.attr('title');if((currenttitle!=undefined)&(currenttitle!='undefined')&(currenttitle!='')){$(selector+' div').html(currenttitle).show('fast');}
$(selector).css('background-image','url("'+next.attr('src')+'")');current.fadeTo(delay,1,function(){$(selector+' div').hide('fast').html('');}).fadeOut(speed,function(){var current=$(selector+' img.current');var next=($(selector+' img.current + img:hidden').size()>0)?$(selector+' img.current + img:hidden'):$(selector+' img:first');current.removeClass('current');next.addClass('current').show();jojo_slideshow(id,delay,speed);});}
$(document).ready(function(){$('input.quantity').change(function(){var id=$(this).attr('id');var code=id.replace(/quantity\[(.*?)\]/ig,"$1");$.getJSON('json/jojo_cart_change_quantity.php',{qty:$(this).val(),code:code},change_quantity_callback);});$('input.quantity').bind('focus',function(){if($(this).val()=='0'){$(this).val('');}});});function change_quantity_callback(data)
{$('#row_'+data.code+' td.cart-linetotal span.linetotal').html(data.linetotal.toFixed(2));$('#row_'+data.code+' input.quantity').val(data.quantity);$('#subtotal').html(data.subtotal.toFixed(2));$('#total').html(data.total.toFixed(2));}
$(document).ready(function(){$('#home_buttons a').html('');$('.courseform').submit(function(){errors=new Array();i=0;$(this).find('.required').each(function(){if($(this).val()==''){errors[i++]=$(this).attr('title')+' is a required field';}});var n=$(this).find("input:checked").length;if(n==0){errors[i++]='Please confirm these details are correct by checking the declaration box';}
if(errors.length==0){return(true);}else{alert(errors.join("\n"));return(false);}});});$(document).ready(function(){$('#Callsignapp').submit(function(){errors=new Array();i=0;$(this).find('.required').each(function(){if($(this).val()==''){errors[i++]=$(this).attr('title')+' is a required field';}});var x=$(this).find("#vhfixed:checked").length;var y=$(this).find("#vhfhandheld:checked").length;if((x==0)&&(y==0)){errors[i++]='Please select either VHF fixed or VHF handheld under equipment carried.';}
if(errors.length==0){return(true);}else{alert(errors.join("\n"));return(false);}});});$(document).ready(function(){if($(window).height()>=$(document).height()){$('#topbutton').hide();}});$(document).ready(function(){initMenu();$('h1:first').each(function(){$("#menu li.selected a").each(function(){var offset=($("h1:first").position().top-$("#menu li.selected a").position().top);offset=130-$("h1:first").height()-offset;$('#menu li.selected a').css('background-position','-'+($("#menu li.selected a").position().left-$("h1:first").position().left)+'px -'+offset+'px');});});});function initMenu(){$('#subnav ul ul').hide();if($('#subnav ul li.selected').length>0){$('#subnav ul li.selected ul').show();}else{$('#subnav ul li:first ul').show();}
$('#subnav ul li a:not(#subnav ul li ul li a)').click(function(){$('#subnav li').removeClass('selected');var checkElement=$(this).next();if((checkElement.is('ul'))&&(checkElement.is(':visible'))){return false;}
if((checkElement.is('ul'))&&(!checkElement.is(':visible'))){$('#subnav ul ul:visible').slideUp('normal');checkElement.slideDown('normal');$(this).parent().addClass('selected');return false;}});}
(function($){$.preLoadImages=function(imageList,callback){var pic=[],i,total,loaded=0;if(typeof imageList!='undefined'){if($.isArray(imageList)){total=imageList.length;for(i=0;i<total;i++){pic[i]=new Image();pic[i].onload=function(){loaded++;if(loaded==total){if($.isFunction(callback)){callback();}}};pic[i].src=imageList[i];}}
else{pic[0]=new Image();pic[0].onload=function(){if($.isFunction(callback)){callback();}}
pic[0].src=imageList;}}
pic=undefined;};$.preLoadCSSImages=function(callback){var pic=[],i,imageList=[],loaded=0,total,regex=new RegExp("url\((.*)\)",'i'),spl;var cssSheets=document.styleSheets,path,myRules,Rule,match,txt,img,sheetIdx,ruleIdx;for(sheetIdx=0;sheetIdx<cssSheets.length;sheetIdx++){var sheet=cssSheets[sheetIdx];if(typeof sheet.href=='string'&&sheet.href.length>0){spl=sheet.href.split('/');spl.pop();path=spl.join('/')+'/';}
else{path='./';}
myRules=sheet.cssRules?sheet.cssRules:sheet.rules;for(ruleIdx=0;ruleIdx<myRules.length;ruleIdx++){Rule=myRules[ruleIdx];txt=Rule.cssText?Rule.cssText:Rule.style.cssText;match=regex.exec(txt);if(match!=null){img=match[1].substring(1,match[1].indexOf(')',1));if(img.substring(0,4)=='http'){imageList[imageList.length]=img;}
else if(match[1].substring(1,2)=='/'){var p2=path.split('/');p2.pop();p2.pop();p2x=p2.join("/");imageList[imageList.length]=p2x+img;}
else{imageList[imageList.length]=path+img;}}};};total=imageList.length;for(i=0;i<total;i++){pic[i]=new Image();pic[i].onload=function(){loaded++;if(loaded==total){if($.isFunction(callback)){callback();}}};pic[i].src=imageList[i];}};$.preLoadAllImages=function(imageList,callback){if(typeof imageList!='undefined'){if($.isFunction(imageList)){callback=imageList;}
else if(!$.isArray(imageList)){imageList=[imageList];}}
$.preLoadCSSImages(function(){if(imageList.length>0){$.preLoadImages(imageList,function(){callback();});}
else{callback();}});}})(jQuery);
