var installpath = "http://vraag.hema.nl/chatbot/selfservice/";
var installpath_fr = "http://vraag.hema.nl/chatbot_frans/selfservice/";
var installpath_be = "http://vraag.hema.nl/chatbot/selfservice/";
var installpath_de = "http://vraag.hema.nl/chatbot_duits/selfservice/";

function startChatbot()
{
	var vars = "";
	var ary=window.location.search.substr(1).split("&");
	
	if(ary != "")
	{
		for (ary_i=0;ary_i<ary.length;ary_i++) 
		{
			ary[ary_i]=ary[ary_i].split("=");
		}
		
		var qStr=new Array();
		for (ary_i2=0;ary_i2<ary.length;ary_i2++)
		{
			ary[ary_i2][0]=ary[ary_i2][0].replace(/\+/g," ");
			ary[ary_i2][0]=unescape(ary[ary_i2][0]);
			ary[ary_i2][1]=ary[ary_i2][1].replace(/\+/g," ");
			ary[ary_i2][1]=unescape(ary[ary_i2][1]);
			qStr[ary[ary_i2][0]]=ary[ary_i2][1];
		}
		vars = qStr["vars"];
	}
	
	if(vars == undefined)
	{
		fillChat('', '', '', '', '','', '', '');
	}
	else
	{
		var ca = vars.split(';');
		for(var i=0;i < ca.length;i++)
		{
				c = ca[i];
				c = trim(c);
				
				if(i == 0)
				{
					var catname = c;
				}
				else if(i == 1)
				{
					var catid = c;
				}
				else if(i == 2)
				{
					var taxtype = c;
				}
				else if(i == 3)
				{
					var taxid = c;
				}
				else if(i == 4)
				{
					var topid = c;
				}
				else if(i == 5)
				{
					var obj = c;
				}
				else if(i == 6)
				{
					var q = c;
				}
				else if(i == 7)
				{
					var target = c;
				}
				else if(i == 8)
				{
					var lang = c;
				}
				else if(i == 9)
				{
					var channel = c;
				}
		}
		fillChat(catname, catid, taxtype, taxid, topid, obj, q, target, lang, channel);
	}
	this.focus();
}

function showAssistant(scrw, scrh, w, h, namewindow, Assistant_Category, Assistant_CategoryID, Tax_type, TaxID, ToplistID, objID, Question, TargetID, LanguageID, ChannelID)
{
	var location = installpath + "chatbot/";

	// set defaults
	if(LanguageID == "4")
	{
		// present french version
		location += "chatbot_fr.htm?vars="+Assistant_Category+";"+Assistant_CategoryID+";"+Tax_type+";"+TaxID+";"+ToplistID+";"+objID+";"+Question+";"+TargetID+";"+LanguageID+";"+ChannelID;
	}
	else if(LanguageID == "64")
	{
		// present belgian version
		location += "chatbot_be.htm?vars="+Assistant_Category+";"+Assistant_CategoryID+";"+Tax_type+";"+TaxID+";"+ToplistID+";"+objID+";"+Question+";"+TargetID+";"+LanguageID+";"+ChannelID;
	}
	else if(LanguageID == "3")
	{
		// present german version
		location += "chatbot_de.htm?vars="+Assistant_Category+";"+Assistant_CategoryID+";"+Tax_type+";"+TaxID+";"+ToplistID+";"+objID+";"+Question+";"+TargetID+";"+LanguageID+";"+ChannelID;
	}
	else
	{
		// present dutch version as default
		location += "chatbot.htm?vars="+Assistant_Category+";"+Assistant_CategoryID+";"+Tax_type+";"+TaxID+";"+ToplistID+";"+objID+";"+Question+";"+TargetID+";"+LanguageID+";"+ChannelID;
	}

	// check for left position; if not there, set in middle
	if(scrw == "" || scrw == undefined)
	{
		var scrw=(screen.width/2)-(w/2);
	}
	// check for top position; if not there, set in middle
	if(scrh == "" || scrh == undefined)
	{
		var scrh=(screen.height/2)-(h/2);
	}
	window.open(location,namewindow,('toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0,menubar=0,copyhistory=0,left='+scrw+',top='+scrh+',width='+w+',height='+h));
}

function fillChat(Assistant_Category, Assistant_CategoryID, Tax_type, TaxID, ToplistID, objID, Question, TargetID, LanguageID, ChannelID)
{
	var Question_set = "";
	if(Assistant_Category == undefined){Assistant_Category = "";} // default categoriebeschrijving, waarde wordt bij inrichting bepaald, mag ook leeg zijn
	if(Assistant_CategoryID == undefined){Assistant_CategoryID = "";} // default categorie id, waarde wordt bij inrichting bepaald, mag ook leeg zijn
	if(Tax_type == undefined){Tax_type = "1";} // default taxonomie is vragenlijst (1 = vragenlijst / 0 = begeleiding)
	if(TaxID == undefined){TaxID = "";} // default taxonomie, waarde wordt bij inrichting bepaald, mag ook leeg zijn
	if(ToplistID == undefined){ToplistID = "";} // default toplijst, waarde wordt bij inrichting bepaald, mag ook leeg zijn
	if(objID == undefined){objID = "";} // object id is default leeg
	if(Question == undefined){Question = "";} // vraag is default leeg
	if(TargetID == undefined){TargetID = "";} // doelgroep is default leeg (worden ini waarden gebruikt)
	if(LanguageID == undefined){LanguageID = "";} // taal is default leeg (worden ini waarden gebruikt)
	if(ChannelID == undefined){ChannelID = "";} // kanaal is default leeg (worden ini waarden gebruikt)
	 
	// maak url variabelen
	if(Assistant_CategoryID !="")
	{
		Assistant_CategoryID = "&cat="+Assistant_CategoryID+"&showcatid="+Assistant_CategoryID;
	}
	
	if(ToplistID != "" && TaxID != "")
	{
	  TaxID = "";
	}
	
	if(Tax_type !="" && TaxID !="")
	{
		Tax_type = "&tt="+Tax_type;
	}
	else
	{
		Tax_type = "&tt=";
	}
	
	if(TaxID !="")
	{
		TaxID = "&tid="+TaxID;
	}
	
	if(ToplistID !="")
	{
		ToplistID = "&tlid="+ToplistID;
	}
	
	if(objID !="")
	{
		objID = "&action=show&obj_id="+objID;
	}
	
	if(Question != "")
	{
		Question_set = "&org="+Question+"&aw="+Question+"&action=results";
	}
	
	if(TargetID !="")
	{
		TargetID = "&tr="+TargetID;
	}
	
	if(LanguageID == 4)
	{
		useinstallpath = installpath_fr;
	}
	else if(LanguageID == 3)
	{
		useinstallpath = installpath_de;
	}
	else if(LanguageID == 64)
	{
		useinstallpath = installpath_be;
	}
	else
	{
		useinstallpath = installpath;
	}

	if(LanguageID !="")
	{
		LanguageID = "&lg="+LanguageID;
	}

	if(ChannelID !="")
	{
		ChannelID = "&ch="+ChannelID;
	}
	
	// check rangorde variabelen
	if(objID != "" && TaxID != "" && Tax_type == "&tt=0")
	{
	 	TaxID = "";
		Tax_type = "";
	}
	
	if(objID != "" && Question_set != "")
	{
	 	Question_set = "&org="+Question;
	}
	
	var newhtml = '<iframe style="overflow-y:auto;overflow-x:hidden;background-color:#FFFFFF" name="Chatbot" height="482" scrolling="no" width="250" src="'
	+useinstallpath
	+'hylo.search.asp?cb=1&ass_cat=' 
	+Assistant_Category
	+Assistant_CategoryID
	+Tax_type
	+TaxID
	+ToplistID
	+objID
	+Question_set
	+TargetID
	+LanguageID
	+ChannelID
	+' " frameborder="0"></iframe>';
	
	//document.getElementById("av").value = Question;
	document.getElementById("chatwindow").innerHTML = newhtml;
}

function submitform()
{
	document.getElementById("ChatinputForm").submit();
}

function checksubmit()
{
	///var actionset = installpath+"hylo.search.asp?action=results";
	var question = document.getElementById("av").value;
	if(question == "")
	{
		alert("U heeft geen vraag gesteld");
		return false;
	}
	else
	{
		submitform();
	}
}

function trim(value)
{
  value = value.replace(/^\s+/,''); 
  value = value.replace(/\s+$/,'');
  return value;
}