var http = false;
var iEncour=false;

function popup(theURL,winName,features) { window.open(theURL,winName,features);}


function get_dom_object(object)
{
        if (document.getElementById) {
                return document.getElementById(object);
        } else if(document.all) {
                return document.all[object];
        }
}

function createRequestObject(){
        var request_o;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer"){
                request_o = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
                request_o = new XMLHttpRequest();
        }
        return request_o;
}

function voire_image(inc)
{
	if(inc) {
		$("#img_lien_1").css('display','none');
		$("#img_lien_2").css('display','none');
		$("#img_lien_3").css('display','none');
		$("#img_lien_4").css('display','none');
		$("#img_lien_"+inc).css('display','block');
		$(document).ready(function(){ $(".jqzoom_"+inc).jqzoom(); });
	}
}

function css_browser_selector() {
		ua=navigator.userAgent.toLowerCase();
		is=function(t){ return ua.indexOf(t) != -1; };
		h=document.getElementsByTagName('html')[0];
		b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('gecko/')? 'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'';
		os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';
	var c=b+os+' js';
	return c;
//	h.className += h.className?' '+c:c;
}	
var moteur=css_browser_selector();


/*

var linkClicked;
var toucheOld;
window.onbeforeunload = function(e) {
//	window.console.log('referer: '+getDomain(document.referrer));
//	window.console.log('    ref: '+getDomain(location.href));
//	window.console.log('linkClicked: '+linkClicked);
//	if(!linkClicked && (getDomain(document.referrer)!=getDomain(location.href))) {
	if(!linkClicked ) {
		var windowQuit=window.open('http://'+getDomain(location.href)+'/enquete.html',windowQuit, 'width=700,height=340,left=50,top=50,resizable=true,resizable=1').blur();
		self.focus();
	}
}

document.onkeydown = function(e) {
	var touche = window.event ? window.event.keyCode : e.which;
//	window.console.log('window.onkeydown: '+touche);
//	alert(touche);
	if(touche==116 || (toucheOld==18 && (touche==37 ||touche==39) )) {
//		window.console.log('window.onkeydown: linkClicked');
		linkClicked=1;
		toucheOld='';
	} else {
		toucheOld=touche;
	}
}
*/

function getDomain(url){
    myregexp = /(http|https|file|ftp):\/\/([^\/]*)\/.*/i;
    var m = myregexp.exec(url);
    if (m == null)
        return '';
    else
        return m[2];
}


/****************
*****************/
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
window.onload = function(e) {
  //var cookie = readCookie("first_go");
  createCookie("first_go", 1, 10000);
}
window.onunload = function(e) {
  //createCookie("first_go", 1, 0);
}

function valid_identifiant_oublie()
{
	document.body.style.cursor="wait";
	document.forms[1].em.disabled=true;
	if(document.forms[1].em.value.length==0) {
		alert('Email : Vide');
		document.forms[1].em.focus();
		document.body.style.cursor="auto";
		document.forms[1].em.disabled=false;
		return false;
	} else {
		date=new Date();
		url="/identifiant_oublie.html?ajax=1&em="+document.forms[1].em.value+"&d="+date.getTime();
		http = createRequestObject();
		iEncour=false;
		if(!iEncour) {
			iEncour=true;
			http.open("GET", url ,true);
			http.onreadystatechange = function parse_test() {
				if (http.readyState == 4) {
					if (http.status == 200) {
						if(http.responseText=='1') {
							alert("Votre demande a été prise en compte");
							document.body.style.cursor="auto";
							document.forms[1].em.disabled=false;
							iEncour=false;
							window.history.back();
						} else if(http.responseText=='0') {
							alert('Email : inconnu');
							document.forms[1].em.focus();
						}
						document.body.style.cursor="auto";
						document.forms[1].em.disabled=false;
						iEncour=false;
					} else {
						document.body.style.cursor="auto";
						document.forms[1].em.disabled=false;
						alert("There was a problem with the request.");
						iEncour=false;
					}
				}
			} ;
			http.send(null);
		}
	}
}

function valid_inscription_newsletter()
{
	document.body.style.cursor="wait";
	document.forms[1].email.disabled=true;
	if(document.forms[1].email.value.length==0) {
		alert('Email : Vide');
		document.forms[1].email.focus();
		document.body.style.cursor="auto";
		document.forms[1].email.disabled=false;
		return false;
	}
	document.body.style.cursor="auto";
	document.forms[1].email.disabled=false;
	return true;
}

function valid_change_page(f,max,byselect)
{
	var re_int=/^[0-9]+$/;
        if(byselect) {
                numero_page=f.options[f.selectedIndex].value;
        } else {
                numero_page=f.num_page.value;
        }

        if(!re_int.test(numero_page)) {
                alert('Page Invalide');
                return false;
        }
        if(numero_page<0 || numero_page>max) {
                alert('Page Invalide (hors limite)');
                return false;
        }

        str=location.href;
        re=/_page\-[0-9]+\./;
        if(re.test(str)) {
                str=str.replace(re,'_page-'+numero_page+'.');
        } else {
                re=/\.html/g;
                //alert(re);
                str=str.replace(re,'_page-'+numero_page+'.html');

        }
        location.href=str;
        return false;
}

function valid_change_nb_element_page(f)
{
        nb_element_page_val=f.options[f.selectedIndex].value;
	//alert(nb_element_page_val);
        //alert('p.php?action=_change_nb_element_page&nb_element_page='+nb_element_page_val+'&url='+encodeURIComponent(location.href));
        location.href='/p.php?action=_change_nb_element_page&nb_element_page='+nb_element_page_val+'&url='+encodeURIComponent(location.href);
        return false;
}

function blinkIt() {
return false;
/*
 if (!document.all) return;
 else {
   for(i=0;i<document.all.tags('blink').length;i++){
      s=document.all.tags('blink')[i];
      s.style.visibility=(s.style.visibility=='visible')  ?'hidden':'visible';
   }
 }
*/
}

jQuery.noConflict();
jQuery(document).ready(function($){
	$('.blink').each(function() {
		var pos = 1;
		var toggle1;
		var toggle2;
		if($(this).find('*').css('color') && $(this).find('*').css('background-color')) {
			var $elmt=$(this).find('*');
		} else {
			var $elmt=$(this);
		}

		if($(this).attr('rel')) {
			tab=$(this).attr('rel').split(';');
			toggle1=tab[0];
			toggle2=tab[1];
		} else {
			if($(this).find('*').css('color') && $(this).find('*').css('background-color')) {
				toggle1=$(this).find('*').css('background-color');
				toggle2=$(this).find('*').css('color');
			} else {
				toggle1=$(this).css('background-color');
				toggle2=$(this).css('color');
			}
		}
		setInterval(function() {
			if(pos==1) {
				$elmt.css({'color':toggle2});   
				pos=2;
			} else {
				$elmt.css({'color':toggle1});   
				pos=1;
			}
		},750);
	});
	/*
	$("#cgv_open_link").click(function() { 
		$("#cgv_open").val("1");
		var newwindow=window.open('cgv_popup.html','','"menubar=no, status=yes, scrollbars=yes, menubar=no, height=400,width=600');
		return false;
	});
	*/
});


function maison(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" /> \n');
	document.write('<param name="movie" value="/images/flash/maison.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> \n');
	document.write('<embed src="/images/flash/maison.swf" quality="high" bgcolor="#ffffff" width="550" height="400" name="cercle" align="middle" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <\/embed /> \n');
	document.write('<\/object /> \n');
}

function texte_def(){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="700" height="25" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" /> \n');
	document.write('<param name="movie" value="/images/flash/texte_def.swf" /><param name="wmode" value="transparent"><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /> \n');
	document.write('<embed src="/images/flash/texte_def.swf" quality="high" bgcolor="#ffffff" width="700" height="25" name="cercle" align="middle" play="true" loop="false" wmode="transparent"  quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <\/embed /> \n');
	document.write('<\/object /> \n');
}

