/* ::::::::::::::::::::::::::::::::::::::::::
   ::::::::::::::::::::::::::::::::::::::::::
   GESTION DU POPUP IMPORT CONTACT
   ::::::::::::::::::::::::::::::::::::::::::
   ::::::::::::::::::::::::::::::::::::::::::
*/

var xmlhttp=false;

try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}


if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	xmlhttp = new XMLHttpRequest();
}

function import_contact(account){
	document.forms['import_contact_form'].mail_import.value = '';
	document.forms['import_contact_form'].pass_import.value = '';
	if(account == 'hotmail'){
		document.forms['import_contact_form'].type_account.value = 'hotmail';
		document.getElementById("title_mail_count").className='hotmail';
		document.getElementById("account_name_2").innerHTML=MISC_IMPORT_CONTACT_EX+' : pseudo@hotmail.com';
		document.getElementById("account_name_3").innerHTML='Hotmail';
		document.getElementById("account_name_4").innerHTML='Hotmail';
	}
		if(account == 'yahoo'){
		document.forms['import_contact_form'].type_account.value = 'yahoo';
		document.getElementById("title_mail_count").className='yahoo';
		document.getElementById("account_name_2").innerHTML=MISC_IMPORT_CONTACT_EX+' : pseudo@yahoo.com';
		document.getElementById("account_name_3").innerHTML='Yahoo!';
		document.getElementById("account_name_4").innerHTML='Yahoo!';
	}
		if(account == 'aol'){
		document.forms['import_contact_form'].type_account.value = 'aol';
		document.getElementById("title_mail_count").className='aol';
		document.getElementById("account_name_2").innerHTML=MISC_IMPORT_CONTACT_EX+' : pseudo@aol.com';
		document.getElementById("account_name_3").innerHTML='AOL';
		document.getElementById("account_name_4").innerHTML='AOL';
	}
		if(account == 'gmail'){
		document.forms['import_contact_form'].type_account.value = 'gmail';
		document.getElementById("title_mail_count").className='gmail';
		document.getElementById("account_name_2").innerHTML=MISC_IMPORT_CONTACT_EX+' : pseudo@gmail.com';
		document.getElementById("account_name_3").innerHTML='Gmail';
		document.getElementById("account_name_4").innerHTML='Gmail';
	}
	HidePage('my_contact_box');
	}
	
	//import
	function member_import(){
		var mail_import = document.getElementById("mail_import").value;
		var pass_import = document.getElementById("pass_import").value;
		var lib			= document.getElementById("type_account").value;
		var params = "do_action=member_import&mail_import="+mail_import+"&pass_import="+pass_import+"&lib="+lib;
		var myform = document.getElementById("infos_import").innerHTML;
		document.getElementById("infos_import").innerHTML="<h4><br>"+MISC_IMPORT_CONTACT_LOADING+"</h4><center><img src=\"../skins/img/ajax-loader.gif\" vspace=\"10\" /></center>";
		xmlhttp.open("POST", "member_process.php", true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", params.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange = function() {		
		
		
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				if (xmlhttp.responseText == 1){
					window.location.replace("import_contact_list.php");
				}else{
					document.getElementById("infos_import").innerHTML=myform;
					document.forms['import_contact_form'].type_account.value=lib;
					ShowBubble(MISC_INFOS_CONTACT_ERROR);
				}
			}
		}
		xmlhttp.send(params);
		
	}

/* ::::::::::::::::::::::::::::::::::::::::::
   ::::::::::::::::::::::::::::::::::::::::::
   SELECTION DE CONTACT
   ::::::::::::::::::::::::::::::::::::::::::
   ::::::::::::::::::::::::::::::::::::::::::
*/
var array_contact= new Array();
function infos_contact(mail){
	this.mail = mail;
}


var array_contact_selected= new Array();


function selectContact(index){
		
	document.getElementById('contact[]').value='';
	//selection
	if(document.getElementById("contact_"+index).className==""){
		document.getElementById("contact_"+index).className="contact_selected";
		//on remplie un tableau
		array_contact_selected.push(array_contact[index].mail);
		}
	//deselection
	else{
		document.getElementById("contact_"+index).className="";
		var new_array_contact_selected= new Array();
		for(i=0; i<array_contact_selected.length;i++){
			if(array_contact_selected[i]!=array_contact[index].mail){
				new_array_contact_selected.push(array_contact_selected[i]);
				}
			}
		array_contact_selected=new_array_contact_selected;

		}
		for(i=0; i<=array_contact_selected.length;i++){
			document.getElementById('contact[]').value=array_contact_selected;
			}

}
function SelectAllContact(){
	//rinitialisation du tableau
	array_contact_selected=new Array();
	document.getElementById('contact[]').value='';
	//on selectionne tout
	if(document.getElementById("select_all").className==""){
		document.getElementById("select_all").className="contact_selected";
		for(i=0; i<array_contact.length;i++){
			document.getElementById("contact_"+i).className="contact_selected";
			array_contact_selected.push(array_contact[i].mail);
			}
		
				
		for(i=0; i<=array_contact_selected.length;i++){
			document.getElementById('contact[]').value=array_contact_selected;
			}
	}
	//on deselectionne tout
	else{
		document.getElementById("select_all").className="";
		for(i=0; i<array_contact.length;i++){
			document.getElementById("contact_"+i).className="";
			
			}
		}

	}

function Submit_select_contact(){
	if(array_contact_selected.length != 0){
		document.forms['contact_list_form'].submit();
	}else{
		Alerte(MISC_TITLE_CONTACT, MISC_ALERTE_CONTACT);
	}
}



