var json='';$(document).ready(function(){$("#selectCities").ajaxStart(function(){startLoading('#selectCities');});});function sendValues(channel,searchtype,hotelID){var checkin_date=$('#CheckInDate').val(),checkout_date=$('#CheckOutDate').val(),vehicle_date=$('#VehiclePickUp').val(),citysel=$('#departure_city_id'),serverfile=$('#serverpath');selectStatus=!citysel?0:citysel.val();if(hotelID)selectStatus=hotelID;if(searchtype=='PFS'||searchtype=='PCS'){checkin_date=checkout_date;checkout_date=vehicle_date;}
var paramsString='channel='+channel+'&searchtype='+searchtype+'&checkin='+checkin_date+'&checkout='+checkout_date+'&selected='+selectStatus;$.ajax({type:"GET",url:path+"/reservation/searchbox.ajax.php",data:paramsString,dataType:'json',success:function(data){json=data;window.setTimeout(function(){var cityselect=$('#selectCities');var cityselect2=$('#selectCities2');if(!cityselect){return;}
cityselect.empty();cityselect2.empty();json.status=(json.status=='disabled')?true:false;if(json.empty||json.data==null)
{var select=$(document.createElement('select')).attr({id:'departure_city_id',name:'departure_city_id',disabled:json.status}).prependTo(cityselect);$(document.createElement('option')).attr('value','0').text('Change Dates').appendTo(select);return false;}
if(channel==2&&json.selected!='')
{referredUser(cityselect,json);return;}
if(channel==2)
{var select=$(document.createElement('select')).attr({id:'departure_country_id',name:'departure_country_id',disabled:json.status,'onchange':'javascript:getCity(this);'}).appendTo(cityselect);$(document.createElement('option')).attr('value','0').text('Select a Country').appendTo(select);for(i=0;i<json.data.length;i++){$(document.createElement('option')).attr('value',json.data[i]['country']).text(json.data[i]['country']).appendTo(select);}
var select2=$(document.createElement('select')).attr({id:'departure_city_id',name:'departure_city_id',disabled:'disabled'}).appendTo(cityselect2);$(document.createElement('option')).attr('value','0').text('Select a City').appendTo(select2);$('#departure_country_id').change(function(){getCity(this);});}
else
{var select=$(document.createElement('select')).attr({id:'departure_city_id',name:'departure_city_id',disabled:json.status}).prependTo(cityselect);$(document.createElement('option')).attr('value','0').text('Select a City').appendTo(select);for(i=0;i<json.data.length;i++){var optgroup=$(document.createElement('optgroup')).attr('label',json.data[i]['country']);for(y=0;y<json.data[i]['cities'].length;y++){var element=$(document.createElement('option')).text(json.data[i]['cities'][y]['name']).attr('value',json.data[i]['cities'][y]['id']);if(json.selected==json.data[i]['cities'][y]['id'])
element.attr('selected',true);element.appendTo(optgroup);}
optgroup.appendTo(select);}}},500);}});}
function getCity(obj)
{var select2=$('#selectCities2');startLoading('#selectCities2');window.setTimeout(function(){select2.empty();var select=$(document.createElement('select')).attr({'id':'departure_city_id','name':'departure_city_id'}).appendTo(select2);$(document.createElement('option')).attr('value','0').text('Select a City').appendTo(select);for(i=0;i<json.data.length;i++){if(obj.value==json.data[i]['country'])
{for(y=0;y<json.data[i]['cities'].length;y++){$(document.createElement('option')).attr('value',json.data[i]['cities'][y]['id']).text(json.data[i]['cities'][y]['name']).appendTo(select);}
return;}}},500);}
function startLoading(id){var image=$(document.createElement('img')).attr('src','/reservation/images/misc/loader.gif');$(id).html(image);}
function referredUser(cityselect,list)
{var cityselect=$('#selectCities'),cityselect2=$('#selectCities2'),countrySelected=false,citySelected=false;var select=$(document.createElement('select')).attr({id:'departure_country_id',name:'departure_country_id',disabled:json.status}).appendTo(cityselect);$(document.createElement('option')).attr('value','0').text('Select a Country').appendTo(select);var select2=$(document.createElement('select')).attr({id:'departure_city_id',name:'departure_city_id'}).appendTo(cityselect2);$(document.createElement('option')).attr('value','0').text('Select a City').appendTo(select2);for(i=0;i<json.data.length;i++){for(y=0;y<json.data[i]['cities'].length;y++){if(json.data[i]['cities'][y]['id']==json.selected){for(z=0;z<json.data[i]['cities'].length;z++){if(json.data[i]['cities'][z]['id']==json.selected){citySelected=true;}
$(document.createElement('option')).attr({'value':json.data[i]['cities'][z]['id'],'selected':citySelected}).text(json.data[i]['cities'][z]['name']).appendTo(select2);citySelected=false;}
countrySelected=true;}}
$(document.createElement('option')).attr({'value':json.data[i]['country'],'selected':countrySelected}).text(json.data[i]['country']).appendTo(select);if(countrySelected)
{$('#departure_country_id').attr('disabled',json.status);$('#departure_city_id').attr('disabled',json.status);}
countrySelected=false;}
$('#departure_country_id').change(function(){getCity(this);});};var bgColor1="#013879";var bgColor2="#004c88";var bgColor3="#317aa7";var bgColor4="#f36324";var bgColor5="#7ea1c9";var refresh="false";var vWinCal;var calChange;var calObj;var parentElem;var calIFrame;var o_navigator=navigator.userAgent.toLowerCase();var isOpera=o_navigator.indexOf("opera")>-1?1:0;var isMacIE=(o_navigator.indexOf("msie 5")>-1&&o_navigator.indexOf("mac")>-1)?1:0;var isPCIE=(o_navigator.indexOf("msie")>-1&&!isMacIE&&o_navigator.indexOf("opera")==-1)?1:0;var arr_months=["January","February","March","April","May","June","July","August","September","October","November","December"];var week_days=["Su","Mo","Tu","We","Th","Fr","Sa"];var days_arr=[31,28,31,30,31,30,31,31,30,31,30,31];var n_weekstart=0;var dt_now_dt=new Date();var dt_now=new Date(dt_now_dt.getFullYear(),dt_now_dt.getMonth(),dt_now_dt.getDate());var isFirstCall=false;var calendarForPopup=false;function doNothing()
{}
function create_calendar(str_target){if(navigator.appName=='Microsoft Internet Explorer'){create_calendar_noIE(str_target);}
create_calendar_noIE(str_target);}
function get_full_target(str_target){var tmpStr=new String(str_target);return(tmpStr.substring(0,3).toString()=="top")?tmpStr.toString():"top."+tmpStr.toString();}
function create_calendar_noIE(str_target){if(calObj!=null){document.body.removeChild(calObj);calObj==null;}
calObj=document.createElement('div');calObj.id='div';calObj.style.zIndex='10000';calObj.style.display='none';calObj.style.position='absolute';calObj.style.width="180px";calObj.style.height=(calendarForPopup)?216:413+"px"
calObj.src="#";calObj.contentEditable="false";calObj.unselectable="on";document.body.appendChild(calObj);}
function hide_calendar(evt,refresh){preclose_calendar(evt);calObj.style.display='none';AutoCompleteDates();if(refresh=='true'){reloadSearchbox();}}
function preclose_calendar(evt){if(isOpera)evt.stopPropagation();}
function getShortElementName(str_target){var re_date=/(\w+)[\.\\-](\w+)[\.\\-](\w+)$/;if(!re_date.exec(str_target))return'';return RegExp.$3;}
function prepare_calendar(str_buffer,str_target,str_datetime,refresh){var curr_date=str2dt4x(str_datetime);var prev_date=getCorrectDate(curr_date.getFullYear()-(((curr_date.getMonth()-1)<0)?1:0),(((curr_date.getMonth()-1)<0)?11:(curr_date.getMonth()-1)),curr_date.getDate(),false);var next_date=getCorrectDate(curr_date.getFullYear()+(curr_date.getMonth()+1)/12,(curr_date.getMonth()+1)%12,curr_date.getDate(),false);var next_of_now=getCorrectDate(dt_now.getFullYear()+(dt_now.getMonth()+1)/12,(dt_now.getMonth()+1)%12,dt_now.getDate(),false);var isNextOfNow=(curr_date.getFullYear()==next_of_now.getFullYear()&&curr_date.getMonth()==next_of_now.getMonth());var next_month_str=(isFirstCall&&isNextOfNow)?dt2dtstr4x(curr_date):dt2dtstr4x(next_date);str_buffer+="<html><body><table border=0 cellspacing=0 sellpadding=0 width=100\%>\n";str_buffer+="<tr height='8' valign='top'><td width=\"10%\"></td>";if((parseInt(prev_date.getFullYear()+""+iup22c(prev_date.getMonth()),10)>=parseInt(dt_now.getFullYear()+""+iup22c(dt_now.getMonth()),10))&&(!(isNextOfNow&&isFirstCall)))
{str_buffer+="<td width=\"80%\"><center><a href=\"#\" onclick=\"top.preclose_calendar(event); top.change_month('"+
get_full_target(str_target)+"', '"+dt2dtstr4x(prev_date)+"', "+refresh+");return false;\">"+"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">&lt;&lt;prev month</font></a></center></td>";}else{str_buffer+='<td width=\"80%\"><font color="black" face="tahoma, verdana" size="2">&nbsp;</font></td>';}
str_buffer+="<td width=\"10%\" align=\"center\">"
+"<a href=\"#\" onclick=\"top.hide_calendar(event); return false;\">"
+"<img onmouseover=\"this.src='http://www.parksleepfly.com/reservation/images/customer/calendar/button_close_down.gif'\" onmouseleave=\"this.src='http://www.parksleepfly.com/reservation/images/customer/calendar/button_close.gif'\" src=\"http://www.parksleepfly.com/reservation/images/customer/calendar/button_close.gif\" width=\"13\" height=\"13\" alt=\"close\" border=\"0\">"
+"</a></td></tr>";str_buffer+="<tr><td colspan=\"3\"><table valign='top' class=\"clsOTable\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">\n"+"<tr><td bgcolor=\""+bgColor1+"\">\n";str_buffer+="<table cellspacing=\"1\" cellpadding=\"1\" border=\"0\" width=\"100%\">\n";str_buffer+="<tr>\n"+"<td bgcolor=\""+bgColor2+"\" colspan=\"7\" align=\"center\">";if(isFirstCall&&isNextOfNow){str_buffer+=prepare_calendar4x(str_target,prev_date,false,refresh);}else{str_buffer+=prepare_calendar4x(str_target,curr_date,true,refresh);}
str_buffer+="<tr><td colspan=\"7\" bgcolor=\""+bgColor2+"\">"+"<font color=\"White\" face=\"tahoma, verdana\" size=\"2\">"+"</table>\n"+"</tr>\n</td>\n</table></td></tr>\n";if(!calendarForPopup){str_buffer+="<table border=0 cellspacing=0 sellpadding=0 width=100\%>\n";str_buffer+="<tr height='8' valign='top'><td width=\"10%\">&nbsp;</td>";str_buffer+="<td width=\"10%\">\&nbsp;</td></tr>";str_buffer+="<tr><td colspan=\"3\"><table valign='top' class=\"clsOTable\" cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">\n"+"<tr><td bgcolor=\""+bgColor1+"\">\n";str_buffer+="<table cellspacing=\"1\" cellpadding=\"1\" border=\"0\" width=\"100\%\">\n";str_buffer+="<tr>\n"+"<td bgcolor=\""+bgColor2+"\" colspan=\"7\" align=\"center\">";if(isFirstCall&&isNextOfNow){str_buffer+=prepare_calendar4x(str_target,curr_date,true,refresh);}else{str_buffer+=prepare_calendar4x(str_target,next_date,false,refresh);}
str_buffer+="<tr><td colspan=\"7\" bgcolor=\""+bgColor2+"\">"+"<font color=\"White\" face=\"tahoma, verdana\" size=\"2\">"+"</table>\n";}
str_buffer+="</tr>\n</td>\n</table></td></tr>\n";str_buffer+="<tr height='8' valign='top'><td colspan = \"3\"><center><a href=\"#\" onclick=\"top.preclose_calendar(event);top.change_month('"+
get_full_target(str_target)+"', '"+next_month_str+"', "+refresh+"); return false;\">"+"<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">next month >></font></a></center></td></tr>";str_buffer+="</table></body></html>";return str_buffer;}
function prepare_calendar4x(str_target,dt_datetime,displayCurrent,refresh)
{var dt_now=new Date(dt_now_dt.getFullYear(),dt_now_dt.getMonth(),dt_now_dt.getDate());var dt_now_date=dt_now.getDate();var dt_datetime_sy=new String(dt_datetime.getFullYear());var dt_firstday=new Date(dt_datetime);dt_firstday.setDate(1);dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);var ret_buffer=new String("");var dt_current_day=new Date(dt_firstday);ret_buffer+="<font color=\"white\" face=\"tahoma, verdana\" size=\"1\" >"
+arr_months[dt_datetime.getMonth()]+" "+dt_datetime_sy+"</font></td>\n";ret_buffer+="</tr>\n";ret_buffer+="<tr>\n";for(var n=0;n<7;n++)
ret_buffer+="        <td width="+((n==0||n==6)?15:14)+"\% align=\"center\" bgcolor=\""+bgColor3+"\">"+"<font color=\"white\" face=\"tahoma, verdana\" size=\"2\">"+
week_days[(n_weekstart+n)%7]+"</font></td>\n";ret_buffer+="</tr>\n";var rowCount=0;while(dt_current_day.getMonth()==dt_datetime.getMonth()||dt_current_day.getMonth()==dt_firstday.getMonth()||rowCount<=6)
{ret_buffer+="<tr>\n";for(var n_current_wday=0;n_current_wday<7;n_current_wday++)
{if(dt_current_day.getDate()==dt_datetime.getDate()&&dt_current_day.getMonth()==dt_datetime.getMonth()&&displayCurrent)
ret_buffer+="        <td bgcolor=\""+bgColor4+"\" align=\"right\">";else if(dt_current_day.getDay()==0||dt_current_day.getDay()==6)
ret_buffer+="        <td bgcolor=\""+bgColor5+"\" align=\"right\">";else
ret_buffer+="        <td bgcolor=\"white\" align=\"right\">";if(dt_now<=dt_current_day)
ret_buffer+="<a href=\"#\" onclick=\""+get_full_target(str_target)+".value = '"+dt2dtstr4x(dt_current_day)+"';top.hide_calendar(event,'"+refresh+"'); return false; \">";if(dt_current_day.getMonth()==dt_datetime.getMonth())
ret_buffer+="<font color=\"black\" face=\"tahoma, verdana\" size=\"2\">";else
ret_buffer+="<font color=\"gray\" face=\"tahoma, verdana\" size=\"2\">";if(dt_now<=dt_current_day)
ret_buffer+=dt_current_day.getDate()+"</font></a></td>\n";else
ret_buffer+=dt_current_day.getDate()+"</font></td>\n";dt_current_day.setDate(dt_current_day.getDate()+1);}
ret_buffer+="</tr>\n";rowCount++;}
return ret_buffer;}
function open_calendar(str_target,str_datetime,refresh){if(!(isPCIE)){calObj.innerHTML=make_calendar_grid(str_target,str_datetime,refresh);}else{var _str=new String(make_calendar_grid(str_target,str_datetime,refresh));top.cframe.document.write(_str);}
calObj.style.display='block';var cal_top=0;var cal_left=0;tmpParent=document.getElementById("psfSearchBlock");if(!tmpParent)tmpParent=parentElem.offsetParent;while(tmpParent!=null){cal_top+=tmpParent.offsetTop;tmpParent=tmpParent.offsetParent;}
tmpParent=document.getElementById("psfSearchBlock");if(!tmpParent)tmpParent=parentElem.offsetParent;while(tmpParent!=null){cal_left+=tmpParent.offsetLeft;tmpParent=tmpParent.offsetParent;}
calObj.style.top=cal_top+'px';calObj.style.left=cal_left+'px';}
function setUnselectableElements(){for(var i=0;i<top.cframe.document.all.length;i++){top.cframe.document.all(i).unselectable="on";}}
function change_month(str_target,str_datetime,refresh){isFirstCall=false;if(isPCIE){show_calendar(str_target,str_datetime,refresh);}else{calObj.innerHTML=make_calendar_grid(str_target,str_datetime,refresh);}}
function make_calendar_grid(str_target,str_datetime,refresh)
{var str_buffer=new String("<table style = \"border:1px solid black\" border=0 cellspacing=0 sellpadding=0 width=100\% bgcolor=#DDDDDD>\n<tr><td>");var datetime=str2dt4x(str_datetime);var dt_now_dt=new Date();if(datetime==null){datetime=dt_now_dt;}
var datetime1=datetime;var datetime2=new Date(datetime.getFullYear()+(datetime.getMonth()+1)/12,(datetime.getMonth()+1)%12,datetime.getDate());str_buffer=prepare_calendar(str_buffer,str_target,dt2dtstr4x(datetime1),refresh);str_buffer+="</td></tr>\n</table></div>";return str_buffer;}
function show_calendar(str_target,str_datetime,refresh){var dt_now_dt=new Date();var datetime=str2dt4x(str_datetime);if(datetime==null){datetime=dt_now_dt;}
datetime=new Date(datetime.getFullYear(),datetime.getMonth(),datetime.getDate());var str_datetime=dt2dtstr4x(datetime);create_calendar(str_target,refresh);parentElem=document.getElementsByName(getShortElementName(str_target))[0];if(isPCIE){}calObj.innerHTML="";calObj.innerHTML="<iframe id=\"cframe\" src = \"javascript:'calendar';\"  onactivate=\"top.setUnselectableElements();\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" width=\"180\" height=\""+((calendarForPopup)?"216":"413")+"\" frameborder=\"0\" ></iframe>";open_calendar(str_target,str_datetime,refresh);}
function show_calendar4x(str_target,str_datetime,refresh)
{isFirstCall=true;show_calendar(str_target,str_datetime,refresh);}
function hcoded_mtom(smonth)
{var fir=smonth.substr(0,3);mtom=fir.toLowerCase();if(mtom=='jan')return 1;if(mtom=='feb')return 2;if(mtom=='mar')return 3;if(mtom=='apr')return 4;if(mtom=='may')return 5;if(mtom=='jun')return 6;if(mtom=='jul')return 7;if(mtom=='aug')return 8;if(mtom=='sep')return 9;if(mtom=='oct')return 10;if(mtom=='nov')return 11;if(mtom=='dec')return 12;return 0;}
function str2dt4x(str_datetime)
{str_datetime=str_datetime.replace(/\s+/ig,'');var re_date=/^(\d+)[\/\\-](\d+)[\/\\-](\d+)$/;var mon=0;var day=0;var year=0;if(!re_date.exec(str_datetime))
{re_date=/^(\w+)[\/\\-](\d+)[\/\\-](\d+)$/;if(!re_date.exec(str_datetime))
return null;mon=hcoded_mtom(RegExp.$1)-1;if(mon<1)
return null;}
else
{mon=parseInt(RegExp.$1,10)-1;day=parseInt(RegExp.$2,10);year=parseInt(RegExp.$3,10);}
return getCorrectDate(year,mon,day,true);}
function dt2dtstr4x(dt_datetime)
{var s_year=new String(dt_datetime.getFullYear());return(new String((iup22c(dt_datetime.getMonth()+1))+"/"+iup22c(dt_datetime.getDate())+"/"+s_year.substring(0,4)));}
function iup22c(value)
{if(value<10)
return new String('0'+value);return value;}
function getCorrectDate(year4,mon,day,retCurrent){var curr_date=new Date();year4=(year4>curr_date.getFullYear())?year4:curr_date.getFullYear();year4=(year4<2100)?year4:curr_date.getFullYear();days_arr[1]=(year4%4==0)?29:28;mon=(mon<0)?0:mon;mon=(mon>11)?11:mon;day=(day<1)?1:day;day=(day>days_arr[mon])?days_arr[mon]:day;var retDate=new Date(year4,mon,day);var currDate=new Date();return((retDate<currDate)&&retCurrent)?currDate:retDate;}