if((navigator.userAgent.match(/IPhone/i))||(navigator.userAgent.
	match(/iPod/i))){
		document.location.href="index.php/home.iphone.html";
}

var color_theo;
var container;
function background_color(visite){
	if( visite == 1 ){
		color_theo = "#136d8c";
		container = "container_two";
		document.getElementsByTagName("body").item(0).id = "body_two";
	}
	else{
		color_theo = "#F20775";
		container = "container_one";
		document.getElementsByTagName("body").item(0).id = "body_one";
	}
	fond(visite);
}

function test_fin(){
	document.getElementById('flash').style.display = 'none';
	document.getElementById('flash_theo').style.display = 'block';
	document.getElementById('pixel').style.display = 'none';
}

function appelTheo(evt){
	var touche = evt.keyCode ? evt.keyCode : evt.which;
	if ( touche == "13" || document.frm.bool.value==1){
		document.frm.question.blur();
		//enregistrement de la question en base
    var httpRequest;

    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) {
            httpRequest.overrideMimeType('text/xml');
            // See note below about this line
        }
    }
    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;
    }
    lbl = document.frm.question.value;
    httpRequest.onreadystatechange = function() { afficheReponse(httpRequest); };
    wurl = 'ajax/ajax_saveQuestionTheo.php?qst='+lbl;
    httpRequest.open('GET', wurl, true);
    httpRequest.send('');

	if (navigator.appName=="Microsoft Internet Explorer"){
		document.getElementById('tr_qst').style.display='block';
	}
	else{
		document.getElementById('tr_qst').style.display='table-row';
	}
   	document.getElementById('boxQuestion').innerHTML = document.frm.question.value;
		document.frm.question.value='';
		document.frm.question.focus();
		document.frm.bool.value = 0;
	}

}

function afficheReponse(httpRequest) {
    if (httpRequest.readyState == 4) {
        if (httpRequest.status == 200) {
            chaine = httpRequest.responseText;
            var tab = chaine.split("|");
           	document.getElementById('boxReponse').innerHTML = tab[1];
            changeTheo(tab[0]);
            setTimeout('changeTheo(4)',2500);
        } else {
            alert('There was a problem with the request.');
        }
    }
   else{
    	document.getElementById('boxReponse').innerHTML = '<img src="system/modules/theo/img/theo_thinking.gif" border="0">';
    }
}

function appelTheoButton(evt){
	document.frm.bool.value=1;
	appelTheo(evt);
}

function dezoom(){
	document.getElementById("reponse").style.display='block';
	document.getElementById("reponse_all").style.display='none';
	document.getElementById("guide-help-bulle").style.display='block';
}

function changeTheo(i){
	if ( navigator.userAgent.indexOf("MSIE") != -1 )
		document.getElementById("fls").movie = 'flash/anim'+i+'.swf';
	else
		document.getElementById("fire").src = 'flash/anim'+i+'.swf';
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function loadTheo(position){
	html = '<table cellspacing="0" cellpadding="0" border="0"><tr><td width="120" valign="bottom"><object id="fls" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="150" height="160"><param name="movie" value="flash/anim4.swf"><param name="wmode" value="transparent"><param name="quality" value="high"><embed src="flash/anim4.swf" quality="high" id="fire" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="150" height="160" wmode="transparent"></embed></object>';
	html += '</td><td valign="top"><table cellspacing="0" cellpadding="0" border="0"><tr><td colspan="3"><img src="img/Bulle_theo_03.png" border="0"></td><td rowspan="3" width="50" valign="top" align="right" style="padding-left:15px;"><a href="javascript:hideTheo('+position+')"><img src="img/button_close.png" border="0" align="right"></a></td></tr><tr height="100"><td width="50" background="img/new_buble_01.gif"></td><td width="339" bgcolor="#ffffff"><div id="boxReponse" style="margin-left: 5px;width:330px;height:160px;overflow-y:auto;font-size:10px;">Vous pouvez taper votre question dans la bulle ci-dessous.</div></td><td width="1" background="img/pixel.gif"></td></tr>';
	html += '<tr><td colspan="3"><img src="img/Bulle_theo_01.png" border="0"></td></tr></table><br><br><table cellspacing="0" cellpadding="0" border="0"><tr><td colspan="4" style="border:0px solid #ffff00;"><img src="img/Bulle_theo_03.png" border="0" onclick="activeQuestion()"></td></tr><tr height="40" id="tr_qst" style="display:none;"><td width="50" background="img/new_buble_01.gif"></td><td width="299" bgcolor="#ffffff" valign="top"><div id="boxQuestion" style="margin-left: 5px;width:280px;height:35px;overflow-y:auto;font-size:10px;"></div></td><td width="40" bgcolor="#ffffff"></td><td width="1" background="img/pixel.gif"></td></tr><tr height="30"><td width="50" background="img/new_buble_01.gif"></td><td width="299" bgcolor="#ffffff" valign="top"><form name="frm"><input type="hidden" name="bool" value="0"><textarea rows="2" cols="38" onkeydown="appelTheo(event)" style="margin-left: 5px;border:0px;background-color:#e8e8e8;border-top:1px solid #a8a8a8;border-left:1px solid #a8a8a8;" name="question" id="question"></textarea></form></td><td width="40" bgcolor="#ffffff"><a href="javascript:void(null)" onclick="appelTheoButton(event)"><img src="img/button_ok.png" border="0" align="bottom"></a></td><td width="1" background="img/pixel.gif"></td></tr><tr><td colspan="4"><img src="img/Bulle_theo_04.png" border="0" onclick="activeQuestion()"></td></tr></table></td></tr></table>';
	if( position == 1 ){
		var theo  = new Element('div', {id: 'theo-bg'});
		$(container).adopt(theo);
		var bulle_theo = new Element('div', {'id' : 'boxQR','styles':{ 'opacity':'1','position':'absolute', 'display':'block','left':'0px','top':'208px','margin-left':'13px','height':'370px','width':'560px','border':'0px solid #000000','z-index':'12'}});
		$(container).adopt(bulle_theo);
		bulle_theo.set('html', html);

	}
	else{
		$("#container").append("<div id=\"theo-bg\"></div>");
		$("#container").append('<div id="boxQR" style="opacity:1;position:absolute;display:block;left:0px;top:208px;margin-left:13px;height:370px;width:560px;border:0px solid #000000;z-index:12;">	</div>');

		$("#boxQR").append(html);
		$("#left").append("<img id='pixel' src='img/pixel_bis.gif' width='210px'/>");
	}
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])

	if ((version >= 5.5 && version <= 6) && (document.body.filters))
	{

	   for(var i=0; i<document.images.length; i++)
	   {
		  var img = document.images[i]
		  var imgName = img.src.toUpperCase()
		  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
		  {
			 var imgID = (img.id) ? "id='" + img.id + "' " : ""
			 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			 var imgStyle = "display:inline-block;" + img.style.cssText
			 if (img.align == "left") imgStyle = "float:left;" + imgStyle
			 if (img.align == "right") imgStyle = "float:right;" + imgStyle
			 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			 var strNewHTML = "<span " + imgID + imgClass + imgTitle
			 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			 + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"

			 img.outerHTML = strNewHTML
			 i = i-1
		  }
	   }
	}
	document.getElementsByTagName("body").item(0).style.backgroundColor = "#051B23";
	if(document.getElementById('zoom-container')){
		document.getElementById('zoom-container').style.display = 'none';
	}
	document.getElementById('guide').style.display='none';
}

function hideTheo(position){
	if( position == 1 ){
		$('boxQR').dispose();
		$('theo-bg').dispose();
	}
	else{
		$("#boxQR").remove();
		$("#theo-bg").remove();
		$("#pixel").remove();
	}
	document.getElementsByTagName("body").item(0).style.backgroundColor = color_theo;
	document.getElementById('guide').style.display='block';
}

function activeQuestion(){
	document.getElementById('question').focus();
}


