/*
	callback of the login action
*/
function loginCheck(comwebBean,requestResume){
	if (! comwebBean.hasError()){
		var comwebBean_user = comwebBean.getSpecificChildren("user")[0];

		//write the registered HTML content
		var params = new HashTable();
		params.put("username",comwebBean_user.getUsername());


		var medianbcomment = 0;
		try{
			medianbcomment = comwebBean.getSpecificChildren("note")[0].getSpecificChildren("detail")[0].getValues("media_nbcomment");
			if (medianbcomment=="null" || medianbcomment == null || medianbcomment ==""){
				medianbcomment = 0;
			}
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"loginCheck can't retrieve the medianbcomment value, error:" + e);
		}

		var medianbvote = 0;
		try{
			medianbvote = comwebBean.getSpecificChildren("note")[0].getSpecificChildren("detail")[0].getValues("media_nbvote");
			if (medianbvote=="null" || medianbvote == null || medianbvote ==""){
				medianbvote = 0;
			}
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"loginCheck can't retrieve the medianbvote value, error:" + e);
		}

		var medianbvisualisation = 0;
		try{
			medianbvisualisation = comwebBean.getSpecificChildren("note")[0].getSpecificChildren("detail")[0].getValues("media_nbvisualisation");
			if (medianbvisualisation=="null" || medianbvisualisation == null || medianbvisualisation ==""){
				medianbvisualisation = 0;
			}
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"loginCheck can't retrieve the medianbvisualisation value, error:" + e);
		}

		var usernbvisualisation = 0;
		try{
			usernbvisualisation = comwebBean.getSpecificChildren("note")[0].getSpecificChildren("detail")[0].getValues("user_nbvisualisation");
			if (usernbvisualisation=="null" || usernbvisualisation == null || usernbvisualisation ==""){
				usernbvisualisation = 0;
			}
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"loginCheck can't retrieve the usernbvisualisation value, error:" + e);
		}

		var usernbcomment= 0;
		try{
			usernbcomment = comwebBean.getSpecificChildren("note")[0].getSpecificChildren("detail")[0].getValues("user_nbcomment");
			if (usernbcomment=="null" || usernbcomment == null || usernbcomment ==""){
				usernbcomment = 0;
			}
		}catch(e){
			CW_logger.log(CW_logger.LEVEL_ERROR,"loginCheck can't retrieve the usernbcomment value, error:" + e);
		}

			params.put("nbvisitprofil",usernbvisualisation);
			params.put("nbcommentprofil",usernbcomment);
			params.put("nbvisitmedia",medianbvisualisation);
			params.put("nbcommentmedia",medianbcomment);
			params.put("nbnotemedia",medianbvote);



		CW_comwebAjax.loadHtml("html/login/registered.html","registerContainer",params);

	}
}

function logout(){
	//sendRequest : function (url,callback ,historyName,transactionId)
	var parameters = new Array();
	parameters.push('action=user.logout');
	CW_comwebAjax.sendRequest('/comweb/user', 'logoutCallback', null, 'login', parameters );
}

function registerLoad(){
	CW_comwebAjax.loadHtml("html/login/register.html","registerContainer");
}
function validInscription1(){
	var form = document.forms['inscription1'];

	var element = CW_util.getFormElement(form,"user.username");
	element.value = (new String(element.value)).toLowerCase();

	element = CW_util.getFormElement(form,"user.password");
	element.value = (new String(element.value)).toLowerCase();

	element = CW_util.getFormElement(form,"repass");
	element.value = (new String(element.value)).toLowerCase();

	CW_Action_User.validInscription1('inscription1Check',form);
}

function inscription1Load(){
	CW_AjaxPage_Manager.displayPage("inscription");
}

function inscription1Check(comwebBean){
	if (! comwebBean.hasError()){
		var comwebBeanSession = comwebBean.getSpecificChildren("session")[0];
		var comwebBeanUser = comwebBean.getSpecificChildren("user")[0];
		var login = comwebBeanUser.getUsername();
		var siteId = CW_config.serviceId;
		//the the html content
		CW_comwebAjax.loadHtml("html/inscription/inscription2.html","masterPage");
		//set the select date html element content
		CW_util.setSelectDateContent("selectYearInscription2","selectMonthInscription2","selectDayInscription2");
		//set the country html element content
		CW_util.setCountryListContent("inscription1","user.country");

		var form = document.forms["inscription1"];
		CW_util.getFormElement(form,"burl").value = CW_config.webappUri;
		CW_util.getFormElement(form,"subm").value = CW_internationalization.getValue("inscription.mail.subject");
		CW_util.getFormElement(form,"smail").value = CW_internationalization.getValue("inscription.mail.sender");
		CW_util.getFormElement(form,"lang.uid").value = CW_internationalization.getUid();
		CW_util.getFormElement(form,"user.username").value = login;
		var img = document.getElementById("captchaImage");
		var src = "/comweb/CaptchaService?captcha.width=200&captcha.height=100&captcha.background=FFFFFF&captcha.color=000000&user.login="+login+"&site.uid="+siteId
		img.setAttribute("src",src);

	}
}

function inscription2Check(comwebBean){
	if (! comwebBean.hasError()){
		/*
			valueText1 email
		*/
		var params = new HashTable();
		params.put("valueText1",CW_Action_User.inscription1_mail);
		CW_comwebAjax.loadHtml("html/inscription/inscription3.html","masterPage",params);
	}
}

/***********************************************************************************************************************/
/* Loading de l'etape2 de l'inscription*/
function inscription4Load(){
	CW_comwebAjax.loadHtml("html/inscription/inscription4.html","masterPage");
	addHistoryFunction("inscription4Load","Inscription4");
}

/* Validation de l'etape2 de l'inscription*/
function validFormInscriptionState3(){
	inscription4Load();
}

function showProfilDetail(){
	CW_comwebAjax.loadHtml("html/inscription/inscriptionProfilDetail.html","profilDetailContainer");
	document.getElementById("profilDetailContainer").style.display="block";
}

