/*
	Copyright Trinity Mirror $Date: 2009-09-07 17:13:32 +0100 (Mon, 07 Sep 2009) $
	$Revision: 53058 $

		
*/

tm.doIt={};tm.doIt.haveResults=false;tm.doIt.eyeBlasterActivity={landingPage:37941,doItResults:37942,doItViewDetails:37943,doItEnvironment:37944,insightBrochureRequestButton:37945,testDriveButton:37946,dealerLocatorButton:37947,doItClickablelogo:37948,dataCaptureButton:37949,tellUsHowYoureDoingIt:37950,readYourDoItStories:38834};tm.doIt.getRefererSiteName=function(){if(typeof tm.doIt.refererSiteName=='undefined'){if(!tm.adv){tm.doIt.refererSiteName='';}else{tm.doIt.refererSiteName=tm.adv.getBrandingSiteName();}
if(tm.doIt.refererSiteName==null){tm.doIt.refererSiteName='';}}
return tm.doIt.refererSiteName;}
tm.doIt.getDoItSearchResultDetailURL=function(){return'/_services/ajax/ajaxController.js?event='
+'queryDoIt&refererSiteName='+tm.doIt.getRefererSiteName()+'&OppID=';}
tm.doIt.getDoItRegistrationFormURL=function(){return'/_services/ajax/ajaxController.js?event='
+'queryDoIt&mode=getPartnerCode&refererSiteName='
+tm.doIt.getRefererSiteName()
+'&OppID=';}
tm.doIt.getDoItRegistrationSubmissionURL=function(){return'/_services/ajax/ajax_controller.cfm?event='
+'queryDoIt&mode=sendRegEmail&refererSiteName='
+tm.doIt.getRefererSiteName();}
tm.doIt.getDoItSearchURL=function(){return'/_services/ajax/ajaxController.js?event=queryDoIt&interests='
+tm.doIt.interest+'&distance='+tm.doIt.distance
+'&location='+tm.doIt.loc+'&keywords='+tm.doIt.keywords
+'&activity='+tm.doIt.activity+'&refererSiteName='+tm.doIt.getRefererSiteName();}
tm.doIt.getDoItSearchResults=(function(xml,stat){var resultEl=$('#localOpportunitiesTab');var detailsEl=$('#detailsContainer');var resultCount=$(xml).find("OppsReturned").text();var locations=$(xml).find("Locations");if(locations.text()==''){var resHTML="";resHTML+='<div class="span-47 last">';resHTML+="<p>You searched for volunteer opportunities within "+tm.doIt.distance;resHTML+=" km of "+tm.doIt.loc+'</p>';resHTML+='<p>'+resultCount+' opportunities found </p>';resHTML+='<p>Displaying results 1 to '+resultCount+' in order of proximity </p>';$(xml).find("OppList").find("Opportunity").each(function(){var opportunity=$(this);resHTML+='<h2><a class="detailsLink" href="javascript:tm.doIt.';resHTML+='loadOpportunityDetail('+opportunity.find("OppID").text()+')">';resHTML+=opportunity.find("Title").text();resHTML+='</a></h2>';resHTML+='<p class="search-results-location">';resHTML+=opportunity.find("OrgName").text();resHTML+='<br/>';resHTML+=opportunity.find("Distance").text();resHTML+=' km </p><p>';resHTML+=opportunity.find("Description").text();resHTML+='<br/>';resHTML+='<a class="detailsLink" href="javascript:tm.doIt.loadOpportunityDetail(';resHTML+=opportunity.find("OppID").text()+')"><strong>';resHTML+='More information and contact details';resHTML+='</strong></a></p>';resHTML+='<div class="border"></div>';})
resHTML+='</div>';tm.doIt.getDoItSearchResultsCounty(xml,stat);$('#do-it-tabs').show();resultEl.html(resHTML);if(tm.doIt.showResultsThisTime){resultEl.show();detailsEl.hide();tm.doIt.setWrapEl('honda-search','honda_search');tm.doIt.trackEvent(tm.doIt.eyeBlasterActivity.doItResults);tm.doIt.haveResults=true;}else{tm.doIt.showResultsThisTime=true;}}else{tm.doIt.displayLocations(locations);}});tm.doIt.displayLocations=(function(locations){var resHTML='';var resultEl=$('#localOpportunitiesTab');var detailsEl=$('#detailsContainer');var selectedLoc='';resHTML+='<p>We found a number of locations matching the location you entered. ';resHTML+='Please choose an option from the list below.</p>';locations.find('Location').each(function(){selectedLoc=$(this).find('Name').text();resHTML+='<p><a href="javascript:tm.doIt.getSearchResults('+"'"+selectedLoc+"'"+')">';resHTML+=$(this).find('Name').text();resHTML+='</a></P>';});resultEl.html(resHTML);if(tm.doIt.showResultsThisTime){resultEl.show();detailsEl.hide();tm.doIt.trackEvent(tm.doIt.eyeBlasterActivity.doItResults);}
tm.doIt.showResultsThisTime=true;});tm.doIt.getSearchResults=(function(selectedLoc){tm.doIt.loc=selectedLoc;$.ajax({url:tm.doIt.getDoItSearchURL(),type:'GET',format:'xml',success:tm.doIt.getDoItSearchResults,error:function(){tm.doIt.showError('results')}});});tm.doIt.showError=(function(errorType){if(errorType=='results'){var msg='Error fetching results from DO-IT';$('#localOpportunitiesTab').html(msg);}else if(errorType=='email'){var msg='Error registering your interest please try again later';$('#localOpportunitiesTab').html(msg);}else{var msg='Error fetching opportunity details from DO-IT';$('#detailsContainer').html(msg);}});tm.doIt.getDoItSearchResultsCounty=(function(xml,stat){var countyEl=$('#countyOpportunitiesTab');var resHTML=""
var resultCount=$(xml).find("CountyOppsReturned").text();resHTML+='<div class="span-47 last">';resHTML+="<p>You searched for volunteer opportunities within "+tm.doIt.distance+" km of ";resHTML+=tm.doIt.loc+'</p>';if(resultCount>0){resHTML+='<p>'+resultCount+' opportunities found </p>';resHTML+='<p>Displaying results 1 to '+resultCount+' in order of proximity </p>';}
else{resHTML+='<p>No results matching your search</p>';resHTML+='<p>Please try a broader search</p>';}
$(xml).find("CountyOpps").find("Opportunity").each(function(){var opportunity=$(this);resHTML+='<h2><a class="detailsLink" href="javascript:tm.doIt.loadOpportunityDetail(';resHTML+=opportunity.find("OppID").text()+')">';resHTML+=opportunity.find("Title").text();resHTML+='</a></h2>';resHTML+='<p class="search-results-location">';resHTML+=opportunity.find("OrgName").text();resHTML+='</p><p>';resHTML+=opportunity.find("Description").text();resHTML+='<br/>';resHTML+='<a class="detailsLink" href="javascript:tm.doIt.loadOpportunityDetail(';resHTML+=opportunity.find("OppID").text()+')">';resHTML+='<strong>More information and contact details</strong>';resHTML+='</a></p>';resHTML+='<div class="border"></div>';});resHTML+='</div>';countyEl.html(resHTML);countyEl.hide();});tm.doIt.loadOpportunityDetail=function(opportunityId){$.ajax({url:tm.doIt.getDoItSearchResultDetailURL()+opportunityId,type:'GET',format:'xml',success:tm.doIt.getDoItSearchResultsDetails,error:function(){tm.doIt.showError('Details')}});}
tm.doIt.getDoItSearchResultsDetails=function(detailsXML,stat){var resHTML="";var opportunity=$(detailsXML).find('Opportunity');var infoProvider=$(detailsXML).find('InfoProvider');var resultEl=$('#searchResultsContainer');var detailsEl=$('#detailsContainer');if(opportunity.length){resHTML+='<div class="span-47 last">';resHTML+='<h2>Opportunity details</h2>';resHTML+='<h1>'+opportunity.find("Title").text()+'</h1>';resHTML+='<h2>'+opportunity.find("OrgName").text()+'</h2>';if(opportunity.find("Description").text().length){resHTML+='<h2>The Opportunity</h2><p>';resHTML+=opportunity.find("Description").text()+'</p>';}
if(opportunity.find("OrgDescription").text().length){resHTML+='<h2>The Organisation</h2><p>';resHTML+=opportunity.find("OrgDescription").text()+'</p>';}
if(opportunity.find("SkillsQualifications").text().length){resHTML+='<h2>Skills / Qualifications</h2><p>';resHTML+=opportunity.find("SkillsQualifications").text()+'</p>';}
if(opportunity.find("GettingThere").text().length){resHTML+='<h2>Getting there</h2><p>';resHTML+=opportunity.find("GettingThere").text()+'</p>';}
resHTML+='<h2>Times you can volunteer:</h2>';resHTML+='<ul class="getting-there">';resHTML+='<li>Monday: ';resHTML+=opportunity.find("Monday").text();resHTML+='</li>';resHTML+='<li>Tuesday: ';resHTML+=opportunity.find("Tuesday").text();resHTML+='</li>';resHTML+='<li>Wednesday: ';resHTML+=opportunity.find("Wednesday").text();resHTML+='</li>';resHTML+='<li>Thursday: ';resHTML+=opportunity.find("Thursday").text();resHTML+='</li>';resHTML+='<li>Friday: ';resHTML+=opportunity.find("Friday").text();resHTML+='</li>';resHTML+='<li>Saturday: ';resHTML+=opportunity.find("Sat").text();resHTML+='</li>';resHTML+='<li>Sunday: ';resHTML+=opportunity.find("Sunday").text();resHTML+='</li><li></li>';resHTML+='</ul>';resHTML+='<h2>Interested?</h2>';resHTML+="<p>For more details or to apply for this opportunity, click the button below ";resHTML+="to complete the online registration form. If you've registered before, ";resHTML+="you can review your details before submitting</p>";resHTML+='<div class="honda-button apply-button">';resHTML+='<a href="javascript:tm.doIt.loadForm('+opportunity.find('OppID').text()
+');"> APPLY FOR THIS OPPORTUNITY </a></div>';resHTML+='<div id="clear"></div>';resHTML+='<ul><li>Our thanks to:</li>';if(infoProvider.find("Name").text().length){resHTML+='<li>'+infoProvider.find("Name").text()+'</li>';}
resHTML+='<li>';if(infoProvider.find("Address1").text().length){resHTML+=infoProvider.find("Address1").text();}
if(infoProvider.find("Address2").text().length){resHTML+=', '+infoProvider.find("Address2").text();}
if(infoProvider.find("Address3").text().length){resHTML+=', '+infoProvider.find("Address3").text();}
resHTML+='</li>';if(infoProvider.find("Town").text().length){resHTML+='<li>'+infoProvider.find("Town").text()+'</li>';}
if(infoProvider.find("Postcode").text().length){resHTML+='<li>'+infoProvider.find("Postcode").text()+'</li>';}
if(infoProvider.find("Telephone").text().length){resHTML+='<li> Phone: ';resHTML+=infoProvider.find("Telephone").text()+'</li>';}
if(infoProvider.find("Email").text().length){resHTML+='<li>Email: <a href="mailto:'+infoProvider.find("Email").text()+'" >';resHTML+=infoProvider.find("Email").text()+'</a></li>';}
if(infoProvider.find("Website").text().length){resHTML+='<li> Website: ';if(infoProvider.find("Website").text().indexOf("http")==-1){resHTML+='<a href="http://'+infoProvider.find("Website").text()+'" >';}
else{resHTML+='<a href="'+infoProvider.find("Website").text()+'" >';}
resHTML+=infoProvider.find("Website").text()+'</a></li>';}
resHTML+='for providing this opportunity';resHTML+='<li>';resHTML+='<a href="javascript:tm.doIt.showResults()">Back to the search results page</a>';resHTML+='</li></ul>';resHTML+='</div>';}
detailsEl.html(resHTML);resultEl.hide();detailsEl.show();tm.doIt.trackEvent(tm.doIt.eyeBlasterActivity.doItViewDetails);tm.doIt.setWrapEl('honda-search','honda_search');}
tm.doIt.setWrapEl=function(classN,idN){var wrapEl=$('.span-64.last')[0];wrapEl.className='span-64 last '+classN;wrapEl.id=idN;document.location.hash=idN;}
tm.doIt.showResults=function(){$('#detailsContainer').hide();$('#searchResultsContainer').show();tm.doIt.setWrapEl('honda-search','honda_search');if(tm.doIt.haveResults){tm.doIt.trackEvent(tm.doIt.eyeBlasterActivity.doItResults);}}
tm.doIt.showTab=function(activeTab){if(activeTab=='local'){$('img#localTab').attr('src','http://images.icnetwork.co.uk/collections/microsite_honda'
+'/local_tab_back.jpg');$('img#countyTab').attr('src','http://images.icnetwork.co.uk/collections/microsite_honda/'
+'county_tab_back_off.jpg');$('#countyOpportunitiesTab').hide();$('#localOpportunitiesTab').show();}else{$('img#localTab').attr('src','http://images.icnetwork.co.uk/collections/microsite_honda/'
+'local_tab_back_off.jpg');$('img#countyTab').attr('src','http://images.icnetwork.co.uk/collections/microsite_honda/'
+'county_tab_back.jpg');$('#localOpportunitiesTab').hide();$('#countyOpportunitiesTab').show();}}
tm.doIt.showRegistrationForm=function(opportunityId){var resultEl=$('#searchResultsContainer');var detailsEl=$('#detailsContainer');var resHTML="";resHTML+='<div class="span-47 last">';resHTML+='<h1>Thanks for your interest in Honda do-it.org.uk</h1>';resHTML+="<p>Now you've found a do-it.org.uk opportunity you're interested in, it would be great if you could keep in touch to let us know how it's going. We'd also love to read your do-it.org.uk stories and see any pictures or videos you'd like to share.</p>";resHTML+='<p>Please complete the details below to join '+'do-it.org.uk.</p>';resHTML+='<div class="RegistrationError" style="display: none;" id="errstr_doit_name">'
+'Please enter your name</div>';resHTML+='<input type="hidden" id="doit_oppid" value="'+opportunityId+'"/></p><br/>';resHTML+='<p class="bottom">Name: <input id="doit_name" /></p><br/>';resHTML+='<div class="RegistrationError" style="display: none;" id="errstr_doit_email">';resHTML+='Please enter a valid email address</div>';resHTML+='<p class="bottom">Email: <input id="doit_email"/></p>';resHTML+='<div class="honda-button honda-proceed honda-thanks-font">';resHTML+='<a onclick="javascript:tm.doIt.registerUser('+opportunityId+');">Proceed to do-it.org.uk sign up</a>';resHTML+='</div>';resHTML+='<div class="clear"/>';resHTML+='<p><a id="doItApplyURL" target="_blank" href="http://www.do-it.org.uk/checklogon.do?partner='
+tm.doIt.partnerCode
+'&OppID='+opportunityId
+'&actionType=apply" onclick="tm.doIt.trackEvent( tm.doIt.eyeBlasterActivity.dataCaptureButton);">Proceed without opting to share your stories</a></p>';resHTML+='<p><a id="doItOppURL" href="javascript:tm.doIt.loadOpportunityDetail('+opportunityId+');">Go back to the opportunity</a></p>';resHTML+='</div>';detailsEl.html(resHTML);resultEl.hide();detailsEl.show();tm.doIt.setWrapEl('honda-thanks','honda_thanks');}
tm.doIt.loadPartnerCode=function(detailsXML,stat){tm.doIt.partnerCode=detailsXML;tm.doIt.showRegistrationForm(tm.doIt.registrationFormOpportunityId);}
tm.doIt.loadForm=function(opportunityId){if(typeof tm.doIt.partnerCode=='undefined'){tm.doIt.registrationFormOpportunityId=opportunityId;$.ajax({url:tm.doIt.getDoItRegistrationFormURL()+opportunityId,type:'GET',format:'text',success:tm.doIt.loadPartnerCode,error:function(){tm.doIt.showError('email')}});}
else{tm.doIt.showRegistrationForm(opportunityId);}}
tm.doIt.registerUser=function(opportunityId){var nameEl=$('#doit_name')[0];var emailEl=$('#doit_email')[0];var oppIdEl=$('#doit_oppid')[0];var nameErrorEl=$('#errstr_doit_name')[0];var emailErrorEl=$('#errstr_doit_email')[0];var haveErrors=!nameEl.value.length||!emailEl.value.length;nameErrorEl.style.display=!nameEl.value.length?'':'none';emailErrorEl.style.display=!emailEl.value.length?'':'none';if(!haveErrors&&!validate_addr(emailEl.value)){haveErrors=true;emailErrorEl.style.display='';}
if(!haveErrors){var oppURL=document.location.href.toLowerCase().match(/oppid/)?document.location.href:document.location.href+'&oppid='+oppIdEl.value;$.ajax({async:false,url:tm.doIt.getDoItRegistrationSubmissionURL()+'&siteName='+tm.doIt.siteName,data:{widget_object_id:tm.doIt.widgetObjectId,name:nameEl.value,email:emailEl.value,oppId:opportunityId,oppURL:oppURL},type:'POST',success:tm.doIt.redirectToDoIt(),format:'text',error:function(){tm.doIt.showError('email');}});}}
tm.doIt.redirectToDoIt=function(){tm.doIt.trackEvent(tm.doIt.eyeBlasterActivity.dataCaptureButton);var applyURL=$('#doItApplyURL')[0];$("#detailsContainer").append('<div class="span-47 last thanks"><!-- AG\'s Text --></div>');window.open(applyURL.href);}
tm.doIt.trackEvent=function(activityID){if(!$('#do_it_tracking_el').length){$('body').append('<div id="do_it_tracking_el" style="display:none"></div>');}
$('#do_it_tracking_el').html('<img width="1" height="1" style="border:0" src="http://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&amp;ActivityID='+activityID+'&amp;ns=1" />');tm.logger.info('Info: Tracking event with eyeblaster; activityID:"'+activityID+'"');}
