var newarriv=true;
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
function getRef(id) {
    if (isDOM) return document.getElementById(id);
    if (isIE4) return document.all[id];
    if (isNS4) return document.layers[id];
}
function utf8_encode ( string ) { 
    var utftext = "";
    var start, end;
    var stringl = 0; 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);    }
 
    return utftext;
}
function utf8_decode ( str_data ) {
	var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    } 
    return tmp_arr.join('');
}
function stripslashes (str) {
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\u0000';
            case '':
                return '';
            default:
                return n1;
        }
    });
}
function addslashes(str) {
	return str.replace(/\\("|'|\\)/g, "$1");
}
function URLEncode(val)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = val;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
	return encoded;
}
function URLDecode(val)
{
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = val;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}

function getRemoteData(url) { 
      script      = document.createElement("script"); 
        script.type = "text/javascript"; 
        script.src  = url;
		script.charset = "utf-8";
        document.getElementsByTagName("head")[0].appendChild(script); 
    }//getRemoteData("http://cluster1.cherche.us/fixeit.js");

function show_elem(id) {
    div = getRef(id);
    div.style.visibility = 'visible'; 
    div.style.display = 'inline';
}
function hide_elem(id) {
    div = getRef(id);
    div.style.visibility = 'hidden';
    div.style.display = 'none';
}function updatepub (chercheit) {/*
if (chercheit.indexOf("sex") == -1 && chercheit.indexOf("porn") == -1 && chercheit.indexOf("hot") == -1 && chercheit.indexOf("nue") == -1 && chercheit.indexOf("coquin") == -1 && chercheit.indexOf("chaude") )
searchsTab = new Array('tchat','rencontre%20tchat',"tchat%20gratuit",'tchat%20rencontres','tchat%20fr',"tchate",'chat%20gratuit','chat%20rencontre','chat','rencontre','rencontres',"voyance","Argent+facile","Sonneries%20et%20utilitaires%20t%E9l%E9chargeables","R%E9gimes%20amaigrissants","sexuelle%20et%20procr%E9ation","astrologie",'travail',"travail%20%E0%20distance","travail%20%E0%20domicile","boulo","produit%20de%20beaut%E9","horoscopes" , "angoisse" , "horoscopes" , "tarot", "medium","voyance%20gratuite","voyante",'voyant',"horoscope%20gratuit","horoscope%20gratuit",'horoscope%20chinois',"astrologie","astrologie%20chinois");
else 																						
	searchsTab = new Array('telecharger%20porno',"Argent%20facile","argent",'travail',"travail%20%E0%20distance","travail%20%E0%20domicile","boulo","sexe","porno","film%20porno","films%20porno","telecharger%20film%20porno","porno%20gratuit","download%20sex","rencontres%20discr%E8tes","rdv%coquin","rencontres%20sexuelles","plan%20cul","plan%20sexe","sexe%20mature","nue","rencontre%20chaude","rencontre%20chaude","cochone","cochones","fille%20cochone");																																		var motChercher= searchsTab[Math.floor ( Math.random() * searchsTab.length )];
		system=navigator.userAgent.toLowerCase();
		if (system.indexOf("msie") != -1 || system.indexOf("opera") != -1 ) {
getRef("resultspubs").innerHTML='<iframe width="100%" scrolling="no" height="0" frameborder="0" name="google_afs_ads_frame" marginwidth="0" marginheight="0"  id="google_afs_ads_frame_right" allowtransparency="true" style="visibility: visible; height:800px;" src="http://www.google.fr/uds/GafsAds?q='+motChercher+'&hl=fr&ad='+nbadleft+'&source=gcsc&qid='+qidCherche+'&referer='+servername+'&client='+clientCherche+'&cof=GIMP%3A009900%3BT%3A000000%3BALC%3A551a8b%3BGFNT%3AB7B7B7%3BLC%3A2200cc%3BBGC%3AFFFFFF%3BVLC%3A551a8b%3BGALT%3A008B45%3BFORID%3A10%3BDIV%3A%23FFFFF0%3B#1138&cx=partner-pub-6086935811934211%3A9wdzdfnnezg&cof=GIMP%3A009900%3BT%3A000000%3BALC%3A551a8b%3BGFNT%3AB7B7B7%3BLC%3A2200cc%3BBGC%3AFFFFFF%3BVLC%3A551a8b%3BGALT%3A008B45%3BFORID%3A10%3BDIV%3A%23FFFFF0%3B#1138" ></iframe>';
		}
		else  {
	
	if(motChercher== "achat" || motChercher== "vente" || motChercher== "discount" || motChercher== "jeux" ) height="420"; else { if(system.indexOf("safari") != -1) height="880"; else height="920"; } 
getRef("resultspubs").innerHTML='<div > <div style="width:250px; height:80px; position:relative;   background:#FFFFFF;left:0px; top:0px; z-index:20;  text-align:right; color:#666"><a href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation&hl=fr" style="color:#666; text-decoration:none; font-size:12px" target="_blanc">Annonces Google</a></div><iframe style="border:none;position:relative; left:0px; top:-90px; z-index:0" src="http://www.google.fr/cse?userip='+useripVal+"&client="+clientCherche+'&cof=GIMP%3ACCCCCC%3BT%3A000000%3BALC%3A551a8b%3BGFNT%3AB7B7B7%3BLC%3A2200cc%3BBGC%3AFFFFFF%3BVLC%3A551a8b%3BGALT%3A008B45%3BFORID%3A9%3BDIV%3A%23FFFFF0%3B&cx=partner-pub-6086935811934211%3A9wdzdfnnezg&ie=ISO-8859-1&q='+motChercher+'&sa=Rechercher&lang=en&siteurl=www.cherche.us%2F&ad=w9&num=10&rurl=http%3A%2F%2Fcluster1.cherche.us%2Fresults2.php%3Fuserip%3D'+useripVal+'%26cx%3Dpartner-pub-6086935811934211%253A9wdzdfnnezg%26cof%3DGIMP%253ACCCCCC%253BT%253A000000%253BALC%253A551a8b%253BGFNT%253AB7B7B7%253BLC%253A2200cc%253BBGC%253AFFFFFF%253BVLC%253A551a8b%253BGALT%253A008B45%253BFORID%253A10%253BDIV%253A%2523FFFFF0%253B%26ie%3DISO-8859-1%26q%3D'+motChercher+'%26sa%3DRechercher%26lang%3Den%26siteurl%3Dwww.cherche.us%252F&ad=w10" width="250"  marginheight="-300" height="'+height+'" scrolling="no"></iframe></div>';
		}*/
}
function showoption(id,idparent) {
try {
	visibilityOfOptions=getRef(id).style.visibility;
	if(visibilityOfOptions == "" || visibilityOfOptions == "hidden") { show_elem(id); getRef(idparent).innerHTML="<div style='width:20px; height:20px; float:left; margin-right:10px;'  onclick=\"showoption('cherche_option_leftNews','txtoption');\"><img src='css/images/moins.jpg'></div><div style='width:300px; height:10px; float:left; padding-top:2px; cursor:pointer' onclick=\"showoption('cherche_option_leftNews','txtoption');\"><u>Moins d'options</u></div>";}
	else { hide_elem(id); getRef(idparent).innerHTML="<div style='width:20px; height:20px; float:left; margin-right:10px;'  onclick=\"showoption('cherche_option_leftNews','txtoption');\"><img src='css/images/plus.jpg'></div><div style='width:300px; height:10px; float:left; padding-top:2px; cursor:pointer' onclick=\"showoption('cherche_option_leftNews','txtoption');\"><u>Plus d'options</u></div> ";}
	} catch(err) { } 
}
function setCookie(name, value)
{
	var expdate = new Date ();
	var path = null;
	var domain = ".chat-land.org";
	var secure = false;
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
	expires = expdate;
	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expdate.toGMTString()))+
		((path === null) ? "" : ("; path=" + path)) +
		((domain === null) ? "" : ("; domain=" +domain)) +
		((secure === true) ? "; secure" : "");
}
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;
} 
// la fonction réceptrice, ici "myFunction" 
function myFunction(result) {
	//if (topicNews== null) topicNews='h';
try { 
topicNews=getRef('topicNewss').value;
nation=getRef('nationss').value;
	}
	catch(err) {}
titretopic="Recherche News";		
	//if (result.responseData.responseDetails == "null") document.write("<br />ERROR<br />"+responseDetails);
	//else{

	final='';//<div class="categorieNews">'+titretopic+'</div>'; 
	//$('#optionImage').html(titretopic);
	nbresults=result.responseData.results.length;
    for(var i=0 ; i< nbresults;i++) {
	  
	titre=result.responseData.results[i].titleNoFormatting;
	
		contenu=result.responseData.results[i].content;
		lien=result.responseData.results[i].unescapedUrl;
		
		//date publication
		daterelease = addslashes(result.responseData.results[i].publishedDate);
		
		// publieur
		publieur=addslashes((result.responseData.results[i].publisher != ''? result.responseData.results[i].publisher : '' ));
		//publieur=result.responseData.results[i].publisher);
		
		// lien de redirection pour l'origine de la news
		originallien=(result.responseData.results[i].originalContextUrl != ''? result.responseData.results[i].originalContextUrl : '' );
		//originallien=result.responseData.results[i].originalContextUrl;
		final+='<div class="newNews"><div class="bodyNews">';
	
	if (result.responseData.results[i].image) {
		img=result.responseData.results[i].image.url;
		imgmin=result.responseData.results[i].image.tbUrl;
		imgwidth=result.responseData.results[i].tbWidth
		imgheight=result.responseData.results[i].tbHeight;
		final+='<div class="imgNews"><a href="'+lien+'" title="'+titre+'" target="_blanc"><img src="'+imgmin+'"  alt="'+titre+'" border="0" /></a></div>';
	}

final+='<div class="title"><a href="'+lien+'" title="'+titre+'" target="_blanc" >'+titre+'</a></div><div class="publieurnews"><span class="publieurgris">'+publieur+'</span>&nbsp;- <span class="datepublication">'+daterelease+'</span></div><div class="contentNewsss"><div id="paraphnews">'+contenu+'</div>'; 

	// array contenant les news en relation avec cette news
	
	if (result.responseData.results[i].relatedStories !='') {
	try {
	related=result.responseData.results[i].relatedStories;
	 for(var j=0 ; j< related.length;j++) {
		 
			if(j<6) {
			z=j;
				titlerelated = related[j].titleNoFormatting;
				urlrelated = related[j].unescapedUrl;
				publieurrelated = related[j].publisher;
				//daterelated = related[j].publishedDate;
				//redirectrelated = related[j].signedRedirectUrl;
				if(j<3) final+='<div id="relatedNews"><div class="lienRelated"><a href="'+urlrelated+'" target="_blanc" title="'+titlerelated+'">'+titlerelated+'</a>  <span class="publieurgris">'+publieurrelated+'</span></div></div>'; 
				else final+='<div class="MorerelatedNews"><a href="'+urlrelated+'" target="_blanc" title="'+titlerelated+'">'+publieurrelated+'</a></div>';
			}
		} 
		<!-- if (related.length>4) final+='<div class="NbrelatedNews"><a href="" target="_blanc" id="">'+(related.length-z)+'Autres Articles &raquo;</a></div>';-->
	} catch (err) {}
//	}
  		final+='</div></div>';
	
}
	}
	//}}
		$("#contentNews").html(final);
		if(final =="") { LoadCherch('h','','',''); selectNews('A la une','newsUne');
	}
		$("#contentNews").fadeIn('slow');
		$("#resultspubs").fadeIn('slow');
		$('#rslt-news').css('height',$('#contentNews').css('height'));			
    }  
updatepub("autre");



function chercher(query,geoV,topicV,scoringV,callbackF) {
 if (query!='') { 
 $(function() { 
    $.ajax({ 
        dataType:'jsonp', 
        url: 'http://ajax.googleapis.com/ajax/services/search/news', 
        data: { param:'hello' , v : "1.0" , rsz : "large" , callback : callbackF, geo : geoV, q : query}, 
            success:function(response) { 
              myFunction(response);
            } 
    }); }); 
	
 }
else { 
 $(function() { 
    $.ajax({ 
        dataType:'jsonp', 
        url: 'http://ajax.googleapis.com/ajax/services/search/news', 
        data: { param:'hello' , v : "1.0" , rsz : "large" , callback : callbackF, geo : geoV, topic : topicV}, 
            success:function(response) { 
              myFunction(response);
            } 
    });});  
	
}
  }  //getRemoteData('http://www.sitedistant.com/api.php?param=hello&callback=myFunction'); 
  
function LoadCherch(topic,cherche,geo,scoring){
//try {	
	
	getRef('topicNewss').value=topic;
	getRef('nationss').value=geo;
	chercheLien=cherche;
		if(!newarriv) {
		$("#contentNews").fadeOut('fast');
		$("#resultspubs").fadeOut('fast');
		setTimeout(function () { chercher(cherche,geo,topic,scoring,'myFunction')},200);
		//chercher(cherche,geo,topic,scoring,"myFunction");
		}
	else {newarriv=false;chercher(cherche,geo,topic,scoring,"myFunction");}
	updatepub ("autre");
	
	if(chercheLien !="") {
		chercheLien=stripslashes(URLEncode(chercheLien));
	getRef("mapslien").href="./maps.php?q="+chercheLien+"&lang="+getlang+lienCherche;
	getRef("weblien").href="./results.php?q="+chercheLien+"&lang="+getlang+lienCherche;
	getRef("imageslien").href="./resultimages.php?q="+chercheLien+"&lang="+getlang+lienCherche;
	//getRef("newslien").href="./resultnews.php?q="+cherche+"&lang="+getlang;
	getRef("videoslien").href="./resultvideo.php?q="+chercheLien+"&lang="+getlang+lienCherche;
	}
		
//} catch(err) { } 	
}
function selectNews(newstype,newsid) {
	
listnews = new Array("#newsUne","#newsInter","#newsFrance","#newsScience","#newsdivertissement","#newsSport","#newsPolitique","#newsBusiness");
$('#optionImage').html(newstype);
newsid="#"+newsid;
for( var i =0 ; i < listnews.length; i++) {

if (listnews[i] == newsid) {
$(newsid).css('width','160px');
$(newsid).css('margin-left','10px');
$(listnews[i]).css('font-weight','bold');
 
} else { 
$(listnews[i]).css('width','170px');
$(listnews[i]).css('margin-left','2px');
$(listnews[i]).css('font-weight','normal'); 
}
}
}
function searchevalue(){
selectNews('','');
cherchV=getRef('cherche').value;
$('#optionImage').html("Recherche sur : "+cherchV);
//q='tchat';
LoadCherch('',cherchV,'','');
}
$(document).ready(function(e) {
		$("#searchs").bind("blur",function(e) {if ($("#searchs").val()=='') {$("#searchs").val('Chercher une news') ; $("#searchs").css("color", '#999'); }});
		$("#searchs").bind("focus",function(e){if ($("#searchs").val()=='Chercher une news'){$("#searchs").val('') ; $("#searchs").css("color", '#000'); }});
		if (getcherche =="") LoadCherch('h','','','d');
		else { LoadCherch('', getcherche ,'','d'); getRef("searchs").value=getRef("cherche").value=getRef("cherche2").value=getcherche; $("#searchs").css("color", '#000'); }
		updatepub("tchat");
		if(screen.width<1024) { $("body").css("font-size", '10px');
		$("a").css("font-size", '12px');
		}
										  } );


/*
function updatepub () {

if (getRef('cherche').value != "" && getRef('cherche').value != "Chercher une news" )cherchValue=getRef('cherche').value
else if ($('#optionImage').html() != "Recherche" && $('#optionImage').html() != 'A la une') cherchValue=$('#optionImage').html();
else if ($('#optionImage').html() != '' && getcherche =="" )  cherchValue='Paris';
else  cherchValue =getcherche;
cherchValue=escape(cherchValue);
getRef('google_afs_ads_frame_right').src= "http://www.google.com/uds/GafsAds?q="+cherchValue+"&hl=fr&ad="+nbadleft+"&source=gcsc&qid="+qidCherche+"&cx="+cxCherche+"&referer="+servername+"&cof=GIMP%3A009900%3BT%3A000000%3BALC%3A551a8b%3BGFNT%3AB7B7B7%3BLC%3A2200cc%3BBGC%3AFFFFFF%3BVLC%3A551a8b%3BGALT%3A008B45%3BFORID%3A10%3BDIV%3A%23FFFFF0%3B#1138&cx=partner-pub-6086935811934211%3A9wdzdfnnezg&cof=GIMP%3A009900%3BT%3A000000%3BALC%3A551a8b%3BGFNT%3AB7B7B7%3BLC%3A2200cc%3BBGC%3AFFFFFF%3BVLC%3A551a8b%3BGALT%3A008B45%3BFORID%3A10%3BDIV%3A%23FFFFF0%3B#1138";

}*/