window.name = 'TuniemploWindow';

// navigator detection
WIN = (navigator.appVersion.indexOf("Windows")!=-1);
MAC = (navigator.appVersion.indexOf("Machintosh")!=-1);
OTH = !WIN && !MAC;
VER = getVersion();

OPERA = (navigator.userAgent.indexOf("Opera") != -1);
GECKO = (navigator.userAgent.indexOf("Gecko") != -1);
MSIE = (navigator.userAgent.indexOf("MSIE") != -1) && WIN && !OPERA;
IE4 = (navigator.appName=='Microsoft Internet Explorer') && (VER>=4) && !OPERA;
IE6 = IE4 && (navigator.appVersion.indexOf("MSIE 6") != -1) && WIN;
IE5 = (IE4 && (navigator.appVersion.indexOf("MSIE 5") != -1) && WIN) || IE6;
NS6 = !GECKO && (navigator.appName=='Netscape') && (VER>=5);
NS4 = !NS6 && (navigator.appName=='Netscape') && (VER>=4);
IE4 = IE4 && !IE5 && !IE6;
KON = (navigator.userAgent.indexOf("Konqueror") != -1);

showRow = (navigator.appName.indexOf('Internet Explorer') != -1) ? 'block' : 'table-row';

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function getVersion() {
	var ua = navigator.userAgent;
	var vs = ua.substring(ua.indexOf(')') + 1);
	var va = vs.split(' ');

	for (var i = va.length - 1; i >= 0; --i) {
		if (parseFloat(va[i]) > 0) {
			return parseFloat(va[i]);
		} else {
			var sp = va[i].split('/');
			for (var s = sp.length - 1; s >= 0; --s) {
				if (parseFloat(sp[s]) > 0) {
					return parseFloat(sp[s]);
				}
			}
		}
	}

	va = ua.split(' ');
	for (var i = 0; i < va.length; i++)
		if (parseFloat(va[i]) > 0)
			return parseFloat(va[i]);
	
	return 0;
}


function hidelayer(nom) {

	if(document.all){document.all(nom).style.visibility="hidden";}

	else if(document.getElementById){document.getElementById(nom).style.visibility="hidden";}

	else if(document.layers){document.layers[nom].visibility="hide";}

}

function showlayer(nom) {

	if(document.all){
		document.all(nom).style.visibility="visible";
	}

	else if(document.getElementById){
		document.getElementById(nom).style.visibility="visible";
	}

	else if(document.layers){
		document.layers[nom].visibility="show";
	}

}

function Hide_Show(Row){
	var objRow = document.getElementById(Row);
	objRow.style.display = (objRow.style.display == 'none')?showRow:'none';
}

//DELETE CONFIRMATION//
function Confirm_Delete(message){
	if (confirm(message)) { 
		delete_record = true;
	} else {  
		delete_record = false;
	} return delete_record;
}

//LIMITS THE MAX CHARACTERS IN A TEXTAREA INPUT//
function textCounter(input, countid, maxlimit) {
	var maxLimit = (maxlimit) ? maxlimit : 2000;
	var counter = document.getElementById(countid);
	if(input.value.length > maxLimit) {
		counter.innerHTML = input.value.length + ' of ' + maxLimit + ' caratères! SVP éditez le texte.';
	} else {
		counter.innerHTML = input.value.length + ' of ' + maxLimit + ' caratères autorizés.';
	}
}

//OPENS NEW WINDOW//
function newWin(url,size) {
	if (size == "s"){ var width = 300; var height = 300 }
	else if (size == "m"){ var width = 550; var height = 475 }
	else { var width = 700; var height = 500 }

	var left = Math.floor( (screen.width - width) / 2);
	var top = Math.floor( (screen.height - height) / 2);
	var winParms = ",top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
	if (parseInt(navigator.appVersion) >= 4) { window.focus(); }
	window.open(url,"","scrollbars=1,resizable=1" + winParms)
}

//Multiple select//
function updateSelectChoices(parentForm, indiffChkId, selectInput, libId, n){
	var checkstr = "";
	for(i=1;i<=n;i++){
		if (document.getElementById(libId+i).checked) {checkstr += document.getElementById(libId+i).value + "_";}
	}
	checkstr = checkstr.substring(0,checkstr.length-1);
	eval("document." + parentForm + "." + selectInput + ".value = checkstr ;");
	document.getElementById(indiffChkId).checked = (checkstr == "");
}
function unCheckChoices(parentForm, indiffChkId, selectInput, libId, n){
	for(i=1;i<=n;i++){
		document.getElementById(libId+i).checked = "";
	}
	eval("document." + parentForm + "." + selectInput + ".value = '' ;");
	document.getElementById(indiffChkId).checked = true;
}
function updateSelectAllChoices(parentForm, AllChkId, selectInput, libId, n){
	var checkstr = "";
	for(i=1;i<=n;i++){
		if (document.getElementById(libId+i).checked) {checkstr += document.getElementById(libId+i).value + "_";}
	}
	checkstr = checkstr.substring(0,checkstr.length-1);
	eval("document." + parentForm + "." + selectInput + ".value = checkstr ;");
	document.getElementById(AllChkId).checked = "";
}
function CheckAllChoices(parentForm, allChkId, selectInput, libId, n){
	var checkstr = "";
	for(i=1;i<=n;i++){
		document.getElementById(libId+i).checked = true;
		checkstr += document.getElementById(libId+i).value + "_";
	}
	checkstr = checkstr.substring(0,checkstr.length-1);
	eval("document." + parentForm + "." + selectInput + ".value = checkstr ;");
	document.getElementById(allChkId).checked = true;
}

/*
function ShowChoices(div){
	if(document.getElementById(div).style.display=='block'){
		document.getElementById(div).style.display='none';
		document.getElementById(div + '_puce').style.backgroundImage='url(../images/puce-down.png)';
	}else{
		document.getElementById(div).style.position='absolute';
		document.getElementById(div).style.display='block';
		document.getElementById(div + '_puce').style.backgroundImage='url(../images/puce-up.png)';
	}
}
function updateChoices(isChecked, indiffCheck, grp, n){
	if(isChecked){		
		if(indiffCheck!='') document.getElementById(indiffCheck).checked="";
	}else{
		if(indiffCheck!=''){
			doCheck=true;
			i=1;
			while(i<=n && doCheck==true){
				doCheck = (document.getElementById(grp+i).checked) ? false : true;
				i++;
			}
			document.getElementById(indiffCheck).checked=doCheck;
		}
	}
}
*/

/* Menu */
function montre(id) {
if (document.getElementById) {
document.getElementById(id).style.display="block";
} else if (document.all) {
document.all[id].style.display="block";
} else if (document.layers) {
document.layers[id].display="block";
}
}

function cache(id) {
if (document.getElementById) {
document.getElementById(id).style.display="none";
} else if (document.all) {
document.all[id].style.display="none";
} else if (document.layers) {
document.layers[id].display="none";
}
}
/*Update States Select*/
function updateStatesSelect(selectId, countryId, defaultHTML){
	if(typeof(statesArray[countryId]) == "undefined"){
		document.getElementById(selectId).innerHTML=defaultHTML;
		/*document.getElementById(selectId).disabled=true;*/
	}else{
		/*document.getElementById(selectId).disabled=false;*/
		document.getElementById(selectId).innerHTML=statesArray[countryId];
	}
}
