
	 var humanyTimeout;
	 var last_ans;
	 var showFields;
	 var humanySubmit;
	 var humanyTextarea;
	 var humanyTable;
	 var humanyGotAnswer = "false";

	 function humanyLog(what) {

			var humanyEmailHeadTag = document.getElementsByTagName("head").item(0); 
			var humanyEmailScriptTag = document.createElement("script");
			
			if (what == "Send" && humanyGotAnswer == "true") {
				humanyEmailScriptTag.src = "http://secure2.humany.com/stenaline/logStat.asp?type=SendAnswer";
			}
			else if (what == "Send" && humanyGotAnswer == "false") {
				humanyEmailScriptTag.src = "http://secure2.humany.com/stenaline/logStat.asp?type=Send";
			}
			else if (what == "Answer") {
				humanyEmailScriptTag.src = "http://secure2.humany.com/stenaline/logStat.asp?type=Answer";
			}
			humanyEmailHeadTag.appendChild(humanyEmailScriptTag);
			return true;			
	 }
	 function humanyExecYes() {
		humanyGotAnswer = "true";
		humanyLog("Answer");
		document.getElementById("humanyYes").checked=true;
		document.getElementById("humanyNo").checked=false;
		document.getElementById("humanyEmailAnswerContainer").style.display = 'block';
		document.getElementById("humanySatisfied").style.display = 'block';
		document.getElementById("humanyUseAltChannel").style.display = 'none';
		document.getElementById("rowTelephone").style.display = 'none';
		document.getElementById("rowEmail").style.display = 'none';
		document.getElementById("rowBooking").style.visibility = 'hidden';
		document.getElementById(humanySubmit).style.display = 'none';
	 }
	 function humanyExecNo() {
	 	document.getElementById("humanyNo").checked=true;
		document.getElementById("humanyYes").checked=false;
		
		if(showFields == "epost") {
			document.getElementById("rowEmail").style.display = '';
			document.getElementById(humanySubmit).style.display = 'inline';
		}
		else if (showFields == "epostBokning") {
			document.getElementById("rowEmail").style.display = '';
			document.getElementById("rowBooking").style.display = '';
			document.getElementById(humanySubmit).style.display = 'inline';
		}
		else if (showFields == "epostTelefon") {
			document.getElementById("rowTelephone").style.display = '';
			document.getElementById("rowEmail").style.display = '';
			document.getElementById(humanySubmit).style.display = 'inline';
		}
		else if (showFields == "webMaster") {
			document.getElementById("humanyUseAltChannel").style.display = 'block';
		}
		else {
			document.getElementById("rowTelephone").style.display = '';
			document.getElementById("rowEmail").style.display = '';
			document.getElementById("rowBooking").style.visibility = 'visible';
			document.getElementById(humanySubmit).style.display = 'inline';
		}
	 }

	function addRow(tableID) {
			var table = document.getElementById(tableID);
			var rowCount = table.rows.length;
			var row = table.insertRow(3);
			var cell1 = row.insertCell(0);
			var cell2 = row.insertCell(1);

			cell2.innerHTML = '<div id="humanyEmailAnswerContainer" class="zipBoxcontentholder"><div class="zipBox"><div class="zipBoxBottom"><div class="zipBoxcontent" id="humanyEmailAnswer"></div></div><div id="humanySatisfied" class="zipBoxcontentholderYesNoBox"><p>Fick du hj&auml;lp av informationen?</p><label><input type="radio" id="humanyYes" value="Ja" title="N&ouml;jd med svaret" onclick="javascript:humanyExecYes();" checked>Ja</label><label><input id="humanyNo" type="radio" value="Nej" onclick="javascript:humanyExecNo();" title="Ej n&ouml;jd med svaret">Nej, jag vill skicka in min e-post</label></div><div id="humanyUseAltChannel" style="display:none;">Klicka h&auml;r f&ouml;r att kontakta v&aring;r webbmaster via email: <a //href="http://www.stenaline.se/farja/contact-webmaster-new/">Kontakta webbmaster</a></div></div>';
			
			table.rows[4].id = "rowTelephone";
			table.rows[5].id = "rowEmail";
			table.rows[6].id = "rowBooking";
	}

	 function hideResult() {
		document.getElementById('humanyEmailAnswer').style.display = 'none';
		document.getElementById('humanySatisfied').style.display = 'none';
		document.getElementById('humanyUseAltChannel').style.display = 'none';
	 }
	 function showResult(typ) {
		document.getElementById('humanyEmailAnswer').style.display = 'block';
		document.getElementById('humanySatisfied').style.display = 'block';
	 }
	 function getResult() {
		 var humanyinput = document.getElementById(humanyTextarea).value;
		 if(humanyinput != "") {
			humanyinput = humanyinput.replace(/\r\n/g, "");
			var headTag = document.getElementsByTagName("head").item(0); 
			var scriptTag = document.createElement("script"); 
			scriptTag.src = "http://secure2.humany.com/stenaline/epost.asp?last=" + last_ans + "&entry=" + escape(humanyinput)
			headTag.appendChild(scriptTag);
		 }
	 }
	 function OpenTQ(id) {
		 if (id != "") {
			var headTag = document.getElementsByTagName("head").item(0); 
			var scriptTag = document.createElement("script"); 
			scriptTag.src = "http://secure2.humany.com/stenaline/epost.asp?last=" + last_ans + "&tq_id=" + id
			headTag.appendChild(scriptTag);
		 }
	 }
	 function suggest() {
		 clearTimeout(humanyTimeout);
		 humanyTimeout = setTimeout("getResult()",350);
		 return true;
	 }
	 function humanyInit() {
		var humanyTableArray = document.getElementsByTagName('table');
		humanyTable = humanyTableArray[1].id; 
		addRow(humanyTable);

		var headTag = document.getElementsByTagName("head").item(0); 
		var cssTag = document.createElement("link");
		cssTag.href = "http://secure2.humany.com/stenaline/css/contactFormMain.css";
		cssTag.rel = "stylesheet";
		cssTag.type = "text/css";
		headTag.appendChild(cssTag);

	 		
		var humanyTextAreaArray = document.getElementsByTagName('textarea');
		humanyTextarea = humanyTextAreaArray[0].id; 

		var humanyInputArray = document.getElementsByTagName('input');
		for (var i = 0; i < humanyInputArray.length; i++) {
			if (humanyInputArray[i].getAttribute('type') == "submit") {
				humanySubmit = humanyInputArray[i].id; 
			}
		}
		//document.getElementById(humanySubmit).onclick=function(){
		//	return humanyLog("Send");

		//}
		//document.getElementById("mainform").onsubmit=function(){
		//	return false;
		//}
		document.getElementById(humanyTextarea).onkeydown=function(){
			suggest();
		}
	 }


	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
	addLoadEvent(humanyInit);
