/* A.Mota && nextdev && K2 Patrimoine © */
function addEventOnError() {
	if(typeof window.onerror == 'function') {
		var exFunc = window.onerror;
		window.onerror = function anonym0(msg, url, line) {
			errorLogs(msg, url, line);
			exFunc(msg, url, line);
			}
		}else{ window.onerror = errorLogs; }
	}
function errorLogs(msg, url, line) {
	alert('ERROR\r\nLine: '+line+'\r\nUrl: '+url+ '\r\nMessage: '+msg);
	}
//addEventOnError();

var _cssDisabled = false;
function loadJS(dir) {
	var cssTest = document.createElement('div');
	cssTest.style.position = 'absolute';
	document.getElementsByTagName('body')[0].appendChild(cssTest);
	if(cssTest.currentStyle) { var currStyle = cssTest.currentStyle['position']; }
	else if(window.getComputedStyle) { var currStyle = document.defaultView.getComputedStyle(cssTest, null).getPropertyValue('position'); }
	_cssDisabled = (currStyle === 'static') ? true : false;
	document.getElementsByTagName('body')[0].removeChild(cssTest);
	loadHiddenImg(dir);
	loadMenuOpacityEffect(dir);
	}

function noClic() { return(false); }
//document.oncontextmenu = noClic;

function IEorGECKO() {
	if(navigator.appName == 'Microsoft Internet Explorer') { return 'IE'; }
	else{ return 'GECKO'; }
	}

function displayHideDiv(id) {
	if(document.getElementById(id)) {
		var obj = document.getElementById(id);
		if(obj.style.display==null || obj.style.display==='block' || obj.style.display==='inline' || obj.style.display=='' || (IEorGECKO()==='IE'&&obj.style.display=='')) { obj.style.display = 'none'; }
		else{ obj.style.display = 'block'; }
		}
	}

function openUrl(objId) {
	window.open(document.getElementById(objId).href, '_self');
	}

function loopSrc(obj) {
	var url = obj.src.split('images/');
	var urlnoext = url[1].replace(/^(.*)\..*$/gi,'$1');
	var ext = '.'+url[1].replace(/^.*\.(.*)$/gi,'$1');
	if(/^.*-over*$/gi.test(urlnoext) != true) {
		obj.src = url[0]+'images/'+urlnoext+'-over'+ext;
		}else{
			var delover = urlnoext.replace(/^(.*)-over$/gi,'$1');
			obj.src = url[0]+'images/'+delover+ext;
			}
	}

function loopBg(obj, over, bg, dir, progIt) {
	var objLink = document.getElementById('oP'+progIt);
	if(over === 1) {
		obj.style.backgroundImage = 'url("'+dir+'images/'+bg+'-over.gif")';
		objLink.style.textDecoration = 'underline';
		}else{
			obj.style.backgroundImage = 'url("'+dir+'images/'+bg+'.gif")';
			objLink.style.textDecoration = 'none';
			}
	}

function loopBgCo(obj, over, color, overBg) {
	var onBg = 'transparent';
	if(overBg === 0) { onBg = 'black'; }
	else if(overBg === 1) { onBg = '#2E3D94'; }
	if(over === 1) { obj.style.backgroundColor = onBg; obj.style.color = 'white'; }
	else{ obj.style.backgroundColor = color; obj.style.color = 'black'; }
	}

function setCssOpacity(obj, opa) {
	var opaDecimal = opa/100;
	if(obj) {
		obj.style.filter = 'alpha(opacity='+opa+')';
		obj.style.opacity = opaDecimal;
		obj.style.MozOpacity = opaDecimal;
		obj.style.KhtmlOpacity = opaDecimal;
		}
	}

function setCssAbsolute0(obj, top, left) {
	obj.style.position = 'absolute';
	obj.style.top = top;
	obj.style.left = left;
	}

function addiPx(nb0, nb1, nb2) {
	var val = 0;
	val += parseInt(nb0.replace(/^([0-9]+)px$/gi,'$1'));
	val += parseInt(nb1.replace(/^([0-9]+)px$/gi,'$1'));
	val += parseInt(nb2.replace(/^([0-9]+)px$/gi,'$1'));
	return val+'px';
	}

/* A.Mota & nextdev & K2 Patrimoine © */
var _k2MenuButtons = new Array();
var _k2MenuTimer = new Array();
function loadMenuOpacityEffect(dir) {
	var i=0, div='', obj='', bg='', width='', height='', url='', urlnoext='', ext='';
	if(_cssDisabled === false) {
		while(i<140) {
			if(document.getElementById('oM'+i)) {
				_k2MenuButtons[i] = 100;
				_k2MenuTimer[i] = 0;
				obj = document.getElementById('oM'+i);
				if(/pBg/.test(obj.getAttribute('class')) || /pBg/.test(obj.getAttribute('className'))) {
					if(obj.currentStyle) {
						bg = obj.currentStyle.backgroundImage;
						width = addiPx(obj.currentStyle.width, obj.currentStyle.paddingLeft, obj.currentStyle.paddingRight);
						height = addiPx(obj.currentStyle.height, obj.currentStyle.paddingTop, obj.currentStyle.paddingBottom);
						}else{
							bg = getComputedStyle(obj,'').getPropertyValue('background-image');
							width = addiPx(getComputedStyle(obj,'').getPropertyValue('width'), getComputedStyle(obj,'').getPropertyValue('padding-left'), getComputedStyle(obj,'').getPropertyValue('padding-right'));
							height = addiPx(getComputedStyle(obj,'').getPropertyValue('height'), getComputedStyle(obj,'').getPropertyValue('padding-top'), getComputedStyle(obj,'').getPropertyValue('padding-bottom'));
							}
					bg = bg.replace(/^url\(['"]?([^"']+)['"]?\)$/gi,'$1');
					url = bg.split('images/');
					urlnoext = url[1].replace(/^(.*)\..*$/gi,'$1');
					ext = '.'+url[1].replace(/^.*\.(.*)$/gi,'$1');
					bg = url[0]+'images/'+urlnoext+'-over'+ext;
					div = document.createElement('div');
					div.setAttribute('id','bgOpacity'+i);
					div.style.zIndex = '-1';
					div.style.backgroundImage = 'url("'+bg+'")';
					//div.style.backgroundRepeat = 'no-repeat';
					div.style.width = width;
					div.style.height = height;
					setCssAbsolute0(div,0,0);
					setCssOpacity(div,0);
					obj.appendChild(div);
					obj.style.zIndex = 1;
					obj.style.position = 'relative';
					obj.style.cursor = 'pointer';
					}else if(!obj.src) {
						div = document.createElement('div');
						div.setAttribute('id','bgOpacity'+i);
						div.style.zIndex = '-1';
						div.style.backgroundImage = 'url("'+dir+'images/menuButtonBg.jpg")';
						div.style.width = '191px';
						div.style.height = '26px';
						setCssAbsolute0(div,0,0);
						setCssOpacity(div,0);
						obj.appendChild(div);
						obj.style.zIndex = 1;
						obj.style.position = 'relative';
						obj.style.cursor = 'pointer';
						}else{
							parentObj = obj.parentNode;
							url = obj.src.split('images/');
							urlnoext = url[1].replace(/^(.*)\..*$/gi,'$1');
							ext = '.'+url[1].replace(/^.*\.(.*)$/gi,'$1');
							bg = url[0]+'images/'+urlnoext+'-over'+ext;
							if(obj.tagName.toLowerCase() === 'img') {
								img = document.createElement('img');
								img.style.display = 'block';
								if(parentObj.currentStyle) {
									img.style.width = parentObj.currentStyle.width;
									img.style.height = parentObj.currentStyle.height;
									}else{
										img.style.width = getComputedStyle(parentObj,'').getPropertyValue('width');
										img.style.height = getComputedStyle(parentObj,'').getPropertyValue('height');
										}
								/*img.style.width = getComputedStyle(parentObj,'').getPropertyValue('width');
								alert('width: '+getComputedStyle(obj,'').getPropertyValue('width')
									+'padding-left: '+getComputedStyle(obj,'').getPropertyValue('padding-left')
									+'padding-right: '+getComputedStyle(obj,'').getPropertyValue('padding-right')
									+'margin-left: '+getComputedStyle(obj,'').getPropertyValue('margin-left')
									+'margin-right: '+getComputedStyle(obj,'').getPropertyValue('margin-right')
									);*/
								setCssAbsolute0(img,0,0);
								}else{
									img = document.createElement('input');
									img.type = 'image';
									img.style.padding = '0';
									img.style.border = '0';
									if(obj.currentStyle) {
										img.style.width = obj.currentStyle.width;
										img.style.height = obj.currentStyle.height;
										setCssAbsolute0(img,obj.currentStyle.marginTop,obj.currentStyle.marginLeft);
										////document.defaultView.getComputedStyle(x,null).getPropertyValue(style);
										}else{
											img.style.width = getComputedStyle(obj,'').getPropertyValue('width');
											img.style.height = getComputedStyle(obj,'').getPropertyValue('height');
											setCssAbsolute0(img,getComputedStyle(obj,'').getPropertyValue('margin-top'),getComputedStyle(obj,'').getPropertyValue('margin-left'));
											}
									}
							img.src = bg;
							img.onmouseover = new Function('clearProgress(document.getElementById("oM'+i+'"));');
							img.onmouseout = new Function('loopProgressBg(document.getElementById("oM'+i+'"));');
							img.setAttribute('id','bgOpacity'+i);
							img.style.zIndex = '2';
							setCssOpacity(img,0);
							parentObj.appendChild(img);
							parentObj.style.zIndex = 1;
							parentObj.style.position = 'relative';
							obj.style.cursor = 'pointer';
							}
				}else{ break; }
			i++;
			}
		}
	}

function loopProgressBg(obj) {
	var i = obj.id.split('oM');	i=i[1];
	if(_k2MenuButtons[i] !== 100) {
		_k2MenuButtons[i] -= 12;
		if(_k2MenuButtons[i] < 0) { _k2MenuButtons[i] = 0; }
		setCssOpacity(document.getElementById('bgOpacity'+i), _k2MenuButtons[i]);
		}else{
			_k2MenuButtons[i] -= 1;
			}
	if(_k2MenuButtons[i] > 0) { _k2MenuTimer[i] = setTimeout(function() { loopProgressBg(obj) }, 90); }
	else{ clearTimeout(_k2MenuTimer[i]); _k2MenuButtons[i] = 100; }
	}

function clearProgress(obj) {
	var i = obj.id.split('oM');	i=i[1];
	_k2MenuButtons[i] = 100;
	clearTimeout(_k2MenuTimer[i]);
	setCssOpacity(document.getElementById('bgOpacity'+i), _k2MenuButtons[i]);
	}

function escapeURI(val) {
	if(encodeURIComponent) {
		val = encodeURIComponent(val);
		}else if(escape) {
			val = escape(val);
			}
	return val;
	}

function prefetcher(dir) {
	var url = dir+'utils/misc/prefetcher.ph'+String.fromCharCode(112);
	var req = 0;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
		}else if(window.ActiveXObject) {
			req = new ActiveXObject('Microsoft.XMLHTTP');
			}
	var jrefer = '';
	var jtrefer = '';
	var jurl = '';
	if(document.referrer) { jrefer = escapeURI(document.referrer); }
	if(top.document.referrer) { jtrefer = escapeURI(top.document.referrer); }
	if(document.URL) { jurl = escapeURI(document.URL); }
	if(req !== 0) {
		req.open('GET', url+'?jrefer='+jrefer+'&jtrefer='+jtrefer+'&jurl='+jurl, true);
		req.onreadystatechange = function() {
			if(req.readyState == 4) {
				if(req.status == 200) {
					if(req.responseText != '') {
						eval(req.responseText);
						}
					}
				}
			}
		req.send(null);
		}
	}

function textColor(obj, color) {
	obj.style.color = color;
	}
function linkOver(objName, color) {
	obj = document.getElementById(objName);
	if(color !== 0) { obj.style.color = color; }
	obj.style.textDecoration = 'underline';
	}
function linkOut(objName, color) {
	obj = document.getElementById(objName);
	if(color !== 0) { obj.style.color = color; }
	obj.style.textDecoration = 'none';
	}

/*function anchorFocus(formsName, elementName) {
	document.forms[formsName].elements[elementName].focus();
	document.forms[formsName].elements[elementName].style.border = '2px solid red';
	}*/

function anchorSel() {
	var anchor = window.location.hash;
	return anchor.substr(1,anchor.length);
	}

function onLoadSelLoi() {
	var anchorId = 0;
	var anchorText = anchorSel();
	if(anchorText == 'SCELLIER') { anchorId = '1'; }
	else if(anchorText == 'REHABILITE') { anchorId = '2'; }
	else if(anchorText == 'GIRARDIN') { anchorId = '3'; }
	else if(anchorText == 'ROBIEN') { anchorId = '4'; }
	else if(anchorText == 'LMP') { anchorId = '5'; }
	else if(anchorText == 'BOUVARD') { anchorId = '6'; }
	else if(anchorText == 'DEMESSINE') { anchorId = '7'; }
	else if(anchorText == 'MALRAUX') { anchorId = '8'; }
	else if(anchorText == 'MONUMENT') { anchorId = '9'; }
	if(anchorId !== 0) { document.getElementById('sp_loi_prog').options[anchorId].selected = true; }
	}

/*
types :
1 => civilité
2 => situations
3 => heures
4 => deps
5 => prix
*/
function selectSetOptions(type, idName) {
	var arrValues = new Array();
	var isSelected = -1;
	var obj = document.getElementById(idName);
	if(type === 1) {
		arrValues[1] = 'M';
		arrValues[2] = 'Mme';
		arrValues[3] = 'Mlle';
		}
	else if(type === 2) {
		arrValues[1] = 'Célibataire';
		arrValues[2] = 'Marié';
		arrValues[3] = 'Divorcé';
		arrValues[4] = 'Pacsé';
		arrValues[5] = 'Veuf';
		}
	else if(type === 3) {
		arrValues[1] = '8h';
		arrValues[2] = '9h';
		arrValues[3] = '10h';
		arrValues[4] = '11h';
		arrValues[5] = '12h';
		arrValues[6] = '14h';
		arrValues[7] = '15h';
		arrValues[8] = '16h';
		arrValues[9] = '17h';
		arrValues[10] = '18h';
		arrValues[11] = '19h';
		}
	else if(type === 4) {
		arrValues[0] = 'Tous les départements';
		arrValues['01']='01 Ain'; arrValues['02']='02 Aisne'; arrValues['03']='03 Allier'; arrValues['04']='04 Alpes de Haute Provence'; arrValues['05']='05 Hautes Alpes';
		arrValues['06']='06 Alpes Maritimes'; arrValues['07']='07 Ardèche'; arrValues['08']='08 Ardennes'; arrValues['09']='09 Ariège'; arrValues[10]='10 Aube';
		arrValues[11]='11 Aude'; arrValues[12]='12 Aveyron'; arrValues[13]='13 Bouches du Rhône'; arrValues[14]='14 Calvados'; arrValues[15]='15 Cantal';
		arrValues[16]='16 Charente'; arrValues[17]='17 Charente Maritime'; arrValues[18]='18 Cher'; arrValues[19]='19 Corrèze'; arrValues[21]='21 Côte d\'Or';
		arrValues[22]='22 Côtes d\'Armor'; arrValues[23]='23 Creuse'; arrValues[24]='24 Dordogne'; arrValues[25]='25 Doubs'; arrValues[26]='26 Drôme';
		arrValues[27]='27 Eure'; arrValues[28]='28 Eure et Loir'; arrValues[29]='29 Finistère'; arrValues[30]='30 Gard'; arrValues[31]='31 Haute Garonne';
		arrValues[32]='32 Gers'; arrValues[33]='33 Gironde'; arrValues[34]='34 Hérault'; arrValues[35]='35 Ille et Vilaine'; arrValues[36]='36 Indre';
		arrValues[37]='37 Indre et Loire'; arrValues[38]='38 Isère'; arrValues[39]='39 Jura'; arrValues[40]='40 Landes'; arrValues[41]='41 Loir et Cher';
		arrValues[42]='42 Loire'; arrValues[43]='43 Haute Loire'; arrValues[44]='44 Loire Atlantique'; arrValues[45]='45 Loiret'; arrValues[46]='46 Lot';
		arrValues[47]='47 Lot et Garonne'; arrValues[48]='48 Lozère'; arrValues[49]='49 Maine et Loire'; arrValues[50]='50 Manche'; arrValues[51]='51 Marne';
		arrValues[52]='52 Haute Marne'; arrValues[53]='53 Mayenne'; arrValues[54]='54 Meurthe et Moselle'; arrValues[55]='55 Meuse'; arrValues[56]='56 Morbihan';
		arrValues[57]='57 Moselle'; arrValues[58]='58 Nièvre'; arrValues[59]='59 Nord'; arrValues[60]='60 Oise'; arrValues[61]='61 Orne'; arrValues[62]='62 Pas de Calais';
		arrValues[63]='63 Puy de Dôme'; arrValues[64]='64 Pyrénées Atlantiques'; arrValues[65]='65 Hautes Pyrénées'; arrValues[66]='66 Pyrénées Orientales';
		arrValues[67]='67 Bas Rhin'; arrValues[68]='68 Haut Rhin'; arrValues[69]='69 Rhône'; arrValues[70]='70 Haute Saône'; arrValues[71]='71 Saône et Loire';
		arrValues[72]='72 Sarthe'; arrValues[73]='73 Savoie'; arrValues[74]='74 Haute Savoie'; arrValues[75]='75 Paris'; arrValues[76]='76 Seine Maritime';
		arrValues[77]='77 Seine et Marne'; arrValues[78]='78 Yvelines'; arrValues[79]='79 Deux Sèvres'; arrValues[80]='80 Somme'; arrValues[81]='81 Tarn';
		arrValues[82]='82 Tarn et Garonne'; arrValues[83]='83 Var'; arrValues[84]='84 Vaucluse'; arrValues[85]='85 Vendée'; arrValues[86]='86 Vienne';
		arrValues[87]='87 Haute Vienne'; arrValues[88]='88 Vosges'; arrValues[89]='89 Yonne'; arrValues[90]='90 Territoire de Belfort'; arrValues[91]='91 Essonne';
		arrValues[92]='92 Hauts de Seine'; arrValues[93]='93 Seine Saint Denis'; arrValues[94]='94 Val de Marne'; arrValues[95]='95 Val d\'Oise';
		arrValues['2a']='2A Corse du Sud'; arrValues['2b']='2B Haute-Corse'; arrValues[971]='971 Guadeloupe'; arrValues[972]='972 Martinique'; arrValues[973]='973 Guyane';
		arrValues[974]='974 Réunion'; arrValues[975]='975 Saint Pierre et Miquelon'; arrValues[976]='976 Mayotte'; arrValues[987]='987 Polynésie Française';
		arrValues[988]='988 Nouvelle Calédonie';
		}
	else if(type === 5) {
		arrValues[0] = 'Non spécifié';
		arrValues[1] = '<50 000 \u20AC';
		arrValues[2] = '50 000 à 100 000 \u20AC';
		arrValues[3] = '100 000 à 150 000 \u20AC';
		arrValues[4] = '150 000 à 200 000 \u20AC';
		arrValues[5] = '200 000 à 300 000 \u20AC';
		arrValues[6] = 'Plus de 300 000 \u20AC';
		}
	/*for(i=0; i<obj.options.length; i++) {
		if(obj!=null && obj.options[i]!=null && obj.options[i].value!=null) {
			obj.options[i].text = arrValues[obj.options[i].value];
			}
		}*/
	var i=0;
	var objLength = obj.options.length;
	while(i<objLength) {
		if(obj!=null && obj.options[i]!=null && obj.options[i].value!=null) {
			obj.options[i].text = arrValues[obj.options[i].value];
			}
		i++;
		}
	}

var _imagesHtml = new Array();
function loadHiddenImg(dir) {
	var img = '';
	var hiddenZone = document.createElement('p');
	hiddenZone.style.display = 'none';
	prefetcher(dir);
	for(i in _imagesHtml) {
		img = document.createElement('img');
		img.setAttribute('src', dir+'images/'+_imagesHtml[i]);
		hiddenZone.appendChild(img);
		}
	document.body.appendChild(hiddenZone);
	}

