/** Calendario personalizado para Lemonk
*
*/

/** TEST
var ini=new Date('05/15/2010');
var fin=new Date('05/16/2010'); //2678400000
ini=new Date(ini.valueOf()+86400000)
alert(ini);
//alert(new Date(ini+86400000));
alert(fin);
alert(fin-ini);
*/

//alert("language "+lang);


function ArraySearchDate(arr, date) {
// Arreglo con las fechas a bloquear --> JIMMY M.
  for(var i=0; i<arr.length; i++) {
    var date2=new Date(arr[i]);
	//alert(date2.getTime());
	//alert(date);
	//alert(date2.getTime());
	//if (date2.getTime() == date) return true;
	//if (date2.getTime() == date) return true;
	if (date2.valueOf() == date) return true;
  }
  return false;
}

function inputCalendar(inputname, min, max, arr, calendars, reserved, position, inputname2, calcular_precios, lang){
	
//Aplica las propiedades del calendario al inptu ingresado--> min es la fecha minima, max: es la fecha maxima, arr --> arreglo de fechas a bloquear --> JIMMY M.
	if(calcular_precios==undefined){
		calcular_precios=false;
	}
	if(inputname2==undefined){
		inputname2='';
	}
	if(position==undefined){
		position='right';//['top'|'left'|'right'|'bottom']
	}
	if(calendars==undefined){
		calendars=1;
	}
	var now = new Date();
	//now=(now.getMonth()+2)+"/"+now.getDate()+"/"+now.getFullYear();
	now=(now.getMonth()+1)+"/"+now.getDate()+"/"+now.getFullYear();
	//now=(now.getFullYear()+"-"+(now.getMonth()+3)+"-"+now.getDate());
	now = new Date(now);
	min = new Date(min);
	max = new Date(max);
	//alert(now);
	/*
	while(min_date<=max_date){
				var =new Date(min_date);
				var l=arr2.length;
				min_date=min_date.valueOf()+86400000;//VALOR DE UN DIA  86400000
			}
	*/
	
	var now_format=now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
	//alert(now_format);
	var bool_val_date=($("#"+inputname).val());
	$("#"+inputname).attr("readonly","readonly");//para colocar en readonly y no permitir que se escriban valores en el input
	$("#"+inputname).DatePicker({
		id:inputname+"_",
		//id:inputname,
		format:'Y-m-d',
		//date: now_format,
		date:$("#"+inputname).val(),
		//date: now_format,
		current: (bool_val_date)?$("#"+inputname).val():now_format,
		//current: $("#"+inputname).val(),
		starts: 1,
		calendars: calendars,
		position: position,
		onBeforeShow: function(){
			if(bool_val_date){
				$("#"+inputname).DatePickerSetDate($("#"+inputname).val(), true);
			}
			else{
				$("#"+inputname).DatePickerSetDate(now_format);
			}
			//alert(now_format);
		},
		onRender: function(date) {
			var class_name=false;
			class_name=getClassDate(date, undefined, undefined, arr, reserved);
			if(class_name===false){
				date.valueOf() == now.valueOf() ? 'datepickerSpecial' : false;
			}
			/*
			return {
				className: class_name
			}
			*/
			
			var date_disable=false;
			if(arr!=undefined){//sobrecarga de la funcion
				date_disable=ArraySearchDate(arr,date.valueOf());
			}
			var boolean_min=false;
			if(min!=undefined){
				boolean_min=date.valueOf() < min.valueOf();
			}
			var boolean_max=false;
			if(max!=undefined){
				boolean_max=date.valueOf() > max.valueOf();
			}
			return {
				disabled: ( boolean_min || boolean_max || date_disable),
				className: class_name
			}
			
		},
		onChange: function(formated, dates){
			$("#"+inputname).val(formated);
			if(inputname2!=''){
				if(document.getElementById(inputname2)!=undefined){
					$("#"+inputname2).val(formated);
				}
				if(calcular_precios){
					colocarPrecios(inputname, inputname2, lang);
				}
			}
			/*
			if ($('#closeOnSelect input').attr('checked')) {
				$('#inputDate').DatePickerHide();
			}
			*/
			$("#"+inputname).DatePickerHide();
		}
		
	});
}

function isArray(obj) {
    return obj.constructor == Array;
}



function getClassDate(date, meddium_disable, high_disable, reserved, lock, css){
	if(css==undefined){
		css='';
	}
	var boolean_meddium=false;
	var boolean_high=false;
	var boolean_reserved=false;
	var boolean_lock=false;
	var class_name=false;
	if(meddium_disable!=undefined){
		boolean_meddium=ArraySearchDate(meddium_disable,date.valueOf());
	}
	if(reserved!=undefined  && isArray(reserved)){
		boolean_reserved=ArraySearchDate(reserved,date.valueOf());
	}
	if(lock!=undefined  && isArray(lock)){
		boolean_lock=ArraySearchDate(lock,date.valueOf());
	}
	if(high_disable!=undefined  && isArray(high_disable)){
		boolean_high=ArraySearchDate(high_disable,date.valueOf());
	}
	
	if(boolean_lock){
		if(css=='input'){
			class_name='datepickerSpecialLock2'
		}
		else{
			class_name='datepickerSpecialLock'
		}
	}
	if(boolean_reserved){
		if(css=='input'){
			class_name='datepickerSpecialReserved2'
		}
		else{
			class_name='datepickerSpecialReserved'
		}
	}
	if(boolean_high){
		class_name='datepickerSpecialHigh'
	}
	if(boolean_meddium){
		class_name='datepickerSpecialMeddium'
	}
	return class_name;
}	

function availabilityCalendar(id, reserved, lock){
	var now = new Date();
	//now=(now.getMonth()+2)+"/"+now.getDate()+"/"+now.getFullYear();
	//now=(now.getFullYear()+"-"+(now.getMonth()+3)+"-"+now.getDate());
	//now = new Date(now);
	var now_format=now.getFullYear()+"-"+(now.getMonth()+1)+"-"+now.getDate();
	$("#"+id).DatePicker({
		//id: id+'_dpick',
		flat: true,
		date: now_format,
		calendars: 1,
		starts: 1,
		format:'Y-m-d',
		//current: (year)+'-03-01',
		current: now_format,
		//prev:'',
		//next:'',
		//position: 'r',
		onRender: function(date) {
			var class_name=false;
			class_name=getClassDate(date, undefined, undefined, reserved, lock, 'input');
			return {
				className: class_name
			}
		
		}
	});
	//$("#"+id).mask("");
}

function enmascarar(id){
	$("#"+id).mask("");
}

function seasonsCalendar(year, id, id2, id3, meddium_disable, high_disable, reserved, lock){
	//if(!(year>2000)){
		if(document.getElementById('year_t')!=undefined && reserved==undefined ){
			year=document.getElementById('year_t').value;
		}
		else{
			if(document.getElementById('year_d')!=undefined && meddium_disable==undefined ){
				year=document.getElementById('year_d').value;
			}
			else{
				year=2010;
			}
		}
	//}
	//document.write("<b>aaaaaaaa</b>");
	$("#"+id).DatePicker({
		//id: id+'_dpick',
		flat: true,
		//date: '',
		date: (year-1)+'-03-01',
		calendars: 4,
		starts: 1,
		format:'Y-m-d',
		current: (year)+'-03-01',
		prev:'',
		next:'',
		//position: 'r',
		onRender: function(date) {
			var class_name=false;
			class_name=getClassDate(date, meddium_disable, high_disable, reserved, lock);
			return {
				className: class_name
			}
		
		}
	});
	$("#"+id2).DatePicker({
		flat: true,
		date: '',
		calendars: 4,
		starts: 1,
		format:'Y-m-d',
		current: year+'-07-01',
		prev:'',
		next:'',
		//position: 'r',
		onRender: function(date) {
			var class_name=false;
			class_name=getClassDate(date, meddium_disable, high_disable, reserved, lock);
			return {
				className: class_name
			}
		}
	});
	/**/
	$("#"+id3).DatePicker({
		flat: true,
		date: '',
		calendars: 4,
		starts: 1,
		format:'Y-m-d',
		current: year+'-11-01',
		prev:'',
		next:'',
		//position: 'r',
		onRender: function(date) {
			var class_name=false;
			class_name=getClassDate(date, meddium_disable, high_disable, reserved, lock);
			return {
				className: class_name
			}
		}
	});
	$("#"+id).mask("");
	$("#"+id2).mask("");
	$("#"+id3).mask("");
	
	//$("#"+id3).attr('disabled','disabled');
	//$("#"+id3).attr('readonly','readonly');
	//$("#div_prueba").mask("Waiting...");
	

	
	/*
	$("#cancel").bind("click", function () {
		$("#content").unmask();
	});
	*/

}
/*
function (){

}
*/

function getRangeDays(arr){ //pendiente funcion
	var min_date="";
	var max_date="";
	var arr2=new Array();
	for(i=0;i<arr.length;i++){
		if(!(arr[i][0].valueOf()==arr[i][1].valueOf())){
			if(arr[i][0].valueOf()>arr[i][1].valueOf()){
				max_date = new Date(arr[i][0].valueOf());
				min_date = new Date(arr[i][1].valueOf());
			}
			else{
				min_date = new Date(arr[i][0].valueOf());
				max_date = new Date(arr[i][1].valueOf());
			}
			while(min_date<=max_date){
				var tmp=new Date(min_date);
				var l=arr2.length;
				arr2[l]=(tmp.getMonth()+1)+"/"+tmp.getDate()+"/"+tmp.getFullYear();
				min_date=min_date.valueOf()+86400000;//VALOR DE UN DIA  86400000
			}
		}
		else{
			var tmp=new Date(arr[i][0].valueOf());
			//alert(tmp);
			var l=arr2.length;
			//arr2[l]=tmp.getFullYear()+"-0"+tmp.getMonth()+"-"+tmp.getDate();
			arr2[l]=tmp.getMonth()+"/"+tmp.getDate()+"/"+tmp.getFullYear();
			//alert(arr2[l]);
			//arr2[arr2.length]=tmp.format("d/m/Y");
		}
		//min_date=min_date.valueOf();
		//alert(min_date.valueOf()); //05/19/2010 1274245200000 ! 05/20/2010 1274331600000 = 86400000 --> valor de un dia
		//alert(new Date(min_date.valueOf())); //05/19/2010 1274245200000 ! 05/20/2010 1274331600000 = 86400000 --> valor de un dia
		//alert(min_date.valueOf()+86400000); //05/19/2010 1274245200000 ! 05/20/2010 1274331600000 = 86400000 --> valor de un dia
		//alert(min_date.addDays(1)); 
		//alert(min_date+1);1274331600000
		//alert(max_date.valueOf()); // 
		//alert(new Date(min_date.valueOf()+86400000)); //05/19/2010 1274245200000 ! 05/20/2010 1274331600000 = 86400000 --> valor de un dia
		//alert(new Date(max_date.valueOf())); // 
		//result=arr2;
	}
	arr2=(arr2.length>0)?arr2:false; 
	return arr2;
}

function loadSeasons(id_product, year, id, id2, id3, main_id,code){
	if(code==undefined){
		code='';
	}
	var meddium_disable=loadSeason(id_product,'media',code, year);
	var high_disable=loadSeason(id_product,'alta',code, year);
	 id=(id==undefined)?'whiteCalendar':id;
	 id2=(id2==undefined)?'whiteCalendar2':id2;
	 id3=(id3==undefined)?'whiteCalendar3':id3;
	 main_id=(main_id==undefined)?'tar_cal_container':main_id;
	 $("#"+id).remove();
	 $("#"+id2).remove();
	 $("#"+id3).remove();
	 $('<div   id="'+id+'" style="width: 800px; height: 150;"></div>').appendTo("div#"+main_id);
	 $('<div   id="'+id2+'" style="width: 800px; height: 150;"></div>').appendTo("div#"+main_id);
	 $('<div   id="'+id3+'" style="width: 800px; height: 150;"></div>').appendTo("div#"+main_id);
	 //alert(meddium_disable);
	 //year=2010;
	//	setTimeOut(,1000);
	 //setInterval( seasonsCalendar(year, id, id2, id3,meddium_disable,high_disable), 1000);
	// setTimeout(" seasonsCalendar("+year+", "+id+", "+id2+", "+id3+","+meddium_disable+","+high_disable+")",15000);
	 seasonsCalendar(year, id, id2, id3, meddium_disable, high_disable);
	
} 

function loadAvailabilitys(id_product, year, id, id2, id3, main_id, code){
	if(code==undefined){
		code='';
	}
	var lock=loadAvailability(id_product,'locked',code,year);
	var reserved=loadAvailability(id_product,'reserved',code, year);
	id=(id==undefined)?'whiteCalendar_d':id;
	id2=(id2==undefined)?'whiteCalendar_d2':id2;
	id3=(id3==undefined)?'whiteCalendar_d3':id3;
	main_id=(main_id==undefined)?'dis_cal_container':main_id;
	$("#"+id).remove();
	$("#"+id2).remove();
	$("#"+id3).remove();
	$('<div   id="'+id+'" style="width: 800px; height: 150;"></div>').appendTo("div#"+main_id);
	$('<div   id="'+id2+'" style="width: 800px; height: 150;"></div>').appendTo("div#"+main_id);
	$('<div   id="'+id3+'" style="width: 800px; height: 150;"></div>').appendTo("div#"+main_id);

	//var meddium_disable=undefined;
	//var high_disable=undefined;
	seasonsCalendar(year, id, id2, id3,undefined,undefined, reserved, lock );
	
} 

function loadAvailability(id_product,type, code, year){ //pendiente
	if(code==undefined){
		code='';
	}
	var arr_return=false;
	var data_str="accion=load_availability&id_product="+id_product+"&type="+type+"&code="+code+"&year="+year;
	$.ajax({
		type: "GET",
		async: false,//para que exija que se ejecute antes de continuar
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		data: data_str,
		dataType: 'json',//para que tome el objeto
		processData:true,
		success: function(datos){
			arr_return=datos.arr_res;
		}
	});
	return arr_return;
}

function getMaxCalendarValue(path){ //pendiente
	//alert(121);
	if(path==undefined){
		path="http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang;
	}
	path="http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang;
	var data_str="accion=get_max_calendar_value";
	var dato='';
	$.ajax({
			type: "GET",
			async: false,//para que exija que se ejecute antes de continuar
			url: path,
			data: data_str,
			//dataType: 'json',//para que tome el objeto
			processData:true,
			success: function(datos){
				dato=datos;
			}
	});
	return dato;
}	

function consultarTemporada(today, products_id){
	//if(today==)
	var path="http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang;
	var data_str="accion=consultar_temporada&today="+today+"&products_id="+products_id;
	//var today='';
	var temporada='baja';
	$.ajax({
			type: "GET",
			async: false,//para que exija que se ejecute antes de continuar
			url: path,
			data: data_str,
			//dataType: 'json',//para que tome el objeto
			processData:true,
			success: function(datos){
				temporada=datos;
			}
	});
	return temporada;
}

function consultarDiasMinimos(products_id){
	var path="http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang;
	var data_str="accion=consultar_dias_minimos&products_id="+products_id;
	var dias=0;
	$.ajax({
			type: "GET",
			async: false,//para que exija que se ejecute antes de continuar
			url: path,
			data: data_str,
			//dataType: 'json',//para que tome el objeto
			processData:true,
			success: function(datos){
				dias=datos;
			}
	});
	return dias;
}

function consultarDiasTemporada(temporada, products_id){
	var path="http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang;
	var data_str="accion=consultar_dias_temporada&temporada="+temporada+"&products_id="+products_id;
	//var today='';
	var dias_minimos='1';
	$.ajax({
			type: "GET",
			async: false,//para que exija que se ejecute antes de continuar
			url: path,
			data: data_str,
			//dataType: 'json',//para que tome el objeto
			processData:true,
			success: function(datos){
				dias_minimos=datos;
			}
	});
	return dias_minimos;
	
}

function setMaxCalendarValue(month, today){
	if(today==undefined){
		today=new Date();
	}
	var month2 = today.getMonth();
	var modifiedMonth = parseInt(month)+parseInt(month2);
	//alert(month);
	//alert(month2);
	var modifiedDate = new Date(today.getFullYear(), modifiedMonth, today.getDate());
	//now=(now.getMonth()+2)+"/"+now.getDate()+"/"+now.getFullYear();
	//alert(today);
	//alert(modifiedDate);
	modifiedDate=dateFormated(modifiedDate);
	return modifiedDate;
}

function dateFormated(date){
	if(date==undefined){
		date=new Date();
	}
	date=(date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear();
	//date=date.getFullYear()+'-'+(date.getMonth()+1)+"-"+date.getDate();
	return date;
}
//pendiente
function loadSeason(id_product,seasson, code, year){ //pendiente
	if(code==undefined){
		code='';
	}
	if(year==undefined){
		year='';
	}
	var arr_return=false;
	var data_str="accion=load_seasons&id_product="+id_product+"&seasson="+seasson+"&code="+code+"&year="+year;
	$.ajax({
			type: "GET",
			async: false,//para que exija que se ejecute antes de continuar
			url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
			data: data_str,
			dataType: 'json',//para que tome el objeto
			processData:true,
			success: function(datos){
				arr_return=datos.arr_res;
			}
	});
	return arr_return;
}		

function setSeasons(seasson, start_date, end_date, id_product,code,op, year,id,id2, id3, main_id,data_str_){ //pendiente
	if(op==undefined){
		op="tmp";
	}
	if(data_str_==undefined){
		data_str_="";
	}
	var data_str="accion=set_seasons&seasson="+seasson+"&start_date="+start_date+"&end_date="+end_date+"&id_product="+id_product+"&op="+op+"&code="+code;
	if(start_date!='' && end_date!=''){
		$.ajax({
			//type: "POST",
			type: "GET",//puede fallar la respuesta si es post
			async: false,
			url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
			data: data_str,
			success: function(datos){
				if(seasson=='save'){
					code='';
					alert("Las fechas han sido guardadas");
					window.location.reload();//quitar del original
					//history.back(-1);
				}
				loadSeasons(id_product, year, id, id2, id3, main_id, code);
			}
		});
	}
}

function toogleLock(type, start_date, end_date, id_product,code,op, year,id,id2, id3, main_id){ //pendiente
	if(op==undefined){
		op="tmp";
	}
	var data_str="accion=toogle_lock&type="+type+"&start_date="+start_date+"&end_date="+end_date+"&id_product="+id_product+"&op="+op+"&code="+code;
	$.ajax({
		//type: "POST",
		type: "GET",//por problemas de carga de la respuesta
		async: false,
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		data: data_str,
		success: function(datos){
			
			//loadSeasons(id_product,code);
			if(type=='save'){
				code='';
				alert("Las fechas han sido guardadas");
				window.location.reload()
				//history.back(-1);//volver a la pagina anterior
			}
			loadAvailabilitys(id_product, year, id, id2, id3, main_id, code);
		}
	});
}

/*
function toogleLock(type, start_date, end_date, lock_dates, unlock_dates){
	addArrayRange(arr, start_date, end_date);
	
}
*/		
	/**
function toogleLock(type, start_date, end_date, id_product, year, id, id2, id3, main_id){ //pendiente
	var data_str="accion=toogle_lock&type="+type+"&start_date="+start_date+"&end_date="+end_date+"&id_product="+id_product;
	$.ajax({
			type: "POST",
			async: false,//para que exija que se ejecute antes de continuar
			url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
			dataType: 'json',//para que tome el objeto
			processData:true,
			data: data_str+"&mode=consulta",
			success: function(datos){
				if(datos.reserved=='t'){
					var x=window.confirm("¿Desea sobreescribir?")
					if (x){
						
					}
					else{
						
					}
					$.ajax({
							type: "POST",
							async: false,//para que exija que se ejecute antes de continuar
							url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
							data: data_str,
							dataType: 'json',//para que tome el objeto
							processData:true,
							success: function(datos){
								loadSeasons(id_product, year, id, id2, id3, main_id);
							}
					});
				}
				else{
					
				}
			}
	});
	/
}		
		
//PATH_OPERATION_DB 
/* Ejemplo de prueba tambien funciona Ajax
$.getJSON("http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang, {accion: "John", time: "2pm" }, function(json){
  alert("JSON Data: " + json.error);
});
*/

/** TEST
var arr=new Array();
arr=['05/19/2010','05/20/2010']; //1274245200000 1272258000000
//now2.addDays(-5);
//now2.setHours(0,0,0,0);
var min = new Date();
//min.addDays(-10);
var max = '06/20/2010';
max = new Date(max);
//max.addDays(10);
*/

function addArrayRange(arr, start_date, end_date){
	var arr_add=[new Array(start_date,end_date)];//'02/25/2010'
	arr_add=getRangeDays(arr_add);
	arr=arr.concat(arr_add);
	return arr;
}


function searchInArray(arr, valor){
	var result=false;
	var ind, pos;
	for(ind=0; ind<arr.length; ind++){
		if (arr[ind] == valor){
		  result=true;
		  break;
		}
	}
	/*
	pos = (ind < arr.length)? ind : -1;
	return (pos);
	*/
	return result;
} 

function savePrices(id_product, data_str_){ //pendiente
	var data_str="accion=save_prices&id_product="+id_product+data_str_;
	$.ajax({
		type: "POST",
		async: false,//para que exija que se ejecute antes de continuar
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		data: data_str,
		dataType: 'json',//para que tome el objeto
		processData:true,
		success: function(datos){
			//if(datos.success){
			alert(datos.info);
			//}
		}
	});
}

function loadPricesBoxValues(id_product, data_str_,id,main_id,id2,main_id2,id3,main_id3,id4,main_id4,id5,main_id5, id6,main_id6, lang){ //pendiente
	//var data_str="accion=save_prices&id_product= "+id_product+data_str_;
	//alert('aaaaaaaa');
	lang=(lang==undefined || lang=='')?"es":lang;
	//alert("load lang "+lang);
	var data_str="id_product="+id_product+data_str_;
	//alert(data_str);
	$.ajax({
		type: "GET",
		async: false,//para que exija que se ejecute antes de continuar
		//url: "http://tendencygroup.com/apartments/operacion_bd.php",,
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		//$url__="http://tendencygroup.com/apartments/index.php?cPath=68&file=search&language={$lang}";
		data: data_str,
		dataType: 'json',//para que tome el objeto
		processData:true,
		success: function(datos){
			//alert(datos);
			//alert('bbbb');
			if(document.getElementById('entrada')!=undefined && document.getElementById('salida')!=undefined){
				if(document.getElementById('fechasalida')!=undefined && document.getElementById('fechallegada')!=undefined){
					document.getElementById('fechallegada').value=document.getElementById('entrada').value;
					document.getElementById('fechasalida').value=document.getElementById('salida').value;
					document.getElementById('codigo_promocion').value=document.getElementById('codigo_promocion_precios').value;
				}
			}
			//alert(datos);
			//alert(datos.valor);
			$("#"+id).remove();
			$("#"+id2).remove();
			$("#"+id3).remove();
			$("#"+id4).remove();
			$("#"+id5).remove();
			$("#"+id6).remove();
				
			if(document.getElementById('div_cont_hiddens_reserva')!=undefined){
				$("#div_cont_hiddens_reserva").remove();
				$('<div   id="div_cont_hiddens_reserva"><input type="hidden" name="total_" id="total_" value="'+datos.total+'"/><input type="hidden" name="a_pagar_" id="a_pagar_" value="'+datos.a_pagar+'" /><input type="hidden" name="al_llegar_" id="al_llegar_" value="'+datos.llegada+'"/><input type="hidden" name="deposito_" id="deposito_" value="'+datos.deposito+'"/><input type="hidden" name="huespedes" id="huespedes" value="'+datos.huespedes+'" /><input type="hidden" name="codigo_promocion" id="codigo_promocion" value="'+datos.cod_prom+'" /><input type="hidden" name="dto_prom" id="dto_prom" value="'+datos.dto_prom+'" /></div>').appendTo("#div_cont_hiddens_reserva_main");
			}
			if(datos.success){
				//alert('ccc');
				$('<div   id="'+id+'" style="color:#FFCC33; font-size: 15px; font-weight:bold;">&nbsp;&nbsp;&euro;&nbsp;'+datos.total+'</div>').appendTo("div#"+main_id);
				$('<div   id="'+id2+'" style="color:#FFCC33; font-size: 15px; font-weight:bold;">&nbsp;&nbsp;&euro;&nbsp;'+datos.a_pagar+'</div>').appendTo("div#"+main_id2);
				$('<div   id="'+id3+'" style="font-size: 14px; font-weight:bold;">&nbsp;&nbsp;&euro;&nbsp;'+datos.llegada+'</div>').appendTo("div#"+main_id3);
				$('<div   id="'+id5+'" style="font-size: 14px; font-weight:bold;">&nbsp;&nbsp;&euro;&nbsp;'+datos.deposito+'</div>').appendTo("div#"+main_id5);
				$('<div   id="'+id4+'"  align="justify" style="color:red;">'+datos.info+'</div>').appendTo("div#"+main_id4);
				$('<div   id="'+id6+'" style=""><input name="consultado" id="consultado" type="hidden" value="true"></div>').appendTo("div#"+main_id6);
			}
			else{
				//alert('ddd');
				//$('<div   id="'+id5+'"  align="justify" style="color:red;">'+datos.info+'</div>').appendTo("div#"+main_id5);
				$('<div   id="'+id4+'"  align="justify" style="color: red; background-color: rgb(0, 0, 0); position: relative; border: medium solid; padding: 40px; width: 300px; top: -215px; left: -20px; ">'+datos.info+'</div>').appendTo("div#"+main_id4);
				$('<div   id="'+id+'" style="">&nbsp;&nbsp;'+''+'</div>').appendTo("div#"+main_id);
				$('<div   id="'+id2+'" style="">&nbsp;&nbsp;'+''+'</div>').appendTo("div#"+main_id2);
				$('<div   id="'+id3+'" style="">&nbsp;&nbsp;'+''+'</div>').appendTo("div#"+main_id3);
				$('<div   id="'+id5+'" style="">&nbsp;&nbsp;'+datos.deposito+'</div>').appendTo("div#"+main_id5);
				$('<div   id="'+id6+'" style=""><input name="consultado" id="consultado" type="hidden" value="false"></div>').appendTo("div#"+main_id6);
				//alert(datos.info);
			}
			//alert('eee');
		}
	});
}

function removeAndSetById(id, main_id, html_add, prop_add){
	if(html_add==undefined){
		html_add='';
	}
	if(prop_add==undefined){
		prop_add='';
	}
	$("#"+id).remove(); 
	$('<div   id="'+id+'" '+prop_add+'>'+html_add+'</div>').appendTo("div#"+main_id);
}
function saveGeneralValues(range,gasto){ //pendiente
	//alert(range);
	var data_str="accion=save_general_values&range="+range+"&gasto="+gasto;
	$.ajax({
		type: "GET",
		async: false,//para que exija que se ejecute antes de continuar
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		data: data_str,
		dataType: 'json',//para que tome el objeto
		processData:true,
		success: function(datos){
			//saveCollectInfo();
		}
	});	
}
function saveCollectInfo(master_categories_id){ //pendiente
	//var products_id=document.getElementByName('products_id').value;
	//alert(products_id);
		/*
	if(!(products_id>0)){
		if(master_categories_id!=undefined){
			//var master_categories_id=document.getElementByName('master_categories_id').value;
			document.getElementByName('master_categories_id').value=master_categories_id;//coloca el valor de la categoria del producto 
		}
		document.new_product.action= "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang;
	}
		*/
	if(master_categories_id==undefined){
		master_categories_id=0;
		//var master_categories_id=document.getElementByName('master_categories_id').value;
		//document.getElementByName('master_categories_id').value=master_categories_id;//coloca el valor de la categoria del producto 
	}
	document.new_product.action= "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang+"&master_categories_id2="+master_categories_id;
	document.new_product.submit();
}


/*
$(document).ready(function (){
	//inputCalendar("inputDate", min, max, arr, 2);// se aplican las propiedades al input
	//inputCalendar("id");
	//seasonsCalendar(year, id, id2, id3, meddium_disable, high_disable )
	var meddium_disable=[new Array('05/15/2010','05/20/2010'), new Array('06/19/2010','07/20/2010'), new Array('08/19/2010','08/20/2010')];
	//alert((meddium_disable[0])); //4/15/2010
	meddium_disable=getRangeDays(meddium_disable);
	//alert((meddium_disable[0])); //4/15/2010
	var high_disable=[new Array('02/19/2010','02/25/2010')];
	high_disable=getRangeDays(high_disable);
	//var date2=new Date(meddium_disable[0]);
	//alert(date2);
	
	//for(i=0;i<meddium_disable.length;i++){
		//for(j=0;i<meddium_disable[i].length;i++){
			alert(meddium_disable[i]);
		//}
	//}
	
	
	
	//alert(meddium_disable[0][0]);
	//alert(meddium_disable[0][1]);
	//alert(meddium_disable[0][1]);
	//alert(meddium_disable[1][1]);
	
	seasonsCalendar(2010,"whiteCalendar","whiteCalendar2","whiteCalendar3",meddium_disable,high_disable );
});
*/

function consultarInforme(){
	var fechallegada=document.getElementById('fecha_inicio_informe_ventas').value;
	var fechasalida=document.getElementById('fecha_fin_informe_ventas').value
	var apartamento_informe=document.getElementById('apartamento_informe').value
	var data_str="accion=consultar_informe&fechhallegada="+fechallegada+"&fechasalida="+fechasalida+"&apartamento_informe="+apartamento_informe;
	$.ajax({
		type: "GET",
		async: false,//para que exija que se ejecute antes de continuar
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		data: data_str,
		//dataType: 'json',//para que tome el objeto
		processData:true,
		success: function(datos){
			//alert(datos);
			removeAndSetById("informe_ventas_conte","informe_ventas_prin", datos, '');
		}
	});
}

function colocarFechasMes(){
	var now=new Date();
	var fecha_ini=(now.getFullYear()+"-"+(now.getMonth()+1)+"-01");
	var fecha_fin=(now.getFullYear()+"-"+(now.getMonth()+2)+"-01");
	document.getElementById('fecha_inicio_informe_ventas').value=fecha_ini;
	document.getElementById('fecha_fin_informe_ventas').value=fecha_fin
}
function colocarFechasAnio(){
	var now=new Date();
	var fecha_ini=(now.getFullYear()+"-01-01");
	var fecha_fin=(now.getFullYear()+"-12-31");
	document.getElementById('fecha_inicio_informe_ventas').value=fecha_ini;
	document.getElementById('fecha_fin_informe_ventas').value=fecha_fin
}
/*
function consultarInforme(){
	var nombre=document.getElementById('nombre_peti').value;
	var mail_peti=document.getElementById('mail_peti').value;
	var mail_peti=document.getElementById('telefono_peti').value;
	var data_str="accion=mail_apto&fechhallegada="+fechallegada+"&fechasalida="+fechasalida;
	$.ajax({
		type: "GET",
		async: false,//para que exija que se ejecute antes de continuar
		url: "http://tendencygroup.com/apartments/index.php?cPath=68&file=operacion_bd.php&language="+lang,
		data: data_str,
		//dataType: 'json',//para que tome el objeto
		processData:true,
		success: function(datos){
			alert(datos);
			removeAndSetById("informe_ventas_conte","informe_ventas_prin", datos, '');
		}
	});
}
*/
function compararFechas(cant_min_reserva){ //pendiente funcion
	var min_date=document.getElementById('fechallegada').value;
	var max_date=document.getElementById('fechasalida').value;;
	min_date=new Date(min_date);
	max_date=new Date(max_date);
	var cont=0;
	while(min_date<=max_date){
		min_date=min_date.valueOf()+86400000;//VALOR DE UN DIA  86400000
		cont ++;
	}
	if (cont>1){
		cont= cont-1;
	}
	return cont;	
}
function validateSearchForm(action, lang){
	lang=(lang==undefined)?'es':lang;
	if(document.getElementById('buscador_fecha_salida')!=undefined && document.getElementById('buscador_fecha_llegada')!=undefined){
		if(document.getElementById('buscador_fecha_salida').value!='' && document.getElementById('buscador_fecha_llegada').value!=''){
			document.forms["buscador_es"].action=action;
			document.forms["buscador_es"].submit();
		}
		else{
			if(lang=='es'){
				alert("Debe seleccionar las fechas de llegada y salida");
				//alert(lang);
			}
			else{
				lang='en';
				alert("You must select the arrival and departure dates");
				//alert(lang);
			}
		}
	}
	
}
function colocarPrecios(id_ini, id_des, lang){ 
	if(id_ini!=undefined || id_des!=undefined ){
		if(document.getElementById(id_ini)!=undefined && document.getElementById(id_des)!=undefined){
			document.getElementById(id_des).value=document.getElementById(id_ini).value;
			//document.getElementById('codigo_promocion').value=document.getElementById('codigo_promocion_precios').value;//fijo por nuevo ajuste
		}
	}
	if(document.getElementById('entrada').value!='' && document.getElementById('salida').value!=''){
		loadPricesBoxValues(id_product, getDataStrPricesBox(),'prices_value_div','prices_value_div_main','prices_value_div_2','prices_value_div_main_2','prices_value_div_3','prices_value_div_main_3','prices_value_div_4','prices_value_div_main_4','prices_value_div_5','prices_value_div_main_5','prices_value_div_6','prices_value_div_main_6', lang);
	}
}
