
// basic functions
// ::::::::::::::::::::::

var PROFILE_IMG_BUTTON_ADD_TO_CONTACTLIST = '';
var PROFILE_IMG_BUTTON_REMOVE_FROM_CONTACTLIST = '';

var chatPopupOpened = false;
var checkForNewMessagesInterval = 13; // in seconds
var checkForNewMessagesID = null;
var checkForBuddiesOnlineInterval = 23; // in seconds
var checkForBuddiesOnlineID = null;

var profileUserID2Check = 0;
var profileIsInBuddyList = false;

function popUp(path, w, h, handler) {
	var t=(screen.height/2)-(h/2)-50;
	var l=(screen.width/2)-(w/2);
  if(!handler) handler="pop"+nRand(100);
	var windowprops = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no, left=" + l + ",top=" + t + ",width=" + w + ",height=" + h;
	popwin = window.open(path,handler,windowprops);
	popwin.focus();
}


function popUpScroll(path, w, h, handler) {
	var t=(screen.height/2)-(h/2)-50;
	var l=(screen.width/2)-(w/2);
  if(!handler) handler="pop"+nRand(100);
  var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no, left=" + l + ",top=" + t + ",width=" + w + ",height=" + h;
	popwin = window.open(path,handler,windowprops);
	popwin.focus();
}


function limitTextByNumber(limitField, maxCharLimit) {
	if (limitField.value.length > maxCharLimit) {
		  limitField.value = limitField.value.substring(0, maxCharLimit);
  }
}


function checkEmail(emailToCheck, level) {
  	if (typeof level == 'undefined') level = 0;
  	var emailPatterns = [
  		/.+@.+\..+$/i,
  		/^\w.+@\w.+\.[a-z]+$/i,
  		/^\w[-_a-z~.]+@\w[-_a-z~.]+\.[a-z]{2}[a-z]*$/i,
  		/^\w[\w\d]+(\.[\w\d]+)*@\w[\w\d]+(\.[\w\d]+)*\.[a-z]{2,7}$/i
  		];
  		
  	if (!emailPatterns[level].test(emailToCheck)) {
        return false;
  	}
  	else {
        return true;
    }
}


function checkMobilePhone(mobilePhoneToCheck) {
  	var mobilePhonePattern = /^06\d{8}$/i;
  		
  	if (!mobilePhonePattern.test(mobilePhoneToCheck)) {
        return false;
  	}
  	else {
        return true;
    }
}


function checkSearchUserNameLength() {
    var sunValue = window.document.forms.search_user.userName.value;
    if (sunValue.length>0 && sunValue.length<3) {
        hideProgress('searchInProgress');
        openErrorMessageBox('searchErrorMessageBox', 'photoPref', 55, -230);
        return false;
    }
    else {
        return true;
    }
}


function showProgress(progressObject) {
    document.getElementById(progressObject).style.display = "inline";
    document.getElementById(progressObject+'Spacer').style.display = "none";
}


function hideProgress(progressObject) {
    document.getElementById(progressObject).style.display = "none";
    document.getElementById(progressObject+'Spacer').style.display = "inline";
}


function displayProfilePhoto(ppID) {
    var pp0 = document.getElementById('ppContainer0');
    var pp1 = document.getElementById('ppContainer1');
    var pp2 = document.getElementById('ppContainer2');
    var pp3 = document.getElementById('ppContainer3');
    var pp4 = document.getElementById('ppContainer4');
    
    if (pp0) {
        pp0.style.display = "none";
    }
    
    if (pp1) {
        pp1.style.display = "none";
    }
    
    if (pp2) {
        pp2.style.display = "none";
    }
    
    if (pp3) {
        pp3.style.display = "none";
    }
    
    if (pp4) {
        pp4.style.display = "none";
    }

    document.getElementById('ppContainer'+ppID).style.display = "inline";
}


var redirectToSendMessageURL;
var redirectToRegistrationURL;
var chatWindowURL;
var onlineNotificationWindowURL;


function redirectToSendMessage(userID) {
    document.location.href = redirectToSendMessageURL + '?userID=' + userID;
}


function redirectToRegistration(userID) {
    document.location.href = redirectToRegistrationURL;
}


// form actions
// ::::::::::::::::::::::

function doLogin() {
    showProgress('loginInProgress');
    
    window.frames['loginFrame'].document.forms[0].userName.value = window.document.forms.login.userName.value;
    window.frames['loginFrame'].document.forms[0].password.value = window.document.forms.login.password.value;
    window.frames['loginFrame'].document.forms[0].loginValid.value = 'true';
    window.frames['loginFrame'].document.forms[0].emailSendValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].logoutValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForNewMessagesValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForBuddiesOnlineValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].submit();
}


function sendPassword() {
    showProgress('sendingEmailInProgress');
    
    window.frames['loginFrame'].document.forms[0].forgottenPasswordEmail.value = window.document.forms.getPassword.forgottenPasswordEmail.value;
    window.frames['loginFrame'].document.forms[0].loginValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].emailSendValid.value = 'true';
    window.frames['loginFrame'].document.forms[0].logoutValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForNewMessagesValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForBuddiesOnlineValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].submit();
}


function checkForNewMessages() {
    if (chatPopupOpened) {
        window.clearInterval(checkForNewMessagesID);
    }
    else {
        window.frames['loginFrame'].document.forms[0].loginValid.value = 'false';
        window.frames['loginFrame'].document.forms[0].emailSendValid.value = 'false';
        window.frames['loginFrame'].document.forms[0].logoutValid.value = 'false';
        window.frames['loginFrame'].document.forms[0].checkForNewMessagesValid.value = 'true';
        window.frames['loginFrame'].document.forms[0].checkForBuddiesOnlineValid.value = 'false';
        window.frames['loginFrame'].document.forms[0].submit();
    }
}


function checkForBuddiesOnline() {
    window.frames['loginFrame'].document.forms[0].loginValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].emailSendValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].logoutValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForNewMessagesValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForBuddiesOnlineValid.value = 'true';
    window.frames['loginFrame'].document.forms[0].submit();
}


function doLogout() {
    window.clearInterval(checkForNewMessagesID);
    window.clearInterval(checkForBuddiesOnlineID);
    
    window.frames['loginFrame'].document.forms[0].loginValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].emailSendValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].logoutValid.value = 'true';
    window.frames['loginFrame'].document.forms[0].checkForNewMessagesValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].checkForBuddiesOnlineValid.value = 'false';
    window.frames['loginFrame'].document.forms[0].submit();
}


function doRegistration() {
    if (checkRegistration(-1)) {
        closeErrorMessageBox('registrationErrorMessageBox');
        
        showProgress('registrationInProgress');
        
        window.frames['registrationFrame'].document.forms[0].userName.value = window.document.forms.registrationForm.userName.value;
        window.frames['registrationFrame'].document.forms[0].password.value = window.document.forms.registrationForm.password.value;
        window.frames['registrationFrame'].document.forms[0].email.value = window.document.forms.registrationForm.email.value;
        window.frames['registrationFrame'].document.forms[0].receivePromo.value = window.document.forms.registrationForm.receivePromo.checked;
        window.frames['registrationFrame'].document.forms[0].alertMessage.value = window.document.forms.registrationForm.alertMessage.checked;
        window.frames['registrationFrame'].document.forms[0].alertBuddy.value = window.document.forms.registrationForm.alertBuddy.checked;
        window.frames['registrationFrame'].document.forms[0].matching.value = window.document.forms.registrationForm.matching.checked;
        window.frames['registrationFrame'].document.forms[0].sex.value = window.document.forms.registrationForm.sex.value;
        window.frames['registrationFrame'].document.forms[0].birthDate.value = window.document.forms.registrationForm.birthDate.value;
        window.frames['registrationFrame'].document.forms[0].department.value = window.document.forms.registrationForm.department.value;
        window.frames['registrationFrame'].document.forms[0].sexPref.value = window.document.forms.registrationForm.sexPref.value;
        window.frames['registrationFrame'].document.forms[0].acceptConditions.value = window.document.forms.registrationForm.acceptConditions.checked;
        window.frames['registrationFrame'].document.forms[0].dataValid.value = 'true';
        window.frames['registrationFrame'].document.forms[0].submit();
    }
}


function doRegistrationProfileUpdate() {
    closeErrorMessageBox('registrationProfileErrorMessageBox');
    showProgress('registrationInProgress');
    
    window.frames['profileUpdateFrame'].document.forms[0].description.value = window.document.forms.registrationProfileUpdate.description.value;
    window.frames['profileUpdateFrame'].document.forms[0].like.value = window.document.forms.registrationProfileUpdate.like.value;
    window.frames['profileUpdateFrame'].document.forms[0].dislike.value = window.document.forms.registrationProfileUpdate.dislike.value;
    window.frames['profileUpdateFrame'].document.forms[0].registrationProfileUpdateValid.value = 'true';
    window.frames['profileUpdateFrame'].document.forms[0].submit();
}


function doProfileUpdate() {
    //closeErrorMessageBox('registrationProfileErrorMessageBox');
    showProgress('profileUpdateInProgress');
    
    window.frames['profileUpdateFrame'].document.forms[0].description.value = window.document.forms.profileUpdate.description.value;
    window.frames['profileUpdateFrame'].document.forms[0].like.value = window.document.forms.profileUpdate.like.value;
    window.frames['profileUpdateFrame'].document.forms[0].dislike.value = window.document.forms.profileUpdate.dislike.value;
    window.frames['profileUpdateFrame'].document.forms[0].department.value = window.document.forms.profileUpdate.department.value;
    window.frames['profileUpdateFrame'].document.forms[0].profileUpdateValid.value = 'true';
    window.frames['profileUpdateFrame'].document.forms[0].uploadPhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].changeCommentsValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].deletePhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].setMainPhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].submit();
}


function doPasswordUpdate() {
    if (checkPassword(-1)) {
        closeErrorMessageBox('registrationErrorMessageBox');
        
        showProgress('passwordChangeInProgress');
        
        window.frames['accountUpdateFrame'].document.forms[0].oldPassword.value = window.document.forms.changePasswordForm.oldPassword.value;
        window.frames['accountUpdateFrame'].document.forms[0].newPassword.value = window.document.forms.changePasswordForm.newPassword.value;
        window.frames['accountUpdateFrame'].document.forms[0].newPasswordConfirm.value = window.document.forms.changePasswordForm.newPasswordConfirm.value;
        window.frames['accountUpdateFrame'].document.forms[0].passwordChangeValid.value = 'true';
        window.frames['accountUpdateFrame'].document.forms[0].emailPhoneChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].sexPrefChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].submit();
    }
}


function doEmailPhoneUpdate() {
    if (checkEmailPhone(-1)) {
        closeErrorMessageBox('registrationErrorMessageBox');
        
        showProgress('emailPhoneChangeInProgress');
        
        window.frames['accountUpdateFrame'].document.forms[0].email.value = window.document.forms.changeInfoForm.email.value;
        window.frames['accountUpdateFrame'].document.forms[0].phone.value = window.document.forms.changeInfoForm.phone.value;
        window.frames['accountUpdateFrame'].document.forms[0].receivePromo.value = window.document.forms.changeInfoForm.receivePromo.checked;
        window.frames['accountUpdateFrame'].document.forms[0].alertMessage.value = window.document.forms.changeInfoForm.alertMessage.checked;
        window.frames['accountUpdateFrame'].document.forms[0].alertBuddy.value = window.document.forms.changeInfoForm.alertBuddy.checked;
        window.frames['accountUpdateFrame'].document.forms[0].matching.value = window.document.forms.changeInfoForm.matching.checked;
        window.frames['accountUpdateFrame'].document.forms[0].passwordChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].emailPhoneChangeValid.value = 'true';
        window.frames['accountUpdateFrame'].document.forms[0].sexPrefChangeValid.value = 'false';        
        window.frames['accountUpdateFrame'].document.forms[0].submit();
    }
}


function doSexPrefUpdate() {

        closeErrorMessageBox('registrationErrorMessageBox');   
        showProgress('sexPrefChangeInProgress');
        
        window.frames['accountUpdateFrame'].document.forms[0].sexPref.value = window.document.forms.changePrefForm.sexPref.value;
            
        window.frames['accountUpdateFrame'].document.forms[0].passwordChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].emailPhoneChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].sexPrefChangeValid.value = 'true';
        window.frames['accountUpdateFrame'].document.forms[0].submit();
        
    
}


function doSendValidateEmail() {

        closeErrorMessageBox('registrationErrorMessageBox');   
        showProgress('sendEmailInProgress');
        
        //window.frames['accountUpdateFrame'].document.forms[0].sexPref.value = window.document.forms.changePrefForm.sexPref.value;
            
        window.frames['accountUpdateFrame'].document.forms[0].passwordChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].emailPhoneChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].sexPrefChangeValid.value = 'false';
        window.frames['accountUpdateFrame'].document.forms[0].sendValidateEmail.value = 'true';
        window.frames['accountUpdateFrame'].document.forms[0].submit();
        
    
}


var UPLOAD_PHOTO_ERROR_PHOTO_NOT_SPECIFIED = 1;
var UPLOAD_PHOTO_ERROR_PHOTO_SIZE_TOO_BIG = 2;
var UPLOAD_PHOTO_ERROR_TOO_MANY_PHOTOS = 3;

function doUploadPhoto() {
    if (window.frames['photoUploadFrame'].document.forms[0].photoLocation.value == '') {
        displayPhotoUploadErrorMessage(UPLOAD_PHOTO_ERROR_PHOTO_NOT_SPECIFIED);
    }
    else {
        closeErrorMessageBox('updateProfileErrorMessageBox');
        showProgress('uploadPhotoInProgress');
        
        window.frames['photoUploadFrame'].document.forms[0].photoComment.value = window.document.forms.profileUpdate.photoComment.value;
        window.frames['photoUploadFrame'].document.forms[0].profileUpdateValid.value = 'false';
        window.frames['photoUploadFrame'].document.forms[0].uploadPhotoValid.value = 'true';
        window.frames['photoUploadFrame'].document.forms[0].changeCommentsValid.value = 'false';
        window.frames['photoUploadFrame'].document.forms[0].deletePhotoValid.value = 'false';
        window.frames['photoUploadFrame'].document.forms[0].setMainPhotoValid.value = 'false';
        window.frames['photoUploadFrame'].document.forms[0].submit();
    }
}


function doChangeComments() {
    //closeErrorMessageBox('registrationProfileErrorMessageBox');
    showProgress('changeCommentsInProgress');
    
    if (window.document.forms.profileUpdate.photoComment0) {
        window.frames['profileUpdateFrame'].document.forms[0].photoComment0.value = window.document.forms.profileUpdate.photoComment0.value;
        window.frames['profileUpdateFrame'].document.forms[0].photoFileID0.value = window.document.forms.profileUpdate.photoFileID0.value;
    }
    if (window.document.forms.profileUpdate.photoComment1) {
        window.frames['profileUpdateFrame'].document.forms[0].photoComment1.value = window.document.forms.profileUpdate.photoComment1.value;
        window.frames['profileUpdateFrame'].document.forms[0].photoFileID1.value = window.document.forms.profileUpdate.photoFileID1.value;
    }
    if (window.document.forms.profileUpdate.photoComment2) {
        window.frames['profileUpdateFrame'].document.forms[0].photoComment2.value = window.document.forms.profileUpdate.photoComment2.value;
        window.frames['profileUpdateFrame'].document.forms[0].photoFileID2.value = window.document.forms.profileUpdate.photoFileID2.value;
    }
    if (window.document.forms.profileUpdate.photoComment3) {
        window.frames['profileUpdateFrame'].document.forms[0].photoComment3.value = window.document.forms.profileUpdate.photoComment3.value;
        window.frames['profileUpdateFrame'].document.forms[0].photoFileID3.value = window.document.forms.profileUpdate.photoFileID3.value;
    }
    if (window.document.forms.profileUpdate.photoComment4) {
        window.frames['profileUpdateFrame'].document.forms[0].photoComment4.value = window.document.forms.profileUpdate.photoComment4.value;
        window.frames['profileUpdateFrame'].document.forms[0].photoFileID4.value = window.document.forms.profileUpdate.photoFileID4.value;
    }
    window.frames['profileUpdateFrame'].document.forms[0].profileUpdateValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].uploadPhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].changeCommentsValid.value = 'true';
    window.frames['profileUpdateFrame'].document.forms[0].deletePhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].setMainPhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].submit();
}


function doDeletePhoto(fileID, index) {
    if (confirm("Es-tu sûr de vouloir supprimer cette photo ?")) {
        document.getElementById('photoUpdateBox'+index).style.display = "none";
        
        var numberFlag0 = document.getElementById('numberFlag0');
        var numberFlag1 = document.getElementById('numberFlag1');
        var numberFlag2 = document.getElementById('numberFlag2');
        var numberFlag3 = document.getElementById('numberFlag3');
        var numberFlag4 = document.getElementById('numberFlag4');
        
        var photoUpdateBox0 = document.getElementById('photoUpdateBox0');
        var photoUpdateBox1 = document.getElementById('photoUpdateBox1');
        var photoUpdateBox2 = document.getElementById('photoUpdateBox2');
        var photoUpdateBox3 = document.getElementById('photoUpdateBox3');
        var photoUpdateBox4 = document.getElementById('photoUpdateBox4');
        
        var counter = 1;
        
        if (numberFlag0 && photoUpdateBox0 && photoUpdateBox0.style.display != "none") {
            numberFlag0.innerHTML = counter++;
            
        }
        
        if (numberFlag1 && photoUpdateBox1 && photoUpdateBox1.style.display != "none") {
            numberFlag1.innerHTML = counter++;
        }
        
        if (numberFlag2 && photoUpdateBox2 && photoUpdateBox2.style.display != "none") {
            numberFlag2.innerHTML = counter++;
        }
        
        if (numberFlag3 && photoUpdateBox3 && photoUpdateBox3.style.display != "none") {
            numberFlag3.innerHTML = counter++;
        }
        
        if (numberFlag4 && photoUpdateBox4 && photoUpdateBox4.style.display != "none") {
            numberFlag4.innerHTML = counter++;
        }
        
        window.frames['profileUpdateFrame'].document.forms[0].fileID.value = fileID;
        window.frames['profileUpdateFrame'].document.forms[0].profileUpdateValid.value = 'false';
        window.frames['profileUpdateFrame'].document.forms[0].uploadPhotoValid.value = 'false';
        window.frames['profileUpdateFrame'].document.forms[0].changeCommentsValid.value = 'false';
        window.frames['profileUpdateFrame'].document.forms[0].deletePhotoValid.value = 'true';
        window.frames['profileUpdateFrame'].document.forms[0].setMainPhotoValid.value = 'false';
        window.frames['profileUpdateFrame'].document.forms[0].submit();
    }
}


function doSetMainPhoto(fileID, index) {
    var mainPhotoFlag0 = document.getElementById('mainPhotoFlag0');
    var mainPhotoFlag1 = document.getElementById('mainPhotoFlag1');
    var mainPhotoFlag2 = document.getElementById('mainPhotoFlag2');
    var mainPhotoFlag3 = document.getElementById('mainPhotoFlag3');
    var mainPhotoFlag4 = document.getElementById('mainPhotoFlag4');
    
    var setMainPhoto0 = document.getElementById('setMainPhoto0');
    var setMainPhoto1 = document.getElementById('setMainPhoto1');
    var setMainPhoto2 = document.getElementById('setMainPhoto2');
    var setMainPhoto3 = document.getElementById('setMainPhoto3');
    var setMainPhoto4 = document.getElementById('setMainPhoto4');
    
    if (mainPhotoFlag0 && setMainPhoto0) {
        mainPhotoFlag0.style.display = "none";
        setMainPhoto0.style.display = "inline";
    }
    
    if (mainPhotoFlag1 && setMainPhoto1) {
        mainPhotoFlag1.style.display = "none";
        setMainPhoto1.style.display = "inline";
    }
    
    if (mainPhotoFlag2 && setMainPhoto2) {
        mainPhotoFlag2.style.display = "none";
        setMainPhoto2.style.display = "inline";
    }
    
    if (mainPhotoFlag3 && setMainPhoto3) {
        mainPhotoFlag3.style.display = "none";
        setMainPhoto3.style.display = "inline";
    }
    
    if (mainPhotoFlag4 && setMainPhoto4) {
        mainPhotoFlag4.style.display = "none";
        setMainPhoto4.style.display = "inline";
    }
    
    document.getElementById('mainPhotoFlag'+index).style.display = "inline";
    document.getElementById('setMainPhoto'+index).style.display = "none";
    
    window.frames['profileUpdateFrame'].document.forms[0].fileID.value = fileID;
    window.frames['profileUpdateFrame'].document.forms[0].profileUpdateValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].uploadPhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].changeCommentsValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].deletePhotoValid.value = 'false';
    window.frames['profileUpdateFrame'].document.forms[0].setMainPhotoValid.value = 'true';
    window.frames['profileUpdateFrame'].document.forms[0].submit();
}


function addUserIntoChat(userID) {
    window.frames['chatFrame'].document.forms[0].userID.value = userID;
    window.frames['chatFrame'].document.forms[0].addUserValid.value = 'true';
    window.frames['chatFrame'].document.forms[0].chatClosedValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].blackListValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].buddyListValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].submit();
}


function doChatClosedNotification() {
    window.frames['chatFrame'].document.forms[0].addUserValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].chatClosedValid.value = 'true';
    window.frames['chatFrame'].document.forms[0].blackListValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].buddyListValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].submit();
}


function doBlackListUser(userID) {
    window[userID].isInBlackList = !window[userID].isInBlackList;
    
    changeImage('blackListImage', getBlackListImage(window[userID].isInBlackList));
    
    window.frames['chatFrame'].document.forms[0].userID.value = userID;
    window.frames['chatFrame'].document.forms[0].addToBlack.value = (window[userID].isInBlackList);
    window.frames['chatFrame'].document.forms[0].addUserValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].chatClosedValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].blackListValid.value = 'true';
    window.frames['chatFrame'].document.forms[0].buddyListValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].submit();
}


function doBuddyListUser(userID, isInBuddyList) {
    window.frames['chatFrame'].document.forms[0].userID.value = userID;
    window.frames['chatFrame'].document.forms[0].addToBuddy.value = (!isInBuddyList);
    window.frames['chatFrame'].document.forms[0].addUserValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].chatClosedValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].blackListValid.value = 'false';
    window.frames['chatFrame'].document.forms[0].buddyListValid.value = 'true';
    window.frames['chatFrame'].document.forms[0].submit();
}


function doBuddyListUserFromChat(userID, isInBuddyList) {
    window.frames['chatFrame'].document.forms[0].fromProfile.value = 'false';
    doBuddyListUser(userID, isInBuddyList);
    // change image immediatelly (image is changed again after the action resturns the status)
    changeBuddyListButtonOnChat(userID, !isInBuddyList);
}


function doBuddyListUserFromProfile(userID, isInBuddyList) {
    window.frames['chatFrame'].document.forms[0].fromProfile.value = 'true';
    doBuddyListUser(userID, isInBuddyList);
    // change image immediatelly (image is changed again after the action resturns the status)
    changeBuddyListButtonOnProfile(userID, !isInBuddyList);
}


function doSendMessage() {
    showProgress('messageSentInProgress');
    
    if (window.document.forms.sendMessageForm.message.value == '') {
        displayMessageSentMessage('messageSentTextNotEntered');
    }
    else {
        window.frames['sentMessageFrame'].document.forms[0].message.value = window.document.forms.sendMessageForm.message.value;
        window.frames['sentMessageFrame'].document.forms[0].userID.value = window.document.forms.sendMessageForm.userID.value;
        window.frames['sentMessageFrame'].document.forms[0].messageSentValid.value = 'true';
        window.frames['sentMessageFrame'].document.forms[0].submit();
    }
}


// AJAX-WX handlers
// ::::::::::::::::::::::

function logout() {
    location.href = 'index.jsp';

    if (chatPopupOpened) {
        chatwin = chatwin = window.open('','chatwin','');
        chatwin.window.close();
    }
}

function displayLoginErrorMessage() {
    var letObject = document.getElementById("loginErrorText");
    letObject.style.display = "block";
    
    hideProgress('loginInProgress');
}


function displayPasswordSendErrorMessage() {
    var fptObject = document.getElementById("forgottenPasswordText");
    var fptiObject = document.getElementById("forgottenPasswordTextInvalid");
    fptObject.style.display = "none";
    fptiObject.style.display = "block";
    
    hideProgress('sendingEmailInProgress');
}


function displayPasswordSendOKMessage() {
    var fptObject = document.getElementById("forgottenPasswordText");
    var fpeObject = document.getElementById("forgottenPasswordEmail");
    var fpbObject = document.getElementById("forgottenPasswordButton");
    var fpsObject = document.getElementById("fpSubmit");
    var fptiObject = document.getElementById("forgottenPasswordTextInvalid");
    var fptvObject = document.getElementById("forgottenPasswordTextValid");

    fptObject.style.display = "none";
    fpeObject.style.display = "none";
    fpbObject.style.display = "none";
    fpsObject.style.display = "none";
    fptiObject.style.display = "none";
    fptvObject.style.display = "inline";
    
    hideProgress('sendingEmailInProgress');
}


function showForgottenPassword() {
    var fpLink = document.getElementById("loginSubmitText");
    var gpObject = document.getElementById("getPassword");
    fpLink.style.display = "none";
    gpObject.style.display = "inline";
    
    hideProgress('sendingEmailInProgress');
}


function displayRegistrationProfileUpdateErrorMessage() {
    hideProgress('registrationInProgress');
    openErrorMessageBox('registrationProfileErrorMessageBox', 'dislike', 23, 13);
}


function displayPhotoUploadErrorMessage(uploadPhotoError) {
    hideProgress('uploadPhotoInProgress');
    
    document.getElementById("upemb1").style.display = "none";
    document.getElementById("upemb2").style.display = "none";
    
    if (uploadPhotoError == UPLOAD_PHOTO_ERROR_PHOTO_SIZE_TOO_BIG) {
        document.getElementById("upemb1").style.display = "block";
    }
    else if (uploadPhotoError == UPLOAD_PHOTO_ERROR_PHOTO_NOT_SPECIFIED) {
        document.getElementById("upemb2").style.display = "block";
    }
    else if (uploadPhotoError == UPLOAD_PHOTO_ERROR_TOO_MANY_PHOTOS) {
        document.getElementById("upemb3").style.display = "block";
    }
    
    openErrorMessageBox('updateProfileErrorMessageBox', 'photoComment', -80, -45);
}


function displayProfileUpdateSuccessMessage(departmentLabel) {
    hideProgress('profileUpdateInProgress');
    
    if (departmentLabel.length>0) {
        document.getElementById('departmentLabel').innerHTML = departmentLabel;
    }
    
    // TODO: change this alert to layer message (but not red error message, but green success message??)
    alert('Le profil a été mis à jour !');

    //openErrorMessageBox('registrationProfileErrorMessageBox', 'dislike', 23, 13);
}


function displayCommentsUpdateSuccessMessage() {
    hideProgress('changeCommentsInProgress');
    
    // TODO: change this alert to layer message (but not red error message, but green success message??)
    alert('Le commentaire a été mis à jour !');

    //openErrorMessageBox('registrationProfileErrorMessageBox', 'dislike', 23, 13);
}


function displayPasswordUpdateSuccessMessage() {
    hideProgress('passwordChangeInProgress');
    
    // TODO: change this alert to layer message (but not red error message, but green success message??)
    alert('Le mot de passe a été mis à jour !');

    //openErrorMessageBox('registrationProfileErrorMessageBox', 'dislike', 23, 13);
}


function displayEmailPhoneUpdateSuccessMessage() {
    hideProgress('emailPhoneChangeInProgress');
    
    // TODO: change this alert to layer message (but not red error message, but green success message??)
    alert('Les préférences de réception ont été mises à jour !');

    //openErrorMessageBox('registrationProfileErrorMessageBox', 'dislike', 23, 13);
}

function displaySexPrefUpdateSuccessMessage() {
    hideProgress('sexPrefChangeInProgress');
        
    alert('Le profil a été mis à jour !');
    
}


function displaySendSucessValidateMailMessage() {
    hideProgress('sendEmailInProgress');
        
    alert('Un email contenant le lien de validation vient d\'être envoyé à cette adresse!');
    
}


function correctMainPhoto(photoID) {
    if (photoID == 0) {
        document.getElementById("changeCommentsButton").style.display = "none";
    }
    else {
        var mainPhotoFlag0 = document.getElementById('mainPhotoFlag0');
        var mainPhotoFlag1 = document.getElementById('mainPhotoFlag1');
        var mainPhotoFlag2 = document.getElementById('mainPhotoFlag2');
        var mainPhotoFlag3 = document.getElementById('mainPhotoFlag3');
        var mainPhotoFlag4 = document.getElementById('mainPhotoFlag4');
        
        var photoUpdateBox0 = document.getElementById('photoUpdateBox0');
        var photoUpdateBox1 = document.getElementById('photoUpdateBox1');
        var photoUpdateBox2 = document.getElementById('photoUpdateBox2');
        var photoUpdateBox3 = document.getElementById('photoUpdateBox3');
        var photoUpdateBox4 = document.getElementById('photoUpdateBox4');
        
        var counter = 1;
        
        if (mainPhotoFlag0 && photoUpdateBox0 && photoUpdateBox0.style.display != "none") {
            mainPhotoFlag0.style.display = "inline";
        }
        else if (mainPhotoFlag1 && photoUpdateBox1 && photoUpdateBox1.style.display != "none") {
            mainPhotoFlag1.style.display = "inline";
        }
        else if (mainPhotoFlag2 && photoUpdateBox2 && photoUpdateBox2.style.display != "none") {
            mainPhotoFlag2.style.display = "inline";
        }
        else if (mainPhotoFlag3 && photoUpdateBox3 && photoUpdateBox3.style.display != "none") {
            mainPhotoFlag3.style.display = "inline";
        }
        else if (mainPhotoFlag4 && photoUpdateBox4 && photoUpdateBox4.style.display != "none") {
            mainPhotoFlag4.style.display = "inline";
        }
    }
}


function clearSendMessageTextarea() {
    window.document.forms.sendMessageForm.message.value = '';
}



var messagesHidden = false;


function displayMessageSentMessage(messageName, isVisible) {
    messagesHidden = false;
    var mstObject = document.getElementById(messageName);
    mstObject.style.display = "block";
    
    hideProgress('messageSentInProgress');
}


function hideMessageSentMessages() {
    if (!messagesHidden) {
        var mstObject = document.getElementById('messageSentText');
        var mstneObject = document.getElementById('messageSentTextNotEntered');
        var mstnaObject = document.getElementById('messageSentTextNoAccess');
        
        mstObject.style.display = "none";
        mstneObject.style.display = "none";
        mstnaObject.style.display = "none";
        
        messagesHidden = true;
    }
}


var ADD_TO_BUDDYLIST_ERROR_LIST_FULL = -1;
var ADD_TO_BUDDYLIST_ERROR_ALREADY_CONTAINS_ID = -2;
var ADD_TO_BUDDYLIST_ERROR_WRONG_ID = -3;
var ADD_TO_BUDDYLIST_ERROR_EXCEPTION = -4;
var ADD_TO_BUDDYLIST_SUCCESS = 1;

var REMOVE_FROM_BUDDYLIST_ERROR = -101;
var REMOVE_FROM_BUDDYLIST_SUCCESS = 101;


function buddyListChanged(isInBuddyList, returnCode) {
    document.getElementById("blemb1").style.display = "none";
    document.getElementById("blemb2").style.display = "none";
    document.getElementById("blemb3").style.display = "none";
    
    if (returnCode == ADD_TO_BUDDYLIST_ERROR_LIST_FULL) {
        document.getElementById("blemb1").style.display = "block";
    }
    else if (returnCode == ADD_TO_BUDDYLIST_ERROR_ALREADY_CONTAINS_ID) {
        document.getElementById("blemb2").style.display = "block";
    }
    else if (returnCode < 0) {
        document.getElementById("blemb3").style.display = "block";
    }
    
    if (returnCode < 0) {
        openErrorMessageBox('buddyListErrorMessageBox', 'buddyListImage', -90, 0);
    }
    
    if (returnCode == ADD_TO_BUDDYLIST_SUCCESS || returnCode == ADD_TO_BUDDYLIST_ERROR_ALREADY_CONTAINS_ID || returnCode == REMOVE_FROM_BUDDYLIST_SUCCESS) {
        return true;
    }
    else {
        return false;
    }
}


function buddyListChangedFromChat(userID, isInBuddyList, returnCode) {
    var success = buddyListChanged(isInBuddyList, returnCode);
    
    changeBuddyListButtonOnChat(userID, isInBuddyList);
    window.opener.changeBuddyListButtonOnProfile(userID, isInBuddyList);
}


function buddyListChangedFromProfile(userID, isInBuddyList, returnCode) {
    var success = buddyListChanged(isInBuddyList, returnCode);
    
    changeBuddyListButtonOnProfile(userID, isInBuddyList);
    if (chatPopupOpened) {
        chatwin = window.open('','chatwin','');
        chatwin.window.changeBuddyListButtonOnChat(userID, isInBuddyList);
    }
}


function changeBuddyListButtonOnProfile(userID, isInBuddyList) {
    // check if there is the right user on the profile page
    if (profileUserID2Check != userID) {
        return;
    }
    
    profileIsInBuddyList = isInBuddyList;
    
    if (isInBuddyList) {
        document.getElementById('buddyListImage').src = PROFILE_IMG_BUTTON_REMOVE_FROM_CONTACTLIST;
    }
    else {
        document.getElementById('buddyListImage').src = PROFILE_IMG_BUTTON_ADD_TO_CONTACTLIST;
    }
}


function changeBuddyListButtonOnChat(userID, isInBuddyList) {
    window[userID].isInBuddyList = isInBuddyList;
    
    // check if there is the right user selected in chat window
    if (activeId != userID) {
        return;
    }
    
    changeImage('buddyListImage', getBuddyListImage(isInBuddyList));
}



// IE dropdown issue conflict (i have to disable tooltips while showing errorMessageBox)
var toolTipsEnabled = true;

var REGISTRATION_OK = 0;
var REGISTRATION_ERROR_USERNAME_ALREADY_EXISTS = 1;
var REGISTRATION_ERROR_USERNAME_TOO_SHORT = 2;
var REGISTRATION_ERROR_PASSWORD_TOO_SHORT = 4;
var REGISTRATION_ERROR_PASSWORDS_DONT_MATCH = 8;
var REGISTRATION_ERROR_EMAIL_NOT_VALID = 16;
var REGISTRATION_ERROR_SEX_NOT_SPECIFIED = 32;
var REGISTRATION_ERROR_BIRTHDATE_NOT_SPECIFIED = 64;
var REGISTRATION_ERROR_CONDITIONS_NOT_ACCEPTED = 128;

function checkRegistration(registrationError) {
    hideProgress('registrationInProgress');

    var userNameObject = window.document.forms.registrationForm.userName;
    var userNameExObject = document.getElementById("userNameEx");
    var userNameExObjectSpacer = document.getElementById("userNameExSpacer");
    
    var passwordObject = window.document.forms.registrationForm.password;
    var passwordExObject = document.getElementById("passwordEx");
    var passwordExObjectSpacer = document.getElementById("passwordExSpacer");
    
    var passwordConfirmObject = window.document.forms.registrationForm.passwordConfirm;
    var passwordConfirmExObject = document.getElementById("passwordConfirmEx");
    var passwordConfirmExObjectSpacer = document.getElementById("passwordConfirmExSpacer");
    
    var emailObject = window.document.forms.registrationForm.email;
    var emailExObject = document.getElementById("emailEx");
    var emailExObjectSpacer = document.getElementById("emailExSpacer");
    
    var acceptConditionsObject = window.document.forms.registrationForm.acceptConditions;
    var acceptConditionsExObject = document.getElementById("acceptConditionsEx");
    var acceptConditionsExObjectSpacer = document.getElementById("acceptConditionsExSpacer");
    
    var sexObject = window.document.forms.registrationForm.sex;
    var sexExObject = document.getElementById("sexEx");
    var sexExObjectSpacer = document.getElementById("sexExSpacer");
    
    var dayBirthDateObject = window.document.forms.registrationForm.DAY__birthDate;
    var monthBirthDateObject = window.document.forms.registrationForm.MONTH__birthDate;
    var yearBirthDateObject = window.document.forms.registrationForm.YEAR__birthDate;
    var birthDateExObject = document.getElementById("birthDateEx");
    var birthDateExObjectSpacer = document.getElementById("birthDateExSpacer");
    
    // clear error highlights
    userNameObject.className = "registrationInput";
    passwordObject.className = "registrationInput";
    passwordConfirmObject.className = "registrationInput";
    emailObject.className = "registrationInput";
    acceptConditionsObject.className = "";
    
    userNameExObject.style.display = "none";
    userNameExObjectSpacer.style.display = "inline";
    
    passwordExObject.style.display = "none";
    passwordExObjectSpacer.style.display = "inline";
    
    passwordConfirmExObject.style.display = "none";
    passwordConfirmExObjectSpacer.style.display = "inline";
    
    emailExObject.style.display = "none";
    emailExObjectSpacer.style.display = "inline";
    
    acceptConditionsExObject.style.display = "none";
    acceptConditionsExObjectSpacer.style.display = "inline";
    
    sexExObject.style.display = "none";
    sexExObjectSpacer.style.display = "inline";
    
    birthDateExObject.style.display = "none";
    birthDateExObjectSpacer.style.display = "inline";
    
    document.getElementById("remb2").style.display = "none";
    document.getElementById("remb4").style.display = "none";
    document.getElementById("remb8").style.display = "none";
    document.getElementById("remb16").style.display = "none";
    document.getElementById("remb32").style.display = "none";
    document.getElementById("remb64").style.display = "none";
    document.getElementById("remb128").style.display = "none";
    
    if (registrationError<0) {
        registrationError=0;
        
        if (userNameObject.value.length<5) {
            registrationError = (registrationError | REGISTRATION_ERROR_USERNAME_TOO_SHORT);
        }
        
        if (passwordObject.value.length<5) {
            registrationError = (registrationError | REGISTRATION_ERROR_PASSWORD_TOO_SHORT);
        }
        
        if (passwordObject.value != passwordConfirmObject.value) {
            registrationError = (registrationError | REGISTRATION_ERROR_PASSWORDS_DONT_MATCH);
        }
        
        if (!checkEmail(emailObject.value, 3)) {
            registrationError = (registrationError | REGISTRATION_ERROR_EMAIL_NOT_VALID);
        }
        
        if (sexObject.selectedIndex == 0) {
            registrationError = (registrationError | REGISTRATION_ERROR_SEX_NOT_SPECIFIED);
        }
        
        if (dayBirthDateObject.selectedIndex == 0 || monthBirthDateObject.selectedIndex == 0 || yearBirthDateObject.selectedIndex == 0) {
            registrationError = (registrationError | REGISTRATION_ERROR_BIRTHDATE_NOT_SPECIFIED);
        }
        
        if (!(acceptConditionsObject.checked)) {
            registrationError = (registrationError | REGISTRATION_ERROR_CONDITIONS_NOT_ACCEPTED);
        }
    }
    
    if (registrationError == REGISTRATION_OK) {
        return true;
    }
    else if (registrationError == REGISTRATION_ERROR_USERNAME_ALREADY_EXISTS) {
        userNameObject.className = "registrationInputError";
        userNameExObject.style.display = "inline";
        userNameExObjectSpacer.style.display = "none";
        document.getElementById("remb2").style.display = "block";
        
      	document.getElementById("registrationUserExistsBox").style.top = findPosY(document.getElementById('receivePromo'))+23+"px";
      	document.getElementById("registrationUserExistsBox").style.left = findPosX(document.getElementById('receivePromo'))+13+"px";
        document.getElementById("registrationUserExistsBox").style.display="inline";
        hideselect(document.getElementById("registrationUserExistsBox"),true);
        toolTipsEnabled = false;
        
        return false;
    }
    else {
        if ((registrationError & REGISTRATION_ERROR_USERNAME_TOO_SHORT) == REGISTRATION_ERROR_USERNAME_TOO_SHORT) {
            userNameObject.className = "registrationInputError";
            userNameExObject.style.display = "inline";
            userNameExObjectSpacer.style.display = "none";
            document.getElementById("remb2").style.display = "block";
        }
        
        if ((registrationError & REGISTRATION_ERROR_PASSWORD_TOO_SHORT) == REGISTRATION_ERROR_PASSWORD_TOO_SHORT) {
            passwordObject.className = "registrationInputError";
            passwordExObject.style.display = "inline";
            passwordExObjectSpacer.style.display = "none";
            document.getElementById("remb4").style.display = "block";
        }
        
        if ((registrationError & REGISTRATION_ERROR_PASSWORDS_DONT_MATCH) == REGISTRATION_ERROR_PASSWORDS_DONT_MATCH) {
            passwordObject.className = "registrationInputError";
            passwordExObject.style.display = "inline";
            passwordExObjectSpacer.style.display = "none";
            passwordConfirmObject.className = "registrationInputError";
            passwordConfirmExObject.style.display = "inline";
            passwordConfirmExObjectSpacer.style.display = "none";
            document.getElementById("remb8").style.display = "block";
        }
        
        if ((registrationError & REGISTRATION_ERROR_EMAIL_NOT_VALID) == REGISTRATION_ERROR_EMAIL_NOT_VALID) {
            emailObject.className = "registrationInputError";
            emailExObject.style.display = "inline";
            emailExObjectSpacer.style.display = "none";
            document.getElementById("remb16").style.display = "block";
        }
        
        if ((registrationError & REGISTRATION_ERROR_SEX_NOT_SPECIFIED) == REGISTRATION_ERROR_SEX_NOT_SPECIFIED) {
            sexExObject.style.display = "inline";
            sexExObjectSpacer.style.display = "none";
            document.getElementById("remb32").style.display = "block";
        }
        
        if ((registrationError & REGISTRATION_ERROR_BIRTHDATE_NOT_SPECIFIED) == REGISTRATION_ERROR_BIRTHDATE_NOT_SPECIFIED) {
            birthDateExObject.style.display = "inline";
            birthDateExObjectSpacer.style.display = "none";
            document.getElementById("remb64").style.display = "block";
        }
        
        if ((registrationError & REGISTRATION_ERROR_CONDITIONS_NOT_ACCEPTED) == REGISTRATION_ERROR_CONDITIONS_NOT_ACCEPTED) {
            acceptConditionsObject.className = "registrationCheckBoxError";
            acceptConditionsExObject.style.display = "inline";
            acceptConditionsExObjectSpacer.style.display = "none";
            document.getElementById("remb128").style.display = "block";
        }
        
        openErrorMessageBox('registrationErrorMessageBox', 'receivePromo', 23, 13);
        
        return false;
    }
}


var ACCOUNT_UPDATE_OK = 0;
var ACCOUNT_UPDATE_ERROR_OLD_PASSWORD_DOESNT_MATCH = 1;
var ACCOUNT_UPDATE_ERROR_NEW_PASSWORD_TOO_SHORT = 2;
var ACCOUNT_UPDATE_ERROR_PASSWORDS_DONT_MATCH = 4;
var ACCOUNT_UPDATE_ERROR_PHONE_NOT_VALID = 8;
var ACCOUNT_UPDATE_ERROR_EMAIL_NOT_VALID = 16;

function checkPassword(accountUpdateError) {
    hideProgress('passwordChangeInProgress');

    var oldPasswordObject = window.document.forms.changePasswordForm.oldPassword;
    var oldPasswordExObject = document.getElementById("oldPasswordEx");
    var oldPasswordExObjectSpacer = document.getElementById("oldPasswordExSpacer");
    
    var newPasswordObject = window.document.forms.changePasswordForm.newPassword;
    var newPasswordExObject = document.getElementById("newPasswordEx");
    var newPasswordExObjectSpacer = document.getElementById("newPasswordExSpacer");
    
    var newPasswordConfirmObject = window.document.forms.changePasswordForm.newPasswordConfirm;
    var newPasswordConfirmExObject = document.getElementById("newPasswordConfirmEx");
    var newPasswordConfirmExObjectSpacer = document.getElementById("newPasswordConfirmExSpacer");
    
    // clear error highlights
    oldPasswordObject.className = "registrationInput";
    newPasswordObject.className = "registrationInput";
    newPasswordConfirmObject.className = "registrationInput";
    
    oldPasswordExObject.style.display = "none";
    oldPasswordExObjectSpacer.style.display = "inline";
    
    newPasswordExObject.style.display = "none";
    newPasswordExObjectSpacer.style.display = "inline";
    
    newPasswordConfirmExObject.style.display = "none";
    newPasswordConfirmExObjectSpacer.style.display = "inline";
    
    document.getElementById("remb2").style.display = "none";
    document.getElementById("remb4").style.display = "none";
    document.getElementById("remb8").style.display = "none";
    document.getElementById("remb16").style.display = "none";
    document.getElementById("remb32").style.display = "none";
    
    if (accountUpdateError<0) {
        accountUpdateError=0;
        
        if (newPasswordObject.value.length<5) {
            accountUpdateError = (accountUpdateError | ACCOUNT_UPDATE_ERROR_NEW_PASSWORD_TOO_SHORT);
        }
        
        if (newPasswordObject.value != newPasswordConfirmObject.value) {
            accountUpdateError = (accountUpdateError | ACCOUNT_UPDATE_ERROR_PASSWORDS_DONT_MATCH);
        }
    }
    
    if (accountUpdateError == REGISTRATION_OK) {
        return true;
    }
    else {
        if ((accountUpdateError & ACCOUNT_UPDATE_ERROR_OLD_PASSWORD_DOESNT_MATCH) == ACCOUNT_UPDATE_ERROR_OLD_PASSWORD_DOESNT_MATCH) {
            oldPasswordObject.className = "registrationInputError";
            oldPasswordExObject.style.display = "inline";
            oldPasswordExObjectSpacer.style.display = "none";
            document.getElementById("remb2").style.display = "block";
        }

        if ((accountUpdateError & ACCOUNT_UPDATE_ERROR_NEW_PASSWORD_TOO_SHORT) == ACCOUNT_UPDATE_ERROR_NEW_PASSWORD_TOO_SHORT) {
            newPasswordObject.className = "registrationInputError";
            newPasswordExObject.style.display = "inline";
            newPasswordExObjectSpacer.style.display = "none";
            document.getElementById("remb4").style.display = "block";
        }
        
        if ((accountUpdateError & ACCOUNT_UPDATE_ERROR_PASSWORDS_DONT_MATCH) == ACCOUNT_UPDATE_ERROR_PASSWORDS_DONT_MATCH) {
            newPasswordObject.className = "registrationInputError";
            newPasswordExObject.style.display = "inline";
            newPasswordExObjectSpacer.style.display = "none";
            newPasswordConfirmObject.className = "registrationInputError";
            newPasswordConfirmExObject.style.display = "inline";
            newPasswordConfirmExObjectSpacer.style.display = "none";
            document.getElementById("remb8").style.display = "block";
        }
        
        openErrorMessageBox('registrationErrorMessageBox', 'newPasswordConfirm', 73, -83);
        
        return false;
    }
}


function checkEmailPhone(accountUpdateError) {
    hideProgress('emailPhoneChangeInProgress');

    var emailObject = window.document.forms.changeInfoForm.email;
    var emailExObject = document.getElementById("emailEx");
    var emailExObjectSpacer = document.getElementById("emailExSpacer");
    
    var phoneObject = window.document.forms.changeInfoForm.phone;
    var phoneExObject = document.getElementById("phoneEx");
    var phoneExObjectSpacer = document.getElementById("phoneExSpacer");
    
    // clear error highlights
    emailObject.className = "registrationInput";
    phoneObject.className = "registrationInput";
    
    emailExObject.style.display = "none";
    emailExObjectSpacer.style.display = "inline";
    
    phoneExObject.style.display = "none";
    phoneExObjectSpacer.style.display = "inline";
    
    document.getElementById("remb2").style.display = "none";
    document.getElementById("remb4").style.display = "none";
    document.getElementById("remb8").style.display = "none";
    document.getElementById("remb16").style.display = "none";
    document.getElementById("remb32").style.display = "none";
    
    if (accountUpdateError<0) {
        accountUpdateError=0;
        
        if (!checkEmail(emailObject.value, 3)) {
            accountUpdateError = (accountUpdateError | ACCOUNT_UPDATE_ERROR_EMAIL_NOT_VALID);
        }
		// phone is not obligatory, when leave fone textbox blank still can update
        if (phoneObject.value.length > 0) {
        if (!checkMobilePhone(phoneObject.value)) {
            accountUpdateError = (accountUpdateError | ACCOUNT_UPDATE_ERROR_PHONE_NOT_VALID);
        }
        }
    }
    
    if (accountUpdateError == REGISTRATION_OK) {
        return true;
    }
    else {
        if ((accountUpdateError & ACCOUNT_UPDATE_ERROR_EMAIL_NOT_VALID) == ACCOUNT_UPDATE_ERROR_EMAIL_NOT_VALID) {
            emailObject.className = "registrationInputError";
            emailExObject.style.display = "inline";
            emailExObjectSpacer.style.display = "none";
            document.getElementById("remb16").style.display = "block";
        }

        if ((accountUpdateError & ACCOUNT_UPDATE_ERROR_PHONE_NOT_VALID) == ACCOUNT_UPDATE_ERROR_PHONE_NOT_VALID) {
            phoneObject.className = "registrationInputError";
            phoneExObject.style.display = "inline";
            phoneExObjectSpacer.style.display = "none";
            document.getElementById("remb32").style.display = "block";
        }
        
        openErrorMessageBox('registrationErrorMessageBox', 'receivePromo', -223, -33);
        
        return false;
    }
}


function openErrorMessageBox(errorMessageBoxName, anchorObjectName, topOffset, leftOffset) {
  	document.getElementById(errorMessageBoxName).style.top = findPosY(document.getElementById(anchorObjectName))+topOffset+"px";
  	document.getElementById(errorMessageBoxName).style.left = findPosX(document.getElementById(anchorObjectName))+leftOffset+"px";
    document.getElementById(errorMessageBoxName).style.display="inline";
    hideselect(document.getElementById(errorMessageBoxName),true);
    toolTipsEnabled = false;
}


function closeErrorMessageBox(errorMessageBoxName) {
    document.getElementById(errorMessageBoxName).style.display="none";
    hideselect(document.getElementById(errorMessageBoxName),false);
    toolTipsEnabled = true;
}


function submitNewPseudo() {
    window.document.forms.registrationForm.userName.value = document.getElementById("newUserName").value;

    document.getElementById("registrationUserExistsBox").style.display="none";
    hideselect(document.getElementById("registrationUserExistsBox"),false);
    toolTipsEnabled = true;
    
    doRegistration();
}


function openUserNameSuggestionsDialog(userNameSuggestions) {
    hideProgress('registrationInProgress');
    
    eval("var suggestionsArray = new Array(" + userNameSuggestions + ");");
    writeUserNameSuggestions(suggestionsArray);
    checkRegistration(REGISTRATION_ERROR_USERNAME_ALREADY_EXISTS);
}


function writeUserNameSuggestions(suggestionsArray) {
    var suggestionsObjectContent = "";
    var checked = "";
    for (i=0; i<suggestionsArray.length; i++) {
        if (i==0) {
            checked = "checked";
            document.getElementById("newUserName").value=suggestionsArray[i];
        }
        else {
            checked = "";
        }
        suggestionsObjectContent += '<div class="userNameSuggestionRow"><span style="vertical-align:middle;"><input type="radio" '+checked+' onclick="setUserNameSuggestion(this.value);" name="userNameSuggestions" id="userNameSuggestions" value="'+suggestionsArray[i]+'"/></span><span style="vertical-align:middle; /*background-color:#00ff00;*/">'+suggestionsArray[i]+'</span></div>';
    }
    
    var suggestionsObject = document.getElementById("registrationUserExistsBoxSuggestions");
    suggestionsObject.innerHTML = suggestionsObjectContent;
}


function setUserNameSuggestion(newValue) {
    document.getElementById("newUserName").value=newValue;
}


function resetSuggestionSelection() {
    var suggestionElements = document.getElementsByName("userNameSuggestions");
    if (suggestionElements) {
        for (i=0; i<suggestionElements.length; i++) {
            suggestionElements[i].checked = false;
        }
    }
}


function openChatWindow(userID) {
    openChat(chatWindowURL, userID);
}


function openOnlineNotification(userID) {
    popUp(onlineNotificationWindowURL + '?userID=' + userID, 380, 170, 'onlinenotification');
}


// CHAT WINDOW
// ::::::::::::::::::::::


function popUpChat(path, w, h, handle) {
	var t=(screen.height/2)-(h/2)-50;
	var l=(screen.width/2)-(w/2);
	var windowprops = "location=no,status=no,scrollbars=no,menubars=no,toolbars=no,resizable=no, left=" + l + ",top=" + t + ",width=" + w + ",height=" + h;

	popwin = window.open('','chatwin',windowprops);
	if (popwin.window.users == null) {
		//popwin.document.location = path; IE6 bug...
		popwin.window.location = path;
	}
	return popwin;
}


function openChat(baseURL,id) {
	var path = baseURL+'?userID='+id;
	chatwin = popUpChat(path,576,383,'chatwin');
	
	if (chatwin.window.users) {
	   chatwin.window.addUserIntoChat(id);
	   chatwin.window.focus();
	}
}



// AOL STUFF
// ::::::::::::::::::::::


function detectBrowser(){
		 if(!document.getElementById)
		     {
		      var alerte = "Certaines fonctionnalitÃ©s avancÃ©es qu'utilise ce site ne sont pas supportÃ©es par votre version de Navigateur.\nVeuillez utiliser une version plus rÃ©cente.\nVous allez Ãªtre redirigÃ© vers http://www.netscape.fr."
		      alert(alerte);
		      document.location.href="http://www.netscape.fr";
     }
	}
// SEARCH FUNCTIONS

/*FORM CONTROL*/
var shakeCount=0;
var shakeSwitch=1;

function shake()
{
	var Obj = document.getElementById("bienv");
	var Qfield = document.req.query;
	shakeSwitch=shakeSwitch*(-1);
	Obj.style.left=parseFloat(Obj.style.left)+shakeSwitch+"em";
	Qfield.value="Veuillez entrer un terme";
	Qfield.blur();
	Qfield.style.color="red";
	if(shakeCount!=3)
	{
		var timer=setTimeout(shake,150);
		shakeCount=shakeCount+1;
	}
	else
	{
		clearTimeout(timer);
		shakeCount=0;
		return false;
	}
}

function queryBehavior(obj)
{
	if(obj.value=='Veuillez entrer un terme')
		obj.value='';
		obj.style.color='#000';
}
function search_focus()
{
	document.req.query.focus();
}
/*FORM CONTROL*/
/*SEARCH URL FORMAT */
var gSearchMode="wf";
function switchMode(mode)
{
	if(mode=="wf")
		gSearchMode="wm";
	else
		gSearchMode="wf";
}
function myEscape(s)
{
	return escape(s).replace(/\+/g, "%2B").replace(/\//g, "%2F");
}
function searchUrl(mode)
{
	var dns="http://www.recherche.aol.fr/";
	var searchurl=dns;
	var p1="";
	if(mode=="wm")
		p1 = 'search?enc=iso&service=WebMondial&first=1&last=10&query=';
	else
		p1 = 'rech?enc=iso&q=';
		searchurl+=p1;
		searchurl+=myEscape(document.req.query.value);
		document.req.url.value=searchurl;
}

function submitUrl()
{
	if((!document.req.query.value || document.req.query.value=="Veuillez entrer un terme") && shakeCount==0)
	{
		search_focus();
		shake();
	}
	else
	{
		searchUrl(gSearchMode);
		window.location.href=document.req.url.value;
	}
}
/*SEARCH URL FORMAT */
// SEARCH FUNCTIONS
