var cmimport = {
	
	list:null, qryCache:new Array(), lastQry:null, fcount:0, 
	cm_mail: null, cm_pass: null, container_fehler:null, box_error: null, box_login: null, box_loader:null, box_contacts:null, box_sucess:null,
	
	GetContacts: function(){
		
		fcount=0;
		
		var box_error = nz.get('box_error'); box_error.style.display = 'none';
		
		var box_login = nz.get('box_login'); box_login.style.display = 'none';
		var box_loader = nz.get('box_loader'); box_loader.style.display = 'block';
		var box_contacts = nz.get('box_contacts'); box_contacts.style.display = 'none';
		var box_sucess = nz.get('box_sucess'); box_sucess.style.display = 'none';
		
		var cm_mail = nz.get('_mail'); var cm_pass = nz.get('_pass');
		
		cont = {"s":"contactImport","m":cm_mail.value,"p":cm_pass.value};
		
		$.get('/tools/', cont, cmimport.listContacts );
		
	},
	
	listContacts: function(data){
		
		data = eval('(' + data + ')'); 
		
		var container_fehler = nz.get('fehler_message'); 
		var box_error = nz.get('box_error'); 
		var box_login = nz.get('box_login'); 
		var box_loader = nz.get('box_loader');
		var box_contacts = nz.get('box_contacts');
		
		cmimport.list = nz.get('_contactlist'); 
		
		if (data.result==true) {
			
			box_error.style.display = 'none';
			box_loader.style.display = 'none';
			
			box_contacts.style.display = 'block';
			
			if( data.contactlist ) 
			{ 
				var res = data.contactlist; 
				
				for( x in res ) { obj = res[x]; l = cmimport.crListEl( obj ); cmimport.list.appendChild( l ); }
				
				var box_sucess = nz.get('box_sucess');  var span_sucess = nz.get('span_sucess');
				span_sucess.innerHTML = data.anzahl; box_sucess.style.display = 'block';
			} 
			
		}
		else if(data.result==2) {
			
			box_error.style.display = 'block'; box_login.style.display = 'block'; box_loader.style.display = 'none';
			container_fehler.innerHTML = 'Dieser Email-Dienst wird nicht unterstützt';
			
		}
		else if(data.result==3) {
			box_error.style.display = 'block'; box_login.style.display = 'block'; box_loader.style.display = 'none';
			container_fehler.innerHTML = 'Bitte geben Sie die Email-Adresse und Passwort Ihres Emailkontos an.';
			
		}
		else if(data.result==4) {
			box_error.style.display = 'block'; box_login.style.display = 'block'; box_loader.style.display = 'none';
			container_fehler.innerHTML = 'Bitte überprüfen Sie Ihre Emailadresse.';
			
		}
		else
		{
			box_contacts.style.display = 'block';
			box_error.style.display = 'none'; box_login.style.display = 'none'; box_loader.style.display = 'none';
			l = cmimport.crListEe(); cmimport.list.appendChild( l );
		}
	},
	
	crListEl:function( obj ){
	
		l = nz.cr('div');
		l.innerHTML += '<table class="liste_freunde" bgcolor="#ffffff" width="100%" cellspacing="0" cellpadding="5" border="0" style="border-bottom: 1px solid #ADC3CD;"><tr><td width="10"><input type="checkbox" name="mid[]" id="mid" value="' + obj.email + '"></td><td width="50%">' + obj.name + '</td><td>'+ obj.email + '</td></tr></table>';
		return l; 
	},
	
	crListEe:function(){
		l = nz.cr('div'); 
		l.innerHTML += '<br><center><strong>Es konnten keine Kontakte geladen werden</strong></center><br>';
		return l; 
	},
	
	ImportAll:function(){
	
		cmimport.MarkAll(true);
		return 1;
	},
	
	MarkAll:function(status){
		var ind; var ic=0; var msglist = document.fo1.elements['mid']; 
		if (msglist) { ind=msglist.length; if (ic < ind) { while (ic < ind) { if(msglist[ic]!="") msglist[ic].checked=status; else continue; ic++; } } else { msglist.checked=status; }}
		return 1;	
	}

	
}
