// JavaScript Document


	//INSERT FISH
	function insert_input_fish() {
		var forms = Array('lake', 'fish', 'size', 'weight', 'put_back');
		var tem = ""
		
		
		for (i=0;i<forms.length;i++) {
			tem += forms[i] + "=" + document.getElementById('form_' + forms[i]).value	 + "&"
		}
		
		var url ="xml/xml_insert_fish.php?" + tem + "profile_id=" + document.getElementById('profile_id').value
		
		xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)  {
				alert ("Your browser does not support AJAX!");
				 return;
			 }
			xmlHttp.onreadystatechange=stateChanged_insert_input_fish
	
			xmlHttp.open("GET", url, true)
			xmlHttp.send(null)
		
	}
	function stateChanged_insert_input_fish() {
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			
			var forms = Array('lake', 'fish', 'size', 'weight', 'put_back');
			for (i=0;i<forms.length;i++) {
				document.getElementById(forms[i] + "_" + document.getElementById('form_' + forms[i]).value).checked = false
				document.getElementById('form_' + forms[i]).value = ""
			}
			
			document.getElementById('update_panel_fish').className = "display"
			select_input_fish()
			run_update_panel_fish = setInterval("update_panel_costomers_fish()", 6000);
		}
	}
	function update_panel_costomers_fish() {
		document.getElementById('update_panel_fish').className = "displaynone"
		window.clearInterval(run_update_panel_fish);
	}
	
	//SELECT FISH
	function select_input_fish() {
		var url ="xml/xml_select_fish.php?profile_id=" + document.getElementById('profile_id').value
		
		xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)  {
				alert ("Your browser does not support AJAX!");
				 return;
			 }
			xmlHttp.onreadystatechange=stateChanged_select_input_fish
	
			xmlHttp.open("GET", url, true)
			xmlHttp.send(null)
		
	}
	function stateChanged_select_input_fish() {
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			var x = ""
			
			for (i=0;i<xmlDoc.getElementsByTagName('costomers').length;i++) {
				x += "<div>"
					x += "<span class='Ajax_color' style='width:162px;' title='" + xmlDoc.getElementsByTagName('lake')[i].childNodes[0].nodeValue + "'>" + xmlDoc.getElementsByTagName('lake')[i].childNodes[0].nodeValue.substr(0,20) + "</span>"
					x += "<span class='Ajax_color' style='width:163px;' title='" + xmlDoc.getElementsByTagName('fish')[i].childNodes[0].nodeValue + "'>" + xmlDoc.getElementsByTagName('fish')[i].childNodes[0].nodeValue.substr(0,20) + "</span>"
					x += "<span class='Ajax_color' style='width:163px;' title='" + xmlDoc.getElementsByTagName('size')[i].childNodes[0].nodeValue + "'>" + xmlDoc.getElementsByTagName('size')[i].childNodes[0].nodeValue + "</span>"
					x += "<span class='Ajax_color' style='width:90px;' title='" + xmlDoc.getElementsByTagName('weight')[i].childNodes[0].nodeValue + "'>" + xmlDoc.getElementsByTagName('weight')[i].childNodes[0].nodeValue + "</span>"
					
					if (xmlDoc.getElementsByTagName('id_put_back')[i].childNodes[0].nodeValue != 2) {
						x += "<span class='Ajax_table_line_1' style='width:10px; cursor:pointer;' title='Ikke genudsat'></span>"
					} else {
						x += "<span class='Ajax_table_line_2' style='width:10px; cursor:pointer;' title='Genudsat'></span>"
					}
				x += "</div>"
			}
				
			if (x=="") {
				x += "<span class='Ajax_color'><br />Venter på den første indrapportering :-)</span>"
			}
			
			document.getElementById('insert_profiles_fish').innerHTML = x
			window.clearInterval(run_select_page);
		}
	}
	
	//INSERT statistik
	function select_input_statistik() {
		var url ="xml/xml_select_statistik.php"
		xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)  {
				alert ("Your browser does not support AJAX!");
				 return;
			 }
			xmlHttp.onreadystatechange=stateChanged_select_input_statistik
	
			xmlHttp.open("GET", url, true)
			xmlHttp.send(null)
	}
	function stateChanged_select_input_statistik() {
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			var x = ""
			var company = ""
			var count_total = xmlDoc.getElementsByTagName('count_input')[0].childNodes[0].nodeValue
			var count_pct = 0
			var id = 0
			
			for (i=0;i<xmlDoc.getElementsByTagName('lakes').length;i++) {
				count_pct =  Math.round((Math.round(xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue) / count_total) * 100,0)
				id = xmlDoc.getElementsByTagName('id')[i].childNodes[0].nodeValue
				id_company =  xmlDoc.getElementsByTagName('company')[i].childNodes[0].nodeValue
				
				if (company != id_company) {
					if (company !="") {
						x += "<div><span>&nbsp;</span></div>"	
					}
					x += "<div>"
						x += "<span id='company_" + id_company + "' class='Ajax_color_head'><b>" + id_company + "</b></span>"
					x += "</div>"
					company = id_company
				}
				x += "<div>"
					x += "<span id='lake_link_" + id + "' class='Ajax_color' style='width:20px; cursor:pointer;' onMousedown='select_input_statistik_fish(" + id + ");' title='" + xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue + "'>+</span>"
					x += "<span id='lake_text_" + id + "'  class='Ajax_color' style='width:130px;' title='" + xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue + "'>" + xmlDoc.getElementsByTagName('text')[i].childNodes[0].nodeValue + "</span>"
					x += "<span class='Ajax_color' style='width:25px; text-align:right;'><b>" + xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue + "</b></span>"
					x += "<span style='width:5px;'></span>"
					x += "<span class='Ajax_table_line' style='width:370px;' title='" + xmlDoc.getElementsByTagName('text')[i].childNodes[0].nodeValue + "\n" + xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue + " stk. af " + count_total + " indrapportede (" + count_pct + "%)'>"
					x += "<span class='Ajax_table_line_inner' style='width:" + count_pct + "%;'></span></span>"
				x += "</div>"
				x += "<div id='lake_" + id + "'></div>"
			}
			document.getElementById('insert_statistik_fish').innerHTML = x
			window.clearInterval(run_select_page);

		}
	}
	
	//INSERT statistik-fish
	function select_input_statistik_fish(id) {
		if (document.getElementById('lake_link_' + id).innerHTML == "+") {
			var url ="xml/xml_select_statistik_fish.php?id_lake=" + id
			xmlHttp=GetXmlHttpObject()
				if (xmlHttp==null)  {
					alert ("Your browser does not support AJAX!");
					 return;
				 }
				xmlHttp.onreadystatechange=stateChanged_select_input_statistik_fish
		
				xmlHttp.open("GET", url, true)
				xmlHttp.send(null)
		} else {
			document.getElementById('lake_' + id).className = "Displaynone"
			document.getElementById('lake_link_' + id).innerHTML = "+"
		}
	}
	function stateChanged_select_input_statistik_fish() {
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			var x = ""
			var count_total = xmlDoc.getElementsByTagName('count_input')[0].childNodes[0].nodeValue
			var id_lake = xmlDoc.getElementsByTagName('id_lake')[0].childNodes[0].nodeValue
			var count_pct = 0
			var id = 0
			
			x += "<div class='Ajax_table_line_space'></div>"
			for (i=0;i<xmlDoc.getElementsByTagName('fish').length;i++) {
				count_pct =  Math.round((Math.round(xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue) / count_total) * 100,0)
				id = xmlDoc.getElementsByTagName('id')[i].childNodes[0].nodeValue
				
				x += "<div>"
					x += "<span style='width:20px;'></span><span id='lake_fish_link_" + id_lake + "_" + id + "' class='Ajax_color' style='width:20px; cursor:pointer;' onMousedown='select_input_statistik_size(" + id_lake + "," + id + ",0);'>+</span><span id='lake_fish_text_" + id_lake + "_" + id + "' class='Ajax_color' style='width:110px;'>" + xmlDoc.getElementsByTagName('text')[i].childNodes[0].nodeValue + "</span><span class='Ajax_color' style='width:25px; text-align:right;'>" + xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue + "</span><span style='width:5px;'></span><span class='Ajax_table_line2' style='width:370px;' title='" + xmlDoc.getElementsByTagName('text')[i].childNodes[0].nodeValue + "\n" + xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue + " stk. af " + count_total + " indrapportede (" + count_pct + "%)'><span class='Ajax_table_line_inner' style='width:" + count_pct + "%;'></span></span>"
				x += "</div>"
				x += "<div id='lake_fish_" + id_lake + "_" + id + "'></div>"

			}
			x += "<div class='Ajax_table_line_space'></div>"
			x += "<div class='Ajax_table_line_space'></div>"
			
			document.getElementById('lake_' + id_lake).innerHTML = x
			document.getElementById('lake_' + id_lake).className = "Display"
			
			document.getElementById('lake_link_' + id_lake).innerHTML = "&ndash;"
		}
	}
	
	//INSERT statistik-size
	function select_input_statistik_size(id_lake, id_fish, id_type) {
		if (document.getElementById('lake_fish_link_' + id_lake + "_" + id_fish).innerHTML == "+" || id_type !=0)  {
			
			var form_properties = Array('fish_size_form', 'fish_weight_form')
			if (id_type == 0) {
				for (i=0;i<form_properties.length;i++) {
					if (document.getElementById(form_properties[i]).checked == true) {
						id_type = document.getElementById(form_properties[i]).value
					}
				}
			}
			var url ="xml/xml_select_statistik_size.php?id_lake=" + id_lake + "&id_fish=" + id_fish + "&id_type=" + id_type
			
			xmlHttp=GetXmlHttpObject()
				if (xmlHttp==null)  {
					alert ("Your browser does not support AJAX!");
					 return;
				 }
				xmlHttp.onreadystatechange=stateChanged_select_input_statistik_size
		
				xmlHttp.open("GET", url, true)
				xmlHttp.send(null)
		} else {
			document.getElementById('lake_fish_' + id_lake + "_" + id_fish).className = "Displaynone"
			document.getElementById('lake_fish_link_' + id_lake + "_" + id_fish).innerHTML = "+"
		}
	}
	function stateChanged_select_input_statistik_size() {
		
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			var x = ""

			var count_total = xmlDoc.getElementsByTagName('count_input')[0].childNodes[0].nodeValue
			var id_lake = xmlDoc.getElementsByTagName('id_lake')[0].childNodes[0].nodeValue
			var id_fish = xmlDoc.getElementsByTagName('id_fish')[0].childNodes[0].nodeValue
			var id_type = xmlDoc.getElementsByTagName('id_type')[0].childNodes[0].nodeValue
			
			var count_pct = 0
			var id = 0
			
			x += "<div class='Ajax_color'><span style='width:40px;'></span><span class='Ajax_table_line_1' style='width:10px; cursor:pointer;' onMousedown='select_input_statistik_size(" + id_lake + "," + id_fish + ",1);' title='" + document.getElementById('lake_text_' + id_lake).innerHTML + " - " + document.getElementById('lake_fish_text_' + id_lake + "_" + id_fish).innerHTML + " - Størrelsen'></span><span style='width:10px;'></span><span class='Ajax_table_line_2' style='width:10px; cursor:pointer;' onMousedown='select_input_statistik_size(" + id_lake + "," + id_fish + ",2);'  title='" + document.getElementById('lake_text_' + id_lake).innerHTML + " - " + document.getElementById('lake_fish_text_' + id_lake + "_" + id_fish).innerHTML + " - Vægten'></span></div>"
			for (i=0;i<xmlDoc.getElementsByTagName('fish_properties').length;i++) {
				count_pct =  Math.round((Math.round(xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue) / count_total) * 100,0)
				id = xmlDoc.getElementsByTagName('id')[i].childNodes[0].nodeValue
				
				x += "<div>"
					x += "<span style='width:40px;'></span><span class='Ajax_color' style='width:110px;'>" + xmlDoc.getElementsByTagName('text')[i].childNodes[0].nodeValue + "</span><span class='Ajax_color' style='width:25px; text-align:right;'>" + xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue + "</span><span style='width:5px;'></span><span class='Ajax_table_line_" + id_type + "' style='width:370px;' title='" + xmlDoc.getElementsByTagName('text')[i].childNodes[0].nodeValue + "\n" + xmlDoc.getElementsByTagName('count_total')[i].childNodes[0].nodeValue + " stk. af " + count_total + " indrapportede (" + count_pct + "%)'><span class='Ajax_table_line_inner' style='width:" + count_pct + "%;'></span></span>"
				x += "</div>"

			}
			
			x += "<div class='Ajax_table_line_space'></div>"
			x += "<div class='Ajax_table_line_space'></div>"
			
			document.getElementById('lake_fish_' + id_lake +  "_" + id_fish).innerHTML = x
			document.getElementById('lake_fish_' + id_lake + "_" + id_fish).className = "Display"
			document.getElementById('lake_fish_link_' + id_lake + "_" + id_fish).innerHTML = "&ndash;"
		}
	}
	
	//SELECT STORIE
	function select_input_storie() {
		var url ="xml/xml_select_storie.php"
		xmlHttp=GetXmlHttpObject()
		if (xmlHttp==null)  {
			alert ("Your browser does not support AJAX!");
			 return;
		 }
		xmlHttp.onreadystatechange=stateChanged_select_input_storie

		xmlHttp.open("GET", url, true)
		xmlHttp.send(null)
	}
	function stateChanged_select_input_storie() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			var x = ""
			var image = ""
			var view_description = ""
			var view_description_short = ""
			var image_width = 150
			
			//Math.round(document.getElementById('tep_image_width').value*0.66,0)
			
			var span_image_width = image_width
			var span_text_width = (530-image_width)
			
			
			for (i=0;i<xmlDoc.getElementsByTagName('costomers').length;i++) {
				id = xmlDoc.getElementsByTagName('id')[i].childNodes[0].nodeValue
				image = "0-12345.jpg"
				if (xmlDoc.getElementsByTagName('image')[i].childNodes[0].nodeValue.length > 1) {
					image = xmlDoc.getElementsByTagName('image')[i].childNodes[0].nodeValue
				}
				if (document.getElementById('costomers_storie_id').value == id) {
					view_description = "ajax_color_describtion"
 					view_description_short = "Displaynone"	
					div_class = "Ajax_table_div_selected"
				} else {
					view_description = "displaynone"
 					view_description_short = "ajax_color_describtion"	
					div_class = "Ajax_table_div_unselected"
				}
					
				x += "<div id='div_storie_" + id + "' class='" + div_class + "' style='cursor:pointer;' onMousedown='set_costomers_description(" + id + ");'><a name='#" + id + "'></a>"
					x += "<span style='width:" + image_width + "px; vertical-align:top;'><img src='images/costomers_storie/" + image + "' width='" + image_width + "'></span>"
					x +="<span style='width:8px;'></span>"
					
					x += "<span style='width:" + span_text_width + "px;' style='text-align:justify;'>"
						//title
						x += "<span class='Ajax_color_title' style='vertical-align:top;'>" + xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue + "</span><br />"
						//describtion
						x += "<span id='description_short_" + id + "' class='" + view_description_short + "' style='vertical-align:top;'>" + xmlDoc.getElementsByTagName('description_short')[i].childNodes[0].nodeValue + " <span class='Ajax_color_costomers'><a>...læs mere</a></span></span>"
						x += "<span id='description_" + id + "' class='" + view_description + "' style='vertical-align:top;'>" + xmlDoc.getElementsByTagName('description')[i].childNodes[0].nodeValue + "</span><br />"
						//name & date
						x += "<span class='Ajax_color_costomers' style='vertical-align:bottom; width:" + (span_text_width-150)  + "px;'>" + xmlDoc.getElementsByTagName('name')[i].childNodes[0].nodeValue + "</span><span class='Ajax_color_costomers' style='width:140px; vertical-align:bottom; text-align:right;'>" + xmlDoc.getElementsByTagName('pubdate')[i].childNodes[0].nodeValue + "</span><br />"
					x += "</span><br />"
				x += "</div>"	
				x +="<div>"
					//space		
					x += "<span class='Ajax_table_line_space_2'></span><br />"

					x += "<span class='Ajax_table_line_doch'></span>"
				x += "</div>"
				
					
			}
			document.getElementById('insert_storie_fish').innerHTML = x
			window.clearInterval(run_select_page);

		}
	}
	
	//SELECT STORIE SINGLE RANDOM
	run_select_page_random_text = setInterval("run_select_page_random()", 1200);
	function run_select_page_random() {
		if (document.getElementById('costomers_storie_random_div') != null) {
			var url ="xml/xml_select_storie_single.php"
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)  {
				alert ("Your browser does not support AJAX!");
				 return;
			 }
			xmlHttp.onreadystatechange=stateChanged_select_input_storie_single
	
			xmlHttp.open("GET", url, true)
			xmlHttp.send(null)
		}
	}
	function stateChanged_select_input_storie_single() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")	{
			xmlDoc=xmlHttp.responseXML;
			var x = ""
			var image = ""
			var image_width = "100"

			
			for (i=0;i<xmlDoc.getElementsByTagName('costomers').length;i++) {
				id = xmlDoc.getElementsByTagName('id')[i].childNodes[0].nodeValue
				image = "0-12345.jpg"
				if (xmlDoc.getElementsByTagName('image')[i].childNodes[0].nodeValue.length > 1) {
					image = xmlDoc.getElementsByTagName('image')[i].childNodes[0].nodeValue
				}
					
				x += "<div>"
					//title
					x += "<a href='http://www.sydfisk.dk/costomers_storie.php?storie_id=" + id + "#" + id + "'><span class='Ajax_color_description' style='vertical-align:top;'><b>" + xmlDoc.getElementsByTagName('title')[i].childNodes[0].nodeValue + "</b></span></a><br />"
					//image
					x += "<span style='width:" + image_width + "px; vertical-align:top;'><a href='http://www.sydfisk.dk/costomers_storie.php?storie_id=" + id + "#" + id + "'><img src='images/costomers_storie/" + image + "' width='" + image_width + "' border='0'></a></span><br />"
				x += "</div>"	
				
					
			}
			document.getElementById('costomers_storie_random_div').innerHTML = x
			document.getElementById('costomers_storie_random_table').className = "display"
			window.clearInterval(run_select_page_random_text);
		}
	}
	
	//---------------------------------------------------------------------------
	
	//Requst HTTP
	function GetXmlHttpObject() { 
		var objXMLHttp=null
	 	if (window.XMLHttpRequest) {
	 		objXMLHttp=new XMLHttpRequest()
	 	} else if (window.ActiveXObject) {
	 		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	 	}
	 	return objXMLHttp
	 } 
