﻿

/*
File which is converted to min : shared/js/Triveltek/rich_calendar.js

Date Created: 15 Nov 2011
Created BY: Ajay-Team websource
last modified Date:
last modified By:
*/

RichCalendar=function(target_obj,show_time){this.value='';this.format='%Y-%m-%d';this.start_week_day=1;this.iframe_obj=null;this.lib_path='rich_calendar/';this.target_obj=target_obj;this.show_time=show_time;this.user_onchange_handler=null;this.user_onclose_handler=null;this.user_onautoclose_handler=null;this.default_lang='en';this.language='en';this.date=new Date();this.skin='';this.auto_close=true;this.value_el=null;this.position=null;}
RichCalendar.is_ie=/msie/i.test(navigator.userAgent)&&!/opera/i.test(navigator.userAgent);RichCalendar.get_iframe_styles=function(){var i;var j;var styles=document.styleSheets;var sheets_num=styles.length;var style_text='';for(i=0;i<sheets_num;i++){if(RichCalendar.is_ie){if(/rich_calendar.css$/.test(styles[i].href)){style_text+=styles[i].cssText;break;}}else{var rules=null;try{if(RichCalendar.is_ie){rules=styles[i].rules;}else{rules=styles[i].cssRules;}}catch(error){continue;}
if(rules!=null){rules_num=rules.length;for(j=0;j<rules_num;j++){var rule_value=rules[j].selectorText;if(/rc_iframe/.test(rule_value)){style_text+=rules[j].cssText;}}}}}
return style_text;}
RichCalendar.attach_event=function(obj,event,handler){if(obj.addEventListener){obj.addEventListener(event,handler,false);}else{if(obj.attachEvent){obj.attachEvent('on'+event,handler);}}}
RichCalendar.detach_event=function(obj,event,handler){if(obj.removeEventListener){obj.removeEventListener(event,handler,false);}else{if(obj.detachEvent){obj.detachEvent('on'+event,handler);}}}
RichCalendar.attach_events=function(obj){RichCalendar.attach_event(obj,'click',RichCalendar.onclick);RichCalendar.attach_event(obj,'mouseover',RichCalendar.onmouseover);RichCalendar.attach_event(obj,'mouseout',RichCalendar.onmouseout);}
RichCalendar.detach_events=function(obj){RichCalendar.detach_event(obj,'click',RichCalendar.onclick);RichCalendar.detach_event(obj,'mouseover',RichCalendar.onmouseover);RichCalendar.detach_event(obj,'mouseout',RichCalendar.onmouseout);}
RichCalendar.onclick=function(e){var event=RichCalendar.get_event(e);var obj=RichCalendar.get_target_object(e);if(!obj)return;var cal=obj.calendar;var cur_year=cal.date.getFullYear();var cur_month=cal.date.getMonth();var cur_day=cal.date.getDate();switch(obj.rc_object_code){case'day':cal.date.setDate(obj.day_num);break;case'prev_year':cal.date.setDate(1);cal.date.setFullYear(cur_year-1);var month_days=RichCalendar.get_month_days(cal.date);if(cur_day>month_days){cal.date.setDate(month_days);}else{cal.date.setDate(cur_day);}
cal.show_date();break;case'prev_month':cal.date.setDate(1);cal.date.setMonth(cur_month-1);var month_days=RichCalendar.get_month_days(cal.date);if(cur_day>month_days){cal.date.setDate(month_days);}else{cal.date.setDate(cur_day);}
cal.show_date();break;case'next_month':cal.date.setDate(1);cal.date.setMonth(cur_month+1);var month_days=RichCalendar.get_month_days(cal.date);if(cur_day>month_days){cal.date.setDate(month_days);}else{cal.date.setDate(cur_day);}
cal.show_date();break;case'next_year':cal.date.setDate(1);cal.date.setFullYear(cur_year+1);var month_days=RichCalendar.get_month_days(cal.date);if(cur_day>month_days){cal.date.setDate(month_days);}else{cal.date.setDate(cur_day);}
cal.show_date();break;case'today':var today=new Date();today.setHours(cal.date.getHours());today.setMinutes(cal.date.getMinutes());today.setSeconds(cal.date.getSeconds());cal.date=today;cal.show_date();break;case'clear':if(cal.value_el){cal.value_el.value='';}
break;case'close':cal.onclose_handler();break;case'week_day':cal.start_week_day=obj.week_day_num;cal.show_date();break;default:break;}
if(obj.rc_object_code!='week_day'){cal.onchange_handler(obj.rc_object_code);}
RichCalendar.hide_auto_close(cal);}
RichCalendar.onmouseover=function(e){var event=RichCalendar.get_event(e);var obj=RichCalendar.get_target_object(e);if(!obj)return;var cal=obj.calendar;var cur_year=cal.date.getFullYear();var cur_month=cal.date.getMonth();var cur_day=cal.date.getDate();switch(obj.rc_object_code){case'day':var date=new Date(cal.date);date.setDate(obj.day_num);cal.set_footer_text(cal.get_formatted_date(cal.text('footerDateFormat'),date));RichCalendar.add_class(obj,"rc_highlight");RichCalendar.add_class(obj.parentNode,"rc_highlight");break;case'clear':case'today':case'close':case'prev_year':case'prev_month':case'next_month':case'next_year':cal.set_footer_text(cal.text(obj.rc_object_code));break;case'week_day':if(obj.week_day_num!=cal.start_week_day){var day_names=cal.text("dayNames");var name=day_names[obj.week_day_num];var text=cal.text("make_first");text=text.replace("%s",name);}else{var text=cal.text('footerDefaultText');}
cal.set_footer_text(text);break;default:cal.set_footer_text(cal.text('footerDefaultText'));break;}}
RichCalendar.onmouseout=function(e){var event=RichCalendar.get_event(e);var obj=RichCalendar.get_target_object(e);if(!obj)return;var cal=obj.calendar;cal.set_footer_text(cal.text('footerDefaultText'));RichCalendar.remove_class(obj,"rc_highlight");RichCalendar.remove_class(obj.parentNode,"rc_highlight");}
RichCalendar.document_onmousedown=function(e){var event=RichCalendar.get_event(e);var obj=RichCalendar.get_target_object(e);if(!obj)return;var el=obj;var cal=null;while(el){if(el.className&&el.className.match(/^rc_iframe_body/)&&el.tagName.toUpperCase()=='BODY'){cal=el.calendar;break;}
el=el.parentNode;}
RichCalendar.hide_auto_close(cal);}
RichCalendar.hide_auto_close=function(cal){var active_cals=[];var i;for(i=0;i<RichCalendar.active_calendars.length;i++){var cur_cal=RichCalendar.active_calendars[i];if(cur_cal.auto_close&&cur_cal!=cal){cur_cal.hide();if(cur_cal.user_onautoclose_handler){cur_cal.user_onautoclose_handler(this);}}else{active_cals[active_cals.length]=cur_cal;}}
RichCalendar.active_calendars=active_cals;}
RichCalendar.make_inactive=function(cal){var active_cals=[];var i;for(i=0;i<RichCalendar.active_calendars.length;i++){var cur_cal=RichCalendar.active_calendars[i];if(cur_cal!=cal){active_cals[active_cals.length]=cur_cal;}}
RichCalendar.active_calendars=active_cals;}
RichCalendar.get_event=function(e){return e||window.event;}
RichCalendar.get_target_object=function(e){return e.target?e.target:(e.srcElement?e.srcElement:window.event.srcElement);}
RichCalendar.skin_suffix=function(skin){return(skin!='')?('_'+skin):'';}
RichCalendar.get_month_days=function(date,month){var year=date.getFullYear();if(month){month=parseInt(month);if(month<=0||month>11)month=null;}
if(!month){month=date.getMonth();}
if(month==1&&RichCalendar.is_leap_year(year)){return 29;}else{return RichCalendar.month_days[month];}}
RichCalendar.is_leap_year=function(year){return(year%4==0&&year%100!=0||year%400==0)?true:false;}
RichCalendar.get_day_of_year=function(date){var now=new Date(date.getFullYear(),date.getMonth(),date.getDate(),0,0,0);var year_start=new Date(date.getFullYear(),0,0,0,0,0);var day_in_msecs=24*60*60*1000;return Math.floor((now-year_start)/day_in_msecs);}
RichCalendar.add_class=function(el,class_name){RichCalendar.remove_class(el,class_name);el.className+=" "+class_name;}
RichCalendar.remove_class=function(el,class_name){if(!el||!el.className)return
var new_class_parts=[];var class_parts=String(el.className).split(" ");var i;for(i=0;i<class_parts.length;i++){if(class_parts[i]!=""&&class_parts[i]!=class_name){new_class_parts[new_class_parts.length]=class_parts[i];}}
el.className=new_class_parts.join(" ");}
RichCalendar.get_obj_pos=function(obj,stop_obj){var pos=Array(0,0);if(!obj)return pos;var iniObj=obj;while(obj&&stop_obj!=obj){pos[0]+=obj.offsetLeft;pos[1]+=obj.offsetTop;if(obj!=iniObj){pos[0]+=parseInt(RichCalendar.get_style(obj,"borderTopWidth"),10)||0;pos[1]+=parseInt(RichCalendar.get_style(obj,"borderLeftWidth"),10)||0;}
obj=obj.offsetParent;}
var obj=iniObj;while(obj&&stop_obj!=obj&&obj.tagName.toLowerCase()!='body'){pos[0]-=obj.scrollLeft;pos[1]-=obj.scrollTop;obj=obj.parentNode;}
return pos;}
RichCalendar.get_style=function(el,name){var view=document.defaultView;if(view&&view.getComputedStyle){var st=view.getComputedStyle(el,"");return st[name];}
var v;if(v=el.currentStyle){return v[name];}
if(v=el.style[name]){return v;}}
RichCalendar.rc_lang_data=[];RichCalendar.month_days=[31,28,31,30,31,30,31,31,30,31,30,31];RichCalendar.active_calendars=[];RichCalendar.handlert_set=false;RichCalendar.prototype.show=function(x,y,el,position){if(!this.value_el){this.value_el=el;}
this.position=position;this.iframe_obj=document.createElement('IFRAME');this.iframe_obj.className='rc_calendar'+RichCalendar.skin_suffix(this.skin);this.iframe_obj.setAttribute('scrolling','no');this.iframe_obj.setAttribute('src','javascript:false;');this.iframe_obj.calendar=this;if(this.is_relative_position(position)){switch(position){case"before":if(el.parentNode){el.parentNode.insertBefore(this.iframe_obj,el);}
break;case"after":if(el.parentNode){el.parentNode.insertBefore(this.iframe_obj,el.nextSibling);}
break;case"child":default:el.appendChild(this.iframe_obj);this.position='child';break;}}else{this.iframe_obj.style.position='absolute';var left=parseInt(x);var top=parseInt(y);if(typeof(x)=='number'&&typeof(y)=='number'){this.iframe_obj.style.left=x+'px';this.iframe_obj.style.top=y+'px';}
this.iframe_obj.style.border='1px solid #000000';this.iframe_obj.value=this.value;document.body.appendChild(this.iframe_obj);}
var iframe_styles=RichCalendar.get_iframe_styles();var iframe_content=''+'<html>'+'<head>'+'<style type="text/css">'+iframe_styles+'</style>'+'</head>'+'<body class="rc_iframe_body'+RichCalendar.skin_suffix(this.skin)+'" id="rc_body">'+'</body></html>'+'';this.iframe_doc=this.iframe_obj.contentWindow.document;this.iframe_doc.open();this.iframe_doc.write(iframe_content);this.iframe_doc.close();RichCalendar.attach_event(this.iframe_doc,'mousedown',RichCalendar.document_onmousedown);this.body_obj=this.iframe_doc.getElementById('rc_body');this.body_obj.calendar=this;this.table_obj=this.iframe_doc.createElement('TABLE');this.table_obj.className='rc_table';this.table_obj.setAttribute('id','rc_iframe_table');this.table_obj.cellSpacing=0;this.table_obj.cellPadding=0;this.table_obj.calendar=this;this.head_tr=this.table_obj.insertRow(0);this.head_tr.className='rc_head_tr';this.clear_td=this.head_tr.insertCell(0);this.clear_td.innerHTML=' ';this.clear_td.rc_object_code='';this.clear_td.calendar=this;RichCalendar.attach_events(this.clear_td);this.head_td=this.head_tr.insertCell(1);this.head_td.colSpan=5;this.close_td=this.head_tr.insertCell(2);this.close_td.innerHTML='x';this.close_td.rc_object_code='close';this.close_td.calendar=this;RichCalendar.attach_events(this.close_td);this.nav_tr=this.table_obj.insertRow(1);this.nav_tr.className='rc_nav_tr';this.prev_year_td=this.nav_tr.insertCell(0);this.prev_year_td.innerHTML='«';this.prev_year_td.rc_object_code='prev_year';this.prev_year_td.calendar=this;RichCalendar.attach_events(this.prev_year_td);this.prev_month_td=this.nav_tr.insertCell(1);this.prev_month_td.innerHTML='‹';this.prev_month_td.rc_object_code='prev_month';this.prev_month_td.calendar=this;RichCalendar.attach_events(this.prev_month_td);this.today_td=this.nav_tr.insertCell(2);this.today_td.colSpan=3;this.today_td.innerHTML=this.text('today');this.today_td.rc_object_code='today';this.today_td.calendar=this;RichCalendar.attach_events(this.today_td);this.next_month_td=this.nav_tr.insertCell(3);this.next_month_td.innerHTML='›';this.next_month_td.rc_object_code='next_month';this.next_month_td.calendar=this;RichCalendar.attach_events(this.next_month_td);this.next_year_td=this.nav_tr.insertCell(4);this.next_year_td.innerHTML='»';this.next_year_td.rc_object_code='next_year';this.next_year_td.calendar=this;RichCalendar.attach_events(this.next_year_td);this.wd_tr=this.table_obj.insertRow(2);this.wd_tr.className='rc_wd_tr';var i;for(i=0;i<7;i++){var td=this.wd_tr.insertCell(i);td.rc_object_code='week_day';td.calendar=this;}
var rows_num=4;var row_indx;var cell_indx;this.cal_tr=[];for(row_indx=0;row_indx<rows_num;row_indx++){this.create_cal_row(row_indx);}
if(this.show_time){this.time_tr=this.table_obj.insertRow(rows_num+3);this.time_tr.className='rc_time_tr';var td=this.time_tr.insertCell(0);td.colSpan=2;td.innerHTML=this.text('time')+':';var td=this.time_tr.insertCell(1);td.colSpan=3;this.hours_obj=this.createElement('INPUT',td);this.hours_obj.className='rc_hours';this.hours_obj.setAttribute('size',1);this.hours_obj.setAttribute('maxlength',2);this.colon_span=this.createElement('SPAN',td);this.colon_span.className='rc_colon_span';this.colon_span.innerHTML=' : ';this.mins_obj=this.createElement('INPUT',td);this.mins_obj.className='rc_mins';this.mins_obj.setAttribute('size',1);this.mins_obj.setAttribute('maxlength',2);var td=this.time_tr.insertCell(2);td.colSpan=2;td.innerHTML=' ';}
this.footer_tr=this.table_obj.insertRow(rows_num+3+(this.show_time?1:0));this.footer_tr.className='rc_footer_tr';this.footer_td=this.footer_tr.insertCell(0);this.footer_td.colSpan=7;this.footer_td.innerHTML=this.text('footerDefaultText');this.body_obj.appendChild(this.table_obj);this.size_div=document.createElement('DIV');this.size_div.className=this.body_obj.className;this.size_div.style.position="absolute";this.size_div.style.left="-1000px";this.size_div.style.top="-1000px";document.body.appendChild(this.size_div);this.show_date();if(!RichCalendar.handlers_set){RichCalendar.attach_event(document,'mousedown',RichCalendar.document_onmousedown);RichCalendar.handlers_set=true;}
RichCalendar.active_calendars[RichCalendar.active_calendars.length]=this;}
RichCalendar.prototype.hide=function(){if(this.iframe_obj){this.iframe_obj.parentNode.removeChild(this.iframe_obj);this.iframe_obj=null;}
RichCalendar.make_inactive(this);}
RichCalendar.prototype.show_at_element=function(el,position){if(typeof(el)!="object"||!el)return;if(this.is_relative_position(position)){this.show(null,null,el,position);return;}
var el_pos=RichCalendar.get_obj_pos(el);var x=-1000;var y=-1000;this.show(x,y,el,position);}
RichCalendar.prototype.fix_position=function(el){var position=this.position;if(this.is_relative_position(position)){return;}
if(!el){el=this.value_el;}
var aligns=String(position).split("-");if(aligns.length==2){var el_pos=RichCalendar.get_obj_pos(el);var x=el_pos[0];var y=el_pos[1]+el.offsetHeight;var border_width=parseInt(this.iframe_obj.style.borderWidth);var cal_width=parseInt(this.iframe_obj.width)+2*border_width;var cal_height=parseInt(this.iframe_obj.height)+2*border_width;switch(aligns[0]){case"left":x-=cal_width;break;case"center":x+=(el.offsetWidth-cal_width)/2;break;case"right":x+=el.offsetWidth;break;case"adj_right":x+=el.offsetWidth-cal_width;break;default:break;}
switch(aligns[1]){case"top":y-=el.offsetHeight+cal_height;break;case"center":y+=(el.offsetHeight-cal_height)/2-el.offsetHeight;break;case"bottom":break;case"adj_bottom":y-=cal_height;break;default:break;}
this.iframe_obj.style.left=x+'px';this.iframe_obj.style.top=y+'px';this.iframe_obj.style.visibility='visible';}}
RichCalendar.prototype.is_relative_position=function(position){switch(position){case"before":case"after":case"child":return true;default:return false;}}
RichCalendar.prototype.createElement=function(tagName,parent){var el=this.iframe_doc.createElement(tagName);if(parent){parent.appendChild(el);}
return el;}
RichCalendar.prototype.text=function(name,language){if(typeof(language)=="undefined"){language=this.language;}
if(typeof(RichCalendar.rc_lang_data[language])!="undefined"){return typeof(RichCalendar.rc_lang_data[language][name])!="undefined"?RichCalendar.rc_lang_data[language][name]:'';}
return typeof(RichCalendar.rc_lang_data[this.default_language][name])!="undefined"?RichCalendar.rc_lang_data[this.default_language][name]:'';}
RichCalendar.prototype.show_date=function(){var weekend_days=this.get_weekend_days();var i;var day_names=this.text('dayNamesShort');for(i=0;i<7;i++){var wd=(i+this.start_week_day)%7;var td=this.wd_tr.cells[i];td.innerHTML=day_names[wd];if(typeof(weekend_days[wd])!="undefined"){td.className="rc_weekend_head";}else{td.className="";}
td.week_day_num=wd;}
var month_days=RichCalendar.get_month_days(this.date);var date=new Date(this.date);date.setDate(1);var week_day=(date.getDay()+7-this.start_week_day)%7+1;var cur_year=this.date.getFullYear();var cur_month=this.date.getMonth();var cur_day=this.date.getDate();var today=new Date();var today_year=today.getFullYear();var today_month=today.getMonth();var today_day=today.getDate();var month_names=this.text('monthNames');this.head_td.innerHTML=month_names[cur_month]+', '+cur_year;var row;var day;var days=0;var last_row;for(row=0;row<6;row++){if(days==month_days){if(this.cal_tr[last_row+1]){this.cal_tr[last_row+1].parentNode.removeChild(this.cal_tr[last_row+1]);this.cal_tr[row]=null;}
continue;}
for(day=0;day<7;day++){if(!this.cal_tr[row]){this.create_cal_row(row);}
var cur_tr=this.cal_tr[row];var cell=cur_tr.cells[day];cell.className="";RichCalendar.detach_events(cell);if(row==0&&day+1<week_day||days==month_days){var td_text=' ';}else{var day_num=days+1;var td_text=day_num;days++;cell.rc_object_code='day';cell.day_num=day_num;cell.calendar=this;if(dateDiff("d",new Date(),new Date(cur_year,cur_month,day_num))>=-1)
{RichCalendar.attach_events(cell);}else{RichCalendar.add_class(cell,"rc_Dissable_day");}
if(cur_day==day_num){RichCalendar.add_class(cell,"rc_current");}
if(day_num==today_day&&cur_month==today_month&&cur_year==today_year){RichCalendar.add_class(cell,"rc_today");}
var wd=(day+this.start_week_day)%7;if(typeof(weekend_days[wd])!="undefined"){RichCalendar.add_class(cell,"rc_weekend_day");}else{RichCalendar.remove_class(cell,"rc_weekend_day");}}
cell.innerHTML=td_text;if(days==month_days){last_row=row;}}}
if(this.show_time&&this.hours_obj&&this.mins_obj){var hours=this.date.getHours();if(hours<10)hours='0'+hours;var mins=this.date.getMinutes();if(mins<10)mins='0'+mins;this.hours_obj.value=hours;this.mins_obj.value=mins;}
var cal=this;window.setTimeout(function(){cal.fit_to_content()},1);window.setTimeout(function(){cal.fix_position()},5);}
RichCalendar.prototype.fit_to_content=function(){try{var table_obj=this.iframe_doc.getElementById('rc_iframe_table');this.iframe_obj.width=table_obj.offsetWidth;this.iframe_obj.height=table_obj.offsetHeight;if(!parseInt(this.iframe_obj.width)||!parseInt(this.iframe_obj.height)){this.size_div.innerHTML=this.body_obj.innerHTML;this.iframe_obj.width=this.size_div.offsetWidth;this.iframe_obj.height=this.size_div.offsetHeight;}}catch(e){}}
RichCalendar.prototype.create_cal_row=function(index){var row=this.table_obj.insertRow(3+index);row.className='rc_cal_tr';var cell_indx;for(cell_indx=0;cell_indx<7;cell_indx++){var td=row.insertCell(cell_indx);}
this.cal_tr[index]=row;return row;}
RichCalendar.prototype.change_skin=function(skin){if(!this.iframe_obj)return;var skin_suffix=RichCalendar.skin_suffix(skin);this.iframe_obj.className='rc_calendar'+skin_suffix;this.body_obj.className='rc_iframe_body'+skin_suffix;this.skin=skin;}
RichCalendar.prototype.get_formatted_date=function(format,date){if(!date)date=this.date;if(!format)format=this.get_date_format();if(this.show_time&&this.hours_obj&&this.mins_obj){this.date.setHours(this.hours_obj.value);var mins=this.date.setMinutes(this.mins_obj.value);}
var y=date.getFullYear();var m=date.getMonth();var d=date.getDate();var wd=date.getDay();var hr=date.getHours();var mins=date.getMinutes();var secs=date.getSeconds();var month_names_short=this.text('monthNamesShort');var month_names=this.text('monthNames');var day_names_short=this.text('dayNamesShort');var day_names=this.text('dayNames');var am=hr<12?true:false;var hr12=hr>12?hr-12:(hr==0?12:hr);var f=[];f["%a"]=am?'am':'pm';f["%A"]=am?'AM':'PM';f["%d"]=d<10?'0'+d:d;f["%D"]=day_names_short[wd];f["%F"]=month_names[m];f["%h"]=hr12<10?'0'+hr12:hr12;f["%H"]=hr<10?'0'+hr:hr;f["%g"]=hr12;f["%G"]=hr;f["%i"]=mins<10?'0'+mins:mins;f["%j"]=d;f["%l"]=day_names[wd];f["%L"]=RichCalendar.is_leap_year(y)?1:0;f["%m"]=m<9?'0'+(m+1):(m+1);f["%n"]=m+1;f["%M"]=month_names_short[m];f["%s"]=secs<10?'0'+secs:secs;f["%t"]=RichCalendar.get_month_days(date);f["%w"]=wd;f["%Y"]=y;f["%y"]=String(y).substr(2,2);f["%z"]=RichCalendar.get_day_of_year(date);var parts=String(format).match(/%./g);var i;var f_date=format;for(i=0;i<parts.length;i++){var value=f[parts[i]];if(typeof(value)!="undefined"){var re=new RegExp(parts[i],'g');f_date=f_date.replace(re,value);}}
return f_date;}
RichCalendar.prototype.set_footer_text=function(text){if(this.footer_td){this.footer_td.innerHTML=text;}}
RichCalendar.prototype.get_weekend_days=function(){var weekend_days=this.text('weekend');var weekend_parts=weekend_days.split(",");var i;var result=[];for(i=0;i<weekend_parts.length;i++){result[weekend_parts[i]]=true;}
return result;}
RichCalendar.prototype.onclose_handler=function(){if(this.user_onclose_handler){this.user_onclose_handler(this);}else{this.hide();}}
RichCalendar.prototype.onchange_handler=function(object_code){if(this.user_onchange_handler){this.user_onchange_handler(this,object_code);}else{if(object_code=='day'){if(this.value_el)this.value_el.value=this.get_formatted_date();if(this.auto_close)this.hide();}else{}}}
RichCalendar.prototype.get_date_format=function(){var lang_date_format=this.text('dateFormat');var format=lang_date_format?lang_date_format:this.format;if(this.show_time){format+=' %H:%i';}
return format;}
RichCalendar.prototype.parse_date=function(str,format){if(typeof(str)=="undefined"){return;}
if(!format)format=this.get_date_format();var today=new Date();var year=0;var month=-1;var day=0;var hours=0;var mins=0;var seconds=0;var month_names=this.text('monthNames');var short_month_names=this.text('monthNamesShort');var en_month_names=this.text('monthNames','en');var en_short_month_names=this.text('monthNamesShort','en');for(j=0;j<month_names.length;j++){var re=new RegExp(month_names[j],'gi');str=str.replace(re,en_month_names[j]);}
for(j=0;j<short_month_names.length;j++){var re=new RegExp(short_month_names[j],'gi');str=str.replace(re,en_short_month_names[j]);}
var p=String(str).split(/\W+/g);var f_p=String(format).match(/%./g);var i;var j;var k;for(i=0;i<f_p.length;i++){if(!p[i])continue;switch(f_p[i]){case'%a':case'%A':if(/am/i.test(p[i])&&hours>=12){hours-=12;}else{if(/pm/i.test(p[i])&&hours<12){hours+=12;}}
break;case'%d':case'%j':day=parseInt(Number(p[i]));break;case'%F':for(j=0;j<en_month_names.length;j++){if(en_month_names[j].toLowerCase()==p[i].toLowerCase()){month=j;break;}}
break;case'%h':case'%H':case'%g':case'%G':hours=parseInt(Number(p[i]));if(/am/i.test(p[i])&&hours>=12){hours-=12;}else{if(/pm/i.test(p[i])&&hours<12){hours+=12;}}
break;case'%i':mins=parseInt(Number(p[i]));break;case'%m':case'%n':month=parseInt(Number(p[i]))-1;break;case'%M':for(j=0;j<en_short_month_names.length;j++){if(en_short_month_names[j].toLowerCase()==p[i].toLowerCase()){month=j;break;}}
break;case'%s':seconds=parseInt(Number(p[i]));break;case'%Y':year=parseInt(Number(p[i]));break;case'%y':year=parseInt(p[i]);if(year<100){year+=year+(year>29?1900:2000);}
break;default:break;}}
if(isNaN(year)||year<=0)year=today.getFullYear();if(isNaN(month)||month<0||month>11)month=today.getMonth();if(isNaN(day)||day<=0||day>31)day=today.getDate();if(isNaN(hours)||hours<0||hours>23)hours=today.getHours();if(isNaN(mins)||mins<0||mins>59)mins=today.getMinutes();if(isNaN(seconds)||seconds<0||seconds>59)seconds=today.getSeconds();this.date=new Date(year,month,day,hours,mins,seconds);}
function dateDiff(datepart,fromdate,todate)
{datepart=datepart.toLowerCase();var diff=todate-fromdate;var divideBy={w:604800000,d:86400000,h:3600000,n:60000,s:1000};return Math.floor(diff/divideBy[datepart]);}
var text=new Array();text['today']='Today';text['time']='Time';text['dayNamesShort']=new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');text['dayNames']=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');text['monthNamesShort']=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');text['monthNames']=new Array('January','February','March','April','May','June','July','August','September','October','November','December');text['footerDateFormat']='%D, %F %j %Y',text['dateFormat']='%n-%j-%Y',text['footerDefaultText']='Select date',text['clear']='Clear Date',text['prev_year']='Previous year',text['prev_month']='Previous month',text['next_month']='Next month',text['next_year']='Next year',text['close']='Close',text['weekend']="0,6";text['make_first']="Start with %s";RichCalendar.rc_lang_data['en']=text;

    var cal_obj3 = null;
    var cal_obj2 = null;
    var format = '%j-%m-%Y';
    
    var defaultpromocodeText = "Promo Code...";
    var defaultwantednameText = "Property Name...";
    var DefaultHolidaysCountry = "Gambia";
    var DefaultHotelsCountry = "Canaries";
    var DefaultFlightsCountry = "Spain";
    var DefaultCityBreaksCountry = "Italy";
    
        var DefaultHolidaysDestair = "BJL";
    var DefaultHotelsDestair = "TFS";
    var DefaultFlightsDestair = "BCN";
    var DefaultCityBreaksDestair = "FCO";
// show calendar
function show_cal(el, calID) {
	if (cal_obj2) return;
	var DDSelecteddate = "[D]-[M]-[Y]";
    var text_field = document.getElementById(calID);

    DDSelecteddate = DDSelecteddate.replace("[D]",document.getElementById("depdate-day").value);
    DDSelecteddate = DDSelecteddate.replace("[M]",document.getElementById("depdate-month").value);
    DDSelecteddate = DDSelecteddate.replace("[Y]",document.getElementById("depdate-year").value);

	cal_obj2 = new RichCalendar();
	cal_obj2.start_week_day = 1;
	cal_obj2.show_time = false;
	cal_obj2.user_onchange_handler = cal2_on_change;
	cal_obj2.user_onclose_handler = cal2_on_close;
	cal_obj2.user_onautoclose_handler = cal2_on_autoclose;
	cal_obj2.parse_date(DDSelecteddate, format);
	cal_obj2.show_at_element(text_field, "adj_right-bottom");
	cal_obj2.change_skin('alt');	
}
// user defined onchange handler
function cal2_on_change(cal, object_code) {
	if (object_code == 'day') {
		//document.getElementById("text_field").value = cal.get_formatted_date(format);
		var temp = new Array();
		 temp = cal.get_formatted_date(format).split("-");		
		 if (temp[1] =="10")
		 {
		 monthNumber = temp[1];
		 }
		 else
		 {
		  monthNumber = temp[1].replace("0","");
		 }
		 
		document.getElementById("depdate-day").value =  temp[0];
		document.getElementById("depdate-month").value =  monthNumber;
		document.getElementById("depdate-year").value =  temp[2];
		
		var ReturnDate= new Date(temp[2], monthNumber -1 , temp[0]);
        ReturnDate.setDate(ReturnDate.getDate() + 7);
        returnMonth =  ReturnDate.getMonth() + 1;
		
		document.getElementById("retdate-day").value =  ReturnDate.getDate();
		document.getElementById("retdate-month").value =  returnMonth;
		document.getElementById("retdate-year").value =  ReturnDate.getFullYear();
		cal.hide();
		cal_obj2 = null;
	}
}
// user defined onclose handler (used in pop-up mode - when auto_close is true)
function cal2_on_close(cal) {
	if (window.confirm('Are you sure to close the calendar?')) {
		cal.hide();
		cal_obj2 = null;
	}
}
// user defined onautoclose handler
function cal2_on_autoclose(cal) {
	cal_obj2 = null;
}


// show calendar
function show_cal3(el, calID) {
	if (cal_obj3) return;
	var DDSelecteddate = "[D]-[M]-[Y]";
    var text_field = document.getElementById(calID);

    DDSelecteddate = DDSelecteddate.replace("[D]",document.getElementById("retdate-day").value);
    DDSelecteddate = DDSelecteddate.replace("[M]",document.getElementById("retdate-month").value);
    DDSelecteddate = DDSelecteddate.replace("[Y]",document.getElementById("retdate-year").value);

	cal_obj3 = new RichCalendar();
	cal_obj3.start_week_day = 1;
	cal_obj3.show_time = false;
	cal_obj3.user_onchange_handler = cal3_on_change;
	cal_obj3.user_onclose_handler = cal3_on_close;
	cal_obj3.user_onautoclose_handler = cal3_on_autoclose;
	cal_obj3.parse_date(DDSelecteddate, format);
	cal_obj3.show_at_element(text_field, "adj_right-bottom");
	cal_obj3.change_skin('alt');	
}
// user defined onchange handler
function cal3_on_change(cal, object_code) {
	if (object_code == 'day') {
		//document.getElementById("text_field").value = cal.get_formatted_date(format);
		var temp = new Array();
		 temp = cal.get_formatted_date(format).split("-");
		if (temp[1] =="10")
		 {
		 monthNumber = temp[1];
		 }
		 else
		 {
		  monthNumber = temp[1].replace("0","");
		 }
		document.getElementById("retdate-day").value =  temp[0];
		document.getElementById("retdate-month").value =  monthNumber;
		document.getElementById("retdate-year").value =  temp[2];
		cal.hide();
		cal_obj3 = null;
	}
}
// user defined onclose handler (used in pop-up mode - when auto_close is true)
function cal3_on_close(cal) {
	if (window.confirm('Are you sure to close the calendar?')) {
		cal.hide();
		cal_obj3 = null;
	}
}
// user defined onautoclose handler
function cal3_on_autoclose(cal) {
	cal_obj3 = null;
}




    function WaterMark(txt, evt)
    {
    

        if(txt.value.length == 0 && evt.type == "blur")
        {
            txt.style.color = "gray";
            if (txt.name == "promocode")
            {
                txt.value = defaultpromocodeText;
            }
            else if(txt.name == "wantedname")
            {
             txt.value = defaultwantednameText;
            }
        }
        if(txt.value == defaultpromocodeText && evt.type == "focus")
        {
            txt.style.color = "black";
            txt.value="";
        }
         if(txt.value == defaultwantednameText && evt.type == "focus")
        {
            txt.style.color = "black";
            txt.value="";
        }
    }
    
  
function submitform(Object)
{
var oForm = Object.form;

 oForm.elements["__VIEWSTATE"].value="";

var StrQerystring = GetFielsValue("sid",oForm) + GetQueryStringFormated(oForm);


        StrQerystring = "http://search.packyourbags.com/fusion/start.pl?" + StrQerystring; 
       
  
      if  (oForm.elements["product"].value == "flight"  )
      {
          if  (oForm.elements["sid"].value == "12865"  )
          {

            
             var Room = oForm.elements["roomcount"];
            
             var newElem = document.createElement("option");
                    newElem.text = "0";
                    newElem.value = "0";
                Room.options.add(newElem);
                Room.value = "0";
          }
      }

        document.forms[0].action =  StrQerystring; 
        document.forms[0].method = "POST";
        document.forms[0].submit();
  
}

function GetQueryStringFormated(oForm)
{
        var products =  oForm.elements["product"].value;
        var QuerystringList = "";
        
        QuerystringList += "&" + GetFielsValue("searchby",oForm);
        QuerystringList += "&" + GetFielsValue("formno",oForm);
        QuerystringList += "&" + GetFielsValue("depdate-day",oForm);
        QuerystringList += "&" + GetFielsValue("depdate-month",oForm);
        QuerystringList += "&" + GetFielsValue("depdate-year",oForm);
        QuerystringList += "&" + GetFielsValue("nights",oForm);
       
        QuerystringList += "&" + GetFielsValue("rating",oForm);

        var searchbyTxt =  oForm.elements["searchby"].value;
        if (searchbyTxt =="dest")
        {
        QuerystringList += "&destair=" + oForm.elements["destair"].value;
        QuerystringList += "&resort=" + oForm.elements["resort"].value;
        QuerystringList += "&country=" + oForm.elements["country"].value;
        }
        else
        {
        QuerystringList += "&" + GetFielsValue("to",oForm);
        }
        QuerystringList += "&" + GetFielsValue("children-1",oForm);
        QuerystringList += "&" + GetFielsValue("adults-1",oForm);
        QuerystringList += "&" + GetFielsValue("adults-2",oForm);
        QuerystringList += "&" + GetFielsValue("adults-3",oForm);
        QuerystringList += "&" + GetFielsValue("children-1",oForm);
        QuerystringList += "&" + GetFielsValue("children-2",oForm);
        QuerystringList += "&" + GetFielsValue("children-3",oForm);

        QuerystringList += GetCustomQuerystring(products,oForm)

        QuerystringList += "&" + GetFielsValue("childage-1-1",oForm);
        QuerystringList += "&" + GetFielsValue("childage-1-2",oForm);
        QuerystringList += "&" + GetFielsValue("childage-1-3",oForm);
        QuerystringList += "&" + GetFielsValue("childage-1-4",oForm);
        QuerystringList += "&" + GetFielsValue("childage-1-5",oForm);
        QuerystringList += "&" + GetFielsValue("childage-2-1",oForm);
        QuerystringList += "&" + GetFielsValue("childage-2-2",oForm);
        QuerystringList += "&" + GetFielsValue("childage-2-3",oForm);
        QuerystringList += "&" + GetFielsValue("childage-2-4",oForm);
        QuerystringList += "&" + GetFielsValue("childage-2-5",oForm);
        QuerystringList += "&" + GetFielsValue("childage-3-1",oForm);
        QuerystringList += "&" + GetFielsValue("childage-3-2",oForm);
        QuerystringList += "&" + GetFielsValue("childage-3-3",oForm);
        QuerystringList += "&" + GetFielsValue("childage-3-4",oForm);
        QuerystringList += "&" + GetFielsValue("childage-3-5",oForm);

        QuerystringList += "&search=Search";
        //alert(QuerystringList);
        return QuerystringList;
}

function GetCustomQuerystring(productstype,oForm){
    var QueryStr = ""
    switch(productstype)
    {
    case 'flighthotelpackage':
        setfield("product", "flighthotelpackage");
        QueryStr = "&product=flighthotelpackage";
        QueryStr += "&depair=" + oForm.elements["depair"].value;
        QueryStr += "&children=" + GetchildrensCount(oForm);
        QueryStr += "&adults=" + GetAdultsCount(oForm);
        QueryStr += "&infants=" + GetinfantsCount(oForm);
        QueryStr += "&" + GetFielsValue("infants-1",oForm);
        QueryStr += "&" + GetFielsValue("infants-2",oForm);
        QueryStr += "&" + GetFielsValue("infants-3",oForm);
        QueryStr += "&" + GetwantednameValue("wantedname",oForm);        
        QueryStr += "&" + GetFielsValue("rating",oForm);
        QueryStr += "&" + GetFielsValue("board",oForm);
        QueryStr += "&" + GetFielsValue("retdate-day",oForm);
        QueryStr += "&" + GetFielsValue("retdate-month",oForm);
        QueryStr += "&" + GetFielsValue("retdate-year",oForm);
        QueryStr += "&" + GetFielsValue("roomcount",oForm);
     break;
    case 'hotel':
        setfield("product", "hotel");
        QueryStr = "&product=hotel";
        QueryStr += "&children=" + GetchildrensCount(oForm);
        QueryStr += "&adults=" + GetAdultsCount(oForm);
        QueryStr += "&" + GetwantednameValue("wantedname",oForm);        
        QueryStr += "&" + GetFielsValue("rating",oForm);
        QueryStr += "&" + GetFielsValue("board",oForm);
        QueryStr += "&" + GetFielsValue("retdate-day",oForm);
        QueryStr += "&" + GetFielsValue("retdate-month",oForm);
        QueryStr += "&" + GetFielsValue("retdate-year",oForm);
         QueryStr += "&" + GetFielsValue("roomcount",oForm);
       break;
    case 'flight':
        setfield("product", "flight");
        QueryStr = "&product=flight&roomcount=0";
        QueryStr += "&depair=" + oForm.elements["depair"].value;
        QueryStr += "&" + GetFielsValue("retdate-day",oForm);
        QueryStr += "&" + GetFielsValue("retdate-month",oForm);
        QueryStr += "&" + GetFielsValue("retdate-year",oForm);
        QueryStr += "&" + GetFielsValue("flightclass",oForm);
        QueryStr += "&" + GetFielsValue("adults",oForm);
        QueryStr += "&" + GetFielsValue("children",oForm);
        QueryStr += "&" + GetFielsValue("infants",oForm); 
        
      break;
    case 'flighthotel':
        setfield("product", "flight");
        QueryStr = "&product=flight";
        QueryStr += "&depair=" + oForm.elements["depair"].value;
        QueryStr += "&children=" + GetchildrensCount(oForm);
        QueryStr += "&adults=" + GetAdultsCount(oForm);
        QueryStr += "&" + GetFielsValue("rating",oForm);
        QueryStr += "&" + GetFielsValue("board",oForm);

        QueryStr += "&" + GetFielsValue("retdate-day",oForm);
        QueryStr += "&" + GetFielsValue("retdate-month",oForm);
        QueryStr += "&" + GetFielsValue("retdate-year",oForm);
        QueryStr += "&" + GetwantednameValue("wantedname",oForm);
        QueryStr += "&" + GetpromocodeValue("promocode",oForm);
        
         QueryStr += "&" + GetFielsValue("roomcount",oForm);
      break;
    }
    return QueryStr;
}



function GetwantednameValue(Fieldname,oForm)
{
var returnString ="";
    try
    {
        if (oForm.elements[Fieldname].value != defaultwantednameText)
        {    
            returnString = oForm.elements[Fieldname].name + "=" + oForm.elements[Fieldname].value;
        }else
        {
            returnString = oForm.elements[Fieldname].name + "=" ;
            oForm.elements[Fieldname].value = "";
            }
    }   
    catch(err)
    {
    //Handle errors here
   // alert(err + "" + Fieldname);
    }
return returnString;
}
function GetpromocodeValue(Fieldname,oForm)
{
var returnString ="";
    try
    {
        if (oForm.elements[Fieldname].value != defaultpromocodeText)
        {    
            returnString = oForm.elements[Fieldname].name + "=" + oForm.elements[Fieldname].value;
        }else
        {
            returnString = oForm.elements[Fieldname].name + "=" ;
            oForm.elements[Fieldname].value = "";
            }
    }   
    catch(err)
    {
    //Handle errors here
   // alert(err + "" + Fieldname);
    }
return returnString;
}

function GetAdultsCount(oForm)
{
    var DDRoomCount = oForm.elements["roomcount"].value;
    var adultCount = 0;
    for (i=1;i<=DDRoomCount;i++)
    {
        adultCount = parseInt(adultCount)  + parseInt(oForm.elements["adults-" + i].value);
    }
    return adultCount;
}

function GetchildrensCount(oForm)
{
    var DDRoomCount = oForm.elements["roomcount"].value;
    //alert(DDRoomCount);
    var intchildrenCount = 0;
    for (i=1;i<=DDRoomCount;i++)
    {
        intchildrenCount = parseInt(intchildrenCount)  + parseInt(oForm.elements["children-" + i].value);
    }
    return intchildrenCount;
}

function GetinfantsCount(oForm)
{
    var DDRoomCount = oForm.elements["roomcount"].value;
    var infantsCountint = 0;
    for (i=1;i<=DDRoomCount;i++)
    {
        infantsCountint = parseInt(infantsCountint)  + parseInt(oForm.elements["infants-" + i].value);
    }
    return infantsCountint;
}

function GetFielsValue(Fieldname,oForm)
{
var returnString ="";
    try
    {
    returnString = oForm.elements[Fieldname].name + "=" + oForm.elements[Fieldname].value;
    }
    catch(err)
    {
    //Handle errors here
   // alert(err + "" + Fieldname);
    }
return returnString;
}

function AddDaysToDate(date, days)
{
date.setDate(date.getDate() + days);
return date;
}

function setform() {
var thispage = document.URL;


var now = new Date();
now.setDate(now.getDate() + 7);
var monthnumber = now.getMonth();
var monthday    = now.getDate();
var year        = now.getYear();

monthnumber = monthnumber +1
var ReturnDate = new Date();
ReturnDate.setDate(ReturnDate.getDate() + 14);
returnMonth =  ReturnDate.getMonth() + 1;

setfield("depdate-year", year);
setfield("depdate-month", monthnumber);
setfield("depdate-day", monthday);
setfield("depdatefull", monthday + "/" + monthnumber+ "/" + year );
setfield("depdateiso", year + "-" + monthnumber + "-" + monthday);
	
setfield("retdate-year", ReturnDate.getYear());
setfield("retdate-month",returnMonth);
setfield("retdate-day", ReturnDate.getDate());
setfield("retdatefull", ReturnDate.getDate() + "/" + returnMonth+ "/" + ReturnDate.getYear() );
setfield("retdateiso", ReturnDate.getYear() + "-" + returnMonth + "-" + ReturnDate.getDate());
	
//}
//setfield("country", "");
//setfield("depair", "");
//setfield("destair", "");

setfield("nights", "7");
setfield("nightsfrom", "7");
setfield("nightsto", "7");
//setfield("from", "");
//setfield("to", "");
setfield("fromgroup", "");
setfield("togroup", "");
setfield("roomcount", "1");
setfield("rating", "");
setfield("board", "");
setfield("wantedname", "Property Name...");
SetWatermark("wantedname");
setfield("adults", "2");
setfield("children", "");
setfield("infants", "");
setfield("plusminus", "3");
setfield("airline", "");
setfield("flightclass", "");
setfield("sc", "");
setfield("pets", "");
setfield("petfree", "");
setfield("locationid", "");
setfield("departparent", "");
setfield("departchild", "");
setfield("destinationparent", "");
setfield("destinationchild", "");
setfield("indepartcode", "");
setfield("inarrivecode", "");
setfield("freechild", "");
setfield("currency", "GBP");
setfield("includescheduled", "no");
setfield("promocode", "Promo Code...");
SetWatermark("promocode");
    if ('' != '') {
	    setfield("branch", "");
	    setfield("bookinguser", "");
    }
    setfield("adults-1", "2");
    setfield("children-1", "0");
    setfield("infants-1", "0");

    roomchange();
    updateoneway("N");
    updatescheduled2("N")
    flexigroupchange('from');
    flexigroupchange('to');
    updatejourneyoption("return");
    
if (!document.getElementById("noinitlist")) {
	dpinitlists(DefaultHolidaysCountry,DefaultHolidaysDestair,'','LGW','','','','','0');	
}
}
function HideABTAimage(Valuetext){
    if(Valuetext == "0")
    {
        Show("ShowABTAImage"); 
    }else{
        hide("ShowABTAImage");
    }
}
function SetWatermark(fieldname)
{
 var byId = document.getElementById(fieldname);
    var products = byId.style.color = "gray";

}
function roomchangeInfents(){

    var byId = document.getElementById("product");
    var products = byId.value;

    if (products == "hotel" || products == "flighthotel")
    {
       ShowHideInfents("none");

    }
}

function removejscssfile(filename, filetype){
 var removedelements=0
 var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist using
 var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
 var allsuspects=document.getElementsByTagName(targetelement)
 for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
  if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1){
   allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
   removedelements+=1
  }
 }
// if (removedelements>0)
// // alert("Removed "+removedelements+" instances of "+filename)
}

function IncludeJS(script_filename) {

removejscssfile("http://search.packyourbags.com/ssi/fusionsearches/12867.js", "js"); //remove all occurences of "12867.js" on page
removejscssfile("http://search.packyourbags.com/ssi/fusionsearches/12866.js", "js"); //remove all occurences of "12866.js" on page
removejscssfile("http://search.packyourbags.com/ssi/fusionsearches/12865.js", "js"); //remove all occurences of "12865.js" on page
removejscssfile("http://search.packyourbags.com/ssi/fusionsearches/12864.js", "js"); //remove all occurences of "12864.js" on page

var filename = "http://search.packyourbags.com/ssi/fusionsearches/"+ script_filename +".js";
include_dom(filename);
}

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
   //
   setTimeout("setDroupdownValues()",1000);
   // alert("JsFile Added");
    return false;
}
var count = 1;
function changeSubmitbuttontext(Altmessage)
{
    var btnsearchbutton = document.getElementById("searchbutton");
    btnsearchbutton.alt = "Find my " + Altmessage;
    switch(Altmessage)
    {
        case 'holiday':
            btnsearchbutton.src = "/images/homepage/Triveltek/Find-my-holidays.png";
        break;
        case 'hotel':  
            btnsearchbutton.src = "/images/homepage/Triveltek/Find-my-Hotel.png"; 
        break;
        case 'flight':
            btnsearchbutton.src = "/images/homepage/Triveltek/Find-my-Flight.png";
        break;
        case 'city break':
            btnsearchbutton.src = "/images/homepage/Triveltek/Find-my-city-break.png";
        break;
     }
}

function SetSearch(Searchtype)
{
var oForm = this.form;
  
    dpsearchtype('dest');

switch(Searchtype)
{
    case 'flighthotelpackage':
  
        setfield("sid", "12867");
        IncludeJS('12867');
        changeTabs('holidays');
        setfield("product", "flighthotelpackage");
        hide("TrTypeinyourdestination");
        Show("Trdepair");
        hide("returndate");
        ShowHideInfents("inline");
        Show("DivRatings");
        Show("divboard"); 
        hide("DivClass");
        hide("divAirline"); 
        hide("FlightMember"); 
        Show("RoomMember");
        Show("DivRoomcount");
        hide("Divpromocode");
        Show("PropertyName");
        HideFlightchildren(5);
        Show("Divnights"); 
        setfield("plusminus", "2");
        Show("DivplusminusDays");
        Show("ShowABTAImage");
        changeSubmitbuttontext("holiday");
       
      break;
      
    case 'hotel':
        setfield("sid", "12866");
        IncludeJS('12866');
        changeTabs('hotels');
        setfield("product", "hotel");     
        hide("returndate");
        Show("TrTypeinyourdestination");
        ShowHideInfents("none");
        Show("DivRatings");
        Show("divboard"); 
        hide("DivClass");
        hide("divAirline"); 
        hide("FlightMember"); 
        Show("RoomMember");
        Show("DivRoomcount");
        hide("Divpromocode");
        Show("PropertyName");
        HideFlightchildren(5);
        Show("Divnights"); 
        setfield("plusminus", "0");
        hide("DivplusminusDays");
        Show("ShowABTAImage");
        changeSubmitbuttontext("hotel");
      
     break;
     
    case 'flights':
        setfield("sid", "12865");
        IncludeJS('12865');
        changeTabs('flights');
        Show("Trdepair");
        setfield("product", "flight");
        Show("TrTypeinyourdestination");
        Show("returndate");
        ShowHideInfents("inline");
        hide("DivRatings");
        hide("divboard"); 
        Show("DivClass");
        Show("divAirline"); 
        Show("FlightMember"); 
        hide("RoomMember");
        hide("DivRoomcount");
        hide("Divpromocode");
        hide("PropertyName");
        hide("Divnights"); 
        setfield("plusminus", "0");
        hide("DivplusminusDays");
        Show("ShowABTAImage");
       changeSubmitbuttontext("flight");
        setfield("roomcount", "0");
          setfield("plusminus", "0");
      break;
      
    case 'flightsAndHotel':
        setfield("sid", "12864");
        IncludeJS('12864');
        changeTabs('flightsAndHotel');
        Show("Trdepair");
        hide("returndate");
        Show("TrTypeinyourdestination");
        setfield("product", "flighthotel");
        ShowHideInfents("none");
        Show("DivRatings");
        Show("divboard"); 
        hide("DivClass");
        hide("divAirline"); 
        hide("FlightMember"); 
        Show("RoomMember");
        Show("DivRoomcount");
        Show("Divpromocode");
        Show("PropertyName");
        Show("Divnights"); 
        HideFlightchildren(5);
        hide("DivplusminusDays");
        setfield("plusminus", "0");
        Show("ShowABTAImage");
        changeSubmitbuttontext("city break");

      break;
      
    default:
        setfield("sid", "12867");
        IncludeJS('12867');
        changeTabs('holidays');
        setfield("product", "flighthotelpackage");
        hide("TrTypeinyourdestination");
        Show("Trdepair");
        hide("returndate");
        ShowHideInfents("inline");
        Show("DivRatings");
        Show("divboard"); 
        hide("DivClass");
        hide("divAirline"); 
        hide("FlightMember"); 
        Show("RoomMember");
        Show("DivRoomcount");
        hide("Divpromocode");
        Show("PropertyName");
        HideFlightchildren(5);
        Show("Divnights"); 
        setfield("plusminus", "2");
        Show("DivplusminusDays");
        Show("ShowABTAImage");
        changeSubmitbuttontext("holiday");

    }   
    setform();
}

function setDroupdownValues()
{
var productType = document.getElementById("product");
var productTypeTxt = productType.value;

  switch(productTypeTxt)
    {
    case 'flighthotelpackage':
     Show("resort");   
     if (!document.getElementById("noinitlist")) {	     
	      dpinitlists(DefaultHolidaysCountry,DefaultHolidaysDestair,'','LGW','','','','','0');
        }
        
        dpchangecountry();
        dpchangedestination();
        dpchangedepair();
    break;
    case 'hotel':
       hide("Trdepair"); 
        Show("resort");   
     
       if (!document.getElementById("noinitlist")) {
	      dpinitlists(DefaultHotelsCountry,DefaultHotelsDestair,'','LGW','','','','','0');	
        }
       dpchangecountry();
       dpchangedestination();
  
     break;
    case 'flight':
      hide("resort");   
      
        dpinitlists(DefaultFlightsCountry,DefaultFlightsDestair,'','LGW','','','','','0');	
        dpchangecountry();
        dpchangedestination();
        dpchangedepair();
    
     break;
    case 'flighthotel':
      hide("resort");   
      if (!document.getElementById("noinitlist")) {
	       dpinitlists(DefaultCityBreaksCountry,DefaultCityBreaksDestair,'','LGW','','','','','0');	
        }
        dpchangecountry();
        dpchangedestination();
        dpchangedepair();
    break;
    }
setform();
}


function ShowHideInfents(Displaytype)
{
var byId = document.getElementById("roomcount");
var Roomcount = byId.value;
//alert( "ShowHideInfents : Displaytype:" + Displaytype);

for (i=1;i<=Roomcount;i++)
    {
      if (Displaytype == "none")
        {
            hide("div_infants-"+i);
        }else
        {
            Show("div_infants-"+i);
        }
    }
}

function hide(Id)
{
var byId = document.getElementById(Id);
    if(byId)
    {
        byId.style.display = 'none'; 
    }
}
function Show(Id)
{
var byId = document.getElementById(Id);
 if(byId)
    {
        byId.style.display = 'inline'; 
    }
}
function Show123(Id)
{
 var byId = document.getElementById(Id);
 if(byId)
    {
    byId.style.display = 'inline'; 
    }
}

function changeTabs(SelectedTab)
{
 var myArray=new Array(); // regular array (add an optional integer
    myArray[0]="holidays"; 
    myArray[1]="hotels"; 
    myArray[2]="flights"; 
    myArray[3]="flightsAndHotel"; 
 
    for (i=0;i<=3;i++)
    {
        var x=document.getElementById(myArray[i]);
        if (x.id== SelectedTab)
        {
            x.className = "selected smooth";
        }else
        {
             x.className = "not-selected smooth";
        }
    }
}
function HideFlightchildren(maxchildren){
    setfield("children", "0");
    showFlightchildren(maxchildren);	
}

function showFlightchildren(maxchildren) {
	// added 14/07/08 M.A. needed more than 5 in a room - sometimes
	if (maxchildren == null){
		maxchildren = 5;
	}

	if (document.getElementById("childlineFlight")) {
		for (i = 2; i <= maxchildren; i++) {

			hide("childtext-" + i);
			hide("childdrop-" + i);
		}

		for (i = 1; i <= document.getElementById("children").value; i++) {		
			if (i > 1) {
				Show("childtext-" + i);
				Show("childdrop-" + i);
			}
		}

		if (document.getElementById("children").value > 0) {			
			Show("Flightchildages");
		} else {
			hide("Flightchildages");
		}
	}
}

