//Fonctions relatives au site
function goConfirm()   {
	if(confirm('Are you sure?') == true)
			   {
		return true;
				}
				else
				{
		return false;
				}
}

function wait()   {
    document.getElementById('attente').style.visibility='visible';
    document.getElementById('attente').style.display='block';
	document.getElementById('attente').style.width='900px';
	document.getElementById('attente').style.height='200px';
	document.getElementById('form').style.visibility='hidden';
    document.getElementById('form').style.display='none';
	document.getElementById('tete').style.visibility='hidden';
    document.getElementById('tete').style.display='none';
  }  

function afficheId(baliseId)   {
  if (document.getElementById && document.getElementById(baliseId) != null)   {
    document.getElementById(baliseId).style.visibility='visible';
    document.getElementById(baliseId).style.display='block';
    }
  }

function cacheId(baliseId)   {
  if (document.getElementById && document.getElementById(baliseId) != null)   {
    document.getElementById(baliseId).style.visibility='hidden';
    document.getElementById(baliseId).style.display='none';
    }
  }

  function redId(baliseId)   {
  if (document.getElementById && document.getElementById(baliseId) != null)   {
    document.getElementById(baliseId).style.height='15px';
    document.getElementById(baliseId).style.display='block';
    }
  }

function popuprez(url)    {
 newwin=window.open(url,'windowname4');
 if (window.focus) {newwin.focus()}
 return false;
}

function popupbis(url,w,h)    {
 params  = 'width='+w;
 params += ', height='+h;
 params += ', top=0, left=0'
 params += ', fullscreen=no';

 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

function fad_in(id, opacity){
afficheId(id);
	opacity = (!opacity ? 0 : opacity)+10;
	var item = document.getElementById(id).style;
	item.opacity = (opacity/100);
	item.filter = 'alpha(opacity='+opacity+')'; 
	
	if(opacity < 100){
		var time = 50;
		setTimeout('fad_in(\''+id+'\', '+opacity+')', time);
	}
}

function fad_out(id, opacity){
	opacity = (!opacity ? 100 : opacity)-10;
	var item = document.getElementById(id).style;
	item.opacity = (opacity/100);
	item.filter = 'alpha(opacity='+opacity+')'; 
	
	if(opacity > 0){
		var time = 30;
		setTimeout('fad_out(\''+id+'\', '+opacity+')', time);
	}
	if(opacity <= 0){
		cacheId(id);
	}
}

function submitform()   {
  document.widget.submit();
}

function refreshsettings(timeoutPeriod) {
	setTimeout("location.href = 'settings';",timeoutPeriod);
}

function check_pwd_strengh(div) {
	var strength = document.getElementById(div);
	var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
	var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
	var enoughRegex = new RegExp("(?=.{6,}).*", "g");
	var pwd = document.getElementById("npass1");
	if (pwd.value.length==0) {
	strength.innerHTML = 'Type Password';
	} else if (false == enoughRegex.test(pwd.value)) {
	strength.innerHTML = '6 Characters minimum';
	} else if (mediumRegex.test(pwd.value)) {
	strength.innerHTML = '<span style="color:green">Strong!</span>';
	} else {
	strength.innerHTML = '<span style="color:red">Weak!</span>';
	}
}

function verify_2pass(pass1,pass2,div_result)	{
	if ($F(pass1) == $F(pass2) )	{
		$(div_result).innerHTML = '<img src="images/icons/valid.png">';
	}

	else	{
		$(div_result).innerHTML = '<img src="images/icons/error.png">';
	}
}