tboks.webexpert.expert={}; 


/**
 * 当用户选定非Pro请求，并点击"继续"时触发
 */
tboks.webexpert.expert.noProContinueButtonClicked=function()
{
	var validCheck = 0;
	
	
	//Description 部分检测
	if (!(document.getElementById('StandardSkillDescription').style.fontStyle == "italic" || $("#StandardSkillDescription").val()=="")) {
		
		if(tboks.webexpert.expert.descriptionWordCheck($("#StandardSkillDescription").val())){
			tboks.webexpert.all_info.setHiddenValue("HNoProDescription", $("#StandardSkillDescription").val());
		}else{
			jAlert("(FR) La  description de votre demande est trop succinte veuillez détailler. Merci.","Tboks");
			return;
		}
	}else{
		validCheck++;
	}
	
	//Price部分检测
	//不再使用Price,直接设定为10欧元
	tboks.webexpert.all_info.setHiddenValue("HPrice","10");
	/*
	if (checkPriceNumber()) {
		setHiddenValue("HPrice", $("#priceInput").attr("value"));
	}else{
		validCheck++;
	}
	*/
	//Domain部分检测
	if($("#HDomain").attr("value") != ""){
		//OK
	}else{
		validCheck++;
	}
	//Category部分检测
	if($("#HCategory").attr("value") != ""){
		//OK
		tboks.webexpert.expert.getSubCategoryIDs($("#HCategory").attr("value"));
	}else{
		validCheck++;
	}
	
	//最终判断
	if(validCheck > 0)
	{
		jAlert("Veuillez remplir tous les champs.","Tboks");
		validCheck = 0;
	}else{
		//alert("可以继续");
		validCheck = 0;
		//预先log
		tboks.webexpert.logs.doPreRequestLog();
		//tboks.webexpert.popup.showPopup("boxySignIn");
		//tboks.webexpert.popup.showSinscrirePartDirect();
		tboks.webexpert.popup.showSinscrirePartDirect_newpopup();
		//showPopup("DIVPOPUP","DIVLOGIN","login");
	}
}


/**
 * 获得subCategory选中值
 * @param {Object} categoryID
 */
tboks.webexpert.expert.getSubCategoryIDs=function(categoryID)
{
	var subCategoryGroupName = "SubCateSelect_CateValueOn" + categoryID;
	var subCategoryValue= new Array();
	$("[name="+subCategoryGroupName+"]:checked").each(function(){
		subCategoryValue.push($(this).val());
	});
	tboks.webexpert.all_info.setHiddenValue("HSubCategory",subCategoryValue.join(","));
}




/**
 * 添加Expert第一调用方法，判断Expert类型
 */
tboks.webexpert.expert.sendRequest=function()
{
	var type = $("#HRequestType").attr("value");
	
	switch(type)
	{
		case "1":
			tboks.webexpert.expert.doNonProRequest();
			tboks.webexpert.popup.loadingShowPopup();
			break;
	}
}

/**
 * Standart 标准 request 发送 Ajax
 */
tboks.webexpert.expert.doNonProRequest=function()
{
	var sessionID = $("#HSessionID").attr("value");
	var domainID = $("#HDomain").attr("value");
	var categoryID = $("#HCategory").attr("value");
	var subCategoryIDs = $("#HSubCategory").attr("value");
	var description = encodeURIComponent($("#HNoProDescription").attr("value"));
	var price = $("#HPrice").attr("value");

	var url = window.location.href.split('/');
		if (url[3] == "en" || url[3] == "EN")
		{
			var languageID = 1;
		}
		else
		{
			var languageID = 2;
		}
	
	var par="method=ADDNEWNOPROEXPERT&sessionID=" + sessionID + "&domainID=" + domainID + "&categoryID=" + categoryID + "&subCategoryIDs=" + subCategoryIDs + "&standarddescription=" + description + "&standardprice=" + price + "&evaluations=&distance=&duration=720&languageID="+languageID;
	//alert(par);
	
	$.ajax(
	{
		url:"/commun/ws/NewExpert.ws.php",
		type:"POST",
		data:par,
		success:tboks.webexpert.expert.onRequestResult,
		error:tboks.webexpert.reg_login.onError
	});
}


/**
 * 原计划用于非Pro Request发送返回函数
 * 现在好像所有Request返回都一样
 * @param {Object} result
 */
tboks.webexpert.expert.onRequestResult=function(result)
{
	tboks.webexpert.popup.loadingClosePopup();

	var r = $.trim(result);
	if(r.length){
		var rf = r.substring(0,2);
		var rm = r.substring(2);
	
		switch(rf)
		{
			case "SU":
			if($("#HOrigin").val() == 20) onCommercialTrack();
			if($("#HOrigin").val() == 21) onAffilinetTrack();
			tboks.webexpert.logs.refererLog("Request");
			//jAlert("Votre demande a bien été envoyée. Connectez vous sur Tboks pour voir les réponses des experts.","Tboks");
			jConfirm("Votre expertise a été correctement ajoutée. Téléchargez l'application puis rendez-vous dans votre espace expert pour consulter les demandes en cours.","Tboks",
					
				function(r){
				//	window.location.reload();
					window.location.href="telecharger_adw.php";
				}
			);
			
			//reload();
			break;
			
			case "FA":
			jAlert(rm,"Tboks");
			break;
		}
	}else{
		jAlert("Une erreur est survenue lors de l'envoi de votre demande. Merci de réessayer à nouveau","Tboks");
	}
	
}

tboks.webexpert.expert.descriptionWordCheck=function(str)
{
	var alphabetMin = 4;
	var wordMin = 3;
	var stringArray = str.split(" ");	
	var num = stringArray.length;
	var bad = 0;
	for(var i = 0; i < num; i++){
		if (stringArray[i].length < alphabetMin) bad++;
	}
	if((num - bad) < wordMin){
		return 0;
	}else{
		return 1;
	}
}
