$(document).ready(function(){
	showOrder();
	showField();
	//showLangueField();	
	/*showExpireCard(); DIGITAS 30/09/08*/
	initFormFunction();
	//var ie = $.browser.msie;
	
	var isIE6 = /MSIE 6/i.test(navigator.userAgent);
	if(isIE6){
		$('.sortSelect').selectbox({debug: false});
	}
	
	miseEnFormeMessageErreur();
});


/*Montrer cacher dans vos commandes */
function showOrder(){
	$(".displayOrder").hide();
	$(".recapHead th a").click(function(){
		$(this).parents().parents().next().find(".displayOrder").slideToggle("normal", function(){		
			$(this).parents().parents().parents().prev().find(".dateHead a").toggleClass("downwards");
		});
		return false;
	});
}

/*Montrer cacher champ raison sociale*/
function showField(){	
	if($("#entreprise").length){
		if($("#entreprise")[0].checked == false)
		$("#fieldEntreprise").hide();	
			
		$("#entreprise , #association").click(function(){
			if(this.checked == true ){
				$("#fieldEntreprise").show();
			}	
		});	
		/*DIGITAS 25/09/08 : modifs*/
		$("#particulier").click(function(){
			if(this.checked == true ){
				$("#fieldEntreprise").hide();
			}	
		});		
		/*DIGITAS 25/09/08 : fin modifs*/
	}
}

/*
//Affichage du champ langue en fonction de la selection pays
function showLangueField(){
	$("#LanguageField").hide();
	
	var CountryList = document.getElementById('Pays');
		if(CountryList){CountryList.onchange = function(){	
			var MyCountry = this.options[this.selectedIndex].value;
				if(MyCountry == "FR"){
					$("#LanguageField").hide();
				}
				
				else{
					$("#LanguageField").show();
				}
		
		}

	}
}
*/
/*Affichage champ expiration de la carte  DIGITAS 30/09/08
function showExpireCard(){
	$("#birthDateBloc").hide();
	
	var cardTypeList = document.getElementById('cardType');
		if(cardTypeList){cardTypeList.onchange = function(){	
			var MyCardType = this.options[this.selectedIndex].value;
				if(MyCardType == "carteAccord"){
					$("#expireDateBloc").hide();
					$("#controlNumberBloc").hide();
					$("#birthDateBloc").show();
				}
				else{
					$("#birthDateBloc").hide();
					$("#expireDateBloc").show();
					$("#controlNumberBloc").show();					
				}
		}
	}

}*/

function closePopin(obj,params){
	$(obj).hide();
	if(params){
		if(params.removeHideDocuement)
			removeHideDocuement();
	}else removeHideDocuement();
		
}

function getPopin(id){
	hideDocuement()

}

function hideDocuement(){
	if(!$('.hideDocument').length)$('body').append('<div class="hideDocument"></div>');
	// traiter les exception
		obj = {hi: 0, wi:0 , top : 0}
	//fin des exception
	var wi = document.documentElement.clientWidth-obj.wi;
	var hi = document.documentElement.clientHeight-obj.hi;
	var top = getScrollTop()-obj.top;
	var left = wi/2;
	$('.hideDocument').attr('style','width:'+wi+'px;height:'+hi+'px;top:'+top+'px;left:'+left+';');
}

function removeHideDocuement(){
	$('.hideDocument').remove();
}

function getScrollTop(){
	if( document.body && ( document.body.scrollLeft || document.body.scrollTop ))
		return document.body.scrollTop;
	else
		return document.documentElement.scrollTop;
}


function initFormFunction(){

		$(".labelNomErreur").hide();
		$(".labelNumCarteErreur").hide();
		$(".submitCarte").hide();
	
	if(document.getElementById('CheckCardWaaoh')!=null && $("#CheckCardWaaoh").val() != "true"){
		$("#carteSelectionnee").hide();
	}else{
		$("#selectionnerCarte").hide();
		$("#opacDivForm").hide();
	}
	
	if($("#CheckCardWaaoh").val() == "oui"){
		$("#waaohOui").attr("checked","checked");
	}
	if($("#CheckCardWaaoh").val() == "non"){
		$("#waaohNon").attr("checked","checked");
	}
	// Si les renseignements donnés pour la carte waaoh sont incorrects, on réaffiche les champs de renseignements
	if($("#topErrorMsgWaooh").css("display")=="block"){
		$(".submitCarte").show();
		$("#opacDivForm").show();
	}
	// On masque l'opacDivForm si on a déjà validé le formulaire et qu'on le réaffiche suite à une erreur 
	if($("#wsErrorMsg").css("display")=="block" || $("#topErrorMsg").css("display")=="block" || $("#topErrorMsgWS").css("display")=="block"){
		$("#opacDivForm").hide();
	}
	if (typeof document.body.style.maxHeight === "undefined") {
		var containerHeight = $("#formDisplayContainer").height();
		$("#opacDivForm").height("940px");
		//$("#formDisplayContainer select").css("visibility","hidden");
	}
	
	

	
	$(".showLayerInput").each(function(){
		if($("#waaohOui").attr("checked") == true && $("#topErrorMsgWaooh").css("display")!="block"){
			$("#opacDivForm").hide();
		}
		
		$(this).click(function(){
			$("#opacDivForm").hide();
			if (typeof document.body.style.maxHeight === "undefined") {
				//$("#formDisplayContainer select").css("visibility","visible");	
			}
			if($(this).attr("value") == "oui"){
				$(".submitCarte").show();
				$("#NumCarte").focus();
				$("#CheckCardWaaoh").attr("value", "oui");
				$("#opacDivForm").show();
			}
			else{
				$("#opacDivForm").hide();
				$(".submitCarte").hide();
				$("#CheckCardWaaoh").attr("value", "non");	
			}
			$(".selectbox").hide();
			$(".selectbox").show();
		});
	});
	
	$("#formDisplayContainer .layerShippingForm").hide();
	
	if($("#formDisplayContainer .shippingTypeForm:checked").attr("value") == "non"){
		$("#formDisplayContainer .layerShippingForm").show();		
	}
	
	$("#formDisplayContainer .shippingTypeForm").click(function(){
		if($(this).attr("value") == "non" ){
			$("#formDisplayContainer .layerShippingForm").show();	
		}
		else{
			$("#formDisplayContainer .layerShippingForm").hide();		
		}
	});
}

function miseEnFormeMessageErreur(){
	$(".erreur").each(function(i,el){
	if($(this).css("display")=="block"){
		//console.log($(this).text());
	}})
}

