function getPopupx(obj_id, pop_id, tpoz, lpoz)
{
	popup = document.getElementById(pop_id);
	obj = document.getElementById(obj_id);
	pos = getElementPositionx(obj_id);
	
	if ((getClientWidthx()-pos.left)<325)
	{
		popup.style.right = 0+'px';
		popup.style.left = 'auto';
		popup.style.display = 'block';
	}
	else popup.style.left = (pos.left-lpoz)+'px';
	popup.style.top = (pos.top-tpoz)+'px';
	popup.style.display = 'block';
}

function getClientWidthx(){
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function hideBlock(hidename){document.getElementById(hidename).style.display = 'none';}

function getElementPositionx(elemId){
	var elem = document.getElementById(elemId);
	var w = elem.offsetWidth;
	var h = elem.offsetHeight;
	var l = 0;
	var t = 0;
	while (elem)
	{
		l += elem.offsetLeft;
		t += elem.offsetTop;
		elem = elem.offsetParent;
	}
	return {"left":l, "top":t, "width": w, "height":h};
}

function getProvinces(region) {
	if(!region)
		region = 0;
	c = document.getElementById('countryObj').value;
	$.ajax({
		url : "../../../Common/Php/Ajax/getRegions.php?c=" + c + "&r=" + region,
		success : function(retour) {
			//alert(retour);
			eval(retour);
			if(region == 0)
				op = new Option('Choisir', '0', true, true);
			else
				op = new Option('Choisir', '0', false, false);
			elSel.options.add(op);
			$('.selectBlock').resetSS();
		}
	});

}

function PopupCGU(lurl) {
	window.open(lurl, "_blank", "width=650,height=500,scrollbars=yes");
}

function showShadow() {
	// var h = $(document).height();
	// $('#shadow').css('height', h);
	$('#shadow').show();
}

function hideShadow() {
	$('.popunder').hide();
	$('#shadow').hide();
}

function authForm(afs) {
	centerDiv('auth_popup');
	if(afs == 1) {
		afsd = 'block';
		showShadow();
	} else {
		afsd = 'none';
		hideShadow();
	}
	document.getElementById('auth_popup').style.display = afsd;
	return false;
}

function centerDiv(id) {
	var h = $(window).height();
	var w = $(window).width();
	h = (h / 2) - ($('#'+id).height() / 2);
	w = (w / 2) - ($('#'+id).width() / 2);
	$('#'+id).css('top', h);
	$('#'+id).css('left', w);
}

function showCgv() {
	centerDiv('cgv');
	showShadow();
	$('#cgv').toggle();
}

function showMyPop(id) {
	hideShadow();
	centerDiv(id);
	showShadow();
	$('#'+id).toggle();
}
