function linkPage(link_id, typeRequest) {
	if (!MyVCFApp.Link) {
		MyVCFApp.Link = new MyVCFApp.LinkObj({}) ;
		MyVCFApp.setView(MyVCFApp.Link, $("#div_main_link")) ;
	} else {
	}
	MyVCFApp.initPage('div_main_link', 0) ;
	MyVCFApp.Link.link(link_id, typeRequest) ;
}

MyVCFApp.LinkObj = $.inherit(MyVCFApp.View, {
	scope: this,
	_initView: function() {
		this.idUser = MyVCFApp.Utils.nextId() ;
	},
	_generate: function() {
		var txt = "" ;
		txt += "<h1><span id='span_link_h1'>"+i18n.ask_exchange+"</span></h1>" ;

		txt += "<div style='padding:0 0 10px 0;'>"+i18n.list_all_contacts+"</div>" ;

		txt += "<div class='frameGray'>" ;
		txt += "<div class='special' style='background-color:red; color:white; padding:3px 10px; margin-bottom:10px;' id='div_link_confirmation'><input type='checkbox' value='1' name='input_link_confirmation' id='input_link_confirmation' /><label for='input_link_confirmation'>"+i18n.i_know_this_person+" (<a href='javascript:void(0);' onclick='MyVCFApp.Link.whyKnow();' style='color:white;'>"+i18n.why+"</a>)</label></div>" ;
		txt += "<div class='special' style='float:left; width:270px;' id='div_link_card_contact'></div>" ;
		txt += "<div style='float:left; width:200px;'><div class='red' style='float:left; font-size:20px; width:148px; padding:40px 0 0 0;'>"+i18n.and_exchange_cards+"</div><div style='float:left; width:52px;'><img src='/statics/images/big-arrow.png' alt='' /></div><div class='clear'></div></div>" ;
		txt += "<div style='float:left; width:280px;'>" ;
		txt += "<div id='div_link_card_my'></div>" ;
		txt += "<div id='div_link_card_my_button'></div>" ;
		txt += "<div id='div_link_card_my_buttonblacklist' style='padding:10px 0 0 0;'><a href='javascript:void(0);' onclick=\"MyVCFApp.Link.blackList();\">"+i18n.blacklist_go+"</a></div>" ;
		txt += "</div>" ;
		txt += "<div class='clear'></div>" ;
		txt += "</div>" ;
		//txt += "<div style='height:300px;'></div>" ;
		return txt ;
	},
	blackList: function() {
		MyVCFApp.blackList(this.link_id) ;
	},
	_onRender: function() {
		var bt = new MyVCFApp.Button({
			text: i18n.save,
			scope: this,
			onClick: function(evt) {
				if (this.typeRequest==0 && !$('#input_link_confirmation').is(':checked')) {
					MyVCFApp.Alert.show(i18n.confirm_know_explain) ;
					return false ;
				}
				var tabCardsIds = [] ;
				$('.cb_link_mycards_:checked').each(function() {
					tabCardsIds.push(this.id.substring(16)) ;
				}) ;
				log('tabCardsIds',tabCardsIds) ;
				if (this.typeRequest==0 && tabCardsIds.length==0) {
					MyVCFApp.Alert.show(i18n.please_select_one_card) ;
					return false ;
				}
				$.ajax({
					type: 'POST',
					url: 'io.php',
					data: {action:'saveLink', link_id:this.link_id, typeRequest:this.typeRequest, tabCardsIds:tabCardsIds},
					context: this,
					dataType: 'json',
					success: function(data) {
						welcomePage();
					}
				});
			}
		}) ;
		bt.render($('#div_link_card_my_button')) ;
		
	},
	whyKnow: function() {
		MyVCFApp.Alert.show(i18n.why_confirm_explain) ;
	},
	//type=0 : une nouvelle demande
	//type=1 : une demande que j'ai fait
	//type=2 : une demande que l'on m'a fait
	link: function(link_id, typeRequest) {
		this.link_id = link_id ;
		this.typeRequest = typeRequest ;
		if (this.typeRequest==0) {
			$("#span_link_h1").html(i18n.do_a_request) ;
			$('#div_link_card_my_button').show() ;
			$('#div_link_card_my_buttonblacklist').hide() ;
			$('#div_link_confirmation').show() ;
		} else if (this.typeRequest==1) {
			$("#span_link_h1").html(i18n.request_i_have_do) ;
			$('#div_link_card_my_button').hide() ;
			$('#div_link_card_my_buttonblacklist').hide() ;
			$('#div_link_confirmation').hide() ;
		} else if (this.typeRequest==2) {
			$("#span_link_h1").html(i18n.request_to_validate) ;
			$('#div_link_card_my_button').show() ;
			$('#div_link_card_my_buttonblacklist').show() ;
			$('#div_link_confirmation').hide() ;
		}
		$.ajax({
			type: 'POST',
			url: 'io.php',
			data: {action: 'link', link_id:this.link_id, typeRequest:this.typeRequest},
			context: this,
			dataType: 'json',
			success: function(data) {
				//var cardContact = data.cardContact ;
				//$("#div_link_card_contact").html("Carte de "+cardContact.vc_firstname+" "+cardContact.vc_lastname+"<br/><img src='/dynamics/p_"+cardContact.vc_id+".png' alt=''/>") ;
				var tabCards = data.tabCards ;
				if (tabCards.length==0 && this.typeRequest==0) {
					welcomePage();
					MyVCFApp.Alert.show(i18n.not_allowed_blacklist) ;
				} else {
					var txt = "" ;
					for(var i=0 ; i<tabCards.length ; i++) {
						txt += i18n.card_of+" "+tabCards[i].vc_firstname+" "+tabCards[i].vc_lastname+"<br/><img src='/dynamics/p_"+tabCards[i].vc_id+".png?d="+(new Date()).getMilliseconds()+"' alt=''/><br/><br/>" ;
					}
					$("#div_link_card_contact").html(txt) ;
					
					var tabMyCards = data.tabMyCards ;
					log('tabMyCards',tabMyCards) ;
					log('this.typeRequest',this.typeRequest) ;
					var txt = "" ;
					for(var i=0 ; i<tabMyCards.length ; i++) {
						if (this.typeRequest==1 && tabMyCards[i].vc_selected==0) continue ;
						txt += "<input id='cb_link_mycards_"+tabMyCards[i].vc_id+"' type='checkbox' class='cb_link_mycards_'" ;
						if (tabMyCards[i].vc_selected==1) txt += " checked='checked'" ;
						txt += "><label for='cb_link_mycards_"+tabMyCards[i].vc_id+"'>"+tabMyCards[i].vc_cardname+"<br/>" ;
						txt += "<img src='/dynamics/p_"+tabMyCards[i].vc_id+".png?d="+(new Date()).getMilliseconds()+"' alt='' /></label><br/><br/>" ;
					}
					$("#div_link_card_my").html(txt) ;
				}
			}
		});
	}
}) ;
