/* 	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<5 || 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{
		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;
	}
}
// ***********************************************
// *** 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;
	}
}
// ***********************************************
// *** Montrer, Cacher les données Carte grise ***
// ***********************************************
function ChangeContactFrmDatas(theForm,theBlocA,theBlocB){
	if (theForm.selectedIndex == 1){
		CVOM_DisplayHideBloc(theBlocA,"none");
		CVOM_DisplayHideBloc(theBlocB,"block");
	}else{
		CVOM_DisplayHideBloc(theBlocA,"block");
		CVOM_DisplayHideBloc(theBlocB,"none");
	}
}
function CVOM_DisplayHideBloc(dhBloc,typeDisplay){
	// typeDisplay = none, inline ou block
	BlocToHideOrBlock = document.getElementById(dhBloc);
	BlocToHideOrBlock.style.display = typeDisplay;
}
// *****************************
// *** Toggle Piese auto BOX ***
// *****************************
function CVOM_ToggleZoomBox(theBloc,theNewStyle){
	var inc=1;
	while (document.getElementById("bloc"+inc)){
		if (theBloc=="bloc"+inc)
			if (document.getElementById("bloc"+inc).style.display=="block")
				document.getElementById("bloc"+inc).style.display = "none";
			else
				document.getElementById("bloc"+inc).style.display = theNewStyle;
		else
			document.getElementById("bloc"+inc).style.display = "none";
		inc++;
	}
}
// *****************************************
// *** Aller sur une page id_doc+options ***
// *****************************************
function CVOM_GoWebDirect(call_doc){
	document.location = call_doc;
}
// ***************************
// *** Retour History.Back ***
// ***************************
function CVOM_GoGack(){
	history.back();
}
