$(document).ready(function(){ 
		
		
var refill = 0;		
var mypath = window.location.pathname;
var varsplit = '';

if(mypath.indexOf('form/formulaire.html') != -1){
refill = 1;
mypath = '';
}else if(mypath.indexOf('form/cform') != -1){
refill = 2;
mypath = mypath.replace('/form/cform','');
mypath = mypath.replace('.html','');
}else if(mypath.indexOf('form/vform') != -1){
refill = 3;
mypath = mypath.replace('/form/vform','');
mypath = mypath.replace('.html','');
}else if(mypath.indexOf('form/formulaire4.html')!= -1){
refill = 4;
mypath = '';
}
if(refill != 0){

$.ajax({
		   type: "POST",
		   url:  "../php/input.php",
		   async: false,
		   data: "refill="+refill+"&path="+mypath,
		   success: function(msg){
			//alert(msg);
			$('#signaturecache').html($('#signaturecache').html()+msg);
			}
	});
}	
		
	//menu
	$("#menu a img + img, #bigmenu a img + img").css({
	position:"absolute",
	top:"0px",
	left:"0px"
	})
	//overfade
    $("#menu a:not('.current'), #bigmenu a")
	.css({position:"relative"})
	.hover(
        function(){

            $(this).find("img").next()
			.stop(true,true)
			.fadeIn(200);
			
        }, function(){
			
            $(this).find("img").next().fadeOut(200);
			
        }
    );
	
	//overfade pour ie6
	$("a.overFade img + img").css({
	position:"absolute",
	top:"0px",
	left:"0px"
	})
	//overfade
    $("a.overFade")
	.css({position:"relative"})
	.hover(
        function(){

            $(this).find("img").next()
			.stop(true,true)
			.fadeIn(200);
			
        }, function(){
			
            $(this).find("img").next().fadeOut(200);
			
        }
    );
	
	//slideshow
	$('.pics').cycle({
	fx: 'scrollHorz',
	speed:800,
	//	easing: 'bounceout',
	next:   '#fleche_droite a', 
    prev:   '#fleche_gauche a' 
	});

  
});
		function radiobox(namec){
		var checked = "";
		//alert("[name="+namec+"] :checked");
		$("[name="+namec+"]:checked").each(function(i,elm){checked += elm.value;})
		return checked;
		}
		function checkbox(namec){
		var checked = "";
		//alert("[name="+namec+"] :checked");
		$("[name="+namec+"]:checked").each(function(i,elm){checked += '&'+elm.name+'[]='+elm.value;})
		return checked;
		}
		function inputfield(){
		return $("[type=text]").serialize();
		}
		function selectfield(namec){
		var checked = "";
		$("[name="+namec+"] :selected").each(function(i,elm){checked += '&'+namec+'='+elm.value;})
		return checked;
		}
		function selectfieldarr(namec){
		var checked = "";
		$("[name*="+namec+"] :selected").each(function(i,elm){checked += '&'+namec+'[]='+elm.value;})
		return checked;
		}
		function optionfield(namec){
		var checked = "";
		$("[name="+namec+"]:checked").each(function(i,elm){checked += '&'+namec+'='+elm.value;})
		return checked;
		}
		function inputtextarea(namec){
		var checked = "";
		$("textarea[name="+namec+"]").each(function(i,elm){checked += '&'+namec+'='+elm.value;})
		return checked;
		}
		
		function initradiobox(namec,valuec){
			$("[name="+namec+"]").each(function(i,elm){
				if(valuec == elm.value){
				//alert(namec+'=='+valuec+'=='+elm.value);
				elm.checked = true;
				}
			})
		}
		
function ValiderInscription(){		
var myhref = window.location.pathname;
var check = 1;
if(myhref.indexOf('formulaire.html') != -1){
	var ind = document.getElementsByName('telresidence[]')[0].value;
	var trois = document.getElementsByName('telresidence[]')[1].value;
	var quatre = document.getElementsByName('telresidence[]')[2].value; 
	if(ind.length < 3 || isNaN(ind) || trois.length < 3 || isNaN(trois) || quatre.length < 4 || isNaN(quatre)){

	check =0;
	}else{
	$("#telerreor").html("");
	}
}
		if(check == 0){
			if(!$('#frm_assauto').valid()){
			$("#telerreor").html("<p><em  class=\"error\">le no. de t&eacute;l&eacute;phone doit &ecirc;tre complet</em></p>");
			$('#msgError').removeClass('hidden');
			return false;
			}
		}else{
			if(!$('#frm_assauto').valid()){
			$('#msgError').removeClass('hidden');
			}
		return $('#frm_assauto').valid();
		}
}
function suivant(){
if(document.frm_assauto.onsubmit()){
var inputelm =inputfield();

var myhash = window.location.hash;
var myhref = window.location.pathname;
var mynexturl = '';
var where = '';
var splithash = '';
if(myhref.indexOf('formulaire.html') != -1){
mynexturl = "cform1.html";
//on grab
inputelm += optionfield('arpq');
inputelm += optionfield('groupe');
inputelm += selectfield('prefcontact');
inputelm += selectfield('queltel');
inputelm += selectfield('nombreconducteurs');
inputelm += selectfield('nombrevehicules');
inputelm += selectfield('enfant');
inputelm += optionfield('difficulte');
inputelm += optionfield('credit');


}else if(myhref.indexOf('cform') != -1){
where = myhref.replace('.html','');
where = where.replace('/form/cform','');
splithash = myhash.split('_');
splithash = splithash[0].replace('#','');
if(where < splithash){
where++;
mynexturl = "cform"+where+".html";
where--;
}else{
mynexturl = 'vform1.html';
}
//on grab


inputelm += optionfield('s'+where+'exe');
inputelm += optionfield('c'+where+'ours');
inputelm += optionfield('s'+where+'uspendu');
inputelm += optionfield('a'+where+'nnulee');
//inputelm += optionfield('a'+where+'ntecedents');
inputelm += selectfield('e'+where+'tatcivil');
inputelm += selectfield('t'+where+'ypepermis');
inputelm += selectfieldarr('d'+where+'atepermis');
inputelm += selectfield('c'+where+'ontraventions');
inputelm += selectfield('a'+where+'ssureur');
inputelm += selectfield('c'+where+'ombientemps');
inputelm += selectfield('r'+where+'eclamations');
inputelm += inputtextarea('c'+where+'ontraventionsnote');
inputelm += inputtextarea('r'+where+'eclamationsnote');

}else if(myhref.indexOf('vform') != -1){
where = myhref.replace('.html','');
where = where.replace('/form/vform','');
splithash = myhash.split('_');
if(where < splithash[1]){
where++;
mynexturl = "vform"+where+".html";
where--;
}else{
mynexturl = 'formulaire4.html';
}

//on grab
inputelm += optionfield('l'+where+'oue');
inputelm += optionfield('m'+where+'odifie');
inputelm += optionfield('a'+where+'ccidente');
inputelm += optionfield('e'+where+'xtansiongarantie');
inputelm += optionfield('r'+where+'esponsabilitecivil');
inputelm += optionfield('r'+where+'estrictionvitres');
inputelm += optionfield('v'+where+'aleurneuf');
inputelm += optionfield('a'+where+'venants');
inputelm += checkbox('a'+where+'ntivol');
inputelm += selectfield('m'+where+'arque');
inputelm += selectfield('a'+where+'nneefab');
inputelm += selectfield('s'+where+'ousmodel');
inputelm += selectfield('c'+where+'ondprincipal');
inputelm += selectfield('c'+where+'ondsecond');
inputelm += selectfieldarr('d'+where+'atevehicule');
inputelm += selectfield('e'+where+'tat');
inputelm += selectfield('c'+where+'reancier');
inputelm += selectfield('s'+where+'uspendu');
inputelm += selectfield('c'+where+'ontraventions');
inputelm += selectfield('r'+where+'esponsabilite');
inputelm += selectfield('f'+where+'ranchiseavec');
inputelm += selectfield('f'+where+'ranchisesans');
inputelm += selectfield('a'+where+'ssureur');
inputelm += selectfield('c'+where+'ombientemps');

inputelm += inputtextarea('c'+where+'ontraventionsnote');



}else if(myhref.indexOf('formulaire4.html')!= -1){
inputelm += selectfield('comment');
inputelm += inputtextarea('notecomp');
mynexturl = "formulaire-terminer.php";

}

mynexturl+=myhash;
$.ajax({
		   type: "POST",
		   url: "../php/session.php",
		   data: encodeURI(inputelm),
		    success: function(msg){
			//alert(msg);
			window.location.href=mynexturl;
			//document.getElementById('link').href= mynexturl;
		   }
		});
		//alert('hey');

}		
}
