function CreateRequestObject() {
	var req = false;
  // branch for native XMLHttpRequest object
  if(window.XMLHttpRequest && !(window.ActiveXObject)) {
      try {
          req = new XMLHttpRequest();
      } catch(e) {
          req = false;
      }
  // branch for IE/Windows ActiveX version
  } else if(window.ActiveXObject) {
         try {
          req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
          try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e) {
                req = false;
          }
      }
  }
	return req;
}

function EcrireCookie(nom, valeur)
{
	var argv=EcrireCookie.arguments;
	var argc=EcrireCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : "/";
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=nom+"="+escape(valeur)+
	((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
	((path==null) ? "" : ("; path="+path))+
	((domain==null) ? "" : ("; domain="+domain))+
	((secure==true) ? "; secure" : "");
}

function CreateHostCookie() {
	var HttpCreateHostCookie = CreateRequestObject();
	HttpCreateHostCookie.open('get', '/'+site_sub_dir+'ajax/new_host.php');
	HttpCreateHostCookie.onreadystatechange = function () { 
		if(HttpCreateHostCookie.readyState == 4){
			var response = HttpCreateHostCookie.responseText;
			if (response != ""){
				date=new Date;
				date.setFullYear(date.getFullYear()+1);
				EcrireCookie("TlfHostId", response, date, "/");
			}
		}
	};
	HttpCreateHostCookie.send(null);
}

function LogTlfHostConnexion(host_id) {
	var HttpLogTlfHostConnexion = CreateRequestObject();
	HttpLogTlfHostConnexion.open('get', '/'+site_sub_dir+'ajax/log_host_connexion.php?host_id='+host_id);
	HttpLogTlfHostConnexion.send(null);
}

function LogHostFlmView(flm_id) {
	var HttpLogHostFlmView = CreateRequestObject();
	HttpLogHostFlmView.open('get', '/'+site_sub_dir+'ajax/log_host_flm_view.php?flm_id='+flm_id);
	HttpLogHostFlmView.send(null);
}

function LogHostBaView(flm_id) {
	var HttpLogHostBaView = CreateRequestObject();
	HttpLogHostBaView.open('get', '/'+site_sub_dir+'ajax/log_host_ba_view.php?flm_id='+flm_id);
	HttpLogHostBaView.send(null);
}

function LogSearch(q, flm_id) {
	var HttpLogSearch = CreateRequestObject();
	HttpLogSearch.open('get', '/'+site_sub_dir+'ajax/log_search.php?q='+q+'&flm_id='+flm_id);
	HttpLogSearch.send(null);
}

function LogClickUrl(flm_id, ste_id) {
	var HttpLogClickUrl = CreateRequestObject();
	HttpLogClickUrl.open('get', '/'+site_sub_dir+'ajax/click_url.php?flm_id='+flm_id+'&ste_id='+ste_id);
	HttpLogClickUrl.send(null);
}

function installSearchEngine() {
	date=new Date;
	date.setFullYear(date.getFullYear()+1);
	EcrireCookie('tlf_searchInstall','hide', date, "/");
	if (window.external && ("AddSearchProvider" in window.external)) {
	 // Firefox 2 and IE 7, OpenSearch
	 window.external.AddSearchProvider("http://www.trouvelefilm.com/opensearch.xml");
	}
	document.getElementById('search_pointer').className = "textoff";
}

function hideInstallSearchEngine() {
	date=new Date;
	date.setFullYear(date.getFullYear()+1);
	EcrireCookie('tlf_searchInstall','hide', date, "/");
	document.getElementById('search_pointer').className='textoff';
}

function urlencode(str) {
	str = escape(str);
	str = str.replace('+', '%2B');
	str = str.replace('%20', '+');
	str = str.replace('*', '%2A');
	str = str.replace('/', '%2F');
	str = str.replace('@', '%40');
	return str;
}

function urldecode(str) {
	str = str.replace('+', ' ');
	str = unescape(str);
	return str;
}