//use this function if you want to close the pop up
//when the window looses focus....this means that another
//window receives focus and calls "closePopUp"
//returns the current scroll position of a page
function getScrollVal(){
   	if(navigator.appName.indexOf("Explorer") > -1){
		return document.body.scrollTop;
		}else{ //Netscape, Mozilla
		return window.pageYOffset;
	}
}

function setScrollVal(theForm){
		theForm.xxxScrollVal.value = getScrollVal();
}

//called when pages is loaded
function doScroll(val){
	if(navigator.appName.indexOf("Explorer") > -1){
 		document.body.scrollTop = val;
		}else{ //Netscape
 		window.scrollBy(0,val);
	}
}

//fonction qui change la valeur d'un champ texte a partir d'une liste de selection
function setSelValue(selList,fieldName){
	document.forms[0].elements[fieldName].value = selList[selList.selectedIndex].value;
}

function action(page,action,id,varName,varValue){
	var doIt = false;
	var theVar = '';
	var amount = 0;
	var amountString = '';
	
	if(action == 'delete'){
		if(confirm("Voulez-vous vraiment EFFACER l'entrée n° "+id+"?\nCette action est irreversible!") == true){
			doIt = true;
		}
	}else if(action == 'NoDelete'){
		alert("Veuillez supprimer les traductions de cette news avant.");
	}else if(action == 'NoAddTraduc'){
		alert("Cette news est déjà traduite dans toutes les langues.");
	}else{
		doIt = true;
	}
	
	
	if(varName != ''){
		theVar = "&"+varName+"="+varValue;
	}
	
	if(action != ''){
		action = 'action='+action+"&";
	}
	
	if(doIt){
		document.location = page+"?"+action+"id="+id+"&scrollValList="+getScrollVal()+theVar+amountString;
	}
}

function submitForm(theForm){
	theForm.scrollValList.value = getScrollVal();
	theForm.submit();
}

function checkfield(theForm){ 
	//sorting out required fields
	for(x = 0; x < requiredFields.length; x++){
		if(theForm.elements[requiredFields[x]]){
			theElement = theForm.elements[requiredFields[x]];
				//getting the type of element
			if(theElement.type == 'select-one'){ //selection list one value
				if(theElement.options[theElement.selectedIndex].value.length == 0){
					theElement.focus();
					alert(standardMsg);
					return false;
				}
			}else if(theElement.type =='select-multiple'){ //selection list multiple values
				//alert('Required: '+theElement.name+' option selected: '+theElement.selectedIndex);
				if(theElement.selectedIndex == -1){
					theElement.focus();
					alert(standardMsg);
					return false;
				}
			}else if(theElement.type == 'text' || theElement.type == 'password' || theElement.type == 'textarea' || theElement.type == 'file'){ //text
				//alert(theElement.name+": "+theElement.value.length);
				if(theElement.value.length == 0){
					theElement.focus();
					alert(standardMsg);
					return false;
				}
			}else if(theElement.type == 'checkbox'){
				//alert(theElement.name+": "+theElement.value.length);
				if(theElement.checked != true){
					theElement.focus();
					alert(standardMsg);
					return false;
				}
			}else if(theElement[0].type == 'radio'){
				//alert(theElement.name+": "+theElement.value.length);
				radioChecked = false;
				for(z = 0; z < theElement.length; z++){
					if(theElement[z].checked == true){
						radioChecked = true;
						break;
					}
				}
				if(!radioChecked){
					theElement[0].focus();
					alert(standardMsg);
					return false;
				}
			}
		}
	}
 	return true;
} // end checkfield()

function preCheckfield(theForm){
	if(theForm.elements['pass'].value.length < 6){
		alert('Le mot de passe contient moins que 6 caractères!');
		return false;
	}else{
		return checkfield(theForm);
	}
}

function deleteFile(page,id,file,fieldName){
	if(confirm('Do you really want to delete this file?\nThis action is irreversible!') == true){
		document.location = page+"?xxxAction=deleteFile&xxxId="+id+"&file="+file+"&fieldName="+fieldName+"&xxxTable="+xxxTable;
	}
}
