// ********************************************************
// *** Code Javascript pour la gestion des utilisateurs	***
// *** Fiche produit - CVOMarket V3.00.00				***
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// *** Version script	1.00.00							***
// *** Date				13/08/2008						***
// ********************************************************

// ************************************************
// *** Login: Vérification de la  saisie lors	***
// *** d'une phase d'identification				***
// ************************************************
function doVerifyLoginFormDatas(TLibVar_BoxName){
	var TLibVar_POSTValues	= new String();
	var TLibVar_UserLog		= new String();
	var TLibVar_PassLog		= new String();
	var TLibVar_CryptPassLog= new String();

	TLibVar_UserLog		= CVOM_TrimString(document.getElementById('ident_user').value);
	TLibVar_PassLog		= CVOM_TrimString(document.getElementById('ident_pass').value);
	TLibVar_CryptPassLog= MD5(TLibVar_UserLog+'*'+TLibVar_PassLog);

	if (!doCheckValidMail(TLibVar_UserLog) || TLibVar_PassLog.length<4){
		alert('Va rugam sa introduceti adresa dvs. de e-mail si parola!');
	}else{
		// Effacer le mot de passe
		document.getElementById('ident_pass').value = '';
		TLibVar_POSTValues = 'BoxToInclude='+encodeURIComponent(CVOM_TrimString(document.getElementById('ident_includeafterlog').value));
		TLibVar_POSTValues+= '&action=doVerifyUserIdent';
		TLibVar_POSTValues+= '&UserLog='+encodeURIComponent(TLibVar_UserLog);
		TLibVar_POSTValues+= '&PassLog='+encodeURIComponent(TLibVar_CryptPassLog);
		// *** Afficher un message d'attente ***
		document.getElementById(TLibVar_BoxName).style.display = "block";
		document.getElementById(TLibVar_BoxName).innerHTML = CVOMVar_MessageWait2;
		// *** Appel ajax - enregistrement nouveau client ***
		CVRSAjaxQueryURL('POST','/lib/include/modules/CVRSTBox_UserManagement.php',TLibVar_POSTValues,TLibVar_BoxName);
	}
}

// **********************************
// *** Login: Rappel mot de passe ***
// **********************************
function doRememberPassword(TLibVar_BoxName){
	TLibVar_POSTValues = 'BoxToInclude=doRememberPasswordForm';
	// *** Afficher un message d'attente ***
	document.getElementById(TLibVar_BoxName).style.display = "block";
	document.getElementById(TLibVar_BoxName).innerHTML = CVOMVar_MessageWait2;
	// *** Appel ajax - enregistrement nouveau client ***
	CVRSAjaxQueryURL('POST','/lib/include/modules/CVRSTBox_UserManagement.php',TLibVar_POSTValues,TLibVar_BoxName);
}
function doSendUserDatas(TLibVar_BoxName){
	var TLibVar_UserMail = new String();

	TLibVar_UserMail = CVOM_TrimString(document.getElementById('remember_user').value);

	if (!doCheckValidMail(TLibVar_UserMail)){
		alert('Va rugam sa introduceti o adresa de e-mail valida!');
	}else{
		TLibVar_POSTValues = 'BoxToInclude=doRememberPasswordForm';
		TLibVar_POSTValues+= '&action=doSendUserDatas';
		TLibVar_POSTValues+= '&UserMail='+encodeURIComponent(TLibVar_UserMail);;
		// *** Afficher un message d'attente ***
		document.getElementById(TLibVar_BoxName).style.display = "block";
		document.getElementById(TLibVar_BoxName).innerHTML = CVOMVar_MessageWait2;
		// *** Appel ajax - enregistrement nouveau client ***
		CVRSAjaxQueryURL('POST','/lib/include/modules/CVRSTBox_UserManagement.php',TLibVar_POSTValues,TLibVar_BoxName);
	}
}

// *******************************************
// *** Aficher le ticket du panier virtuel ***
// *******************************************
function doDisplayTicket(TLibVar_BoxName){
	TLibVar_POSTValues = 'BoxToInclude=doDisplayClientTicket';
	// *** Afficher un message d'attente ***
	document.getElementById(TLibVar_BoxName).style.display = "block";
	document.getElementById(TLibVar_BoxName).innerHTML = CVOMVar_MessageWait2;
	// *** Appel ajax - enregistrement nouveau client ***
	CVRSAjaxQueryURL('POST','/lib/include/modules/CVRSTBox_UserManagement.php',TLibVar_POSTValues,TLibVar_BoxName);
}

// ************************************************
// *** Nouveau compte: Société ou particulier?	***
// ************************************************
function doSwitchCompanyPersonTypeRegister(TLibVar_TypeThirdAccount){
    if (TLibVar_TypeThirdAccount == 'pj'){
    	document.getElementById('third_accounttype').value = TLibVar_TypeThirdAccount;
		document.getElementById('TBoxContentCompanyType').style.display = "block";
		document.getElementById('TBoxContentPersonType').style.display = "none";
	}else{
    	document.getElementById('third_accounttype').value = TLibVar_TypeThirdAccount;
		document.getElementById('TBoxContentCompanyType').style.display = "none";
		document.getElementById('TBoxContentPersonType').style.display = "block";
	}
}

// ********************************************
// *** Vérifier le formulaire d'ajout tiers ***
// ********************************************
function doCheckRegisterThirdForm(TLibVar_BoxForm,TLibVar_BoxMessage){
	var TLibVar_ThirdAccType= new String();
	var TLibVar_ThirdCType	= new String();
	var TLibVar_ThirdCName	= new String();
	var TLibVar_ThirdROAttr	= new String();
	var TLibVar_ThirdCIFCNP	= new String();
	var TLibVar_ThirdCodR	= new String();
	var TLibVar_ThirdCFName	= new String();
	var TLibVar_ThirdCLName	= new String();
	var TLibVar_ThirdAddr	= new String();
	var TLibVar_ThirdAddr1	= new String();
	var TLibVar_ThirdZip	= new String();
	var TLibVar_ThirdCity	= new String();
	var TLibVar_ThirdROJud	= new String();
	var TLibVar_ThirdROJudN	= new Number(0);
	var TLibVar_ThirdCountry= new String();
	var TLibVar_ThirdPhone	= new String();
	var TLibVar_ThirdGSM	= new String();
	var TLibVar_ThirdFax	= new String();
	var TLibVar_ThirdBank	= new String();
	var TLibVar_ThirdIBAN	= new String();
	var TLibVar_ThirdMail	= new String();
	var TLibVar_ThirdPass	= new String();
	var TLibVar_ThirdPass2	= new String();
	var TLibVar_ThirdCPass	= new String();
	var TLibVar_POSTValues	= new String();
/*
	var TLibVar_ThirdNewStatut		= new String('y');
	var TLibVar_ThirdNotifyAccount	= new String('n');
	var TLibVar_ThirdNotifyUserPass	= new String('n');
*/
	// ***************************
	// *** Filtrer les entrées ***
	// ***************************
	TLibVar_ThirdCType= document.getElementById('third_accounttype').value;
	if (TLibVar_ThirdCType == 'pj'){
		//TLibVar_ThirdCType = document.getElementById('third_typecompany').value;
		TLibVar_ThirdCName	= CVOM_TrimString(document.getElementById('third_companyname').value);
		TLibVar_ThirdROAttr	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_roattribute').value));
		TLibVar_ThirdCIFCNP	= CVOM_TrimString(document.getElementById('third_companycif').value);
		TLibVar_ThirdCodR	= CVOM_TrimString(document.getElementById('third_companyregcom').value);
		TLibVar_ThirdCFName	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companycontactfname').value));
		TLibVar_ThirdCLName	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companycontactlname').value));
	}else{
		//TLibVar_ThirdCType = document.getElementById('third_typeperson').value;
		TLibVar_ThirdCFName	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companyfname').value));
		TLibVar_ThirdCLName	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companylname').value));
		TLibVar_ThirdCName	= TLibVar_ThirdCFName+' '+TLibVar_ThirdCLName;
		TLibVar_ThirdCIFCNP	= CVOM_TrimString(document.getElementById('third_companycnp').value);
	}
	TLibVar_ThirdAddr	= CVOM_TrimString(document.getElementById('third_companyaddr').value);
	TLibVar_ThirdAddr1	= CVOM_TrimString(document.getElementById('third_companyaddrcpl').value);
	TLibVar_ThirdZip	= CVOM_TrimString(document.getElementById('third_companyzip').value);
	TLibVar_ThirdCity	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companycity').value));
	TLibVar_ThirdROJud	= document.getElementById('third_companyjudetro').options[document.getElementById('third_companyjudetro').selectedIndex].text;
	TLibVar_ThirdROJudN	= document.getElementById('third_companyjudetro').options[document.getElementById('third_companyjudetro').selectedIndex].value;
	TLibVar_ThirdCountry= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companycountry').value));
	TLibVar_ThirdPhone	= CVOM_TrimString(document.getElementById('third_companyphone').value);
	TLibVar_ThirdGSM	= CVOM_TrimString(document.getElementById('third_companygsm').value);
	TLibVar_ThirdFax	= CVOM_TrimString(document.getElementById('third_companyfax').value);
	TLibVar_ThirdBank	= CVOM_TrimString(FilterValueToAlpha(document.getElementById('third_companybank').value));
	TLibVar_ThirdIBAN	= CVOM_TrimString(document.getElementById('third_companyiban').value);
	TLibVar_ThirdMail	= CVOM_TrimString(document.getElementById('third_companymail').value);
	TLibVar_ThirdPass	= CVOM_TrimString(document.getElementById('third_companypass').value);
	TLibVar_ThirdPass2	= CVOM_TrimString(document.getElementById('third_companypassconfirm').value);
	TLibVar_ThirdCPass	= MD5(TLibVar_ThirdMail+'*'+TLibVar_ThirdPass);

	if (TLibVar_ThirdPass.valueOf() != TLibVar_ThirdPass2.valueOf() ||
		TLibVar_ThirdPass.length<4){
		alert('Va rugam sa introduceti o parola valida si sa o confirmati!\n(min. 4 caractere) '+TLibVar_ThirdPass+' - '+TLibVar_ThirdPass2+ ' '+TLibVar_ThirdPass.length);
	}else{
		TLibVar_POSTValues = 'BoxToInclude='+escape(document.getElementById('BoxToInclude').value);
		TLibVar_POSTValues+= '&action='+escape(document.getElementById('action').value);
		TLibVar_POSTValues+= '&IdThird='+parseInt(document.getElementById('IdThird').value);
		TLibVar_POSTValues+= '&ThirdType='+escape(TLibVar_ThirdCType);
		TLibVar_POSTValues+= '&Company='+escape(TLibVar_ThirdCName);
		TLibVar_POSTValues+= '&ROAttrib='+escape(TLibVar_ThirdROAttr);
		TLibVar_POSTValues+= '&CIFCNP='+escape(TLibVar_ThirdCIFCNP);
		TLibVar_POSTValues+= '&CodR='+escape(TLibVar_ThirdCodR);
		TLibVar_POSTValues+= '&ContactFName='+escape(TLibVar_ThirdCFName);
		TLibVar_POSTValues+= '&ContactLName='+escape(TLibVar_ThirdCLName);
		TLibVar_POSTValues+= '&Address='+escape(TLibVar_ThirdAddr);
		TLibVar_POSTValues+= '&AddressCpl='+escape(TLibVar_ThirdAddr1);
		TLibVar_POSTValues+= '&AddressZip='+escape(TLibVar_ThirdZip);
		TLibVar_POSTValues+= '&AddressCity='+escape(TLibVar_ThirdCity);
		TLibVar_POSTValues+= '&AddressROJud='+escape(TLibVar_ThirdROJud);
		TLibVar_POSTValues+= '&AddressROJudN='+escape(TLibVar_ThirdROJudN);
		TLibVar_POSTValues+= '&AddressCountry='+escape(TLibVar_ThirdCountry);
		TLibVar_POSTValues+= '&Phone='+escape(TLibVar_ThirdPhone);
		TLibVar_POSTValues+= '&GSM='+escape(TLibVar_ThirdGSM);
		TLibVar_POSTValues+= '&Fax='+escape(TLibVar_ThirdFax);
		TLibVar_POSTValues+= '&Bank='+escape(TLibVar_ThirdBank);
		TLibVar_POSTValues+= '&IBAN='+escape(TLibVar_ThirdIBAN);
		TLibVar_POSTValues+= '&Mail='+encodeURIComponent(TLibVar_ThirdMail);
		TLibVar_POSTValues+= '&Pass='+escape(TLibVar_ThirdPass);
		TLibVar_POSTValues+= '&CryptedPass='+escape(TLibVar_ThirdCPass);
		TLibVar_POSTValues+= '&Statut=s'
		// *** Afficher un message d'attente ***
		document.getElementById(TLibVar_BoxMessage).style.display = "block";
		document.getElementById(TLibVar_BoxMessage).innerHTML = CVOMVar_MessageWait;
		// *** Réduire la boîte avec le formulaire ***
		document.getElementById(TLibVar_BoxForm).style.display = "none";
		// *** Appel ajax - enregistrement nouveau client ***
		CVRSAjaxQueryURL('POST','/lib/include/modules/CVRSTBox_UserAccountManagement.php',TLibVar_POSTValues,TLibVar_BoxMessage);
	}
}

// ********************************************************
// *** Adresse de livraison: Société ou particulier?	***
// ********************************************************
function doSwitchDAPersonTypeRegister(){
    if (document.getElementById('third_typecompany').checked){
		document.getElementById('TBoxContentCompanyType').style.display = "block";
		document.getElementById('TBoxContentPersonType').style.display = "none";
	}else{
		document.getElementById('TBoxContentCompanyType').style.display = "none";
		document.getElementById('TBoxContentPersonType').style.display = "block";
	}
}
