/* @Author : Tosom s.r.l. @version : 1.0 @notes : Js for handling cruises cookie. */ /* @params : cval => string: reserach raw datas type => int [0,1] : if advanced search changes the ordering function type field => string:orderding field @returns : array[0] => string with converted datas array[1] => id of the first panel */ function cookieValToHtml( cval , type , field ) { cval = unescape(cval); var xml = false; if (window.DOMParser) { parser=new DOMParser(); xml=parser.parseFromString(cval,"text/xml"); } else // Internet Explorer { xml=new ActiveXObject("Microsoft.XMLDOM"); xml.async="false"; xml.loadXML(cval); } if(!xml) return "ERROR 003"; var root = xml.documentElement; var ord = root.getAttribute("order") ; if( field ) ord = field; var comps = root.getElementsByTagName("company") ; if( !comps || comps.length <=0 ) { return "ERROR: 004";} var labels = "" ; var labelsNo = "" ; var boxes = "" ; var node = null ; var cruises = null ; var cabins = null ; var tmp = null ; var bttn_class = "" ; var bttn_events = "" ; var bttn_style = "" ; var totCruises = 0 ; var firstBox = null ; var firstBoxLoad = null ; var selCruise = null ; var dbg ="" ; // Force the correct value into the type var, avoid type=-1,4,asd and so on if( type==1 ) type = 1 ; else type = 0 ; for(var i= 0 ; i" ; totCruises = 0 ; if(tmp>0) { if( !firstBoxLoad ) firstBoxLoad = node.getAttribute('label'); cdetNO = cruises.getElementsByTagName("cruise") ; var tmp2 = null; var cfields = null; var tblCont = "" ; var print = true ; var tdc = "" ; var tmpStr = "" ; var acts = "" ; var icon = "" ; if(!field) field = "departure_date" // ORDER DATA cdet = orderBy( field , cdetNO , false ); for( var j=0 ; j0 ) print = true; else print = false; if( print ) { /* RUN ALL SUB DATA 0- code 1- dep date 2- dep port 3- arr date 4- arr port 5- min price 6- max price 7- itinerary -- ignore cabins 4 now */ var currDetail = "openCruiseDetails( '"+escape(node.getAttribute("type"))+"' , '"+escape(node.getAttribute("label"))+"' , '"+tmp2.getAttribute("code")+"')" ; cfields = new Array(); cfields[0] = tmp2.getAttribute("code"); cfields[1] = tmp2.getAttribute("departure_date") ? tmp2.getAttribute("departure_date") : " " ; cfields[2] = tmp2.getAttribute("departure_port") ? tmp2.getAttribute("departure_port") : " " ; cfields[3] = tmp2.getAttribute("arrival_date") ? tmp2.getAttribute("arrival_date") : " " ; cfields[4] = tmp2.getAttribute("arrival_port") ? tmp2.getAttribute("arrival_port") : " " ; cfields[5] = tmp2.getAttribute("cabins_min_price") ; cfields[6] = tmp2.getAttribute("cabins_max_price") ; cfields[7] = tmp2.getAttribute("itinerary") ; acts = "\"\"" //boxes += ""+cfields[0]+"" ; // Mark the selected cruise try{ //dbg = "Check "+pType+" , "+pLabel+" , "+pCode+""; if( pType && pLabel && pCode ) { //dbg += " OK-1 " ; if( pType == node.getAttribute("type") && pLabel == node.getAttribute("label") && pCode == cfields[0] ) { //dbg += " OK-2 " ; selCruise = "
" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "" ; selCruise += "
"+"Selected cruise"+""+node.getAttribute("name")+" - "+unescape(cfields[7])+""+"Min price"+" : € "+parseFloat(unescape(cfields[5])).toFixed(2)+"
" ; selCruise += ""+"Max price"+" : € "+parseFloat(unescape(cfields[6])).toFixed(2)+"
"+"Departure"+""+unescape(cfields[1])+" - "+unescape(cfields[2])+"
"+"Arrival"+""+unescape(cfields[3])+" - "+unescape(cfields[4])+"
" ; //selCruise = "Selected cruise"+" : ["+unescape(cfields[0])+"] "+unescape(cfields[7])+"
" ; //selCruise += "Departure"+" : "+"From"+" "+unescape(cfields[1])+" "+unescape(cfields[2]) ; //selCruise += "Itinerary"+" "+unescape(cfields[7])+" " ; } else {}//dbg += " FAIL-2 " ; } else {}//dbg += " FAIL-1 " ; }catch(e){ /*dbg= e ;*/ } tdc = "light"; if( totCruises%2==0 ) tdc = "dark"; tblCont +="" ; tblCont += ""+unescape(cfields[1])+"" ; tblCont += ""+unescape(cfields[2])+"" ; tblCont += ""+unescape(cfields[3])+"" ; tblCont += ""+unescape(cfields[4])+"" ; tblCont += "€ "+parseFloat(unescape(cfields[5])).toFixed(2)+"" ; tblCont += "€ "+parseFloat(unescape(cfields[6])).toFixed(2)+"" ; tblCont += ""+unescape(cfields[7])+"" ; //tblCont += ""+acts+"" ; tblCont +="" ; totCruises++ ; } } boxes += "
" boxes += "" ; if( selCruise ) boxes += "" ; boxes += "" ; //boxes += "" ; var arrowGreen = "\"\""; var arrowRed = "\"\""; var orderLabel = "Order" ; tmpStr = "" ; if( ord=="departure_date" ) { tmpStr = ""+arrowRed+"Departure date"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Departure date"+""; } boxes += "" ; tmpStr ="" ; if( ord=="departure_port" ) { tmpStr = ""+arrowRed+"Departure port"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Departure port"+""; } boxes += "" ; tmpStr = "" ; if( ord=="arrival_date" ) { tmpStr = ""+arrowRed+"Arrival date"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Arrival date"+""; } boxes += "" ; tmpStr = "" ; if( ord=="arrival_port" ) { tmpStr = ""+arrowRed+"Arrival port"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Arrival port"+""; } boxes += "" ; tmpStr = "" ; if( ord=="min_price" ) { tmpStr = ""+arrowRed+"Min price"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Min price"+""; } boxes += "" ; tmpStr = "" ; if( ord=="max_price" ) { tmpStr = ""+arrowRed+"Max price"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Max price"+""; } boxes += "" ; tmpStr = "" ; if( ord=="itinerary" ) { tmpStr = ""+arrowRed+"Itinerary"+""; tmpStr = ""+tmpStr+"" ; } else { tmpStr = ""+arrowGreen+"Itinerary"+""; } boxes += "" ; //boxes += "" ; boxes +="" ; boxes += tblCont ; boxes += "
"+"Displayed cruise"+" : "+node.getAttribute('name')+"
"+selCruise+"
CODE"+tmpStr+""+tmpStr+""+tmpStr+""+tmpStr+""+tmpStr+""+tmpStr+""+tmpStr+""+"Actions"+"
" ; } else { //labelsNo += ""+node.getAttribute('name')+" ("+tmp+")" ; //labels += ""+node.getAttribute('name')+" ("+tmp+")" ; var msg = unescape( cruises.getAttribute('message') ) ; if(!msg) msg = "No cruises found"; msg = "Warning"+": "+msg ; boxes += '

'; boxes += ''; boxes += ''; boxes += ''; boxes += ''; boxes += ''; boxes += '
 
'+msg+'
'; // boxes += '
'+unescape(cruises.getAttribute('message'))+'
'; boxes += '


'; } //icon = "\"\""; labels += "" ; labels += ""+node.getAttribute('name')+"
"; labels += ""+totCruises+""; labels += "
" ; /*labels += "" labels += "" ; labels += "" labels += "" labels += ""; labels += "" labels += "
"+icon+"" ; labels += node.getAttribute('name')+"
"; labels += ""+totCruises+"
"; labels += "
"; */ boxes += ""; }// end for companies labels = "
"+labels+"
 
" ; boxes = "
"+boxes+"
" ; if( firstBoxLoad ) firstBox = firstBoxLoad; return new Array( labels+boxes , firstBox ); } /* Data sorting function, uses bubble sort Used inside cookieValToHtml funct to reorder datas */ function orderBy( field , arr , debug ) { var swap = false ; var data = new Array(); var tmp1 = null; var tmp2 = null; var tmp3 = null; var curr = arr.length ; var out = new Array(); var str = "" ; var tmpField = "" ; if(debug) str = "[order by : "+field+" - "+curr+"]start is :
" ; // Copy the array for( var i=0 ; i"; else str += data[i].getAttribute(field)+"
"; }*/ } if(debug) str += "
" ; while( curr >0 ) { for( var i=0 ; i "+tmp2+" "+( ( tmp1 > tmp2 ) ? "Y": "N" ) +"
" ; if( tmp1 > tmp2 ) //SWAP !! { tmp3 = data[i] ; data[i] = data[i+1]; data[i+1] = tmp3 ; } } break; case "arrival_date" : tmp1 = data[i].getAttribute("arrival_date").split("/") ; tmp1 = tmp1[2]+"-"+tmp1[1]+"-"+tmp1[0] ; if(data[i+1]) { tmp2 = data[i+1].getAttribute("arrival_date").split("/") ; tmp2 = tmp2[2]+"-"+tmp2[1]+"-"+tmp2[0] ; //if(debug) // str += "arrival_date : "+i+" "+data[i+1]+" - "+tmp1+"> "+tmp2+" "+( ( tmp1 > tmp2 ) ? "Y": "N" ) +"
" ; if( tmp1 > tmp2 ) //SWAP !! { tmp3 = data[i] ; data[i] = data[i+1]; data[i+1] = tmp3 ; } } break; case "max_price" : case "min_price" : tmpField = "cabins_"+field tmp1 = data[i].getAttribute(tmpField) ; if( data[i+1] ) { tmp2 = data[i+1].getAttribute(tmpField) ; //if(debug) // str += "max/min_price : "+i+" "+data[i+1]+" - "+tmp1+" > "+tmp2+" "+( ( parseFloat(tmp1) > parseFloat(tmp2) ) ? "Y": "N" ) +"
" ; if( parseFloat(tmp1) > parseFloat(tmp2) ) //SWAP !! { tmp3 = data[i]; data[i] = data[i+1]; data[i+1] = tmp3 ; } } break; default : //str +=field; tmp1 = unescape(data[i].getAttribute(field)) ; if(tmp1) { tmp2 = data[i+1] if( tmp2 ) { tmp2 = unescape(tmp2.getAttribute(field)) ; if(debug) str += "default : "+i+" "+data[i+1]+" - "+tmp1+"> "+tmp2+" "+( ( tmp1 > tmp2 ) ? "Y": "N" ) +"
" ; var swap = ( ( tmp1 == tmp2 ) ? 0 : ( ( tmp1 > tmp2 ) ? 1 : -1 ) ); //str += tmp1+" "+tmp2+" = "+swap+"\n"; if( swap == 1 ) //SWAP !! { tmp3 = data[i] ; data[i] = data[i+1]; data[i+1] = tmp3 ; } } } else return arr; } } curr -= 1 ; } if(debug) { writePanel("debug" , "BUBBLE STORT TESTING :
"+str); } //if(str)alert(str); /*if(debug) { str += "
end is :
" ; for( var i=0 ; i"; else str += data[i].getAttribute(field)+"
"; } writePanel("debug" , "BUBBLE STORT TESTING :
"+str); }*/ return data; } function createCookie(name,value,hours) { // var maxDim = 3000 ; var expires ="" ; var cookieData = new Array(); var token = "" ; var p = "" ; var str = "" ; if (!hours || isNaN(hours) ) { hours = 48 ; } var date = new Date(); date.setTime( date.getTime()+(hours*3600000) ); //expires = "expires="+date.toGMTString() ; expires = date.toUTCString() ; value = encodeURIComponent(value); // if value is too big break cookie value into multiple cookies /* if( value.length>maxDim ) { var cnt = 0 ; do { token = value.substring( cnt*maxDim , (cnt*maxDim)+maxDim ) ; cookieData[cnt] = token ; p = name+"_"+cnt+"="+token+";"+expires+";path=/;domain=\"www.tosom.it\""; document.cookie = p ; str +="[ADDED COOKIE : "+name+"_"+cnt+"][ "+cnt*maxDim+" , "+( (cnt*maxDim)+maxDim )+" ]
" ; cnt ++ ; str += cnt*maxDim+" > "+value.length+" = "+( cnt*maxDim > value.length ? "Y" : "N" )+"\n"; } while( cnt*maxDim < value.length ) ; } else { cookieData[0] = value; p = name+"_0="+token+";"+expires+";path=/;domain=\"www.tosom.it\""; document.cookie = p ; str +="[ADDED COOKIE] :
"+p+"
" ; } */ p= name+"="+value+"; expires="+expires+"; path=/; domain=www.lovelycrociere.com"; document.cookie = p ; str += "[ADDED COOKIE] :
"+p+"
" ; //alert("NAME=>"+name+"\nVALUE=>"+value+"\nEXPIRES=>"+expires) //writePanel("debug" , str); } function readCookie(name) { /* var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null;*/ if (document.cookie.length>0) { c_start=document.cookie.indexOf(name + "="); if (c_start!=-1) { c_start=c_start + name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; } function ereaseCookie(name) { createCookie(name,"",-1); } var lastPanelId = null ; function handleSearchResultLabel(panelId) { var label = "company_label_"+panelId ; var box = "company_data_box_"+panelId ; if( lastPanelId!=null) { var last_label = "company_label_"+lastPanelId ; var last_box = "company_data_box_"+lastPanelId ; if( lastPanelId == panelId ) { /* changeClass( getId( last_label ) , "label_std bttn_flat_light_blue" ) ; hidePanel( last_box ) ; lastPanelId = null; return;*/ } else { changeClass( getId( last_label ) , "advs_cicon" ) ; hidePanel( last_box ) ; } } changeClass( getId(label) , "advs_cicon_selected" ) ; showPanel( box ); if( getId( box ) ) getId( box ).scrollTop = 0 ; lastPanelId = panelId ; } function openCruiseDetails( type , label , id ) { var searchParams = "" ; // alert(unescape(lastCruiseSearch)) try{ if( lastCruiseSearch ) { // Start xml parsing cval = unescape(lastCruiseSearch); var xml = false; if (window.DOMParser) { parser=new DOMParser(); xml=parser.parseFromString(cval,"text/xml"); } else // Internet Explorer { xml=new ActiveXObject("Microsoft.XMLDOM"); xml.async="false"; xml.loadXML(cval); } if(xml) { var root = xml.documentElement; // load search options node var so = root.getElementsByTagName("fields"); so = so.item(0) if(so) { // REAS SEARCHED OPTIONS ATTRIBUTES var cnt = 0 ; var istr = "" var curr =null; while( so.attributes[cnt] ) { curr = so.attributes[cnt]; searchParams += "&"+curr.nodeName+"="+escape(curr.value) ; cnt++; } } } } } catch(e){} var p = "type="+escape(type)+"&label="+escape(label)+"&cc="+escape(id)+searchParams ; window.location.href = "./cruise_details.html?"+p ; } function reorderSearch(field,type) { var cname = "lovely_last_search_cruises" ; var cval = "" ; var str = "" ; if(lastCruiseSearch) { //CREATE NEW OR RESET SEARCH COOKIE DATA // CONVERT COOKIE DATA cval = cookieValToHtml(lastCruiseSearch,type,field) ; // WRITE DATA str = cval[0]; if(!type || type==0) { writePanel( "search_cruise_tabled_data" , cval[0] ) ; showPanel( "company_data_box_"+lastPanelId ) ; } else { writePanel("adv_search_result" , cval[0] ); showPanel("adv_search_result") ; } handleSearchResultLabel(lastPanelId); } } function highlightTr( elem , classTo ) { if(elem.childNodes && elem.childNodes.length>0) { var tot = elem.childNodes.length for( var i=0 ; i0) { var tot = elem.childNodes.length for( var i=0 ; i