// code by ricardo küster
// www.asgardcommunications.ch
// started jan 2009

// SYSTEM

var xmlHttp

function GetXmlHttpObject() {
	var xmlHttp=null;
	try { // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest(); }
	catch (e) { //Internet Explorer
		try {
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }	
	}
	return xmlHttp;
}

var browserType;

if (document.layers) {browserType = "nn4"}
if (document.all) {browserType = "ie"}
if (window.navigator.userAgent.toLowerCase().match("gecko")) {
	browserType = "gecko"
}

function montrer_log(where) { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState == "complete") {
		document.getElementById(where).innerHTML = xmlHttp.responseText;
	} 
}

function montrer_contenu(id,cat_or_sub) {
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return 
	}
	// designer notes :
	// categories = equivalent to a menu item
	if ((id == '5') && (cat_or_sub == 'categorie')) { var url="liens.php?ajax=true"; }
	else if ((id == '6') && (cat_or_sub == 'categorie')) { var url="contact.php?ajax=true"; }
	else if ((id == '8') && (cat_or_sub == 'categorie')) { var url="spinbooster.php?ajax=true"; }
	else if ((id == '10') && (cat_or_sub == 'categorie')) { var url="demande.php?ajax=true"; }
	// sub_categories = equivalent to a SUB menu item
	else if ((id == '1') && (cat_or_sub == 'sub_categorie')) { var url="produits_mhf.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true"; }
	else if ((id == '2') && (cat_or_sub == 'sub_categorie')) { var url="produits_mmo.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true"; }
	else if ((id == '3') && (cat_or_sub == 'sub_categorie')) { var url="produits_mbc.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true"; }
	else if ((id == '8') && (cat_or_sub == 'sub_categorie')) { var url="offre_emploi.php?ajax=true"; }
	else if ((id == '10') && (cat_or_sub == 'sub_categorie')) { var url="jobs_form.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true"; }
	else if ((id == '11') && (cat_or_sub == 'sub_categorie')) { var url="liens_nh.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true"; }
	else if ((id == '12') && (cat_or_sub == 'sub_categorie')) { var url="references.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true"; }
	else {
		var url = "contenu.php?id="+id+"&contenu="+cat_or_sub+"&ajax=true";
	}
	xmlHttp.onreadystatechange = function() {
		montrer_log('contenu');
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function montrer_news(id) {
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return 
	}
	var url = "news_load.php?id="+id+"&ajax=true";
	xmlHttp.onreadystatechange = function() {
		montrer_log('contenu');
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function montrer_site(first_time) { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState == "complete") {
		if (first_time) { cacher('div_lang_select'); }
		if (first_time) { montrer('div_site_meyrat'); }
		document.getElementById('div_site_meyrat').innerHTML = xmlHttp.responseText;
	} 
}

function langue_select(lang,first_time) {
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return 
	}
	var url="meyrat.php?lang="+lang;
	xmlHttp.onreadystatechange = function() {
		montrer_site(first_time);
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function montrer_tableau_produit(fichier,texte,where,lang) {
	montrer(where);
	cacher('div_tab_diametres');
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return 
	}
	var url = "produits_tableaux.php?fichier=img/produits/tableaux/"+lang+"_"+fichier+".jpg&texte="+texte;
	xmlHttp.onreadystatechange = function() {
		montrer_log(where);
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

function montrer_img_produit(fichier,where) {
	// document.getElementById(where).innerHTML = "<? list($width, $height) = getimagesize('img/produits/"+fichier+".jpg'); ?><img src='img/produits/"+fichier+".jpg' width='<? echo $width; ?>' height='<? echo $height; ?>' border='0' />";
	
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return 
	}
	var url = "produits_img.php?fichier=img/produits/"+fichier+".jpg";
	xmlHttp.onreadystatechange = function() {
		montrer_log(where);
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	}

function check_champs_demande(langue) {
	var can_we_go = false;
	if (document.getElementById("demande_doc").checked == true) {
		can_we_go = true;
	}
	if (document.getElementById("demande_tel").checked == true) {
		can_we_go = true;
	}
	if (document.getElementById("demande_offre").checked == true) {
		can_we_go = true;
	}
	if (can_we_go == false) {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "Je désire - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "Ich wünsche - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "I would like - obligatory<br>"; }
		fade_in('div_contact_log');
		return (false);
	}
	if (form_contact.societe.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "Societé - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "Unternehmen - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "Company - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.societe.focus();
		return (false);
	}
	if (form_contact.nom.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "Nom - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "Name - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "Name - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.nom.focus();
		return (false);
	}
	if (form_contact.npa.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "NPA - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "PLZ - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "ZIP - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.npa.focus();
		return (false);
	}
	if (form_contact.ville.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "Ville - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "Stadt - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "City - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.ville.focus();
		return (false);
	}
	if (form_contact.pays.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "Pays - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "Land - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "Country - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.pays.focus();
		return (false);
	}
	if (form_contact.email.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "E-mail - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "E-mail - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "E-mail - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.email.focus();
		return (false);
	}
	if (form_contact.application.value == "") {
		if (langue == 'fr') { document.getElementById("div_contact_log").innerHTML = "Application - champ obligatoire<br>"; }
		if (langue == 'de') { document.getElementById("div_contact_log").innerHTML = "Anwendung - obligatorisch<br>"; }
		if (langue == 'en') { document.getElementById("div_contact_log").innerHTML = "Application - obligatory<br>"; }
		fade_in('div_contact_log');
		form_contact.application.focus();
		return (false);
	}

	// si tout va bien, envoi le form
	return (true);
}

function envoyer_email(msg,societe,nom,prenom,adresse,npa,ville,pays,tel,fax,email) {
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null) {
		alert ("Browser does not support HTTP Request");
		return 
	}
	document.getElementById("div_contact_log").innerHTML = "<img src='img/loading.gif' width='16' height='16'>";
	var url = "contact_mail.php?ajax=true&msg="+msg+"&societe="+societe+"&nom="+nom+"&prenom="+prenom+"&adresse="+adresse+"&npa="+npa+"&ville="+ville+"&pays="+pays+"&tel="+tel+"&fax="+fax+"&email="+email;
	xmlHttp.onreadystatechange = function() {
		montrer_log('div_contact_log');
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);	
}

// -----

function montrer_menu(where,num_categories) {
	// fait le loop pour fermer toutes les categories
	for (i=1;i<=num_categories;i++) {
		if (where != 'categorie_'+i) {
			document.getElementById('categorie_'+i).style.display = 'none';
		}
	}
	if (document.getElementById(where).style.display == "none") {
		fade_in(where);
	} else {
		fade_out(where);
	}
}

function montrer(where) {
	if (document.getElementById(where).style.display == "none") {
		fade_in(where);
	} else {
		fade_out(where);
	}
}

function cacher(where) {
	document.getElementById(where).style.display = 'none';
	document.getElementById(where).style.opacity = 0;
}

// -----

var tempo = 15;

primeira_vez = true;

function fade_in(where) {
	i = 0;
	document.getElementById(where).style.opacity = 0;
	if (document.getElementById(where).style.display == 'none') {
		document.getElementById(where).style.display = "";
	}
	fade_in_var = window.setInterval("fade_in_app('"+where+"')", tempo);
}
function fade_in_app(where) {
	document.getElementById(where).style.opacity = i / 10;
	i++;
	if (i==10) {
		clearInterval(fade_in_var); 
		document.getElementById(where).style.opacity = 1;
	}
}

// -----

function fade_out(where) {
	i = 10;
	document.getElementById(where).style.opacity = 1;
	fade_out_var = window.setInterval("fade_out_app('"+where+"')", tempo);
}
function fade_out_app(where) {
	document.getElementById(where).style.opacity = i / 10;
	i--;
	if (i<=0) {
		clearInterval(fade_out_var);
		document.getElementById(where).style.display = "none";
		document.getElementById(where).style.opacity = 0;
	}
}

// -----
