var popUpWin=0;function popUpWindow(URLStr, left, top, width, height){  if(popUpWin)  {    if(!popUpWin.closed) popUpWin.close();  }  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,  status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+  ',height='+height+',left='+left+', top='+top+',screenX='+left+',  screenY='+top+'');}	

function postwith (to,p) {
  var myForm = document.createElement("form");
  myForm.method="post" ;
  myForm.action = to ;
  for (var k in p) {
    var myInput = document.createElement("input") ;
    myInput.setAttribute("name", k) ;
    myInput.setAttribute("value", p[k]);
    myForm.appendChild(myInput) ;
  }
  document.body.appendChild(myForm) ;
  myForm.submit() ;
  document.body.removeChild(myForm) ;
}

function toggle_view(id) {
       var e = document.getElementById(id);
        if (e.style.display == 'block') 
	{
          e.style.display = 'none';
	}
	else
	{
	  e.style.display = 'block';
	}    
}


function on_visibility(id) {
       var e = document.getElementById(id);
          e.style.display = 'block';
    }

function off_visibility(id) {
       var e = document.getElementById(id);
       
          e.style.display = 'none';
    }



function removeAccents(strAccents){ 
    strAccents = strAccents.split(''); 
    strAccentsOut = new Array(); 
    strAccentsLen = strAccents.length; 
    var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž'; 
    var accentsOut = ['A','A','A','A','A','A','a','a','a','a','a','a','O','O','O','O','O','O','O','o','o','o','o','o','o','E','E','E','E','e','e','e','e','e','C','c','D','I','I','I','I','i','i','i','i','U','U','U','U','u','u','u','u','N','n','S','s','Y','y','y','Z','z']; 
    for (var y = 0; y < strAccentsLen; y++) { 
        if (accents.indexOf(strAccents[y]) != -1) { 
            strAccentsOut[y] = accentsOut[accents.indexOf(strAccents[y])]; 
        } 
        else 
            strAccentsOut[y] = strAccents[y]; 
    } 
    strAccentsOut = strAccentsOut.join(''); 
    return strAccentsOut; 
} 
			
					
					function CheckForm(form)
					{
						
						var buff = "";
						var errMsgOne = "S.V.P. fournir les informations suivantes: \n";		
						PrixAchat =  form.PrixAchat.value;
						MiseFond  =  form.MiseFond.value;
						if ( PrixAchat== "" || PrixAchat < 0 )
						{				
							buff += "\n- Prix d'achat";				
						}
						
						if ( MiseFond == "" || MiseFond< 0)
						{
							form.MiseFond.value = 0;				
						}
						
						if ( form.TauxInteret.value == ""  ||
							 form.TauxInteret.value >= 100 || 
							 form.TauxInteret.value <= 0 )
						{
							buff += "\n- Taux d'int&eacute;r&ecirc;ts";				
						}			
						
						if ( buff.length > 0 ) 
						{
							alert(errMsgOne + buff);
							return (false);
						}
						
						form.check.value = "OK";
						compute_amount(form);
						return (false);
					}
					
					function binomial(a, n)
					{
					  var i;
					  var sum, pow, term, cof;
						
					  sum = 1.0;
					  pow = n;
					  term = 1;
					  cof = 1.0;
					  for (i = 1; i< 10; i++ ) 
					  {
						cof  = cof * pow / i;
						pow  = pow - 1.0;
						term = term * a;
						sum  = sum + cof * term;
					  }
					
					  return sum;	  
					}
			
			
					function compute_amount(form)
					{	
						var P = eval ( form.PrixAchat.value );
						var	I = eval ( form.TauxInteret.value ) / 100.0;
						var	N = eval ( form.Periode.options[form.Periode.selectedIndex].value );
						var	D = eval ( form.MiseFond.value );
						var	Y = 12;
						var	M;
								
						//alert ( form.Periode.options[form.Periode.selectedIndex].value);
						if ( D != 0 )
						{
							P = P - D;
						}
			
						if ( ( P == 0 ) ||( I == 0 ) )
						{
							M = "0.00";
						}
						else 
						{				
							M = P * I / Y / (1.0 - 1 / binomial ( I / Y, N ) );				
						}			
						
						form.amount.value = "" + Math.round ( 100 * M ) / 100;
					}
			
				
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) 
{
  // the highlightStartTag and highlightEndTag parameters are optional
  if ((!highlightStartTag) || (!highlightEndTag)) {
    highlightStartTag = "<font style='color:blue; background-color:yellow;'>";
    highlightEndTag = "</font>";
  }
  
  // find all occurences of the search term in the given text,
  // and add some "highlight" tags to them (we're not using a
  // regular expression search, because we want to filter out
  // matches that occur within HTML tags and script blocks, so
  // we have to do a little extra validation)
  var newText = "";
  var i = -1;
  var lcSearchTerm = removeAccents(searchTerm.toLowerCase());
  var lcBodyText = removeAccents(bodyText.toLowerCase());
    
  

  while (bodyText.length > 0) {
    i = lcBodyText.indexOf(lcSearchTerm, i+1);
    if (i < 0) {
      newText += bodyText;
      bodyText = "";
    } else {
      // skip anything inside an HTML tag
      if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
        // skip anything inside a <script> block
        if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
          newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
          bodyText = bodyText.substr(i + searchTerm.length);
          lcBodyText = removeAccents(bodyText.toLowerCase());
          i = -1;
        }
      }
    }
  }
  
  return newText;
}
 
 
/*
 * This is sort of a wrapper function to the doHighlight function.
 * It takes the searchText that you pass, optionally splits it into
 * separate words, and transforms the text on the current web page.
 * Only the "searchText" parameter is required; all other parameters
 * are optional and can be omitted.
 */
function highlightSearchTerms(searchText, treatAsPhrase, warnOnFailure, highlightStartTag, highlightEndTag)
{
  // if the treatAsPhrase parameter is true, then we should search for 
  // the entire phrase that was entered; otherwise, we will split the
  // search string so that each word is searched for and highlighted
  // individually
  if (treatAsPhrase) {
    searchArray = [searchText];
  } else {
    searchArray = searchText.split(" ");
  }
  
  if (!document.body || typeof(document.body.innerHTML) == "undefined") {
    if (warnOnFailure) {
      alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");
    }
    return false;
  }
  
  var bodyText = document.body.innerHTML;
  for (var i = 0; i < searchArray.length; i++) {
    bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag);
  }
  
  document.body.innerHTML = bodyText;
  return true;
}
