molSubmit = true;

$(function(){

	$('img[@src$=.png]').ifixpng();
	var ltie7 = ($.browser.msie && /MSIE\s(5\.5|6\.)/.test(navigator.userAgent));

	if ($("#recherche").size() > 0) {
		$("#recherche").click(function() {
			if ($("#recherche").val() == "Recherche")
				$("#recherche").val("");
		});
	}

	// Message de  confirmation lors de la création de compte cpme : A supprimer lors du réatblissement du service
//	$('.confimCPME').click(function(){
//		 if(confirm('Le service OSEO capital PME est en maintenance, lors de la création de votre profil merci de saisir les même identifiants (courriel et mot de passe) que ceux utilisés dans monOSEO.')){
//		 } else{
//		 	return false;
//		 }
//	});

	// A supprimer lors du réatblissement du service quoi que !!
	if($('.accueil').size() > 0){
		if ($('#services .middle').height() > '80'){
			$('#monProfil .middle').height($('#services .middle').height()+3+'px');
		}
	}


	// Gestion des bloc sousService
	$('.ssService').each(function(){
	//	$(this).prev().find('.bottom').css("background", "url(/_media/img/large_top_cc_ssService.png)");
		var height = $(this).prev().find('.bottom').height();
		//console.log($(this).prev().find('.bottom').height());
		if (ltie7){
			$(this).find('.top').css("background", "url(/_media/img/large_top_cc_ssService.png)").css('height', '25px').ifixpng();
			height = height - 15;
			$(this).prev().find('.bottom').css("filter", "none");
		}
		else{
			$(this).find('.top').css("background", "url(/_media/img/large_top_cc_ssService.png)").ifixpng();
		}

		//$(this).css('margin-top', -height);
		$(this).css('margin-top', 0);

		$(this).prev().find('.bottom').css("background", "none").remove();

		$(this).mouseover(function(){
			$(this).find('.top').css('background', 'url("/_media/img/large_top_cc_ssService_red.png")').ifixpng();


		}).mouseout(function(){
			$(this).find('.top').css('background', 'url("/_media/img/large_top_cc_ssService.png")').ifixpng();

		});
	});


	if (($("#listeAtrier").size()) > 0 ) {
		var FnD=function(objCourrant)
		{
			if (window.ActiveXObject) objCourrant.style["filter"]="alpha(opacity="+(50)+")";
			else objCourrant.style["opacity"]=(50/100);
			objCourrant.style["zIndex"]=10000;
			objCourrant.style['backgroundColor']="#fefefe";
			objCourrant.style['border']="1px dashed red";
		};
		var FnU=function(objCourrant)
		{
			if ((window.ActiveXObject)) objCourrant.style["filter"]="";
			else 	objCourrant.style["opacity"]="";
			objCourrant.style["zIndex"]="";
			objCourrant.style["backgroundColor"]="";
			objCourrant.style['border']="1px solid #FFFFFF";
		};
		var list=new ListeDragAndSort("liste","itemListe","div","TBL_favoris","FAVORI_id","FAVORI_ordre","lesids","listeAtrier","sortListe",FnD,FnU);


		// Comportement liste favoris

		// Traitement du submit
		$('#listeAtrier').submit(function () {
			if ($.browser.msie) {
				$(this).find('a:first').focus();
			} else {
				$(this).find('input.toEdit').blur();
			}
			return false;
		});

		// onclic du bouton pour modifier le nom du lien
		$('#listeAtrier img.edit').click(function(){
			// on valide tous les inputs en modification
			try {	// Garder le try catch pour IE
				changed = $('#listeAtrier').find('input.toEdit').blur();
			} catch (e) {
			}
			if (changed.length == 0) {	// Si on a caché des éléments, on se contente de tout désactiver
				var saveUrl=$(this).nextAll('.texte').find('a').attr('href');
				var fav = $(this).nextAll('.texte');
				var texte = fav.text();
				fav.html("<input type='text' class='toEdit' name='temp' size='75' style='position:relative;z-index:50' value='' />");
				fav.find('>input').focus();
				fav.find('>input').val(jQuery.trim(texte));
				fav.find('>input').blur(function(){
					oseoruc_setNameFavori($(this).parent().prev().val(),$(this).val());
					$(this).parent().html("<a href='"+saveUrl+"' target='_blank'>"+$(this).val()+"</a>");
				});
			}
		});

		$('#listeAtrier img.sup').click(function(){
			if (confirm("Supprimer ce favori?")) {
				oseoruc_supFavori($(this).nextAll('.lesidobj').val());
				if (ltie7)
					var bros = $(this).parent('div').siblings();
				$(this).parent('div').remove();
				if (ltie7) {
					bros.hide();
					bros.show();
				}
			}
		});
	}

	if ($("#echanges").size() > 0) {
		$('#resultatakio').Accordion({
					headerSelector	: 'dt',
					panelSelector	: 'dd',
					activeClass		: 'myAccordionActive',
					hoverClass		: 'myAccordionOver',
					panelHeight		: 200,
					speed			: 300
		});
	}

	$('.lienrss').xbinfos({
		offsetX : -240,
		offsetY : 0,
		fade : false,
		addImage : false,
		cssToolTip : "toolTipRssActu"
	});


	// Mouse over sur les services
	if ($("#allServices").size()>0) {
		$('#allServices .bloc').mouseover(function() {
			$(this).addClass('over');
			if (ltie7) {
				$('div.top', this).addClass('over');
				$('div.bottom', this).addClass('overBottom');
			}
		});

		$('#allServices .bloc').mouseout(function() {
			$(this).removeClass('over');
			if (ltie7) {
				$('div.top', this).removeClass('over');
				$('div.bottom', this).removeClass('overBottom');
			}
		});
	}

	// Selection date creation entreprise
	if ($("#profil").size()>0) {
		$.datepicker.regional['fr'];
		$.datepicker.setDefaults({
					showOn: 'both',
					buttonImageOnly: true,
					buttonImage: '_media/img/calendar.jpg',
					buttonText: 'Calendrier',
					currentText: 'Aujourd\'hui',
					nextText: 'Suiv>',
					dateFormat: 'dd/mm/yy',
					speed: 0
		});
		$('#company_date').datepicker();

		$("#form_id").submit(function () {
			try {
				if ($(this).find("input[@name=P_is_client_oseo][@checked=1]").size() == 0) {
					alert("Vous devez précisez si vous êtes déjà client OSEO");
					return false;
				}
				if ($(this).find("input[@name=P_informations_oseo][@checked=1]").size() == 0) {
					alert("Vous devez préciser si vous souhaitez recevoir des informations d'OSEO");
					return false;
				}
			} catch (e) {
				return true;
			}
		});
	}


	// Completion
	if ($("#naf_search_id").size()>0) {
		setCompletion("naf_search_id");
	}


	// Liste des échanges AKIO
	if ($("#listeDossiers").size()>0) {
		$("#listeDossiers .reduced").click(function() {
			var splitDossier = $(this).attr('id').split('_');
			var idDossier = splitDossier[1];
			$("#listeDossiers .bloc").hide();
			$("#listeDossiers .reduced").show();
			$(this).hide();
			$("#full_"+idDossier).show();
		});

		$("#listeDossiers .bloc").hide();
		$("#listeDossiers .reduced:first").click();

		$("#listeDossiers .reduced").mouseover(function(){
			$(this).addClass("over");
		});
		$("#listeDossiers .reduced").mouseout(function(){
			$(this).removeClass("over");
		});
	}

	$("#P_home_newsletter_lien_id").click(function() {
		oseoruc_managenews();
		return false;
	});

	$("#P_newsletter_lien_id").click(function() {
		oseoruc_managenews($('#P_newsletter_id').attr("checked") ? 1 : 0);
		return false;
	});


	if (ltie7) {
		// Emulation du 'position: fixed' pour IE6
		$("#conteneur_footer").css('position','absolute');
		$(window).scroll(function(){ $("body").each(function(){
			$("#conteneur_footer").css('top',(document.documentElement.scrollTop+document.documentElement.clientHeight-38)+'px');
		});}).resize(function(){ $("body").each(function(){
			$("#conteneur_footer").css('top',(document.documentElement.scrollTop+document.documentElement.clientHeight-38)+'px');
		});});
		$("input[type='radio']").css('border', 0);
		$("input[type='checkbox']").css('border', 0);
	}


	if ($("#banniere").size() > 0) {
		var so = new SWFObject("/_media/swf/ban_non_logge.swf", "banniereInscription", "485", "55", "8", "#FFFFFF");
		so.addParam("wmode", "transparent");
		so.write("banniere");
	}

	$("#link_logout").click(function(){
		return clearCookies();
	});

	$("#clear_sso").each(function(){
		clearSSO();
	});

	$("#logout_cpme").each(function(){
		logoutCpme();
	});

	/**
	 GEstion MOL
	 */
	if (molSubmit == true && $("#submitMOL").size()>0){
		$("#submitMOL").submit();
	}

	date = new Date();
	lastInit = parseInt(date.getTime()/1000);
	if ($("#lienMol").size() > 0 && $("#molFrame").size() > 0 && $("#molUrl").size() > 0) {
		$("#lienMol").click(function () {
			var date = new Date();
			var time = parseInt(date.getTime()/1000);
			var delay = parseInt($("#molDelay").val());
			if (lastInit + delay > time) {
				$("#molFrame").attr("src", $("#molUrl").val());
			} else {
				lastInit = time;
				$("#submitMolDefaut").submit();
			}
			return false;
		});
	}


	// Ouverture popup CGV MOL
	if ($("#lienCgvMol").size()>0) $("#lienCgvMol").click(function(){
		if(window.open('cgv_mol.php','Conditions_Generales','width=615,height=600,left=600,top=0,resizable=0, scrollbars=1')){
			return false;
		}
	});

});

function openInFullScreen() {
	if (window.parent.location != window.location) {
		window.parent.location = window.location;
	}
}
