var rad20 = {
		tl: { radius: 20 },
		tr: { radius: 20 },
		bl: { radius: 20 },
		br: { radius: 20 },
		antiAlias: true
	}
	var rad15 = {
		tl: { radius: 15 },
		tr: { radius: 15 },
		bl: { radius: 15 },
		br: { radius: 15 },
		antiAlias: true
	}
	var rad10 = {
		tl: { radius: 10 },
		tr: { radius: 10 },
		bl: { radius: 10 },
		br: { radius: 10 },
		antiAlias: true
	}

function chargement(){
	curvyCorners(rad15, "#title-middle-home, #bd-home,#guide-help");
	curvyCorners(rad20, "#nav");
	$("logo").addEvent('click', function(){
		document.location.href="index.php";
	});
	$("logo").setStyle('cursor', 'pointer');

	$("guide").addEvent('click', function(){
		loadTheo(1);
	});
	$("guide").setStyle('cursor', 'pointer');

	$("bd_interactive").setStyle('cursor','pointer');
	$("bd_interactive").addEvent('click', function(){
		loadBD();
	});
}

var color;
var container;
function fond(visite){
	if( visite == 1 ){
		color = "#136d8c";
		container = "container_two";
		document.getElementById('container').id = 'container_two';
	}
	else{
		color = "#F20775";
		container = "container_one";
		document.getElementById('container').id = 'container_one';
	}
}

function loadBD(){
	//alert('Votre resolution : '+screen.width+'px X '+screen.height+'px');
	var bd = "";
	var theo  = new Element('div', {id: 'theo-bg'});
	$(container).adopt(theo);
	document.getElementsByTagName("body").item(0).style.backgroundColor = "#051B23";
	if( screen.width == 1024 && screen.height == 768 ) bd = new Element('div', {'id' : 'boxBD','styles':{ 'opacity':'1','position':'absolute', 'display':'block','margin-left':'0','top':'17%','height':'380px','width':'1170px','border':'0px solid #000000','z-index':'12'}});
	else bd = new Element('div', {'id' : 'boxBD','styles':{ 'opacity':'1','position':'absolute', 'display':'block','margin-left':$(document.body).getWidth()/20,'top':'17%','height':'380px','width':'1170px','border':'0px solid #000000','z-index':'12'}});
	$(document.body).adopt(bd);
	html = '<div style="float:left;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="book_demo" width="1130px" height="370px" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="movie" value="flash/BD/book_demo.swf" /><param name="quality" value="high" /><param value="transparent" name="wmode"/><param name="allowScriptAccess" value="sameDomain" /><embed src="flash/BD/book_demo.swf" quality="high" width="1130px" height="370px" name="book_demo" align="middle" play="true" loop="false" quality="high" transparent="true" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed></object></div>';
	html += '<div style="float:right;"><a href="javascript:closeBD();"><img border="0" align="right" src="img/button_close.png"/></a></div>';
	bd.set('html', html);
}

function closeBD(){
	$('boxBD').dispose();
	$('theo-bg').dispose();
	document.getElementsByTagName("body").item(0).style.backgroundColor = color;
}

function show_contact()
{
	var theo  = new Element('div', {id: 'theo-bg'});
	var contact  = new Element('div', {id: 'form_contact'});
	$(container).adopt(theo);
	$(container).adopt(contact);

	document.getElementsByTagName("body").item(0).style.backgroundColor = "#051B23";

	var req = new Request({

		url: 'ajax/ajax_contact.php',

		onSuccess: function(txt){
			$('form_contact').set('html', txt);
		},

		// Our request will most likely succeed, but just in case, we'll add an
		// onFailure method which will let the user know what happened.
		onFailure: function(){
			$('form_contact').set('text', 'The request failed.');
		}

	});

	req.send();
}

function isValid(str)
{
	if(str == '' || str == undefined)
		return false;
	return true;
}

function displayError(elt)
{
	$(elt).setStyle("color","#D8000C");
	$(elt).setStyle("background-color","#FFBABA");
}

function disableError(elt)
{
	$(elt).setStyle("color","");
	$(elt).setStyle("background-color","");
}

function checkFormContact()
{
	var nbErr = 0;
	var elts = new Array("nom", "prenom", "email", "societe", "sujet", "message");
	var re_email = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ ;
	var re_tel = /^(0[1-6]{1})[0-9]{8}$/;
	var post = "action=sendMail";

	for(var i = 0; i < elts.length; ++i)
	{
		//console.log($("#"+elts[i]).val());
		if(!isValid($(elts[i]).get("value")))
		{
			nbErr++;
			displayError(elts[i]);
		}else
		{
			if(elts[i] != "email")
				post += "&"+elts[i]+"="+$(elts[i]).get("value");
			disableError(elts[i]);
		}
	}

	if($("adresse").get("value")!="")post += "&adresse="+$("adresse").get("value");
	if($("civilite").get("value")!="")post += "&civilite="+$("civilite").get("value");
	if($("ville").get("value")!="")post += "&ville="+$("ville").get("value");
	if($("cp").get("value")!="")post += "&cp="+$("cp").get("value");
	if($("telephone").get("value")!="")post += "&telephone="+$("telephone").get("value");

	/*if(!re_tel.test($("telephone").get("value")))
	{
		nbErr++;
		displayError("telephone");
	}else
	{
		post += "&telephone="+$("telephone").get("value");
		disableError("telephone");
	}*/


	if(!re_email.test($("email").get("value")))
	{
		nbErr++;
		displayError("email");
	}else
	{
		post += "&email="+$("email").get("value");
		disableError("email");
	}

	if(nbErr == 0)
	{
		post += "&societe="+$("societe").get("value");
		//console.log("nouvelle requete ajax : "+post);
		var req = new Request({

		url: 'ajax/ajax_contact.php',
		type: "POST",
		data: post,
		onSuccess: function(response){
				$('form_contact').set('html',response);
			}
		});

		req.send();
	}

}

function hideContactForm()
{
	document.getElementsByTagName("body").item(0).style.backgroundColor = color;
	$("form_contact").dispose();
	$("theo-bg").dispose();
}
