var winDetail, winAdd, winMsg, winMsgBox, win_popup, win_popup_NT, winSignIn, winContent;
var timer;
var actif;
Window.keepMultiModalWindow=true;
Windows.overlayHideEffectOptions = null;

function showLang(){
	document.getElementById("list_lang").style.display = "inline-block";
	window.clearTimeout(actif);
}
function outLang(){
	actif=window.setTimeout("document.getElementById('list_lang').style.display = 'none';",100);
}
function openAjaxLoaderDialog(content) {
	Dialog.info(content, {className:"bzk", top: 100, width:250, showProgress: true, showEffectOptions:{duration: 0 }, hideEffectOptions:{duration: 0 }});
}
function closeAjaxLoaderDialog(content) {
		if (content!="") {
		Dialog.closeInfo();
		Dialog.info(content, {className:"bzk", buttonClass: "bzk_buttons", closable: true, top: 100, width:250, showProgress: false, showEffectOptions:{duration: 0 }, hideEffectOptions:{duration: 0 }});
		setTimeout("closeAjaxLoaderDialog('')", 1500)
	}
	else Dialog.closeInfo();
}
function ajaxOnCompleteCallBack(t){
	ajax_result='';
	closeAjaxLoaderDialog(ajax_result);
	if (t) eval(t.responseText);
	closeAjaxLoaderDialog(ajax_result);
}
function UpdateFAQ(toThis) {
	new Tooltip('bloc_help', toThis, 'Quick help');	
}
function initFAQ(toThis){
	new Tooltip('bloc_help', toThis, 'Quick help');
}
function showGTCS(){
		
}
function ShowMap(i,t){
	url_map=base_url+"google_map.php?wh="+i+'&ty='+t;
	winMap = new Window({id:"popMap", className: "bzk", title: "",	top:100, height: 400, width:550,  url: url_map, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 100, showEffectOptions: {duration:0.5}});
	winMap.keepMultiModalWindow=true;
	winMap.showCenter(true,50); 
	
}
function ShowEvent(id,dt){
	url_popup=base_url+"popup_event.php?id="+id+"&date="+dt;
	winDetail = new Window({id:"popDetail", className: "bzk", top:100, height: 200, width:650,  url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winDetail.keepMultiModalWindow=true;
	winDetail.showCenter(true,50);    // option true: fenetre modale 
}
function AddEvent(){
	url_popup=base_url+"popup_add_event.php?id=";
	winAdd = new Window({id:"popAdd", className: "bzk", top:100, height: 350, width:590,  url: url_popup, showEffect:Element.show,  onload: function(){winAdd.updateSize();}, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winAdd.keepMultiModalWindow=true;
	winAdd.showCenter(true,50);    // option true: fenetre modale 
}
function JoinEvent(id,dt){
	url_popup=base_url+"popup_EventIn.php?id_evt="+id+"&date="+dt;
	winSignIn = new Window({id:"popEventIn", className: "bzk", width:600, height: 250, url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winSignIn.keepMultiModalWindow=true;
	winSignIn.showCenter(true,100);   
}
function ShowVenue(id){
	url_popup=base_url+"popup_venue.php?id="+id;
	winDetail = new Window({id:"popDetail", className: "bzk", top:100, height: 200, width:650,  url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winDetail.keepMultiModalWindow=true;
	winDetail.showCenter(true,50);    // option true: fenetre modale 
}
function AddVenue(){
	url_popup=base_url+"popup_add_venue.php?id=";
	winAdd = new Window({id:"popAdd", className: "bzk", top:100, height: 350, width:590,  url: url_popup, showEffect:Element.show,  onload: function(){winAdd.updateSize();}, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winAdd.keepMultiModalWindow=true;
	winAdd.showCenter(true,50);    // option true: fenetre modale 
}
function addFavorite(id,action){
	url= url_ajax+'ajax_FavoriteVenue.php?id='+id+'&action='+action;
	new Ajax.Request(url,{onComplete:ajaxOnCompleteCallBack,method:'get'});
	openAjaxLoaderDialog("Sending...");
}
function ShowMember(token){
	url_popup=base_url+"popup_member_detail.php?token="+token;
	titre ="Member details";
	winDetail = new Window({id:"popDetail", className: "bzk", title: titre, width:650, height: 500, top:100, url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winDetail.keepMultiModalWindow=true;
	winDetail.showCenter(true,50);    // option true: fenetre modale 
}
function SendDetail(id,ty){
	url_msg=base_url+"popup_SendDetail.php?id="+id+"&ty="+ty;
	winMsg = new Window({id:"popCompose", className: "bzk", onClose: function(win){onCloseMessage(); return true;}, width:360, height: 205, url: url_msg, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winMsg.keepMultiModalWindow=true;
	winMsg.showCenter(true,100);   
}
function ShowMessage(id,own){
	if(winMsg) winMsg.close();
	url_msg=base_url+"popup_ShowMessage.php?id="+id;
	titre="Message";
	if (own) winHeight = 250;
	else winHeight = 350;
	winMsg = new Window({id:"popMsg", className: "bzk",onClose: function(win){onCloseMessage(); return true;}, title: titre, width:450, height:winHeight, url: url_msg, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winMsg.keepMultiModalWindow=true;
	winMsg.showCenter(true,100);   
}
function Compose(id){
	if (id) url_msg=base_url+"popup_NewMessage.php?id="+id;
	else url_msg=base_url+"popup_NewMessage.php";
	titre="New message";
	winMsg = new Window({id:"popCompose", className: "bzk", onClose: function(win){onCloseMessage(); return true;}, title: titre, width:360, height: 100, url: url_msg, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winMsg.keepMultiModalWindow=true;
	winMsg.showCenter(true,100);   
}
function ReadStatus(msg,status){
	if(msg!="") {
		url=base_url+"trt/ajax_MsgUnread.php?msg="+msg+"&status="+status;
		new Ajax.Request(url,{onComplete:ajaxOnCompleteCallBack,method:'get'});
	}
	else return false;
}function onCloseMessage(){
	if($('mybiziker_msg')) {
		displayMsgList();
	}
	if ($('list_msg')){		
		getMessage(activeTab,'','');	
	}
}	
function ShowMessageBox(idm){
	url_msg=base_url+"popup_contact_form.php?id_membre="+idm;
	titre="Send a message";
	winMsgBox = new Window({id:"popMsgBox", className: "bzk", title: titre, width:600, height: 400, url: url_msg, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	winMsgBox.keepMultiModalWindow=true;
	winMsgBox.showCenter(true,100);   
}
function SendMessage(msgform, dest, notification, ty,id){ 
	if(!ty) ty="";
	if(!id) id="";
	if(dest!="") {
		openAjaxLoaderDialog("Sending your message...");
		url=url_ajax+"ajax_SendMessage.php?dest="+dest+"&notification="+notification+"&ty="+ty+"&id="+id;
		new Ajax.Request(url,{method: 'post', parameters: $(msgform).serialize(true), onComplete:ajaxOnCompleteCallBack});
	}
	else return false;
}

function DeleteMessage(msg){
	if(msg!="") {
		url=url_ajax+"ajax_MsgDelete.php?msg="+msg;
		new Ajax.Request(url,{onComplete:ajaxOnCompleteCallBack,method:'get'});
	}
	else return false;
}	
function show_list1(){
	$('slist1').style.display = 'block';
}
function hide_list1(){
	$('slist1').style.display = 'none';
}
function show_list2(){
	$('slist2').style.display = 'block';
}
function hide_list2(){
	$('slist2').style.display = 'none';
}
function show_list3(){
	$('slist3').style.display = 'block';
}
function hide_list3(){
	$('slist3').style.display = 'none';
}
function pop_NewTrip(titre){
	url_popup=base_url+"popup_newtrip.php";
	win_popup_NT = new Window({id:"popNewTrip", className: "bzk", title: titre, width:400, height: 100, url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, onShow: function(){win_popup_NT.updateSize();}, onClose: localCloseNewTrip, showEffectOptions: {duration:0.5}});
	win_popup_NT.keepMultiModalWindow=true;
	win_popup_NT.showCenter(true,100);   
}
function localCloseNewTrip(){} // Override in template when necessary


function AddNewCity(titre){
	if (!titre) titre="Add a new destination";
	url_popup=base_url+"popup_newcity.php";
	win_popup = new Window({id:"popNewCity", className: "bzk", title: titre, url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, onShow: function(){win_popup.updateSize();}, showEffectOptions: {duration:0.5}});
	win_popup.keepMultiModalWindow=true;
	win_popup.showCenter(true,100); 
}
function send_codepromo(promo){
	openAjaxLoaderDialog("Sending...");	
	new Ajax.Updater('reponse_trt',base_url+'trt/ajax_edit_info_abo.php?champ=code&code='+promo,{onComplete:ajaxOnCompleteCallBack, method:'get'});
}

function winDivToDialog(t,titre){
	if (winContent != null) winContent.close();
	winContent = new Window({className: "bzk", title: titre, maximizable: false, resizable: true, minimizable: false, hideEffect:Element.hide, showEffect:Element.show, minWidth: 10, zIndex: 999, destroyOnClose: true, showEffectOptions: {duration:0.5}, onShow: function(){winContent.updateSize();}, onClose: function() {t.style.display="none";} })
	winContent.setContent(t, true, true)
	winContent.keepMultiModalWindow=true;
	winContent.showCenter(true, 100);	
}

function closeDivToDialog(){winContent.close();}

function resendcmf(token){		
			new Ajax.Request(base_url+'resendcmf.php?token='+token,{method:'get'});
		}
function go_premium(idm){			
	//window.location.href=base_url+"index.php?page=payment&token="+token;
}
function go_basic(idm){
	//window.location.href=base_url+"index.php?page=payment&token="+token;
			
}

function delNetwork(idm,cfm){
	if(window.confirm(cfm)){
		new Ajax.Request(base_url+'trt/ajax_NetworkDel.php?idm='+idm,{onComplete:Finished,method:'get'});
	}
}
function addToNetwork(idm,cfm){
	if(window.confirm(cfm)){
		new Ajax.Request(base_url+'trt/ajax_NetworkAdd.php?idm='+idm,{onComplete:Finished,method:'get'});
	}
}	
function Finished(){
	window.reload();
}
function NetworkAccept(network,cfm){
	if (window.confirm(cfm)) {
		openAjaxLoaderDialog("Sending...");	
		url = url_ajax+'ajax_edit_info_network.php?champ=accepter&network='+network;
		if($('lstcshd'+network)) url += ($('lstcshd'+network).checked==true)?'&authd=1':'&authd=0';
		if($('lstcsht'+network)) url += ($('lstcsht'+network).checked==true)?'&autht=1':'&autht=0';
		new Ajax.Request( url, {onComplete:ajaxOnCompleteCallBack, method:'get'});
	}
}
function NetworkDecline(network,cfm){
	if (window.confirm(cfm)) {
		openAjaxLoaderDialog("Sending...");	
		new Ajax.Request(base_url+'trt/ajax_edit_info_network.php?champ=refuser&network='+network,{onComplete:ajaxOnCompleteCallBack, method:'get'});
	}
}
function NetworkClean(network){
	new Ajax.Request(base_url+'trt/ajax_NetworkClear.php?idr='+network,{onComplete:ajaxOnCompleteCallBack, method:'get'});
}

function SendInvitation(id){
	var url= url_ajax+'ajax_invitation.php?membre='+id;
	new Ajax.Request(url,{onComplete:ajaxOnCompleteCallBack,method:'get'});	
	openAjaxLoaderDialog("Sending...");
}


// Fonctions générales
function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\0/g,'\0');
	str=str.replace(/\\\\/g,'\\');
	return str;
}
function trim (myString){
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'')
} 


/* Convertit une chaine au format dd-mm-yyyy en date. Return false si le nombre n'est pas une date valide */
function s
(sDate) {
	if (sDate.length<7) return false
	var str= sDate.substring(3,5)+"/"+sDate.substring(0,2)+"/"+sDate.substring(6,10);
	var d = new Date(str);
	if (d.toString() == "NaN" || d.toString() == "Invalid Date") return false;
else return d;
}
function datetostr(t) {
	t1 = t.getMonth()+1;
	t1= (t1<10) ? "0"+t1 : t1;
	t0= (t.getDate()<10) ? "0"+t.getDate() : t.getDate();
	return t0+"-"+t1+"-"+t.getFullYear();
}
function MembersOnly(){
	url_popup=base_url+"popup_membersonly.php";
	win_popup = new Window({id:"popMembersOnly", className: "bzk", url: url_popup, showEffect:Element.show, hideEffect: Element.hide, draggable:true, closable: true, minimizable: false, maximizable: false, wiredDrag: false, destroyOnClose: true, zIndex: 99, showEffectOptions: {duration:0.5}});
	win_popup.keepMultiModalWindow=true;
	win_popup.showCenter(true,100); 
	
}

function dialog_photo(id){
	url=base_url+"formulaire_photos.php?id="+id;
	var win = new Window({id:"bzkFormPic", className: "bzk", title: "Upload picture", width:370,	height:100, top:100,
					resizable: false, minimizable: false, maximizable:false, destroyOnClose: true, url: url});
	win.keepMultiModalWindow=true;
	win.showCenter(true, 100);             
}

// LEFT MENU
function researchLength(){
		if($('box_qsearch').value.length<3)	$('text_error').innerHTML = "Please type at least 3 characters";	
		return $('box_qsearch').value.length;
	}
function toggleBlogMenu(){
		if ($('RSS_feed').style.display=="block"){
			$('RSS_feed').style.display="none";
			$('img_display').src=static_url+"images/wa-down.png";
		}
		else{
			$('RSS_feed').style.display="block";
			$('img_display').src=static_url+"images/wa-up.png";		
		}
	}
	
// placeholders (safari like)
function activatePlaceholders() {
	var detect = navigator.userAgent.toLowerCase(); 
	if (detect.indexOf("safari") > 0) return false;
	var inputs = document.getElementsByTagName("input");
	for (var i=0;i<inputs.length;i++) {
		if (inputs[i].getAttribute("type") == "text") {
			var placeholder = inputs[i].getAttribute("placeholder");
			if (inputs[i].getAttribute("placeholder")!=null){
				if (placeholder.length > 0) {
					inputs[i].value = placeholder;
					inputs[i].onclick = function() {
						if (this.value == this.getAttribute("placeholder")) {
							this.value = "";
						}
						return false;
					}
					inputs[i].onblur = function() {
						if (this.value.length < 1) {
							this.value = this.getAttribute("placeholder");
						}
					}
				}
			}
		}
	}
}

//quick search on members area
function sschoice(c){
	$('ss_type').value=c;
	if(c=='1') var ss=ss_people;
	if(c=='2') var ss=ss_events;
	if(c=='3') var ss=ss_venues;	
	$('ss_choice').style.display='none';
	if($('box_qsearch').value==$('box_qsearch').getAttribute('placeholder')){
		$('box_qsearch').setAttribute('placeholder',ss);
		$('box_qsearch').value=ss;
	}
	else {
		ssgo();
		$('fsss').submit();
	}
}
function ssgo(){
  if($('ss_type').value=='1') $('fsss').action=base_url+'mynetwork/';
  if($('ss_type').value=='2') $('fsss').action=base_url+'events/';
  if($('ss_type').value=='3') $('fsss').action=base_url+'venues/';
  
}
function ss_show(){
	document.getElementById("ss_choice").style.display = "block";
	window.clearTimeout(actif);
}
function ss_out(){
	actif=window.setTimeout("document.getElementById('ss_choice').style.display = 'none';",100);
}
function strtodate(sDate) {
	if (sDate.length<7) return false
	var str= sDate.substring(3,5)+"/"+sDate.substring(0,2)+"/"+sDate.substring(6,10);
	var d = new Date(str);
	if (d.toString() == "NaN" || d.toString() == "Invalid Date") return false;
else return d;
}
function datetostr(t) {
	t1 = t.getMonth()+1;
	t1= (t1<10) ? "0"+t1 : t1;
	t0= (t.getDate()<10) ? "0"+t.getDate() : t.getDate();
	return t0+"-"+t1+"-"+t.getFullYear();
}
