var buffer_key="";
var locked=false;



function seek_key(obj,e){


    if (e==null){

        e=window.event;

    }

    buffer_key+=String.fromCharCode(e.keyCode).toLowerCase();
    
    for (i=0 ; i< obj.options.length; i++ ){
        
        if (obj.options[i].text.substr(0,buffer_key.length).toLowerCase()==buffer_key){
            
            if (obj.selectedIndex!=-1)
                obj.options[obj.selectedIndex].selected=false;            
            
            obj.options[i].selected=true;
            break;

        }

    }

    if (!locked){
        locked=true;
        window.setTimeout("clear_buffer()",2000);
    }

    return false;

}


function clear_buffer(){
    
    buffer_key="";

    locked=false;

} 

//----------------------- selectionner toutes les cases a cocher --//

var checkflag = "false";
function check(field) {
if (checkflag == "false") {
  for (i = 0; i < field.length; i++) {
  field[i].checked = true;}
  checkflag = "true";
  }
else {
  for (i = 0; i < field.length; i++) {
  field[i].checked = false; }
  checkflag = "false";
  }
}

function ajax(filename,datas,method, div_name, function_name){

    /*
    filename            = nom du fichier a atteindre sans le "?" 
    datas                    = parametres sous la forme : name_1=val_1&name_2=val_2& name_3=val_3.. etc 
    method                = "POST" | "GET"    (GET par defaut )
    div_name            =  nom d'un DIV qui recevra le retour de la requete AJAX 
    */

    asynchronous=true;

    if (method==null || method == "undefined"){
         method = "GET";
    }

    if (asynchronous==null || asynchronous == "undefined"){
         asynchronous = true;
    }


    var xhr_object = null; 
     
    if (window.XMLHttpRequest){
        // Firefox 
        xhr_object = new XMLHttpRequest(); 

    }else if(window.ActiveXObject){
        // Internet Explorer 
        xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 

    }else{ 
        // XMLHttpRequest non supporté par le navigateur 
        alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
        return; 
    }

    if (method == "GET" ){
        filename+="?"+datas;
        datas=null; 
    }else{
        // POST on ne fait rien 
    }

    xhr_object.open(method, filename, asynchronous); 

    if (function_name != null && function_name != "undefined"){

        xhr_object.onreadystatechange = function() { if (xhr_object.readyState == 4) {function_name(xhr_object.responseText);} };

    }else{

        xhr_object.onreadystatechange = function() { 
        
            if(xhr_object.readyState == 4) { 
                
                if (div_name!=null && div_name!="undefined"){
                
                    var elem = document.getElementById(div_name)
                    if ( elem ) {
                        elem.innerHTML = xhr_object.responseText;
                    }

                }else{

                    if (xhr_object.responseText!=""){
                    
                        eval(xhr_object.responseText);
                    
                    }

                }    

                    
            } 

        } 



    }


    if(method == "POST") 
        xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 

    xhr_object.send(datas); 

}




function clear_combo(id)
{
    var elem = document.getElementById(id);
    if ( elem )  {
        elem.options.length= 0;
        elem.options[0] = new Option ("Choisissez","");
    } 
}


function empty_combo(id){
    var elem = document.getElementById(id);
    if ( elem ) { 
        elem.options.length= 0;
    }

}


function wait_combo(id){
    var elem = document.getElementById(id);
    if ( elem ) {
        elem.options.length= 0;
        elem.options[0] = new Option ("Veuillez patienter ...","-");
    } 
}


function wait_field(id){
    var elem = document.getElementById(id);
    if ( elem ) {
        elem.value = "Veuillez patienter ...";
    }

}


function confirm_suppr_proposition(){

    return window.confirm("Etes-vous sur de vouloir effacer cette proposition ?");

}

function confirm_suppr_alert(){

    return window.confirm("Etes-vous sur de vouloir effacer cette alerte ?");

}

function confirm_suppr_contact(){

    return window.confirm("Etes-vous sur de vouloir effacer ce contact ?");

}


function confirm_suppr_salestask(){

    return window.confirm("Etes-vous sur de vouloir effacer cette action commerciale ?");

}

function inputenable(id,state)
{
 var divObj = null;
  if (document.getElementById) {
  divObj = document.getElementById(id);
 } else if(document.all) {
  divObj = document.all(id);
 } else if (document.layers) {
  divObj = document.layers[id];
 }
 if ( divObj ) {
     if ( window.event ) {
        divObj.readOnly = !state
     }
     else {
         if(state) {
          divObj.removeAttribute("readonly");
         } else {
          divObj.setAttribute("readonly","readonly");
         }
     }
 }
}


function toggle(id)
{
    var elem = document.getElementById(id)
    if ( elem ) {
        if ( elem.style.display == 'none' ) {
            elem.style.display = 'block'
        }
        else {
            elem.style.display = 'none'
        }
    }
}

function phoneCall(number)
{
    ajax('index.php','mod=cti&cmd=call&number=' + number, 'GET');
    return false;
}

function listenCall(to)
{
    ajax('index.php','page=empty&mod=cti&cmd=listen&to=' + to, 'GET');
    return false;
}

//----------------------- acceptation des conditions d'utilisations --//

function checkConditions(adresse) {
	if(document.getElementById('accept').checked == true) {
		window.location = adresse;
	} else {
		alert('Veuillez lire et accepter les conditions d\'utilisation du service avant de continuer.');	
	}
}

//debut----------------------- popUp de selection des fonds --

var newWin = null;
function closeWin(){
    if (newWin != null){
        if(!newWin.closed) {
            newWin.close();
        }
    }
}
function popUp(strURL,strType,strHeight,strWidth,popup_skandia) {
    closeWin();
    var newUrl = "";
    if (popup_skandia) {
       newUrl = strURL + "&decorator=false";
    } else {
       newUrl = strURL   + "?&decorator=false&mod=policy&cmd=ariAddFunds&operationType=ARI&fundID=&page=&categFilter=&isinFilter=&x=44&y=9";
    }
    var strOptions="";
    if (strType=="console") {
        strOptions="resizable,height="+strHeight+",width="+strWidth;
    }
    newWin = window.open(newUrl, 'newWin', strOptions);
    newWin.focus();
}
//fin----------------------- popUp de selection des fonds -

/*
// debut---------------------- openClosedD
function getE(id)
{
	if(document.getElementById) {
		return document.getElementById(id);
	} else if(document.all) {
		return document.all[id];
	} else return;
}


function openCloseD(id,mode){
	element = getE(id);
	
	if(element.style) {
		if(mode == 0) {
			if(element.style.display == 'block' ) {
				element.style.display = 'none';
			} else {
				element.style.display = 'block';
			}
		} else if(mode == 1) {
			element.style.display = 'block';
		} else if(mode == -1) {
			element.style.display = 'none';
		}
	}
}
// fin---------------------- openClosedD
*/




// Fonction print pour les pages comportant des onglets
var ongletcourant='tab1';

function PrintThisPageOnglet() { 
   var sOptionOnglet="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOptionOnglet+="scrollbars=yes,width=750,height=600,left=100,top=25"; 

   var sWinHTMLOnglet = document.getElementById(ongletcourant).innerHTML;
   
   var winprintOnglet=window.open("","",sOptionOnglet); 
       winprintOnglet.document.open(); 
       winprintOnglet.document.write('<html><link href=http://www.skandia.fr/institutionnel/stylesheet/site.css rel=stylesheet><body><table width=100% border=0 cellpadding=15 cellspacing=0 bgcolor=#FFFFFF><tr><td><img src=http://www.skandia.fr/institutionnel/images/skandia_mast_logo.gif><br />'); 
       winprintOnglet.document.write(sWinHTMLOnglet);          
       winprintOnglet.document.write('</td></tr></body></html>'); 
       winprintOnglet.document.close(); 
       winprintOnglet.focus(); 
       winprintOnglet.print(); 
}

function SetOngletCourant(onglet) {
	ongletcourant=onglet;
}

// Fonction print pour les pages ne comportant pas d'onglets
function PrintThisPage() { 
   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 
	   
	var sWinHTML = document.getElementById('main').innerHTML; 
	
	var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write('<html><link href=http://www.skandia.fr/institutionnel/stylesheet/site.css rel=stylesheet><body><table width=100% border=0 cellpadding=15 cellspacing=0 bgcolor=#FFFFFF><tr><td><img src=http://www.skandia.fr/institutionnel/images/skandia_mast_logo.gif><br /><br />'); 
       winprint.document.write(sWinHTML);          
       winprint.document.write('</td></tr></body></html>'); 
       winprint.document.close(); 
       winprint.focus(); 
       winprint.print(); 
}





var Form = {
    /**
     * check if keypress is a number
     */ 
    'onlyNumber': function (e)
    {
        var key;
        if ( window.event ) {
            key = window.event.keyCode;
        }
        else {
            key = e.which;
        }
        return (key < 32 || (key > 47 && key < 58 ));
    }
}

var AslForm = {
    /**
     * Calcul du total des allocation pour le formulaire de saisie des allocations cible
     */
    'updateTotal': function (support)
    {
        var totalField = document.getElementById('asl_totalSupports_' + support);
        
        var val = 0;
        for ( index in totalField.form.elements ) {
            var elem = totalField.form.elements[index];
            try {
                if (elem.type == 'text' && elem.name.indexOf('supports[' + support +']') == 0 && elem != totalField && elem.value) {
                    val += parseFloat(elem.value);
                }
            }
            catch (exception) {
            }
        }
        totalField.value = val;
        if ( val != 100 ) {
            totalField.style.color = 'red';
        }
        else {
            totalField.style.color = '';
        }
        return true;
    }
}

var AriForm = {
    /**
     * Calcul du total des allocation pour le formulaire de saisie des allocations cible
     */
    'updateTotal': function ()
    {
        var totalField = document.getElementById('ari_totalSupports');
        
        var val = 0;
        for ( index in totalField.form.elements ) {
            var elem = totalField.form.elements[index];
            try {
                if (elem.type == 'text' && elem.name.indexOf('supports[') == 0 && elem != totalField && elem.value) {
                    val += parseFloat(elem.value);
                }
            }
            catch (exception) {
            }
        }
        totalField.value = val;
        if ( val != 100 ) {
            totalField.style.color = 'red';
        }
        else {
            totalField.style.color = '';
        }
        return true;
    }
}

function detailsArbitrage(laCondition) {
	var nava = (document.layers);
	var dom = (document.getElementById);
	var iex = (document.all);
	
	if (nava) { details = document.details_1 }
	else if (dom) { details = document.getElementById("details_1").style }
	else if (iex) { details = details_1.style;}
	
	if (laCondition=="1") {
		details.display = "block";
		details.top = 220;
		details.left = 800;
	} else {
		details.display= "none";	
	}
}

function MM_jumpMenu(targ,selObj,restore) { //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function ageFromBirthday(id, birthday, currentDate) {

	var elt = document.getElementById(id);
	
	if (elt) {
	
		var bithDoy = birthday.split('/');
		var currentDoy = currentDate.split('/');
		// now d is the array ['31','01','2000'] 
		var today = new Date(currentDoy[2], currentDoy[1]-1, currentDoy[0]);
		// The year, month, and day of the variable today
		// are 2006, 1, and 1, respectively.
		// Remember, I am a JavaScript interpreter.
		var bday = new Date(bithDoy[2], bithDoy[1]-1, bithDoy[0]);
		// The year of bday is 2000.
		// The month of bday would be 1 (remember, to me, 1 is February)
		// except that the given date (31) is too large for February
		// so we go into March -- the 2nd day of March, to be exact.
		// To me, March is month 2.
		// So, the month and day of bday are 2 and 2, respectively. 
		var by = bday.getFullYear(); // this is 2000. 
		var bm = bday.getMonth(); // this is 1 (because 2-1=1)
		var bd = bday.getDate(); // this is 2
		var age = 0;
		var dif = bday; 

		while (dif <= today) { 

			var dif = new Date(by+age, bm, bd); 
			age++; 
		}

		// so you loop with the 2nd of February as the date of birth!!
		age += -2; 
		// what is the above line supposed to do?
		elt.innerHTML = age + ' ans';
	}
}