// JavaScript Document

//Tooltip
this.tooltip = function(){	
	
		xOffset = 10;
		yOffset = 20;		

		
	$("a.tooltip").hover(function(e){											  

		//ptext=$("#policyContent_"+this.id).html();
		ptext=$(this).find('.tooltip_content').html();
		
		tagContent=$(this).find('.tooltip_content').get(0).nodeName;
		if(tagContent=="SPAN" || tagContent=="DIV" || tagContent=="P" || tagContent=="IMG")
		{
			
			
			if(tagContent!="IMG")
			{
				$("body").append("<div id='tooltip'>"+ptext+"</div>");
				//$("#tooltip").css("width","400px");
			}else{
				$("body").append("<div id='tooltip'><img src='"+$(this).find('.tooltip_content').attr("src")+"'/></div>");
			}
			
		//alert($("#tooltip").html());
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(e.pageX + yOffset) + "px")
				.fadeIn(100);
				//alert(ptext.length)
				if(ptext.length>50)
				{
					$("#tooltip").css("width","250px");
				}else{
					
					$("#tooltip").css("width",$("#tooltip").width()+"px");
				}
		}
				
    },
	function(){
			$("#tooltip").remove();		
    });
	
	$("a.tooltip").mousemove(function(e){
		
		var mousex = e.pageX + 20; //Get X coodrinates
		var mousey = e.pageY + 20; //Get Y coordinates
		var tipWidth = $("#tooltip").width(); //Find width of tooltip
		var tipHeight = $("#tooltip").height(); //Find height of tooltip
		
		//Distance of element from the right edge of viewport
		var tipVisX = $(window).width() - (mousex + tipWidth);
		//Distance of element from the bottom of viewport
		var tipVisY = $(window).height() - (mousey + tipHeight);
		  
		if ( tipVisX < 20 ) { //If tooltip exceeds the X coordinate of viewport
			mousex = e.pageX - tipWidth - 20;
		} if ( tipVisY < 20 ) { //If tooltip exceeds the Y coordinate of viewport
			mousey = e.pageY - tipHeight - 20;
		} 
		$("#tooltip").css({  top: mousey, left: mousex });
	});
	
};

this.imgFloat = function(){	
	
	xOffset=10;
	yOffset=20;	
	$(".imgFloat").each(function(){
		$(this).hover(function(){
		$("body").append("<div id='imgFloat'></div>");
		var imgBig=$(this).attr('href');
		$("#imgFloat")
			.html("<img src='"+imgBig+"' class='preload'>")
			.css("top",(e.pageY) + "px")
			.css("left",(e.pageX) + "px")
			.fadeIn(100);
		},
		function(){
		$("#imgFloat").remove();
		});
		
		$(this).mousemove(function(e){
		$("#imgFloat")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
		});
	});
	
};
//End Tooltip

//DatePicker

var date_advance_bht=1;

function CreateCalendar()
{
	
	$(".vPicker").each(function(index){
		cInput=this.id;	
		cInput=cInput.replace("Input","");
		if(!$("#"+cInput).length)
		{
			dateInputDefault=$(this).attr("rel");
			$(this).after('<input type="hidden" name="'+cInput+'" id="'+cInput+'">');
			if($("#"+cInput).val()!=""){
				$("#"+cInput).val(dateInputDefault);
				$(this).val(getFormatDate(dateInputDefault,1))
				//alert($(this).val());
			}else{
				if(dateInputDefault!="")
				{
					$("#"+cInput).val(dateInputDefault);
					$(this).val(getFormatDate(dateInputDefault,1))
				}else{
					$(this).val("");
				}
			
			}
			
		}
		
		if(index==1)
		{
			var dateSet=new Date();
			setDatePickerInput(this.id,"",date_advance_bht+1,1);
			
		}else{
			var dateSet=new Date();
			setDatePickerInput(this.id,"",date_advance_bht,1);
		}
		
	});
}

function getDateDiff(dateStart,dateEnd)
{
	return (Math.ceil((dateEnd.getTime()-dateStart.getTime())/(24*60*60*1000)));
}
function getFormatDate(dateInput,typeFormat)
{

	var arrMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
	
	var dateSplit =dateInput.split("-");
    var dateYear = dateSplit[0];
    var dateMonth = dateSplit[1] - 1;
    var dateDate = dateSplit[2];
	
	dDate = new Date(dateYear, dateMonth, dateDate);	
	var stringDateFormat = dDate.getDate() + "-" + arrMonth[dDate.getMonth()] + "-" + dDate.getFullYear();
	return stringDateFormat;
}

function setDatePickerInput(elemInput,dateDefault,dateMin,typeDisplay){

	cInput='#'+elemInput.replace("Input","");
	$("#"+elemInput).datepicker({
	minDate:dateMin,
	changeMonth:true,
	changeYear:true,
	dateFormat:'dd-M-yy',
	altField:cInput,
	altFormat:'mm/dd/yy',
	showOn: 'both',
    buttonImage: 'vcalendar/ico_calendar_search.jpg',
    buttonImageOnly: true,
    showButtonPanel: true
		});
}
//End DatePicker


