/* proposaljs.php dargaville.net Fix - multi-questions/answers array/value ??? */ // // initialise data structures // if(!window.JOE){var JOE={};} if(typeof JOE.data=='undefined'){JOE.data={};} if(typeof JOE.event=='undefined'){JOE.event={};} JOE.data.request={}; JOE.data.pagesection={}; JOE.data.question={}; JOE.data.layout={}; JOE.data.answer={}; var o; // // format layout data // var lo=function(request,page,section,question,answers,classes){ var jdl=JOE.data.layout; if(!jdl[request]) jdl[request]={}; if(!jdl[request][page]) jdl[request][page]={}; if(!jdl[request][page][section]) jdl[request][page][section]={}; if(!jdl[request][page][section][question]) jdl[request][page][section][question]=[answers,classes]; } // // proposal // controls the main proposal // name not used as yet // JOE.proposal={ key:null, name:null, email:null, request:null, saveToCookie:function(){ if(this.key!=null) Cookie.write('key',this.key,{duration:30}); if(this.name!=null) Cookie.write('name',this.name,{duration:30}); if(this.email!=null) Cookie.write('email',this.email,{duration:30}); if(this.request!=null) Cookie.write('request',this.request,{duration:30}); }, copyToDoc:function(){ if(this.email!=null){ $('proposalCreateEmail').value=this.email; $('proposalCreateEmail').fireEvent('verify'); $('proposalForgotEmail').value=this.email; $('proposalForgotEmail').fireEvent('verify'); } if(this.key!=null) $('proposalKey').value=this.key; if(this.request!=null) $('requestOption').value=this.request; }, clear:function(){ this.key=null; this.email=null; this.request=null; // just remove key Cookie.dispose('key'); this.display(); }, display:function(){ if(this.key!=null){ JOE.core.hide('proposalKeyNotExists'); JOE.core.show('proposalKeyExists'); }else{ JOE.core.hide('proposalKeyExists'); JOE.core.show('proposalKeyNotExists'); } }, retrieve:function(){ // arguments are [number question, string answer],... JOE.data.answer={}; for(var i=0,l=arguments.length;iFrequently Asked Questions as your question may have already been answered.']; o[2]=['Business Solution Proposal','Business Solutions can range greatly from information sites to full e-commerce sites. These questions will help determine the type of business solution you may require at this stage of your business.']; o[3]=['Community Solution Proposal','Most community pages will be informational primarily focusing on keeping members informed and letting potential members know what your organisation is about.']; o[4]=['Open Source Proposal','There are many cheaper options, however Return on Investment is not alway apparent. Let us talk to you about your needs and if and how what available options may be appropriate.']; o[5]=['General comment','We are always happy to hear constructive comments. And if they are less than constructive, please still let us know as it will hopefully allow us to identify areas where we can improve our service.']; o[6]=['Site/Page correction','No one is perfect, let us know where we may be in error, or where we may be less than clear. Thank you for taking the time to help us improve our products and service to the Dargaville area.']; o[7]=['Site/Page/Business recommentation','The greatest source of ideas for improvement come from our customers and those who use our services. If you see areas where we can improve, please let us know. If it is something that we can use, we will show our appreciation.']; o[8]=['Directory - New Listing or Update','If your business or community group is not listed or needed to have information updated, please let us know.']; o=JOE.data.pagesection; o[1]=['General','General Details']; o[2]=['Contact','Contact Details']; o[3]=['Plan','Plan Purpose']; o[11]=['General Details','General Contact Details.']; o[12]=['Customer Details','Your business or community group name and contact details.']; o[13]=['Objectives','Help us understand your business or community group goals and objectives?']; o[14]=['Resources','What resources are available and what do you expect to provide as part of creating this project?']; o[15]=['Constraints','What limitations, constraints, or risks; either in time or resources may need to be factored into this project?']; o=JOE.data.question; o[1]=['Your Business Name','Your business, company, community group name or how your customers know you.','']; o[2]=['What does your business do?','What is the primary purpose of your business? What products or services do you currently provide.','']; o[3]=['Your name','Your name and title (also include how you would like to be addressed)','']; o[4]=['Your job position','What position or job function you perform for your company','']; o[5]=['Your contact details','Please include your phone number or other contact method including your prefered method and times of contact.','']; o[6]=['Your email','We need to be able to contact and reply by email.','']; o[7]=['Your physical and/or mailing addresses','Your address for face to face contact or .','']; o[8]=['Any other Your name and contact details','some helpful information','']; o[9]=['Notes or other comments','Any other information you deem useful','']; o[10]=['Your request or comment','How can we help or what can we do to improve our service','']; o[20]=['Your web page or internet project','Describe your project','']; o[21]=['Your business plan','Does you business have a business plan? In what way would this project support your plan?','']; o[22]=['Your timeframe','What timeframe do you need this project completed by?','']; o[23]=['Your people resources','What personnel and experience will your company provide in relation to what you anticipate you will need?','']; o[24]=['Your budget','What budget constraints do you have?','']; lo(1,1,11,3,1,'senderName'); lo(1,1,11,6,1,'senderEmail'); lo(1,1,11,10,1,''); lo(2,1,11,3,1,'senderName'); lo(2,1,11,5,1,''); lo(2,1,11,6,1,'senderEmail'); lo(2,1,12,9,0,''); lo(2,1,12,8,0,''); lo(2,1,12,7,0,''); lo(2,1,12,4,1,''); lo(2,1,12,2,1,''); lo(2,1,12,1,1,''); lo(2,2,13,20,0,''); lo(2,2,13,21,0,''); lo(2,2,13,22,0,''); lo(2,2,13,23,0,''); lo(2,2,13,24,0,''); window.addEvent('domready',function(){ // // declarations // var jda=JOE.data.answer, jdl=JOE.data.layout, jdp=JOE.data.pagesection, jdq=JOE.data.question, jdr=JOE.data.request, out=''; // // // miscellaneous function declarations // // // prepare answers in JOE.data.answer for POST // function currentAnswers(){ var jda=JOE.data.answer, answers=''; // get answers for(var answer in jda){ // only answers with values for(var a=0,l=jda[answer].length;a0 add class mandatory // add answers class and unique seq and number of mandatory entries to id // pageNNN is a reference back to the page number for validation checks against the class if(html.toLowerCase().indexOf('class="')!=-1){ html=html.replace('class="','class="answers page'+page+' '+(mandatoryEntries>0?'mandatory ':'')+classes+' '); html=html.replace('id="$q"','id="'+id+'"'); }else{ html=html.replace('id="$q"','class="answers page'+page+' '+(mandatoryEntries>0?'mandatory ':'')+classes+'" id="'+id+'"'); } html=html.replace('$v',details); return '
'+html+'
'; } function questionWithAnyExistingAnswers(question,config,page){ var jda=JOE.data.answer, answersExist=false, out='', seq=0; // // any existing answers // for(var answer in jda) if(parseInt(answer)==question){ answersExist=true; for(var a=0,la=jda[answer].length;a'+jdp[page][0]+''; for(var section in layout[page]){ var out=''; for(var question in layout[page][section]){ // number of manadatory entries required for question var config=layout[page][section][question]; out+=questionWithAnyExistingAnswers(question,config,page); } // if sections not on first page then hide outSection+= '
'+ ''+jdp[section][0]+''+ '
'+jdp[section][1]+'
'+ out+ '
'; } outSections+= '
'+ outSection+ '
'+ (pageSeq>1?'':'')+ (pageSeq':'')+ '
'+ '
'; } $('pages').innerHTML='Sections'+outPage; $('sections').innerHTML=outSections; // // // triggers for pages and section answers // // Custom events for answers <-> pages <-> submit // ok: process if ok // notOk: process if not ok // childrenOk: check ok status of children and invoke ok/notOk // verify: verify entry if okay and invoke ok/notOk // $$('.page').addEvents({ 'click':function(){ var page=this.getProperty('id').substring(4); // display section(s) $$('.pageSections').addClass('hide'); $$('#pageSection'+page).removeClass('hide'); // highlight section $$('#pages div').removeClass('current'); this.addClass('current'); }, 'ok':function(){ this.addClass('ok'); this.removeClass('notOk'); $('submitProposal').fireEvent('childrenOk'); }, 'notOk':function(){ this.addClass('notOk'); this.removeClass('ok'); $('submitProposal').fireEvent('notOk'); }, 'childrenOk':function(){ var page=this.getProperty('id').substring(4), ok=true; // check that each question for this page is ok $$('.answers.page'+page).each(function(el){ if(!el.hasClass('ok')) ok=false; }) this.fireEvent(ok?'ok':'notOk'); }, 'verify':function(){ var page=this.getProperty('id').substring(4); $$('.answers.page'+page).each(function(el){ el.fireEvent('verify'); }) this.fireEvent('childrenOk'); } }); // // store and verify answers // $$('.answers').addEvents({ 'blur':function(){ this.fireEvent('changes'); }, 'focus':function(){ if(this.hasClass('email')&&this.value=='') this.value=JOE.proposal.email; }, 'keyup':function(){ if(this.hasClass('notOk')) this.fireEvent('changes'); }, 'changes':function(){ // store data.answer var jda=JOE.data.answer, arr=this.get('id').split('_'), question=arr[1], seq=arr[2]; if(typeof jda[question]=='undefined') jda[question]=[]; jda[question][seq]=this.value; // if(this.hasClass('senderName')) JOE.proposal.name=this.value; if(this.hasClass('senderEmail')) JOE.proposal.email=this.value; // verify this.fireEvent('verify'); }, 'ok':function(){ this.addClass('ok'); this.removeClass('notOk'); var parent='page'+this.get('id').split('_')[4]; // notify parent of change $(parent).fireEvent('childrenOk'); }, 'notOk':function(){ this.addClass('notOk'); this.removeClass('ok'); var parent='page'+this.get('id').split('_')[4]; // notify parent of change $(parent).fireEvent('notOk'); }, 'verify':function(){ var page=this.get('id').split('_')[4], alerted=false; // remove existing alerts this.removeClass('alertMandatory'); this.removeClass('alertEmail'); if(this.hasClass('mandatory')&&this.value==''){ this.addClass('alertMandatory'); alerted=true; } if(!alerted&& this.value!=''&& this.hasClass('email')&& !JOE.core.checkEmail(this.value) ){ this.addClass('alertEmail'); alerted=true; } this.fireEvent(alerted?'notOk':'ok'); } }); // force $$('.page').fireEvent('verify'); }; // // display request when request specified i.e. proposal.php?request=1 // // find url parameter value function gup(name){ name=name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regexS="[\\?&]"+name+"=([^&#]*)"; var regex=new RegExp(regexS); var results=regex.exec(window.location.href); return results==null ?"" :results[1]; } var p_request=gup('request'); if(p_request!=""){ $('requestOption').value=p_request; $('requestOption').onchange(); // trigger } // // cookie defaults // populate fields // var nameCrumb=Cookie.read('name'), emailCrumb=Cookie.read('email'), keyCrumb=Cookie.read('key'); if(nameCrumb!=null){JOE.proposal.name=nameCrumb;} if(emailCrumb!=null){JOE.proposal.email=emailCrumb;} if(keyCrumb!=null){JOE.proposal.key=keyCrumb;} JOE.proposal.copyToDoc(); // // cookie update triggers // $$('#proposalCreateEmail','#proposalForgotEmail').addEvent('change',function(){ if(this.value!='') Cookie.write('email',this.value,{duration:30}); else Cookie.dispose('email'); }); // // // initialise - proposal options // // // create // // email valid $('proposalCreateEmail').addEvents({ 'keyup':function(){$('proposalCreate').fireEvent('verify');}, 'blur':function(){ JOE.event.classValidator.isMandatoryAlert(this); // if value exists if(this.value!='') JOE.event.classValidator.isEmailAlert(this); $('proposalCreate').fireEvent('verify'); }, 'focus':function(){JOE.event.classValidator.clearAlerts(this);} }); $('proposalCreate').addEvents({ 'click':function(){ var request=$('requestOption'), email=$('proposalCreateEmail').value; if(request.value==0){ alert('Please first select a type of communication'); request.focus(); return false; } var req=new Request({ url:'lib/php/proposalKey.php', data:'create='+encodeURI(email)+'&request='+request.value+currentAnswers(), onSuccess:function(responseText,responseXML){ eval(responseText); if(error) alert('Error: Not able to create proposal.\n'+errorMsg); else{ JOE.proposal.key=key; JOE.proposal.email=email; JOE.proposal.request=parseInt(request.value); JOE.proposal.copyToDoc(); JOE.proposal.saveToCookie(); JOE.proposal.display(); request.onchange(); } }, onFailure:function(){alert('system failure on request for proposal key, please notify administrator');} }).send(); return true; }, 'verify':function(){ var email=$('proposalCreateEmail'); this.disabled=!(JOE.event.classValidator.isMandatoryAndFilled(email)&&JOE.event.classValidator.isEmailFormatCorrect(email)); } }); $('proposalCreate').fireEvent('verify'); // validate any cookie defaults // // retrieve // $('proposalKeyEntry').addEvent('keyup',function(){ $('proposalKeyRetrieve').fireEvent('verify'); }); $('proposalKeyRetrieve').addEvents({ 'click':function(){ var key=$('proposalKeyEntry').value; var req=new Request({ url:'lib/php/proposalKey.php', data:'retrieve='+encodeURI(key), onSuccess:function(responseText,responseXML){ eval(responseText); if(error) alert(errorMsg); else{ JOE.proposal.key=key; JOE.proposal.copyToDoc(); JOE.proposal.saveToCookie(); JOE.proposal.display(); $('requestOption').onchange(); } }, onFailure:function(){alert('request for key(s) failed, please notify administrator');} }).send(); return true; }, 'verify':function(){ // actually length >4 but not to be hinted at this.disabled=($('proposalKeyEntry').value.length<3); } }); $('proposalKeyRetrieve').fireEvent('verify'); // validate any cookie defaults // // forgot // // email valid $('proposalForgotEmail').addEvents({ 'keyup':function(){$('proposalForgot').fireEvent('verify');}, 'blur':function(){ JOE.event.classValidator.isMandatoryAlert(this); // if value exists if(this.value!='') JOE.event.classValidator.isEmailAlert(this); $('proposalForgot').fireEvent('verify'); }, 'focus':function(){JOE.event.classValidator.clearAlerts(this);} }); $('proposalForgot').addEvents({ 'click':function(){ var email=$('proposalForgotEmail'); // send email var req=new Request({ url:'lib/php/proposalKey.php', data:'forgot='+encodeURI(email.value), onSuccess:function(responseText,responseXML){ alert(responseText); }, onFailure:function(){alert('request for key(s) failed, please notify administrator');} }).send(); return true; }, 'verify':function(){ var email=$('proposalForgotEmail'); this.disabled=!(JOE.event.classValidator.isMandatoryAndFilled(email)&&JOE.event.classValidator.isEmailFormatCorrect(email)); } }); $('proposalForgot').fireEvent('verify'); // force to valid any cookie defaults // // save // $('proposalSave').addEvent('click',function(){ var out=currentAnswers(); // get answers if(out==''){ alert('No answers to save'); return; } var req=new Request({ url:'lib/php/proposalKey.php', data:'save='+JOE.proposal.key+'&request='+$('requestOption').value+out, onSuccess:function(responseText,responseXML){ eval(responseText); if(error) alert(errorMsg); }, onFailure:function(){alert('request for key(s) failed, please notify administrator');} }).send(); }); // // clear // $('proposalClear').addEvent('click',function(){ // update display JOE.proposal.clear(); }); // // delete // $('proposalDelete').addEvent('click',function(){ if(window.confirm("Please confirm to completely remove your proposal key and any existing answers?")){ var req=new Request({ url:'lib/php/proposalKey.php', data:'delete='+JOE.proposal.key, onSuccess:function(responseText,responseXML){ eval(responseText); JOE.proposal.key=null; JOE.proposal.display(); }, onFailure:function(){alert('request for key(s) failed, please notify administrator');} }).send(); } }); // // Submit Proposal // $('submitProposal').addEvents({ 'click':function(){ // check pages ok - we have to verify if users try to skip ahead var ok=true; $$('.page').each(function(el){ // verify - may not have been entered yet if(!el.hasClass('ok')) el.fireEvent('verify'); if(!el.hasClass('ok')) ok=false; }) if(!ok){ alert('Errors exist, please correct and then try re-submitting') this.disabled=true; return false; } if(!window.confirm("Finalisation process\nThe details entered will be sent to your email address.\nThe final step will be for you to review that email and then reply.\n\nDo you wish to continue?")) return false; // send email var req=new Request({ url:'lib/php/proposalKey.php', data:'submit='+JOE.proposal.request+ '&name='+encodeURI(JOE.proposal.name.replace(/&/g,'%26'))+ '&email='+encodeURI(JOE.proposal.email.replace(/&/g,'%26'))+ currentAnswers(), onRequest:function(){ $('content').innerHTML='

Your communication is being processed

'; }, onSuccess:function(responseText,responseXML){ $('content').innerHTML= '

Your communication has been sent to your email

\

To complete this process

\
    \
  1. Go to your email
  2. \
  3. Review
  4. \
  5. You can adjust the email content
  6. \
  7. Add attachments if required
  8. \
  9. Reply or forward on to us
  10. \
\

Thank you - Dargaville.NET team

\

'+responseText+'

'; }, onFailure:function(){alert('sorry request/comment submission failed, please contact adminstrator');} }).send(); return true; }, 'ok':function(){ this.disabled=false; }, 'notOk':function(){ this.disabled=true; }, 'childrenOk':function(){ var ok=true; // check that each question for this page is valid $$('.page').each(function(el){ if(el.hasClass('alertInvalid','alertMandatory')) ok=false; }) this.fireEvent(ok?'ok':'notOk'); } }); // // // // closable proposal accordion - major adaption of http://pr0digy.com/mootools/mootools-slide-effect/ // // // void function(){ var list=$$('#proposalAccordion dd'), headings=$$('#proposalAccordion dt'), collapsibles=[]; headings.each(function(heading,i){ // add properties to heading object heading.isOpen=false; heading.slider=new Fx.Slide(list[i],{ duration:500, transition:Fx.Transitions.quadIn }); // heading pointers collapsibles[i]=heading; // trigger heading.onclick=function(){ // reset all others for(var j=0,l=collapsibles.length;j