
$(document).ready(function(){
	initFormContact();
});

function initFormContact() {
	videText();
	videEmail();
	//cvAjax();
	inputFileButton();
    btnJSParcourir();

    if(navigator.userAgent.indexOf("MSIE") == -1) {
      setTimeout(function(){
        $('#contact_ddn_day').selectmenu({style:'dropdown', width:46});
        $('#contact_ddn_month').selectmenu({style:'dropdown', width:46});
        $('#contact_ddn_year').selectmenu({style:'dropdown', width:46});
        $('#contact_service').selectmenu({style:'dropdown', width:168, heigth:60});
      }, 200);

      setTimeout(function() {
        jQuery("#form_contact .ui-selectmenu-status").html("&nbsp;");
        jQuery("#contact_service-button .ui-selectmenu-status").html(jQuery("#contact_service option:first").html());
        jQuery(".ui-selectmenu-menu li a").each(function() {
          var str = jQuery(this).html();
          if(str =="undefined" || str=="") {
            jQuery(this).parent("li:first").remove();
          }
        });
        jQuery("#contact_ddn_day option:first").remove();
        jQuery("#contact_service-menu").css("height", "84px");
      }, 300);

      jQuery("#contact_service-menu").height("100px");
      setTimeout(function() {
        $('#contact_ddn_day-menu').jScrollPane();
        $('#contact_ddn_month-menu').jScrollPane();
        $('#contact_ddn_year-menu').jScrollPane();
      }, 400);
    }


}

function btnJSParcourir() {
  /*PARCOURIR CV*/
  var img;
  if (hour<9 || hour>=19) {
    img = "/css/images/btn_parcourir_noir.jpg";
    if ($('html').attr('lang') == 'en'){
    img = "/css/images/btn_browse_noir.jpg";}
  } else {
    img = "/css/images/btn_parcourir_blanc.jpg";
    if ($('html').attr('lang') == 'en'){
    img = "/css/images/btn_browse_blanc.jpg";}
  }
  
  jQuery("input.parcourir").filestyle({
    image: img,
    imageheight : 15,
    imagewidth : 58,
    width : 120
  });
}

function inputFileButton(){
    jQuery("#btn_ok").click(function(){
        jQuery("#form_parcourir").submit();
    });
    jQuery("#cv_nom_originel").bind("change", function(){
        jQuery("#contenu-file").html(jQuery(this).val());
    });



}

function videText()
{
	$("textarea").focus(function() {

	    if( $(this).text() == "Merci d'écrire votre message ici...*" || $(this).text() == "Please write your message here...*") {
	        $(this).text(""); 
	    }

	});
}



function videEmail()
{
	$("#email_input_ok").focus(function() {

	        $(this).val("");

	});
}

function cvAjax()
{
	
		
		var $cv_file = $('#cv_nom_originel').val();
		
		var $csrf = $('#cv__csrf_token').val();
		
		$.post("contact/upload",
				   {'cv[nom_originel]': $cv_file , 'cv[_csrf_token]': $csrf},
				   function(data){
					   jQuery("#content").empty().append(data).fadeIn();
					   activerPopin();
				        // formulaire contact
				    	videText();
				    	videEmail();
				    	$("span").remove(); // enlever la duplication des input a chaque chargement
				        Custom.init();
				   }
		 );
		
	
	return false;
}


function contactAjax(url)
{
	
	 if( $("textarea").text() == "Merci d'écrire votre message ici...*" || $("textarea").text() == "Please write your message here...*" ) {
	        $("textarea").text("");
	    }

		// CHOISIR UN SERVICE PAR DEFAUT

	    
	/*   if( $("#contact_service option:selected").text() == "Choisir un service" ) {
	        $("#contact_service option:selected").attr('value','Service client');
	    }
	*/ 
		
		var contact_nom = $('#contact_nom').val();
		
		var contact_prenom = $('#contact_prenom').val();
		
		var contact_email = $('#contact_email').val();
		
		var contact_ville = $('#contact_ville').val();
		
		var contact_code_postal = $('#contact_code_postal').val();
		
		var contact_deja_client_0 = $('input[id=contact_deja_client_0]:checked').val();
		
		var contact_deja_client_1 = $('input[id=contact_deja_client_1]:checked').val();
		
		var contact_ddn_day = $('#contact_ddn_day').val();
				
		var contact_ddn_month = $('#contact_ddn_month').val();
		
		var contact_ddn_year = $('#contact_ddn_year').val();
		
		var contact_message = $('#contact_message').val();
		
		var contact_autorise_infos_1 = $('input[id=contact_autorise_infos_1]:checked').val();
		
		var contact_autorise_offres_1 = $('input[id=contact_autorise_offres_1]:checked').val();
		
		var contact_service = $('#contact_service').val();
		
		var csrf = $('#contact__csrf_token').val();
		
		var contact_ddn = {'day': contact_ddn_day, 'month': contact_ddn_month, 'year': contact_ddn_year};
		
		
		$.post(url,
				
				   {'contact[nom]': contact_nom , 'contact[prenom]': contact_prenom,'contact[email]': contact_email,'contact[ville]': contact_ville,'contact[code_postal]': contact_code_postal,'contact[deja_client]': contact_deja_client_1 || contact_deja_client_0 ,'contact[ddn]': contact_ddn ,'contact[message]': contact_message,'contact[autorise_infos]': contact_autorise_infos_1,'contact[autorise_offres]': contact_autorise_offres_1,'contact[service]': contact_service, 'contact[_csrf_token]': csrf},
				   function(data){
					   jQuery("#content").empty().append(data).fadeIn();

					   activerPopin();
				        // formulaire contact
				    	initFormContact();
				    	$("#popin_inscription span").remove(); // enlever la duplication des input a chaque chargement
				        $("#form_contact span").remove();
                                        
                                        Custom.init();
				   }
		 );
		
	
	return false;
}

