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];
}


var shown=false;
function verifNb(mt) {
   if (mt == "") {
    return "vide";
    }

    if (isNaN(mt)) {
      return false;
	   
    }
	else  return true;
}
 	var baseIcon = new GIcon(G_DEFAULT_ICON);
    baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
    baseIcon.iconSize = new GSize(20, 34);
    baseIcon.shadowSize = new GSize(37, 34);
    baseIcon.iconAnchor = new GPoint(9, 34);
    baseIcon.infoWindowAnchor = new GPoint(9, 2);
	var map = null;
    var geocoder = null;
	  var mapOptions = {
		googleBarOptions : {
		  style : "new",
		  adsOptions: {
			client: "pub-6086935811934211:9wdzdfnnezg",
			//channel: "AdSense for Search channel",
			adsafe: "high",
			language: "fr"
		  }
		}
	  }
	  function updatepub () {
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","argent",'travail',"travail%20%E0%20distance","travail%20%E0%20domicile","boulo","beaut%E9","produit%20de%20beaut%E9","horoscopes" , "angoisse" , "horoscopes" , "tarot", "medium","voyance%20gratuite","voyante",'voyant',"horoscope%20gratuit","horoscope%20gratuit","vetements%20femmes",'horoscope%20chinois',"astrologie","astrologie%20chinois");
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 stripslashes (str) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins
    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // +   input by: Brant Messenger (http://www.brantmessenger.com/)
    // +   bugfixed by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch (n1) {
            case '\\':
                return '\\';
            case '0':
                return '\u0000';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

function URLDecode(val)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   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 showAddress(address,map) {

      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
			map = new GMap2(document.getElementById("chercheusMaps"), mapOptions);
			  map.setCenter(point, 13);
              var marker = new GMarker(point);
              map.addOverlay(marker);
              marker.openInfoWindowHtml(address);
			  map.enableGoogleBar();
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
            }
          }
        );
      }
    }
function initialize(longit,latit) {
var longit= longit;
var latit = latit;
 updatepub();
      if (GBrowserIsCompatible()) {
		$("#directions").html('');
		$('#directions').css('display',"block");
		$('#directions').css('visibility',"visible");
		$("#chercheusMaps").css('width',"78%");
		$("#chercheusMaps").css('float',"left");
		map = new GMap2(document.getElementById("chercheusMaps"), mapOptions);
       
		if(verifNb(longit) && verifNb(latitude)) { 
		center =new GLatLng(longit, latit);
		map.setCenter(center, 13);
		$("#chercheusMaps").css('width',"100%");		
		//var marker =  map.addOverlay(createMarker(center,'A'));
		var myHtml = "<b>Selon votre fournisseur d'internet</b> <br/><br/> Vous Etes ICI";  
      map.openInfoWindow(map.getCenter(), myHtml);
	 $('#rslt-maps').css('height',$('#resultspubs').css('height'));
		}
		else if(!verifNb(longit) && verifNb(latit)=="vide"){
			geocoder = new GClientGeocoder();
			setTimeout('showAddress("'+longit+'")',0);	
		$('#rslt-maps').css('height',$('#resultspubs').css('height'));
		}
		else { 
		$('#directions').css('display',"block");
		$('#directions').css('visibility',"visible");
		$('#directions').css('float',"left");
		gdir = new GDirections(map, document.getElementById("directions"));
			GEvent.addListener(gdir, "load", onGDirectionsLoad);
			GEvent.addListener(gdir, "error", handleErrors);
/*			$("#chercheusMaps").css('width',(screen.width/2)+"px"); */
			$("#chercheusMaps").css('width',"78%");
			$("#chercheusMaps").css('float',"left");
			$("#directions").css('float',"left");
			$("#directions").css('width',"20%");
			$("#chercheusMaps").css('height',"700px");
			setDirections(longit, latit, "fr_FR");		
		}
	//setupWeatherMarkers();	
		map.enableGoogleBar();
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
        map.addControl(new GOverviewMapControl());
		
      }
    }
	
   function setDirections(fromAddress, toAddress, locale) {
	  // alert('direction');
      gdir.load("from: " + fromAddress + " to: " + toAddress,
                { "locale": locale });

/*$("#chercheusMaps").css('height',$('#directions').css('height'));*/
	  setTimeout(resize,2000);
	   }
   // }
function resize(){
$('#rslt-maps').css('height',$('#directions').css('height'));	
//$("#chercheusMaps").css('height',$('#directions').css('height'));		
}
	
function handleErrors(){
     if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
       alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
     else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
       alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
     
     else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
       alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
    
     else if (gdir.getStatus().code == G_GEO_BAD_KEY)
       alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
    
     else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
       alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
      
     else alert("An unknown error occurred.");
	 initialize(longitude,latitude);
    }
	
	    function onGDirectionsLoad(){
        // Use this function to access information about the latest load()
        // results.
    
        // e.g.
        // document.getElementById("getStatus").innerHTML = gdir.getStatus().code;
      // and yada yada yada...
   			}
$(document).ready(function(){
						   initialize(longitude,latitude);					   
						 
						   });
