// JavaScript Document
// Tableau gérant les traductions utilisées dans le code javascript

var langSwitch = new Object();

// Langue EN
langSwitch.en = new Array();
langSwitch.en[0] = "Please enter your company";
langSwitch.en[1] = "Please enter your address";
langSwitch.en[2] = "Please enter your city";
langSwitch.en[3] = "Please enter your zip code";
langSwitch.en[4] = "Please enter your continent";
langSwitch.en[5] = "Please enter your country";
langSwitch.en[6] = "Please enter your firstname";
langSwitch.en[7] = "Please enter your phone number";
langSwitch.en[8] = "Wrong mail adress";
langSwitch.en[9] = "Mail adresses doesn't match";

// Langue ZH
langSwitch.zh = new Array();
langSwitch.zh[0] = "Please enter your company";
langSwitch.zh[1] = "Please enter your address";
langSwitch.zh[2] = "Please enter your city";
langSwitch.zh[3] = "Please enter your zip code";
langSwitch.zh[4] = "Please enter your continent";
langSwitch.zh[5] = "Please enter your country";
langSwitch.zh[6] = "Please enter your firstname";
langSwitch.zh[7] = "Please enter your phone number";
langSwitch.zh[8] = "Wrong mail adress";
langSwitch.zh[9] = "Mail adresses doesn't match";

// Langue JA
langSwitch.ja = new Array();
langSwitch.ja[0] = "あなたの勤務先を入力してください";
langSwitch.ja[1] = "あなたの住所を入力してください";
langSwitch.ja[2] = "あなたのお住まいの市名を入力してください";
langSwitch.ja[3] = "あなたの郵便番号を入力してください";
langSwitch.ja[4] = "あなたのお住まいの大陸を選択してください";
langSwitch.ja[5] = "あなたのお住まいの国を選択してください";
langSwitch.ja[6] = "あなたの下の名前を入力してください";
langSwitch.ja[7] = "あなたの電話番号を入力してください";
langSwitch.ja[8] = "メールアドレスが間違っています";
langSwitch.ja[9] = "メールアドレスが一致しません";


function makeRequest(url,IDBalise)
{
	/*
	Note : if you are sending a request to a piece of code that will return XML, rather than to a static XML file, you must set some response 
	headers if your page is to work in Internet Explorer in addition to Mozilla. If you do not set header Content-Type: application/xml, IE 
	will throw a JavaScript error, 'Object Expected', after the line where you try to access an XML element. If you do not set header 
	Cache-Control: no-cache the browser will cache the response and never re-submit the request, making debugging "challenging."
	*/
	/*
	Response.ContentType = "application/xml"
	Response.CacheControl = "no-cache"
	*/

	var httpRequest ;

	
	if (window.XMLHttpRequest) // Mozilla, Safari, ...
	{
		httpRequest = new XMLHttpRequest() ;
		if (httpRequest.overrideMimeType)
		{
			//alert(httpRequest.overrideMimeType('text/xml'));
			httpRequest.overrideMimeType('text/xml') ;
			// Note: The line httpRequest.overrideMimeType('text/xml'); above will cause JavaScript Console errors in Firefox 1.5 or later, as documented in bug 311724 (https://bugzilla.mozilla.org/show_bug.cgi?id=311724) if the page retrieve by XMLHttpRequest is not valid XML (e.g., if it is plain text). This is actually correct behavior; this article will be revised soon to address this change.

		}
	} 
	else if (window.ActiveXObject) // IE
	{
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP") ;
		} 
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP") ;
			} 
			catch (e) {}
		}
	}

	if (!httpRequest)
	{
		alert('Giving up :( Cannot create an XMLHTTP instance') ;
		return false ;
	}
	httpRequest.onreadystatechange = function()
		{
			httpRequest_callback(httpRequest) ;
			DivID = GetVariablesURL(url,IDBalise);
		} ;
	httpRequest.open('GET', url, true) ;
	httpRequest.send('') ;
}

function httpRequest_callback(httpRequest)
{
        try
	{
		if (httpRequest.readyState == 4)
		{
			if (httpRequest.status == 200)
			{

				var el4 = document.getElementById(DivID);//alert(DivID);
				el4.innerHTML = httpRequest.responseText;
			
			
			}
			else
			{
				//alert('There was a problem with the request.\nhttpRequest.status: ' + httpRequest.status) ;
			}
		}
        }
        catch( e )
	{
		//alert('Caught Exception: ' + e.description) ;
        }
}

function GetVariablesURL(URL,NameVar)
{
var Req = "";
var nTemp = "";
//alert(location.search.substring(1,location.search.length));
if(URL == "")
{
Req = location.search.substring(1,location.search.length);	//suppression du ? en début de chaine
}
else
{
Req = URL.split("?");
//alert(Req[1]);
Req = Req[1];
//alert(Req[1]);
//Req = URL[1].substring(1,URL.length);	//suppression du ? en début de chaine
}

Req = Req.split("&"); //transformation en tableau

	for (var i=0;i<Req.length;i++)
	{
		if (Req[i].substring(0,Req[i].indexOf("=")) == NameVar)
		{
		nTemp = Req[i].substring(Req[i].indexOf("=")+1,Req[i].length);
		}
	}

//alert(nTemp);

	while (true)
	{
		var i = nTemp.indexOf('+');
		if (i < 0) break;
		nTemp = nTemp.substring(0,i) + '%20' + nTemp.substring(i + 1, nTemp.length);
	}

return (nTemp);
}
/*
function SetCheckBox(IdCheckBox)
{
	for(i=0;i<box_ids.length;i+=2) //on va de 2 en 2 car il ya les id de contenus aussi
	{	
		alert(IdCheckBox+box_ids[i]);
		formAdd.elements[IdCheckBox+box_ids[i]].checked = 'true';
	}
}
*/

function afficher_menu(menu, idarticle)
{
	document.getElementById(menu).className = menu+'_on';
	
	switch(menu)
	{
		case 'rouge' :
			document.getElementById('orange').className = 'orange_off';
			document.getElementById('bleu').className 	= 'bleu_off';
			document.getElementById('vert').className 	= 'vert_off';
			break;
		case 'orange' :
			document.getElementById('rouge').className 	= 'rouge_off';
			document.getElementById('bleu').className 	= 'bleu_off';
			document.getElementById('vert').className 	= 'vert_off';
			break;
		
		case 'bleu' :
			document.getElementById('rouge').className 	= 'rouge_off';
			document.getElementById('orange').className = 'orange_off';
			document.getElementById('vert').className 	= 'vert_off';
			break;
		
		case 'vert' :
			document.getElementById('rouge').className 	= 'rouge_off';
			document.getElementById('bleu').className 	= 'bleu_off';
			document.getElementById('orange').className	= 'orange_off';
			break;
		
		default :
			document.getElementById('rouge').className	= 'rouge_on';
			document.getElementById('orange').className = 'orange_off';
			document.getElementById('bleu').className 	= 'bleu_off';
			document.getElementById('vert').className 	= 'vert_off';
			break;
	}
	makeRequest('?page=contenu_article_home&DivID=texte_article_home&id_article='+idarticle+'&couleur='+menu,'DivID');
	makeRequest('?page=contenu_visuel_home&DivID=visuel_article_home&id_article='+idarticle,'DivID');
}
function SetCookie (name, value)
{
	//nouvel objet date
	var aujourdhui = new Date() ;
	//nouvel objet date
	var expdate = new Date() ;
	//plus an an à partir d'aujourdh'ui le cookie ne s'efface jamais
	expdate.setTime( aujourdhui.getTime() + ( 365*24*60*60*1000 ) )
	//creation du cookie
	document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() ;
	return true;
}

function getCookieVal(offset)
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1) endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr)); 
}

function LireCookie(nom)
{
	var arg=nom+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen)
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
	}
	return false; 
}

function affichePopup()
{
	if(LireCookie("popuphome") == false)
	{
		document.getElementById("popuphome").style.display = "block";
		SetCookie("popuphome", "1");
	}
}

function check_mail(mail){

    var re    = new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$", "gi");

    if(!re.test(mail)){
	   return false;
	}else{
	   return true;
	}

}

function validForm( lang ){
	var company		= document.getElementById('name').value;
	var address		= document.getElementById('address').value;
	var city		= document.getElementById('city').value;
	var zip			= document.getElementById('zip').value;
	var continent	= document.getElementById('continent').value;
	var country		= document.getElementById('country').value;
	var firstname	= document.getElementById('firstname').value;
	var lastname	= document.getElementById('lastname').value;
	var phone		= document.getElementById('phone').value;
	var mail		= document.getElementById('mail').value;
	var mail2		= document.getElementById('mail2').value;
	
	var ls;
	if( lang == "en" ) ls = langSwitch.en;
	if( lang == "zh" ) ls = langSwitch.zh;
	if( lang == "ja" ) ls = langSwitch.ja;
	
	if(company == ""){
		alert(ls[0]);
		return false;
	}

	if(address == ""){
		alert(ls[1]);
		return false;
	}

	if(city == ""){
		alert(ls[2]);
		return false;
	}	
	
	if(zip == ""){
		alert(ls[3]);
		return false;
	}	
	
	if(continent == ""){
		alert(ls[4]);
		return false;
	}
	
	if(country == ""){
		alert(ls[5]);
		return false;
	}
	
	if(firstname == ""){
		alert(ls[6]);
		return false;
	}
	
	if(lastname == ""){
		alert(ls[6]);
		return false;
	}

	if(phone == ""){
		alert(ls[7]);
		return false;
	}
	
	if(!check_mail(mail)){
		alert(ls[8]);
		return false;
	}
	
	if(!check_mail(mail2)){
		alert(ls[8]);
		return false;
	}
	
	if(mail != mail2){
		alert(ls[9]);
		return false;
	}
	
	return true;	
}

function select_continent(select, lang){
	
	// initialisation des variables
	var continent	= select.options[select.selectedIndex].value;
	var country		= document.getElementById('country');
	var i 			= 0;
	var taille_select = country.options.length;
	
	// je reduis la taille de 1 pour être conforme à la position des options
	taille_select--;
	
	// je vide la liste des pays (a vider à l'envers sinon les indexs des options changent) 
	for(i=taille_select; i > 0; i--){
		country.options[i] = null;
	}	
	
	switch(lang){
	
	case "en" :
		// je rempli en fonction du continent choisi
		switch(select.value){
			case "North America" :
			country.options[1] = new Option("Canada","Canada");	
			country.options[2] = new Option("Mexico","Mexico");	
			country.options[3] = new Option("USA","USA");
			country.options[0].selected = true;
			break;
			
			case "Central, South America" :
			country.options[1] = new Option("Argentina","Argentina");	
			country.options[2] = new Option("Bolivia","Bolivia");	
			country.options[3] = new Option("Brazil","Brazil");
			country.options[4] = new Option("Chile","Chile");
			country.options[5] = new Option("Ecuador","Ecuador");
			country.options[6] = new Option("Paraguay","Paraguay");
			country.options[7] = new Option("Peru","Peru");
			country.options[8] = new Option("Uruguay","Uruguay");
			country.options[9] = new Option("other countries","other countries");
			country.options[0].selected = true;
			break;
			
			case "Europe, Middle East, Africa" :
			country.options[1] = new Option("Austria","Austria");	
			country.options[2] = new Option("Belgium","Belgium");	
			country.options[3] = new Option("Bulgaria","Bulgaria");
			country.options[4] = new Option("Croatia","Croatia");
			country.options[5] = new Option("Czech Republic","Czech Republic");
			country.options[6] = new Option("Denmark","Denmark");
			country.options[7] = new Option("Estonia","Estonia");
			country.options[8] = new Option("Finland","Finland");
			country.options[9] = new Option("France","France");
			country.options[10] = new Option("Germany","Germany");
			country.options[11] = new Option("Greece","Greece");
			country.options[12] = new Option("Hungary","Hungary");
			country.options[13] = new Option("Ireland","Ireland");
			country.options[14] = new Option("Israel","Israel");
			country.options[15] = new Option("Italy","Italy");
			country.options[16] = new Option("Latvia","Latvia");
			country.options[17] = new Option("Lithuania","Lithuania");
			country.options[18] = new Option("Middle East","Middle East");
			country.options[19] = new Option("Netherlands","Netherlands");
			country.options[20] = new Option("Norway","Norway");
			country.options[21] = new Option("Other countries","Other countries");
			country.options[22] = new Option("Poland","Poland");
			country.options[23] = new Option("Portugal","Portugal");
			country.options[24] = new Option("Romania","Romania");
			country.options[25] = new Option("Russia","Russia");
			country.options[26] = new Option("Serbia and Montenegro","Serbia and Montenegro");
			country.options[27] = new Option("Slovakia","Slovakia");
			country.options[28] = new Option("Slovenia","Slovenia");
			country.options[29] = new Option("South Africa","South Africa");
			country.options[30] = new Option("Spain","Spain");
			country.options[31] = new Option("Sweden","Sweden");
			country.options[32] = new Option("Switzerland","Switzerland");
			country.options[33] = new Option("Turkey","Turkey");
			country.options[34] = new Option("Ukraine","Ukraine");
			country.options[35] = new Option("United Kingdom","United Kingdom");
			country.options[0].selected = true;
			break;
			
			case "Asia Pacific" :
			country.options[1] = new Option("Australia","Australia");	
			country.options[2] = new Option("India","India");	
			country.options[3] = new Option("Indonesia","Indonesia");	
			country.options[4] = new Option("Japan","Japan");	
			country.options[5] = new Option("Korea","Korea");	
			country.options[6] = new Option("Malaysia","Malaysia");	
			country.options[7] = new Option("New Zealand","New Zealand");	
			country.options[8] = new Option("Other countries","Other countries - Asia Pacific");	
			country.options[9] = new Option("Singapore","Singapore");	
			country.options[10] = new Option("Taiwan","Taiwan");	
			country.options[11] = new Option("Thailand","Thailand");	
			country.options[12] = new Option("Vietnam","Vietnam");
			country.options[0].selected = true;		
			break;
			
			default :
			country.options[0].selected = true;
			break;
			
		}
	
	case "zh" :
		// je rempli en fonction du continent choisi
		switch(select.value){
			case "北美" :
			country.options[1] = new Option("Canada","Canada");	
			country.options[2] = new Option("Mexico","Mexico");	
			country.options[3] = new Option("USA","USA");
			country.options[0].selected = true;
			break;
			
			case "中美洲、南美洲" :
			country.options[1] = new Option("Argentina","Argentina");	
			country.options[2] = new Option("Bolivia","Bolivia");	
			country.options[3] = new Option("Brazil","Brazil");
			country.options[4] = new Option("Chile","Chile");
			country.options[5] = new Option("Ecuador","Ecuador");
			country.options[6] = new Option("Paraguay","Paraguay");
			country.options[7] = new Option("Peru","Peru");
			country.options[8] = new Option("Uruguay","Uruguay");
			country.options[9] = new Option("其他国家","其他国家");
			country.options[0].selected = true;
			break;
			
			case "欧洲、中东、非洲" :
			country.options[1] = new Option("Austria","Austria");	
			country.options[2] = new Option("Belgium","Belgium");	
			country.options[3] = new Option("Bulgaria","Bulgaria");
			country.options[4] = new Option("Croatia","Croatia");
			country.options[5] = new Option("Czech Republic","Czech Republic");
			country.options[6] = new Option("Denmark","Denmark");
			country.options[7] = new Option("Estonia","Estonia");
			country.options[8] = new Option("Finland","Finland");
			country.options[9] = new Option("France","France");
			country.options[10] = new Option("Germany","Germany");
			country.options[11] = new Option("Greece","Greece");
			country.options[12] = new Option("Hungary","Hungary");
			country.options[13] = new Option("Ireland","Ireland");
			country.options[14] = new Option("Israel","Israel");
			country.options[15] = new Option("Italy","Italy");
			country.options[16] = new Option("Latvia","Latvia");
			country.options[17] = new Option("Lithuania","Lithuania");
			country.options[18] = new Option("Middle East","Middle East");
			country.options[19] = new Option("Netherlands","Netherlands");
			country.options[20] = new Option("Norway","Norway");
			country.options[21] = new Option("Other countries","Other countries");
			country.options[22] = new Option("Poland","Poland");
			country.options[23] = new Option("Portugal","Portugal");
			country.options[24] = new Option("Romania","Romania");
			country.options[25] = new Option("Russia","Russia");
			country.options[26] = new Option("Serbia and Montenegro","Serbia and Montenegro");
			country.options[27] = new Option("Slovakia","Slovakia");
			country.options[28] = new Option("Slovenia","Slovenia");
			country.options[29] = new Option("South Africa","South Africa");
			country.options[30] = new Option("Spain","Spain");
			country.options[31] = new Option("Sweden","Sweden");
			country.options[32] = new Option("Switzerland","Switzerland");
			country.options[33] = new Option("Turkey","Turkey");
			country.options[34] = new Option("Ukraine","Ukraine");
			country.options[35] = new Option("United Kingdom","United Kingdom");
			country.options[0].selected = true;
			break;
			
			case "亚太地区" :
			country.options[1] = new Option("澳大利亚","澳大利亚");	
			country.options[2] = new Option("印度","印度");	
			country.options[3] = new Option("印度尼西亚","印度尼西亚");	
			country.options[4] = new Option("日本","日本");	
			country.options[5] = new Option("韩国","韩国");	
			country.options[6] = new Option("马来西亚","马来西亚");	
			country.options[7] = new Option("新西兰","新西兰");	
			country.options[8] = new Option("其他国家","其他国家 - 亚太地区");	
			country.options[9] = new Option("新加坡","新加坡");	
			country.options[10] = new Option("台湾","台湾");	
			country.options[11] = new Option("泰国","泰国");	
			country.options[12] = new Option("越南","越南");
			country.options[0].selected = true;		
			break;
			
			default :
			country.options[0].selected = true;
			break;
			
		}
	
	case "ja" :
		// je rempli en fonction du continent choisi
		switch(select.value){
			case "北米" :
			country.options[1] = new Option("カナダ","カナダ");	
			country.options[2] = new Option("メキシコ","メキシコ");	
			country.options[3] = new Option("米国","米国");
			country.options[0].selected = true;
			break;
			
			case "中部、南米" :
			country.options[1] = new Option("アルゼンチン","アルゼンチン");	
			country.options[2] = new Option("ボリビア","ボリビア");	
			country.options[3] = new Option("ブラジル","ブラジル");
			country.options[4] = new Option("チリ","チリ");
			country.options[5] = new Option("エクアドル","エクアドル");
			country.options[6] = new Option("パラグアイ","パラグアイ");
			country.options[7] = new Option("ペルー","ペルー");
			country.options[8] = new Option("ウルグアイ","ウルグアイ");
			country.options[9] = new Option("その他の国","その他の国");
			country.options[0].selected = true;
			break;
			
			case "ヨーロッパ、中東、アフリカ" :
			country.options[1] = new Option("オーストリア","オーストリア");	
			country.options[2] = new Option("ベルギー","ベルギー");	
			country.options[3] = new Option("ブルガリア","ブルガリア");
			country.options[4] = new Option("クロアチア","クロアチア");
			country.options[5] = new Option("チェコ共和国","チェコ共和国");
			country.options[6] = new Option("デンマーク","デンマーク");
			country.options[7] = new Option("エストニア","エストニア");
			country.options[8] = new Option("フィンランド","フィンランド");
			country.options[9] = new Option("フランス","フランス");
			country.options[10] = new Option("ドイツ","ドイツ");
			country.options[11] = new Option("ギリシア","ギリシア");
			country.options[12] = new Option("ハンガリー","ハンガリー");
			country.options[13] = new Option("アイルランド","アイルランド");
			country.options[14] = new Option("イスラエル","イスラエル");
			country.options[15] = new Option("イタリア","イタリア");
			country.options[16] = new Option("ラトビア","ラトビア");
			country.options[17] = new Option("リトアニア","リトアニア");
			country.options[18] = new Option("中東","中東");
			country.options[19] = new Option("オランダ","オランダ");
			country.options[20] = new Option("ノルウェー","ノルウェー");
			country.options[21] = new Option("その他の国","その他の国");
			country.options[22] = new Option("ポーランド","ポーランド");
			country.options[23] = new Option("ポルトガル","ポルトガル");
			country.options[24] = new Option("ルーマニア","ルーマニア");
			country.options[25] = new Option("ロシア","ロシア");
			country.options[26] = new Option("セルビア・モンテネグロ","セルビア・モンテネグロ");
			country.options[27] = new Option("スロバキア","スロバキア");
			country.options[28] = new Option("スロヴェニア","スロヴェニア");
			country.options[29] = new Option("南アフリカ","南アフリカ");
			country.options[30] = new Option("スペイン","スペイン");
			country.options[31] = new Option("スウェーデン","スウェーデン");
			country.options[32] = new Option("スイス","スイス");
			country.options[33] = new Option("トルコ","トルコ");
			country.options[34] = new Option("ウクライナ","ウクライナ");
			country.options[35] = new Option("イギリス","イギリス");
			country.options[0].selected = true;
			break;
			
			case "アジア・アフリカ" :
			country.options[1] = new Option("オーストラリア","オーストラリア");	
			country.options[2] = new Option("インド","インド");	
			country.options[3] = new Option("インドネシア","インドネシア");	
			country.options[4] = new Option("日本","日本");	
			country.options[5] = new Option("韓国","韓国");	
			country.options[6] = new Option("マレーシア","マレーシア");	
			country.options[7] = new Option("ニュージーランド","ニュージーランド");	
			country.options[8] = new Option("その他の国","その他の国 - アジア・アフリカ");	
			country.options[9] = new Option("シンガポール","シンガポール");	
			country.options[10] = new Option("台湾","台湾");	
			country.options[11] = new Option("タイ","タイ");	
			country.options[12] = new Option("ベトナム","ベトナム");
			country.options[0].selected = true;		
			break;
			
			default :
			country.options[0].selected = true;
			break;
			
		}
	}
	return false;
}

