/*
 * SimpleModal Contact Form
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2009 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: contact.js 185 2009-02-09 21:51:12Z emartin24 $
 *
 */

function linkClickAux(prov){
	//rn_formulario8.php
    direcc = "/formularios/rn_form_pidecita.php";
    if ( prov != "" ) direcc = direcc + "?prov=" + prov;
    // load the contact form using ajax
		$.get(direcc, function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
}

$(document).ready(function () {
	
	$('#formulario1a a.link, #formulario1b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//rn_formulario1.php
		$.get("/formularios/rn_form_meinteresa.php", {art:$('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	$('#formulario2a a.link, #formulario2b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//$.get("/rn_formulario2.php", function(data){
		$.get("/formularios/rn_form_probarcoche.php", {art:$('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			$(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	jQuery('#formulario3a a.link, #formulario3b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario3.php", function(data){
		jQuery.get("/formularios/rn_form_quemellamen.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});

	jQuery('#formulario4a a.link, #formulario4b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario4a.php", function(data){
		jQuery.get("/formularios/rn_form_imprimirficha.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container2',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	jQuery('#formulario5a a.link, #formulario5b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario5.php", function(data){
		jQuery.get("/formularios/rn_form_contactarconcesionario.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container2',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	jQuery('#formularioConta a.link, #formularioContb a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario5.php", function(data){
		jQuery.get("/formularios/rn_form_contactarconcesionario.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	jQuery('#formulario6a a.link, #formulario6b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario6.php", function(data){
		jQuery.get("/formularios/rn_form_citataller.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container2',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	jQuery('#formulario7a a.link, #formulario7b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario7.php", function(data){
		jQuery.get("/formularios/rn_form_contactarconcesionario.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%", ],
				overlayId: 'contact-overlay',
				containerId: 'vn-container2',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close,
				opacity:50,
				height:1100,
				overlayCss: "contact-overlay"
				
			});
		});
	});
	
	jQuery('#formulario8a a.link, #formulario8b a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario8.php", function(data){
		jQuery.get("/formularios/rn_form_pidecita.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%", ],
				overlayId: 'contact-overlay',
				containerId: 'vn-container2',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close,
				opacity:50,
				height:1100,
				overlayCss: "contact-overlay"
				
			});
		});
	});
	
	
	jQuery('#formularioCitaa a.link, #formularioCitab a.link').click(function (e) {
		e.preventDefault();
		linkClickAux("");
	});
	
	
	jQuery('#formularioCitaCentroa a.link').click(function (e) {
		e.preventDefault();
		// load the contact form using ajax
		//jQuery.get("/rn_formulario6.php", function(data){
		jQuery.get("/formularios/rn_form_citataller.php", {art:jQuery('[name=art]').val()}, function(data){
			// create a modal dialog with the data
			jQuery(data).modal({
				close: true,
				position: ["3%",],
				overlayId: 'contact-overlay',
				containerId: 'vn-container',
				onOpen: contact.open,
				onShow: contact.show,
				onClose: contact.close
			});
		});
	});
	
	// preload images
	//var img = ['cancel.png', 'form_bottom.gif', 'form_top.gif', 'loading.gif', 'send.png'];
	var img = [''];
	jQuery(img).each(function () {
		var i = new Image();
		i.src = '/images/' + this;
	});
});

function dist_c_neucita()
{
	
	// load the contact form using ajax
	//jQuery.get("/rn_formulario6.php", function(data){
	jQuery.get("/formularios/rn_form_citataller.php", {art:jQuery('[name=art]').val()}, function(data){
		// create a modal dialog with the data
		jQuery(data).modal({
			close: true,
			position: ["3%",],
			overlayId: 'contact-overlay',
			containerId: 'vn-container',
			onOpen: contact.open,
			onShow: contact.show,
			onClose: contact.close
		});
	});

}

var contact = {
		message: null,
		open: function (dialog) {
			// add padding to the buttons in firefox/mozilla
			if (jQuery.browser.mozilla) {
				jQuery('#contact-container .contact-button').css({
					'padding-bottom': '2px'
				});
			}
			// input field font size
			if (jQuery.browser.safari) {
				jQuery('#contact-container .contact-input').css({
					'font-size': '.9em'
				});
			}

			// dynamically determine height
			var h = 280;
			if (jQuery('#contact-subject').length) {
				h += 26;
			}
			if (jQuery('#contact-cc').length) {
				h += 22;
			}

			var title = jQuery('#contact-container .contact-title').html();
			jQuery('#contact-container .contact-title').html('Loading...');
			dialog.overlay.fadeIn(200, function () {
				dialog.container.fadeIn(200, function () {
					dialog.data.fadeIn(200, function () {
						jQuery('#contact-container .contact-content').animate({
							height: h
						}, function () {
							jQuery('#contact-container .contact-title').html(title);
							jQuery('#contact-container form').fadeIn(200, function () {
								jQuery('#contact-container #contact-name').focus();

								jQuery('#contact-container .contact-cc').click(function () {
									var cc = jQuery('#contact-container #contact-cc');
									cc.is(':checked') ? cc.attr('checked', '') : cc.attr('checked', 'checked');
								});

								// fix png's for IE 6
								if (jQuery.browser.msie && jQuery.browser.version < 7) {
									jQuery('#contact-container .contact-button').each(function () {
										if (jQuery(this).css('backgroundImage').match(/^url[("']+(.*\.png)[)"']+jQuery/i)) {
											var src = RegExp.jQuery1;
											jQuery(this).css({
												backgroundImage: 'none',
												filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' +  src + '", sizingMethod="crop")'
											});
										}
									});
								}
							});
						});
					});
				});
			});
		},
		show: function (dialog) {
			jQuery('#contact-container .contact-send').click(function (e) {
				e.preventDefault();
				// validate form
				if (contact.validate()) {
					jQuery('#contact-container .contact-message').fadeOut(function () {
						jQuery('#contact-container .contact-message').removeClass('contact-error').empty();
					});
					jQuery('#contact-container .contact-title').html('Sending...');
					jQuery('#contact-container form').fadeOut(200);
					jQuery('#contact-container .contact-content').animate({
						height: '80px'
					}, function () {
						jQuery('#contact-container .contact-loading').fadeIn(200, function () {
							jQuery.ajax({
								url: '/envia.php',
								data: jQuery('#contact-container form').serialize() + '&action=send',
								type: 'post',
								cache: false,
								dataType: 'html',
								complete: function (xhr) {
									jQuery('#contact-container .contact-loading').fadeOut(200, function () {
										jQuery('#contact-container .contact-title').html('Thank you!');
										jQuery('#contact-container .contact-message').html(xhr.responseText).fadeIn(200);
									});
								},
								error: contact.error
							});
						});
					});
				}
				else {
					if (jQuery('#contact-container .contact-message:visible').length > 0) {
						var msg = jQuery('#contact-container .contact-message div');
						msg.fadeOut(200, function () {
							msg.empty();
							contact.showError();
							msg.fadeIn(200);
						});
					}
					else {
						jQuery('#contact-container .contact-message').animate({
							height: '30px'
						}, contact.showError);
					}
					
				}
			});
		},
		close: function (dialog) {
			jQuery('#contact-content form').fadeOut(200);		
			jQuery.modal.close();					
		}
	};