$(document)
		.ready(
				function() {

					arrayOrder = [];

					picOldPos = 0;

					createArray = function() {
						if ($('div#selPic .carPic').attr('id') != undefined) {

							arrayOrder[10] = $('div#selPic .carPic').attr('id');

							i = 20;
						} else {
							i = 10;
						}

						$.each($('div#thumbnails').children().children(
								'.carPic'), function() {

							if ($(this).attr('id') == $(this).attr('name')) {
								arrayOrder[i] = 'n' + $(this).attr('id');
							} else {
								arrayOrder[i] = $(this).attr('id');
							}

							i = i + 10;
						});

						if ((i > 10)
								&& ($('div#selPic .carPic').attr('id') == undefined)) {
							j = 0;
							while ((arrayOrder[j] == undefined)
									&& (j <= arrayOrder.length)) {
								j++;
							}
							nextTarget = ((arrayOrder[j].indexOf('n') >= 0) ? arrayOrder[j]
									.substring(1)
									: arrayOrder[j]);
							nextFirst = 'div#thumbnails #' + nextTarget;

							$(nextFirst).parent().css(
									'background',
									'url(' + baseUrl
											+ '/img/bgs/bg_ord_pic.png)');
							$(nextFirst).parent().css('display', 'block');
							$(nextFirst).parent().css('position', 'relative');
							$(nextFirst)
									.parent()
									.append(
											'<p id ="textPic" style=" font-size:18px; color:#900; display:block; position:absolute; top:25px; left:105px; ">Imagen Principal</p>');
							$(nextFirst).css('float', 'right');
							$(nextFirst).parent().css('width', '300px');
							$(nextFirst).siblings(' .picOrder').addClass(
									'firstPic');
							$(nextFirst).siblings(' .picOrder').removeClass(
									'picOrder');
							$('div#selPic').append($(nextFirst).parent());
							picOldPos = jQuery.inArray(i, arrayOrder);
						}
						chgOrderVal();
						$('div#thumbnails .newAdd').click(processOrderFis);
						$('div#thumbnails .picOrder').removeClass('newAdd');

					}

					createArray();
					
					
					$('.tdCheckSubCat input').change(function(){
						
						if($(this).attr('checked')==false){
							$(this).parent().next().removeClass('checkAdvert');
							
						}	
						
						if($(this).attr('checked')==true){
							if($('#total_'+$(this).parents('form table').attr('name')).attr('value')==''){
								$('#total_'+$(this).parents('form table').attr('name')).attr('value',0);
							}else{
								$('#total_'+$(this).parents('form table').attr('name')).attr('value',parseInt(($('#total_'+$(this).parents('form table').attr('name')).attr('value')))+10);
							}	
						
						
						}else{
							if($('#total_'+$(this).parents('form table').attr('name')).attr('value')==0){
								$('#total_'+$(this).parents('form table').attr('name')).attr('value','');
							}else{
								$('#total_'+$(this).parents('form table').attr('name')).attr('value',parseInt(($('#total_'+$(this).parents('form table').attr('name')).attr('value')))-10);
							}	
							
						}
						
						if($(this).attr('checked')==true){
							if($('.checkAdvert').length == 0){ 
									$(this).parent().next().html('<div class="op-extra">A partir de ahora, cada opción extra que requiera marcar le costara a razón de 10€ + I.V.A. por “check”</div>');
									$(this).parent().next().addClass('checkAdvert');
									$(this).parent().next().addClass('notice');
									//alert('total_'+$(this).parent().parent().parent().parent().attr('name'));
									
								}
						}else{
							if($('.checkAdvert').length == 0){ 
								$(this).parent().next().html('');
								$('.checkAdvert').removeClass('checkAdvert');
								$('.notice').html('');
								
							}
						}
						
					});
					
//					$('.tdCheckSubCat input').click(function(){
//						if($('.checkAdvert').length == 0){ 
//						$(this).parent().next().html('<div class="op-extra">A partir de ahora, cada opción extra que requiera marcar le costara a razón de 10€ + I.V.A. por “check”</div>');
//						$(this).parent().next().addClass('checkAdvert');
//						}
//					});
					
					
					$('form [name="serviceCategory"]')
					.change(
							function(){
								$('.visibleSubCategory').css('display','none');
								$('.visibleSubCategory').removeClass('visibleSubCategory');
								
								if($('#'+$(this).attr('value')+'_type').attr('typeservice')==1){									
									$('form [name="make"]').attr('disabled',false);
								}else{
									if($('form [name="make"]').attr('disabled')==false){
										$('form [name="make"]').attr('value',0);
										$('form [name="make"]').attr('disabled',true);
									}
									
									$('form [name="'+$(this).attr('value')+'"]').css('display','block');
									$('form [name="'+$(this).attr('value')+'"]').addClass('visibleSubCategory');
								}	
							});
					
                                        /**
                                         *  When a make is select we need to refresh the model input select list values
                                         *  
                                         *  @author     PHILL
                                         */
					$('form [name="make"]').change(
                                            function() 
                                            {
                                                make = $(this).attr('value');
                                                $.get(baseUrl + '/com/get-models/make/' + make, function(data) 
                                                    {
                                                        html = '<option value="0">Cualquiera</option>' + data;
                                                        $('form [name="model"]').html(html);
                                                    });
                                            }
                                        );
                                            
                                        /**
                                         *  In case of make is already selected (ex, coming back with the "back" button navigator) we need to refresh the model input select list value
                                         *  
                                         *  @author     FERNANDO
                                         */
                                        if($('form [name="make"]').val() != '0')
                                        {   
                                            make = $('form [name="make"]').val();
                                            $.get(baseUrl + '/com/get-models/make/' + make, function(data) 
                                            {
                                                html = '<option value="0">Cualquiera</option>' + data;
                                                $('form [name="model"]').html(html);
                                            });
                                        }
					
			
					if(
							$('#'+$('form [name="category"]').attr('value')+'_type').attr('typeservice')!=1)
								{
						$('form .mini-form-vd   [name="make"]').attr('disabled','disabled');
								}
					else
					{
					
					$('form [name="subCategory"]').attr('disabled','disabled');
					}
						//changes selects depending of the type of category 
					// type = 1  , populate make select
					// type = 2 , populate subCategory select
					// type = 3 , populate anything
					//@Cesar
					$('form [name="category"]')
					
							
				
					
					.change(
							
							function() {
								
							/*	
								if(
										$('form [name="category"]').attr('value') != 'taller_oficial')
											{
									$('form [name="make"]').attr('disabled','disabled');
									$('form [name="subCategory"]').removeAttr('disabled');
											}
								else
									{
									$('form [name="make"]').removeAttr('disabled');
									$('form [name="subCategory"]').attr('disabled','disabled');
									}
							*/
								cat = $(this).attr('value');
								
								
								$
										.get(
												baseUrl
														+ '/com-service-directory/get-child/category/'
														+ cat,
												function(data) {
												
													type = data.substring(0,4);
													data = data.substring(4);
													
													html = '<option value="0">Cualquiera</option>'
															+data ;
													
													if(type=='make'){
														
													$(														
															'form [name="subCategory"]')
															.html('<option value="0">Cualquiera</option>');
													$('form [name="make"]').removeAttr('disabled');
													$('form [name="subCategory"]').attr('disabled','disabled');
													
													
													$(														
													'form [name="make"]')
													.html(html);
													}else if(type=='subc'){
														$('.mini-form-vd form [name="make"]').attr('disabled','disabled');
														
														$(														
														'form [name="make"]')
														.html('<option value="0">Cualquiera</option>');
														$('form [name="subCategory"]')
															.html(html);
														$('form [name="subCategory"]').removeAttr('disabled');
														
														
													}else{
														$('form [name="subCategory"]').attr('disabled','disabled');
														$('form .mini-form-vd [name="make"]').attr('disabled','disabled');
														
														$(														
														'form [name="subCategory"]')
														.html('<option value="0">Cualquiera</option>');
														
														$(														
														'form [name="make"]')
														.html('<option value="0">Cualquiera</option>');	
														
														
													}
													

												});

							});

					$('form [name="carMake"]')
							.change(
									function() {
										make = $(this).attr('value');

										$
												.get(
														baseUrl
																+ '/com/get-models/make/'
																+ make,
														function(data) {

															html = '<option value="0">Seleccionar Modelo</option>'
																	+ data;

															$(
																	'form [name="carModel"]')
																	.html(html);

														});

									});

					$('#head-boto .box-login,#head-boto .box-login >*').hover(
							function() {

								$('#head-boto .box-sesion').stop();
								$('#head-boto .box-sesion').css('opacity', 100)
								$('#head-boto .box-sesion').css('display',
										'block');

							}
					/*
					 * function(){
					 * 
					 * $('#head-boto .box-sesion').css('display','none'); }
					 */
					);
                                            
                                        // Onpress enter event login    
                                        $('.box-sesion #form1').keypress(function(e){
                                            key = e.which;
                                            if(key == null)
                                            {
                                                key = e.keyCode;
                                            }
                                            
                                            if(key == 13)
                                            {
                                                $(this).submit();
                                            }
                                        });

					$('#head-boto .box-sesion').mouseleave(function() {
						$('#head-boto .box-sesion').fadeOut(5000);
						/*
						 * $('#head-boto .box-sesion').css( 'display', 'none');
						 */

					}
					/*
					 * function(){
					 * 
					 * $('#head-boto .box-sesion').css('display','none'); }
					 */
					);

					$('#head-boto .box-sesion').hover(function() {
						$('#head-boto .box-sesion').stop();
						$('#head-boto .box-sesion').css('opacity', 100)
						$('#head-boto .box-sesion').css('display', 'block');

					});

					$('#head').mouseenter(function() {
						$('#head-boto .box-sesion').fadeOut(5000);
						/*
						 * $('#head-boto .box-sesion').css( 'display', 'none');
						 */

					});
					/*
					 * function(){
					 * 
					 * $('#head-boto .box-sesion').css('display','none'); }
					 */

					$('#head-boto .last').mouseenter(function() {
						$('#head-boto .box-sesion').fadeOut(5000);
						/*
						 * $('#head-boto .box-sesion').css( 'display', 'none');
						 */

					}

					/*
					 * function(){
					 * 
					 * $('#head-boto .box-sesion').css('display','none'); }
					 */
					);
					idCheckeds = new Array;
					$('div#cont-right .unchecked').change(
							function() {
								if ($(this).is(':checked')) {

									countCheckeds = idCheckeds.length;
									idCheckeds.push($(this).attr('id'));

									if (countCheckeds >= 3) {
										$(
												'div#cont-right #'
														+ idCheckeds.shift())
												.attr('checked', false);
									}

								} else {
									idCheckeds.splice(idCheckeds
											.indexOf($(this).attr('id')), 1);

								}
								url = baseUrl + '/car/compare/carIds/';
								for (i = 0; i <= (idCheckeds.length) - 1; i++) {
									url += idCheckeds[i] + '-';
								}
								url = url.substring(0, url.length - 1);
								$('div#cont-right #urlComp').attr('href', url);

							});

					function processOrderFis() {

						if ($(this).hasClass('newAdd')) {
							$('div#thumbnails').append(
									$('div#selPic .firstPic').parent());
							$('#textPic').remove();
							$('div#thumbnails .firstPic').parent().css('width',
									'102px');
							$('div#thumbnails .firstPic').parent().css(
									'background', '');
							$('div#thumbnails .firstPic').addClass('picOrder');
							$('div#thumbnails .firstPic').siblings('.carPic')
									.css('float', 'left');
							$('div#thumbnails .firstPic').removeClass(
									'firstPic');
							if (picOldPos > 0) {
								arrayOrder[picOldPos] = arrayOrder[0];
								arrayOrder[0] = undefined;
							}

							$(this).parent().css(
									'background',
									'url(' + baseUrl
											+ '/img/bgs/bg_ord_pic.png)');
							$(this).parent().css('display', 'block');
							$(this).parent().css('position', 'relative');
							$(this)
									.parent()
									.append(
											'<p id ="textPic" style=" font-size:18px; color:#900; display:block; position:absolute; top:25px; left:105px; ">Imagen Principal</p>');
							$(this).siblings('.carPic').css('float', 'right');

							$(this).parent().css('width', '300px');
							$(this).removeClass('picOrder');

							$(this).addClass('firstPic');
							$('div#selPic').append($(this).parent());
							picOldPos = jQuery.inArray($(this).siblings(
									'.carPic').attr('id'), arrayOrder);
							arrayOrder[picOldPos] = undefined;
							arrayOrder[0] = $(this).siblings('.carPic').attr(
									'id');
						}

						chgOrderVal();
						changeRankCurrentCarPic();

					}

					$('#head-boto').mouseleave(function() {

						/*
						 * $('#head-boto .box-sesion').css( 'display', 'none');
						 */

						$('#head-boto .box-sesion').fadeOut(5000);

					}
					/*
					 * function(){
					 * 
					 * $('#head-boto .box-sesion').css('display','none'); }
					 */
					);
					
					
					
					function changeRankCurrentCarPic(){
						
						if($('#selPic .firstPic').length>0){

								if(($('#selPic .firstPic').attr('src').indexOf('med_thumb'))>0){
									
									$('#currentCarPic').attr('src',$('#selPic .firstPic').attr('src').replace('med_thumb','small_thumb'));
									
								}else{
									
									selPicId = $('#selPic .carPic').attr('id');
									src = baseUrl + '/com/show-thumbnail-rank/instid/'+instid+'/?id='+(selPicId);			
												if($('#currentCarPic').length > 0){
														$('#currentCarPic').attr('src',src);
													}
													$('#carRankSelPic').remove();
													$('#bg-body').append('<input type="hidden" value="'+src+'" id="carRankSelPic">');
		
							
								}
							
					}else{
						if($('#currentCarPic').length > 0){
							$('#currentCarPic').attr('src',baseUrl+'/img/foto/gris_55x45.jpg');
						}
						$('#carRankSelPic').remove();
					}		
						
					}

					function newClickables() {
						$('div#thumbnails .unclickable')
								.click(
										function() {										
											if ($(this).siblings('.firstPic').length > 0) {
												while (arrayOrder.shift() == undefined) {
												}
												arrayOrder.unshift(undefined);
												if(arrayOrder.indexOf($(this).attr('id'))>0){
													arrayOrder[arrayOrder.indexOf($(this).attr('id'))]=undefined;
												}
												i = 0;

												while ((arrayOrder[i] == undefined)
														&& (i <= arrayOrder.length)) {
													i++;
												}												
												if (arrayOrder[i] != undefined) {													
													nextTarget = ((arrayOrder[i]
															.indexOf('n') >= 0) ? arrayOrder[i]
															.substring(1)
															: arrayOrder[i]);
													nextFirst = 'div#thumbnails #'
															+ nextTarget;

													$(nextFirst)
															.parent()
															.css(
																	'background',
																	'url('
																			+ baseUrl
																			+ '/img/bgs/bg_ord_pic.png)');
													$(nextFirst).parent().css(
															'display', 'block');
													$(nextFirst).parent().css(
															'position',
															'relative');
													$(nextFirst)
															.parent()
															.append(
																	'<p id ="textPic" style=" font-size:18px; color:#900; display:block; position:absolute; top:25px; left:105px; ">Imagen Principal</p>');
													$(nextFirst).css('float',
															'right');
													$(nextFirst).parent().css(
															'width', '300px');
													$(nextFirst).siblings('.picOrder').addClass('firstPic');
													$(nextFirst).siblings('.picOrder').removeClass('picOrder');
													$('div#selPic').append(
															$(nextFirst)
																	.parent());
													picOldPos = jQuery.inArray(
															i, arrayOrder);
												} else {

													arrayOrder = new Array;
												}
											}

											chgOrderVal();

											id = $(this).attr('id');
											$(this).parent().remove();

											$
													.get(baseUrl
															+ '/com/pro-user-delete-fis-pic/id/'
															+ id);
											
											changeRankCurrentCarPic();

										});
					}
					
					
					
					

					$("div#contentPreffered").hover(function() {
						$(this).children().children('#preffered').stop();
						$(this).children().children('#preffered').animate({
							bottom : '+0'
						});
						// $(this).css('bottom','0px');
					}, function() {
						$(this).children().children('#preffered').stop();
						$(this).children().children('#preffered').animate({
							bottom : '-35'
						});

					});

					$("div#contentHightlited").hover(function() {
						$(this).children().children('#hightlited').stop();
						$(this).children().children('#hightlited').animate({
							height: '50'
						});
						// $(this).css('bottom','0px');
					}, function() {
						$(this).children().children('#hightlited').stop();
						$(this).children().children('#hightlited').animate({
							height: '18'
                                                        
						});

					});

					

					
					$('.linkLoc').click(function(){
						
						window.open(baseUrl+"/car/location?businessId="+$('.bId').attr('id'),null, "height=900,width=750 ,status=no,toolbar=no,menubar=no,location=no");
					});
                                        
                                       
					$('.linkComp').click(function(){
						window.open(baseUrl+"/car/location?businessId="+$('.bId2').attr('id'),null, "height=900,width=750 ,status=no,toolbar=no,menubar=no,location=no");
					});
					
					$('.linkComp2').click(function(){
						window.open(baseUrl+"/car/location?businessId="+$('.bId3').attr('id'),null, "height=900,width=750 ,status=no,toolbar=no,menubar=no,location=no");
					});
					
					$('#carProSellPrice').keyup(function(){						
						$('#carProSellGrossMargin').attr('value',($('#carProSellPrice').attr('value').replace('.','') - $('#carBuyPrice').attr('value').replace('.','')));
						
					});
					
					$('#carConsumerSellPrice').keyup(function(){						
						$('#carConsumerSellGrossMargin').attr('value',($('#carConsumerSellPrice').attr('value').replace('.','') - $('#carBuyPrice').attr('value').replace('.','')));
						
					});
					
					
					$('#linkFacebook').click(function(){
						var link = document.location.toString();
						var facebookLink = link;
						if(link.indexOf('?')> -1){
							facebookLink = link.substring(0,link.indexOf('?'));
						}
						window.open("http://www.facebook.com/sharer/sharer.php?u="+facebookLink,null, "height=400,width=450 ,status=no,toolbar=no,menubar=no,location=no");
					});
					
					$('#linkTwitter').click(function(){
						
						var link = document.location.toString();
						var twitterLink = link;
						if(link.indexOf('?')> -1){
							twitterLink = link.substring(0,link.indexOf('?'));
						}
						window.open("http://twitter.com/home?status="+twitterLink,null, "height=400,width=450 ,status=no,toolbar=no,menubar=no,location=no");
					});
					
					
					
					
					
					function picOrder() {
						$('div#thumbnails .picOrder')
								.click(
										function() {

											if ($(this).hasClass('picOrder')) {
												$('div#thumbnails')
														.append(
																$(
																		'div#selPic .firstPic')
																		.parent());
												$('#textPic').remove();
												$('div#thumbnails .firstPic')
														.parent().css('width',
																'102px');
												$('div#thumbnails .firstPic')
														.parent().css(
																'background',
																'');
												$('div#thumbnails .firstPic')
														.addClass('picOrder');

												$('div#thumbnails .firstPic')
														.siblings('.carPic')
														.css('float', 'left');
												$('div#thumbnails .firstPic')
														.removeClass('firstPic');
												if (picOldPos > 0) {
													arrayOrder[picOldPos] = arrayOrder[0];
													arrayOrder[0] = undefined;
												}

												$(this)
														.parent()
														.css(
																'background',
																'url('
																		+ baseUrl
																		+ '/img/bgs/bg_ord_pic.png)');
												// $(this).parent().append('<p
												// id ="textPic"
												// style="font-size:18px;color:#900">Imagen
												// Principal</p>');
												$(this).parent().css('display',
														'block');
												$(this).parent().css(
														'position', 'relative');
												$(this)
														.parent()
														.append(
																'<p id ="textPic" style=" font-size:18px; color:#900; display:block; position:absolute; top:25px; left:105px; ">Imagen Principal</p>');
												$(this).siblings('.carPic')
														.css('float', 'right');
												$(this).parent().css('width',
														'300px');
												$(this).removeClass('picOrder');

												$(this).addClass('firstPic');
												$('div#selPic').append(
														$(this).parent());
												picOldPos = jQuery.inArray($(
														this).siblings(
														'.carPic').attr('id'),
														arrayOrder);
												arrayOrder[picOldPos] = undefined;
												arrayOrder[0] = $(this)
														.siblings('.carPic')
														.attr('id');
											}

											chgOrderVal();
											changeRankCurrentCarPic();
										});

					}

					function chgOrderVal() {
						strOrd = "";
						strTempOrd = "";
						$.each(arrayOrder, function(index, value) {
							if (value != undefined) {
								if (value.indexOf('n') >= 0) {
									strTempOrd += index + ":"
											+ value.substring(1) + ",";
								} else {
									strOrd += index + ":" + value + ',';
								}
							}
						});
						$('#order').attr('value', strOrd);
						$('#orderTemp').attr('value', strTempOrd);
					}
					picOrder();
					newClickables();

					$('form [name="correo"],[name="password"]')
							.click(
									function() {

										if ($(this).attr('name') == 'correo') {

											if ($(this).val().substr(0, 10) == 'Correo ele') {
												{
													$(this).attr('value', '');
												}
											}
										} else {
											$(this).attr('value', '');
										}

									});

					$('form [name="correo"],[name="password"]').blur(
							function() {
								if ($(this).attr('value') == '') {
									if ($(this).attr('name') == 'correo') {
										$(this).attr('value',
												'Correo electroníco');
									}

								}

							});

					/*
					 * $("#calendar").datepicker({ showOn: 'both', buttonImage:
					 * 'calendar.png', buttonImageOnly: true, changeYear: true,
					 * numberOfMonths: 2 });
					 */

					/* Add calendar */

					$(function() {

						$("#calendar").datepicker({

							onSelect : function(selectedDate, objDatepicker) {

								$("#selectedDate").val(selectedDate);

								// window.location.href = baseUrl +
								// '/pro/menu/?&search=' +
								// selectedDate;
							}

						});

					});

					// //////////////////////////////////////

					/*
					 * $("#campofecha").datepicker({ showOn: 'both',
					 * buttonImage: 'calendar.png', buttonImageOnly: true,
					 * changeYear: true, numberOfMonths: 2, onSelect:
					 * function(textoFecha, objDatepicker){ $("#mensaje").html("<p>Has
					 * seleccionado: " + textoFecha + "</p>"); } });
					 * 
					 * 
					 */

					/* add car ranking */

					params = new Array();

					$('form [name="carMake"]').change(function() {
						value = $(this).attr('value');

						params['make'] = 'make=' + value;
						if (value == 1) {
							params['make'] = '';
							params['model'] = '';
						}
						url = makeUrl();

					});

					$('form [name="carModel"]').change(function() {
						value = $(this).attr('value');
						params['model'] = 'model=' + value;

						url = makeUrl();

					});

					$('form [name="carTransmissionType"]').change(function() {
						value = $(this).attr('value');

						params['trx'] = 'trx=' + value;

						url = makeUrl();

					});

					$('form [name="carFuel"]').change(function() {
						value = $(this).attr('value');

						params['fuel'] = 'fuel=' + value;

						url = makeUrl();

					});

					$('form [name="carChassisType"]').change(function() {
						value = $(this).attr('value');

						params['chassis'] = 'chassis=' + value;

						url = makeUrl();

					});

					$('form [name="carNumberPlateDateYear"]').change(
							function() {
								value = $(this).attr('value');

								params['year'] = 'year=' + value;

								url = makeUrl();

							});

					$('form [name="carMileage"]').keyup(function() {
						value = $(this).attr('value');

						params['km'] = 'km=' + value;

						if (value.length > 2) {

							url = makeUrl();

						}

					});

					$('form #logoPhoto').change(function() {

						$('#logoText').val($('#logoPhoto').val());

					});
					$('form [name="carHorsePower"]').keyup(function() {
						value = $(this).attr('value');

						params['hp'] = 'hp=' + value;

						if (value.length > 2) {

							url = makeUrl();

						}

					});

					$('form [name="carConsumerSellPrice"]').keyup(function() {
						value = $(this).attr('value');

						params['price'] = 'price=' + value;

						if (value.length > 2) {

							url = makeUrl();

						}

					});

					function makeUrl() {
						rUrl = '';

						and = '';

						for ( var i in params)

						{
							// alert(params[i]);
							// if(params[i] != 'make=1'){
							// if(params[i].substr(5) != 'model')

							rUrl = rUrl + and + params[i];
							if (params[i] != '') {
								and = '&';
							}

							// }

						}

						rUrl = baseUrl + '/com/car-add-rank/' + rUrl;

						// alert(rUrl);

						return rUrl;
					}

				}); // Fin

/* Add car */

$(function($) {
	$.datepicker.regional['es'] = {
		closeText : 'Cerrar',
		prevText : '&#x3c;Ant',
		nextText : 'Sig&#x3e;',
		currentText : 'Hoy',
		monthNames : [ 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio',
				'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre',
				'Diciembre' ],
		monthNamesShort : [ 'Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul',
				'Ago', 'Sep', 'Oct', 'Nov', 'Dic' ],
		dayNames : [ 'Domingo', 'Lunes', 'Martes', 'Mi&eacute;rcoles',
				'Jueves', 'Viernes', 'S&aacute;bado' ],
		dayNamesShort : [ 'Dom', 'Lun', 'Mar', 'Mi&eacute;', 'Juv', 'Vie',
				'S&aacute;b' ],
		dayNamesMin : [ 'Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'S&aacute;' ],
		weekHeader : 'Sm',
		dateFormat : 'yy-mm-dd',
		firstDay : 1,
		isRTL : false,
		showMonthAfterYear : false,
		yearSuffix : ''
	};
	$.datepicker.setDefaults($.datepicker.regional['es']);
	// hasta aqui codigo antiguo

	// search filter (ampliar seleccion)

	/* mostrar prueba */

	$('.box-res-gral .result-gral .link').click(function() {

		aUrl = '';
		value = $(this).attr('name');
		switch (value) {
		case 'fuel':
			aUrl = baseUrl + '/com/form-filter-fuel' + aUrl;
			break;
		case 'hp':
			aUrl = baseUrl + '/com/form-filter-pot' + aUrl;
			break;
		case 'chassis':
			aUrl = baseUrl + '/com/form-filter-chassis' + aUrl;
			break;
		case 'color_ext':
			aUrl = baseUrl + '/com/form-filter-colorext' + aUrl;
			break;
		case 'upholstry':
			aUrl = baseUrl + '/com/form-filter-upholstry' + aUrl;
			break;
		case 'color_int':
			aUrl = baseUrl + '/com/form-filter-colorint' + aUrl;
			break;
		case 'equip':
			aUrl = baseUrl + '/com/form-filter-equip' + aUrl;
			break;
		case 'wheel':
			aUrl = baseUrl + '/com/form-filter-wheel' + aUrl;
			break;

		}
		// alert(aUrl);

		$.get(aUrl, function(data)

		{

			html = data;

			$('#main').prepend(html);

		});

		$('#caja').load(aUrl);

	});
	
	
	// rating click handles
	$('.rating_stars, .coment, .see_coments').click( function()
			{
		
		if(($(this).hasClass('inactive')))
			{
			return false;
			}
		bid = $(this).attr('bid');
		
		if($(this).attr('btype') == 'service')
			{
			
			callUrl = baseUrl + '/com-rate/display-comments-layer/bid/' + bid + '/btype/service';
			}
		else
			{
			callUrl = baseUrl + '/com-rate/display-comments-layer/bid/' + bid;
			}
		
		$.get(callUrl, function(data)

				{
			
					html = data; $('.layer-box').remove();
					
					//$('#bg-body').before('<div class="layer-box"  id="comments-layer-box-outer" style="height:100%;position:fixed">');
					$('#bg-body').before(html);
					
					$('#comments-layer-box-outer').click( function(event){
						
						if($(this).attr('id') == 'comments-layer-box-outer')
							{
						$('#comments-layer-box-outer').remove(); 
							}
						
						$('#comments-layer-box-inner').remove();
						},false);
					
					$('#comments-layer-box-inner .cerrar').click( function(){
						
						$('#comments-layer-box-outer').remove(); 	
						$('#comments-layer-box-inner').remove();
						
						return false;
					});
				
				});

		
	
		
		return false;
			});
	
	
	  $('.liveAdminButton').click(function(){
						
                window.open(baseUrl+"/index/help",'mywin', 'resizable=0,height=330,width=500 ,status=0,toolbar=0,menubar=0,location=0');
            });
	
	
	$('.addCategory').click( function()
			{
		
			callUrl = baseUrl + '/com-service-directory/display-add-category-layer';
		
		$.get(callUrl, function(data)

				{
			
			
					html = data; $('.layer-box').remove();
					
					//$('#bg-body').before('<div class="layer-box"  id="comments-layer-box-outer" style="height:100%;position:fixed">');
					$('#bg-body').before(html);
					
					$('#service-layer-box-outer').click( function(event){
						
						if($(this).attr('id') == 'service-layer-box-outer')
							{
						$('#service-layer-box-outer').remove(); 
							}
						
					$('#service-layer-box-inner').remove();
						},false);
					
					$('#service-layer-box-inner .cerrar').click( function(){
						
						$('#service-layer-box-outer').remove(); 	
						$('#service-layer-box-inner').remove();
						
						return false;
					});
				
				});

		
	
		
		return false;
			});
	
	
	//this method changes value to '' if this value equals to his defaultValue  @CESAR
	
	$('.changeDefaultValue').click( function()
			{
				if($(this).attr('value')==$(this).attr('defaultvalue')){
					$(this).attr('value','');
				}
		
			});
	
	
	
	/***************************************************************
	 * 
	 * 	APPRAISALS FORM
	 * 
	 **************************************************************/
	
	$('.appraisalsForm input[type="checkbox"]').click(function(){
		$('.appraisalsForm input[name="' + $(this).attr('name') + '"]').not(this).removeAttr('checked');	
	});
	
	/***************************************************************
	 * 
	 * 	END APPRAISALS FORM
	 * 
	 **************************************************************/
	
	
	/***************************************************************
	 * 
	 * 	DIRECT SALES USER RESERCED CAR LIST
	 * 
	 **************************************************************/
	$("#directSales-userReservedCarsList-button").toggle(
		function(){
			$("#directSales-userReservedCarsList").cagSlideDown();
		},
		function(){
			$("#directSales-userReservedCarsList").cagSlideUp();
		});
                
        /***************************************************************
	 * 
	 * 	CAR PANEL PERPAGE VALUES
	 * 
	 **************************************************************/
	$(".perPageUpdateAction").change(
		function(){
			$(".perPageUpdateTarget").val($(this).val());
		});    
                
         /***************************************************************
	 * 
	 * 	CAR PANEL ORDER BY VALUES
	 * 
	 **************************************************************/
                
        $(".orderByUpdateAction").change(
		function(){
			$(".orderByUpdateTarget").val($(this).val());
		});    
                
                
      /**
       * 
       * PROCESS LAYER
       * Activate load icon @CESAR
       * 
       */  
       $(".processButton").mousedown(
                function(){
                   
                    
                    if($('#processLayer').length>0){
                     $('#processLayer').css('display','block');   
                    }
                    
                    $(this).parents('form').submit();
                    
                    
                              
                });
                
               
               
		
});

