/*---- CarteFrance.js ----*/

function PJPAGetSecteurId(secteurName) {
	if (secteurName == "Immobilier") {
		return 1;
	}
	else if (secteurName == "Automobile") {
		return 2;
	}
	else if (secteurName == "Moto") {
		return 3;
	}
	else if (secteurName == "Emploi") {
		return 4;
	}
	else if (secteurName == "Services") {
		return 6;
	}
	else {
		return 0;
	}	
}

var newModeActif = false;

function PJPARegionMap(id, nom, coords, idRef, urlbase, idMapFrance, secteur) {
	this.Id = id;
	this.Nom = nom;
	this.IdRef = idRef;
	this.Secteur = secteur;
	this.Coords = coords;
	this.Urlbase = urlbase;
	this.IdMapFrance = idMapFrance;

	this.Img = new Image();
	this.Img.src = urlbase + "Aucun/" + id + "_Aucun.png";

	this.Html = "<area href=\"#\" id=\"" + this.Id + "\" shape=\"poly\" coords=\"" + this.Coords + "\" "
    + " onmouseover='" + idMapFrance + ".ImgOn(this)' onmouseout='" + idMapFrance + ".ImgOut(this)' onclick='"
    + idMapFrance + ".ImgClick(this)' />";    
}

PJPARegionMap.prototype.ChangeSecteur = function(secteur) {
	this.Secteur = secteur;	
	this.Img.src = this.Urlbase + "Aucun/" + this.Id + "_Aucun.png";
}

function PJPACarteFrance(id, imgFondId, imgAreaId, divRenduId, defautSecteurId, titreNbAnnonceId, 
						 sectorHiddenFieldId, regionHiddenFieldId, submitButtonId,
						 target, useUrlServeur) {
    this.ID = id;
    this.Secteur = defautSecteurId;
    this.UrlBase = "/_Images/CarteFrance/";
    this.ImgFond = document.getElementById(imgFondId);
    this.ImgArea = document.getElementById(imgAreaId);
    this.RenduId = document.getElementById(divRenduId);
    this.SectorHiddenFieldId = sectorHiddenFieldId;
    this.RegionHiddenFieldId = regionHiddenFieldId;
    this.SubmitButtonId = submitButtonId;
   	this.CurrentSecteur = document.getElementById(defautSecteurId);
    this.Target = target;
    this.UseUrlServeur = useUrlServeur;
    
	this.RegionSelected = null;
    
    this.ImgArea.usemap = "#map_" + this.ID;

    this.InitCoords();
    this.SetIdSecteur(this.Secteur);
    if (this.CurrentSecteur != undefined) {
    	this.CurrentSecteur.className += " Selected";

    	this.ImgDefaut = new Image();
    	this.ImgDefaut.src = this.UrlBase + "cf_" + this.Secteur + ".png";

    	this.ImgFond.src = this.ImgDefaut.src;
    	this.ImgArea.src = this.ImgDefaut.src;
	}

	var divAlerte = "alerteCF";
	this.DivAlerteTexte = "id" + divAlerte + "_texte";
	this.DivAlerte = PJPAPopinAlerte.ErreurFormulaire(divAlerte, "id" + divAlerte, "id" + divAlerte + "_texte", this.MsgDefaut, 35, 55, 185);
	this.ObjAlerteTexte = document.getElementById(this.DivAlerteTexte);
	this.ObjAlerteTexte.innerHTML = "Sélectionnez une région";
	this.MovePositionAlerte(325, 90, 150);
	PJPAPopinAlerte.ChangeCss(this.DivAlerte, "bg");
    this.CreateMaps();    
}

PJPACarteFrance.prototype.SetIdSecteur = function(secteurName) {
	this.SecteurID = PJPAGetSecteurId(secteurName);
}

PJPACarteFrance.prototype.InitCoords = function() {
	this.Img = new Object();
	this.Img['alsace'] = new PJPARegionMap('alsace', 'alsace', '193,78,184,83,181,74,184,47,199,46,193,63', 1, this.UrlBase, this.ID, this.Secteur);
	this.Img['aquitaine'] = new PJPARegionMap('aquitaine', 'aquitaine', '65,191,44,179,50,173,56,127,72,139,83,128,93,128,98,142,87,161,72,167,70,175,73,182', 2, this.UrlBase, this.ID, this.Secteur);
	this.Img['auvergne'] = new PJPARegionMap('auvergne', 'auvergne', '139,147,127,142,123,148,120,143,113,150,108,147,114,131,115,109,121,100,139,108,135,120,137,133,147,136', 3, this.UrlBase, this.ID, this.Secteur);
	this.Img['bassenormandie'] = new PJPARegionMap('bassenormandie', 'basse normandie', '88,67,74,61,54,58,47,32,56,33,60,39,81,42,88,56', 4, this.UrlBase, this.ID, this.Secteur);
	this.Img['bourgogne'] = new PJPARegionMap('bourgogne', 'bourgogne', '158,104,136,114,138,110,130,102,124,102,124,67,128,64,135,72,148,72,151,76,158,80', 5, this.UrlBase, this.ID, this.Secteur);
	this.Img['bretagne'] = new PJPARegionMap('bretagne', 'bretagne', '60,61,59,76,37,84,11,72,6,56,26,53,34,59', 6, this.UrlBase, this.ID, this.Secteur);
	this.Img['centre'] = new PJPARegionMap('centre', 'centre', '121,99,112,107,94,111,87,97,76,89,80,82,89,69,89,55,97,55,108,66,122,72,122,87', 7, this.UrlBase, this.ID, this.Secteur);
	this.Img['champagneardenne'] = new PJPARegionMap('champagneardenne', 'champagne ardenne', '159,80,148,72,136,73,130,62,130,52,135,41,140,27,153,33,151,55,166,70', 8, this.UrlBase, this.ID, this.Secteur);
	this.Img['corse'] = new PJPARegionMap('corse', 'corse', '202,204,194,200,192,180,205,171,208,183', 9, this.UrlBase, this.ID, this.Secteur);
	this.Img['franchecomte'] = new PJPARegionMap('franchecomte', 'franche comte', '171,111,156,106,162,81,167,72,180,75,185,82', 10, this.UrlBase, this.ID, this.Secteur);
	this.Img['hautenormandie'] = new PJPARegionMap('hautenormandie', 'haute normandie', '98,54,89,55,85,51,82,37,81,33,98,28,103,39', 11, this.UrlBase, this.ID, this.Secteur);
	this.Img['iledefrance'] = new PJPARegionMap('iledefrance', 'ile de france', '120,67,105,63,100,50,101,45,123,48,130,55,128,64', 12, this.UrlBase, this.ID, this.Secteur);
	this.Img['languedocroussillon'] = new PJPARegionMap('languedocroussillon', 'languedoc roussillon', '125,200,105,201,108,193,103,181,116,178,129,163,125,150,127,143,137,147,140,157,151,157,154,163,144,175,126,188', 13, this.UrlBase, this.ID, this.Secteur);
	this.Img['limousin'] = new PJPARegionMap('limousin', 'limousin', '106,143,97,140,94,128,86,128,88,114,111,108,113,132', 14, this.UrlBase, this.ID, this.Secteur);
	this.Img['lorraine'] = new PJPARegionMap('lorraine', 'lorraine', '180,74,166,69,153,55,154,36,178,45,184,53', 15, this.UrlBase, this.ID, this.Secteur);
	this.Img['midipyrenees'] = new PJPARegionMap('midipyrenees', 'midi pyrenees', '68,192,72,176,69,167,87,161,99,143,108,149,114,149,119,145,130,164,117,176,103,180,106,198,85,193', 16, this.UrlBase, this.ID);
	this.Img['nordpasdecalais'] = new PJPARegionMap('nordpasdecalais', 'nord pas de calais', '138,23,115,21,104,18,102,7,114,5', 17, this.UrlBase, this.ID);
	this.Img['paysdelaloire'] = new PJPARegionMap('paysdelaloire', 'pays de la loire', '65,108,55,109,39,97,39,85,58,73,59,62,74,62,89,66,76,90,62,95', 18, this.UrlBase, this.ID);
	this.Img['picardie'] = new PJPARegionMap('picardie', 'picardie', '130,52,122,45,102,43,103,30,98,24,100,18,115,25,138,26,133,39', 19, this.UrlBase, this.ID);
	this.Img['poitoucharentes'] = new PJPARegionMap('poitoucharentes', 'poitou charentes', '73,138,57,123,57,110,65,110,62,96,74,94,84,97,92,111,84,126', 20, this.UrlBase, this.ID);
	this.Img['provencealpescotedazur'] = new PJPARegionMap('provencealpescotedazur', 'provence alpes cote d azur', '147,176,152,159,158,157,167,160,162,150,177,138,187,144,188,156,199,161,200,168,183,182,163,181', 21, this.UrlBase, this.ID);
	this.Img['rhonealpes'] = new PJPARegionMap('rhonealpes', 'rhone alpes', '165,158,158,158,143,157,139,148,146,135,139,132,137,116,155,107,172,112,179,109,186,118,187,133,176,137,165,150', 22, this.UrlBase, this.ID);

	this.Img['guadeloupe'] = new PJPARegionMap('guadeloupe', 'guadeloupe', '256,73,238,70,236,54,248,46,259,55', 23, this.UrlBase, this.ID);
	this.Img['martinique'] = new PJPARegionMap('martinique', 'martinique', '259,103,250,107,242,103,236,86,243,83,255,88', 23, this.UrlBase, this.ID);
	this.Img['guyane'] = new PJPARegionMap('guyane', 'guyane', '250,140,240,139,240,131,239,119,255,117,258,129', 23, this.UrlBase, this.ID);
	this.Img['lareunion'] = new PJPARegionMap('lareunion', 'la réunion', '256,175,243,175,230,162,238,154,252,154,260,163', 23, this.UrlBase, this.ID);
}

PJPACarteFrance.prototype.CreateMaps = function() {
	var html = '<map name="map_' + this.ID + '" id="map' + this.ID + '" >';
	var areas = "";
	$.each(this.Img,
		function(i, n) {
			areas += n.Html + "\n";
		}
	);
	html = html + areas + "</map>";
	this.RenduId.innerHTML = html;
}

PJPACarteFrance.prototype.ImgOn = function(indexRegion) {
    this.ImgArea.src = this.Img[indexRegion.id].Img.src;
}

PJPACarteFrance.prototype.ImgOut = function(indexRegion) {
    this.ImgArea.src = "/_Images/pix.gif";
}

PJPACarteFrance.prototype.ImgClick = function(indexRegion) {
	this.RegionSelected = this.Img[indexRegion.id];
	this.Valide();
}

PJPACarteFrance.prototype.SelectSecteur = function(SecteurItem) {
	if (this.Secteur == SecteurItem.id) {
		$(this.DivAlerte).show();
	}
	else {
		$(this.DivAlerte).hide();
		var oldSelected = document.getElementById(this.Secteur);
		if (oldSelected != undefined && oldSelected != null) {
			oldSelected.className = "Secteur_" + this.Secteur;
		}

		this.Secteur = SecteurItem.id;
		this.SetIdSecteur(this.Secteur);

		SecteurItem.className += " Selected";

		this.ImgDefaut.src = this.UrlBase + "cf_" + this.Secteur + ".png";
		this.ImgFond.src = this.ImgDefaut.src;
		this.ImgArea.src = this.ImgDefaut.src;
	}
}

PJPACarteFrance.prototype.MovePositionAlerte = function(left, top, width) {
	this.DivAlerte.css("left", left);
	this.DivAlerte.css("top", top);
	$("#" + this.DivAlerteTexte).css("width", width);
}

PJPACarteFrance.prototype.ChgCss = function(obj, css) {
	if (this.Secteur != obj.id) {
		obj.className = css;
	}
}

PJPACarteFrance.prototype.CarteFranceOut = function() {
$(this.DivAlerte).hide();
}

PJPACarteFrance.prototype.Valide = function() {

	PJPATagXitiRechercheExpress(this.Secteur);

	if (this.SecteurID >= 1 && this.SecteurID <= 3) {
		this.ValideImmoAutoMoto();
	} //emploi
	 else if (this.SecteurID == 4) {
		this.ValideEmploi();
	} //stages	
	else if (this.SecteurID == 5) {
		this.ValideStages();
	} //services	
	else if (this.SecteurID == 6) {
		this.ValideServices();
	}
}


PJPACarteFrance.prototype.ValideImmoAutoMoto = function() {
	var sectorHiddenField = document.getElementById(this.SectorHiddenFieldId);
	var regionHiddenFieldId = document.getElementById(this.RegionHiddenFieldId);
	var submitButtonId = document.getElementById(this.SubmitButtonId);

	if (this.SecteurID == 1) {
		secteur = 'immo';
	} else if (this.SecteurID == 2) {
		secteur = 'auto';
	} else if (this.SecteurID == 3) {
		secteur = 'moto';
	}

	sectorHiddenField.value = secteur;
	regionHiddenFieldId.value = this.RegionSelected.Nom;
	submitButtonId.click();
}

PJPACarteFrance.prototype.RedirectToUrl = function(relativeUrl) {
	if (relativeUrl != null) {
		var url = _pjpaUrlServeur + relativeUrl;

		if (this.Target == '_blank') {
			window.open(url);
		} else if (this.Target == '_parent') {
			window.parent.location = url;
		} else {
			if (this.UseUrlServeur) {
				window.location = url;
			} else {
				window.location = relativeUrl;
			}
		}
	}
	return false;
}


PJPACarteFrance.prototype.ValideEmploi = function() {
	var ou = this.RegionSelected.IdRef;
	var url = "http://www.embauche.com/recherche_d_offres_d_emploi/?keyword=&search=search&newSimpleSearch=1&categories=0&lieux=" + ou + "&subregions=0";
	window.open(url);
}


PJPACarteFrance.prototype.ValideStages = function() {
	var idFonction = "0";
	var idNiveauQualification = "0";
	var ou = this.RegionSelected.Nom;

	var url = "/Stages/stages.aspx";
	url += "?IdFonction=" + idFonction;
	url += "&IdNiveauQualification=" + idNiveauQualification;
	url += "&Ou=" + ou;

	this.RedirectToUrl(url);
}

PJPACarteFrance.prototype.ValideServices = function() {
	if ( this.RegionSelected.Nom !=  undefined && this.RegionSelected.Nom != '') {
		PJPACarteFrance.SubmitFormService("", "", this.RegionSelected.Nom);
	}
}

PJPACarteFrance.SubmitFormService = function(cat_id, srv_id, ou) {
	var ouval = PJPARemplaceOu(ou);
	var reg = new RegExp(" ", "gi");
	ouval = ouval.replace(reg, "-");
	document.location = "http://services.annoncesjaunes.fr/recherche-d-etudiants/" + ouval + "/0-0-0-0-1-1-P-0/0.html";
}


function PJPATagXitiRechercheExpress(secteurName) {
	if (secteurName == "Immobilier") {
		xt_med('C', '0', 'Home::I_Moteur_Trouvez', 'N');
	}
	else if (secteurName == "Automobile") {
		xt_med('C', '0', 'Home::A_Moteur_Trouvez', 'N');
	}
	else if (secteurName == "Moto") {
		xt_med('C', '0', 'Home::M_Moteur_Trouvez', 'N');
	}
	else if (secteurName == "Services") {
		xt_med('C', '0', 'Home::S_Moteur_Trouvez', 'N');
	}
	else if (secteurName == "Emploi") {
		xt_med('C', '0', 'Home::E_Moteur_Trouvez', 'N');
	}	
}




