﻿$(document).ready(function(){	
	$('a[href^="http://"]').addTargetBlank();	
	
	$('#slider').cycle({
		fx: 'fade'
	});
	
	$(".expend-list h2 a, .expend-list h3 a").click(function () {
		var elem = $(this).parents('li');
		
		elem.find('.hide-content').slideToggle();
		
		if(elem.hasClass('expend')){
			elem.removeClass('expend');
		} else {
			elem.addClass('expend');
		}
		
		return false;
	});
	
	if($('#submit_btn').length > 0){
		
		$('#submit_btn').click(function(){
			
			if($('#name').val() == "" || $('#email').val() == "" || $('#desc').val == ""){
				if($('#lang').val() == 'FR'){
					alert('Vous devez remplir les champs marqués d\'une étoile!');
				}else{
					alert('Please, fill the fields marked with a star!');
				}
			}else{
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
							
				if(reg.test($('#email').val()) === false) {
					if($('#lang').val() == 'FR'){
						alert('Le courriel est incorrect!');
					}else{
						alert('Email is not valid!');
					}
				}else{
					var url_post = "ajax/quote_task.php";
					if($('#lang').val() == 'EN'){
						url_post = "../ajax/quote_task.php";
					}
					$.ajax({
						type : 'POST',
							dataType : 'json',
						url : url_post,
						data : {
							name : $('#name').val(),
							company : $('#business').val(),
							email : $('#email').val(),
							phone1 : $('#phone1').val(),
							phone2 : $('#phone2').val(),
							desc : $('#desc').val(),
							lang : $('#lang').val()
						},
						success : function(){
							
							if($('#lang').val() == 'FR'){
								alert('Merci!\n\rNous vous contacterons sous peu.');
							}else{
								alert('Thank you!\n\rWe will contact you shortly.');
							}
							
							$('#name').val(""),
							$('#business').val(""),
							$('#email').val(""),
							$('#phone1').val(""),
							$('#phone2').val(""),
							$('#desc').val("")
						}
					});
				}
			}
		});
	}
});

// Simuler un target=_blank
$.fn.addTargetBlank = function() {
   $(this).bind('click',function(){
		window.open(this.href);
		return false;
	});
};

// vide / remplit un élément on focus / blur
var originalValue = new Array;
$.fn.emptyField = function() {
	val = $(this).val();
	
	if(!originalValue[$(this).attr('id')]) {
		originalValue[$(this).attr('id')] = val;
	}
	
	if(val == originalValue[$(this).attr('id')]) {
		$(this).val('');
	}
	
	$(this).blur(function(){
		if($(this).val() == "") {
			$(this).val(originalValue[$(this).attr('id')]);
		}
	});
}







