function setOptions(price) {
	if( $.trim($('#purchase_price').val()) != '' )	var PurchasePrice = $('#purchase_price').val().replace(',', '').replace('.', '');
	ParseUrl = getUrlVars();
			if( typeof(ParseUrl['PricePurchase']) != 'undefined' ) var PurchasePrice = ParseUrl['PricePurchase'];
	var options = {
			chart: {
				zoomType: 'x',
				spacingRight: 20,
				renderTo: 'containerHighcharts',
				type: 'area',
				//marginRight: 130,
				//marginBottom: 25
				  className: 'skies',
				  borderWidth: 0,
				  plotShadow: true,
				  plotBackgroundImage: '/intranetimages/coughlinteam/users/6882/skies.jpg',
				  //plotBackgroundImage: 'http://www.highcharts.com/demo/gfx/skies.jpg',
				  plotBackgroundColor: {
					 linearGradient: [0, 0, 250, 500],
					 stops: [
						[0, 'rgba(203, 213, 223, 1)'],
						[1, 'rgba(203, 213, 223, 0.5)']
					 ]
				  },
				  plotBorderWidth: 1
			},
			exporting: {
					type:"image/png",
					url:"https://export.highcharts.com/",
					buttons:{
						contextButton:{symbol:"menu",
						_titleKey:"contextButtonTitle",
						menuItems: [
						{
							textKey:"printChart",
							onclick:function(){this.print()}
						},
						{
							separator:!0
						},
						{
							textKey:"downloadPNG",
							onclick:function(){this.exportChart()}
						},
						{
							textKey:"downloadJPEG",
							onclick:function(){this.exportChart({type:"image/jpeg"})}
						},
						/*{
							textKey:"downloadPDF",
							onclick:function(){this.exportChart({type:"application/pdf"})}
						},*/
						{
							text:"Download GIF",
							onclick:function(){this.exportChart({type:"image/gif"})}
						},
						/*{
							textKey:"downloadSVG",
							onclick:function(){this.exportChart({type:"image/svg+xml"})}
						},*/
						{
							text:"Personalize",
							onclick:function(){$('#popup_box').fadeIn("slow");$('html, body').animate({scrollTop: $("#popup_box").offset().top}, 500);$('#personnalize_address').focus();}
						},
						{
							text: 'Save settings',
							onclick: function() {  
								ParseUrl = getUrlVars();
								var IdSummary;
								var AddressData;
								var Yr;
								var DatePurchase;
								var PricePurchase;
								if( typeof(ParseUrl['IdSummary']) == 'undefined') IdSummary = '';
								if( typeof(ParseUrl['AddressStr']) == 'undefined') AddressData = ( $.trim($('#personnalize_address').val()) != '' ? $.trim($('#personnalize_address').val()) : '' );
								else AddressData = ParseUrl['AddressStr'];
								if( typeof(ParseUrl['range']) == 'undefined') Yr = $('#CompareVal').val()/12;
								else Yr = ParseUrl['range'];
								if( typeof(ParseUrl['DatePurchase']) == 'undefined') DatePurchase = $('#purchase_month').val()+"-"+$('#purchase_year').val();
								else DatePurchase = ParseUrl['DatePurchase'];
								if( typeof(ParseUrl['PricePurchase']) == 'undefined') PricePurchase = $('#purchase_price').val().replace(',', '').replace('.', '');
								else PricePurchase = ParseUrl['PricePurchase'];
								var rows = $("#example").dataTable().fnGetNodes();
								var datatablesData = {};
								for(var i=0;i<rows.length;i++)
								{
									datatablesDataKey = false;
									// Get HTML of 3rd column (for example)
									$(rows[i]).find("td").each(function(td, val){
										if( !datatablesDataKey ) datatablesDataKey = $(val).html();
										else datatablesDataVal = $(val).html();
									});
									datatablesData[datatablesDataKey] = datatablesDataVal; 
								}
								data = {
										HashId: IdSummary, 
										Address: AddressData,
										Yr: Yr,
										DatePurchase: DatePurchase.replace('-',' / '),
										PricePurchase: "$ "+Highcharts.numberFormat(PricePurchase, 0,'.',','),
										datatablesDatadata: JSON.stringify(datatablesData)
								};
								var form = $('<form method="POST" action="/SaveDataToTable.php">');
								$.each(data, function(k, v) {
									form.append($('<input type="hidden" name="' + k +'" value=\'' + v + '\'>'));
								});
								$('body').append(form);
								var iOS = ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
								var android = navigator.userAgent.toLowerCase().match(/android/g) ? true : false;
								if (iOS || android)
								form.attr("target", "_blank");

								// Submit the form using JavaScript
								//$("#form_jsSubmit").submit();
								form.submit();
								form.remove();
								/*$.ajax({
									type: "POST",
									url: "/intranetimages/coughlinteam/users/6882/SaveDataToTable.php",
									data: {
										HashId: IdSummary, 
										Address: AddressData,
										Yr: Yr,
										DatePurchase: DatePurchase.replace('-',' / '),
										PricePurchase: "$ "+Highcharts.numberFormat(PricePurchase, 0,'.',','),
										datatablesDatadata: JSON.stringify(datatablesData)
									}, 
									success: function(data){
										alert(data);
									},
									error: function() {
										//$( "div#Loading" ).hide( "slow" );
										alert("An error occurred while processing your request.");
									}
								});*/

								//alert('Settings saved');
							}
						},
						{
							text: 'Email me ',
							onclick: function() { 
								$('#popup_email_box').show('slow');
								$('a#popupBoxClose1').click(function(){ $('#popup_email_box').hide('slow'); });
								$('#PersonnalizeReportEmail').click(function(){ 
									ParseUrl = getUrlVars();
									if( typeof($('#email_to').val()) == 'undefined' || $.trim($('#email_to').val()) == '' ) var Email = prompt("Please provide us your email address", '');
									else var Email = $('#email_to').val();
									var IdSummary;
									var AddressData;
									var Yr;
									var DatePurchase;
									var PricePurchase;
									if( typeof(ParseUrl['IdSummary']) == 'undefined') IdSummary = '';
									if( typeof(ParseUrl['AddressStr']) == 'undefined' || $.trim($('#personnalize_address').val()) != '' ) AddressData = ( $.trim($('#personnalize_address').val()) != '' ? $.trim($('#personnalize_address').val()) : '' );
									else AddressData = ParseUrl['AddressStr'];
									if( typeof(ParseUrl['range']) == 'undefined') Yr = $('#CompareVal').val()/12;
									else Yr = ParseUrl['range'];
									if( typeof(ParseUrl['DatePurchase']) == 'undefined') DatePurchase = $('#purchase_month').val()+"-"+$('#purchase_year').val();
									else DatePurchase = ParseUrl['DatePurchase'];
									if( typeof(ParseUrl['PricePurchase']) == 'undefined') PricePurchase = $('#purchase_price').val().replace(',', '').replace('.', '');
									else PricePurchase = ParseUrl['PricePurchase'];
									if( typeof(ParseUrl['DocumentID']) == 'undefined' ) DocumentID = '';
									else DocumentID = ParseUrl['DocumentID'];
									$.ajax({
										type: "POST",
										url: "/SaveDataToTable.php",
										/*dataType: "xml",*/
										data: {
											HashId: IdSummary, 
											Address: AddressData,
											Yr: Yr,
											DatePurchase: DatePurchase,
											PricePurchase: PricePurchase,
											Type: 'email',
											filename: $('#FirstFilenameSelected').val(),
											email: Email,
											DocumentID: DocumentID,
											emailfrom : $('#email_from').val(),
											Comment : $('#email_comments').val()
										}, 
										success: function(data){
											alert(data);
											$('#popup_email_box').hide('slow');
										},
										error: function() {
											//$( "div#Loading" ).hide( "slow" );
											alert("An error occurred while processing your request.");
											$('#popup_email_box').hide('slow');
										}
									});

									//alert('Settings saved');
								});
							}
						}
						]
					}
				}
			},
			tooltip: {
				style: {
					fontWeight: 'bold',
					fontSize: '16px',
				},
				followPointer: true,
				useHTML: true,
				formatter: function() {
						var s = Highcharts.dateFormat('%B %Y', this.x);
						var SamePrice = 0;
						var CurrentValueSerie = false;
						var chart = $('#containerHighcharts').highcharts();
						var series = chart.series;

						$.each(this.points, function(i, point) {
							//for( ttt in this.point) alert(ttt + " --- " +this.point[ttt]);
							//alert(this.series.name);
							//~ console.log(this.series.name);
							if( this.series.name == 'Red Line' )
							{
								return false;
							}
							if( this.series.name == 'Purchase date ' )
							{
								s = Highcharts.dateFormat('%B %Y', this.x) + '<br /><span style="color:' + this.series.color +'">' + this.series.name +'</span>: $ '+ Highcharts.numberFormat(this.y, 0,'.',',');
								return false;
							}
							else if( this.series.name == 'Current Value' )
							{
								if( typeof(PurchasePrice) == 'undefined' && price > 0 ) PurchasePrice = price;
								if( !CurrentValueSerie ) {
									//alert(PurchaseDateDiff);
									var CurrentValueDiff = new Date(Highcharts.dateFormat('%Y', this.x),parseInt(Highcharts.dateFormat('%m', this.x))-1 ,1);
									var testDate = new Date(Highcharts.dateFormat('%Y', this.x),parseInt(Highcharts.dateFormat('%m', this.x))-1 ,1);
									//alert(Highcharts.dateFormat('%B %Y', CurrentValueDiff));
									var LessDeprecation = 0.0006 * PurchasePrice * monthDiff(PurchaseDateDiff, CurrentValueDiff);
									var AdjustedHomeValue = PurchasePrice - LessDeprecation;
									//s1 = '<div style="width:380px"><div style="float:left;">Your Home Value</div><div style="float:right; text-align:right; margin-right:2px;">'+Highcharts.dateFormat('%B %Y', this.x)+ '</div>';/*Highcharts.dateFormat('%B %Y', this.x);*/ 
									//s1 = '<div style="width:380px"><div style="float:left;">'+Highcharts.dateFormat('%B %Y', this.x)+' Purchase Price </div><div style="float:right; text-align:right; margin-right:2px;">$ '+ Highcharts.numberFormat(PurchasePrice, 0,'.',',')+'</div>';
									s1 = '<div style="width:450px;"><div style="float:left;"><span style="font-weight:normal">'+PurchaseDateHighcharts+'</span> Purchase Price </div><div style="float:right; text-align:right; margin-right:2px;">$ '+ Highcharts.numberFormat(PurchasePrice, 0,'.',',')+'</div>';
									s1 += '<br /><div style="float:left; color:' + this.series.color +'">' + this.series.name +' <span style="font-weight:normal">(Unadjusted)</span> </div> <div style="float:right; text-align:right; margin-right:2px;">$ '+ Highcharts.numberFormat(this.y, 0,'.',',')+'</div>';
									s1 += '<br /><div style="float:left; padding-left:20px;">Less Depreciation (.8%/yr) </div> <div style="color:red;float:right; text-align:right; margin-right:2px;">-$ '+ Highcharts.numberFormat(LessDeprecation, 0,'.',',')+'</div>';
									s1 += '<br /><div style="float:left;"><span style="font-weight:normal">'+Highcharts.dateFormat('%B %Y', this.x)+'</span> Adjusted Home Value </div> <div style="float:right; text-align:right; margin-right:2px;">$ '+ Highcharts.numberFormat(this.y - LessDeprecation, 0,'.',',')+'</div>';
									s1 += '<br /><div style="margin-bottom:7px;"><div style="float:left; padding-left:20px;">Add Renovations </div> <div style="color:red;float:right; text-align:right; margin-right:2px;"><input type="text" id="AddRenovations" name="AddRenovations" style="background-color:#ffff00; border:#ccc solid 2px; width:100px;" /></div></div>';
									s1 += '<br /><div style="margin-bottom:7px;"><div style="float:left; padding-left:40px; font-weight:normal;font-size:14px; ">Home Display (+/-) </div> <div style="color:red;float:right; text-align:right; margin-right:2px;"><input type="text" id="LandUseChange" name="LandUseChange" style="background-color:#ffff00; border:#ccc solid 2px; width:100px;" /></div></div>';
									s1 += '<br /><div style="margin-bottom:10px;"><div style="float:left; padding-left:40px; font-weight:normal; font-size:14px;">Neighborhood Change (+/-) </div> <div style="color:red;float:right; text-align:right; margin-right:2px;"><input type="text" id="NeighborhoodChange" name="NeighborhoodChange" style="background-color:#ffff00; border:#ccc solid 2px; width:100px;" /></div></div>';
									//s1 += '<br /><div style="float:left;">Adjusted Home Value </div> <div style="float:right; text-align:right; margin-right:2px;">$ '+ Highcharts.numberFormat(this.y - LessDeprecation, 0,'.',',')+'</div>';
									s1 += '<br /><div style="float:left"><span style="font-weight:normal">'+Highcharts.dateFormat('%B %Y', this.x)+'</span> Realtor Adjusted Home Value </div> <div style="color:red;float:right; text-align:right; margin-right:2px;"><input type="text" id="ReatorLandUseChange" name="ReatorLandUseChange" style="background-color:#ffff00; border:#ccc solid 2px; width:100px;" /></div><br />';


									

									s1 += '</div>';
									s=s1;
								}
								else if( SamePrice != this.y ) { s1 += '<br /><div style="float:left; color:' + this.series.color +'">' + this.series.name +': </div><div style="float:right; text-align:right; margin-right:2px;">$ '+ Highcharts.numberFormat(this.y, 0,'.',',')+'</div>'; s = s1}
								if( CurrentValueSerie ) return s = s1;
								CurrentValueSerie = true;
								SamePrice = this.y;
							}
							else
							{
								//alert(this.series.index);
								var IndexSerie = ( (i > 0 && $.trim(filename2) != '') || (i == 0 && this.series.index > series.length/2) ) ? series.length/2 : 0 ;
								if( IndexSerie == 7.5 ) IndexSerie = 8;
								//~ console.log(IndexSerie);
								if( typeof(series[IndexSerie]) != 'undefined' )
								{
									var SerieName;
									if( !i && this.series.name == 'HPIp' ) SerieName = 'Home Price Index HPIp';
									else if( !i && this.series.name == 'Your Home History' ) SerieName = 'Your Home Price History';
									else if( !SerieName && !i ) SerieName = series[0].name;
									else if( $.trim(filename2) == '' ) SerieName = this.series.name;
									else if( $.trim(filename2) != '' ) SerieName = series[IndexSerie].name;
									//else SerieName = this.series.name;
									if( !i ) 
									{
										z = '<div style="float:right; text-align:right; margin-right:2px;">'+s+'</div>';
										s = '<div style="float:left;">'+SerieName+'</div>'+z;
									}
									if( i == 2 && $.trim(filename2) != '' ) 
									{
										s += '<br /><br /><div style="float:left;">'+series[IndexSerie].name+'</div>'+z;
									}
									if( this.series.name == 'HPIp' || this.series.name == 'Your Home History' )
									{
										s += '<br /><span style="color:' + this.series.color +'; display:inline-block; min-width:250px;">' + series[IndexSerie].name +'</span> $ '+ Highcharts.numberFormat(this.y, 0,'.',',') + this.percentage;
									}
									else
									{
										s += '<br /><span style="color:' + this.series.color +'; display:inline-block; min-width:250px;">' + this.series.name +'</span> $ '+ Highcharts.numberFormat(this.y, 0,'.',',') + this.percentage;
									}
								}
							}
						});
						return s;
				},
				shared: true,
			},
			title: {
				text: 'Powered by the Greater Vancouver Market Reports HPIp'
			},
	xAxis: {
	type: 'datetime',
	maxZoom: 14 * 24 * 3600000, // fourteen days
	tickInterval: 24 * 3600 * 31000 * 3, // one month
	title: {
		text: document.ontouchstart === undefined ?
			'<img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" />' : '<img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" />',/*Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in' :
			'Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in',*/
		style: {
			color: '#FF0000',
			font: 'bold 18px Helvetica',
		},
		useHTML:true,
	},
	labels: {
			rotation: -45,
			style: {
				font: '14px Helvetica',
			}

		}
	// categories: []
	},
	yAxis: {
		title: {
			text: ''
		},
		labels: {
			formatter: function () {
				return "$" + Highcharts.numberFormat(this.value, 0,'.',',');
			},
			style: {
				//color: '#4572A7',
				font: 'bold 14px Helvetica',
			},
		},
		gridLineWidth: 2,
		lineWidth:1,
	},
			legend: {
				align: 'top',
				verticalAlign: 'top',
				x: 0,
				y: 50,
				margin : 10,
				width: 907,
				useHTML: true,
				itemStyle: {
					fontWeight: 'bold',
					fontSize: '11px',
				},
				labelFormatter: function() {
					if( this.type == 'scatter' ) { return '<div style="width:250px; text-align:right; font-size: 12px;"><b>'+this.name+'</b></div>';}
					return this.name;
				}
			},
			plotOptions: {
				area: {
					fillColor: {
						linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
						stops: [
							/*[0, Highcharts.getOptions().colors[0]],
							[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]*/
							[0, 'rgba(208, 48, 85,0.5)'],
							[1, 'rgba(208, 48, 85,0)']										
						]
					},
					lineWidth: 1,
					marker: {
						enabled: true
					},
					shadow: false,
					states: {
						hover: {
							lineWidth: 1
						}
					},
					threshold: null
				},
				series: {
					events: {
						legendItemClick: function(event) {
							var seriesIndex = this.index;
							var series = this.chart.series;
							var TwoFile = 0;
							for (var i = 0; i < series.length; i++)
							{
								if( series[i].type == 'scatter' ) TwoFile++;
							}
							if( seriesIndex == 0 || ( seriesIndex == series.length/2 && TwoFile == 2 ) )
							{
								var limitSeries = (TwoFile == 2 ? series.length/2 : series.length);
								//alert(limitSeries);
								for (var i = 0; i < limitSeries; i++)
								{
									var j = i + seriesIndex;
									if (series[j].index != seriesIndex)
									{
										series[seriesIndex].visible ? series[j].hide() : series[j].show();
									} 
								}
							}
							if (!this.visible)	return true;
							
							series[this.index].hide();

							return false;
						}
					}
				}
				
			},
			series: []
	};
	return options;
}

function ManageGraph(filename, DatePurchase, Forcast_Positiv, Forcast_Minus, period, price, filename2) {
	//alert(filename2);
	var options = setOptions(price);
	var dataTableVal = new Array();
	var currentYear = (new Date).getFullYear();
	var PurchasePrice = price;
	DatePurchase = decodeURIComponent(DatePurchase);
	//alert(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+period+'&value='+price);
	
	$.get(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase.split("-").join(" - ")+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+period+'&value='+price, function(xml) {
		
		//var chart = $('#containerHighcharts').highcharts();	//alert(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+this.id+'&value='+price);

		// Split the lines
		var HPlp = 0;
		var $xml = $(xml);

		$xml.find('default').each(function(i, defaultValue) {
		price = $(defaultValue).text();
		});
		var FirstDate = $xml.find('categories item')[0];
		var LastDate = $xml.find('categories item').last();
		var LastMonth = $(LastDate).text();
		var MonthToday = LastMonth.substring(0,3);
		var YearToday = LastMonth.slice(-2);
		var DataTableDateStop = MonthToday +" "+currentYear;
		var DataTableContinue = true;

		if( MonthToday == 'Jan' ) MonthToday = 0;
		else if( MonthToday == 'Feb' ) MonthToday = 1;
		else if( MonthToday == 'Mar' ) MonthToday = 2;
		else if( MonthToday == 'Apr' ) MonthToday = 3;
		else if( MonthToday == 'May' ) MonthToday = 4;
		else if( MonthToday == 'Jun' ) MonthToday = 5;
		else if( MonthToday == 'Jul' ) MonthToday = 6;
		else if( MonthToday == 'Aug' ) MonthToday = 7;
		else if( MonthToday == 'Sep' ) MonthToday = 8;
		else if( MonthToday == 'Oct' ) MonthToday = 9;
		else if( MonthToday == 'Nov' ) MonthToday = 10;
		else if( MonthToday == 'Dec' ) MonthToday = 11;

		var YearToday2 = '20'+YearToday;

		var FirstMonth = $(FirstDate).text();
		var Month = FirstMonth.substring(0,3);
		var Year = FirstMonth.slice(-2);
		var ArrayMonth = new Array();
		if( Month == 'Jan' ) Month = 0;
		else if( Month == 'Feb' ) Month = 1;
		else if( Month == 'Mar' ) Month = 2;
		else if( Month == 'Apr' ) Month = 3;
		else if( Month == 'May' ) Month = 4;
		else if( Month == 'Jun' ) Month = 5;
		else if( Month == 'Jul' ) Month = 6;
		else if( Month == 'Aug' ) Month = 7;
		else if( Month == 'Sep' ) Month = 8;
		else if( Month == 'Oct' ) Month = 9;
		else if( Month == 'Nov' ) Month = 10;
		else if( Month == 'Dec' ) Month = 11;
//alert(DatePurchase);
//alert();
		var datesUrlTable = DatePurchase.split("-");
		//var MonthSelected = $('#purchase_month').val();
		var MonthSelected = datesUrlTable[0];
		var yearPurchase = parseInt('20'+datesUrlTable[1]);
		//alert(DatePurchase + '   ' +MonthSelected+'   '+yearPurchase);
		if( MonthSelected == 'Jan' ) MonthSelected = 0;
		else if( MonthSelected == 'Feb' ) MonthSelected = 1;
		else if( MonthSelected == 'Mar' ) MonthSelected = 2;
		else if( MonthSelected == 'Apr' ) MonthSelected = 3;
		else if( MonthSelected == 'May' ) MonthSelected = 4;
		else if( MonthSelected == 'Jun' ) MonthSelected = 5;
		else if( MonthSelected == 'Jul' ) MonthSelected = 6;
		else if( MonthSelected == 'Aug' ) MonthSelected = 7;
		else if( MonthSelected == 'Sep' ) MonthSelected = 8;
		else if( MonthSelected == 'Oct' ) MonthSelected = 9;
		else if( MonthSelected == 'Nov' ) MonthSelected = 10;
		else if( MonthSelected == 'Dec' ) MonthSelected = 11;
		yearPurchase2 = '20'+ Year;
		//alert(yearPurchase2);
		PurchaseDateDiff = new Date(yearPurchase,MonthSelected,1);
		PurchaseDateHighcharts = Highcharts.dateFormat('%B %Y', Date.UTC(yearPurchase, MonthSelected, 1));
//alert(PurchaseDateHighcharts);
		// push series
		//var seriesOptions;
		var TwoGraphs = false;

		nbreSeries = $xml.find('series').length;
		var seriesOptions = 
		{
				data: [],
				name: decodeURIComponent(filename.split('.').join(' '))+' :',
				//name: $('#location').val() + ' ' + $('#prop_type').val() + ' ' +$('#market').val(),
				type: 'scatter',
				marker:{enabled:false}
			};
			options.series.push(seriesOptions);
			var ValDataTables;
			var PriceForcast;
		$xml.find('series').each(function(i, series) {
			var visibility = true;
			var colorValue = 'blue';
			var DatePointStart = Date.UTC(parseInt(yearPurchase2), Month , 01);
			//alert(DatePointStart);
			var lineWidthValue = 0.5;
			var radiusValue = 3;
			var StartMonthData = 0;
			var StartYearData = 2005;
			if( i == 0 && nbreSeries == 6 ) 
			{
				colorValue = 'blue';
				var StartMonthData = Month;
				var StartYearData = parseInt(yearPurchase2);
			}
			else if( i == 1 && nbreSeries == 6 ) 
			{
				colorValue = 'green';
				var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
				var StartMonthData = MonthSelected;
				var StartYearData = yearPurchase;
			}
			else if( i == 0 && (nbreSeries == 4 || nbreSeries == 5) ) 
			{
				colorValue = 'green';
				if( nbreSeries == 4 )
				{
					var StartMonthData = Month;
					var StartYearData = parseInt(yearPurchase2);
				}
				else if( nbreSeries == 5 )
				{
					var StartMonthData = MonthSelected;
					var StartYearData = yearPurchase;
				}
			}
			else if( (i == 2 && nbreSeries == 6) || (i == 1 && nbreSeries == 5) ) 
			{
				colorValue = '#DDAA2B'; //yellow
				var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
				var lineWidthValue = 2.5;
				var radiusValue = 12;
				var StartMonthData = MonthSelected;
				var StartYearData = yearPurchase;
			}
			else if( (i == 3 && nbreSeries == 4) || (i == 4 && nbreSeries == 5) || (i == 5 && nbreSeries == 6) ) 
			{
				colorValue = '#DDAA2B'; //yellow
				var DatePointStart = Date.UTC(parseInt(YearToday2), MonthToday , 01);
				var lineWidthValue = 2.5;
				var radiusValue = 12;
				var StartMonthData = MonthToday;
				var StartYearData = parseInt(YearToday2);
			}
			else if( (i == 1 && nbreSeries == 4) || (i == 3 && nbreSeries == 6) || (i == 2 && nbreSeries == 5)  )
			{
				colorValue = 'red'; //yellow
				var StartMonthData = MonthToday;
				var StartYearData = parseInt(YearToday2);
				visibility = false;
			}
			else if( (i == 2 && nbreSeries == 4) || (i == 4 && nbreSeries == 6) || (i == 3 && nbreSeries == 5)  )
			{
				colorValue = 'blue'; //yellow
				var StartMonthData = MonthToday;
				var StartYearData = parseInt(YearToday2);
				visibility = false;
			}
			var seriesOptions = {
				type: 'area',
				name: $(series).find('name').text(),
				color : colorValue,//(i > 0 ? 'green' : 'blue'),
				data: [],
				marker: {
					enabled: true,
					lineWidth : lineWidthValue,
					radius : radiusValue,
					symbol : 'circle'
				},
			};
			// push data points
			var DataValues = new Array();
			var DataValues2 = new Array();
			var DataValuesDataTables = new Array();
			var HomeHistorySerie = false;
			$(series).find('data point').each(function(i, point) {
				//alert($(series).find('name').text());
			if( $(series).find('name').text() == 'Your Home History' )	
			{
				HomeHistorySerie = true;
			}
				
				if( $(series).find('name').text() != 'Forecast+' && $(series).find('name').text() != 'Forecast-' && $(series).find('name').text() != "Current Value" )
				{//alert(HomeHistorySerie);
					if( parseFloat($(point).text()) )
					{
						TwoGraphs = true;
						if( !HPlp ) HPlp = parseFloat($(point).text());
						//alert(parseFloat($(point).text()) * price);
						price = parseFloat($(point).text()) * price / HPlp;
						//price2 = price * 100 / PurchasePrice - 100;
						//price2 = (parseFloat($(point).text()) * 100) - 100;
						//alert(price);
						HPlp = parseFloat($(point).text());
					}
					if( HomeHistorySerie )
					{
						PriceForcast = price;
						//alert(PriceForcast);
					}
				}
				else if( $(series).find('name').text() == "Current Value" ) price = PriceForcast;
				else
				{
					if( parseFloat($(point).text()) == 0 ) 
					{
						price = PriceForcast;
						
					}
					else
					{
						price += PriceForcast * parseFloat($(point).text())/100;
					}
				}
				price2 = price * 100 / PurchasePrice - 100;
				DataValues.push(Math.round(price));
				DataValues2.push(Math.round(price2));
				DataValuesDataTables.push(Math.round(price));
			});
			
			dLen = DataValues.length;
			//if( $(series).find('name').text() == "Current Value" )	ValDataTables = "$" + Highcharts.numberFormat(DataValues[dLen - 1], 0,'.',',');
			if( $(series).find('name').text() == "Current Value" )	ValDataTables = "$" + Highcharts.numberFormat(PriceForcast, 0,'.',',');

			for (var indexDate = 0; indexDate < dLen; indexDate++) {//alert(StartYearData); alert(StartMonthData + indexDate); alert(DataValues[indexDate]);
				if( indexDate == 0 ) var percentages = '';
				else{
					PercentagesColor = (DataValues2[indexDate] >= 0 ? 'green' : 'red' );
					percentages = (DataValues2[indexDate] > 0 ? '+' : '' ) + DataValues2[indexDate];
					percentages = ' <span style="color:'+PercentagesColor+'">('+percentages+'%)</span>';
				}
				seriesOptions.data.push({								
				y: DataValues[indexDate],
				x: Date.UTC(StartYearData, StartMonthData + indexDate, 1),
				color: '#FF0000',
				percentage : percentages,
			});
			
				if( indexDate < dLen && !dataTableVal[Highcharts.dateFormat('%b %Y', Date.UTC(StartYearData, StartMonthData + indexDate, 1))] && DataTableContinue && $(series).find('name').text() == 'Your Home History' ){
					dataTableVal[Highcharts.dateFormat('%b %Y', Date.UTC(StartYearData, StartMonthData + indexDate, 1))] = true;
					newRow = $('#example').dataTable().fnAddData( [
						Highcharts.dateFormat('%b %Y', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)),
						"$" + Highcharts.numberFormat(DataValuesDataTables[dLen - indexDate - 1], 0,'.',','),
					] );
					if( $('#purchase_month').val() != Highcharts.dateFormat('%b', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)) )
					{
						var oSettings = $('#example').dataTable().fnSettings();
						var nTr = oSettings.aoData[ newRow[0] ].nTr;
						$('td', nTr)[0].setAttribute( 'class', 'WrongMonth' );
						$('td', nTr)[1].setAttribute( 'class', 'WrongMonth' );
					}
					
					if( DataTableDateStop == Highcharts.dateFormat('%b %Y', Date.UTC(StartYearData, StartMonthData + indexDate, 1)) ) DataTableContinue = false;
				}
			}
			// add it to the options
			options.series.push(seriesOptions);
		});
		$('#example').dataTable().fnUpdate( ValDataTables, 0, 1 );
		var chart = new Highcharts.Chart(options);
		var SeriesOnGraph = chart.series.length;
		//if( $('#CompareVal').val() != 3000 )
		//{
			chart.series[SeriesOnGraph-2].hide();
			chart.series[SeriesOnGraph-3].hide();
		//}


		$('#containerHighcharts1').hide();
		$('#containerHighcharts').show();
//alert(filename2);
	if( $.trim(filename2) != ''){
		//chart = $('#containerHighcharts').highcharts();
	$.get(document.location.origin+'/excel_reader2.php?file='+filename2+'&date='+DatePurchase.split("-").join(" - ")+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+period+'&value='+PurchasePrice, function(xml) {
	//var chart = $('#containerHighcharts').highcharts();
		// Split the lines
		var $xml = $(xml);
		
	var HPlp = 0;
	$xml.find('default').each(function(i, defaultValue) {
		price = $(defaultValue).text();
	});
	var FirstDate = $xml.find('categories item')[0];
	var LastDate = $xml.find('categories item').last();
	var LastMonth = $(LastDate).text();
	var MonthToday = LastMonth.substring(0,3);
	var YearToday = LastMonth.slice(-2);
	var DataTableDateStop = MonthToday +" "+currentYear;
	var DataTableContinue = true;
	
	if( MonthToday == 'Jan' ) MonthToday = 0;
	else if( MonthToday == 'Feb' ) MonthToday = 1;
	else if( MonthToday == 'Mar' ) MonthToday = 2;
	else if( MonthToday == 'Apr' ) MonthToday = 3;
	else if( MonthToday == 'May' ) MonthToday = 4;
	else if( MonthToday == 'Jun' ) MonthToday = 5;
	else if( MonthToday == 'Jul' ) MonthToday = 6;
	else if( MonthToday == 'Aug' ) MonthToday = 7;
	else if( MonthToday == 'Sep' ) MonthToday = 8;
	else if( MonthToday == 'Oct' ) MonthToday = 9;
	else if( MonthToday == 'Nov' ) MonthToday = 10;
	else if( MonthToday == 'Dec' ) MonthToday = 11;
	
	var YearToday2 = '20'+YearToday;
	
	var FirstMonth = $(FirstDate).text();
	var Month = FirstMonth.substring(0,3);
	var Year = FirstMonth.slice(-2);
	var ArrayMonth = new Array();
	if( Month == 'Jan' ) Month = 0;
	else if( Month == 'Feb' ) Month = 1;
	else if( Month == 'Mar' ) Month = 2;
	else if( Month == 'Apr' ) Month = 3;
	else if( Month == 'May' ) Month = 4;
	else if( Month == 'Jun' ) Month = 5;
	else if( Month == 'Jul' ) Month = 6;
	else if( Month == 'Aug' ) Month = 7;
	else if( Month == 'Sep' ) Month = 8;
	else if( Month == 'Oct' ) Month = 9;
	else if( Month == 'Nov' ) Month = 10;
	else if( Month == 'Dec' ) Month = 11;
	
	var datesUrlTable = DatePurchase.split("-");
	//var MonthSelected = $('#purchase_month').val();
	var MonthSelected = datesUrlTable[0];
	var yearPurchase = parseInt('20'+datesUrlTable[1]);
	if( MonthSelected == 'Jan' ) MonthSelected = 0;
	else if( MonthSelected == 'Feb' ) MonthSelected = 1;
	else if( MonthSelected == 'Mar' ) MonthSelected = 2;
	else if( MonthSelected == 'Apr' ) MonthSelected = 3;
	else if( MonthSelected == 'May' ) MonthSelected = 4;
	else if( MonthSelected == 'Jun' ) MonthSelected = 5;
	else if( MonthSelected == 'Jul' ) MonthSelected = 6;
	else if( MonthSelected == 'Aug' ) MonthSelected = 7;
	else if( MonthSelected == 'Sep' ) MonthSelected = 8;
	else if( MonthSelected == 'Oct' ) MonthSelected = 9;
	else if( MonthSelected == 'Nov' ) MonthSelected = 10;
	else if( MonthSelected == 'Dec' ) MonthSelected = 11;
	yearPurchase2 = '20'+ Year;
		//alert(MonthSelected + "   " + yearPurchase);
		// push series
		//var seriesOptions;
		var TwoGraphs = false;
		var nbreSeries = $xml.find('series').length;
		var seriesOptions = 
		{
				data: [],
				name: decodeURIComponent(filename2.split('.').join(' '))+' :',
				//name: $('#location_second').val() + ' ' +$('#prop_type_second').val() + ' ' + $('#market_second').val(),
				type: 'scatter',
				marker:{enabled:false}
			};
			chart = $('#containerHighcharts').highcharts();
			chart.addSeries(seriesOptions);
			var PriceForcast;
		$xml.find('series').each(function(i, series) {
			var visibility = true;
			var colorValue = '#C03000';
			var DatePointStart = Date.UTC(parseInt(yearPurchase2), Month , 01);
			var lineWidthValue = 0.5;
			var radiusValue = 3;
			var StartMonthData = 0;
			var StartYearData = 2005;
			if( i == 0 && nbreSeries == 6 ) 
			{
				colorValue = '#C03000';
				var StartMonthData = Month;
				var StartYearData = parseInt(yearPurchase2);
			}
			else if( i == 1 && nbreSeries == 6 ) 
			{
				colorValue = '#4C1B1B';
				colorValue = '#EB2F86';
				var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
				var StartMonthData = MonthSelected;
				var StartYearData = yearPurchase;
			}
			else if( i == 0 && (nbreSeries == 4 || nbreSeries == 5) ) 
			{
				colorValue = '#4C1B1B';
				colorValue = '#EB2F86';
				if( nbreSeries == 4 )
				{
					var StartMonthData = Month;
					var StartYearData = parseInt(yearPurchase2);
				}
				else if( nbreSeries == 5 )
				{
					var StartMonthData = MonthSelected;
					var StartYearData = yearPurchase;
				}
			}
			else if( (i == 2 && nbreSeries == 6) || (i == 1 && nbreSeries == 5) ) 
			{
				colorValue = '#DDAA2B'; //yellow
				var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
				var lineWidthValue = 2.5;
				var radiusValue = 12;
				var StartMonthData = MonthSelected;
				var StartYearData = yearPurchase;
			}
			else if( (i == 3 && nbreSeries == 4) || (i == 4 && nbreSeries == 5) || (i == 5 && nbreSeries == 6) ) 
			{
				colorValue = '#666666'; //yellow
				var DatePointStart = Date.UTC(parseInt(YearToday2), MonthToday , 01);
				var lineWidthValue = 2.5;
				var radiusValue = 12;
				var StartMonthData = MonthToday;
				var StartYearData = parseInt(YearToday2);
			}
			else if( (i == 1 && nbreSeries == 4) || (i == 3 && nbreSeries == 6) || (i == 2 && nbreSeries == 5)  )
			{
				colorValue = 'red'; //yellow
				var StartMonthData = MonthToday;
				var StartYearData = parseInt(YearToday2);
				visibility = false;
			}
			else if( (i == 2 && nbreSeries == 4) || (i == 4 && nbreSeries == 6) || (i == 3 && nbreSeries == 5)  )
			{
				colorValue = 'blue'; //yellow
				var StartMonthData = MonthToday;
				var StartYearData = parseInt(YearToday2);
				visibility = false;
			}
			var seriesOptions = {
				type: 'area',
				name: $(series).find('name').text(),
				color : colorValue,//(i > 0 ? 'green' : 'blue'),
				data: [],
				marker: {
					enabled: true,
					lineWidth : lineWidthValue,
					radius : radiusValue,
					symbol : 'circle'
				},
			};
			// push data points
			var DataValues = new Array();
			var DataValues2 = new Array();
			var HomeHistorySerie = false;
			$(series).find('data point').each(function(i, point) {
				//alert($(series).find('name').text());
			if( $(series).find('name').text() == 'Your Home History' )	
			{
				HomeHistorySerie = true;
			}
				
				if( $(series).find('name').text() != 'Forecast+' && $(series).find('name').text() != 'Forecast-' && $(series).find('name').text() != "Current Value" )
				{//alert(HomeHistorySerie);
					if( parseFloat($(point).text()) )
					{
						TwoGraphs = true;
						if( !HPlp ) HPlp = parseFloat($(point).text());
						//alert(parseFloat($(point).text()) * price);
						price = parseFloat($(point).text()) * price / HPlp;
						//price2 = price * 100 / PurchasePrice - 100;
						//price2 = (parseFloat($(point).text()) * 100) - 100;
						//alert(price);
						HPlp = parseFloat($(point).text());
					}
					if( HomeHistorySerie )
					{
						PriceForcast = price;
						//alert(PriceForcast);
					}
				}
				else if( $(series).find('name').text() == "Current Value" ) price = PriceForcast;
				else
				{
					if( parseFloat($(point).text()) == 0 ) 
					{
						price = PriceForcast;
						
					}
					else
					{
						price += PriceForcast * parseFloat($(point).text())/100;
					}
				}
				price2 = price * 100 / PurchasePrice - 100;
				DataValues.push(Math.round(price));
				DataValues2.push(Math.round(price2));
			});
			/*$(series).find('data point').each(function(i, point) {
				if( parseFloat($(point).text()) )
				{
					TwoGraphs = true;
					if( !HPlp ) HPlp = parseFloat($(point).text());
					price = parseFloat($(point).text()) * price / HPlp;
					price2 = price * 100 / PurchasePrice - 100;
					
					HPlp = parseFloat($(point).text());
					DataValues.push(Math.round(price));
					DataValues2.push(Math.round(price2));
				}
			});*/
			
			dLen = DataValues.length;

			for (var indexDate = 0; indexDate < dLen; indexDate++) {//alert(StartYearData); alert(StartMonthData + indexDate); alert(DataValues[indexDate]);
				if( indexDate == 0 ) var percentages = '';
				else{
					PercentagesColor = (DataValues2[indexDate] >= 0 ? 'green' : 'red' );
					percentages = (DataValues2[indexDate] > 0 ? '+' : '' ) + DataValues2[indexDate];
					percentages = ' <span style="color:'+PercentagesColor+'">('+percentages+'%)</span>';									
				}
				seriesOptions.data.push({
				
				y: DataValues[indexDate],
				x: Date.UTC(StartYearData, StartMonthData + indexDate, 1),
				color: '#FF0000',
				percentage : percentages,
			});

			}
			chart.addSeries(seriesOptions);
		});
		$('#containerHighcharts1').hide();
		$('#containerHighcharts').show();
		$("input#button").removeAttr("disabled");
		var SeriesOnGraph = chart.series.length;
		//if( $('#CompareVal').val() != 3000 )
		//{
			chart.series[SeriesOnGraph-2].hide();
			chart.series[SeriesOnGraph-3].hide();
		//}
	});
}
	if( typeof(ParseUrl['StartPoint']) != 'undefined' )
	{
		var str1 = ParseUrl['StartDate'];
		if( str1.indexOf( "-" ) > -1 )
			ParseUrl['StartDate'] = ParseUrl['StartDate'].split('-');
		else
			ParseUrl['StartDate'] = ParseUrl['StartDate'].split('/');

		var str1 = ParseUrl['EndDate'];
		if( str1.indexOf( "-" ) > -1 )
			ParseUrl['EndDate'] = ParseUrl['EndDate'].split('-');
		else
			ParseUrl['EndDate'] = ParseUrl['EndDate'].split('/');
			
		ParseUrl['EndPoint'] = ParseUrl['EndPoint'].replace(/\D/g,'');
		ParseUrl['StartPoint'] = ParseUrl['StartPoint'].replace(/\D/g,'');

		console.log(ParseUrl);
		//~ var seriesOptions = {
			//~ type: 'line',
			//~ name: 'Red Line',
			//~ color : 'red',//(i > 0 ? 'green' : 'blue'),
			//~ data: [],
			//~ lineWidth: 7,
			//~ marker: {
				//~ enabled: true,
				//~ lineWidth : 5,
				//~ radius : 8,
				//~ symbol : 'circle'
			//~ },
			//~ showInLegend: false,
			//~ tooltip:{
				//~ enabled: false,
			//~ },
		//~ };
		//~ seriesOptions.data.push({
			//~ y: parseInt(ParseUrl['StartPoint']),
			//~ x: Date.UTC(parseInt(ParseUrl['StartDate'][2]) + 2000, parseInt(ParseUrl['StartDate'][0]) - 1, parseInt(ParseUrl['StartDate'][1])),
			//~ color: '#FF0000',
			//~ percentage : '',
		//~ });
		//~ seriesOptions.data.push({
			//~ y: parseInt(ParseUrl['EndPoint']),
			//~ x: Date.UTC(parseInt(ParseUrl['EndDate'][2]) + 2000, parseInt(ParseUrl['EndDate'][0]) - 1, parseInt(ParseUrl['EndDate'][1])),
			//~ color: '#FF0000',
			//~ percentage : '',
		//~ });
		//~ chart.addSeries(seriesOptions);
		console.log('zzk : '+chart.yAxis[0].max);
	}
		var title = '<div style="width:800px; display:inline-block; text-align:left;"><div style="float:left; width:380px;">';
	if( typeof(ParseUrl['Address']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['Address'])) != '' )
	{
		title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red">'+$.trim(decodeURIComponent(ParseUrl['Address'])).split('.').join(' ')+'</span></span>';
		$('#personnalize_address').val($('<div />').text(ParseUrl['Address']).html());
	}
	else
	{
		title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red"><a href="javascript:void(0);" onclick="$(\'#popup_box\').fadeIn(\'slow\');" style="color:red; text-decoration:none;">Click here to Input Your Address</a></span></span>';
	}
		if( typeof(ParseUrl['Owner']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['Owner'])) != '' ) 
		{
			title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">Provided for : '+decodeURIComponent(ParseUrl['Owner'])+'</span>';
			$('#personnalize_agent').val(decodeURIComponent(ParseUrl['Owner']));
		}
		else if( $.trim($('#personnalize_agent').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">Provided for : '+$('#personnalize_agent').val()+'</span>';
		if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">By : '+$('#personnalize_company').val()+'</span>';
		title += '</div><div style="float:right;"><img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" /></div>';
		//if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:14px; text-align:left;">Company : '+$('#personnalize_company').val()+'</span>';
		title += '</div>';
		chart.xAxis[0].update({
			 title:{
				text: title,
				useHTML: true,
			 }
		});
		chart.setSize(927, 600);
	});
}

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = value;
        //alert(key + " = " + value);
    });
    return vars;
}

//alert((typeof(getUrlVars()['zz']) == 'undefined'));

function monthDiff(d1, d2) {
    var months;
    months = (d2.getFullYear() - d1.getFullYear()) * 12;
    months -= d1.getMonth() + 1;
    months += d2.getMonth();
    return months <= 0 ? 0 : months;
}

function sortDropDownListByText(selectId) {
    var foption = $('#'+ selectId + ' option:first');
    var soptions = $('#'+ selectId + ' option:not(:first)').sort(function(a, b) {
       return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
    });
    $('#' + selectId).html(soptions).prepend(foption);              

};
function RedColorDropDown(){
	$('div#FileNameSelect').find('select').each(function(){
		var selectId = this.id;
		//alert(selectId);
	   $('#'+ selectId + ' option:first').css('color', 'red');
	   $('#'+ selectId + ' option:not(:first)').css('color', 'black');
	   //$(this).css('color','red');
	   //$(this).change(function() {
		  var current = $(this).val();
		  if (current != '') {
			  $(this).css('color','black');
		  } else {
			  $(this).css('color','red');
		  }
	   //}); 	
	});
}

function ManageGraphPercentages(filename, filename2, TwoYearsIndex)
{
	var FirstFileName = filename;
	var SecondFileName = filename2;
	if( $('#category_graph').length > 0 )
	{
		if( $('#category_graph').val() != '' && $('#location').val() != '' && $('#prop_type').val() != '' && $('#market').val() != '' ) 
		{
			filename = filenamesSelect[$('#category_graph').val()][$('#location').val()][$('#prop_type').val()][$('#market').val()];
			FirstFileName = decodeURIComponent(filename);
			if( $('#category_graph_second').val() != '' && $('#location_second').val() != '' && $('#prop_type_second').val() != '' && $('#market_second').val() != '' && $('#category_graph_second').val() !== null && $('#location_second').val() !== null && $('#prop_type_second').val() !== null && $('#market_second').val() !== null ) 
			{
				//alert($('#category_graph_second').val() + ' '+ $('#location_second').val() + ' '+ $('#prop_type_second').val() + ' '+ $('#market_second').val() + 'entered here');
				filename2 = filenamesSelect[$('#category_graph_second').val()][$('#location_second').val()][$('#prop_type_second').val()][$('#market_second').val()];
				SecondFileName = decodeURIComponent(filename2);
			}
		}
	}
	else if( $("input#FirstFilenameSelected").length > 0 && $("input#FirstFilenameSelected").val() != '' )
	{
		filename = $('input#FirstFilenameSelected').val();
		FirstFileName = decodeURIComponent(filename);
		SecondFileName = decodeURIComponent(filename2);
		if( $("input#FirstFilenameSelected2").length > 0 && $("input#FirstFilenameSelected2").val() != '' ) 
		{
			//alert($('#category_graph_second').val() + ' '+ $('#location_second').val() + ' '+ $('#prop_type_second').val() + ' '+ $('#market_second').val() + 'entered here');
			filename2 = $("input#FirstFilenameSelected2").val();
			SecondFileName = decodeURIComponent(filename2);
		}
	}

$('#example').dataTable().fnClearTable();	
			$('#containerHighcharts').hide();
			$('#containerHighcharts1').show();
			var options = {
				chart: {
					zoomType: 'x',
					spacingRight: 20,
					renderTo: 'containerHighcharts',
					type: 'area',
					color : '#FFFFFF',
				//	marginRight: 130,
					//marginBottom: 50
					  className: 'skies',
					  borderWidth: 0,
					  plotShadow: true,
					  plotBackgroundImage: '/intranetimages/coughlinteam/users/6882/skies.jpg',
					  //plotBackgroundImage: 'http://www.highcharts.com/demo/gfx/skies.jpg',
					  plotBackgroundColor: {
						 linearGradient: [208, 48, 85, 1000],
						 stops: [
							[0, 'rgba(203, 213, 223, 1)'],
							[1, 'rgba(203, 213, 223, 0.5)']
						 ]
					  },
					  plotBorderWidth: 1
				},
			exporting: {
					type:"image/png",
					url:"https://export.highcharts.com/",
					buttons:{
						contextButton:{symbol:"menu",
						_titleKey:"contextButtonTitle",
						menuItems: [
						{
							textKey:"printChart",
							onclick:function(){this.print()}
						},
						{
							separator:!0
						},
						{
							textKey:"downloadPNG",
							onclick:function(){this.exportChart()}
						},
						{
							textKey:"downloadJPEG",
							onclick:function(){this.exportChart({type:"image/jpeg"})}
						},
						/*{
							textKey:"downloadPDF",
							onclick:function(){this.exportChart({type:"application/pdf"})}
						},*/
						{
							text:"Download GIF",
							onclick:function(){this.exportChart({type:"image/gif"})}
						},
						/*{
							textKey:"downloadSVG",
							onclick:function(){this.exportChart({type:"image/svg+xml"})}
						},*/
						{
							text:"Personalize",
							onclick:function(){$('#popup_box').fadeIn("slow");$('html, body').animate({scrollTop: $("#popup_box").offset().top}, 500);$('#personnalize_address').focus();}
						},
						{
							text: 'Save settings',
							onclick: function() {  
								ParseUrl = getUrlVars();
								var IdSummary;
								var AddressData;
								var Yr;
								var DatePurchase;
								var PricePurchase;
								if( typeof(ParseUrl['IdSummary']) == 'undefined') IdSummary = '';
								if( typeof(ParseUrl['AddressStr']) == 'undefined') AddressData = ( $.trim($('#personnalize_address').val()) != '' ? $.trim($('#personnalize_address').val()) : '' );
								else AddressData = ParseUrl['AddressStr'];
								if( typeof(ParseUrl['range']) == 'undefined') Yr = $('#CompareVal').val()/12;
								else Yr = ParseUrl['range'];
								if( typeof(ParseUrl['DatePurchase']) == 'undefined') DatePurchase = $('#purchase_month').val()+"-"+$('#purchase_year').val();
								else DatePurchase = ParseUrl['DatePurchase'];
								if( typeof(ParseUrl['PricePurchase']) == 'undefined') PricePurchase = $('#purchase_price').val().replace(',', '').replace('.', '');
								else PricePurchase = ParseUrl['PricePurchase'];
								$.ajax({
									type: "POST",
									url: "/SaveDataToTable.php",
									/*dataType: "xml",*/
									data: {
										HashId: IdSummary, 
										Address: AddressData,
										Yr: Yr,
										DatePurchase: DatePurchase.replace('-',' / '),
										PricePurchase: "$ "+Highcharts.numberFormat(PricePurchase, 0,'.',',')
									}, 
									success: function(data){
										alert(data);
									},
									error: function() {
										//$( "div#Loading" ).hide( "slow" );
										alert("An error occurred while processing your request.");
									}
								});

								//alert('Settings saved');
							}
						}
						]
					}
				}
			},
				tooltip: {
					style: {
						fontWeight: 'bold',
						fontSize: '16px',
						width: '1000px',
					},
					followPointer: true,
					useHTML: true,
					formatter: function() {
						var s = Highcharts.dateFormat('%B %Y', this.x);
						var chart = $('#containerHighcharts').highcharts();
						var series = chart.series;
						var LimitSeries = (typeof(filename2) == 'undefined' || $.trim(filename2) == '')  ? series.length : series.length/2;
						var nbrePoints = this.points.length;
						var FirstPass;
						var TestHPIp;
						//alert(this.points.length);
						$.each(this.points, function(i, point) {
							//alert(i);
							//alert(this.y);
							var IndexSerie = ( i > 0 ? LimitSeries : 0 );
							var SerieName;
							//alert(this.series.name);
							if( this.series.name == 'HPIp' )
							{
								if( !i && this.series.name == 'HPIp' ) 
								{
									SerieName = 'Home Price Index HPIp';
									s = '<div style="float:left;">'+SerieName+'</div><div style="float:right; text-align:right; margin-right:2px;">'+s+'</div>';
									s +=  '<br /><span style="color:' + this.series.color +'">' + series[IndexSerie].name +'</span> $'+ Highcharts.numberFormat(this.total, 0,'.',',') + ' ' +Highcharts.numberFormat(this.y, 2,'.',',')+  '% ' + this.percentage; 
								}
								else if( !i && this.series.name == 'Your Home History' ) SerieName = 'Your Home Price History';
								else SerieName = this.series.name;
								if( typeof(filename2) != 'undefined' && filename2 != '' && i > 0 )
								{
									s +=  '<br /><span style="color:' + series[LimitSeries+1].color +'">' + series[LimitSeries].name +'</span> $'+ Highcharts.numberFormat(this.total, 0,'.',',') + ' ' +Highcharts.numberFormat(this.y, 2,'.',',')+  '% ' + this.percentage; 
								}
								TestHPIp = true;
								if( ( !i && (typeof(filename2) == 'undefined' || $.trim(filename2) == '') ) || i > 0 ) return false;
							}

							//else if( !i && this.series.name == 'HPIp' ) SerieName = '';
							else if( typeof(TestHPIp) == 'undefined' ){
								if( !i ) 
								{
									z = '<div style="float:right; text-align:right; margin-right:2px; display:inline;">'+s+'</div>';
									if( this.series.index < 4 )	s = '<div style="float:left;">'+series[0].name+'</div>'+z;
								}
								//if( ((nbrePoints == 4 && i == 2) || (nbrePoints == 2 && i == 1)) && typeof(filename2) != 'undefined' && filename2 != '' ) 
								if( this.series.index > 4 && typeof(FirstPass) == 'undefined' )
								{
									FirstPass = true;
									s += '<br /><br /><div style="float:left;">'+series[4].name+'</div>'+z;
								}
								s +=  '<br /><span style="color:' + this.series.color +'; min-width:180px; display:inline-block;">' + this.series.name +'</span> $'+ Highcharts.numberFormat(this.total, 0,'.',',') + ' ' +Highcharts.numberFormat(this.y, 2,'.',',')+  '% ' + this.percentage; 
							}
							//this.series.name
						});
						return s;
					},
					shared: true,
				},
				title: {
					text: 'Powered by the Greater Vancouver Market Reports HPIp'
				},
				/*subtitle: {
					text: document.ontouchstart === undefined ?
						'Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in' :
						'Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in',
					style: {
						color: '#FF0000',
						fontWeight: 'bold'
					}
				},		*/		
            xAxis: {
                type: 'datetime',
                maxZoom: 14 * 24 * 3600000, // fourteen days
                tickInterval: 24 * 3600 * 31000 * 3, // one month
                title: {
					text: document.ontouchstart === undefined ?
						'<img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" />' : '<img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" />',/*Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in' :
			'Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in',*/
					style: {
						color: '#FF0000',
						font: 'bold 18px Helvetica',
					},
					useHTML: true,
                },
                labels: {
   						rotation: -45,
						style: {
							font: '14px Helvetica',
						}

					}
              // categories: []
            },
				yAxis: {
					title: {
						text: '',
					},
					labels: {
						formatter: function () {
							return Highcharts.numberFormat(this.value, 0,'.',',')+"%";
						},
						style: {
							//color: '#4572A7',
							font: 'bold 14px Helvetica',
						}
					},
					gridLineWidth: 2,
					lineWidth:1,
				},
				legend: {
					align: 'top',
					verticalAlign: 'top',
					x: 0,
					y: 50,
					margin : 10,
					width: 600,
					useHTML: true,
					itemStyle: {
						fontWeight: 'bold',
					},
					labelFormatter: function() {
						if( this.type == 'scatter' ) { return '<span style="width:250px; text-align:right; font-size: 12px; display:block"><b>'+this.name+'</b></span>';}
						return this.name;
					}
				},
				plotOptions: {
					area: {
						fillColor: {
							linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
							stops: [
								[0, Highcharts.getOptions().colors[0]],
								[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]
								/*[0, 'rgba(208, 48, 85,0.5)'],
								[1, 'rgba(208, 48, 85,0)']*/
							]
						},
						lineWidth: 1,
						marker: {
							enabled: true,
							lineWidth : 1,
							radius : 4,
							symbol : 'circle'
						},
						shadow: false,
						states: {
							hover: {
								lineWidth: 1
							}
						},
						threshold: null
					},
					series: {
						events: {
							legendItemClick: function(event) {
								var seriesIndex = this.index;
								var series = this.chart.series;
								var LimitSeries = (typeof(filename2) == 'undefined' || $.trim(filename2) == '') ? series.length/1 : series.length/2;
								//alert(filename);
								//alert(filename2);
								if( seriesIndex == 0 || seriesIndex == LimitSeries )
								{
									for (var i = 0; i < LimitSeries; i++)
									{
										var j = i + seriesIndex;
										if (series[j].index != seriesIndex)
										{
											series[seriesIndex].visible ? series[j].hide() : series[j].show();
										} 
									}
								}
								if (!this.visible)	return true;
								
								series[this.index].hide();

								return false;
							}
						}
					}
					
				},
				series: []
			};

				var DatePurchase = $('#purchase_month').val()+" - "+$('#purchase_year').val();
				var HPlp = 0;
				var price;
				//alert(document.location.origin+'/excel_reader2.php?file='+filename);
				//alert('excel_reader2.php?file='+filename);
				//$.get('http://coughlinteam.com/plugins/excel_reader2.php?file='+filename, function(xml) {
				//$.get(document.location.origin+'/excel_reader2.php?file='+filename, function(xml) {
					//alert(document.location.origin+'/excel_reader2.php?file='+$.trim(filename));
				if( typeof(TwoYearsIndex) == 'undefined' ) TwoYearsIndex = 0;
				$.get(document.location.origin+'/excel_reader2.php?file='+$.trim(filename), function(xml) {
					
					// Split the lines
						var $xml = $(xml);
						
					$xml.find('default').each(function(i, defaultValue) {
						price2 = $(defaultValue).text();
					});
					price = 100;
					var FirstDate = $xml.find('categories item')[0];
					var LastDate = $xml.find('categories item').last();
					var LastMonth = $(LastDate).text();
					var MonthToday = LastMonth.substring(0,3);
					var YearToday = LastMonth.slice(-2);
					//alert($.trim($(FirstDate).text()).slice(-2));
					if( MonthToday == 'Jan' ) MonthToday = 0;
					else if( MonthToday == 'Feb' ) MonthToday = 1;
					else if( MonthToday == 'Mar' ) MonthToday = 2;
					else if( MonthToday == 'Apr' ) MonthToday = 3;
					else if( MonthToday == 'May' ) MonthToday = 4;
					else if( MonthToday == 'Jun' ) MonthToday = 5;
					else if( MonthToday == 'Jul' ) MonthToday = 6;
					else if( MonthToday == 'Aug' ) MonthToday = 7;
					else if( MonthToday == 'Sep' ) MonthToday = 8;
					else if( MonthToday == 'Oct' ) MonthToday = 9;
					else if( MonthToday == 'Nov' ) MonthToday = 10;
					else if( MonthToday == 'Dec' ) MonthToday = 11;
					
					var YearToday2 = '20'+YearToday;
					
					var FirstMonth = $(FirstDate).text();
					var Month = FirstMonth.substring(0,3);
					var Year = FirstMonth.slice(-2);
					var ArrayMonth = new Array();
					if( Month == 'Jan' ) Month = 0;
					else if( Month == 'Feb' ) Month = 1;
					else if( Month == 'Mar' ) Month = 2;
					else if( Month == 'Apr' ) Month = 3;
					else if( Month == 'May' ) Month = 4;
					else if( Month == 'Jun' ) Month = 5;
					else if( Month == 'Jul' ) Month = 6;
					else if( Month == 'Aug' ) Month = 7;
					else if( Month == 'Sep' ) Month = 8;
					else if( Month == 'Oct' ) Month = 9;
					else if( Month == 'Nov' ) Month = 10;
					else if( Month == 'Dec' ) Month = 11;
					
					var MonthSelected = $('#purchase_month').val();
					if( MonthSelected == 'Jan' ) MonthSelected = 0;
					else if( MonthSelected == 'Feb' ) MonthSelected = 1;
					else if( MonthSelected == 'Mar' ) MonthSelected = 2;
					else if( MonthSelected == 'Apr' ) MonthSelected = 3;
					else if( MonthSelected == 'May' ) MonthSelected = 4;
					else if( MonthSelected == 'Jun' ) MonthSelected = 5;
					else if( MonthSelected == 'Jul' ) MonthSelected = 6;
					else if( MonthSelected == 'Aug' ) MonthSelected = 7;
					else if( MonthSelected == 'Sep' ) MonthSelected = 8;
					else if( MonthSelected == 'Oct' ) MonthSelected = 9;
					else if( MonthSelected == 'Nov' ) MonthSelected = 10;
					else if( MonthSelected == 'Dec' ) MonthSelected = 11;
					yearPurchase2 = '20'+ Year;

						var TwoGraphs = false;
						var ForcastSeries = false;
						nbreSeries = $xml.find('series').length;
						var seriesOptions = 
						{
								data: [],
								//name: decodeURIComponent(FirstFileName.split('.').join(' '))+' :',
								name: FirstFileName.split('.').join(' ')+' :',
								type: 'scatter',
								marker:{enabled:false}
							};
							options.series.push(seriesOptions);

						$xml.find('series').each(function(i, series) {
							var newSerie = true;
							var visibility = true;
							var colorValue = 'blue';
							var DatePointStart = Date.UTC(parseInt(yearPurchase2), Month , 01);
							var lineWidthValue = 0.5;
							var radiusValue = 3;
							var StartMonthData = 0;
							//var StartYearData = 2005;
							var StartYearData = parseInt(yearPurchase2);
							if( i == 1 )
							{
								colorValue = 'red'; //yellow
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
								visibility = false;
							}
							else if( i == 2 )
							{
								colorValue = 'blue'; //yellow
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
								visibility = false;
							}
//alert(colorValue);
							var seriesOptions = {
								type: 'area',
								name: $(series).find('name').text(),
								color : colorValue,//(i > 0 ? 'green' : 'blue'),
								data: [],
								marker: {
									enabled: true,
									lineWidth : lineWidthValue,
									radius : radiusValue,
									symbol : 'circle'
								},
							};
							// push data points
							var DataValues = new Array();
							var DataValues2 = new Array();
							var DataValuesDataTables = new Array();
							$(series).find('data point').each(function(i, point) {
								//alert($(point).text());
								if( !ForcastSeries )
								{
									if( parseFloat($(point).text()) )
									{
										TwoGraphs = true;
										if( !HPlp ) HPlp = parseFloat($(point).text());
										//alert(parseFloat($(point).text()) * price);
										price = parseFloat($(point).text()) * price / HPlp;
										price2 = parseFloat($(point).text()) * price2 / HPlp;
										//alert(price);
										HPlp = parseFloat($(point).text());
										DataValues.push(Math.round(price*10)/10);
										DataValues2.push(Math.round(price2));
										DataValuesDataTables.push(Math.round(price*10)/10);
									}
								}
								else
								{
									//alert(price);
									//alert(price2);
									TwoGraphs = true;
									//alert(parseFloat($(point).text()) * price);
									//alert(parseFloat($(point).text()));
									if( typeof(PriceForcastMinus) == 'undefined' )
									{
										PriceForcastMinus2 = price2;
										PriceForcastMinus = price;
									}
									if( typeof(AddedVal) == 'undefined' || AddedVal == 0 || newSerie )
									{
										//alert(parseFloat($(point).text()));
										AddedVal = parseFloat($(point).text());
										AddedVal2 = parseFloat($(point).text()) * PriceForcastMinus/100;
										if( $(series).find('name').text() == 'Forecast-')
										{
											price = PriceForcastMinus;
											price2 = PriceForcastMinus2;
										}
										newSerie = false;
										//alert(AddedVal);
									}
									price += AddedVal;
									price2 += AddedVal2;
									//alert(price);
									//alert(price2);
									//alert(price);
									DataValues.push(Math.round(price*10)/10);
									DataValues2.push(Math.round(price2));
									DataValuesDataTables.push(Math.round(price*10)/10);
								}
							});
							dLen = DataValues.length;
							DataValuesDataTables.reverse();
							if( TwoYearsIndex > 0 && !ForcastSeries ) 
							{
								DataValues.reverse();
								DataValues = DataValues.slice(0, TwoYearsIndex);
								DataValues.reverse();
								DataValues2.reverse();
								DataValues2 = DataValues2.slice(0, TwoYearsIndex);
								DataValues2.reverse();
								dLen = DataValues.length;
								DataValuesDataTables = DataValuesDataTables.slice(0, TwoYearsIndex);
							}
							for (var indexDate = 0; indexDate < dLen; indexDate++) {
								if( indexDate == 0 ) var percentages = '';
								else{
									var diff = (DataValues2[indexDate] - DataValues2[indexDate-1]);
									percentages = ( ( DataValues[indexDate] * 100 / DataValues[indexDate-1] ) - 100 ).toFixed(2);
									
									PercentagesColor = (percentages >= 0 ? 'green' : 'red' );
									if( percentages > 0 ) percentages = '+'+percentages;
									if( diff >= 0 ) diff = '+ $'+Highcharts.numberFormat(diff, 0,'.',',');
									else
									{
										diff = Math.abs(diff);
										diff = '- $'+Highcharts.numberFormat(diff, 0,'.',',');
									}
									percentages = ' <span style="color:'+PercentagesColor+'"> ('+diff+')</span>';
								}
								var dateDefaultAxis = Date.UTC(StartYearData, StartMonthData + indexDate, 1);
								if( TwoYearsIndex > 0 && !ForcastSeries )
								{
									//~ alert(TwoYearsIndex);
									dateDefaultAxis = Date.UTC(parseInt(YearToday2), MonthToday - TwoYearsIndex + indexDate + 1, 1);
								}
								//~ alert(new Date(dateDefaultAxis));
								seriesOptions.data.push({
								y: DataValues[indexDate],
								x: dateDefaultAxis,
								color: '#FF0000',
								total: DataValues2[indexDate],
								percentage : percentages,
							});
								if( !ForcastSeries )
								{
									newRow = $('#example').dataTable().fnAddData( [
										Highcharts.dateFormat('%b %Y', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)),
										"% " + Highcharts.numberFormat(DataValuesDataTables[indexDate], 2,'.',','),
									 ] );
										if( Highcharts.dateFormat('%b', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)) != 'Jan' )
										{
											var oSettings = $('#example').dataTable().fnSettings();
											var nTr = oSettings.aoData[ newRow[0] ].nTr;
											$('td', nTr)[0].setAttribute( 'class', 'WrongMonth' );
											$('td', nTr)[1].setAttribute( 'class', 'WrongMonth' );
										}
								}
							}
							// add it to the options
							options.series.push(seriesOptions);
							//var seriesOptions;
							ForcastSeries = true;
						});
						var chart = new Highcharts.Chart(options);
						chart.series[3].hide();
						chart.series[2].hide();
						$('#containerHighcharts1').hide();
						$('#containerHighcharts').show();
						if( typeof(filename2) != 'undefined' && $.trim(filename2) != '' ) {
						var dataTableVal = new Array();

							$.get(document.location.origin+'/excel_reader2.php?file='+$.trim(filename2), function(xml) {
								
								var HPlp = 0;
								var price;
								var $xml = $(xml);
								var PriceForcastMinus = 0;
								var ForcastSeries = false;
								var AddedVal = 0;
						var chart = $('#containerHighcharts').highcharts();
							$xml.find('default').each(function(i, defaultValue) {
								price2 = $(defaultValue).text();
							});
							price = 100;
							var FirstDate = $xml.find('categories item')[0];
							var LastDate = $xml.find('categories item').last();
							var LastMonth = $(LastDate).text();
							var MonthToday = LastMonth.substring(0,3);
							var YearToday = LastMonth.slice(-2);
							var currentYear = (new Date).getFullYear();
							var DataTableDateStop = MonthToday +" "+currentYear;
							var DataTableContinue = true;
							
							if( MonthToday == 'Jan' ) MonthToday = 0;
							else if( MonthToday == 'Feb' ) MonthToday = 1;
							else if( MonthToday == 'Mar' ) MonthToday = 2;
							else if( MonthToday == 'Apr' ) MonthToday = 3;
							else if( MonthToday == 'May' ) MonthToday = 4;
							else if( MonthToday == 'Jun' ) MonthToday = 5;
							else if( MonthToday == 'Jul' ) MonthToday = 6;
							else if( MonthToday == 'Aug' ) MonthToday = 7;
							else if( MonthToday == 'Sep' ) MonthToday = 8;
							else if( MonthToday == 'Oct' ) MonthToday = 9;
							else if( MonthToday == 'Nov' ) MonthToday = 10;
							else if( MonthToday == 'Dec' ) MonthToday = 11;
							
							var YearToday2 = '20'+YearToday;
							
							var FirstMonth = $(FirstDate).text();
							var Month = FirstMonth.substring(0,3);
							var Year = FirstMonth.slice(-2);
							var ArrayMonth = new Array();
							if( Month == 'Jan' ) Month = 0;
							else if( Month == 'Feb' ) Month = 1;
							else if( Month == 'Mar' ) Month = 2;
							else if( Month == 'Apr' ) Month = 3;
							else if( Month == 'May' ) Month = 4;
							else if( Month == 'Jun' ) Month = 5;
							else if( Month == 'Jul' ) Month = 6;
							else if( Month == 'Aug' ) Month = 7;
							else if( Month == 'Sep' ) Month = 8;
							else if( Month == 'Oct' ) Month = 9;
							else if( Month == 'Nov' ) Month = 10;
							else if( Month == 'Dec' ) Month = 11;
							
							var MonthSelected = $('#purchase_month').val();
							if( MonthSelected == 'Jan' ) MonthSelected = 0;
							else if( MonthSelected == 'Feb' ) MonthSelected = 1;
							else if( MonthSelected == 'Mar' ) MonthSelected = 2;
							else if( MonthSelected == 'Apr' ) MonthSelected = 3;
							else if( MonthSelected == 'May' ) MonthSelected = 4;
							else if( MonthSelected == 'Jun' ) MonthSelected = 5;
							else if( MonthSelected == 'Jul' ) MonthSelected = 6;
							else if( MonthSelected == 'Aug' ) MonthSelected = 7;
							else if( MonthSelected == 'Sep' ) MonthSelected = 8;
							else if( MonthSelected == 'Oct' ) MonthSelected = 9;
							else if( MonthSelected == 'Nov' ) MonthSelected = 10;
							else if( MonthSelected == 'Dec' ) MonthSelected = 11;
							yearPurchase2 = '20'+ Year;
								// push series
								//var seriesOptions;
								var TwoGraphs = false;
								var nbreSeries = $xml.find('series').length;
								var seriesOptions = 
								{
										data: [],
										//name: decodeURIComponent(SecondFileName.split('.').join(' '))+' :',
										name: SecondFileName.split('.').join(' ')+' :',
										type: 'scatter',
										marker:{enabled:false}
									};
									chart.addSeries(seriesOptions);
								$xml.find('series').each(function(i, series) {
									var newSerie = true;
									var visibility = true;
									var colorValue = '#C03000';
									var DatePointStart = Date.UTC(parseInt(yearPurchase2), Month , 01);
									var lineWidthValue = 0.5;
									var radiusValue = 3;
									var StartMonthData = 0;
									//var StartYearData = 2005;
									var StartYearData = parseInt(yearPurchase2);
									if( i == 1 )
									{
										colorValue = 'red'; 
										var StartMonthData = MonthToday;
										var StartYearData = parseInt(YearToday2);
										visibility = false;
									}
									else if( i == 2 )
									{
										colorValue = 'blue'; 
										var StartMonthData = MonthToday;
										var StartYearData = parseInt(YearToday2);
										visibility = false;
									}

									var seriesOptions = {
										type: 'area',
										name: $(series).find('name').text(),
										color : colorValue,
										data: [],
										marker: {
											enabled: true,
											lineWidth : lineWidthValue,
											radius : radiusValue,
											symbol : 'circle'
										},
										visible : (i == 0),
									};
									// push data points
									var DataValues = new Array();
									var DataValues2 = new Array();
									$(series).find('data point').each(function(i, point) {
										//alert($(point).text());
										if( !ForcastSeries )
										{
											if( parseFloat($(point).text()) )
											{
												TwoGraphs = true;
												if( !HPlp ) HPlp = parseFloat($(point).text());
												price = parseFloat($(point).text()) * price / HPlp;
												price2 = parseFloat($(point).text()) * price2 / HPlp;
												HPlp = parseFloat($(point).text());
												DataValues.push(Math.round(price*10)/10);
												DataValues2.push(Math.round(price2));
											}
										}
										else
										{
											//alert(price);
											//alert(price2);
											TwoGraphs = true;
											//alert(parseFloat($(point).text()) * price);
											//alert(parseFloat($(point).text()));
											if( PriceForcastMinus == 0 )
											{
												PriceForcastMinus2 = price2;
												PriceForcastMinus = price;
											}
											if( AddedVal == 0 || newSerie )
											{
												//alert(parseFloat($(point).text()));
												AddedVal = parseFloat($(point).text());
												AddedVal2 = parseFloat($(point).text()) * PriceForcastMinus/100;
												if( $(series).find('name').text() == 'Forecast-')
												{
													price = PriceForcastMinus;
													price2 = PriceForcastMinus2;
												}
												newSerie = false;
												//alert(AddedVal);
											}
											price += AddedVal;
											price2 += AddedVal2;
											//alert(price);
											//alert(price2);
											//alert(price);
											DataValues.push(Math.round(price*10)/10);
											DataValues2.push(Math.round(price2));
										}
									});
									dLen = DataValues.length;
									if( TwoYearsIndex > 0 && !ForcastSeries ) 
									{
										DataValues.reverse();
										DataValues = DataValues.slice(0, TwoYearsIndex);
										DataValues.reverse();
										DataValues2.reverse();
										DataValues2 = DataValues2.slice(0, TwoYearsIndex);
										DataValues2.reverse();
										dLen = DataValues.length;
									}

									for (var indexDate = 0; indexDate < dLen; indexDate++) {
										if( indexDate == 0 ) var percentages = '';
										else{
											var diff = (DataValues2[indexDate] - DataValues2[indexDate-1]);
											percentages = ( ( DataValues[indexDate] * 100 / DataValues[indexDate-1] ) - 100 ).toFixed(2);
											
											PercentagesColor = (percentages >= 0 ? 'green' : 'red' );
											if( percentages > 0 ) percentages = '+'+percentages;
											if( diff >= 0 ) diff = '+ $'+Highcharts.numberFormat(diff, 0,'.',',');
											else
											{
												diff = Math.abs(diff);
												diff = '- $'+Highcharts.numberFormat(diff, 0,'.',',');
											}
											percentages = ' <span style="color:'+PercentagesColor+'"> ('+diff+')</span>';
										}
										var dateDefaultAxis = Date.UTC(StartYearData, StartMonthData + indexDate, 1);
										if( TwoYearsIndex > 0 && !ForcastSeries )
										{
											dateDefaultAxis = Date.UTC(parseInt(YearToday2), MonthToday - TwoYearsIndex + indexDate + 1, 1);
										}
										seriesOptions.data.push({
											y: DataValues[indexDate],
											x: dateDefaultAxis,
											color: '#FF0000',
											total: DataValues2[indexDate],
											percentage : percentages,
										});
									};
									ForcastSeries = true;
				
								chart.addSeries(seriesOptions);
								$('#containerHighcharts1').hide();
								$('#containerHighcharts').show();
							});
						chart.series[6].hide();
						chart.series[7].hide();


								
								
								

							});
						}
						else {
						$('#containerHighcharts1').hide();
						$('#containerHighcharts').show();
					}
					/*if( $.trim($('#personnalize_address').val()) != '' || $.trim($('#personnalize_agent').val()) != '' || $.trim($('#personnalize_company').val()) ) //typeof(ParseUrl['Address']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['Address'])) != '' )
					{
						var title = '<div style="width:800px; display:inline-block; text-align:left;"><div style="float:left; width:380px;">';
						if( $.trim($('#personnalize_address').val()) != '' ) title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red">'+$('#personnalize_address').val()+'</span></span>';
						else
						{
							title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red"><a href="javascript:void(0);" onclick="$(\'#popup_box\').fadeIn(\'slow\');" style="color:red; text-decoration:none;">Click here to Input Your Address</a></span></span>';
						}

						if( $.trim($('#personnalize_agent').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">Provided for : '+$('#personnalize_agent').val()+'</span>';
						if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">By : '+$('#personnalize_company').val()+'</span>';
						title += '</div><div style="float:right;"><img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" /></div>';
						//if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:14px; text-align:left;">Company : '+$('#personnalize_company').val()+'</span>';
						title += '</div>';
						chart = $('#containerHighcharts').highcharts();
						chart.xAxis[0].update({
							 title:{
								text: title,
								useHTML: true,
							 }
						});
						chart.setSize(927, 600);
					}		*/			

					});
}
		$(document).ready(function() {
			$(document).on("submit", "form.fileDownloadForm", function (e) {
				//alert('ici');
				$.fileDownload($(this).prop('action'), {
					preparingMessageHtml: "We are preparing your report, please wait...",
					failMessageHtml: "There was a problem generating your report, please try again.",
					httpMethod: "POST",
					data: $(this).serialize(),
					success: function (url) {
						//alert('ff');
						$preparingFileModal.dialog('close');
					},
					failCallback: function (responseHtml, url) {
						//alert('zz');
						$preparingFileModal.dialog('close');
						$("#error-modal").dialog({ modal: true });
					}
				}).done(function () { $preparingFileModal.dialog('close'); });
				return false;
				e.preventDefault(); //otherwise a normal form submit would occur
			});
			if( filename.slice(-1) == '%' ) filename = filename+"25";
			if( filename2.slice(-1) == '%' ) filename2 = filename2+"25";
			$('input#FirstFilenameSelected').val(filename);
//$('form#testhich').submit();
			if( $("div#CityMenu").length > 0 ) {
				var $menu = $("<ul id='UlCityMenu' style='display:none;'></ul>");
				for( i in OrderCategories)
				{
					if( i != 'removeItem' )
					{
						var $item = $("<li></li>").html('<a href="#">'+OrderCategories[i]+'</a>');
						$sub = $("<ul></ul>");
						var z = OrderCategories[i];
						for( j in filenamesSelect[z] )
						{
							if( j != 'removeItem' )
							{
								$subli = $("<li></li>").html('<a href="#">'+j+'</a>');
								$sub2 = $("<ul></ul>");
								for( k in filenamesSelect[z][j] )
								{
									if( k != 'removeItem' )
									{
										$sub2li = $("<li></li>").html('<a href="#">'+k+'</a>');
										$sub3 = $("<ul></ul>");
										for( l in filenamesSelect[z][j][k] )
										{
											if( l != 'removeItem' )
											{
												var TextHelperTitleIndex = z+'_'+j+'_'+k+'_'+l;
												$sub3li = $("<li></li>").html('<a href="#" title="'+TextHelper[TextHelperTitleIndex]+'" data-infos="'+filenamesSelect[z][j][k][l]+'" data-city="'+j+'">'+l+'</a>');

												//$sub3li = $("<li></li>").html('<a href="#">'+l+'</a>');
												$sub3.append($sub3li);
											}
										}
										$sub2li.append($sub3);
										$sub2.append($sub2li);
									}
								}
								$subli.append($sub2);
								$sub.append($subli);
							}
						}
						$item.append($sub);
						$menu.append($item);
					}
				}
				$("div#CityMenu").append($menu);
				$('#UlCityMenu').slicknav({label: 'Click here to choose a new city',});
			}
			if( $("div#CityMenu2").length > 0 ) {
				var $menu = $("<ul id='UlCityMenu2' style='display:none;'></ul>");
				for( i in OrderCategories)
				{
					if( i != 'removeItem' )
					{
						var $item = $("<li></li>").html('<a href="#">'+OrderCategories[i]+'</a>');
						$sub = $("<ul></ul>");
						var z = OrderCategories[i];
						for( j in filenamesSelect[z] )
						{
							if( j != 'removeItem' )
							{
								$subli = $("<li></li>").html('<a href="#">'+j+'</a>');
								$sub2 = $("<ul></ul>");
								for( k in filenamesSelect[z][j] )
								{
									if( k != 'removeItem' )
									{
										$sub2li = $("<li></li>").html('<a href="#">'+k+'</a>');
										$sub3 = $("<ul></ul>");
										for( l in filenamesSelect[z][j][k] )
										{
											if( l != 'removeItem' )
											{
												var TextHelperTitleIndex = z+'_'+j+'_'+k+'_'+l;
												$sub3li = $("<li></li>").html('<a href="#" title="'+TextHelper[TextHelperTitleIndex]+'" data-infos="'+filenamesSelect[z][j][k][l]+'">'+l+'</a>');

												//$sub3li = $("<li></li>").html('<a href="#">'+l+'</a>');
												$sub3.append($sub3li);
											}
										}
										$sub2li.append($sub3);
										$sub2.append($sub2li);
									}
								}
								$subli.append($sub2);
								$sub.append($subli);
							}
						}
						$item.append($sub);
						$menu.append($item);
					}
				}
				$("div#CityMenu2").append($menu);
				$('#UlCityMenu2').slicknav({prependTo: 'div#CityMenu2', label: 'Choose a comparable city',});
				$("div#CityMenu2").css("display","none");
			}

			$('#PersonnalizeReport').click( function() {			
				$('#popup_box').fadeIn("slow");
				//loadPopupBox();
			});
		
			$('#popupBoxClose').click( function() {			
				$('#popup_box').fadeOut("slow");
				//unloadPopupBox();
			});
			$('#PersonnalizeReport1').click( function() {			
				$('#popup_box').fadeIn("slow");
				//loadPopupBox();
			});
		
			
			$('#PersonnalizeReportUpdate').click(function(){
				var chart = $('#containerHighcharts').highcharts();
				//alert(chart.options.xAxis[0].title.text);
				//var title = chart.options.xAxis[0].title.text+'<div>';
				var title = '<div style="width:800px; display:inline-block; text-align:left;"><div style="float:left; width:380px;">';
				if( $.trim($('#personnalize_address').val()) != '' ) title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red">'+$('#personnalize_address').val()+'</span></span>';
				else
				{
					title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red"><a href="javascript:void(0);" onclick="$(\'#popup_box\').fadeIn(\'slow\');" style="color:red; text-decoration:none;">Click here to Input Your Address</a></span></span>';
				}

				if( $.trim($('#personnalize_agent').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">Provided for : '+$('#personnalize_agent').val()+'</span>';
				if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">By : '+$('#personnalize_company').val()+'</span>';
				title += '</div><div style="float:right;"><img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" /></div>';
				//if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:14px; text-align:left;">Company : '+$('#personnalize_company').val()+'</span>';
				title += '</div>';
				chart.xAxis[0].update({
					 title:{
						text: title,
						useHTML: true,
					 }
				});
				chart.setSize(927, 600);
				//$('#containerHighcharts').height(750);
				$('#popup_box').fadeOut("slow");
			});
			$('#ContainerPersonnalizeReport').click( function(evt) {
				if (evt.target == evt.currentTarget) {
				$('#popup_box').fadeOut("slow");
				}
			});
			
			$(function() {
				$( 'select#market' ).tooltip({ hide: { effect: "explode", duration: 500 } });
				$( 'select#market_second' ).tooltip({ hide: { effect: "explode", duration: 500 } });
				$( 'div#CityMenu' ).tooltip({ hide: { effect: "explode", duration: 500 } });
			});
			var tdChart = $("td#chartContent"),
			curWidth = tdChart.width();
			//alert(curWidth);
			$("div#containerHighcharts").css('width', curWidth+'px');
			//alert($("div#containerHighcharts").width());
			if( $('#summary').length > 0 )
			{
				oTable1 = $('#summary').dataTable({
					"bJQueryUI": true,
					"sPaginationType": "full_numbers",
					"bFilter": false,
					"bInfo": false,
					"bSort": false,
					//"sDom": '<"top"i>rt<"bottom"flp><"clear">',
					/*"bScrollInfinite": true,
					"bScrollCollapse": true,
					"sScrollY": "200px",*/
					"iDisplayLength": 12,
					//"aLengthMenu": [[12, 24, -1], [12, 24, "All"]],					
					"aLengthMenu": [[12, -1], ["Monthly", 'Yearly']],
					"fnDrawCallback":function(){
						  if ( $('#summary_paginate span span.paginate_button').size()) {
						  $('#summary_paginate')[0].style.display = "block";
						 } else {
						 $('#summary_paginate')[0].style.display = "none";
					   }
					   $('div#summary_wrapper > .fg-toolbar').css({'height':'15px','text-align':'center'});
					   $('div#summary_wrapper > div#summary_length').css('float','none');
					},
					"aoColumns": [
							  {"bSortable": false, "sWidth": "140px"},
							  {"bSortable": false, "sWidth": "140px"},
							  {"bSortable": false, "sWidth": "150px"},
							  {"bSortable": false, "sWidth": "80px"},
							  {"bSortable": false, "sWidth": "130px"},
							  {"bSortable": false, "sWidth": "120px"},
							  {"bSortable": false, "sWidth": "170px"},
							 ],
					"oLanguage": {
					  "sLengthMenu": "Summary",
					  "oPaginate": {
						"sFirst": "&lt;&lt;",
						"sLast": "&gt;&gt;",
						"sNext": "&gt;",
						"sPrevious": "&lt;",
					  }
					}
				});
			}
			oTable = $('#example').dataTable({
				"bJQueryUI": true,
				"sPaginationType": "full_numbers",
				"bFilter": false,
				"bInfo": false,
				"bSort": false,
				/*"bScrollInfinite": true,
				"bScrollCollapse": true,
				"sScrollY": "200px",*/
				"iDisplayLength": 12,
				//"aLengthMenu": [[12, 24, -1], [12, 24, "All"]],					
				"aLengthMenu": [[12, -1], ["Monthly", 'Yearly']],
				"aoColumns": [
						  {"bSortable": false},
						  {"bSortable": false},
						 ],
				"oLanguage": {
				  "sLengthMenu": "_MENU_ Home values",
				  "oPaginate": {
					"sFirst": "&lt;&lt;",
					"sLast": "&gt;&gt;",
					"sNext": "&gt;",
					"sPrevious": "&lt;",
				  }
				}
			});
			$("select", "#dt_example").change(function(){
				if( $("select", "#dt_example").val() == -1 )
				{
					$(".WrongMonth").css("display", "none");
				}
				else
				{
					$(".WrongMonth").css("display", "");
				}
				//alert($("select", "#dt_example").val());
			});
			//alert($('#summary').length);
			//alert('http://www.coughlinteam.comhttps://coughlinteam.com/excel_reader2.php?file='+filename);
			var currentYear = (new Date).getFullYear();
			var nbreSeries = 0;
			$("#button").attr("disabled", "disabled");
			for( i = 2000; i <= currentYear; i++)
			{
				// get Year format yy
				var yy = i.toString();
				$('#purchase_year').append('<option value="'+yy.substring(2,4)+'" >'+yy.substring(2,4)+'</option>');
			}

			
			if( Object.keys(filenamesSelect).length > 1 ) $('#category_graph').append('<option value="">Choose a category</option>');
			if( OrderCategories.length > 0 )
			{
				for( i in OrderCategories )
				{
					//alert(i);
					//alert('<option value="'+i+'" >'+i+'</option>');
					if( i != 'removeItem' )
						$('#category_graph').append('<option value="'+OrderCategories[i]+'" >'+OrderCategories[i]+'</option>');
				}
			}
			else
			{
				for( i in filenamesSelect )
				{
					//alert(i);
					//alert('<option value="'+i+'" >'+i+'</option>');
					if( i != 'removeItem' )
						$('#category_graph').append('<option value="'+i+'" >'+i+'</option>');
				}
				sortDropDownListByText('category_graph');
			}
			if( Object.keys(filenamesSelect).length == 1 )
			{
				var i = $('#category_graph').val();
				if( Object.keys(filenamesSelect[i]).length > 1 ) $('#location').append('<option value="">Pick your location</option>');
				for( j in filenamesSelect[i] )
				{
					if( j != 'removeItem' )
						$('#location').append('<option value="'+j+'" >'+j+'</option>');
				}
				sortDropDownListByText('location');
				if( Object.keys(filenamesSelect[i]).length == 1 )
				{
					var k = $('#location').val();
					if( Object.keys(filenamesSelect[i][k]).length > 1 ) $('#prop_type').append('<option value="">Choose a property type</option>');
					for( l in filenamesSelect[i][k] )
					{
						if( l != 'removeItem' )
							$('#prop_type').append('<option value="'+l+'" >'+l+'</option>');
					}
					sortDropDownListByText('prop_type');
					if( Object.keys(filenamesSelect[i][k]).length == 1 )
					{
						var m = $('#prop_type').val();
						if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
						for( n in filenamesSelect[i][k][m] )
						{
							if( n != 'removeItem' )
							{
								var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
								$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
							}
						}
						$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
						sortDropDownListByText('market');
					}
					else
					{
						$('#prop_type').change(function(){
							var m = $('#prop_type').val();
							$('#market').empty();
							$('#market').unbind('change');
							$("#button").attr("disabled", "disabled");
							if( m != '' )
							{
								if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
								for( n in filenamesSelect[i][k][m] )
								{
									if( n != 'removeItem' )
									{
										var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
										$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
									}
								}
								$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
								sortDropDownListByText('market');
								
							}
							RedColorDropDown();
						});
					}
				}
				$('#location').change(function(){
					var k = $('#location').val();
					//alert($('#location').val().replace(' ','.'));
					$('#prop_type').empty();
					$('#market').empty();
					$('#prop_type').unbind('change');
					$('#market').unbind('change');
					$("#button").attr("disabled", "disabled");
					if( k != '' )
					{
						if( Object.keys(filenamesSelect[i][k]).length > 1 ) $('#prop_type').append('<option value="">Choose a property type</option>');
						for( l in filenamesSelect[i][k] )
						{
							if( l != 'removeItem' )
								$('#prop_type').append('<option value="'+l+'" >'+l+'</option>');
						}
						
						
						
						
					if( Object.keys(filenamesSelect[i][k]).length == 1 )
					{
						var m = $('#prop_type').val();
						if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
						for( n in filenamesSelect[i][k][m] )
						{
							if( n != 'removeItem' )
							{
								var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
								$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
							}
						}
						$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
						sortDropDownListByText('market');
					}
						
						
						
						
						
						
						
						
						
						
						
						
						
						
						sortDropDownListByText('prop_type');
						$('#prop_type').change(function(){
							var m = $('#prop_type').val();
							$('#market').empty();
							$('#market').unbind('change');
							$("#button").attr("disabled", "disabled");
							if( m != '' )
							{
								if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
								for( n in filenamesSelect[i][k][m] )
								{
									if( n != 'removeItem' )
									{
										var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
										$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
									}
								}
								$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
								sortDropDownListByText('market');
								
							}
							RedColorDropDown();
						});
					}
					RedColorDropDown();
				});
				
			}
			//sortDropDownListByText('category_graph');
			RedColorDropDown();
			$('#category_graph').change(function(){
				var i = $('#category_graph').val();
				$('#prop_type').empty();
				$('#location').empty();
				$('#market').empty();
				$('#prop_type').unbind('change');
				$('#location').unbind('change');
				$('#market').unbind('change');
				$("#button").attr("disabled", "disabled");
				if( i != '' )
				{
					if( Object.keys(filenamesSelect[i]).length > 1 ) $('#location').append('<option value="">Pick your location</option>');
					for( j in filenamesSelect[i] )
					{
						if( j != 'removeItem' )
							$('#location').append('<option value="'+j+'" >'+j+'</option>');
					}
					sortDropDownListByText('location');
					if( Object.keys(filenamesSelect[i]).length == 1 )
					{
						var k = $('#location').val();
						if( Object.keys(filenamesSelect[i][k]).length > 1 ) $('#prop_type').append('<option value="">Choose a property type</option>');
						for( l in filenamesSelect[i][k] )
						{
							if( l != 'removeItem' )
								$('#prop_type').append('<option value="'+l+'" >'+l+'</option>');
						}
						sortDropDownListByText('prop_type');
						if( Object.keys(filenamesSelect[i][k]).length == 1 )
						{
							var m = $('#prop_type').val();
							if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
							for( n in filenamesSelect[i][k][m] )
							{
								if( n != 'removeItem' )
								{
									var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
									$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
								}
							}
							$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
							sortDropDownListByText('market');
						}
						else
						{
							$('#prop_type').change(function(){
								var m = $('#prop_type').val();
								$('#market').empty();
								$('#market').unbind('change');
								$("#button").attr("disabled", "disabled");
								if( m != '' )
								{
									if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
									for( n in filenamesSelect[i][k][m] )
									{
										if( n != 'removeItem' )
										{
											var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
											$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
										}
									}
									$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
									sortDropDownListByText('market');
									
								}
								RedColorDropDown();
							});
						}
					}
					$('#location').change(function(){
						var k = $('#location').val();
						//alert($('#location').val().replace(' ','.'));
						$('#prop_type').empty();
						$('#market').empty();
						$('#prop_type').unbind('change');
						$('#market').unbind('change');
						$("#button").attr("disabled", "disabled");
						if( k != '' )
						{
							if( Object.keys(filenamesSelect[i][k]).length > 1 ) $('#prop_type').append('<option value="">Choose a property type</option>');
							for( l in filenamesSelect[i][k] )
							{
								if( l != 'removeItem' )
									$('#prop_type').append('<option value="'+l+'" >'+l+'</option>');
							}
							
							
							
							
						if( Object.keys(filenamesSelect[i][k]).length == 1 )
						{
							var m = $('#prop_type').val();
							if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
							for( n in filenamesSelect[i][k][m] )
							{
								if( n != 'removeItem' )
								{
									var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
									$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
								}
							}
							$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
							sortDropDownListByText('market');
						}
							
							
							
							
							
							
							
							
							
							
							
							
							
							
							sortDropDownListByText('prop_type');
							$('#prop_type').change(function(){
								var m = $('#prop_type').val();
								$('#market').empty();
								$('#market').unbind('change');
								$("#button").attr("disabled", "disabled");
								if( m != '' )
								{
									if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market').append('<option value="">Choose one of the markets below</option>');
									for( n in filenamesSelect[i][k][m] )
									{
										if( n != 'removeItem' )
										{
											var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
											$('#market').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
										}
									}
									$('#market').change(function(){$("#button").attr("disabled", "disabled"); RedColorDropDown();});
									sortDropDownListByText('market');
									
								}
								RedColorDropDown();
							});
						}
						RedColorDropDown();
					});
				}
				RedColorDropDown();
			});
			var ParseUrl = getUrlVars();
			//alert(DatePurchase); alert(Forcast_Positiv); alert(Forcast_Minus); alert(period); alert(price);
			if( typeof(ParseUrl['DatePurchase']) != 'undefined' && typeof(ParseUrl['PricePurchase']) != 'undefined' )
			{
				//alert('hich');
				var DatePurchase = ParseUrl['DatePurchase'];
				var price = ParseUrl['PricePurchase'];
				var Forcast_Positiv = (typeof(ParseUrl['Forcast_Positiv']) == 'undefined') ? '' : ParseUrl['Forcast_Positiv'];
				var Forcast_Minus = (typeof(ParseUrl['Forcast_Minus']) == 'undefined') ? '' : ParseUrl['Forcast_Minus'];
				var period = (typeof(ParseUrl['range']) == 'undefined') ? 240 : ParseUrl['range'] * 12;
				if( typeof(ParseUrl['filename']) != 'undefined' )
				{
					console.log(ParseUrl['filename']);
					filename = ParseUrl['filename'];
					filename2 = '';
				}
				//if( typeof(filename2) != 'undefined' && $.trim(filename2) != '' ) var filename2 = '';
				ManageGraph(filename, DatePurchase, Forcast_Positiv, Forcast_Minus, period, price, filename2);
				//year = 5; Purchase Date =‘mm/yy”; Purchase Price= ‘$$$$$$’; Forecast -2, 2, ??Renovation= $$$$$??display = '$';
				if( typeof(ParseUrl['IdSummary']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['IdSammary'])) != '' )
				{
					IdSummary = $.trim(decodeURIComponent(ParseUrl['IdSammary']));
				}
				else
				{
					IdSummary = 'N/A'
				}
				if( typeof(ParseUrl['AddressStr']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['AddressStr'])) != '' )
				{
					AddressData = $.trim(decodeURIComponent(ParseUrl['AddressStr'])).split('.').join(' ');
				}
				else
				{
					AddressData = '';
				}
				if( typeof(ParseUrl['City']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['City'])) != '' )
				{
					CityData = $.trim(decodeURIComponent(ParseUrl['City'])).split('.').join(' ');
				}
				else
				{
					CityData = '';
				}
				if( $('#summary').length > 0 )
				{
					newRow = $('#summary').dataTable().fnAddData( [IdSummary,AddressData, CityData, period/12, DatePurchase.replace('-',' / '), "$ " + Highcharts.numberFormat(price, 0,'.',','), $.trim(decodeURIComponent(filename.split('.').join(' ')))] );
					$('table#summary tr td').css('text-align', 'center');
				}
			}
			else if( typeof(DatePurchase_Default) != 'undefined' && typeof(Forcast_Positiv_Default) != 'undefined' && typeof(Forcast_Minus_Default) != 'undefined' && typeof(period_Default) != 'undefined' && typeof(price_Default) != 'undefined' )
			{
				DatePurchase_Default = DatePurchase_Default.replace(' - ','-');
				ManageGraph(filename, DatePurchase_Default, Forcast_Positiv_Default, Forcast_Minus_Default, period_Default, price_Default, filename2);
			}
		/*	var filename = 'Abbotsford.Homes.Top.50%';
var filename2 = 'Abbotsford.Homes.Lower.50%';
var DatePurchase = 'Feb - 06';
var Forcast_Positiv = 5;
var Forcast_Minus = 2;
var period = 240;
var price = 250000;*/

			else{
				if( typeof(TwoYearsIndex) != 'undefined' ) ManageGraphPercentages(filename, filename2, TwoYearsIndex);
				else	ManageGraphPercentages(filename, filename2);
				};
			$('input#ViewPercentages').click(function(){
				//alert('here');
				ManageGraphPercentages(filename, filename2);
			});
			$('input#ViewPercentages2Years').click(function(){
				//alert('here');
				ManageGraphPercentages(filename, filename2, 24);
			});

			
			// Load the data from the XML file 
			
			$("input[name='subgraph']").click(function(){
				filename2 = '';
				$("#button").attr("disabled", "disabled");
				var price = $('#purchase_price').val().replace(',', '').replace('.', '');
				var PurchasePrice = price;
				var Forcast_Minus = $('#forcast_minus').val();
				var Forcast_Positiv = $('#forcast_positiv').val();
				if( parseFloat(Forcast_Positiv) < 0 ) 
				{
					alert("Both Forcast+ and Forcast- values should be positiv");
				}
				else if( isNaN(parseFloat(price)) )
				{
					alert("Please input your Purchase Price");
					//$('#purchase_price').focus();
				}
				/*else if( $('#category_graph').val() == '' || $('#prop_type').val() == '' || $('#location').val() == '' || $('#market').val() == '' )
				{
					alert("Please check 'Market Areas', 'Location', 'Property type',  and 'Market' lists");
				}*/
				else
				{
					$('#containerHighcharts').hide();
					$('#containerHighcharts1').show();
					var options = setOptions(price);
				var DatePurchase = $('#purchase_month').val()+" - "+$('#purchase_year').val();
				var yearPurchase = parseInt('20'+$('#purchase_year').val());
				var HPlp = 0;
				var ForcastId = this.id;
				$('#CompareVal').val(this.id);
				var dataTableVal = new Array();

				//var filename = $('#location').val()+"."+$('#prop_type').val()+".HPIp."+$('#market').val();
				//var filename = $('#location').val().replace(/\s+/g,'.')+"."+$('#prop_type').val().replace(/\s+/g,'.')+"."+$('#market').val().replace(/\s+/g,'.');
				//alert(filename);
				if( $("input#FirstFilenameSelected").length > 0 )		var filename = $('input#FirstFilenameSelected').val();
				else var filename = filenamesSelect[$('#category_graph').val()][$('#location').val()][$('#prop_type').val()][$('#market').val()];
				$('#SecondFile').empty();
				$('#example').dataTable().fnClearTable();
				if( $('#summary').length > 0 ) $('#summary').dataTable().fnClearTable();
				var period = parseInt(this.id) > 0 ? parseInt(this.id) : 120;
				if( typeof(IdSummary) == 'undefined' ) IdSummary = 'N/A';
				if( typeof(AddressData) == 'undefined' ) AddressData = 'N/A';
				if( typeof(CityData) == 'undefined' ) CityData = $('input#FirstCitySelected').val();
				if( $('#summary').length > 0 )
				{
					$('#summary').dataTable().fnAddData( [IdSummary,AddressData, CityData, period/12, DatePurchase.replace('-','/'), "$ " + Highcharts.numberFormat(price, 0,'.',','), $.trim(decodeURIComponent(filename.split('.').join(' ')))] );
				}
				$('table#summary tr td').css('text-align', 'center');
				$.ajax({
					type: "POST",
					url: "/intranetimages/coughlinteam/users/6882/update_evalulator_summary.php",
					/*dataType: "xml",*/
					data: {
						HashId: IdSummary, 
						Date: '',
						City: CityData,
						Yr: period/12,
						DatePurchase: DatePurchase.replace('-',' / '),
						PricePurchase: "$ " + Highcharts.numberFormat(price, 0,'.',','),
						CityHPI: $.trim(decodeURIComponent(filename.split('.').join(' '))),
						Owner: $('#personnalize_agent').val(),
						Address: $('#personnalize_address').val(),
						Agent: $('#personnalize_company').val(),
					}, 
					success: function(data){
						//alert(data);
					},
					error: function() {
						//$( "div#Loading" ).hide( "slow" );
						//alert("An error occurred while processing your request.");
					}
				});
					//alert('excel_reader2.php?file='+filename+'&date='+DatePurchase+'&period='+this.id+'&value='+price);
					//$.get('http://coughlinteam.com/plugins/excel_reader2.php?file='+filename+'&date='+DatePurchase, function(xml) {
				//alert(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+this.id+'&value='+price);	//$.get(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+this.id+'&value='+price, function(xml) {
					//alert(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+this.id+'&value='+price);
					$.get(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+this.id+'&value='+price, function(xml) {
						//alert(document.location.origin+'/excel_reader2.php?file='+filename+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+this.id+'&value='+price);

						// Split the lines
						var $xml = $(xml);
						
					$xml.find('default').each(function(i, defaultValue) {
						price = $(defaultValue).text();
					});
					var FirstDate = $xml.find('categories item')[0];
					var LastDate = $xml.find('categories item').last();
					var LastMonth = $(LastDate).text();
					var MonthToday = LastMonth.substring(0,3);
					//alert(MonthToday);
					var YearToday = LastMonth.slice(-2);
					var DataTableDateStop = MonthToday +" "+currentYear;
					var DataTableContinue = true;
					
					if( MonthToday == 'Jan' ) MonthToday = 0;
					else if( MonthToday == 'Feb' ) MonthToday = 1;
					else if( MonthToday == 'Mar' ) MonthToday = 2;
					else if( MonthToday == 'Apr' ) MonthToday = 3;
					else if( MonthToday == 'May' ) MonthToday = 4;
					else if( MonthToday == 'Jun' ) MonthToday = 5;
					else if( MonthToday == 'Jul' ) MonthToday = 6;
					else if( MonthToday == 'Aug' ) MonthToday = 7;
					else if( MonthToday == 'Sep' ) MonthToday = 8;
					else if( MonthToday == 'Oct' ) MonthToday = 9;
					else if( MonthToday == 'Nov' ) MonthToday = 10;
					else if( MonthToday == 'Dec' ) MonthToday = 11;
					
					var YearToday2 = '20'+YearToday;
					
					var FirstMonth = $(FirstDate).text();
					var Month = FirstMonth.substring(0,3);
					var Year = FirstMonth.slice(-2);
					var ArrayMonth = new Array();
					if( Month == 'Jan' ) Month = 0;
					else if( Month == 'Feb' ) Month = 1;
					else if( Month == 'Mar' ) Month = 2;
					else if( Month == 'Apr' ) Month = 3;
					else if( Month == 'May' ) Month = 4;
					else if( Month == 'Jun' ) Month = 5;
					else if( Month == 'Jul' ) Month = 6;
					else if( Month == 'Aug' ) Month = 7;
					else if( Month == 'Sep' ) Month = 8;
					else if( Month == 'Oct' ) Month = 9;
					else if( Month == 'Nov' ) Month = 10;
					else if( Month == 'Dec' ) Month = 11;
					
					var MonthSelected = $('#purchase_month').val();
					if( MonthSelected == 'Jan' ) MonthSelected = 0;
					else if( MonthSelected == 'Feb' ) MonthSelected = 1;
					else if( MonthSelected == 'Mar' ) MonthSelected = 2;
					else if( MonthSelected == 'Apr' ) MonthSelected = 3;
					else if( MonthSelected == 'May' ) MonthSelected = 4;
					else if( MonthSelected == 'Jun' ) MonthSelected = 5;
					else if( MonthSelected == 'Jul' ) MonthSelected = 6;
					else if( MonthSelected == 'Aug' ) MonthSelected = 7;
					else if( MonthSelected == 'Sep' ) MonthSelected = 8;
					else if( MonthSelected == 'Oct' ) MonthSelected = 9;
					else if( MonthSelected == 'Nov' ) MonthSelected = 10;
					else if( MonthSelected == 'Dec' ) MonthSelected = 11;
					yearPurchase2 = '20'+ Year;
					PurchaseDateDiff = new Date(yearPurchase,MonthSelected,1);
					PurchaseDateHighcharts = Highcharts.dateFormat('%B %Y', Date.UTC(yearPurchase, MonthSelected, 1));
						
						// push series
						//var seriesOptions;
						var TwoGraphs = false;

						nbreSeries = $xml.find('series').length;
						var seriesOptions = 
						{
								data: [],
								name: decodeURIComponent(filename.split('.').join(' '))+' :',
								//name: $('#location').val() + ' ' + $('#prop_type').val() + ' ' +$('#market').val(),
								type: 'scatter',
								marker:{enabled:false}
							};
							options.series.push(seriesOptions);
							var ValDataTables;
							var PriceForcast;
						$xml.find('series').each(function(i, series) {
							var visibility = true;
							var colorValue = 'blue';
							var DatePointStart = Date.UTC(parseInt(yearPurchase2), Month , 01);
							var lineWidthValue = 0.5;
							var radiusValue = 3;
							var StartMonthData = 0;
							var StartYearData = 2005;
							if( i == 0 && nbreSeries == 6 ) 
							{
								colorValue = 'blue';
								var StartMonthData = Month;
								var StartYearData = parseInt(yearPurchase2);
							}
							else if( i == 1 && nbreSeries == 6 ) 
							{
								colorValue = 'green';
								var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
								var StartMonthData = MonthSelected;
								var StartYearData = yearPurchase;
							}
							else if( i == 0 && (nbreSeries == 4 || nbreSeries == 5) ) 
							{
								colorValue = 'green';
								if( nbreSeries == 4 )
								{
									var StartMonthData = Month;
									var StartYearData = parseInt(yearPurchase2);
								}
								else if( nbreSeries == 5 )
								{
									var StartMonthData = MonthSelected;
									var StartYearData = yearPurchase;
								}
							}
							else if( (i == 2 && nbreSeries == 6) || (i == 1 && nbreSeries == 5) ) 
							{
								colorValue = '#DDAA2B'; //yellow
								var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
								var lineWidthValue = 2.5;
								var radiusValue = 12;
								var StartMonthData = MonthSelected;
								var StartYearData = yearPurchase;
							}
							else if( (i == 3 && nbreSeries == 4) || (i == 4 && nbreSeries == 5) || (i == 5 && nbreSeries == 6) ) 
							{
								colorValue = '#DDAA2B'; //yellow
								var DatePointStart = Date.UTC(parseInt(YearToday2), MonthToday , 01);
								var lineWidthValue = 2.5;
								var radiusValue = 12;
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
							}
							else if( (i == 1 && nbreSeries == 4) || (i == 3 && nbreSeries == 6) || (i == 2 && nbreSeries == 5)  )
							{
								colorValue = 'red'; //yellow
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
								visibility = false;
							}
							else if( (i == 2 && nbreSeries == 4) || (i == 4 && nbreSeries == 6) || (i == 3 && nbreSeries == 5)  )
							{
								colorValue = 'blue'; //yellow
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
								visibility = false;
							}
							if( ForcastId == 3000 ) visibility = true;
							var seriesOptions = {
								type: 'area',
								name: $(series).find('name').text(),
								color : colorValue,//(i > 0 ? 'green' : 'blue'),
								data: [],
								marker: {
									enabled: true,
									lineWidth : lineWidthValue,
									radius : radiusValue,
									symbol : 'circle'
								},
							};
							// push data points
							var DataValues = new Array();
							var DataValues2 = new Array();
							var DataValuesDataTables = new Array();
							var HomeHistorySerie = false;
							$(series).find('data point').each(function(i, point) {
								//alert($(series).find('name').text());
							if( $(series).find('name').text() == 'Your Home History' )	
							{
								HomeHistorySerie = true;
							}
								
								if( $(series).find('name').text() != 'Forecast+' && $(series).find('name').text() != 'Forecast-' && $(series).find('name').text() != "Current Value" )
								{//alert(HomeHistorySerie);
									if( parseFloat($(point).text()) )
									{
										TwoGraphs = true;
										if( !HPlp ) HPlp = parseFloat($(point).text());
										//alert(parseFloat($(point).text()) * price);
										price = parseFloat($(point).text()) * price / HPlp;
										//price2 = price * 100 / PurchasePrice - 100;
										//price2 = (parseFloat($(point).text()) * 100) - 100;
										//alert(price);
										HPlp = parseFloat($(point).text());
									}
									if( HomeHistorySerie )
									{
										PriceForcast = price;
										//alert(PriceForcast);
									}
								}
								else if( $(series).find('name').text() == "Current Value" ) price = PriceForcast;
								else
								{
									if( parseFloat($(point).text()) == 0 ) 
									{
										price = PriceForcast;
										
									}
									else
									{
										price += PriceForcast * parseFloat($(point).text())/100;
									}
								}
								price2 = price * 100 / PurchasePrice - 100;
								DataValues.push(Math.round(price));
								DataValues2.push(Math.round(price2));
								//alert(price);
								DataValuesDataTables.push(Math.round(price));
								if( $(series).find('name').text() == "Current Value" )	ValDataTables = "$" + Highcharts.numberFormat(PriceForcast, 0,'.',',');
							});
							
							dLen = DataValues.length;
							//if( $(series).find('name').text() == "Current Value" )	ValDataTables = "$" + Highcharts.numberFormat(DataValues[dLen - 1], 0,'.',',');

							for (var indexDate = 0; indexDate < dLen; indexDate++) {//alert(StartYearData); alert(StartMonthData + indexDate); alert(DataValues[indexDate]);
								if( indexDate == 0 ) var percentages = '';
								else{
									PercentagesColor = (DataValues2[indexDate] >= 0 ? 'green' : 'red' );
									percentages = (DataValues2[indexDate] > 0 ? '+' : '' ) + DataValues2[indexDate];
									percentages = ' <span style="color:'+PercentagesColor+'">('+percentages+'%)</span>';
								}
								//if( $(series).find('name').text() == "Current Value" ) indexDate = 1;
								seriesOptions.data.push({								
								y: DataValues[indexDate],
								x: Date.UTC(StartYearData, StartMonthData + indexDate, 1),
								color: '#FF0000',
								percentage : percentages,
							});
							
								if( indexDate < dLen && !dataTableVal[Highcharts.dateFormat('%b %Y', Date.UTC(StartYearData, StartMonthData + indexDate, 1))] && DataTableContinue && $(series).find('name').text() == 'Your Home History' ){
									//alert(Highcharts.dateFormat('%b %Y', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)));
									dataTableVal[Highcharts.dateFormat('%b %Y', Date.UTC(StartYearData, StartMonthData + indexDate, 1))] = true;
									newRow = $('#example').dataTable().fnAddData( [
										Highcharts.dateFormat('%b %Y', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)),
										"$" + Highcharts.numberFormat(DataValuesDataTables[dLen - indexDate - 1], 0,'.',','),
									] );
									if( $('#purchase_month').val() != Highcharts.dateFormat('%b', Date.UTC(parseInt(YearToday2), MonthToday - indexDate, 1)) )
									{
										var oSettings = $('#example').dataTable().fnSettings();
										var nTr = oSettings.aoData[ newRow[0] ].nTr;
										$('td', nTr)[0].setAttribute( 'class', 'WrongMonth' );
										$('td', nTr)[1].setAttribute( 'class', 'WrongMonth' );
									}
									
									if( DataTableDateStop == Highcharts.dateFormat('%b %Y', Date.UTC(StartYearData, StartMonthData + indexDate, 1)) ) DataTableContinue = false;
								}
							}
							// add it to the options
							options.series.push(seriesOptions);
						});
						$('#example').dataTable().fnUpdate( ValDataTables, 0, 1 );
						var chart = new Highcharts.Chart(options);
						var SeriesOnGraph = chart.series.length;
						if( $('#CompareVal').val() != 3000 )
						{
							chart.series[SeriesOnGraph-2].hide();
							chart.series[SeriesOnGraph-3].hide();
						}

						
						$('#containerHighcharts1').hide();
						$('#containerHighcharts').show();
						
					if( $.trim($('#personnalize_address').val()) != '' || $.trim($('#personnalize_agent').val()) != '' || $.trim($('#personnalize_company').val()) ) //typeof(ParseUrl['Address']) != 'undefined' && $.trim(decodeURIComponent(ParseUrl['Address'])) != '' )
					{
						var title = '<div style="width:800px; display:inline-block; text-align:left;"><div style="float:left; width:380px;">';
						if( $.trim($('#personnalize_address').val()) != '' ) title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red">'+$('#personnalize_address').val()+'</span></span>';
						else
						{
							title += '<span style="color:#000; font-weight:normal; font-size:20px; text-align:left;">Market History : <span style="color:red"><a href="javascript:void(0);" onclick="$(\'#popup_box\').fadeIn(\'slow\');" style="color:red; text-decoration:none;">Click here to Input Your Address</a></span></span>';
						}

						if( $.trim($('#personnalize_agent').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">Provided for : '+$('#personnalize_agent').val()+'</span>';
						if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:13px; text-align:left;">By : '+$('#personnalize_company').val()+'</span>';
						title += '</div><div style="float:right;"><img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" /></div>';
						//if( $.trim($('#personnalize_company').val()) != '' ) title += '<br /><span style="color:#000; font-weight:normal; font-size:14px; text-align:left;">Company : '+$('#personnalize_company').val()+'</span>';
						title += '</div>';
						chart = $('#containerHighcharts').highcharts();
						chart.xAxis[0].update({
							 title:{
								text: title,
								useHTML: true,
							 }
						});
						chart.setSize(927, 600);
					}					

						$('.SecondFileDiv').css('display','block');
						$("div#CityMenu2").css("display","block");
						$('#ContainerPersonnalizeReport').css('display','block');
			if( Object.keys(filenamesSelect).length > 1 ) $('#category_graph_second').append('<option value="">Choose a category</option>');
			if( OrderCategories.length > 0 )
			{
				for( i in OrderCategories )
				{
					if( i != 'removeItem' )
						$('#category_graph_second').append('<option value="'+OrderCategories[i]+'" >'+OrderCategories[i]+'</option>');
				}
			}
			else
			{
				for( i in filenamesSelect )
				{
					if( i != 'removeItem' )
						$('#category_graph_second').append('<option value="'+i+'" >'+i+'</option>');
				}
				sortDropDownListByText('category_graph_second');
			}
			RedColorDropDown();
			if( Object.keys(filenamesSelect).length == 1 )
			{
				var i = $('#category_graph_second').val();
				if( Object.keys(filenamesSelect[i]).length > 1 ) $('#location_second').append('<option value="">Pick a second location</option>');
				for( j in filenamesSelect[i] )
				{
					if( j != 'removeItem' )
						$('#location_second').append('<option value="'+j+'" >'+j+'</option>');
				}
				sortDropDownListByText('location_second');
				if( Object.keys(filenamesSelect[i]).length == 1 )
				{
					var k = $('#location_second').val();
					if( Object.keys(filenamesSelect[i][k]).length > 1 ) $('#prop_type_second').append('<option value="">Choose a property type</option>');
					for( l in filenamesSelect[i][k] )
					{
						if( l != 'removeItem' )
							$('#prop_type_second').append('<option value="'+l+'" >'+l+'</option>');
					}
					sortDropDownListByText('prop_type_second');
					if( Object.keys(filenamesSelect[i][k]).length == 1 )
					{
						var m = $('#prop_type_second').val();
						if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market_second').append('<option value="">Choose one of the markets below</option>');
						for( n in filenamesSelect[i][k][m] )
						{
							if( n != 'removeItem' )
							{
								var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
								$('#market_second').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
							}
						}
						if( $('#market_second').val() != '' ) $("#button").removeAttr("disabled");
						$('#market_second').change(function(){if( $(this).val() == '' ) $("#button").attr("disabled", "disabled"); else $("input#button").removeAttr("disabled");RedColorDropDown();});
						sortDropDownListByText('market');
					}
					else
					{
						$('#prop_type_second').change(function(){
							var m = $('#prop_type_second').val();
							$('#market_second').empty();
							$('#market_second').unbind('change');
							$("#button").attr("disabled", "disabled");
							if( m != '' )
							{
								if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market_second').append('<option value="">Choose one of the markets below</option>');
								for( n in filenamesSelect[i][k][m] )
								{
									if( n != 'removeItem' )
									{
										var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
										$('#market_second').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
									}
								}
								if( $('#market_second').val() != '' ) $("#button").removeAttr("disabled");
								$('#market_second').change(function(){if( $(this).val() == '' ) $("#button").attr("disabled", "disabled"); else $("input#button").removeAttr("disabled");RedColorDropDown();});
								sortDropDownListByText('market');
								
							}
							RedColorDropDown();
						});
					}
				}
			}
			$('#category_graph_second').change(function(){
				var i = $('#category_graph_second').val();
				$('#prop_type_second').empty();
				$('#location_second').empty();
				$('#market_second').empty();
				$('#prop_type_second').unbind('change');
				$('#location_second').unbind('change');
				$('#market_second').unbind('change');
				$("#button").attr("disabled", "disabled");
				if( i != '' )
				{
					$('#location_second').append('<option value="">Pick your location</option>');
					for( j in filenamesSelect[i] )
					{
						if( j != 'removeItem' )
							$('#location_second').append('<option value="'+j+'" >'+j+'</option>');
					}
					sortDropDownListByText('location_second');
					$('#location_second').change(function(){
						var k = $('#location_second').val();
						$('#prop_type_second').empty();
						$('#market_second').empty();
						$('#prop_type_second').unbind('change');
						$('#market_second').unbind('change');
						$("#button").attr("disabled", "disabled");
						if( k != '' )
						{
							if( Object.keys(filenamesSelect[i][k]).length > 1 ) $('#prop_type_second').append('<option value="">Choose a property type</option>');
							for( l in filenamesSelect[i][k] )
							{
								if( l != 'removeItem' )
									$('#prop_type_second').append('<option value="'+l+'" >'+l+'</option>');
							}
							sortDropDownListByText('prop_type_second');

							if( Object.keys(filenamesSelect[i][k]).length == 1 )
							{
								var m = $('#prop_type_second').val();
								if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market_second').append('<option value="">Choose one of the markets below</option>');
								for( n in filenamesSelect[i][k][m] )
								{
									if( n != 'removeItem' )
									{
										var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
										$('#market_second').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
									}
								}
								if( $('#market_second').val() != '' ) $("#button").removeAttr("disabled");
								$('#market_second').change(function(){if( $(this).val() == '' ) $("#button").attr("disabled", "disabled"); else $("input#button").removeAttr("disabled");RedColorDropDown();});
								sortDropDownListByText('market_second');
							}
							else
							{
								$('#prop_type_second').change(function(){
									var m = $('#prop_type_second').val();
									$('#market_second').empty();
									$('#market_second').unbind('change');
									$("#button").attr("disabled", "disabled");
									if( m != '' )
									{
										if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market_second').append('<option value="">Choose one of the markets below</option>');
										for( n in filenamesSelect[i][k][m] )
										{
											if( n != 'removeItem' )
											{
												var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
												$('#market_second').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
											}
										}
										if( $('#market_second').val() != '' ) $("#button").removeAttr("disabled");
										$('#market_second').change(function(){if( $(this).val() == '' ) $("#button").attr("disabled", "disabled"); else $("input#button").removeAttr("disabled");RedColorDropDown();});
										sortDropDownListByText('market_second');
										
									}
									RedColorDropDown();
								});
							}




							$('#prop_type_second').change(function(){
								var m = $('#prop_type_second').val();
								$('#market_second').empty();
								$('#market_second').unbind('change');
								$("#button").attr("disabled", "disabled");
								if( m != '' )
								{
									if( Object.keys(filenamesSelect[i][k][m]).length > 1 ) $('#market_second').append('<option value="">Choose one of the markets below</option>');
									for( n in filenamesSelect[i][k][m] )
									{
										if( n != 'removeItem' )
										{
											var IndexTextHelper = i + '_' + k + '_' + m + '_' + n;
											$('#market_second').append('<option title="'+TextHelper[IndexTextHelper]+'" value="'+n+'" >'+n+'</option>');
										}
									}
									if( $('#market_second').val() != '' ) $("#button").removeAttr("disabled");
									$('#market_second').change(function(){if( $(this).val() == '' ) $("#button").attr("disabled", "disabled"); else $("input#button").removeAttr("disabled");RedColorDropDown();});
									sortDropDownListByText('market_second');
								}
								RedColorDropDown();
							});
						}
						RedColorDropDown();
					});
				}
				RedColorDropDown();
			});
					});
				}
			});
			
			    $('#button').click(function() {
					$("#button").attr("disabled", "disabled");
					var chart = $('#containerHighcharts').highcharts();

				var price = $('#purchase_price').val().replace(',', '').replace('.', '');
				var PurchasePrice = price;				
				var Forcast_Minus = $('#forcast_minus').val();
				var Forcast_Positiv = $('#forcast_positiv').val();
				var SecondFileSelected = $("#SecondFile");
				if( parseFloat(Forcast_Minus) < 0 || parseFloat(Forcast_Positiv) < 0 ) 
				{
					alert("Both Forcast+ and Forcast- values should be positiv");
					$("input#button").removeAttr("disabled");
				}
				else if( isNaN(parseFloat(price)) )
				{
					alert("Please input your Purchase Price");
					$("input#button").removeAttr("disabled");
				}
				else
				{
					if( nbreSeries+1 < chart.series.length ){
						for (var i = 0 ; i < chart.series.length; i++) {
							var NewSerieToDelete = nbreSeries+1;
						   chart.series[NewSerieToDelete].remove();
						}
					}
					$('#containerHighcharts').hide();
					$('#containerHighcharts1').show();
					var options = {
						chart: {
							zoomType: 'x',
							spacingRight: 20,
							renderTo: 'containerHighcharts',
							type: 'area',
							//marginRight: 130,
							//marginBottom: 25
							  className: 'skies',
							  borderWidth: 0,
							  plotShadow: true,
							  plotBackgroundImage: '/intranetimages/coughlinteam/users/6882/skies.jpg',
							  //plotBackgroundImage: 'https://www.highcharts.com/demo/gfx/skies.jpg',
							  plotBackgroundColor: {
								 linearGradient: [0, 0, 250, 500],
								 stops: [
									[0, 'rgba(203, 213, 223, 1)'],
									[1, 'rgba(203, 213, 223, 0.5)']
								 ]
							  },
							  plotBorderWidth: 1
						},
			exporting: {
					type:"image/png",
					url:"https://export.highcharts.com/",
					buttons:{
						contextButton:{symbol:"menu",
						_titleKey:"contextButtonTitle",
						menuItems: [
						{
							textKey:"printChart",
							onclick:function(){this.print()}
						},
						{
							separator:!0
						},
						{
							textKey:"downloadPNG",
							onclick:function(){this.exportChart()}
						},
						{
							textKey:"downloadJPEG",
							onclick:function(){this.exportChart({type:"image/jpeg"})}
						},
						/*{
							textKey:"downloadPDF",
							onclick:function(){this.exportChart({type:"application/pdf"})}
						},*/
						{
							text:"Download GIF",
							onclick:function(){this.exportChart({type:"image/gif"})}
						},
						/*{
							textKey:"downloadSVG",
							onclick:function(){this.exportChart({type:"image/svg+xml"})}
						},*/
						{
							text:"Personalize",
							onclick:function(){$('#popup_box').fadeIn("slow");$('html, body').animate({scrollTop: $("#popup_box").offset().top}, 500);$('#personnalize_address').focus();}
						},
						{
							text: 'Save settings',
							onclick: function() {  
								ParseUrl = getUrlVars();
								var IdSummary;
								var AddressData;
								var Yr;
								var DatePurchase;
								var PricePurchase;
								if( typeof(ParseUrl['IdSummary']) == 'undefined') IdSummary = '';
								if( typeof(ParseUrl['AddressStr']) == 'undefined') AddressData = ( $.trim($('#personnalize_address').val()) != '' ? $.trim($('#personnalize_address').val()) : '' );
								else AddressData = ParseUrl['AddressStr'];
								if( typeof(ParseUrl['range']) == 'undefined') Yr = $('#CompareVal').val()/12;
								else Yr = ParseUrl['range'];
								if( typeof(ParseUrl['DatePurchase']) == 'undefined') DatePurchase = $('#purchase_month').val()+"-"+$('#purchase_year').val();
								else DatePurchase = ParseUrl['DatePurchase'];
								if( typeof(ParseUrl['PricePurchase']) == 'undefined') PricePurchase = $('#purchase_price').val().replace(',', '').replace('.', '');
								else PricePurchase = ParseUrl['PricePurchase'];
								$.ajax({
									type: "POST",
									url: "/SaveDataToTable.php",
									/*dataType: "xml",*/
									data: {
										HashId: IdSummary, 
										Address: AddressData,
										Yr: Yr,
										DatePurchase: DatePurchase.replace('-',' / '),
										PricePurchase: "$ "+Highcharts.numberFormat(PricePurchase, 0,'.',',')
									}, 
									success: function(data){
										alert(data);
									},
									error: function() {
										//$( "div#Loading" ).hide( "slow" );
										alert("An error occurred while processing your request.");
									}
								});

								//alert('Settings saved');
							}
						}
						]
					}
				}
			},
						tooltip: {
							style: {
								fontWeight: 'bold',
								fontSize: '16px',
							},
							formatter: function() {
								var s = Highcharts.dateFormat('%B %Y', this.x);
								$.each(this.points, function(i, point) {
									s += '<br /><span style="color:' + this.series.color +'">' + this.series.name +'</span>: $ '+ Highcharts.numberFormat(this.y, 0,'.',',');
								});
								return s;
							},
							shared: true,
						},
						title: {
							text: 'High HPlp'
						},
           xAxis: {
                type: 'datetime',
                maxZoom: 14 * 24 * 3600000, // fourteen days
                tickInterval: 24 * 3600 * 31000 * 3, // one month
                title: {
					text: document.ontouchstart === undefined ?
						'<img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" />' : '<img src="/intranetimages/coughlinteam/users/6882/zoomgif0-3.gif" />',/*Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in' :
			'Drag over area to <span style="font-color:#ff0000;">ZOOM</span> in',*/
					style: {
						color: '#FF0000',
						font: 'bold 18px Helvetica',
					},
					useHTML: true,
                },
                labels: {
   						rotation: -45,
						style: {
							font: '14px Helvetica',
						}
					}
              // categories: []
            },
				yAxis: {
					title: {
						text: ''
					},
					labels: {
						formatter: function () {
							return "$" + Highcharts.numberFormat(this.value, 0,'.',',');
						},
						style: {
							//color: '#4572A7',
							font: 'bold 14px Helvetica',
						}
					},
					gridLineWidth: 2,
					lineWidth:1,
				},
						legend: {
							align: 'top',
							verticalAlign: 'top',
							x: 0,
							y: 50,
							margin : 20,
						},
						plotOptions: {
							area: {
								fillColor: {
									linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1},
									stops: [
										/*[0, Highcharts.getOptions().colors[0]],
										[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0).get('rgba')]*/
										[0, 'rgba(208, 48, 85,0.5)'],
										[1, 'rgba(208, 48, 85,0)']										
									]
								},
								lineWidth: 1,
								marker: {
									enabled: true
								},
								shadow: false,
								states: {
									hover: {
										lineWidth: 1
									}
								},
								threshold: null
							}
						},
						series: []
					};
				var DatePurchase = $('#purchase_month').val()+" - "+$('#purchase_year').val();
				var yearPurchase = parseInt('20'+$('#purchase_year').val());
				var HPlp = 0;
				var ForcastId = this.id;
				//$('#example').dataTable().fnClearTable();
				var dataTableVal = new Array();
					if( $("input#FirstFilenameSelected2").length > 0 )		filename2 = $('input#FirstFilenameSelected2').val();
					else filename2 = filenamesSelect[$('#category_graph_second').val()][$('#location_second').val()][$('#prop_type_second').val()][$('#market_second').val()];
					$.get(document.location.origin+'/excel_reader2.php?file='+filename2+'&date='+DatePurchase+'&forcast_positiv='+Forcast_Positiv+'&forcast_minus='+Forcast_Minus+'&period='+$('#CompareVal').val()+'&value='+price, function(xml) {

						// Split the lines
						var $xml = $(xml);
						
					$xml.find('default').each(function(i, defaultValue) {
						price = $(defaultValue).text();
					});
					var FirstDate = $xml.find('categories item')[0];
					var LastDate = $xml.find('categories item').last();
					var LastMonth = $(LastDate).text();
					var MonthToday = LastMonth.substring(0,3);
					var YearToday = LastMonth.slice(-2);
					var DataTableDateStop = MonthToday +" "+currentYear;
					var DataTableContinue = true;
					
					if( MonthToday == 'Jan' ) MonthToday = 0;
					else if( MonthToday == 'Feb' ) MonthToday = 1;
					else if( MonthToday == 'Mar' ) MonthToday = 2;
					else if( MonthToday == 'Apr' ) MonthToday = 3;
					else if( MonthToday == 'May' ) MonthToday = 4;
					else if( MonthToday == 'Jun' ) MonthToday = 5;
					else if( MonthToday == 'Jul' ) MonthToday = 6;
					else if( MonthToday == 'Aug' ) MonthToday = 7;
					else if( MonthToday == 'Sep' ) MonthToday = 8;
					else if( MonthToday == 'Oct' ) MonthToday = 9;
					else if( MonthToday == 'Nov' ) MonthToday = 10;
					else if( MonthToday == 'Dec' ) MonthToday = 11;
					
					var YearToday2 = '20'+YearToday;
					
					var FirstMonth = $(FirstDate).text();
					var Month = FirstMonth.substring(0,3);
					var Year = FirstMonth.slice(-2);
					var ArrayMonth = new Array();
					if( Month == 'Jan' ) Month = 0;
					else if( Month == 'Feb' ) Month = 1;
					else if( Month == 'Mar' ) Month = 2;
					else if( Month == 'Apr' ) Month = 3;
					else if( Month == 'May' ) Month = 4;
					else if( Month == 'Jun' ) Month = 5;
					else if( Month == 'Jul' ) Month = 6;
					else if( Month == 'Aug' ) Month = 7;
					else if( Month == 'Sep' ) Month = 8;
					else if( Month == 'Oct' ) Month = 9;
					else if( Month == 'Nov' ) Month = 10;
					else if( Month == 'Dec' ) Month = 11;
					
					var MonthSelected = $('#purchase_month').val();
					if( MonthSelected == 'Jan' ) MonthSelected = 0;
					else if( MonthSelected == 'Feb' ) MonthSelected = 1;
					else if( MonthSelected == 'Mar' ) MonthSelected = 2;
					else if( MonthSelected == 'Apr' ) MonthSelected = 3;
					else if( MonthSelected == 'May' ) MonthSelected = 4;
					else if( MonthSelected == 'Jun' ) MonthSelected = 5;
					else if( MonthSelected == 'Jul' ) MonthSelected = 6;
					else if( MonthSelected == 'Aug' ) MonthSelected = 7;
					else if( MonthSelected == 'Sep' ) MonthSelected = 8;
					else if( MonthSelected == 'Oct' ) MonthSelected = 9;
					else if( MonthSelected == 'Nov' ) MonthSelected = 10;
					else if( MonthSelected == 'Dec' ) MonthSelected = 11;
					yearPurchase2 = '20'+ Year;
						
						// push series
						//var seriesOptions;
						var TwoGraphs = false;
						var nbreSeries = $xml.find('series').length;
						var seriesOptions = 
						{
								data: [],
								//name: $('#location_second').val() + ' ' +$('#prop_type_second').val() + ' ' + $('#market_second').val(),
								name: decodeURIComponent(filename2.split('.').join(' '))+':',
								type: 'scatter',
								marker:{enabled:false}
							};
							chart.addSeries(seriesOptions);
							var PriceForcast;
						$xml.find('series').each(function(i, series) {
							var visibility = true;
							var colorValue = '#C03000';
							var DatePointStart = Date.UTC(parseInt(yearPurchase2), Month , 01);
							var lineWidthValue = 0.5;
							var radiusValue = 3;
							var StartMonthData = 0;
							var StartYearData = 2005;
							if( i == 0 && nbreSeries == 6 ) 
							{
								colorValue = '#C03000';
								var StartMonthData = Month;
								var StartYearData = parseInt(yearPurchase2);
							}
							else if( i == 1 && nbreSeries == 6 ) 
							{
								colorValue = '#4C1B1B';
								colorValue = '#EB2F86';
								var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
								var StartMonthData = MonthSelected;
								var StartYearData = yearPurchase;
							}
							else if( i == 0 && (nbreSeries == 4 || nbreSeries == 5) ) 
							{
								colorValue = '#4C1B1B';
								colorValue = '#EB2F86';
								if( nbreSeries == 4 )
								{
									var StartMonthData = Month;
									var StartYearData = parseInt(yearPurchase2);
								}
								else if( nbreSeries == 5 )
								{
									var StartMonthData = MonthSelected;
									var StartYearData = yearPurchase;
								}
							}
							else if( (i == 2 && nbreSeries == 6) || (i == 1 && nbreSeries == 5) ) 
							{
								colorValue = '#DDAA2B'; //yellow
								var DatePointStart = Date.UTC(yearPurchase, MonthSelected , 01);
								var lineWidthValue = 2.5;
								var radiusValue = 12;
								var StartMonthData = MonthSelected;
								var StartYearData = yearPurchase;
							}
							else if( (i == 3 && nbreSeries == 4) || (i == 4 && nbreSeries == 5) || (i == 5 && nbreSeries == 6) ) 
							{
								colorValue = '#666666'; //yellow
								var DatePointStart = Date.UTC(parseInt(YearToday2), MonthToday , 01);
								var lineWidthValue = 2.5;
								var radiusValue = 12;
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
							}
							else if( (i == 1 && nbreSeries == 4) || (i == 3 && nbreSeries == 6) || (i == 2 && nbreSeries == 5)  )
							{
								colorValue = 'red'; //yellow
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
								visibility = false;
							}
							else if( (i == 2 && nbreSeries == 4) || (i == 4 && nbreSeries == 6) || (i == 3 && nbreSeries == 5)  )
							{
								colorValue = 'blue'; //yellow
								var StartMonthData = MonthToday;
								var StartYearData = parseInt(YearToday2);
								visibility = false;
							}
							if( ForcastId == 3000 ) visibility = true;
							var seriesOptions = {
								type: 'area',
								name: $(series).find('name').text(),
								color : colorValue,//(i > 0 ? 'green' : 'blue'),
								data: [],
								marker: {
									enabled: true,
									lineWidth : lineWidthValue,
									radius : radiusValue,
									symbol : 'circle'
								},
							};
							// push data points
							var DataValues = new Array();
							var DataValues2 = new Array();
							var HomeHistorySerie = false;
							$(series).find('data point').each(function(i, point) {
								//alert($(series).find('name').text());
							if( $(series).find('name').text() == 'Your Home History' )	
							{
								HomeHistorySerie = true;
							}
								
								if( $(series).find('name').text() != 'Forecast+' && $(series).find('name').text() != 'Forecast-' && $(series).find('name').text() != "Current Value" )
								{//alert(HomeHistorySerie);
									if( parseFloat($(point).text()) )
									{
										TwoGraphs = true;
										if( !HPlp ) HPlp = parseFloat($(point).text());
										//alert(parseFloat($(point).text()) * price);
										price = parseFloat($(point).text()) * price / HPlp;
										//price2 = price * 100 / PurchasePrice - 100;
										//price2 = (parseFloat($(point).text()) * 100) - 100;
										//alert(price);
										HPlp = parseFloat($(point).text());
									}
									if( HomeHistorySerie )
									{
										PriceForcast = price;
										//alert(PriceForcast);
									}
								}
								else if( $(series).find('name').text() == "Current Value" ) price = PriceForcast;
								else
								{
									if( parseFloat($(point).text()) == 0 ) 
									{
										price = PriceForcast;
										
									}
									else
									{
										price += PriceForcast * parseFloat($(point).text())/100;
									}
								}
								price2 = price * 100 / PurchasePrice - 100;
								DataValues.push(Math.round(price));
								DataValues2.push(Math.round(price2));
							});
							/*$(series).find('data point').each(function(i, point) {
								if( parseFloat($(point).text()) )
								{
									TwoGraphs = true;
									if( !HPlp ) HPlp = parseFloat($(point).text());
									price = parseFloat($(point).text()) * price / HPlp;
									price2 = price * 100 / PurchasePrice - 100;
									
									HPlp = parseFloat($(point).text());
									DataValues.push(Math.round(price));
									DataValues2.push(Math.round(price2));
								}
							});*/
							
							dLen = DataValues.length;

							for (var indexDate = 0; indexDate < dLen; indexDate++) {//alert(StartYearData); alert(StartMonthData + indexDate); alert(DataValues[indexDate]);
								if( indexDate == 0 ) var percentages = '';
								else{
									PercentagesColor = (DataValues2[indexDate] >= 0 ? 'green' : 'red' );
									percentages = (DataValues2[indexDate] > 0 ? '+' : '' ) + DataValues2[indexDate];
									percentages = ' <span style="color:'+PercentagesColor+'">('+percentages+'%)</span>';									
								}
								seriesOptions.data.push({
								
								y: DataValues[indexDate],
								x: Date.UTC(StartYearData, StartMonthData + indexDate, 1),
								color: '#FF0000',
								percentage : percentages,
							});

							}
							chart.addSeries(seriesOptions);
						});
						$('#containerHighcharts1').hide();
						$('#containerHighcharts').show();
						$("input#button").removeAttr("disabled");
						var SeriesOnGraph = chart.series.length;
						if( $('#CompareVal').val() != 3000 )
						{
							chart.series[SeriesOnGraph-2].hide();
							chart.series[SeriesOnGraph-3].hide();
						}
					});
				}
    });
	$("input#ClickToAdd").click(function(){
		var div = $("div#fileAdd"),
		curHeight = div.height(),
		autoHeight = curHeight > 0 ? 0 : div.css('height', 'auto').height();
		div.height(curHeight).animate({height: autoHeight}, 1000);
		curHeight == 0 ? div.css('border', '#ccc solid 1px') : div.css('border', 'none');
	});		
		});