// language
function toggleLanguage(){
	if ($('language_list').style.display == 'block'){
		$('language_list').style.display = 'none';
	}else{
		$('language_list').style.display = 'block';
	}
}

function SubMenu(section){
	if ($('sub_'+section).style.display == 'block'){
		$('sub_'+section).setStyle({display:'none'});
	}else{
		$('sub_'+section).setStyle({display:'block'});
	}
}

function myStatus(){	
	win_changemystatus = new MessageBox({className: "alphacube",typeWin: "info", closeByOverlay:true, closable:true, scrolling:false, width:650, height:450, destroyOnClose:true, modal:true}); 
	win_changemystatus.show('center');
	win_changemystatus.getContent().update("<div class=\"info\"><p class=\"info_content\">"+lang.waiting_onprocess+"</p></div>");
	new Ajax.Request('mystatus.php',
		{
			parameters: $H({sel: 'changeform'}).toQueryString(),
			method: 'post',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					win_changemystatus.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					win_changemystatus.getContent().update(tab[1]);
				}else if (tab[0] == "ko"){
					win_changemystatus.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
			}
		}
	);
	return false;
}

function changeMyStatus(){
	$('content_status').hide();
	$('result_status_send').update("<img src=\"templates/images/progress.gif\" alt=\"loading\" /> <strong>"+lang.waiting_onprocess+"</strong>");
	$('result_status_send').show();
	new Ajax.Request('mystatus.php',
		{
			parameters: $H({sel: 'changestatus'}).toQueryString(),
			method: 'post',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					$('result_status_send').update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
					$('content_status').show();
				}else if (tab[0] == "ok"){
					$('result_status_send').update("<div class=\"success\">"+tab[1]+"</div>");
					$('header_mystatus').removeClassName(tab[2]);
					$('header_mystatus').addClassName(tab[3]);
					$('header_mystatus').down('span').update(tab[4]);
					$('content_status').show();
					$('change_status_button').down('span').update(tab[5]);
				}else if (tab[0] == "ko"){
					win_changemystatus.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

// données de formulaire

function loadCitiesByCountry(id_country, elt_id, section_name, reload_close_cities, close_cities_id){
	if ($(elt_id))
		if ($('progress_cities')){
			$('progress_cities').setStyle({display:'inline'});
		}
		if (reload_close_cities == null)
			reload_close_cities = 0;
			
		new Ajax.Request( "act.php",
			{
				method: 'post',
				parameters: $H({sel: 'load_cities', id: id_country, section: section_name}).toQueryString(),
				onComplete: function(requester) {
					var res = requester.responseText;
					var tab = res.split("||");
					if (tab[0] == "no"){
						$(elt_id).update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
					}else if (tab[0] == "ok"){
						$(elt_id).update(tab[1]);
					}else if (tab[0] == "ko"){
						document.location.href='index.php?sel=logoff&auto=1';
					}
					if ($(close_cities_id) && reload_close_cities == 1)
						loadCloseCities(0, close_cities_id, section_name)
				}
			}
		);
}

function loadCloseCities(id_city, elt_id, section_name){
	if ($(elt_id))
		if ($('progress_close_cities')){
			$('progress_close_cities').setStyle({display:'inline'});
		}
		new Ajax.Request( "act.php",
			{
				method: 'post',
				parameters: $H({sel: 'load_close_cities', id: id_city, section: section_name}).toQueryString(),
				onComplete: function(requester) {
					var res = requester.responseText;
					var tab = res.split("||");
					if (tab[0] == "no"){
						$(elt_id).setStyle({display: 'none'});
					}else if (tab[0] == "ok"){
						$(elt_id).setStyle({display: 'block'});
						$(elt_id).update(tab[1]);
					}else if (tab[0] == "ko"){
						document.location.href='index.php?sel=logoff&auto=1';
					}
				}
			}
		);
}

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0] && inputs[i].parentNode.getElementsByTagName("span")[0].className == 'hint') {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	var selects = document.getElementsByTagName("select");
	for (var i=0; i<selects.length; i++){
		// test to see if the hint span exists first
		if (selects[i].parentNode.getElementsByTagName("span")[0] && selects[i].parentNode.getElementsByTagName("span")[0].className == 'hint') {
			// the span exists!  on focus, show the hint
			selects[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			// when the cursor moves away from the field, hide the hint
			selects[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}

function prepareHintRegistration(){
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		// test to see if the hint span exists first
		if (inputs[i].parentNode.getElementsByTagName("span")[0] && inputs[i].parentNode.getElementsByTagName("span")[0].className == 'hint') {
			// the span exists!  on focus, show the hint
			inputs[i].onfocus = function () {
				var hint_text = this.parentNode.getElementsByTagName("span")[0].innerHTML;
				$('content_error').update(hint_text);
				$('registration_error').style.display = 'block';
			}
			// when the cursor moves away from the field, hide the hint
			inputs[i].onblur = function () {
				$('content_error').update('');
				$('registration_error').style.display = 'none';
			}
		}
	}
}

// actions users
function sendKiss(the_url, title){
	send_kiss = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true}); 
	send_kiss.getContent().update("<div class=\"info\"><p class=\"info_content\">"+title+"</p></div>");
	send_kiss.show('center');
	new Ajax.Request(the_url,
		{
			method: 'get',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					send_kiss.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					send_kiss.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					send_kiss.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
				send_kiss.setCloseByOverlay(true);
			}
		}
	);
}

function loadActionsBarSubmenu(id){	
	if ($(id)){
		if ($(id).style.display == 'block'){
			$(id).setStyle({display:'none'});
		}else{
			$(id).setStyle({display:'block'});
		}
	}
}

function addHotlist(the_url, template_path, fromProfil){
	add_hotlist = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
	add_hotlist.show('center');
	add_hotlist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+lang.waiting_onadd+"</p></div>");
	processAddHotlist(the_url, template_path, fromProfil);
}

function processAddHotlist(the_url, template_path, from_profil){
	new Ajax.Request(the_url,
		{
			method: 'get',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					add_hotlist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					var id = tab[2];
					if (from_profil == null){
						$(id + '_hotlist').update('<img src="'+template_path+'/images/icon/actions_bar_addhotlist_off.gif" alt="" />');
					}else{
						$('addhotlist_link_off').show();
						$('addhotlist_link').hide();
						$('delhotlist_link').show();
						$('delhotlist_link_off').hide();
					}
					add_hotlist.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					add_hotlist.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
				if ($('hotlist_submenu')){
					$('hotlist_submenu').hide();
				}
				add_hotlist.setCloseByOverlay(true);
			}
		}
	);
}

function deleteHotlist(the_url, template_path, fromProfil){
	del_hotlist = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
	del_hotlist.show('center');
	del_hotlist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+lang.waiting_ondelete+"</p></div>");
	processDeleteHotlist(the_url, template_path, fromProfil);
}

function processDeleteHotlist(the_url, template_path, from_profil){
	new Ajax.Request(the_url,
		{
			method: 'get',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					del_hotlist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					var id = tab[2];
					if (from_profil == true){
						$('delhotlist_link_off').show();
						$('delhotlist_link').hide();
						$('addhotlist_link').show();
						$('addhotlist_link_off').hide();
					}
					del_hotlist.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					del_hotlist.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
				if ($('hotlist_submenu')){
					$('hotlist_submenu').hide();
				}
				del_hotlist.setCloseByOverlay(true);
			}
		}
	);
}

//////////////////// BLACK LIST

function addBlacklist(the_url, template_path, fromProfil){
	add_blacklist = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
	add_blacklist.show('center');
	add_blacklist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+lang.waiting_onadd+"</p></div>");
	processAddBlacklist(the_url, template_path, fromProfil);
}

function processAddBlacklist(the_url, template_path, from_profil){
	new Ajax.Request(the_url,
		{
			method: 'get',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					add_blacklist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					var id = tab[2];
					if (from_profil == true){
						$('addblacklist_link_off').show();
						$('addblacklist_link').hide();
						$('delblacklist_link').show();
						$('delblacklist_link_off').hide();
					}
					add_blacklist.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					add_blacklist.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
				if ($('blacklist_submenu')){
					$('blacklist_submenu').hide();
				}
				add_blacklist.setCloseByOverlay(true);
			}
		}
	);
}

function deleteBlacklist(the_url, template_path, fromProfil){
	del_blacklist = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
	del_blacklist.show('center');
	del_blacklist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+lang.waiting_ondelete+"</p></div>");
	processDeleteBlacklist(the_url, template_path, fromProfil);
}

function processDeleteBlacklist(the_url, template_path, from_profil){
	new Ajax.Request(the_url,
		{
			method: 'get',
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					del_blacklist.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					var id = tab[2];
					if (from_profil == true){
						$('delblacklist_link_off').show();
						$('delblacklist_link').hide();
						$('addblacklist_link').show();
						$('addblacklist_link_off').hide();
					}
					del_blacklist.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					del_blacklist.close();
					document.location.href='index.php?sel=logoff&auto=1';
				}
				if ($('blacklist_submenu')){
					$('blacklist_submenu').hide();
				}
				del_blacklist.setCloseByOverlay(true);
			}
		}
	);
}

///////////// FIN BLACK LIST

///////////// GALLARY PUBLIC
function loadUserPublicAlbum(first_photo, key, nb_photo, login, width){
	if (width == null){
		width = (nb_photo * (100+2)) + 10 + 10 + 20; // width min
	}else{
		width += 2 + 10 + 10 + 20;
	}
	
	loadgallary_win = new MessageBox({className: "alphacube", title:login, typeWin: "content", closeByOverlay:true, closable:true, scrolling:true, width:width, height:300, top:30, destroyOnClose:true, modal:true});
	loadgallary_win.getContent().update("<div class=\"progress\"><p>&nbsp;</p></div>");
	loadgallary_win.show('top');
	new Ajax.Request('gallary.php',
		{
			method: 'post',
			parameters: $H({sel: 'album', from_popup: 1, k: key}).toQueryString(),
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					loadgallary_win.setSize(400, 140, true);
					loadgallary_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					loadgallary_win.getContent().update(tab[1]);
					loadPhotoGallary(first_photo, nb_photo);
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function loadPhotoGallary(imgPath, nb_photo){
	var width_min = (nb_photo * (90+2)) + 10 + 10 + 20;
	
	$('album_current_photo').setStyle({display:'none'});
	$('album_photo_loader').setStyle({display:'block'});
	
	var imgPreloader = new Image();
	imgPreloader.onload = function(){
		$('album_photo_loader').setStyle({display:'none'});
		var w = imgPreloader.width + 2 + 10 + 10 + 20;
		if (w < width_min) w = width_min;
		var h = imgPreloader.height
		if (nb_photo > 1)
			h += + 25 + 10 + 10 + 90 + 1 + 20;
		else
			h += 10 + 10 + 25 + 20;
		
		loadgallary_win.setSize(w, h, true);
		$('album_current_photo').setStyle({display:'block'});
		$('album_current_photo').src = imgPath;
	};
	imgPreloader.src = imgPath;
}

///////////// FIN GALLARY PUBLIC

///////////// ACCOUNT
function updateUserAlerts(){
	updatealerts_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:140, destroyOnClose:true, modal:true});
	updatealerts_win.show('center');
	updatealerts_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onprocess+"</p></div>");
	processUpdateUserAlerts();
}

function processUpdateUserAlerts() {
	var the_params = Form.serialize('notifications_form');
	new Ajax.Request('myaccount.php',
		{
			method: 'post',
			parameters: the_params,
			onFailure: function (){
				updatealerts_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					updatealerts_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					updatealerts_win.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function updateUserAccount(){
	updateaccount_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:140, destroyOnClose:true, modal:true});
	updateaccount_win.show('center');
	updateaccount_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onprocess+"</p></div>");
	processUpdateUserAccount();
}

function processUpdateUserAccount() {
	var the_params = Form.serialize('info_form');
	new Ajax.Request('myaccount.php',
		{
			method: 'post',
			parameters: the_params,
			onFailure: function (){
				updateaccount_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					updateaccount_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					updateaccount_win.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
					if ($('unvalid_email'))
						$('unvalid_email').setStyle({display: 'none'});
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function deleteUserAccount(){
	if (confirm(lang.confirm_deleteAccount)){
		deleteaccount_win = new MessageBox({className: "alphacube", typeWin: "info", scrolling:false, width:500, height:200, destroyOnClose:true, modal:true});
		deleteaccount_win.show('center');
		deleteaccount_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onprocess+"</p></div>");
		processDeleteUserAccount();
	}else{
		return;
	}
}

function processDeleteUserAccount() {
	closeFunc = function(){
		document.location.href = 'index.php';
	}
	new Ajax.Request('myaccount.php',
		{
			method: 'post',
			parameters: $H({sel:'deleteaccount', from_popup:1}).toQueryString(),
			onFailure: function (){
				deleteaccount_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					deleteaccount_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
					deleteaccount_win.setClosable(true);
					deleteaccount_win.setCloseByOverlay(true);
				}else if (tab[0] == "ok") {
					deleteaccount_win.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
					deleteaccount_win.setClosable(true);
					deleteaccount_win.setCloseByOverlay(true);
					deleteaccount_win.setCloseFunc(closeFunc);
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function toggleAccountInfoPass(type){
	if (type == 'pass'){
		var elt = 'account_info_pass';
	}else{
		var elt = 'account_info_addon';
	}
	new Effect.toggle(elt, 'slide', {duration: 0.5});
}

function sendPassInfo(passID){
	passinfo_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:200, destroyOnClose:true, modal:true});
	passinfo_win.show('center');
	passinfo_win.setCloseByOverlay(true);
	passinfo_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onsend+"</p></div>");
	processSendPassInfo(passID);
}

function processSendPassInfo(passID) {
	var email = $('email_info_pass').value;

	new Ajax.Request('myaccount.php',
		{
			method: 'post',
			parameters: $H({sel:'infopayment', from_popup:1, pi: passID, m: email}).toQueryString(),
			onFailure: function (){
				passinfo_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					passinfo_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					passinfo_win.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

///////////// FIN ACCOUNT

// recherche
function toggleSearchItem(status){
	if (status == 'less'){
		$('more_item_button').show();
		$('less_item_button').hide();
	}else{
		$('more_item_button').hide();
		$('less_item_button').show();
	}
	new Effect.toggle('more_item', 'appear', {duration: 0.5});
}

function processSearch(){
	$('sel_search').value = 'search';
	$('search_form').submit();
}

function countResSearch() {
	$('sel_search').value = 'count';
	var the_param = Form.serialize('search_form');
	new Ajax.Request('search.php',
		{
			method: 'post',
			parameters: the_param+"&from_popup=1",
			onFailure: function (){
				$('count_res').value = '0';
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					$('count_res').value = '0';
				}else if (tab[0] == "ok") {
					$('count_res').value = tab[1];
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function saveSearch(){
	savesearch_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
	savesearch_win.show('center');
	savesearch_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onsave+"</p></div>");
	processSaveSearch();
}

function processSaveSearch() {
	$('sel_search').value = 'save';
	var the_param = Form.serialize('search_form');
	closeFunc = function(){
		loadSearchRecords();
	}
	new Ajax.Request('search.php',
		{
			method: 'post',
			parameters: the_param+"&from_popup=1",
			onFailure: function (){
				savesearch_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					savesearch_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					savesearch_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
				savesearch_win.setCloseByOverlay(true);
				savesearch_win.setCloseFunc(closeFunc);
			}
		}
	);
}

function loadSearchRecords(){
	new Ajax.Request('search.php',
		{
			method: 'post',
			parameters: $H({sel: 'loadrecords', from_popup:1}).toQueryString(),
			onFailure: function (){
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "ok"){
					$('progress_search_record').hide();
					$('record_content').setStyle({display:'block'});
					$('record_content').update(tab[1]);
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function processLoadSearch(){
	var searchID = $F('record');
	if (searchID == null || searchID == 0){
		return;
	}
	$('progress_search_record').show();
	$('record_content').setStyle({display:'none'});
	new Ajax.Request('search.php',
		{
			method: 'post',
			parameters: $H({sel: 'loadsearch', searchID: searchID, from_popup:1}).toQueryString(),
			onFailure: function (){
				$('progress_search_record').hide();
				$('record_content').setStyle({display:'block'});
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					$('progress_search_record').hide();
					$('record_content').setStyle({display:'block'});
					loadsearch_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
					loadsearch_win.update("<div class=\"info\"><p class=\"info_content\"></p>"+tab[1]+"</div>");
					loadsearch_win.show('center');
					loadsearch_win.setCloseByOverlay(true);
				}else if (tab[0] == "ok"){
					document.location.href = 'search.php?si='+tab[1];
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function processDeleteSearch(){
	var searchID = $F('record');
	if (searchID == null || searchID == 0){
		return;
	}
	$('progress_search_record').show();
	$('record_content').setStyle({display:'none'});
	new Ajax.Request('search.php',
		{
			method: 'post',
			parameters: $H({sel: 'deletesearch', searchID: searchID, from_popup:1}).toQueryString(),
			onFailure: function (){
				$('progress_search_record').hide();
				$('record_content').setStyle({display:'block'});
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					$('progress_search_record').hide();
					$('record_content').setStyle({display:'block'});
				}else if (tab[0] == "ok"){
					loadSearchRecords();
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

// ! FIN recherche

function sendFriend(the_url){
	if (!window.ie_old){
		send_friend = new MessageBox({className: "alphacube",typeWin: "info", url: the_url, closeByOverlay:true, closable:true, scrolling:false, width:550, height:400, destroyOnClose:true, modal:true}); 
		send_friend.show('center');
	}else{
		send_friend_popup = window.open(the_url, 'sendfriendprofile', 'width=550,height=400,top=200,left=200,location=no,menubar=no,status=no,directories=no,tollbar=no,scrolling=auto');
		send_friend_popup.focus();
	}
}

function importContactsForm(){
	document.location.href = 'myfriends.php';
}

function validateUserEmail(){
	valid_user_email = new MessageBox({className: "alphacube",typeWin: "info", url: "homepage.php?sel=validemail", closeByOverlay:true, closable:true, scrolling:false, width:700, height:475, destroyOnClose:true, modal:true}); 
	valid_user_email.show('center');
	return false;
}

function displayCGU(type){
	if (type == null){
		return;
	}
	cgu_win = new MessageBox({className: "alphacube", typeWin: "content", closable:true, scrolling:false, width:750, height:550, top:30, destroyOnClose:true, modal:true});
	cgu_win.setCloseByOverlay(true);
	cgu_win.show('top');
	var url = '';
	var titre_str = '';
	var top_str = "<div style=\"margin:10px 20px;\">";
	if (type == 'chat'){
		url = 'policy.php?sel=chat&fp=1';
		titre = lang.policy_chatTitle;
	}else if (type == 'site'){
		url = 'policy.php?sel=site&fp=1';
		titre = lang.policy_siteTitle;
	}
	
	titre = "<div class=\"subtitle\">"+titre+"</div>";
	new Ajax.Request(url,
		{
			method: 'get',
			onFailure: function (){
				cgu_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					cgu_win.getContent().update(top_str + titre_str + "<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else{
					cgu_win.getContent().update(top_str + titre_str + tab[0] + "</div>");
				}
			}
		}
	);
}

function processDisplayCGU(type) {
	if (type == null){
		return;
	}
	var url = '';
	var top_str = "<div style=\"margin:10px 20px;\">";
	if (type == 'chat'){
		url = 'policy.php?sel=chat&fp=1';
	}else if (type == 'site'){
		url = 'policy.php?sel=site&fp=1';
	}
	var titre_str = "";
	if (t)
	"<div class=\"subtitle\">"+titre+"</div>";
	new Ajax.Request(url,
		{
			method: 'get',
			onFailure: function (){
				cgu_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					cgu_win.getContent().update(top_str + titre_str + "<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else{
					cgu_win.getContent().update(top_str + titre_str + tab[0] + "</div>");
				}
			}
		}
	);
}

function ContactUs(){
	contactus_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:140, destroyOnClose:true, modal:true});
	contactus_win.show('center');
	contactus_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onsend+"</p></div>");
	processContactUs();	
}

function processContactUs() {
	var the_params = Form.serialize('contactus_form');
	new Ajax.Request('info.php',
		{
			method: 'post',
			parameters: the_params,
			onFailure: function (){
				contactus_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					contactus_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					contactus_win.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
					$('contactus_form').reset();
				}
			}
		}
	);
}

function checkScreen(){
	new Ajax.Request('act.php',
		{
			parameters: $H({sel:'screen', sw: screen.width, sh: screen.height}).toQueryString(),
			method: 'post',
			onFailure: function (requester){
				// nothing
			},
			onComplete: function(requester){
				// nothing
			}
		}
	);
}

// viewprofile et myprofile

function loadProfile(id, key, type, force_refresh){
	if ($(id+'_data')){
		if (typeof updateSessionTimer != 'undefined'){
			clearInterval(updateSessionTimer);
		}
		
		$$('#profile_menu ul li').each(function(elt){
			elt.removeClassName('current');
		});
		$(id).addClassName('current');
		$$('#middle_container .section').each(function(elt){
			elt.hide();
		});
		$(id+'_data').show();
		var content = $(id+'_data').innerHTML;
		if (content == '' || force_refresh == true){
			$(id+'_data').update("<div class=\"progress\"><p>"+lang.waiting_onprocess+"</p></div>");
			processLoadProfile(id, key, type);
		}else{
			updateUserSession();
			return;
		}
	}else{
		return;
	}
}

function processLoadProfile(id, key, type){
	var url;
	if (type == 'view')
		url = 'viewprofile.php';
	else
		url = 'myprofile.php';
	new Ajax.Request(url,
		{
			method: 'post',
			parameters: $H({sel: id, k: key, from_popup: 1}).toQueryString(),
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					$(id+'_data').update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok"){
					$(id+'_data').update(tab[1]);
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}else{
					$(id+'_data').update(tab[0]);
				}
			}
		}
	);
}

function loadPhotoSection(section){
	if ($(section+'_album')){
		updateUserSession();
		if (typeof updateSessionTimer != 'undefined'){
			clearInterval(updateSessionTimer);
		}
		
		$$('#profile_photos_menu li').each(function(elt){
			elt.removeClassName('current');
		});
		$(section).addClassName('current');
		$$('.upload_container').each(function(elt){
			elt.hide();
		});
		$(section+'_album').show();
	}else{
		return;
	}
}

function saveProfile(section){
	if (!$(section+'_form')){
		return;
	}
	
	saveprofile_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:400, height:150, destroyOnClose:true, modal:true});
	saveprofile_win.show('center');
	saveprofile_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onupdate+"</p></div>");
	processSaveProfile(section);	
}

function processSaveProfile(section){
	var the_params = Form.serialize(section+'_form');
	new Ajax.Request('myprofile.php',
		{
			parameters: the_params,
			method: 'post',
			onFailure: function (){
				saveprofile_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					saveprofile_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					saveprofile_win.getContent().update("<div class=\"success\">"+tab[1]+"</div>");
					if ($('unvalid_email'))
						$('unvalid_email').setStyle({display: 'none'});
			
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
				saveprofile_win.setCloseByOverlay(true);
			}
		}
	);
}

// FIN myprofile et viewprofile

function lostPassword() {
	if (!window.ie_old){
		passwd_win = new MessageBox({className: "alphacube", typeWin: "info", url: "lostpassword.php", closable:true, scrolling:false, width:600, height:350, destroyOnClose:true, modal:true});
		passwd_win.setCloseByOverlay(true);
		passwd_win.show('center');
	}else{
		passwd_win_popup = window.open('lostpassword.php', 'lostpassword', 'width=600,height=350,top=200,left=100,location=no,menubar=no,status=no,directories=no,tollbar=no,scrolling=auto');
		passwd_win_popup.focus();
	}
}

function ToggleFraudSystem(etat){
	if (etat == 'less'){
		$('antifraud_toptext_long').hide();
		$('antifraud_toptext_short').show();
	}else{
		$('antifraud_toptext_short').hide();
		$('antifraud_toptext_long').show();
	}
}

// FIN actions_users

// fonctions session
function updateUserSession() {
	new Ajax.Request('act.php',
		{
			method: 'post',
			parameters: $H({sel: 'update_session'}).toQueryString(),
			onComplete: function (requester){
				// nothing to do
			}
		});
} // majSession
// FIN fonctions session

// functions upload images
function appearUploadForm(section){	
	$(section+'_upload').show();
	
	if ($('display_'+section))
		$('display_'+section).hide();
}		

function uploadImage(the_form){
	if ($(the_form)){
		uploadimage_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:120, destroyOnClose:true, modal:true});
		uploadimage_win.show('center');
		uploadimage_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onuploadImage+"</p></div>");
		$(the_form).submit();
	}
}

function uploadImageComplete(res, file_path, file_id, section){
	var status = res.split('||');
	var res_str = '';
	var file_str = '';
	// status upload
	if (status[0] == 'no'){
		res_str = "<div class=\"info\"><p class=\"info_content\">"+status[1]+"</p></div>";
		uploadimage_win.getContent().update(res_str+file_str);
		uploadimage_win.setCloseByOverlay(true);
	}else{
		uploadimage_win.close();
		viewImage(file_path, file_id, section, status[1], true, false);
	}
}

function viewImage(file_path, file_id, section, res_str, is_upload, is_rotate){
	closeFunc = function(){
		document.location.href = 'myprofile.php?sel=myphotos';
	}
	
	var is_registered = WindowsBox.isRegistered('viewimage_win', 'msg');
	if (!is_registered){
		viewimage_win = new MessageBox({className: "alphacube", typeWin: "info", nameWin: 'viewimage_win', closable:true, scrolling:false, width:500, height:120, destroyOnClose:true, modal:true});
		viewimage_win.show('center');
	}
	

	tools_str = "<ul class=\"buttons_file\">";
	tools_str += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:rotateImage("+file_id+", '"+section+"', 'left');\" class=\"rotate_file_left\">&nbsp;</a></li>";
	tools_str += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:rotateImage("+file_id+", '"+section+"', 'left');\" id=\"rotate_left\"></a></li>";
	tools_str += "<li class=\"sep\">&nbsp;</li>";
	tools_str += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:rotateImage("+file_id+", '"+section+"', 'right');\" id=\"rotate_right\"></a></li>";
	tools_str += "<li><a href=\"javascript:void(0);\" onclick=\"javascript:rotateImage("+file_id+", '"+section+"', 'right');\" class=\"rotate_file_right\">&nbsp;</a></li>";
	tools_str += "</ul>";
		
	var file_str = "<div id=\"file_uploaded\"><img src=\"templates/blank.gif\" id=\"file_uploaded_img\" alt=\"\" /></div>";
	
	if (res_str != ''){
		res_str = "<div id=\"results_upload_popup\" class=\"result_popup\">"+res_str+"</div>";	
	}
	
	if (is_rotate == true || is_upload == true){
		viewimage_win.setCloseFunc(closeFunc);
	}		
	viewimage_win.setCloseByOverlay(true);
	viewimage_win.getContent().update(res_str+tools_str+file_str);
	
	$('rotate_left').update(lang.image_rotateLeft);
	$('rotate_right').update(lang.image_rotateRight);
				
	var d = new Date();
	var imgLoaded = new Image();
	imgLoaded.onload = function(){
		var min_width = 250;
		var w = imgLoaded.width;
		var h = imgLoaded.height + 10 + 10 + 10 + 23;
		if (w < 400){
			w = 400;
		}
		w += 2 + 10 + 10 + 20 + 20;
		
		if (res_str != ''){
			var height_top = $('results_upload_popup').getHeight();
			h += height_top + 10 + 10;
		}	
		
		viewimage_win.setSize(w, h, true, true);
		$('file_uploaded_img').src = file_path+"?"+d.getMilliseconds();
		$('file_uploaded_img').setStyle({width:imgLoaded.width+'px', height:imgLoaded.height+'px'});
		$('file_uploaded').setStyle({width:(imgLoaded.width+8)+'px', height:(imgLoaded.height+8)+'px'});
	};
	imgLoaded.src = file_path+"?"+d.getMilliseconds();
}

function rotateImage(fileID, section, rotate){
	if (typeof viewimage_win == 'undefined'){
		viewimage_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:120, destroyOnClose:true, modal:true});
		viewimage_win.show('center');
	}
	viewimage_win.getContent().update("<div class=\"progress\"><p>&nbsp;</p></div>");
	viewimage_win.setCloseByOverlay(false);
	viewimage_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_onprocess+"</p></div>");
	processRotateImage(fileID, section, rotate);
}

function processRotateImage(fileID, section, rotate){
	new Ajax.Request('myprofile_upload.php',
		{
			parameters: $H({sel: 'rotate'+section, fileID: fileID, rotate: rotate, from_popup: 1}).toQueryString(),
			method: 'post',
			onFailure: function (){
				viewimage_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				if (tab[0] == "no"){
					viewimage_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div></div>");
				}else if (tab[0] == "ok") {
					viewImage(tab[1], tab[2], tab[3], '', false, true);
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function deleteImage(fileID, fileStatus, section){	
	deleteimage_win = new MessageBox({className: "alphacube", typeWin: "info", closable:true, scrolling:false, width:500, height:120, destroyOnClose:true, modal:true});
	deleteimage_win.show('center');
	deleteimage_win.getContent().update("<div class=\"progress\"><p>"+lang.waiting_ondelete+"</p></div>");
	processDeleteImage(fileID, fileStatus, section);
}

function processDeleteImage(fileID, fileStatus, section){
	new Ajax.Request('myprofile_upload.php',
		{
			parameters: $H({sel: 'delete'+section, fileID: fileID, fileStatus: fileStatus, from_popup: 1}).toQueryString(),
			method: 'post',
			onFailure: function (){
				deleteimage_win.close();
			},
			onComplete: function(requester){
				var res = requester.responseText;
				var tab = res.split("||");
				deleteimage_win.setCloseByOverlay(true);
				if (tab[0] == "no"){
					deleteimage_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");
				}else if (tab[0] == "ok") {
					deleteimage_win.getContent().update("<div class=\"info\"><p class=\"info_content\">"+tab[1]+"</p></div>");					
					document.location.href = 'myprofile.php?sel=myphotos';
				}else if (tab[0] == "ko"){
					document.location.href = 'index.php?sel=logoff&auto=1';
				}
			}
		}
	);
}

function resizeImg(v, class_name) {
	var scalePhotos = document.getElementsByClassName(class_name);
	for (i=0; i < scalePhotos.length; i++) {
		scalePhotos[i].style.width = v+'px';
	}
} 
// FIN function upload images

// function mailbox
function itemsSearchInMsg(){
	new Effect.toggle('items_search', 'appear', { duration: 0.5 });
	return false;
}

function processSearchInMsg(type, part){
	var expr = $F('expr_search');
	if (expr == '' || expr.length < 3)
		return;
		
	$('folder_search').value = type;
	if (part != null)
		$('part_search').value = part;
		
	$('msg_search_form').submit();
}

// function resil payment
function CancelPayment(id_abo, type_abo){
	document.location.href = 'myaccount.php?sel=cancelpaymentform&i='+id_abo+'&t='+type_abo;
	return;
	/*
	if (!window.ie_old){
		cancelpayment_win = new MessageBox({className: "alphacube", typeWin: "info", url: 'myaccount.php?sel=cancelpaymentform&i='+id_abo+'&t='+type_abo+'&p=1', closeByOverlay:true, closable:true, scrolling:false, width:600, height:400, destroyOnClose:true, modal:true}); 
		cancelpayment_win.setCloseByOverlay(true);
		cancelpayment_win.show('center');
	}else{
		cancelpayment_win_popup = window.open('myaccount.php?sel=cancelpaymentform&i='+id_abo+'&t='+type_abo+'&p=1', 'cancelpayment', 'width=600,height=400,top=100,left=100,location=no,menubar=no,status=no,directories=no,tollbar=no,scrolling=auto');
		cancelpayment_win_popup.focus();
	}*/
}

// FIN fonction payment resil
function checkBox(class_name){
	checkflag = !checkflag;
	$$('.'+class_name).each(function(elt){
		elt.checked = checkflag;
	});
}

var openedChat = 0;

function initChatLoader(){
	setTimeout(function(){ thisMovie('flashAddInvit').isOpened(); }, 500);
}

function isChatOpened(etatOpenChat){
	openedChat = etatOpenChat;
}

function launchChat(u, p, c){
	window.name = 'chichou';
	if (openedChat == 1 && u != 0){
		thisMovie("flashAddInvit").askinvit(u);
	}else{
		var url_visio;
		if (u != 0){
			url_visio = 'visiochat/visiochat.php?u='+u+'&p='+p;
		}else{
			if (c == 1){
				url_visio = 'visiochat/visiochat.php?check=ok';
			}else{
				url_visio = 'visiochat/visiochat.php';
			}
		}
		windowVS = window.open(url_visio,'visiochat','directories=no, location=no,menubar=no,scrollbars=no,resizable=yes, status=no,toolbar=no,left=0,top=0,width=800,height=650');
		windowVS.focus();
	}
	return false;
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName];
    }else{
        return document[movieName];
    }
}

// function external
function init_input(id, text, type){
	if (type == 'focus'){
		if ($(id).value == text){
			$(id).value = '';
		}
	}else if (type == 'blur'){
		if ($(id).value == ''){
			$(id).value = text;
		}
	}
	return;
}