var isiPad;


function iniciaFormulario(){

	// Actualizamos fechas
	
	var f = new Date();
	f.setDate(f.getDate() + 2);
	fec = padNum(f.getDate()) + "/" + padNum((f.getMonth() +1)) + "/" + f.getFullYear();
	f.setDate(f.getDate() + 7);
	fec2 = padNum(f.getDate()) + "/" + padNum((f.getMonth() +1)) + "/" + f.getFullYear();
	if (document.getElementById('pickup_date').value==''){
		document.getElementById('pickup_date').value = fec;
	}
	if(document.getElementById('dropoff_date').value==''){
		document.getElementById('dropoff_date').value = fec2;
	}



	// Carga inicial de paises, si no
	air = getAirValue(); 


	if (pickupDest=='' || pickupDest=='null'){

		if (pickupCountry){
			cargaSelector('pais',$('#country'),pickupCountry);
			cargaSelector('destinos',$('#pickup_loc'),pickupCountry, air);
			cargaSelector('destinos',$('#dropoff_loc'),pickupCountry, air);
		} else {
			cargaSelector('paises',$('#country'));
			yaCargado=false;
		}
	} else {
		cargaSelector('paisDestino',$('#country'), pickupDest);
		cargaSelector('destino',$('#pickup_loc'), pickupDest);
		cargaSelector('destino',$('#dropoff_loc'), dropoffDest);
		yaCargado=false;
	}

	// Si se selecciona pais se carga y habilita todo
	$('#country').change(function () {
		air = getAirValue();
		 if ($("#country option:selected").val()=='reload')
		 {
			 cargaSelector('paises',$('#country'));
		 } else {
			 idPais = getCountryValue();
			 cargaSelector('destinos',$('#pickup_loc'),idPais, air);
			 cargaSelector('destinos',$('#dropoff_loc'),idPais, air);
			 $('#form_btn').attr("disabled",false);
			 yaCargado=true;
		 }
		 
	 })




	 // Si se cambia destino de recogida
	 $('#pickup_loc').change(function () {
		air = getAirValue();
		if ($("#pickup_loc option:selected").val()=='reload')
		{
			idPais = getCountryValue();
			 cargaSelector('destinos',$('#pickup_loc'),idPais, air);
			 cargaSelector('destinos',$('#dropoff_loc'),idPais, air);
			 $('#form_btn').attr("disabled",false);
			 yaCargado=true;

		} else {
			selVal = $("#pickup_loc option:selected").text();
			$("#dropoff_loc option:contains("+selVal+")").attr("selected",true);
		}
	 })

		 // Si se cambia destino de devolucion a reload
	 $('#dropoff_loc').change(function () {
		air = getAirValue();
		if ($("#dropoff_loc option:selected").val()=='reload')
		{
			idPais = getCountryValue();
			 cargaSelector('destinos',$('#dropoff_loc'),idPais, air);
			 $('#form_btn').attr("disabled",false);
			 yaCargado=true;

		} 
	 })




	// Rellenamos selectores de horas / minutos
	hor_min_init = (window['hor_min_init']) ? hor_min_init : '12:00';
	hor_min_end = (window['hor_min_end']) ? hor_min_end : '12:00';
	if (document.getElementById("pickup_time").length<1){
		generaOpcionesTiempo($('#pickup_time'), hor_min_init);
	}
	if (document.getElementById("dropoff_time").length<1){
		generaOpcionesTiempo($('#dropoff_time'), hor_min_end);
	}


	// Chequeamos si es un ipad
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	//alert (isiPad);
}


function generaOpcionesTiempo(destino, selected){


	for(i=0; i<=23;i+=1){
		for (j=0; j<=45 ; j+=15 ){
			cmpStr = padNum(i) + ':' + padNum(j);
			selStr = (cmpStr==selected) ? ' selected="selected"' : '';
			destino.append('<option value="' + cmpStr + '"' + selStr + '>' + cmpStr + '</option>');
		}
		
	}
}

function padNum(num){
	var num = '' + num;
	if (num.length<2){
		num = '0' + num;
	}
	return num;
}


// Si se cambia casilla aeropuertos
function changeAero(value){
	// cambiamos clases



	if (value){
		$('#airpt_bot').removeClass("airpt_bot_disab"); 
		$('#airpt_bot').addClass("airpt_bot_enab"); 
		$('#alldest_bot').removeClass("alldest_bot_enab"); 
		$('#alldest_bot').addClass("alldest_bot_disab"); 
	} else {
		$('#airpt_bot').removeClass("airpt_bot_enab"); 
		$('#airpt_bot').addClass("airpt_bot_disab"); 
		$('#alldest_bot').removeClass("alldest_bot_disab"); 
		$('#alldest_bot').addClass("alldest_bot_enab"); 
	}

	document.getElementById('solo_aero').value = value;
	air = getAirValue();

	idPais = getCountryValue();

	if (idPais!='null' && idPais!='reload')
	{
		cargaSelector('destinos',$('#pickup_loc'),idPais, air);
		cargaSelector('destinos',$('#dropoff_loc'),idPais, air);
		$('#form_btn').attr("disabled",false);
		yaCargado=true;
	}
}


function cargaSelector(fuente,destino,cod, air){
	switch (fuente){
		case 'pais':
			action = 'getPais';
			relationCod = '&countryCod='+cod;
		break;

		case 'paises':
			action = 'getPaises';
			relationCod = '';
		break;

		case 'destinos':
			action = 'getDestinos';
			relationCod = '&parent='+cod+'&air='+air;
		break;

		case 'paisDestino':
			action = 'getPaisDestino';
			relationCod = '&locationCod='+cod;
		break;

		case 'destino':
			action = 'getDestino';
			relationCod = '&locationCod='+cod;
		break;
	}
	
	// Vacia receptor
	destino.attr('disabled',true);
	if (destino.attr('id')=='pickup_loc' || destino.attr('id')=='dropoff_loc')
		destino.append('<option selected>------ loading --------</option>');

	// Llamada AJAX
	//alert (domain + "includes2011/motor-selector.php?action="+action+"&idioma="+lang+relationCod);
	$.get(domain + "includes2011/motor-selector.php?action="+action+"&idioma="+lang+relationCod,{},function(xml){
		destino.empty();
		

		// Recorre documento XML y asigna valores
		$('option',xml).each(function(i) {
			name = $(this).find("name").text();
			value = $(this).find("value").text();
			selected = $(this).attr("selected");
			//alert (name+value); 
			optionHTML = themeOption(value, name, selected);
			destino.append(optionHTML);
			//alert (optionHTML);
		});

		destino.attr("disabled",false);
		
	});

}


function themeOption(value,name,selected){
	selTxt='';
	if (selected==1) selTxt = ' selected';
	retHTML = '<option value="' + value + '"' + selTxt + '>' + name + '</option>';
	return retHTML;
}

function reloadPickup(pVal){
	pVal = (pVal) ? 'on' : '';
	document.getElementById('cpickup').value = pVal;
	document.formu.submit();
}

function validateSrchFrm(){
	numError = 0;
	//alert ('valida');

	if (document.getElementById('pickup_loc')){
		elm = document.getElementById('pickup_loc');
		idx = document.getElementById('pickup_loc').selectedIndex;
		txt = elm.options[idx].value;
		if (txt=='null' || txt=='Select')
		{
			alert(label_select_pickup_location);
			return false;
		}
	}

	if (document.getElementById('dropoff_loc')){
		elm = document.getElementById('dropoff_loc');
		idx = document.getElementById('dropoff_loc').selectedIndex;
		txt = elm.options[idx].value;
		if (txt=='null' || txt=='Select')
		{
			alert(label_select_dropoff_location);
			return false;
		}
	}

	// Validamos e-mail para promo-cod


	if (document.getElementById('promo_email') && document.getElementById('promo_email').value!='' && echeck(document.getElementById('promo_email').value)==false){
		alert(label_not_valid_email);
		return false;
	}


	return true;

}



// Control de fechas
$(function()
{
	$('#pickup_date')
		.datepick(
			{	
				showOn: 'both', 
				buttonImage: '/hs2011/img/calendar.gif',
				showAnim: 'slideDown',
				closeAtTop: false,
				yearRange: ('+0:+1'),
				showOtherMonths: true,
				selectOtherMonths: true,
				numberOfMonths: 2,
				minDate: +2,
				mandatory: true
			}
		);

	$('#dropoff_date')
		.datepick(
			{	
				showOn: 'both', 
				buttonImage: '/hs2011/img/calendar.gif',
				showAnim: 'slideDown',
				closeAtTop: false,
				yearRange: ('+0:+1'),
				showOtherMonths: false,
				numberOfMonths: 2,
				minDate: +2,
				mandatory: true
			}
		);

});



// Sincronizamos fecha de devolucion si se cambia recogida
function sinchroDates(){

	date1 = dateReverse(document.getElementById('pickup_date').value);
	date2 = dateReverse(document.getElementById('dropoff_date').value);

	if(date1>date2){
		document.getElementById('dropoff_date').value = document.getElementById('pickup_date').value;
	}

}




// Utilidad - damos la vuelta a una cadena
function dateReverse(string){
	cadena = string.substring(6,10) + '/' + string.substring(3,5) + '/' + string.substring(0,2);
	return cadena;

}


// Inicializamos
$(document).ready(function(){

	// Selector idiomas
	$("#langBut").mouseover(function(e){$("#langBut").addClass("active");$("#langPop").show();e.stopPropagation();return false;});
	$("#langPop").mouseleave(function(){if($("#langPop").is(':visible')){$("#langBut").removeClass("active");$("#langPop").hide();}
return false;}).mouseover(function(e){e.stopPropagation();inSub=false});

	// Bind pestanas
	$("#offersBut").click(function(){toogleDivs('#offers', '#offersBut');return false});
	$("#aboutBut").click(function(){toogleDivs('#about', '#aboutBut');return false});
	$("#relatedBut").click(function(){toogleDivs('#relatedText', '#relatedBut');return false});


	// Comprobamos estado
	callAjax('testState', false);

	// Iniciamos formulario
	if (window.iniciaFormulario) iniciaFormulario();

});


function toogleDivs(divName, butName){
	// Apagamos divs
	$("#offers").hide(100);
	$("#about").hide(100);
	$("#relatedText").hide(100);


	// Mostramos div seleccionado
	$(divName).show(100);


	// Agregamos clases inactivas
	$("#offersBut").addClass('tabMenuDisab');
	$("#aboutBut").addClass('tabMenuDisab');
	$("#relatedBut").addClass('tabMenuDisab');

	// Quitamos clases activas
	$("#offersBut").removeClass('tabMenuEnab');
	$("#aboutBut").removeClass('tabMenuEnab');
	$("#relatedBut").removeClass('tabMenuEnab');


	// Mostramos clase
	$(butName).addClass('tabMenuEnab');
	$(butName).removeClass('tabMenuDisab');

}

// Llamada AJAX
function callAjax(action, value, hideResponse){
	url = domain + 'ajax/doLogin2011.php?action=' + action + '&value=' + value + '&' + session + '&lang=' + lang;

	// Mostramos precarga
	$('#preL').show();


	$.get(url,{},function(html){
		if (!hideResponse)
			$('#res').html(html);

		$('#preL').hide();
	});
}




// Inicializacion caja login
function doInit(){
	$('#fbBot').hide();
	$('#retBot').hide();
	iniSel();
	bind();
}


// Inicializamos selector inicial
function iniSel(){
	// Restablecemos selector
	html = '';
	html += '<div id="noConn">';
	html += '	<b>' + label_status + ':' + label_disconnected + '</b>';
	html += '	<p>' + label_connect_now + '</p>';
	html += '</div>';
	html += '<input type="button" id="connectBot" value=""/>';
	
	html += '<div id="hidSelector" style="display:none">';
	html += '	<p>' + label_if_fb + '</p>';
	html += '	<div>';
	html += '		<input type="radio" name="clType" value="1"/> ' + label_im_client + ' <br/>';
	html += '		<input type="radio" name="clType" value="2"/> ' + label_im_fan + ' <br/>';
	html += '		<input type="radio" name="clType" value="3"/> ' + label_im_client_fan + '<br/>';
	html += '	</div>';
	html += '	<p>' + no_fan_yet + '</p>';
	html += '</div>';

	$('#res').html(html);
}



function bind(){
	// Capturamos selector tipo cliente
	$('input[name="clType"]').click(function(){
		callAjax('clType', $("input[name='clType']:checked").val());
	});

	// Capturamos boton enviar email cliente
	$('#sendEmailClient').click(function(){
		callAjax('sendEmailClient', $('#email').val());
	});


	// Capturamos boton logout
	$('#logoutBot').click(function(){
		doLogOut();
	});

	// Capturamos link logout
	$('#logOutLink').click(function(){
		doLogOut2();
		return false;
	});
	


	// Capturamos envio email cliente y facebook
	$('#sendEmailClientAndFB').click(function(){
		callAjax('sendEmailClientAndFB', $('#email').val());
	});



	// Capturamos reintento de facebook
	$('#retryFB').click(function(){
		callAjax('reload', false);
	});


	// Capturamos boton conectar para abrir selector tipo de cliente
	$('#connectBot').click(function(){
		$('#connectBot').hide(100);
		$('#hidSelector').show(100);
	});
	
}



function showReturnBot(){
	$('#retBot').show();
}


function hideReturnBot(){
	$('#retBot').hide();
}


function doLogOut(){
	$('#fbBot').hide();
	$('#retBot').hide();
	iniSel();
	callAjax('logOut', 0, true);
	bind();
}

function doLogOut2(){
	$('#fbBot').hide();
	$('#retBot').hide();
	iniSel();
	callAjax('logOut2', 0, true);
	bind();
}

function showFBBot(){
	$('#fbBot').show();
}

function doReload(){
	callAjax('reload', false);
}


function getCountryValue(){
	if (a= $("#country option:selected").val()){
		return a;
	} else {
		return pickupCountry;
	}
}

function getAirValue(){
	if (a = $('#solo_aero').val()){
		return a;
	} else {
		return pickupAir;
	}
}

function forceNotAir(){
	$('#solo_aero').val(0);
	pickupAir = 0;
}

function direccionarPresupuesto(vproveedor, quoteRef){

	document.getElementById('vproveedor').value = vproveedor;
	document.getElementById('quoteRef').value = quoteRef;


	switch(lang){
		case 'en':
			theFile='quote';
		break;

		case 'fr':
			theFile='devis';
		break;

		case 'de':
			theFile='angebot';
		break;

		case 'es':
			theFile='presupuesto';
		break;

		case 'it':
			theFile='preventivo';
		break;

		case 'nl':
			theFile='offerte';
		break;
	}

	document.getElementById('formu').action = "/" + theFile + ".php";
	validateAndSendForm(true);
}




function showDropoffSelector(){
	disp = (document.getElementById('diffDropOff').checked) ? 'block' : 'none';
	document.getElementById('dropoffCont').style.display = disp;



	// Cargamos paises si se activa
	if (disp=='block'){
		cargaSelector('destinos',$('#dropoff_loc'),pickupCountry, 0);
	}

	// Borramos opciones si se desactiva
	if (disp=='none'){
		$('#dropoff_loc').empty();

		tmphtml = $('#pickup_loc').html();

		$('#dropoff_loc').html($('#pickup_loc').html());

	}
}


function showPromo_container(){
	disp = (document.getElementById('promocheck').checked) ? 'block' : 'none';
	document.getElementById('promo_container').style.display = disp;

	if (disp=='none'){
		$('#promo_cod').val('');
	}
}


function toogleFamily(checkId, divId){
	checkObj = document.getElementById(checkId);
	divObj = document.getElementById(divId);

	divObj.style.display = (checkObj.checked) ? 'block' : 'none';
}


function validateAndSendForm(sendform){
	numError = 0;

	if (document.getElementById('pickup_loc')){
		elm = document.getElementById('pickup_loc');
		idx = document.getElementById('pickup_loc').selectedIndex;
		txt = elm.options[idx].value;
		if (txt=='null' || txt=='Select')
		{
			alert(label_select_pickup_location);
			return false;
		}
	}

	if (document.getElementById('dropoff_loc')){
		elm = document.getElementById('dropoff_loc');
		idx = document.getElementById('dropoff_loc').selectedIndex;
		txt = elm.options[idx].value;
		if (txt=='null' || txt=='Select')
		{
			alert(label_select_dropoff_location);
			return false;
		}
	}



	if(sendform){
		document.getElementById('formu').submit();
	} else {
		return true;
	}
}


function validateRegFrm(){

	numError = 0;

	/*if (document.getElementById('register_name') && document.getElementById('register_name').value==''){
		numError = 1;
		alert(label_enter_name);
		return false;
	}

	if (document.getElementById('register_surname') && document.getElementById('register_surname').value==''){
		numError = 1;
		alert(label_enter_surname);
		return false;
	}*/

	if (document.getElementById('register_email') && document.getElementById('register_email').value==''){
		numError = 1;
		alert(label_enter_email);
		return false;
	}

	// Email validation
	if (echeck(document.getElementById('register_email').value)==false){
		numError = 1;
		alert(label_not_valid_email);
		return false;
	}

	if (numError==0){
		return true;
	}
}


function validateLogFrm(){

	numError = 0;

	if (document.getElementById('email') && document.getElementById('email').value==''){
		numError = 1;
		alert(label_enter_email);
		return false;
	}

	// Email validation
	if (echeck(document.getElementById('email').value)==false){
		numError = 1;
		alert(label_not_valid_email);
		return false;
	}

	if (numError==0){
		return true;
	}
}


function validateSaveQuotFrm(minAge){


	numError = 0;

	if (document.getElementById('save_quote_name') && document.getElementById('save_quote_name').value==''){
		numError = 1;
		alert(label_enter_name);
		return false;
	}


	if (document.getElementById('save_quote_surname') && document.getElementById('save_quote_surname').value==''){
		numError = 1;
		alert(label_enter_surname);
		return false;
	}


	if (document.getElementById('save_quote_email') && document.getElementById('save_quote_email').value==''){
		numError = 1;
		alert(label_enter_email);
		return false;
	}


	// Email validation
	if (echeck(document.getElementById('save_quote_email').value)==false){
		numError = 1;
		alert(label_not_valid_email);
		return false;
	}


	if (document.getElementById('save_quote_age') && document.getElementById('save_quote_age').value==''){
		numError = 1;
		alert(label_enter_driver_age);
		return false;
	}



	if (document.getElementById('save_quote_age') && document.getElementById('save_quote_age').value<minAge){
		numError = 1;
		alert(label_driver_age_not_valid + " " + minAge + " " +label_driver_age_not_valid2);
		return false;
	}


	if (document.getElementById('save_quote_age') && isNaN(document.getElementById('save_quote_age').value)){
		numError = 1;
		alert(label_enter_driver_age);
		return false;
	}


	if (numError==0){
		return true;
	}
}


function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }
	 return true					
}







function saveQuote(vprovider,minAge){

	document.getElementById('save_quote_details').style.display='block';

	
	if (!validateSaveQuotFrm(minAge)) return false;


	sqURL = encodeURI(domain  + 'ajax/saveQuote.php?action=save&vprovider=' + vprovider + '&data=' + xmlEncoded + '&name=' + document.getElementById('save_quote_name').value + '&surname=' + document.getElementById('save_quote_surname').value + '&email=' + document.getElementById('save_quote_email').value + '&age=' + document.getElementById('save_quote_age').value);


	$('#save_quote_details_container').html('<div class="loading"></div>');

	$.get(sqURL ,{},function(res){
		$('#save_quote_details_container').html(res);
	});
}


function showWindow(winName){
	if (document.getElementById(winName)){
		document.getElementById(winName).style.display='block';
	}


	// Actualizamos valores
	if (winName=='extras_details'){
		$('#sub_additional_drivers').val($('#additional_drivers').val());
		$('#sub_booster_seats').val($('#booster_seats').val());
		$('#sub_baby_seats').val($('#baby_seats').val());
		
		if ($("#force_full_full").is(':checked')){
			$("#sub_force_full_full").attr('checked', true);  
		} else {
			$("#sub_force_full_full").attr('checked', false);  
		}

		if ($("#force_extended_insurance").is(':checked')){
			$("#sub_force_extended_insurance").attr('checked', true);  
		} else {
			$("#sub_force_extended_insurance").attr('checked', false);  
		}
	}
}


function hideWindow(winName, noReload){
	if (document.getElementById(winName)){
		document.getElementById(winName).style.display='none';
	}


	///////////////////////  Actualizamos valores ////////////////////////


	// Ventana extras
	if (winName=='extras_details' && !noReload){
		$('#additional_drivers').val($('#sub_additional_drivers').val());
		$('#booster_seats').val($('#sub_booster_seats').val());
		$('#baby_seats').val($('#sub_baby_seats').val());
		
		if ($("#sub_force_full_full").is(':checked')){
			$("#force_full_full").attr('checked', true);  
		} else {
			$("#force_full_full").attr('checked', false);  
		}

		if ($("#sub_force_extended_insurance").is(':checked')){
			$("#force_extended_insurance").attr('checked', true);  
		} else {
			$("#force_extended_insurance").attr('checked', false);  
		}

		// Enviamos formulario
		validateAndSendForm(true);
	}




	// Ventana detalles
	if (winName=='vehicle_details'){
		$('#vehicle_details_container').html('<div class="loading"></div>');
	}


	// Ventana save quote
	if (winName=='save_quote_details'){
		$('#save_quote_details_container').html('<div class="loading"></div>');
	}

	////////////////////////////////////////////////////////////////////
}





function loadVehicleDetails(vprovider){
	document.getElementById('vehicle_details').style.display='block';

	lvURL = domain  + 'ajax/loadVehicleDetails.php?vprovider=' + vprovider + '&data=' + xmlEncoded;


	$.get(lvURL ,{},function(res){
		$('#vehicle_details_container').html(res);
	});

}



$(function() {
	$(".boxicons a, .datacollft a, .datacolrgt a").tooltip({
		track: true,
		delay: 0,
		showURL: false,
		fixPNG: true,
		showBody: " - ",
		extraClass: "fancy",
		fixPNG: true
	});
});


function showGetPromoCod(){
	theDisplay = (document.getElementById('showPCCheck').checked) ? 'block' : 'none';
	document.getElementById('getPromoDiv').style.display = theDisplay;

	// contamos clicks
	if (theDisplay=='block'){
		countClick('mod_form', 'promocheck');
	}
	
}


function countClick(page, objectId){

	if (page && objectId){

		ccURL = domain  + 'ajax/countClicks.php?page=' + page + '&id=' + objectId;


		$.get(ccURL ,{},function(res){
			// alert('ok');
		});

	}
}





/*
 * jQuery Tooltip plugin 1.3
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/
 * http://docs.jquery.com/Plugins/Tooltip
 *
 * Copyright (c) 2006 - 2008 Jörn Zaefferer
 *
 * $Id: jquery.tooltip.js 5741 2008-06-21 15:22:16Z joern.zaefferer $
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */;(function($){var helper={},current,title,tID,IE=$.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),track=false;$.tooltip={blocked:false,defaults:{delay:200,fade:false,showURL:true,extraClass:"",top:15,left:15,id:"tooltip"},block:function(){$.tooltip.blocked=!$.tooltip.blocked;}};$.fn.extend({tooltip:function(settings){settings=$.extend({},$.tooltip.defaults,settings);createHelper(settings);return this.each(function(){$.data(this,"tooltip",settings);this.tOpacity=helper.parent.css("opacity");this.tooltipText=this.title;$(this).removeAttr("title");this.alt="";}).mouseover(save).mouseout(hide).click(hide);},fixPNG:IE?function(){return this.each(function(){var image=$(this).css('backgroundImage');if(image.match(/^url\(["']?(.*\.png)["']?\)$/i)){image=RegExp.$1;$(this).css({'backgroundImage':'none','filter':"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+image+"')"}).each(function(){var position=$(this).css('position');if(position!='absolute'&&position!='relative')$(this).css('position','relative');});}});}:function(){return this;},unfixPNG:IE?function(){return this.each(function(){$(this).css({'filter':'',backgroundImage:''});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){$(this)[$(this).html()?"show":"hide"]();});},url:function(){return this.attr('href')||this.attr('src');}});function createHelper(settings){if(helper.parent)return;helper.parent=$('<div id="'+settings.id+'"><h3></h3><div class="body"></div><div class="url"></div></div>').appendTo(document.body).hide();if($.fn.bgiframe)helper.parent.bgiframe();helper.title=$('h3',helper.parent);helper.body=$('div.body',helper.parent);helper.url=$('div.url',helper.parent);}function settings(element){return $.data(element,"tooltip");}function handle(event){if(settings(this).delay)tID=setTimeout(show,settings(this).delay);else
show();track=!!settings(this).track;$(document.body).bind('mousemove',update);update(event);}function save(){if($.tooltip.blocked||this==current||(!this.tooltipText&&!settings(this).bodyHandler))return;current=this;title=this.tooltipText;if(settings(this).bodyHandler){helper.title.hide();var bodyContent=settings(this).bodyHandler.call(this);if(bodyContent.nodeType||bodyContent.jquery){helper.body.empty().append(bodyContent)}else{helper.body.html(bodyContent);}helper.body.show();}else if(settings(this).showBody){var parts=title.split(settings(this).showBody);helper.title.html(parts.shift()).show();helper.body.empty();for(var i=0,part;(part=parts[i]);i++){if(i>0)helper.body.append("<br/>");helper.body.append(part);}helper.body.hideWhenEmpty();}else{helper.title.html(title).show();helper.body.hide();}if(settings(this).showURL&&$(this).url())helper.url.html($(this).url().replace('http://','')).show();else
helper.url.hide();helper.parent.addClass(settings(this).extraClass);if(settings(this).fixPNG)helper.parent.fixPNG();handle.apply(this,arguments);}function show(){tID=null;if((!IE||!$.fn.bgiframe)&&settings(current).fade){if(helper.parent.is(":animated"))helper.parent.stop().show().fadeTo(settings(current).fade,current.tOpacity);else
helper.parent.is(':visible')?helper.parent.fadeTo(settings(current).fade,current.tOpacity):helper.parent.fadeIn(settings(current).fade);}else{helper.parent.show();}update();}function update(event){if($.tooltip.blocked)return;if(event&&event.target.tagName=="OPTION"){return;}if(!track&&helper.parent.is(":visible")){$(document.body).unbind('mousemove',update)}if(current==null){$(document.body).unbind('mousemove',update);return;}helper.parent.removeClass("viewport-right").removeClass("viewport-bottom");var left=helper.parent[0].offsetLeft;var top=helper.parent[0].offsetTop;if(event){left=event.pageX+settings(current).left;top=event.pageY+settings(current).top;var right='auto';if(settings(current).positionLeft){right=$(window).width()-left;left='auto';}helper.parent.css({left:left,right:right,top:top});}var v=viewport(),h=helper.parent[0];if(v.x+v.cx<h.offsetLeft+h.offsetWidth){left-=h.offsetWidth+20+settings(current).left;helper.parent.css({left:left+'px'}).addClass("viewport-right");}if(v.y+v.cy<h.offsetTop+h.offsetHeight){top-=h.offsetHeight+20+settings(current).top;helper.parent.css({top:top+'px'}).addClass("viewport-bottom");}}function viewport(){return{x:$(window).scrollLeft(),y:$(window).scrollTop(),cx:$(window).width(),cy:$(window).height()};}function hide(event){if($.tooltip.blocked)return;if(tID)clearTimeout(tID);current=null;var tsettings=settings(this);function complete(){helper.parent.removeClass(tsettings.extraClass).hide().css("opacity","");}if((!IE||!$.fn.bgiframe)&&tsettings.fade){if(helper.parent.is(':animated'))helper.parent.stop().fadeTo(tsettings.fade,0,complete);else
helper.parent.stop().fadeOut(tsettings.fade,complete);}else
complete();if(settings(this).fixPNG)helper.parent.unfixPNG();}})(jQuery);
