// Copyright (c) 2006-2008 RockAuto, LLC

var waitPanel;Results=function(id){if(id){this.id=id;}
this.waitPanel=new YAHOO.widget.Panel("wait",{width:"240px",fixedcenter:true,underlay:"shadow",close:false,visible:false,draggable:false,modal:true});this.waitPanel.setBody("<img src=\"../jslib/rel_interstitial_loading.gif\"/>");};Results.prototype={id:null,waitPanel:null,success:null,heading:null,vehicle1:null,vehicle2:null,carCode1:null,carCode2:null,adCode:null,ratio:null,graphUrl:null,shortGraphUrl:null,fromEmail:null,fromName:null,message:null,recipients:[],emailSent:false,getHTML:function(){var html=[];var continueLink='<span class="mouseover btn" onclick="ReturnToVehicles()" title="'+SELECTVEHICLES+'"><span><img src="images/leftArrow.png" /> '+SELECTVEHICLES+'</span></span>';html[html.length]='<div class="center">';html[html.length]='<table class="layout">';html[html.length]='<tr><td>';if(this.success!=null){html[html.length]='<table>';html[html.length]='<tr style="text-align: center"><td style="font-size: 14px;" colspan="2" style="text-align: center">'+this.heading+'</td></tr>';html[html.length]='<tr><td colspan="2" /></tr>';if((this.graphUrl!=null)&&(this.graphUrl.length>0)){html[html.length]='<tr><td colspan="2" style="text-align: center"><img src="'+this.graphUrl+'" /></td></tr>';html[html.length]='<tr><td style="text-align: center;"><a style="text-decoration: none" href="http://www.rockauto.com/catalog/raframecatalog.php?a='+this.adCode+'&carcode='+this.carCode2+'" target="_blank"><img style="border: none" src="/Images/'+LANGUAGE+'/FindPartsCar.gif" title="'+VIEWPARTSFORABOVECAR+'" alt="'+VIEWPARTSFORABOVECAR+'" /></a></td>';html[html.length]='<td style="text-align: center;"><a style="text-decoration: none" href="http://www.rockauto.com/catalog/raframecatalog.php?a='+this.adCode+'&carcode='+this.carCode1+'" target="_blank"><img style="border: none" src="/Images/'+LANGUAGE+'/FindPartsCar.gif" title="'+VIEWPARTSFORABOVECAR+'" alt="'+VIEWPARTSFORABOVECAR+'" /></a></td></tr>';}
html[html.length]='<tr><td colspan="2"><table id="emailtable">';if(!this.emailSent){html[html.length]='<tr><td colspan="4" class="bold">'+SHARETHISCOMPARISON+':</td></tr>';html[html.length]='<tr><td style="text-align: right">'+YOUREMAIL+':</td><td><input type="text" name="fromemail" onblur="CheckInputs()" '+((this.fromEmail!=null)?'value="'+this.fromEmail+'" ':'')+'/></td>';html[html.length]='<td style="text-align: right">'+YOURNAME+'</td><td><input type="text" name="fromname" onblur="CheckInputs()" '+((this.fromName!=null)?'value="'+this.fromName+'" ':'')+'/></td></tr>';html[html.length]='<tr><td style="text-align: right; vertical-align: top">'+MESSAGE+':</td><td colspan="3"><textarea rows="4" style="width: 100%" name="message" onblur="CheckInputs()">'+((this.message!=null)?this.message:'')+'</textarea></td></tr>';html[html.length]='<tr><td colspan="4">'+ENTERFRIENDADDRESSES+'</td></tr>';html[html.length]='<tr><td style="text-align: right">'+ADDRESS+' 1:</td><td><input type="text" name="recipient[0]" onblur="CheckInputs()" '+((this.recipients[0]!=null)?'value="'+this.recipients[0]+'" ':'')+'/></td>';html[html.length]='<td style="text-align: right">'+ADDRESS+' 2:</td><td><input type="text" name="recipient[1]" onblur="CheckInputs()" '+((this.recipients[1]!=null)?'value="'+this.recipients[1]+'" ':'')+'/></td></tr>';html[html.length]='<tr><td style="text-align: right">'+ADDRESS+' 3:</td><td><input type="text" name="recipient[2]" onblur="CheckInputs()" '+((this.recipients[2]!=null)?'value="'+this.recipients[2]+'" ':'')+'/></td>';html[html.length]='<td style="text-align: right">'+ADDRESS+' 4:</td><td><input type="text" name="recipient[3]" onblur="CheckInputs()" '+((this.recipients[3]!=null)?'value="'+this.recipients[3]+'" ':'')+'/></td></tr>';html[html.length]='<tr><td style="text-align: right">'+ADDRESS+' 5:</td><td><input type="text" name="recipient[4]" onblur="CheckInputs()" '+((this.recipients[4]!=null)?'value="'+this.recipients[4]+'" ':'')+'/></td>';html[html.length]='<td style="text-align: right">'+ADDRESS+' 6:</td><td><input type="text" name="recipient[5]" onblur="CheckInputs()" '+((this.recipients[5]!=null)?'value="'+this.recipients[5]+'" ':'')+'/></td></tr>';html[html.length]='<tr><td colspan="4">'+PLEASEENTERSECURITYCODE+':</td></tr>';html[html.length]='<tr><td colspan="2"><img id="captcha" src="/captcha/securimage/securimage_show.php?'+Math.random()+'" alt="CAPTCHA Image" /><a class="minilink" href="javascript:NewCAPTCHA()">'+NEWIMAGE+'</a></td>';html[html.length]='<td style="vertical-align: bottom"><input type="text" size="8" id="captchacode" name="captchacode" onblur="CheckInputs()" /></td>';html[html.length]='<td style="vertical-align: bottom"><span class="mouseover btn" onclick="SendEmail()" title="'+SENDEMAIL+'"><span>'+SENDEMAIL+'</span></span></td></tr>';html[html.length]='<tr><td colspan="4" style="text-align: center">'+EMAILNOTADDEDTOLIST+'</td></tr>';}else{html[html.length]='<tr><td>'+EMAILSENT+'</td></tr>';}
html[html.length]='</table></td></tr>';html[html.length]='</table>';}else{html[html.length]='<table>';html[html.length]='<tr><td /></tr>';html[html.length]='<tr><td /></tr>';html[html.length]='<tr><td /></tr>';html[html.length]='<tr class="center"><td class="center">'+NOCARSSELECTED+'</td></tr>';html[html.length]='</table>';}
html[html.length]='</td></tr>';html[html.length]='<tr><td /></tr>';html[html.length]='<tr><td /></tr>';html[html.length]='<tr><td /></tr>';html[html.length]='<tr class="center"><td class="center">'+continueLink+'</td></tr>';html[html.length]='</table>';html[html.length]='</div>';return html.join("");},generateResults:function(carCode1,carCode2){this.carCode1=carCode1;this.carCode2=carCode2;this.adCode='ri'+carCode1+'_'+carCode2;var postParams='func=results&carcode1='+carCode1+'&carcode2='+carCode2+'&adcode='+encode(this.adCode);this.sendRequest(postParams);},setFromEmail:function(fromEmail){this.fromEmail=(fromEmail.length>0)?fromEmail:null;},setFromName:function(fromName){this.fromName=(fromName.length>0)?fromName:null;},setMessage:function(message){this.message=(message.length>0)?message:null;},setRecipients:function(recipients){this.recipients=recipients;},clearForm:function(){this.fromEmail=null;this.fromName=null;this.message=null;this.recipients=[];this.emailSent=false;},showErrorDialog:function(msg){var msgDialog=new YAHOO.widget.SimpleDialog("msg",{width:"300px",fixedcenter:true,visible:true,draggable:true,close:false,text:msg,icon:YAHOO.widget.SimpleDialog.ICON_INFO,constraintoviewport:true,buttons:[{text:"Ok",handler:function(){msgDialog.hide();},isDefault:true}]});msgDialog.setHeader(REPAIRINDEXINFO);msgDialog.render(document.body);msgDialog.show();},draw:function(){document.getElementById(this.id).innerHTML=this.getHTML();},showLoadingPanel:function(msgTxt){var txt=msgTxt?msgTxt:CALCULATINGOMPARISON+"...";this.waitPanel.setHeader(txt);this.waitPanel.render(document.body);this.waitPanel.show();},hideLoadingPanel:function(){if(this.waitPanel){this.waitPanel.hide();}},loadResultsCallback:{timeout:30000,success:function(o){var resultsElem=o.responseXML.getElementsByTagName('results')[0];if(resultsElem!=null){results.success=(resultsElem.getAttribute('success')=='true');results.heading=resultsElem.getAttribute('text');results.vehicle1=resultsElem.getAttribute('vehicle1');results.vehicle2=resultsElem.getAttribute('vehicle2');if(results.success){results.ratio=resultsElem.getAttribute('ratio');}
results.graphUrl=resultsElem.getAttribute('graphurl');results.shortGraphUrl=resultsElem.getAttribute('shortgraphurl');results.clearForm();}
var emailResultElem=o.responseXML.getElementsByTagName('emailresult')[0];if(emailResultElem!=null){var captchaResultElem=emailResultElem.getElementsByTagName('captcha')[0];if(captchaResultElem!=null){var captchaResult=captchaResultElem.getAttribute('match');if(captchaResult=='false'){}}
var emailResultsElem=emailResultElem.getElementsByTagName('email')[0];if(emailResultsElem!=null){var emailSent=emailResultsElem.getAttribute('sent');if(emailSent=='true'){results.emailSent=true;}}}
var errorElement=o.responseXML.getElementsByTagName('error')[0];if(errorElement){results.showErrorDialog(errorElement.getAttribute('message'));results.hideLoadingPanel();}
results.draw();results.hideLoadingPanel();},failure:function(o){results.hideLoadingPanel();alert(o.statusText);}},sendRequest:function(postParams,showPanel){if((showPanel==null)||showPanel){this.showLoadingPanel();}
var cObj=YAHOO.util.Connect.asyncRequest('POST','rixml.php',this.loadResultsCallback,postParams);}};var results=null;var loadingElem=null;var loadingElemContent=null;function loadResults(){results=new Results("resultscontent");parent.results=results;results.draw();};function ReturnToVehicles(){if(parent.tabs){parent.tabs.set("activeIndex",parent.tabIndex['vehicles']);}};function CheckInputs(){var emailElem=document.getElementById('emailtable');var recipients=[];var inputs=emailElem.getElementsByTagName('input');for(var i=0;i<inputs.length;i++){var txtValue=inputs[i].value.replace(/^\s+/,"").replace(/\s+$/,"");if(inputs[i].name=='fromemail'){results.setFromEmail(txtValue);}else if(inputs[i].name=='fromname'){results.setFromName(txtValue);}
if((txtValue.length>0)&&inputs[i].name.match(/^recipient/)){recipients[recipients.length]=txtValue;}}
if(recipients.length>0){results.setRecipients(recipients);}
var textArea=emailElem.getElementsByTagName('textarea')[0];if(textArea!=null){var txtValue=textArea.value.replace(/^\s+/,"").replace(/\s+$/,"");if(txtValue.length>0){results.setMessage(txtValue);}}}
function SendEmail(){var emailElem=document.getElementById('emailtable');var postParams='';var captchaCode=null;var captchaCodeElem=document.getElementById('captchacode');var txtValue=captchaCodeElem.value.replace(/^\s+/,"").replace(/\s+$/,"");if(txtValue.length>0){captchaCode=txtValue;postParams+='&captchacode='+encode(captchaCode);}
if(results.success!=null){var isValid=results.success?'true':'false';postParams+='&isvalid='+encode(isValid);}
if(results.fromEmail!=null){postParams+='&fromemail='+encode(results.fromEmail);}
if(results.fromName!=null){postParams+='&fromname='+encode(results.fromName);}
if(results.message!=null){postParams+='&message='+encode(results.message);}
if(results.vehicle1!=null){postParams+='&vehicle1='+encode(results.vehicle1);}
if(results.vehicle2!=null){postParams+='&vehicle2='+encode(results.vehicle2);}
if(results.ratio!=null){postParams+='&ratio='+encode(results.ratio);}
if(results.graphUrl!=null){postParams+='&graphurl='+encode(results.graphUrl);}
if(results.shortGraphUrl!=null){postParams+='&shortgraphurl='+encode(results.shortGraphUrl);}
if(results.adCode!=null){postParams+='&adcode='+encode(results.adCode);}
var send=true;if((captchaCode!=null)&&(results.fromEmail!=null)&&(results.fromName!=null)&&(results.recipients.length>0)){for(var i=0;i<results.recipients.length;i++){postParams+='&recipient['+i+']='+encode(results.recipients[i]);}
var cObj=YAHOO.util.Connect.asyncRequest('POST','rixml.php',results.loadResultsCallback,'func=sendemail'+postParams);}else{results.showErrorDialog(UNABLETOSEND+'<br /><br />'+GENERALEMAILERROR);}}
function NewCAPTCHA(){var captchaImgElem=document.getElementById('captcha');if(captchaImgElem!=null){captchaImgElem.src='/captcha/securimage/securimage_show.php?'+Math.random();}}
function printResults(){if(!printWindow||printWindow.closed){printWindow=window.open("blank.html","print","menubar=yes,scrollbars=yes,resizable=yes");setTimeout("writeResultsToWindow()",1000);}else if(printWindow.focus){printWindow.focus();writeResultsToWindow();}};function writeResultsToWindow(){var resultsHtml=document.getElementById('results').parentNode.innerHTML;var winDoc=printWindow.document;var winContent=winDoc.getElementById('content');winContent.innerHTML=resultsHtml;var winHeading=winDoc.getElementById('heading');if(winHeading){winHeading.innerHTML=RESULTSCONTENTS;}
printWindow.print();};