/** COMMON **/
function initLayer() {
	for(i = 0; i < 11; i++) {
  	$("#a"+i).hide();
	}
}
function rollBackLine () {
	for(k = 4; k < 46; k++) {
		nameLine = "sel"+k;
		document.getElementById(nameLine).className = '';
	}
}
/* Menu principal */
function changerLayer(idLayer){
	initLayer();
	if(idLayer == 'contact') {
		/* Affichage contact */
		//$("#contact1").show();
		$("#garantie1").hide();
		$("#help1").hide();
		$("#about1").hide();
		/* Onglet */
		$("#contact0").attr("class","navOn");
		$("#garantie0").attr("class","navOff");
		$("#help0").attr("class","navOff");
		$("#about0").attr("class","navOff");
	}
	else if (idLayer == 'garantie') {
		/* Affichage garantie + change onglet */
		//$("#contact1").hide();
		$("#garantie1").show();
		$("#help1").hide();
		$("#about1").hide();
		/* Onglet */
		$("#contact0").attr("class","navOff");
		$("#garantie0").attr("class","navOn");
		$("#help0").attr("class","navOff");
		$("#about0").attr("class","navOff");
		/* Gestion affichage bloc */
		$("#intro4").show();
		$("#questions4").show();
	}
	else if (idLayer == 'help') {
		/* Affichage help + change onglet */
		//$("#contact1").hide();
		$("#garantie1").hide();
		$("#help1").show();
		$("#about1").hide();
		/* Onglet */
		$("#contact0").attr("class","navOff");
		$("#garantie0").attr("class","navOff");
		$("#help0").attr("class","navOn");
		$("#about0").attr("class","navOff");
		$("#zone2").show;
	}
	else if (idLayer == 'about') {
		/* Affichage about + change onglet */
		//$("#contact1").hide();
		$("#garantie1").hide();
		$("#help1").hide();
		$("#about1").show();
		/* Onglet */
		$("#contact0").attr("class","navOff");
		$("#garantie0").attr("class","navOff");
		$("#help0").attr("class","navOff");
		$("#about0").attr("class","navOn");
		$("#zone3").show();
	}
}
/* Sous menu */
function affSousMenu (idSMenu,idIntro,idQuestions) {
	initLayer();
	rollBackLine();
	if(idSMenu == "smenu5" || idSMenu == "smenu6"  || idSMenu == "smenu7" || idSMenu == "smenu8") {
		$("#zone2").hide();
	}
	if(idSMenu == "smenu9" || idSMenu == "smenu10") {
		$("#zone3").hide();
	}
	for(i = 0; i < 11; i++)
	{
		var nameMenu = "smenu"+i;
		var nameIntro = "intro"+i;
		var nameQ = "questions"+i;
		if(nameMenu == idSMenu) {
			$("#"+idSMenu).attr("class","zoneHelpOn");
			$("#"+idIntro).show();
			$("#"+idQuestions).show();
		}
		else {
			/* Exception */
			if(i != 4 && i != 0 && i != 1 && i != 2 && i != 3) {
				$("#"+nameMenu).attr("class","zoneHelpOff");
			  $("#"+nameIntro).hide();
			  $("#"+nameQ).hide();
			}
		}
	}
}
/* Affichage questions / reponses */
function affAnswers (idOrigine,numBloc,maxNumOrigine,lineSelected) {
	rollBackLine();
	$("#"+lineSelected).attr("class","lineSel");
	for(i = 0; i < 11; i++) {
		nameOrigine = "a"+i;
		if(nameOrigine == idOrigine) {
			$("#"+idOrigine).show();
			for(j = 0; j < maxNumOrigine; j++) {
				nameQ = idOrigine+"-"+j;
				if(j == numBloc) {
					$("#"+idOrigine+"-"+numBloc).show();
				}
				else {
					$("#"+nameQ).hide();
				}
			}
		}
		else {
      $("#"+nameOrigine).hide();
		}
	}	
}
/** END COMMON **/
/** CONTACT **/
function ContainsSomething(Field)
{
	if ((Field.type == "text") || (Field.type == "textarea"))
	{
		if (Field.value == "")
		{
			return false;
		}
	}
	else
	{   
		if (returnSelection(Field) == null)
		{
			return false;
		}
	}
	return true;
}

function ValidEmail(Field)
{
	if (!ContainsSomething(Field))
	{
		return false;
	}
	if (Field.value.indexOf("@")==-1  
	|| Field.value.indexOf(".")==-1 
	|| Field.value.indexOf(" ")!=-1 
	|| Field.value.length<6)
	{
		return false;
	}
	else
	{
		return true;
	}
}   

function IsOnlyLetters(Field)
{
	if (!ContainsSomething(Field))
	{
		return false;
	}
	var Letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÜÖÄ'´ -"
	for (i=0; i < Field.value.length; i++)
	{
		var CheckChar = Field.value.charAt(i);
		CheckChar = CheckChar.toUpperCase();
		if (Letters.indexOf(CheckChar) == -1)
		{
			return false;
		}
	}
	return true;
}

function IsNotEqual(Field, strCompare)
{
	if (Field.value== strCompare) {
		return false;
	}
	return true;
}

function checkForm()
{
	var error = false;
	
	if (!ContainsSomething(document.Contact.LastName))
	{
		$("#LastName").attr("class","err");
		error = true;
	}
	else 
    $("#LastName").attr("class","text");
	
	if (!ContainsSomething(document.Contact.FirstName))
	{
		$("#FirstName").attr("class","err");
		error = true;
	}
	else 
    $("#FirstName").attr("class","text");
	
	if (!ContainsSomething(document.Contact.Company))
	{
		$("#Company").attr("class","err");
		error = true;
	}
	else 
    $("#Company").attr("class","text");
	
	if (!ContainsSomething(document.Contact.ContactMSG))
	{
		$("#ContactMSG").attr("class","err");
		error = true;
		//document.location = '#Tel';
	}
	else 
    $("#ContactMSG").attr("class","text");
	
	if (!ValidEmail(document.Contact.Login))
	{
		$("#strLogin").attr("class","err");
		dE('badMail');
		error = true;
	}
	else
	{
		$("#strLogin").attr("class","text");
		$("#badMail").hide();
	}
	
	if(error==true)
	{
		dE('error');
		document.location = '#q';
		return false;
	}
	else objectMail();
}

function objectMail() {
	var Cobject = document.Contact.ContactSubject.value;
	var StaticObj = document.Contact.BuyerEmailSubject.value;
	document.Contact.BuyerEmailSubject.value = StaticObj+' - '+Cobject;
	document.Contact.submit();
}
function ck(sind) {
	var mess;
	hidansw();
	// tableau des valeurs pour lesquelles le formulaire est requis
	//var tabSind = new Array('qDE', 'qWI', 'qOC', 'qMP', 'qAU','qMX');
	if (sind != "") {
		switch(sind) {										
			case 'qWI':
				mess = true;
				break;
			case 'qOC':
				mess = true;
				break;
			case 'qAU':
				mess = true;
				break;
			case 'qIP':
				mess = true;
				break;
			case 'qMP':
				mess = true;
				break;
			case 'qMX':
				mess = true;
				break;
			default :
				mess = false;
				break;
		}
		if(mess == true) {
			dE('mess');
			dE('q');
		}			
		dE(sind);
		
		if (sind == 'qOC') {
		//|| sind == 'qPL'
			dE("nuor");
		}
	}
}
function sel() {
	var sind = document.Contact.ContactSubject.options[document.Contact.ContactSubject.options.selectedIndex].value;
	hidall();
	if (sind != "") {
		dE(sind);
		dE("QUES");
		if(sind != 'qCP') dE('qAU');
	}
}
function dE (el) {
	document.getElementById(el).style.display = 'block';
}
function hidall () {
	hidansw();
	//liste des valeurs des elements à masquer
	var maskQ = new Array('AIP', 'QLL', 'QLC', 'QLR', 'QMC', 'QSP', 'AUT', 'QUES', 'qAU','QMX');
	for (i=0; i<maskQ.length; i++) {
		document.getElementById(maskQ[i]).style.display = "none";
	}
}
function hidansw() {
	//liste des valeurs des elements à masquer
	var maskA = new Array('nuor', 'q', 'mess', 'badMail', 'error', 'qAI', 'qCP', 'qCP', 'qPA', 'qME', 'qMG', 'qRE', 'qEX', 'qTL', 'qOC', 'qPL', 'qFA', 'qDE', 'qRM', 'qMR', 'qCB', 'qIM', 'qMP', 'qNL', 'qIP', 'qWI', 'qPE', 'qEC', 'qDL', 'qLE', 'qCC', 'qRP', 'qDEV', 'qMM', 'qLER', 'qGA' ,'qLW');
	for (i=0; i<maskA.length; i++) {
		document.getElementById(maskA[i]).style.display = "none";
	}
}

function getAbsolutePos(el) {
	var r = { x: el.offsetLeft, y: el.offsetTop };
	if (el.offsetParent) {
		var tmp = getAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}

$(document).ready(function(){
  // EVENTS TABS
  //$("#contact0").click(function(){
    //changerLayer("contact");
  //});
  $("#garantie0").click(function(){
    changerLayer("garantie");
  });
  $("#help0").click(function(){
    changerLayer("help");
  });
  $("#about0").click(function(){
    changerLayer("about");
  });
});