/* 	Fonctions JavaScript pour le site
	CVO Market Nelimitat V1.0 */
// ******************************************
// *** Déclaration des variables globales ***
// ******************************************
var CVOMVar_TimeNow = Math.round(Math.random()*1000000000);
// ****************************
// *** Trim sur theStringCT ***
// ****************************
function CVOM_TrimString(theStringCVOM){
	txtStringCVOM = new String(theStringCVOM);
	while (txtStringCVOM.substring(0,1) == ' '){
		txtStringCVOM = txtStringCVOM.substring(1, txtStringCVOM.length);
	}
	while (txtStringCVOM.substring(txtStringCVOM.length-1, txtStringCVOM.length) == ' '){
		txtStringCVOM = txtStringCVOM.substring(0,txtStringCVOM.length-1);
	}
	return txtStringCVOM;
}
// *******************************
// *** Fonctions Ouverture POP ***
// *******************************
function CVOM_OpenPop(filepopname,namepopwin){
	window.open(filepopname,namepopwin,"menubar=yes,toolbar=no,scrollbars=yes,status=yes,width=500,height=400,top=0,left=0");
}
function CVOM_OpenPopXY(filepopname,namepopwin,popxsize,popysize){
	window.open(filepopname,namepopwin,"menubar=no,toolbar=no,scrollbars=no,status=yes,width="+popxsize+",height="+popysize+",top=0,left=0");
}
function CVOM_OpenPopCenter(filepopname,namepopwin,popxsize,popysize){
	var popwinleftpos = Math.round((screen.width-popxsize)/2);
	var popwintoppos  = Math.round((screen.height-popysize)/2);
	window.open(filepopname,namepopwin,"menubar=no,toolbar=no,scrollbars=no,status=yes,width="+popxsize+",height="+popysize+",top="+popwintoppos+",left="+popwinleftpos+"");
}
// ********************************
// *** Vérifier Newsletter Form ***
// ********************************
function CVOM_CheckNewsletter(theForm){
	var frm_message = 'Eroare inregistrare formular!\n\n';
	var err_count	= 0;
	theForm.nom_newsletter.value	= CVOM_TrimString(theForm.nom_newsletter.value);
	theForm.mail_newsletter.value	= CVOM_TrimString(theForm.mail_newsletter.value);
	if (theForm.nom_newsletter.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti numele dvs.\n';
		err_count++;
	}
	if (theForm.mail_newsletter.value.length<8){
		frm_message = frm_message+'- Va rugam sa introduceti adresa dvs. de e-mail.\n';
		err_count++;
	}
	if (err_count!=0){
		alert(frm_message);
		return false;
	}else
		return true;
}
// *****************************
// *** Vérifier Opinion Form ***
// *****************************
function CVOM_CheckOpinion(theForm){
	var frm_message = 'Eroare inregistrare formular!\n\n';
	var err_count	= 0;
	theForm.nom_opinion.value	= CVOM_TrimString(theForm.nom_opinion.value);
	theForm.mail_opinion.value	= CVOM_TrimString(theForm.mail_opinion.value);
	theForm.text_opinion.value	= CVOM_TrimString(theForm.text_opinion.value);
	if (theForm.nom_opinion.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti numele dvs.\n';
		err_count++;
	}
	if (theForm.mail_opinion.value.length<8){
		frm_message = frm_message+'- Va rugam sa introduceti adresa dvs. de e-mail.\n';
		err_count++;
	}
	if (theForm.text_opinion.value.length<10){
		frm_message = frm_message+'- Va rugam sa introduceti opinia dvs.\n';
		err_count++;
	}
	if (theForm.text_opinion.value.length>500){
		frm_message = frm_message+'- Opinia dvs. nu poate contine mai mult de 255 de caractere!\n';
		err_count++;
	}
	if (err_count!=0){
		alert(frm_message);
		return false;
	}else
		return true;
}
// *************************************
// *** Enregistrement nouveau client ***
// *************************************
function CVOM_CheckNewUserPFPJ(theForm){
	var frm_message = 'Eroare date formular!\n\n';
	var err_count	= 0;
	theForm.new_nom.value		= CVOM_TrimString(theForm.new_nom.value);
	theForm.new_prenom.value	= CVOM_TrimString(theForm.new_prenom.value);
	theForm.new_adresse.value	= CVOM_TrimString(theForm.new_adresse.value);
	theForm.new_cp.value		= CVOM_TrimString(theForm.new_cp.value);
	theForm.new_ville.value		= CVOM_TrimString(theForm.new_ville.value);
	theForm.new_email.value		= CVOM_TrimString(theForm.new_email.value);
	theForm.new_pass.value		= CVOM_TrimString(theForm.new_pass.value);
	theForm.new_passconfirm.value	= CVOM_TrimString(theForm.new_passconfirm.value);
	if (theForm.new_nom.value.length<3 || theForm.new_prenom.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti numele si prenumele dvs.\n';
		err_count++;
	}
	// *** Code spécifique aux sociétés ***
	if (theForm.user_type.value=='pj'){
		theForm.new_srl.value		= CVOM_TrimString(theForm.new_srl.value);
		theForm.new_cui.value		= CVOM_TrimString(theForm.new_cui.value);
		theForm.new_rc.value		= CVOM_TrimString(theForm.new_rc.value);
		theForm.new_account.value	= CVOM_TrimString(theForm.new_account.value);
		theForm.new_nombanque.value	= CVOM_TrimString(theForm.new_nombanque.value);
		if (theForm.new_srl.value.length<5 || theForm.new_adresse.value<5 || theForm.new_cp.value<6 || theForm.new_ville.value<3){
			frm_message = frm_message+'- Va rugam sa introduceti numele si adresa firmei dvs.\n';
			err_count++;
		}
		if (theForm.new_cui.value.length<4 || theForm.new_rc.value<5){
			frm_message = frm_message+'- Va rugam sa introduceti CUI (R) si Codul Fiscal (J)\n';
			err_count++;
		}
		if (theForm.new_account.value.length<24 || theForm.new_nombanque.value.length<3){
			frm_message = frm_message+'- Va rugam sa introduceti datele bancii.\n';
			err_count++;
		}
	}else{
		// *** Code spécifique aux particuliers ***
		theForm.new_cnp.value		= CVOM_TrimString(theForm.new_cnp.value);
		if (theForm.new_cnp.value.length!=13){
			frm_message = frm_message+'- Va rugam sa introduceti un CNP valid (un numar CNP contine 13 cifre).\n';
			err_count++;
		}
		if (theForm.new_adresse.value<5 || theForm.new_cp.value<5 || theForm.new_ville.value<3){
			frm_message = frm_message+'- Va rugam sa introduceti adresa dvs.\n';
			err_count++;
		}
	}
	if (theForm.new_tel.value.length<10){
		frm_message = frm_message+'- Va rugam sa introduceti cel putin un numar de telefon.\n';
		err_count++;
	}
	if (theForm.new_email.value.length<6 || theForm.new_pass.value.length<4 ||
		theForm.new_pass.value!=theForm.new_passconfirm.value){
		frm_message = frm_message+'- Va rugam sa introduceti adresa dvs de e-mail si o parola valida.\n';
		err_count++;
	}
	if (err_count!=0){
		alert(frm_message);
		return false;
	}else{
		doChallengeMD5NewUser(theForm);
		return true;
	}
}
// *************************************
// *** Enregistrement nouveau client ***
// *************************************
function doCheckModifyAccount(theForm){
	var frm_message = 'Eroare date formular!\n\n';
	var err_count	= 0;
	theForm.myaccount_modifyadr.value	= CVOM_TrimString(theForm.myaccount_modifyadr.value);
	theForm.myaccount_modifycp.value	= CVOM_TrimString(theForm.myaccount_modifycp.value);
	theForm.myaccount_modifyville.value	= CVOM_TrimString(theForm.myaccount_modifyville.value);
	theForm.myaccount_modifytel.value	= CVOM_TrimString(theForm.myaccount_modifytel.value);
	if (theForm.myaccount_modifyadr.value.length<3
		|| theForm.myaccount_modifycp.value.length<6
		|| theForm.myaccount_modifyville.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti o adresa valida (ATTENTIE: se cere noul cod postal).\n';
		err_count++;
	}
	// *** Code spécifique aux sociétés ***
	if (theForm.myaccount_modiftype.value=='pj'){
		theForm.myaccount_modifynom.value		= CVOM_TrimString(theForm.myaccount_modifynom.value);
		theForm.myaccount_modifypnom.value		= CVOM_TrimString(theForm.myaccount_modifypnom.value);
		theForm.myaccount_modifycomptebnq.value	= CVOM_TrimString(theForm.myaccount_modifycomptebnq.value);
		theForm.myaccount_modifynombnq.value	= CVOM_TrimString(theForm.myaccount_modifynombnq.value);
		if (theForm.myaccount_modifynom.value.length<3
			|| theForm.myaccount_modifypnom.value<3){
			frm_message = frm_message+'- Va rugam sa introduceti numele si prenumele persoanei de contact.\n';
			err_count++;
		}
		if (theForm.myaccount_modifycomptebnq.value.length<24
			|| theForm.myaccount_modifynombnq.value.length<3){
			frm_message = frm_message+'- Va rugam sa introduceti datele bancii.\n';
			err_count++;
		}
	}
	if (theForm.myaccount_modifytel.value.length<10){
		frm_message = frm_message+'- Va rugam sa introduceti cel putin un numar de telefon.\n';
		err_count++;
	}
	if (err_count!=0){
		alert(frm_message);
		return false;
	}else{
		return true;
	}
}
// ***********************************************
// *** Verifier les données formulaire Contact ***
// ***********************************************
function CVOM_CheckContactForm(theForm){
	theForm.cvrs_nume.value = CVOM_TrimString(theForm.cvrs_nume.value);
	theForm.cvrs_tel.value  = CVOM_TrimString(theForm.cvrs_tel.value);
	theForm.cvrs_mail.value  = CVOM_TrimString(theForm.cvrs_mail.value);
	theForm.cvrs_mess.value  = CVOM_TrimString(theForm.cvrs_mess.value);
	if (theForm.cvrs_nume.value.length<3 ||
		theForm.cvrs_tel.value.length<6 ||
		theForm.cvrs_mail.value.length<6 ||
		theForm.cvrs_mess.value.length<5){
		alert('Eroare!\n\nVa rugam sa completati toate campurile.');
		return false;
	}else{
		return true;
	}
}

// ****************************************
// *** Voir les détails d'une commande	***
// *** Développer les lignes de la cde	***
// ****************************************
function ExpandViewDetailsOrder(TLibVar_IdOrder,TLibVar_IndxBox){
	// *** Développer la TBox apropriée ***
	TBoxExpand(TLibVar_IndxBox,'TBox_MyAccountViewDetailsOrder','block');
	// *** Remplir le document avec le message d'attente ***
	document.getElementById('TBox_MyAccountViewDetailsOrder'+TLibVar_IndxBox).innerHTML='<center><br><b>Se incarca, va rugam asteptati...</b><br><br></center>';
	// *** Appel ajax - affichage module détails ***
	CVRSAjaxQueryURL('POST','ajax_inc/CVRSTBox_Content.php','BoxToInclude=ViewOrderDetails&IdOrder='+TLibVar_IdOrder,'TBox_MyAccountViewDetailsOrder'+TLibVar_IndxBox);
}

// ****************************************
// *** Voir les détails d'une commande	***
// *** Développer l'adresse de livraison***
// ****************************************
function ExpandViewDetailsOrderAdrLivre(TLibVar_IdOrder,TLibVar_IndxBox){
	// *** Développer la TBox apropriée ***
	TBoxExpand(TLibVar_IndxBox,'TBox_MyAccountViewDetailsOrderALT','block');
	// *** Remplir le document avec le message d'attente ***
	document.getElementById('TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox).innerHTML='<center><br><b>Se incarca, va rugam asteptati...</b><br><br></center>';
	// *** Appel ajax - affichage module détails adresse livraison ***
	CVRSAjaxQueryURL('POST','ajax_inc/CVRSTBox_Content.php','BoxToInclude=ViewOrderAdrLivre&IdOrder='+TLibVar_IdOrder,'TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox);
}

// ****************************************
// *** Voir les détails d'une commande	***
// *** Choix de l'adresse de livraison	***
// ****************************************
function ExpandViewDetailsOrderChangeAdrLivre(TLibVar_IdOrder,TLibVar_IndxBox){
	// *** Développer la TBox apropriée ***
	// *** Remplir le document avec le message d'attente ***
	document.getElementById('TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox).innerHTML='<center><br><b>Se incarca, va rugam asteptati...</b><br><br></center>';
	// *** Appel ajax - affichage module détails adresse livraison ***
	CVRSAjaxQueryURL('POST','ajax_inc/CVRSTBox_Content.php','BoxToInclude=ChangeAdrLivre&IdOrder='+TLibVar_IdOrder,'TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox);
}

// ********************************************
// *** Développer case Société dans ajout	***
// *** nouvelle adresse de livraison		***
// ********************************************
function ExpandViewDetailsOrderNewSteAdrLivre(){
	if (document.frm_ordernewadrlivre.myaccount_newadrlivretype.options[document.frm_ordernewadrlivre.myaccount_newadrlivretype.selectedIndex].value=="pj"){
		document.getElementById('TBox_NewAdrLivrePJ').style.display = "block";
	}else{
		document.getElementById('TBox_NewAdrLivrePJ').style.display = "none";
	}
}

// ****************************************
// *** Voir les détails d'une commande	***
// *** Développer le transportateur		***
// ****************************************
function ExpandViewDetailsOrderTransport(TLibVar_IdOrder,TLibVar_IndxBox){
	// *** Développer la TBox apropriée ***
	TBoxExpand(TLibVar_IndxBox,'TBox_MyAccountViewDetailsOrderALT','block');
	// *** Remplir le document avec le message d'attente ***
	document.getElementById('TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox).innerHTML='<center><br><b>Se incarca, va rugam asteptati...</b><br><br></center>';
	// *** Appel ajax - affichage module détails transport ***
	CVRSAjaxQueryURL('POST','ajax_inc/CVRSTBox_Content.php','BoxToInclude=ViewOrderDetailsTrans&IdOrder='+TLibVar_IdOrder,'TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox);
}

// ****************************************
// *** Ajouter une adresse de livraison	***
// *** depuis la liste des adresses		***
// ****************************************
function doAddSelectedAdrLivre(TLibVar_IdOrder,TLibVar_IndxBox,TLibVar_IdAdrLivre){
	// *** Remplir le document avec le message d'attente ***
	document.getElementById('TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox).innerHTML='<center><br><b>Se proceseaza, va rugam asteptati...</b><br><br></center>';
	// *** Appel ajax ***
	CVRSAjaxQueryURL('POST','ajax_inc/CVRSTBox_Content.php','BoxToInclude=doModifySelectAdrLivre&IdOrder='+TLibVar_IdOrder+'&IdAdrLivre='+TLibVar_IdAdrLivre,'TBox_MyAccountViewDetailsOrderALT'+TLibVar_IndxBox);
}

// ************************************************
// *** Ajouter une nouvelle adresse de livraison***
// *** et modifier la commande client			***
// ************************************************
function doCheckNewAdrLivre(theForm,TLibVar_IdOrder){
	var frm_message = 'Eroare date formular!\n\n';
	var err_count	= 0;
	var TLibVar_POSTValues = "";
	theForm.myaccount_newadrlivresrl.value	= CVOM_TrimString(theForm.myaccount_newadrlivresrl.value);
	theForm.myaccount_newadrlivrelnom.value	= CVOM_TrimString(theForm.myaccount_newadrlivrelnom.value);
	theForm.myaccount_newadrlivrefnom.value	= CVOM_TrimString(theForm.myaccount_newadrlivrefnom.value);
	theForm.myaccount_newadrlivretel.value	= CVOM_TrimString(theForm.myaccount_newadrlivretel.value);
	theForm.myaccount_newadrlivreadr.value	= CVOM_TrimString(theForm.myaccount_newadrlivreadr.value);
	theForm.myaccount_newadrlivrecp.value	= CVOM_TrimString(theForm.myaccount_newadrlivrecp.value);
	theForm.myaccount_newadrlivreville.value= CVOM_TrimString(theForm.myaccount_newadrlivreville.value);
	// *** Nom société ***
	if (theForm.myaccount_newadrlivretype.options[theForm.myaccount_newadrlivretype.selectedIndex].value=="pj"
		&& theForm.myaccount_newadrlivresrl.value.length<5){
		frm_message = frm_message+'- Va rugam sa introduceti numele firmei.\n';
		err_count++;
	}
	// *** Nom et prénom
	if (theForm.myaccount_newadrlivrelnom.value.length<3 || theForm.myaccount_newadrlivrefnom.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti un nume si un prenume valid.\n';
		err_count++;
	}
	// *** Téléphone
	if (theForm.myaccount_newadrlivretel.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti un numar de telefon valid.\n';
		err_count++;
	}
	// *** Adresse,CP et Ville
	if (theForm.myaccount_newadrlivreadr.value.length<5
		|| theForm.myaccount_newadrlivrecp.value.length<6
		|| theForm.myaccount_newadrlivreville.value.length<3){
		frm_message = frm_message+'- Va rugam sa introduceti o adresa valida (ATTENTIE: se cere noul cod postal.).\n';
		err_count++;
	}
	if (err_count!=0){
		alert(frm_message);
		return false;
	}else{
		TLibVar_POSTValues = "BoxToInclude=doAddNewAdrLivre&IdOrder="+TLibVar_IdOrder;
		TLibVar_POSTValues+= "&new_adrlivresrl="+theForm.myaccount_newadrlivresrl.value;
		TLibVar_POSTValues+= "&new_adrlivrenom="+theForm.myaccount_newadrlivrelnom.value;
		TLibVar_POSTValues+= "&new_adrlivrepnom="+theForm.myaccount_newadrlivrefnom.value;
		TLibVar_POSTValues+= "&new_adrlivretel="+theForm.myaccount_newadrlivretel.value;
		TLibVar_POSTValues+= "&new_adrlivreadr="+theForm.myaccount_newadrlivreadr.value;
		TLibVar_POSTValues+= "&new_adrlivrecp="+theForm.myaccount_newadrlivrecp.value;
		TLibVar_POSTValues+= "&new_adrlivreville="+theForm.myaccount_newadrlivreville.value;
		TLibVar_POSTValues+= "&new_adrlivreregion="+theForm.myaccount_newadrlivreregion.options[theForm.myaccount_newadrlivreregion.selectedIndex].value;
		TLibVar_POSTValues+= "&new_adrlivretype="+theForm.myaccount_newadrlivretype.options[theForm.myaccount_newadrlivretype.selectedIndex].value;
		// *** Remplir le document avec le message d'attente ***
		document.getElementById('TBox_MyAccountViewDetailsOrderALT1').innerHTML='<center><br><b>Se proceseaza, va rugam asteptati...</b><br><br></center>';
		// *** Appel ajax ***
		CVRSAjaxQueryURL('POST','ajax_inc/CVRSTBox_Content.php',TLibVar_POSTValues,'TBox_MyAccountViewDetailsOrderALT1');
	}
}

// *****************************************
// *** Aller sur une page id_doc+options ***
// *****************************************
function CVOM_GoWebDirect(call_doc){
	document.location = call_doc;
}
// ***************************
// *** Retour History.Back ***
// ***************************
function CVOM_GoGack(){
	history.back();
}

// ****************************************
// *** Filtrer les numéros de téléphone ***
// ****************************************
function doCheckWriteTelFormatSimple(theStringCVOM){
	var re = /\d{10}/;
	var TLibVar_TrueTelFormat = re.exec(theStringCVOM);
	if (!TLibVar_TrueTelFormat || theStringCVOM.length>10)
		return false;
	else
		return true;
}

// ***********************************
// *** Filtrer les adresses e-mail ***
// ***********************************
function doCheckValidMail(theStringCVOM){
	var TLibVarFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (TLibVarFilter.test(theStringCVOM))
		return true;
	else
		return false;
}

// ****************************************************
// *** Accepter uniquement les caracères Numériques ***
// ****************************************************
function FilterValueToNum(theStringCVOM){
	return theStringCVOM.replace(/[^0-9]/g,"");
}

// ***********************************************
// *** Accepter uniquement les caracères Alpha ***
// ***********************************************
function FilterValueToAlpha(theStringCVOM){
	return theStringCVOM.replace(/[^a-zéàçèôê' ]/gi,"");
}