var loadingImg = new Image(50,50); 
	loadingImg.src = "fileadmin/images/ajax_loading.gif";
var loadingImg2 = new Image(40,40); 
	loadingImg2.src = "fileadmin/images/ajax-loader.gif";
var overlayBkImg = new Image(1,1); 
	overlayBkImg.src = "fileadmin/images/overlay_bk.png"; 
var overlayBkImg2 = new Image(1,1); 
	overlayBkImg2.src = "fileadmin/images/overlay_bk_white.png"; 
var bigPath = '';
var bigW = 0;
var bigH = 0;

jQuery.fn.ForceNumericOnly =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, end, home, comma, point, numbers and keypad numbers ONLY
            return (
                key == 8 || 
                key == 9 ||
				key == 13 ||
				key == 35 ||
				key == 36 ||
                key == 46 ||
				key == 190 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        });
    });
};

jQuery.fn.ForceTelephoneNumber =
function()
{
    return this.each(function()
    {
        $(this).keydown(function(e)
        {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, end, home, comma, point, numbers and keypad numbers ONLY
            return (
                key == 8 || 
                key == 9 ||
				key == 13 ||
				key == 35 ||
				key == 36 ||
                key == 46 ||
				key == 107 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        });
    });
};

$(function() {
	jQuery('table.quotation-list-table tr').hover(function(){
		jQuery(this).addClass('over');
	} , function(){
		jQuery(this).removeClass('over');
	});
	jQuery('label.input-radio-label').click(function(){
		jQuery(this).prev('input.input-radio').trigger('click');
	});

	jQuery('a.show-quotation-details-link').click(function(){
		jQuery(this).parent().parent().parent().parent().parent().next('tr').find('div.quotation-details').toggle();
		return false;
	});
	
	jQuery('ul.image_thumbs li').each(function(i){
		var revArray = jQuery(this).find('a').attr('rev').split("|",2);
		if(revArray[1] < bigH || bigH == 0){
			bigH = revArray[1];
		}
	});
	if(bigH != 0){
		jQuery('div.image_big').css({'height':bigH,'overflow':'hidden'});
	}

	jQuery('ul.image_thumbs li a').mouseover(function(){
		var href = jQuery(this).attr('href');
		var revArray = jQuery(this).attr('rev').split("|",2);
		var bigImgDiv = jQuery('div.image_big');
		var bigImg = jQuery('div.image_big img');
		if(bigImg.attr('src') != href){
			bigImg.fadeOut('',function(){bigImg.attr({'src':href,'width':revArray[0],'height':revArray[1]}); bigImg.fadeIn('', function(){  }); });
		}
		return false;
	});

	jQuery('ul#left-menu li a, ul#top-menu li a').hover(function(){
		jQuery(this).parent().find('div.menu-over').fadeIn();
	}, function(){ jQuery(this).parent().find('div.menu-over').fadeOut(); });

	jQuery('input.formatNumeric').ForceNumericOnly();

	jQuery('input.formatTelephone').ForceTelephoneNumber();

	jQuery("div#slider").easySlider({
		auto: true, 
		continuous: true
	});

	jQuery('div.quote-list a').click(function(){
		if(!jQuery('div.quote-list ul li').last().is(':visible')){
			jQuery('div.quote-list ul li:visible').slideUp().next('li').slideDown();
		} else {
			jQuery('div.quote-list ul li:visible').slideUp();
			jQuery('div.quote-list ul li').first().slideDown();
		}
	});

	if(jQuery('#send-email-overlay').hasClass('modal-dialog')){
		jQuery('#send-email-overlay').dialog({
			autoOpen: false,
			draggable: false,
			bgiframe: true,
			resizable: false,
			modal: true,
			minHeight: 300,
			width: 600,
			buttons: {
				'Send email': function() {
					addLoader(jQuery(this).parent());
					tx_dzgetaquote_pi1sendEmailAJAX(xajax.getFormValues('send-email-xajax'));
				},
				'Close': function() {
					jQuery(this).dialog('close');
				}
			}
			});
			jQuery('a.send-email-link').click(function(){
				var id = jQuery(this).attr('id');
				jQuery('input#send-email-quid').val(parseInt(id.replace('send-email-uid-','')));
				jQuery('#send-email-overlay').find('.error-input').removeClass('error-input');
				jQuery('#send-email-info').hide();
				jQuery('#send-email-overlay').dialog('open');
				addLoader(jQuery('#send-email-overlay'));
				tx_dzgetaquote_pi1loadSendEmailDataAJAX(xajax.getFormValues('send-email-xajax'));				
				return false;
			});
	}

	jQuery('#submitQuoteBtn').formValidator({
				onSuccess	: function() { addLoader(jQuery('#get-a-quote-from-step2')); tx_dzgetaquote_pi1addQuotationToSessionAJAX(xajax.getFormValues('get-a-quote-form')); },
				scope		: '#get-a-quote-form',
				errorDiv	: '#error-div-get-a-quote'
			});
	jQuery('#submitQuoteBtn2').formValidator({
				onSuccess	: function() { addLoader(jQuery('#get-a-quote-from-step3')); tx_dzgetaquote_pi1getQuotationWithoutLoginAJAX(xajax.getFormValues('get-a-quote-form-without-login')); },
				scope		: '#get-a-quote-form-without-login',
				errorDiv	: '#error-div-get-a-quote2'
			});
	jQuery('#submitQuoteBtn3').formValidator({
				onSuccess	: function() { addLoader(jQuery('#get-a-quote-from-step3')); tx_dzgetaquote_pi1getQuotationWithLoginAJAX(xajax.getFormValues('get-a-quote-form-with-login')); },
				scope		: '#get-a-quote-form-with-login',
				errorDiv	: '#error-div-get-a-quot3e'
			});
	jQuery('#submitSignupBtn').formValidator({
				onSuccess	: function() { addLoader(jQuery('#signup-form')); tx_dzgetaquote_pi1checkSignupAJAX(xajax.getFormValues('signup-form')); },
				scope		: '#signup-form',
				errorDiv	: '#error-div-signup'
			});
	jQuery('#submitEditAccountBtn').formValidator({
				onSuccess	: function() { addLoader(jQuery('#edit-account-form')); tx_dzgetaquote_pi1checkEditAccountAJAX(xajax.getFormValues('edit-account-form')); },
				scope		: '#edit-account-form-form',
				errorDiv	: '#error-div-signup'
			});

	
	//imagePreview();

	jQuery("a[rel^='prettyPhoto']").each(function(){
		if(jQuery(this).hasClass('preview_pdf')){
			var $href = jQuery(this).attr('href');
			jQuery(this).attr('href',$href+'?iframe=true&width=100%&height=100%');
		}
	});
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_square'});


});


function addFormValidation(){
	jQuery('#submitQuoteBtn2').formValidator({
				onSuccess	: function() { addLoader(jQuery('#get-a-quote-from-step3')); tx_dzgetaquote_pi1getQuotationWithoutLoginAJAX(xajax.getFormValues('get-a-quote-form-without-login')); },
				scope		: '#get-a-quote-form-without-login',
				errorDiv	: '#error-div-get-a-quote2'
			});
	jQuery('#submitQuoteBtn3').formValidator({
				onSuccess	: function() { addLoader(jQuery('#get-a-quote-from-step3')); tx_dzgetaquote_pi1getQuotationWithLoginAJAX(xajax.getFormValues('get-a-quote-form-with-login')); },
				scope		: '#get-a-quote-form-with-login',
				errorDiv	: '#error-div-get-a-quot3e'
			});
}

function addLoader(elem){
	jQuery('body').addClass('loading');
	elem.append('<div id="loadingmask"><div id="loading-mask-loader" class="loader"><img alt="Loading..." src="'+loadingImg.src+'"></div><div id="loading-mask"></div></div>');
}

function addImageLoader(elem){
	jQuery('body').addClass('loading');
	elem.append('<div id="loadingmask"><div id="loading-mask-loader" class="loader"><img alt="Loading..." src="'+loadingImg2.src+'"></div><div id="loading-mask"></div></div>');
}

function removeLoader(){
	jQuery('body').removeClass('loading');
	jQuery('#loadingmask').remove();
}

function goToQuoteQizardStep(step){
	//jQuery('div.get-a-quote-from').find('div.get-a-quote-from-step:visible').animate({ });
	//jQuery('div.get-a-quote-from').find('div#get-a-quote-from-step'+step).animate({ });
	jQuery('div.get-a-quote-from').find('div.get-a-quote-from-step:visible').hide();
	jQuery('div.get-a-quote-from').find('div#get-a-quote-from-step' + step).show();
	return false;
}
