function get(id){
	return document.getElementById(id);
}

function menu_over(id){
	get('btn_'+id).src = 'images/white_btn_over2.gif';
}

function menu_out(id){
	get('btn_'+id).src = 'images/white_btn.gif';
}



function checkForm1 ()
{
    var err = '';

    if (!get('mr').checked && !get('mr2').checked && !get('mr3').checked) err +='La civilité est obligatoire.\n';

	if(!get('nom').value) err+= "Le nom est obligatoire.\n";

	if(!get('prenom').value) err+= "Le prénom est obligatoire.\n";

    if (!get('telephone').value && !get('email').value) err+='Merci de renseigné au moins votre téléphone ou votre email. \n';

    if(get('email').value){
        if(!isEmail(get('email').value)) err+= "Le champs \"Email\" n'est pas correctement renseigné.\n";
    }

    if(!get('messages').value) err+= "Le message est obligatoire.\n";


    //if(!get('societe').value)

	if(err) alert(err);
	else get('formcontact').submit();
}

function createObject(type){
	var select = get('object');

	var size = select.length;
	for(i = 0 ; i < size ; i++){
		select.remove(0);
	}

	var client = new Array(
	'-- Choisissez un objet --',
	'Remarque g�n�rale',
	'Attestation pr�fecture',
	'Relev� d\'informations',
	'Duplicata carte verte',
	'Information tarif',
	'Demande de  devis',
	'Renseignement sur un sinistre'
	);

	var no_client = new Array('-- Choisissez un objet --','Remarque g�n�rale','Information tarif','Demande de  devis');

	if(type == 'client'){
		list_array = client;
	}else{
		list_array = no_client;
	}

	for(i = 0 ; i < list_array.length ; i++){
		y=document.createElement('option');
		y.text  = list_array[i];
		y.value = list_array[i];
		try{
			select.add(y,null); // standards compliant
		}catch(ex){
			select.add(y); // IE only
		}
	}
}


function nextDevisForm(){
	var err = '';
	var perso = '';
	var car = '';
	var prefix = '     -> ';

	if(!get('type').selectedIndex)
	perso+= prefix+"Type de structure\n";
	else if(get('type').selectedIndex == 2 && !get('raison').value)
	perso+=  prefix+"Raison sociale\n";

	if(!get('gender_m').checked && !get('gender_mlle').checked && !get('gender_mme').checked){
		perso+=  prefix+"Civilit�\n";
	}

	if(!get('name').value) perso+=  prefix+"Nom\n";

	if(!get('permis_month').selectedIndex || !get('permis_year').selectedIndex){
		perso+= prefix+"Date du permis\n";
	}

	if(!get('phone_input').value) perso+=  prefix+"Num�ro de t�l�phone\n";

	if(get('email_input').value && !isEmail(get('email_input').value)){
		perso+=  prefix+"Email incorrect\n";
	}

	if(!get('zip').value) perso+= prefix +"Code postal\n";
	else if(!isNumeric(get('zip').value) || get('zip').value.length != 5){
		perso += prefix + "Code postal incorrect (5 chiffres)\n";
	}

	if(perso){
		perso = "Informations personnelles\n" + perso + "\n";
		err += perso;
	}


	if(!get('car_mark').value) car+= prefix +"Marque\n";
	if(!get('car_name').value) car+= prefix +"Appellation commerciale\n";
	if(!get('car_cv').value) car+= prefix +"CV fiscaux\n";
	if(!get('titu').value) car+= prefix +"Titulaire de la carte grise\n";
	if(!get('car_nrj').value) car+= prefix +"Energie\n";

	if(car){
		car = "Informations v�hicule\n" + car + "\n";
		err += car;
	}

	if(err) alert("Certains champs obligatoires du formulaire ne sont pas remplis ou sont incorrects : \n\n" + err);
	else{
		get('step_1').style.visibility = "hidden";
		get('step_2').style.visibility = "visible";
	}
}

function checkDevisForm(){
	var err = '';
	var prefix = '     -> ';


	var histo = '';
	var accident = '';

	if(!get('offer_1').checked && !get('offer_2').checked && !get('offer_3').checked){
		err+=  "Vous devez choisir une offre d'assurance.\n\n";
	}

	if(!get('histo_0_yes').checked && !get('histo_0_no').checked) histo += prefix + "D�lit de fuite\n";
	if(!get('histo_1_yes').checked && !get('histo_1_no').checked) histo += prefix + "Conduite en �tat d'ivresse\n";
	if(!get('histo_2_yes').checked && !get('histo_2_no').checked) histo += prefix + "Suspension, retrait ou annulation du permis de conduire\n";
	if(!get('histo_3_yes').checked && !get('histo_3_no').checked) histo += prefix + "Contrat r�sili� par votre pr�c�dent assureur\n";

	if(histo){
		histo = "Ant�c�dents du conducteur sur 36 mois\n" + histo + "\n";
		err += histo;
	}

	if(!get('accident_0_yes').checked && !get('accident_0_no').checked) accident += prefix + "Corporel responsable\n";
	if(!get('accident_1_yes').checked && !get('accident_1_no').checked) accident += prefix + "Mat�riel responsable\n";
	if(!get('accident_2_yes').checked && !get('accident_2_no').checked) accident += prefix + "Bris de glace\n";
	if(!get('accident_3_yes').checked && !get('accident_3_no').checked) accident += prefix + "Incendie/Vol\n";

	if(accident){
		accident = "Ant�c�dents sinistres sur 36 mois\n" + accident + "\n";
		err += accident;
	}

	if(err) alert("Certaines questions obligatoires du formulaire ne sont pas renseign�es : \n\n" + err);
	else{
		get('devis_form').submit();
	}
}

function returnDevisForm(){
	get('step_2').style.visibility = "hidden";
	get('step_1').style.visibility = "visible";
}

// returns true if the string is a valid email
function isEmail(str){
	var re = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
	return re.test(str);
}

// returns true if the string only contains characters 0-9 and is not null
function isNumeric(str){
	var re = /[\D]/g
	if (re.test(str)) return false;
	return true;
}


function getDim(){

    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;

    if (self.innerHeight) {	// all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }

    return [pageWidth,pageHeight];
}

function preload() {
  var args = preload.arguments;
  imgs = new Array();
  for(x=0; x < args.length; x++) {
    imgs[x] = new Image();
    imgs[x].src = args[x];
  }
}