
function init(){observeAllEvents();checkAndShowEditSolutionReportLink();gSolutionReport.init();gS2SolutionStartSession=new S2StartSession({origin:Object.clone(gOrigin)});gS2SolutionStartSession.setOriginType("sessionReport");}
function observeAllEvents(){if(gConnectButtonEnabled){$$(".startSessionButton").each(function(connectBtn){connectBtn.src=gStartSessionUrls.connect_regular;connectBtn.className="startSessionButton linkImg"
disableObject(connectBtn,false);Event.observe(connectBtn,'mouseout',function(){this.src=gStartSessionUrls.connect_regular});Event.observe(connectBtn,'mouseup',function(){this.src=gStartSessionUrls.connect_regular});Event.observe(connectBtn,'mouseover',function(){this.src=gStartSessionUrls.connect_over});Event.observe(connectBtn,'mousedown',function(){this.src=gStartSessionUrls.connect_pressed});});}
observeAddThisEvents();}
function observeAddThisEvents(){Event.observe($('addThisButton'),'mouseover',function(){return addthis_open($('addThisButton'),'','[URL]','[TITLE]');});Event.observe($('addThisButton'),'mouseout',function(){addthis_close();});Event.observe($('addThisButton'),'click',function(){return addthis_sendto();});}
function checkAndShowEditSolutionReportLink(){if(gIsUserEditor&&g_experts[0].id==gCurrentUser.id){$("editSolutionReport").show();}}
function onSolutionReportSubmitSuccess(){window.location.reload();}
var SolutionReport=Class.create({initialize:function(formUrl,solutionReportId){this.formUrl=formUrl;this.solutionReportId=solutionReportId;this.autoSuggestReport=null;},init:function(){this.sessionReportForm=$("sessionReportForm");this.sessionReportError=$("sessionReportError");this.sessionReportResolution=$("sessionReportResolution");this.whatHappenedUserFreeText=$("whatHappenedUserFreeText");this.reportExpertise=$("reportExpertise");this.expertiseDetails=$("expertiseDetails");this.reportTitle=$("reportTitle");this.expertiseId=$("expertiseId");this.scopeOfWork=$("scopeOfWork");this.problemDetails=$("problemDetails");this.solutionDetails=$("solutionDetails");this.sessionReportNewLink=$("dSessionReportNewLink");this.sessionReportLinks=$("dSessionReportLinks");this.initForm();},initForm:function(){this.autoSuggestReport=new S2AutoSuggest('EXPERTISE',this.reportExpertise,this.buildExpertisesAutosuggest.bind(this),this.setExpertise.bind(this),200,this.sessionReportError);if(this.expertiseId&&this.expertiseId.value)
{this.autoSuggestReport.setSelectedValue(this.expertiseId.value);}},edit:function(displayForm){$('dOverlaySessionReport').update('<img class="preloader" src="'+gCommonUrls.preloader+'" alt="" />');lightBoxOn({rel:"dOverlaySessionReport"});var params={};if(this.sessionId){params["supportSessionId"]=this.sessionId;}
if(this.solutionReportId){params["solutionReportId"]=this.solutionReportId;}
new Ajax.Request(this.formUrl,{parameters:params,method:'get',onSuccess:function(transport){$('dOverlaySessionReport').update(transport.responseText);$('dOverlaySessionReport').show();$('dOverlaySessionReport').style.backgroundColor='transparent';if(displayForm){(function(){this.init()}.bind(this)).defer();}}.bind(this)});},buildExpertisesAutosuggest:function(jsonResultsStr){var resultsArry=eval(jsonResultsStr);var resultsStr=[];var resultsKeys=[];resultsArry.each(function(obj){var display=obj.expertiseName;var id=obj.expertiseId;if(display&&id)
{resultsStr.push(display);resultsKeys.push(id)}});this.autoSuggestReport.setResults(resultsStr)
this.autoSuggestReport.setResultsIds(resultsKeys)
this.autoSuggestReport.displayResults();},retrieveIdOfSelectedExpertise:function(){var selectedValues=this.autoSuggestReport.getSelectedValues();if(!selectedValues['sessionReport.expertise']&&!selectedValues['reportExpertise']){this.autoSuggestReport.setSelectedValue(this.expertiseId.value);}
return selectedValues['sessionReport.expertise']||selectedValues['reportExpertise'];},setExpertise:function(){if(!this.autoSuggestReport)
return
var selectedValues=this.autoSuggestReport.getSelectedValues();if(!selectedValues['sessionReport.expertise']&&!selectedValues['reportExpertise']){this.reportExpertise.value=''}},addLink:function(){var links_length=this.sessionReportLinks.immediateDescendants().length;if(links_length>10)return;var new_link=this.sessionReportNewLink.value;if(!this.validateLink(new_link)){return;}
if(isEltPresent(this.sessionReportLinks,"links[INT].link",new_link))
return;var html='<div class="dSessionReportLinkRow">'+'<div class="linkText ellipsis" style="float:left;">'+new_link+'</div>'+'<img onclick="removeFromList(this)" class="linkImg" src="'+gCommonUrls.remove_btn+'"/>'+'<input type="hidden" namebase="links[INT].link" name="links['+links_length+'].link" value="'+new_link+'"/>'+'</div>';new Insertion.Bottom(this.sessionReportLinks,html)
this.sessionReportNewLink.value=''},validateLink:function(link){this.sessionReportError.innerHTML='';this.sessionReportError.show();if(!link||link==null||link=='')
{this.sessionReportError.innerHTML="links should have value";return false;}
if(!link.match(g_regExpNoHtmlTags))
{this.sessionReportError.innerHTML=gCommonErrors["errors.htmlEscape"].replace('{0}',gSDStrings.session_report_links);return false;}
if(link.length>300){return false;}
return true;},validate:function(){this.sessionReportError.innerHTML='';this.sessionReportError.show();if(!this.autoSuggestReport){this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_3;return false;}
var selectedExpertiseId=this.expertiseId.value;if(isNaN(selectedExpertiseId)||selectedExpertiseId<1)
{if(this.sessionReportError.childNodes.length==0)
this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_3;return false;}
if(this.expertiseDetails&&this.expertiseDetails.value.length>255)
{this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_5;return false;}
if(this.expertiseDetails&&!this.expertiseDetails.value.match(g_regExpNoHtmlTags))
{this.sessionReportError.innerHTML=gCommonErrors["errors.htmlEscape"].replace('{0}',gSolutionReportStrings.session_report_expertise_details);return false;}
var textTitle=this.reportTitle;if(textTitle&&(textTitle.value.length==0||textTitle.value.length>255))
{this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_7;return false;}
if(textTitle&&(!textTitle.value.match(g_regExpNoHtmlTags)||textTitle.value.indexOf('/')>=0))
{this.sessionReportError.innerHTML=gCommonErrors["errors.htmlEscape"].replace('{0}',gSolutionReportStrings.session_report_title);return false;}
var problemDetails=this.problemDetails;if(problemDetails&&problemDetails.value.length==0)
{this.sessionReportError.innerHTML=gCommonErrors["errors.required"].replace('{0}',gSolutionReportStrings.session_report_problem_details);return false;}
if(problemDetails&&problemDetails.value.length>4000)
{this.sessionReportError.innerHTML=gCommonErrors["errors.maxlength"].replace('{0}',gSolutionReportStrings.session_report_problem_details).replace('{1}','4000');return false;}
if(problemDetails&&!problemDetails.value.match(g_regExpNoHtmlTags))
{this.sessionReportError.innerHTML=gCommonErrors["errors.htmlEscape"].replace('{0}',gSolutionReportStrings.session_report_problem_details);return false;}
var solutionDetails=this.solutionDetails;if(solutionDetails&&solutionDetails.value.length==0)
{this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_5;return false;}
if(solutionDetails&&solutionDetails.value.length>4000)
{this.sessionReportError.innerHTML=gCommonErrors["errors.maxlength"].replace('{0}',gSolutionReportStrings.session_report_solution_details).replace('{1}','4000');return false;}
if(solutionDetails&&!solutionDetails.value.match(g_regExpNoHtmlTags))
{this.sessionReportError.innerHTML=gCommonErrors["errors.htmlEscape"].replace('{0}',gSolutionReportStrings.session_report_solution_details);return false;}
this.sessionReportError.hide();return true;},submit:function(){gErrorDivs={ui:this.sessionReportError,msg:this.sessionReportError};this.expertiseId.value=this.retrieveIdOfSelectedExpertise();if(this.validate()){disableObject('bServiceReportSendButton',true);var links_length=this.sessionReportLinks.immediateDescendants().length;this.sessionReportForm.request({parameters:{sessionReportLinksLength:links_length,jabberUsername:g_experts[0].jabberUsername},onSuccess:function(response){if(response.responseText.length>0){this.sessionReportError.innerHTML=response.responseText;}
else{onSolutionReportSubmitSuccess();lightBoxOff();}},onFailure:function(response){this.sessionReportError.innerHTML=response.text;}})}}});var SessionReport=Class.create(SolutionReport,{initialize:function($super,formUrl,sessionId){$super(formUrl);this.lastResolutionSelected="";this.sessionId=sessionId;},onSelectedResolutionChanged:function(reportResolutionSelectBox){var selectedResolution=reportResolutionSelectBox[reportResolutionSelectBox.selectedIndex].value;var matchingResolutionTypeSelectBox=$('selectResolutionType_'+selectedResolution);matchingResolutionTypeSelectBox.style.display="block";matchingResolutionTypeSelectBox.disabled=false;var lastResolutionTypeSelectBox=$('selectResolutionType_'+this.lastResolutionSelected);lastResolutionTypeSelectBox.style.display="none";lastResolutionTypeSelectBox.disabled=true;this.lastResolutionSelected=selectedResolution;this.lastResolutionTypeSelectBox=$('selectResolutionType_'+this.lastResolutionSelected);},onSelectedResolutionTypeChanged:function(resolutionTypeSelectBox){if(this.whatHappened){var selectedResolutionType=resolutionTypeSelectBox[resolutionTypeSelectBox.selectedIndex].value;if(this.isResolutionTypeRequiresAdditionalFreeText(selectedResolutionType))
{this.whatHappened.show();this.whatHappenedUserFreeText.disabled=false;}
else
{this.whatHappened.hide();this.whatHappenedUserFreeText.disabled=true;}}},isResolutionTypeRequiresAdditionalFreeText:function(selectedResolutionType){return selectedResolutionType?selectedResolutionType.toLowerCase().endsWith('requiresfreetext'):false;},retrieveSelectedResolutionType:function(){if(this.lastResolutionTypeSelectBox){var selectedIndex=this.lastResolutionTypeSelectBox.selectedIndex;return this.lastResolutionTypeSelectBox[selectedIndex].value;}
return null;},validate:function($super){this.sessionReportError.innerHTML='';this.sessionReportError.show();if(!$('sessionReportResolutionText')&&this.sessionReportResolution.value=='')
{if(this.sessionReportError.childNodes.length==0)
this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_4;return false;}
if(!$('selectResolutionTypeText')&&this.retrieveSelectedResolutionType()=='')
{if(this.sessionReportError.childNodes.length==0)
this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_resolution;return false;}
if(!$('selectResolutionTypeText')&&this.isResolutionTypeRequiresAdditionalFreeText(this.retrieveSelectedResolutionType()))
{if(this.whatHappenedUserFreeText&&this.whatHappenedUserFreeText.value=='')
{if(this.sessionReportError.childNodes.length==0)
this.sessionReportError.innerHTML=gSolutionReportStrings.session_report_validate_resolution_details;return false;}}
if(!$super()){return false;}
this.sessionReportError.show();if(this.scopeOfWork&&this.scopeOfWork.value.length>4000){this.sessionReportError.update(gCommonErrors["errors.maxlength"].replace('{0}',gSolutionReportStrings.session_report_validate_2).replace('{1}','4000'));}
if(this.scopeOfWork&&!this.scopeOfWork.value.match(g_regExpNoHtmlTags))
{this.sessionReportError.update(gCommonErrors["errors.htmlEscape"].replace('{0}',gSolutionReportStrings.session_report_scope));return false;}
this.sessionReportError.hide();return true;}});