var Graphic=_Gr={

	servData:{

		urlXml:"",

		weekdays:[],

		monthNames:[],

		depart:"",

		dateFormat:"",

		txtNoPrice:"",

		currencyPosition:"I",

		currency:"€"

	},
	
	numberOfTabs:5,

	type:"",

	account:"",

	totalAccount:"",

	lay:null,	

	departPrice:0,

	returnPrice:0, 

	percentageToBroke:80,

	rupturePrice:[],

	min:[],

	max:[],

	clickedDay:[],

	allDatedays:[],

	auxArrPrices:[],
	
	waitingAjax:false,

	

	setEstadisticsVals:function(obj,type){



		var arrPrices=[];

		var media=0;

		var rango=0;

		var rows=obj.getElementsByTagName("tbody")[0].getElementsByTagName("tr");

		var i=1;

		var auxMedia=0;

		var min=10000000;

		var max=0;

		_Gr.allDatedays[type]=[];

		if(_Gr.servData.dateFormat.split("/")[0]=="MM")
			var firstMonth = rows[0].getElementsByTagName("td")[0].firstChild.nodeValue.split("/")[0];
		else if(_Gr.servData.dateFormat.split("/")[1]=="MM")
		var firstMonth = rows[0].getElementsByTagName("td")[0].firstChild.nodeValue.split("/")[1];
		else if(_Gr.servData.dateFormat.split("/")[2]=="MM")
			var firstMonth = rows[0].getElementsByTagName("td")[0].firstChild.nodeValue.split("/")[2];

		for (var xx=0;xx<rows.length;xx++){

		

			var tds=rows[xx].getElementsByTagName("td")

			if (tds.length==4) {_Gr.allDatedays[type][_Gr.allDatedays[type].length]=tds[0]};



			i=parseInt(xx+1)

			var multiplePrice=parseInt(tds[0].getAttribute("rowspan"))

			var concretPrice=_Gr. getNumberPrice(tds[1].firstChild.nodeValue) 

	

			if(multiplePrice==2){

				var subPrice1=parseFloat(tds[1].firstChild.nodeValue)

				var subPrice2=parseFloat(rows[i].getElementsByTagName("td")[0].firstChild.nodeValue)

				concretPrice=(subPrice1<=subPrice2)? subPrice1:subPrice2;

				xx++

			}

			

			auxMedia+=parseFloat(concretPrice);

			arrPrices[arrPrices.length]=parseFloat(concretPrice);

			if(parseInt(concretPrice)<min) min=parseFloat(concretPrice)

			if(parseInt(concretPrice)>max) max=parseFloat(concretPrice)
			
			if(type==page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue){
				if(_Gr.servData.dateFormat.split("/")[0]=="MM")
					var month = tds[0].firstChild.nodeValue.split("/")[0];
				else if(_Gr.servData.dateFormat.split("/")[1]=="MM")
				var month = tds[0].firstChild.nodeValue.split("/")[1];
				else if(_Gr.servData.dateFormat.split("/")[2]=="MM")
					var month = tds[0].firstChild.nodeValue.split("/")[2];
					
				_Gr.numberOfTabs=month-firstMonth+1;
				if(_Gr.numberOfTabs<0)_Gr.numberOfTabs+=12
			}

		}

		

		

		media=auxMedia/arrPrices.length

		rango=max-min;

		

		var porc0_20=[]

		var porc21_40=[]

		var porc41_60=[]

		var porc61_80=[]

		var porc81_100=[]

		

		var lim1=min 

		var lim2=lim1 + rango/5

		var lim3=lim2 + rango/5

		var lim4=lim3 + rango/5

		var lim5=max

		

		var maxOfLim1=0;

		var maxOfLim2=0;

		var maxOfLim3=0;

		var maxOfLim4=0;

		var maxOfLim5=0;

		

		var auxMediaPercentajeToBroke=0;

		

		_Gr.auxArrPrices = arrPrices;

		for(var yy=0;yy<arrPrices.length;yy++){

			if(arrPrices[yy]<=lim1){

				porc0_20.push(parseInt(arrPrices[yy]))

				if(arrPrices[yy]>maxOfLim1) maxOfLim1=arrPrices[yy]

			}else if(arrPrices[yy]>=lim1 && arrPrices[yy]<lim2 ){

				porc21_40.push(arrPrices[yy])

				if(arrPrices[yy]>maxOfLim2) maxOfLim2=arrPrices[yy]

			}else if(arrPrices[yy]>=lim2 && arrPrices[yy]<lim3){

				porc41_60.push(arrPrices[yy])

				if(arrPrices[yy]>maxOfLim3) maxOfLim3=arrPrices[yy]

			}else if(arrPrices[yy]>=lim3 && arrPrices[yy]<lim4){

				porc61_80.push(arrPrices[yy])

				if(arrPrices[yy]>maxOfLim4) maxOfLim4=arrPrices[yy]

			}else if(arrPrices[yy]>=lim4 ){

				porc81_100.push(arrPrices[yy])

				if(arrPrices[yy]>maxOfLim5) maxOfLim5=arrPrices[yy]

			}	

		}

		

		var len=arrPrices.length

		var acum1=porc0_20.length*100/len 

		var acum2=acum1+ porc21_40.length*100/len

		var acum3=acum2+ porc41_60.length*100/len

		var acum4=acum3+ porc61_80.length*100/len

		var acum5=acum4+ porc81_100.length*100/len		

		var percent=_Gr.percentageToBroke;

		

		if(acum1>=percent)

			_Gr.rupturePrice[type]=maxOfLim1;

		else if(acum2>=percent)

			_Gr.rupturePrice[type]=maxOfLim2;

		else if(acum3>=percent)

			_Gr.rupturePrice[type]=maxOfLim3;

		else if(acum4>=percent)

			_Gr.rupturePrice[type]=maxOfLim4;

		else if(acum5>=percent)

			_Gr.rupturePrice[type]=maxOfLim5;

		else

			_Gr.rupturePrice[type]=max;

		

		_Gr.max[type]=max;

		_Gr.min[type]=min;

		_Gr.adjustBars(type);

		_Gr.arrPricesMin=arrPrices

	},

	adjustBars:function(type){

		var max = _Gr.getRupturePrice(type);

		var min = _Gr.getMinPrice(type);

		var rank = max-min;

		if(rank%4 == 1){

			_Gr.rupturePrice[type] += 3;}

		else if(rank%4 == 2){

			_Gr.rupturePrice[type] += 2;}

		else if(rank%4 == 3){

			_Gr.rupturePrice[type] += 1;}

	},

	getRupturePrice:function(type){return _Gr.rupturePrice[page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue];},

	getMinPrice:function(type){return _Gr.min[page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue]},

	getMaxPrice:function(type){return _Gr.max[page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue]},

	showPrice:function(value,currency,position,longPrices){

	   if (!page.$("auxaxis")){

		  var capa = dom.createElementWidthClass("div","transparente");

          capa.id = "auxaxis";

          capa.innerHTML = currency;

		  currency = capa.innerHTML;

        }else var capa = page.$("auxaxis");        

		if(longPrices) return value;     
		switch (position){

			case "D":return value+currency;break;

			case "I":return currency+value;break;

		}

	},

	addElements:function(obj,elements){for (var i=0;i<elements.length;i++) {obj.appendChild(elements[i])}},

	removeAllChildren:function(obj){if (obj) {for (var x=obj.childNodes.length-1;x>=0;x--){obj.removeChild(obj.childNodes[x])}}},

	addTotal:function(departPrice,returnPrice){

		var total=dom.createElementWidthClass("p","totalPrice")

		total.setAttribute("id","totalPrice")

		_Gr.totalAccount=(departPrice+returnPrice);

		_Gr.totalAccount=_Gr.totalAccount.round();

		_Gr.totalAccount=_Gr.totalAccount.toString().replace(".",",");

		

		var p=Graphic.servData.str3.replaceVars();

		total.innerHTML=p;

		_Gr.addElements(page.$("graphics"),[total]);

	},

	showGraph:function(){ 

		page.$("graphics").appendChild(_Gr.lay);

		if ((page.$("graphicsBack")) && (page.$("formGraphics").landingType.value == "1")){

			page.$("graphicsBack").appendChild(_Gr.lay);}

		},

	header:function(from,to,type,longPrices){

		var header=dom.createElementWidthClass("p","titular")

		_Gr.type=type;

		var p=Graphic.servData.str2.replaceVars();



		var prg=p + " " + from + "- " +to;

		header.innerHTML=prg;
		if (longPrices){
			var leyend=dom.createElementWidthClass("p","leyenda")
			leyend.innerHTML=page.$("formGraphics").currencyMessage.value + " <strong>"+Graphic.servData.currency+"</strong>";
			
			var head=dom.createElementWidthClass("div","head")
			head.appendChild(header)
			head.appendChild(leyend)
			return head;	
		}
			return header;	

	},
	tabs:function(type,data,date){



		var list=dom.createElementWidthClass("ul","pestanyas clearfix")

		var actualMonth=date.getMonth();
		
		if(_Gr.numberOfTabs<3)_Gr.numberOfTabs=3;
		for (var i=0;i<=_Gr.numberOfTabs-1;i++){

			var element=document.createElement("li");
			element.tabIndex=0;
			switch(i){

				case 0:element.className="sel";break;

				case _Gr.numberOfTabs-1:element.className="last";break;

				default:;

			}
			element.style.width=(591/_Gr.numberOfTabs)+"px";
			
			var text=Calendar.servData.shortMonths[actualMonth];

			var newMonth=actualMonth+1;

			if (newMonth>11) {newMonth=0;}

			if (i==0){

				var nextMonth=actualMonth+1;

				if (nextMonth>11) {nextMonth=0;}

				var endDate=new Date(date.getFullYear(),date.getMonth(),date.getDate()+30);

				if (endDate.getMonth()!=date.getMonth()) {text+="/"+Calendar.servData.shortMonths[newMonth];}			

				var tabId=type+"tab"+Gdate.dateToString(date,_Gr.servData.dateFormat).split("/").join("_");

			}

			else {

				var tabId=type+"tab"+Gdate.dateToString(new Date(date.getFullYear(),date.getMonth()+i,1),_Gr.servData.dateFormat).split("/").join("_");

			}

			element.setAttribute("id",tabId);

			element.appendChild(document.createTextNode(text));

			actualMonth++;

			if (actualMonth>11) {actualMonth=0;}			

			element.onclick=function(){_Gr.selectTab(this,type,data);}	
			element.onkeypress=function(event){if(event.keyCode==13)_Gr.selectTab(this,type,data); }			

			list.appendChild(element);

		}		

		return list;

	},
	selectTab:function(element,type,data){
		var aux=element.id.replace(type+"tab","").split("_");

		if (_Gr.servData.dateFormat == "dd/MM/yyyy") _Gr.fillData(element.parentNode.parentNode,new Date(aux[2],parseInt(aux[1]-1),parseInt(aux[0])),data,_Gr.getFirstDay(data),type);

		if (_Gr.servData.dateFormat == "MM/dd/yyyy") _Gr.fillData(element.parentNode.parentNode,new Date(parseInt(aux[2]),parseInt(aux[0]-1),aux[1]),data,_Gr.getFirstDay(data),type);

		var nodes=element.parentNode.childNodes;

		for (var node=0;node<nodes.length;node++){

			nodes[node].className=nodes[node].className.replace("sel","");

			nodes[node].className=nodes[node].className.replace("prevSel","");

		}

		element.className+=" sel";

		if (element.previousSibling) {element.previousSibling.className="prevSel"}
	},

	axis:function(data,type,longPrices){

		var thelay=dom.createElementWidthClass("div","values")

		var pr=_Gr.getRupturePrice(type)

		var min=_Gr.getMinPrice(type)

		var rank = pr-min

		var interval=rank/4

		var miarr=[];

			for (var i=0;i<5;i++){

				var num=document.createElement("span");

				miarr.push(Math.round(pr-interval*i))

				if (i == 0){

					auxNum=num;

					num.className="max";

					var txt=document.createTextNode(_Gr.showPrice(Math.round(pr-interval*i),_Gr.servData.currency,_Gr.servData.currencyPosition,longPrices));

				 num.appendChild(txt);

					thelay.appendChild(num);

				}

				

			}

			var conta=0;

			for (var i=1;i<5;i++){

				if ((miarr[i] != miarr[i+1]) && (miarr[i-1] != miarr[i])){

				

					conta++;

					var num=document.createElement("span");

					var txt=document.createTextNode(_Gr.showPrice(Math.round(pr-interval*i),_Gr.servData.currency,_Gr.servData.currencyPosition,longPrices));

					num.appendChild(txt);

					thelay.appendChild(num);

				}

			}

		

		if (conta == 0){ 

			auxNum.className="move"

		}

		var thelay1=dom.createElementWidthClass("div","clearfix")

		var barsZone= dom.createElementWidthClass("div","bars");

		thelay1.appendChild(thelay);

		thelay1.appendChild(barsZone);

		

		return thelay1;

	},

	searchDay:function(day,data,type){ 

		for (var j=0;j<_Gr.allDatedays[type].length;j++){

			if (_Gr.allDatedays[type][j].firstChild.data==day){return _Gr.allDatedays[type][j]}

		}		

		return null;

	},	

	getNextRow:function(objDate){

		var rows=objDate.parentNode.parentNode.getElementsByTagName("tr");

		var aux;

		for (var r=0;r<rows.length;r++){

			if (objDate.firstChild.data==rows[r].getElementsByTagName("td")[0].firstChild.data) {return rows[r+1]}	

		}	

	},	

	createHint:function(objDate,origin,destination,type){

		var tip="";

		if (objDate){

		

			tip+=objDate.firstChild.data+" ";

			tip+=origin+"-"+destination+"<br/>";

			var prices=new Array(objDate.parentNode.getElementsByTagName("td")[1]);

			if (objDate.getAttribute("rowspan")>1) prices[prices.length]=_Gr.getNextRow(objDate).getElementsByTagName("td")[0]; 

			for (var n=0;n<prices.length;n++){

				tip+="<p class=\"clearfix\"><span class=\"precio\">"+prices[n].firstChild.data+"</span><span class=\"hora\">";

				var hours=prices[n].parentNode.getElementsByTagName("li");

				tip+=type;
				
				tip+=" ";

				for (var m=0;m<hours.length;m++){m<hours.length-1?tip+=hours[m].firstChild.data+" h, ":tip+=hours[m].firstChild.data+"h";}

				tip+="</span></p>";

			}

		}	

		return tip;

	},

	showHint:function(obj){

		obj.hint.style.left=xy._x-xy.getX(obj.parentNode)+8+"px";

		obj.hint.style.top=xy._y+page.YOffset()-xy.getY(obj.parentNode)+"px";

		obj.parentNode.appendChild(obj.hint);		

	},

	moveHint:function(obj){

		obj.hint.style.left=xy._x-xy.getX(obj.parentNode)+8+"px";

		obj.hint.style.top=xy._y+page.YOffset()-xy.getY(obj.parentNode)+"px";

	},

	hideHint:function(obj){

		if (obj.hint.parentNode==obj.parentNode){obj.parentNode.removeChild(obj.hint);}

	},

	selectedPrice:function(value,type){ 

		var price=dom.createElementWidthClass("p","selectedPrice")

		_Gr.type=type;

		_Gr.account=value;

		var p=Graphic.servData.str1.replaceVars();

		price.innerHTML=p

		return price;

	},

	getNumberPrice:function(data){

		var auxPrice=data.replace(",",".")

		if(isNaN(auxPrice) && _Gr.servData.currencyPosition=="I"){auxPrice=auxPrice.split(" ")[1]}

		return parseFloat(auxPrice)

	},

	createBar:function(n,obj,type,vMin,vMax,data){



		var thelay=document.createElement("span");
		thelay.tabIndex=0;
		thelay.style.left=7+19*n+"px"; 

		var minPrice;

		obj ? minPrice = _Gr. getNumberPrice(obj.parentNode.getElementsByTagName("td")[1].firstChild.data): minPrice = 0;

		

		if( obj.parentNode.getElementsByTagName("td")[0].getAttribute("rowspan")==2){

			var p1=_Gr. getNumberPrice(obj.parentNode.getElementsByTagName("td")[1].firstChild.nodeValue)

			var x=obj.parentNode.nextSibling;

			while (x.nodeType!=1 && x.nodeName!="tr"){

				x=x.nextSibling;

			}

			var p2=_Gr. getNumberPrice(x.getElementsByTagName("td")[0].firstChild.nodeValue)

			minPrice=(p1>p2)? p2:p1;

		}

		var vMaxMin=(vMax==vMin)? 5:(vMax-vMin)

		

		minPrice >0 ? valor=parseInt((minPrice-vMin)*(92/vMaxMin) + 22 ): valor = 0 ;

		thelay.setAttribute("id",type+"barra"+obj.firstChild.data.split("/").join("_"));

		

		var messCount=dom.getElementsByClassName(page.$("dates"),"span","data ftl");

		if (type == page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue){

			var envType=messCount[0].firstChild.nodeValue;

			thelay.hint=Widget.toolTip(215,_Gr.createHint(obj,page.$("from").firstChild.nodeValue, page.$("to").firstChild.nodeValue,envType),"hint");

		}

		else if (type == page.$("dates").getElementsByTagName("span")[3].firstChild.nodeValue) {

			envType=messCount[1].firstChild.nodeValue;

			thelay.hint=Widget.toolTip(215,_Gr.createHint(obj,page.$("to").firstChild.nodeValue, page.$("from").firstChild.nodeValue,envType),"hint");

		}

		thelay.price=minPrice;

		thelay.type=type;

		

		if (Math.floor(minPrice)>Math.floor(vMax)){

			thelay.className="outLimit";

		}else{

			if (valor==0){thelay.className="vacio"};

			if (Math.floor(minPrice)<=Math.floor(vMin)){thelay.className="bestPrice"};

			if(Math.floor(valor) >= 0)
			{
				thelay.style.height=Math.floor(valor) + "px";
			}
			else
			{
				thelay.style.height="0px";
			}

		}

		

		thelay.type=type

		

		thelay.onmouseover=function(){_Gr.overInAFly(thelay)}

		thelay.onmousemove=function(){_Gr.moveInAFly(thelay)}

		thelay.onmouseout=function(){_Gr.outInAFly(thelay)}

		thelay.onclick=function(){_Gr.clickInAFly(thelay,type,this)}

		thelay.onkeypress=function(event){if(event.keyCode==13)_Gr.clickInAFly(thelay,type,this) }

		return thelay;

	},	

	overInAFly:function(ox){

		if(ox!=null){

			_Gr.showHint(ox);

			var layRollOver= dom.createElementWidthClass("span","rollOver") 

			layRollOver.style.left=(parseInt(ox.style.left)-2)+"px"

			ox.parentNode.insertBefore(layRollOver,ox.parentNode.childNodes[0]);

		}

	},

	moveInAFly:function(ox){

		if(ox!=null){_Gr.moveHint(ox);}

	},

	outInAFly:function(ox){

		if(ox!=null){

			_Gr.hideHint(ox);

			if (ox.parentNode.childNodes[0].className=="rollOver"){

				ox.parentNode.removeChild(ox.parentNode.childNodes[0])				

			}

		}

	},	

	clickInAFly:function(ox,type,dayObj){

		

		var thelay=ox

		var auxIdTxt=(ox==null)? dayObj.id.split("dayElement")[1]:ox.id.split("barra")[1];

		page.$("formGraphics").departureDate.value = auxIdTxt.replace(/_/gi, "\/")

		var date=page.$("formGraphics").departureDate.value.split("/");

	

		var price=(thelay!=null)? thelay.price:0;

		page.$("formGraphics").outwardFlightPrice.value = price;		

		

		if(_Gr.clickedDay[type][0]!=null){

			_Gr.clickedDay[type][0].className=_Gr.clickedDay[type][0].className.replace("selected","");

			if(_Gr.clickedDay[type][1]!=null){

				_Gr.clickedDay[type][1].className=_Gr.clickedDay[type][1].className.replace("selected","");

			}

		}

		if(thelay!=null){

			for (var i=0;i<thelay.parentNode.childNodes.length;i++){

				thelay.parentNode.childNodes[i].className=thelay.parentNode.childNodes[i].className.replace("selected","");

			}

			thelay.className+=" selected";

			if (thelay.className.indexOf("outLimit")==-1) {thelay.style.backgroundImage="none";}

			var day=thelay.id.replace(type+"barra","");

			if(_Gr.lay.childNodes.length>2){

				for (var i=0;i<_Gr.lay.childNodes[3].childNodes.length;i++){

					if(thelay.parentNode.parentNode.parentNode.childNodes[3].childNodes[i]) thelay.parentNode.parentNode.parentNode.childNodes[3].childNodes[i].className=thelay.parentNode.parentNode.parentNode.childNodes[3].childNodes[i].className.replace("selected","");

					else thelay.parentNode.parentNode.parentNode.childNodes[3].className=thelay.parentNode.parentNode.parentNode.childNodes[3].className.replace("selected","");

				}

			}

		

			if (thelay.parentNode.parentNode.parentNode.childNodes[5]) {thelay.parentNode.parentNode.parentNode.removeChild(thelay.parentNode.parentNode.parentNode.childNodes[5])}

			thelay.price=price.round();

		

			_Gr.addElements(thelay.parentNode.parentNode.parentNode,[_Gr.selectedPrice(thelay.price.toString().replace(".",","),type)]);			

			if (page.$("totalPrice")) {page.$("graphics").removeChild(page.$("totalPrice"));}

		}else{

			if(dayObj.parentNode.parentNode.childNodes[5])dayObj.parentNode.parentNode.removeChild(dayObj.parentNode.parentNode.childNodes[5])

			

			var noPrice=document.createElement("div")

			noPrice.id=type+"noPrice"

			noPrice.className="landingNoPrice"

			var txt=document.createTextNode(Graphic.servData.txtNoPrice)		

			noPrice.appendChild(txt)	

			_Gr.addElements(dayObj.parentNode.parentNode, [noPrice])

			dayObj.parentNode.parentNode.appendChild(noPrice)

			if (page.$("totalPrice")) {page.$("graphics").removeChild(page.$("totalPrice"));}

		}

		

		_Gr.clickedDay[type][0]=page.$(type+"dayElement"+auxIdTxt);

		_Gr.clickedDay[type][1]=(page.$(type+"barra"+auxIdTxt)==null)? null:page.$(type+"barra"+auxIdTxt);

	

		page.$(type+"dayElement"+auxIdTxt).className+=" selected";

	

		

		if (type == page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue) {

			if (page.$("formGraphics").landingType.value == "1" && thelay!=null){

				_Gr.load(page.$("dates").getElementsByTagName("span")[3].firstChild.nodeValue,"vuelta",_Gr.servData.urlXml);

			}

			

			_Gr.departPrice=price;

			_Gr.returnPrice=0

			if (_Gr.servData.dateFormat == "dd/MM/yyyy"){

				Calendar.returnSelection(parseInt(date[0],10),parseInt(date[1]-1,10),parseInt(date[2]),["diaSalida","mesAnioSalida","diaSalidaNmDia"])

			}					

			if (_Gr.servData.dateFormat == "MM/dd/yyyy"){

				Calendar.returnSelection(parseInt(date[1],10),parseInt(date[0]-1,10),parseInt(date[2]),["diaSalida","mesAnioSalida","diaSalidaNmDia"])

			}

							

		}else {	

		

			if(thelay!=null){	

				_Gr.returnPrice=thelay.price; 

				if(page.$("SalidanoPrice")==null && page.$("RegresonoPrice")==null) {

					_Gr.addTotal(_Gr.departPrice,_Gr.returnPrice)

				}

			}

			if (_Gr.servData.dateFormat == "dd/MM/yyyy"){

				Calendar.returnSelection(parseInt(date[0],10),parseInt(date[1]-1,10),parseInt(date[2]),["diaRegreso","mesRegreso","diaRegresoNmDia"])	

			}

			if (_Gr.servData.dateFormat == "MM/dd/yyyy"){	

				Calendar.returnSelection(parseInt(date[1],10),parseInt(date[0]-1,10),parseInt(date[2]),["diaRegreso","mesRegreso","diaRegresoNmDia"])	

			}				

		}	



		landing.shadowModule()

	},

	fillData:function(obj,start,data,graphicStart,type){

		

		var pr=_Gr.getRupturePrice(type)



		if (obj.childNodes[2]) _Gr.removeAllChildren(obj.childNodes[2].childNodes[1]);

		_Gr.removeAllChildren(obj.childNodes[3]);

		_Gr.removeAllChildren(obj.childNodes[4]);

		var limit=0;

			if ((start.getFullYear()==graphicStart.getFullYear()) && (start.getMonth()==graphicStart.getMonth()) && (start.getDate()==graphicStart.getDate()) ) {

			limit=31;		

			_Gr.addMonthsBars(obj,start,Gdate.daysDiff(start,new Date(start.getFullYear(),start.getMonth()+1,1)),_Gr.getFirstDay(data));

		}	

		else {

			limit=Gdate.dayMonth(start.getMonth(),start.getFullYear());

			_Gr.addMonthsBars(obj,start,limit,_Gr.getFirstDay(data));

		}

		var inter=0;

		

		for (var cont=0;cont<limit;cont++){

			

			var newDay=new Date(start.getFullYear(),start.getMonth(),start.getDate()+cont);	

			var objAux=_Gr.searchDay(Gdate.dateToString(newDay,_Gr.servData.dateFormat),data,type);



			if (objAux) {

				inter=1;

				_Gr.addElements(

					obj.childNodes[2].childNodes[1],

					[

						_Gr.createBar(cont,objAux,type,_Gr.getMinPrice(type),pr,data)

					]

				);

			}

	

			

			

			var el=document.createElement("li");

			el.style.cursor="pointer"

			

			el.setAttribute("id",type+"dayElement"+Gdate.dateToString(newDay,_Gr.servData.dateFormat).split("/").join("_"));

			el.appendChild(document.createTextNode(newDay.getDate()));

			if ((newDay.getDay()==6) || (newDay.getDay()==0)) {el.className="weekend"}

			_Gr.addElements(obj.childNodes[3],[el]);

				

			el.idbarra=type+"barra"+Gdate.dateToString(newDay,_Gr.servData.dateFormat).split("/").join("_")

			el.onmouseover=function(){_Gr.overInAFly(document.getElementById(this.idbarra))}

			el.onmousemove=function(){_Gr.moveInAFly(document.getElementById(this.idbarra))}

			el.onmouseout=function(){; _Gr.outInAFly(document.getElementById(this.idbarra))}

			el.onclick=function(){_Gr.clickInAFly(document.getElementById(this.idbarra),type,this)}					

				

		}	

		

		if (inter == 0){

			var cp=document.createElement("div");

			cp.className="noInfo";	

			var cp1=document.createElement("p");

			if(page.$("formGraphics").message) {

				var tt=page.$("formGraphics").message.value;

				var cpText=document.createTextNode(tt);

				cp1.appendChild(cpText);

			}

			cp.appendChild(cp1);

			var obj=dom.getElementsByClassName(page.$("graphics"),"div","bars");

			if (type == page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue) obj[0].appendChild(cp);

			else obj[1].appendChild(cp);

		}	

		

	},	

	addMonthsBars:function(obj,start,daysToNextMonth,graphicStart){

		

		var endMonthOn=new Date(start.getFullYear(),start.getMonth()+1,0);

		var c1=dom.createElementWidthClass("div","clearfix") 

		

		c1.style.marginLeft="6px";

		var c2=dom.createElementWidthClass("div","clearfix") 

		

		var w1=0;

		var d=new Date(start.getFullYear(),start.getMonth(),start.getDate()+30);

		w1=19*daysToNextMonth+35;

		var thelay=dom.createElementWidthClass("div","month selected ftl")

		thelay.style.width=w1+"px";

		var bar=dom.createElementWidthClass("div","bar")

		var contMonth=dom.createElementWidthClass("div","monthText ftl") 



		

		contMonth.style.paddingLeft=45+"px";

		contMonth.appendChild(document.createTextNode(_Gr.servData.monthNames[start.getMonth()]));

		thelay.appendChild(bar);

		c1.appendChild(thelay);

		c2.appendChild(contMonth);

		if ((endMonthOn.getMonth()!=d.getMonth())&&(graphicStart.getMonth()==start.getMonth())){

			var w2=625-w1-7-5;

			

			var thelay=dom.createElementWidthClass("div","month ftr") 

			thelay.style.border="1px solid #ccc"

			thelay.style.height="6px"

			

			var bar=dom.createElementWidthClass("div","month ftr") 

			

			thelay.style.width=w2+"px";

			var newMonth=start.getMonth()+1;

			if (newMonth>11) newMonth=0;

			thelay.appendChild(bar);

			

			var contMonth=dom.createElementWidthClass("div","monthText ftr")  

			

			contMonth.appendChild(document.createTextNode(_Gr.servData.monthNames[newMonth]));

			c1.appendChild(thelay);

			c2.appendChild(contMonth)

		}

		_Gr.addElements(obj.childNodes[4],[c1,c2]);

	},	

	getFirstDay:function(obj){return Gdate.stringToDate(obj.getElementsByTagName("td")[0].firstChild.data,_Gr.servData.dateFormat);},	

	addPreloader:function(){
		
		if(page.$("preloader"))page.$("preloader").style.display="block";
		else{

			var thelay=document.createElement("div");
	
			thelay.setAttribute("id","preloader");
	
			var image=document.createElement("img");
	
			image.setAttribute("src","/ibcomv3/images/indicator.gif");
	
			image.setAttribute("alt","");
	
			thelay.appendChild(image);
	
			page.$("graphics").appendChild(thelay);
		}

	},

	removePreloader:function(){

		page.$("graphics").removeChild(page.$("preloader"))

	},	

	loadFromXML:function(type,urlData){
		
		if (_Gr.waitingAjax) return;
		
		_Gr.rupturePrice[type]=0

		_Gr.addPreloader();

		if (dom.getElementsByClassName(page.$("graphics"),"div","graphic")[1]){

			page.$("graphics").removeChild(dom.getElementsByClassName(page.$("graphics"),"div","graphic")[1]);

		}

		

		var strSession=(ClientSession.getBVsession()==null ||ClientSession.getBVengenie()==null )? "":"&BV_SessionID="+ClientSession.getBVsession()+"&BV_EngineID="+ClientSession.getBVengenie();		

		var formData=page.$("formGraphics");

		var landingId=(formData.landingId)? formData.landingId.value:null;

		var origen=(formData.origin)? formData.origin.value:null;

		var destino=(formData.destiny)? formData.destiny.value:null;

		var departureDate=(formData.departureDate)? formData.departureDate.value:null;

		var outwardFlightPrice=(formData.outwardFlightPrice)? formData.outwardFlightPrice.value:null;

		var market=(formData.marketGraph)? formData.marketGraph.value:null;

		var language=(formData.languageGraph)? formData.languageGraph.value:null;

	

		var sep=url.str2concat(urlData)

		var newUrlData=urlData.replace(/&amp;/g, "&")

		

		var objGraph=objAjax.create();

		objGraph.abort()

		_Gr.waitingAjax=true;

		objGraph.open('GET', newUrlData+sep + 'landingId='+landingId+'&origen='+origen+'&destino='+destino+'&departureDate='+departureDate+'&outwardFlightPrice='+outwardFlightPrice+'&market='+market+'&language='+language +strSession, true);
		
		objGraph.onreadystatechange = function(){

		 if (objGraph.readyState == 4){

				if (objGraph.status == 200){	
				
					_Gr.waitingAjax=false;

					_Gr.init(type,objGraph.responseXML);

					_Gr.removePreloader();

					landing.shadowModule(); 

				}

			}	

		}

		objGraph.send(null);

	
	},	

	init:function(type,data){

		_Gr.setEstadisticsVals(data,type)

		_Gr.clickedDay[type]=[]

		var capa = dom.createElementWidthClass("div","transparente");
        capa.innerHTML = this.rupturePrice[type]+_Gr.servData.currency;
		var longPrices = capa.innerHTML.length > 5
		
		if (type == page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue){

			_Gr.addElements(

				_Gr.lay,

				[_Gr.header(page.$("from").firstChild.nodeValue,page.$("to").firstChild.nodeValue,type,longPrices),

				_Gr.tabs(type,data,_Gr.getFirstDay(data)),

				_Gr.axis(data,type,longPrices),

				dom.createElementWidthClass("ul","daysList clearfix"),

				dom.createElementWidthClass("div","months clearfix")]

			);

		}

		else{

			_Gr.addElements(

				_Gr.lay,
				[_Gr.header(page.$("to").firstChild.nodeValue,page.$("from").firstChild.nodeValue,type,longPrices),
				_Gr.tabs(type,data,_Gr.getFirstDay(data)),

				_Gr.axis(data,type,longPrices),

				dom.createElementWidthClass("ul","daysList clearfix"),

				dom.createElementWidthClass("div","months clearfix")]

			);

		}

		_Gr.fillData(_Gr.lay,_Gr.getFirstDay(data),data,_Gr.getFirstDay(data),type);

		_Gr.showGraph();	

		

	},

	load:function(type, typeFly, data){ 

		_Gr.rupturePrice[type]=0

		var graphLyr=dom.createElementWidthClass("div","graphic clearfix")

		ev.addEvent(document,"mousemove",xy.trackMouse);

		_Gr.lay=graphLyr;		

		graphLyr.type=type;

		typeof(data)=="object"?_Gr.init(type,data):_Gr.loadFromXML(type,data);

	

		landing.shadowModule();  

	}	

}



ev.addEvent(

	window,

	"load",

	function(){

		_Gr.load(page.$("dates").getElementsByTagName("span")[0].firstChild.nodeValue,"ida",page.$("graphics").getElementsByTagName("table")[0].parentNode);

		if (page.$("formGraphics").landingType.value != "1"){

			_Gr.load(page.$("dates").getElementsByTagName("span")[3].firstChild.nodeValue,"vuelta",page.$("graphicsBack").getElementsByTagName("table")[0].parentNode);

		}

		//ClientSession.load();

	},

	false

)

