/*
 Copyright (c) 2008  Wise Owl Technology Ltd.
 All Rights Reserved.
*/
var windowNameSuffix="";var blockedSites=new Array();var popupsBlocked=false;var popupAlert;var numSitesBlocked=0;function getSiteIndex(name)
{for(var i=0;i<blockedSites.length;i++)
{if(blockedSites[i][0]===name)
{return i;}}
return-1;}
function isBroswerIE6()
{if(window.XMLHttpRequest)
{return false;}
else
{return true;}}
function showRequestFlight(formData,jqForm,options)
{return showRequest(formData,jqForm,options,"flight");}
function showRequestHotel(formData,jqForm,options)
{return showRequest(formData,jqForm,options,"hotel");}
function showRequestVacation(formData,jqForm,options)
{return showRequest(formData,jqForm,options,"vacation");}
function showRequest(formData,jqForm,options,searchType)
{var queryString=$.param(formData);popupsBlocked=false;if(isBroswerIE6())
{windowNameSuffix=Math.round(Math.random()*100000);}
$('input[@class=sites]:checked').each(function(i){var rc;var launchUrl=getPreclickUrl(this.id,this.value,searchType);rc=openWindow(launchUrl,this.id,true);gaTracker.trackSearch(searchType,this.id);if(!rc)
{popupsBlocked=true;}
var index=getSiteIndex(this.id,blockedSites);if(index===-1)
{index=blockedSites.length;blockedSites[index]=new Array(4);}
blockedSites[index][0]=this.id;blockedSites[index][1]=rc;blockedSites[index][2]=launchUrl;blockedSites[index][3]="";});return true;}
function getPreclickUrlFlight(launchUrl,siteId)
{if(siteId=="LANcom")
{launchUrl="http://click.linksynergy.com/fs-bin/click?id=ZwSs4M4aWcM&offerid=145196.10000075&subid=0&type=4";}
else if(siteId=="Traxcom")
{launchUrl="http://www.tkqlhce.com/click-3238565-10635259";}
else if(siteId=="virgin-atlanticcom")
{launchUrl="http://www.tkqlhce.com/click-3238565-10584465";}
else if(siteId=="cheapOaircom")
{launchUrl="http://www.kqzyfj.com/click-3238565-10594969";}
else if(siteId=="yatracom")
{launchUrl="http://www.kqzyfj.com/click-3238565-10535920";}
return launchUrl;}
function getPreclickUrlHotel(launchUrl,siteId)
{if(siteId=="HotelsCombinedcom")
{launchUrl="http://click.linksynergy.com/fs-bin/click?id=ZwSs4M4aWcM&offerid=163355.10000006&type=4&subid=0";}
else if(siteId=="BestWesterncom")
{launchUrl="http://www.dpbolvw.net/click-3238565-10415148";}
return launchUrl;}
function getPreclickUrlVacation(launchUrl,siteId)
{if(siteId=="Hotwirecom")
{launchUrl="http://click.linksynergy.com/fs-bin/click?id=ZwSs4M4aWcM&offerid=120349.10000101&subid=0&type=4";}
else if(siteId=="Travelocityca")
{launchUrl="http://www.kqzyfj.com/interactive?desturl=http%3A%2F%2Ftravel.travelocity.ca%2Fflights%2FInitialSearch.do%3FService%3DCJCA&url=http%3A%2F%2Ftravel.travelocity.ca%3FService%3DCJCA%26desturl%3Dhttp%3A%2F%2Ftravel.travelocity.ca%3FService%3DCJCA&aid=10539292&pid=3270177";}
return launchUrl;}
function getPreclickUrl(siteId,siteVal,searchType)
{var launchUrl="/launchPartnerSite.php?partner="+siteVal;if(isBroswerIE6())
{return launchUrl;}
if(searchType=="flight")
{return getPreclickUrlFlight(launchUrl,siteId);}
else if(searchType=="hotel")
{return getPreclickUrlHotel(launchUrl,siteId);}
else if(searchType=="vacation")
{return getPreclickUrlVacation(launchUrl,siteId);}}
function showResponse(responseText,statusText){if(responseText.length!=0)
{var validityArray=new Array();validityArray=responseText.split("^");if(validityArray.length!=2)
{alert("Invalid response returned by server: "
+validityArray.length+" "+responseText);return;}
if($.trim(validityArray[0])!="invalidLoc")
{if(typeof handleRecSearch=='function')
{handleRecSearch(validityArray[0]);}}
else
{self.focus();}
var urlArray=new Array();urlArray=validityArray[1].split(",");for(var i=0;i<urlArray.length;i++)
{if(urlArray[i].length!=0)
{var urlName=new Array();urlName=urlArray[i].split(" ");if(urlName.length!=2)
{alert("Invalid url/name pair returned by server: "
+urlName.length+" "+responseText);continue;}
var index=getSiteIndex(urlName[1],blockedSites);if(index===-1)
{alert("index is not set: "+urlName[1]);}
blockedSites[index][3]=$.trim(urlName[0]);if(blockedSites[index][1])
{setTimeout('openWindow(\''+$.trim(urlName[0])+'\','+'\''+$.trim(urlName[1])+'\''+');',2000);}}}
if(popupsBlocked)
{handleBlockedPopups();}}}
function openWindow(url,name,phase0)
{if(!phase0)
{phase0=false;}
var strippedName=name.replace(/\./,"");strippedName=strippedName+windowNameSuffix;var newWindow=isBroswerIE6()?window.open(url,strippedName,"location=1,directories=1,scrollbars=1,resizable=1,menubar=1,toolbar=1,status=1,width=800,height=600"):window.open(url,strippedName);if(newWindow)
{if((window.focus)&&phase0)
{newWindow.focus();}
return true;}
return false;}
function doSearch()
{var $cm=$(this).parent().parent().find("img[@class=checkmark]");if($cm.css('display')=='none')
{$cm.show();numSitesBlocked--;}
else if(isBroswerIE6())
{return false;}
var id=new Array();id=$cm.attr('id').split("_");if(id.length!=2)
{alert("Invalid id: "+$cm.attr('id'));return;}
var index=getSiteIndex(id[1],blockedSites);if(index===-1)
{alert("this should not happen: "+urlName[1]);return false;}
openWindow(blockedSites[index][2],blockedSites[index][0],true);setTimeout('openWindow(\''+blockedSites[index][3]+'\','+'\''+blockedSites[index][0]+'\''+');',2000);if(numSitesBlocked==0)
{popupAlert.find('.jqiclose').click();}
return false;}
function handleBlockedPopups()
{numSitesBlocked=0;var text="<div id='popupAlert'>";text+="<h3>A pop-up blocker prevented search windows from opening.</h3>";text+="<p>1. Disable pop-up blockers and retry the search, or</p>";text+="<p>2. Click on the \"Search\" buttons below to search your travel sites:</p>";var col_num=0;text+="<table>";$('input[@class=sites]:checked').each(function(i){var index=getSiteIndex(this.id,blockedSites);if(index===-1)
{alert("index not set: "+this.id);}
else
{var display="";if(!blockedSites[index][1])
{numSitesBlocked++;display="display:none;";}
var $img=$(this).parent().find("img");if(col_num==0)
{text+="<tr>";}
text+="<td><table><tr>";text+="<td width='106'>";text+="<span><img src='"+$img.attr("src")+"' /></span>";text+="</td>";text+="<td width='92'>";text+="<a href='' class='pb_search' title='"+$img.attr("title")+"'><img src='/small_button.png' alt='"+$img.attr("alt")+"' /></a>";text+="</td>";text+="<td width='30'>"
text+="<img class='checkmark' src='/checkmark.jpg' style='margin-left: 5px;"+display+"' id='cm_"+this.id+"' />";text+="</td>";text+="</tr></table></td>";col_num+=1;if(col_num==2)
{col_num=0;text+="</tr>";}}});if(col_num==1)
{text+="</tr>";}
text+="</table>";text+="</div>";popupAlert=$.prompt(text,{buttons:{}}).children('#jqi').corner();$(".pb_search").click(doSearch);return false;}
