
function showLeftMenu()
{
	$('#meniuParcAuto').show('slow');
	document.getElementById('parcAutoLi').attributes["onclick"].value = "hideLeftMenu(); return false;";
}

function hideLeftMenu()
{
	$('#meniuParcAuto').hide('slow');
	document.getElementById('parcAutoLi').attributes["onclick"].value = "showLeftMenu(); return false;";
	
}

function showConfortDetails($detailsId)
{

	$lastShowed = $('#confortDetalii').val();

	if ($lastShowed == $detailsId)
	return false;
		
	
	if ($lastShowed != '')
	{
		$('#detalii'+$lastShowed).hide('fast');
		$('#poze'+$lastShowed).hide('fast');
	}

	$('#detalii'+$detailsId).show('fast');
	$('#poze'+$detailsId).show('fast');
	
	$('#confortDetalii').val($detailsId);
}
	
function showMenu(menuToShow)
{
	$('#'+menuToShow).show("slow");
	$('#'+menuToShow+'_parent').toggleClass("selected");
	document.getElementById(menuToShow+"_link").attributes["onclick"].value = "hideMenu('"+menuToShow+"'); hideContent('content"+menuToShow+"'); return false;";
}

function hideMenu(menuToHide)
{
	$('#'+menuToHide).hide("slow");
	$('#'+menuToHide+'_parent').toggleClass("selected");
	document.getElementById(menuToHide+"_link").attributes["onclick"].value = "showMenu('"+menuToHide+"'); showContent('content"+menuToHide+"'); return false;";
}

function showContent($divToShow)
{
	$divToHide = $('#lastVisibleContent').val();
	$('#'+$divToHide).hide('fast');
	$('#'+$divToShow).show('fast');
	$('#lastVisibleContent').val($divToShow);
}

function hideContent($divToHide)
{
	$divToHide = $('#lastVisibleContent').val();
	$('#'+$divToHide).hide('fast');
	$('#contentfirst').show('fast');
	$('#lastVisibleContent').val('contentfirst');
}

function submitForm(formId)
{
	if (document.getElementById(formId).onsubmit) {
		if(document.getElementById(formId).onsubmit()) {
		document.getElementById(formId).submit();
		}
		} else {
		document.getElementById(formId).submit();
		}
}
jQuery.ajaxSetup({
	url: "/ajax.php",
	global: false,
	type: "get",
	dataType: "json",
	error: function(XMLHttpRequest, textStatus, errorThrown) {
		jQuery('#error_place').html('Error:' + textStatus);
		jQuery('#error_place').hide(); 
		jQuery('#error_place').show("slow");
	}
});

function getLoadingImage(id) {
	img = jQuery(document.createElement("img"));
	img.attr("id",id);
	img.attr("src", getLoadingImagePath());
	return img;
}

function getLoadingImagePath() {
	return '/images/loading.gif';
}



function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
	    //Netscape compliant
	    scrOfY = window.pageYOffset;
	    scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	    //DOM compliant
	    scrOfY = document.body.scrollTop;
	    scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
	    //IE6 standards compliant mode
	    scrOfY = document.documentElement.scrollTop;
	    scrOfX = document.documentElement.scrollLeft;
	  }
  return [ scrOfX, scrOfY ];
}


(function (jQuery) {

	jQuery.cookie = function(name, value, options) {
	    if (typeof value != 'undefined') { // name and value given, set cookie
	        options = options || {};
	        if (value === null) {
	            value = '';
	            options.expires = -1;
	        }
	        var expires = '';
	        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
	            var date;
	            if (typeof options.expires == 'number') {
	                date = new Date();
	                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
	            } else {
	                date = options.expires;
	            }
	            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
	        }
	        // CAUTION: Needed to parenthesize options.path and options.domain
	        // in the following expressions, otherwise they evaluate to undefined
	        // in the packed version for some reason...
	        var path = options.path ? '; path=' + (options.path) : '';
	        var domain = options.domain ? '; domain=' + (options.domain) : '';
	        var secure = options.secure ? '; secure' : '';
	        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	    } else { // only name given, get cookie
	        var cookieValue = null;
	        if (document.cookie && document.cookie != '') {
	            var cookies = document.cookie.split(';');
	            for (var i = 0; i < cookies.length; i++) {
	                var cookie = jQuery.trim(cookies[i]);
	                // Does this cookie string begin with the name we want?
	                if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
	                    break;
	                }
	            }
	        }
	        return cookieValue;
	    }
	};

	jQuery.modal = function (data, options) {
		return jQuery.modal.impl.init(data, options);
	};

	jQuery.modal.close = function () {
		jQuery.modal.impl.close(true);
	};

	jQuery.fn.modal = function (options) {
		return jQuery.modal.impl.init(this, options);
	};


	jQuery.modal.defaults = {
		overlay: 50,
		overlayId: 'modalOverlay',
		overlayCss: {},
		containerId: 'modalContainer',
		containerCss: {},
		close: true,
		closeTitle: 'Close',
		closeClass: 'modalClose',
		persist: false,
		onOpen: null,
		onShow: null,
		onClose: null
	};

	jQuery.modal.impl = {
		opts: null,
		dialog: {},
		init: function (data, options) {
			// don't allow multiple calls
			if (this.dialog.data) {
				return false;
			}

			// merge defaults and user options
			this.opts = jQuery.extend({}, jQuery.modal.defaults, options);

			// determine how to handle the data based on its type
			if (typeof data == 'object') {
				// convert DOM object to a jQuery object
				data = data instanceof jQuery ? data : jQuery(data);

				// if the object came from the DOM, keep track of its parent
				if (data.parent().parent().size() > 0) {
					this.dialog.parentNode = data.parent();

					// persist changes? if not, make a clone of the element
					if (!this.opts.persist) {
						this.dialog.original = data.clone(true);
					}
				}
			}
			else if (typeof data == 'string' || typeof data == 'number') {
				// just insert the data as innerHTML
				data = jQuery('<div>').html(data);
			}
			else {
				// unsupported data type!
				if (console) {
					console.log('SimpleModal Error: Unsupported data type: ' + typeof data);
				}
				return false;
			}
			this.dialog.data = data.addClass('modalData');
			data = null;

			// create the modal overlay, container and, if necessary, iframe
			this.create();

			// display the modal dialog
			this.open();

			// useful for adding events/manipulating data in the modal dialog
			if (jQuery.isFunction(this.opts.onShow)) {
				this.opts.onShow.apply(this, [this.dialog]);
			}

			// don't break the chain =)
			return this;
		},
		/*
		 * Create and add the modal overlay and container to the page
		 */
		create: function () {
			// create the overlay
			this.dialog.overlay = jQuery('<div>')
				.attr('id', this.opts.overlayId)
				.addClass('modalOverlay')
				.css(jQuery.extend(this.opts.overlayCss, {
					opacity: this.opts.overlay / 100,
					height: '100%',
					width: '100%',
					position: 'fixed',
					left: 0,
					top: 0,
					zIndex: 3000
				}))
				.hide()
				.appendTo('body');

			// create the container
			this.dialog.container = jQuery('<div>')
				.attr('id', this.opts.containerId)
				.addClass('modalContainer')
				.css(jQuery.extend(this.opts.containerCss, {
					position: 'fixed', 
					zIndex: 3100
				}))
				.append(this.opts.close 
					? '<a class="modalCloseImg ' 
						+ this.opts.closeClass 
						+ '" title="' 
						+ this.opts.closeTitle + '"></a>'
					: '')
				.hide()
				.appendTo('body');

			// fix issues with IE and create an iframe
			if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
				this.fixIE();
			}

			// hide the data and add it to the container
			this.dialog.container.append(this.dialog.data.hide());
		},
		/*
		 * Bind events
		 */
		bindEvents: function () {
			var modal = this;

			// bind the close event to any element with the closeClass class
			jQuery('.' + this.opts.closeClass).click(function (e) {
				e.preventDefault();
				modal.close();
			});
		},
		/*
		 * Unbind events
		 */
		unbindEvents: function () {
			// remove the close event
			jQuery('.' + this.opts.closeClass).unbind('click');
		},
		/*
		 * Fix issues in IE 6
		 */
		fixIE: function () {
			var wHeight = jQuery(document).height() + 'px';
			var wWidth = jQuery(document.body).width() + 'px';

			// position hacks
			this.dialog.overlay.css({position: 'absolute', height: wHeight, width: wWidth});
			scro = getScrollXY();
			tpos = scro[1] + 100;
			this.dialog.container.css({position: 'absolute', top: tpos + 'px'});
			

			// add an iframe to prevent select options from bleeding through
			this.dialog.iframe = jQuery('<iframe src="javascript:false;">')
				.css(jQuery.extend(this.opts.iframeCss, {
					opacity: 0, 
					position: 'absolute',
					height: wHeight,
					width: wWidth,
					zIndex: 1000,
					width: '100%',
					top: 0,
					left: 0
				}))
				.hide()
				.appendTo('body');
		},
		/*
		 * Open the modal dialog elements
		 * - Note: If you use the onOpen callback, you must "show" the 
		 *         overlay and container elements manually 
		 *         (the iframe will be handled by SimpleModal)
		 */
		open: function () {
			// display the iframe
			if (this.dialog.iframe) {
				this.dialog.iframe.show();
			}

			if (jQuery.isFunction(this.opts.onOpen)) {
				// execute the onOpen callback 
				this.opts.onOpen.apply(this, [this.dialog]);
			}
			else {
				// display the remaining elements
				this.dialog.overlay.show();
				this.dialog.container.show();
				this.dialog.data.show();
			}
			if (jQuery.browser.msie) {
            	jQuery("#priceApp select").each(function() {
                	jQuery(this).css("visibility", "hidden");
                });
            }
			// bind default events
			this.bindEvents();
		},

		close: function (external) {
			// prevent close when dialog does not exist
			if (!this.dialog.data) {
				return false;
			}
            if (jQuery.browser.msie) {
            	jQuery("#priceApp select").each(function() {
                	jQuery(this).css("visibility", "visible");
                });
            }
			if (jQuery.isFunction(this.opts.onClose) && !external) {
				// execute the onClose callback
				this.opts.onClose.apply(this, [this.dialog]);
			}
			else {
				// if the data came from the DOM, put it back
				if (this.dialog.parentNode) {
					// save changes to the data?
					if (this.opts.persist) {
						// insert the (possibly) modified data back into the DOM
						this.dialog.data.hide().appendTo(this.dialog.parentNode);
					}
					else {
						// remove the current and insert the original, 
						// unmodified data back into the DOM
						this.dialog.data.remove();
						this.dialog.original.appendTo(this.dialog.parentNode);
					}
				}
				else {
					// otherwise, remove it
					this.dialog.data.remove();
				}

				// remove the remaining elements
				this.dialog.container.remove();
				this.dialog.overlay.remove();
				if (this.dialog.iframe) {
					this.dialog.iframe.remove();
				}

				// reset the dialog object
				this.dialog = {};
			}

			// remove the default events
			this.unbindEvents();
		}
	};
})(jQuery);
