// JavaScript Document

   var http_request = false;
   function makeRequest(url, parameters, obj) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
	  
     if(obj =="dest_list"){
	 
	 http_request.onreadystatechange = alertContents;
	 }
	     if(obj =="calculate"){
	 
	 http_request.onreadystatechange = Contentscalculate;
	 }
	 	     if(obj =="getfirst"){
	 
	 http_request.onreadystatechange = getfirstdest;
	 }
	http_request.open('GET', url + parameters, true);
      http_request.send(null);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
          // alert(http_request.responseText);
            result = http_request.responseText;
          document.getElementById("dest_list").innerHTML = result;            
         document.getElementById("menu").style.display = "block"; 
		 } else {
            alert('There was a problem with the request.');
         }
      }
   }
      function Contentscalculate() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
          // alert(http_request.responseText);
            result = http_request.responseText;
          document.getElementById("calculate").innerHTML = result;
		  
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
         function getfirstdest() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
      
            result = http_request.responseText;
          //document.getElementById("firstdest").innerHTML = result;
		  
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   function get(obj) {
      var getstr = "?";
      for (i=0; i<obj.childNodes.length; i++) {
         if (obj.childNodes[i].tagName == "INPUT") {
            if (obj.childNodes[i].type == "text") {
               getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
            }
            if (obj.childNodes[i].type == "checkbox") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               } else {
                  getstr += obj.childNodes[i].name + "=&";
               }
            }
            if (obj.childNodes[i].type == "radio") {
               if (obj.childNodes[i].checked) {
                  getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
               }
            }
         }   
         if (obj.childNodes[i].tagName == "SELECT") {
            var sel = obj.childNodes[i];
            getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
         }
         
      }
      makeRequest('paid.php', getstr);
   }

  function getcheckbox(chkbox, id) {
    obj = document.getElementById(id);
	 
	 var getstr = "?";
     var check = 0;
	 
            if (obj.checked) {
			check = 1;
			}
				  getstr +="user="+ id + "&value="+check+"&";
                  getstr += "event=" + chkbox+"";
			
		
   //makeRequest('http://www.thuroeif.dk/includes/paid.php', getstr);
   
      
  }
  
  function getroutes(objid, destid, loa, boa, depth, codefrom, codeto) {
    obj = document.getElementById(objid);
	 objdest = document.getElementById(destid);
	 var getstr = "?";
     var check = 0;
	 
          /*  if (obj.checked) {
			check = 1;
			}*/
	
			if(codefrom =="" && destid ==  27){
				alert("Foreign destinations only selectable as disembarkation.");
			}else{
				  getstr +="destination="+ destid + "&loa="+loa+"&"+ "boa="+boa+"&"+ "depth="+depth+"&codefrom="+codefrom+"&"+"&codeto="+codeto+"&";
                  getstr += "action=getroutes";
		
		obj.innerHTML="<div class='loading' style='position:absolute;left:230px;top:100px;z-index:800;'><img src='images/bigrotation2.gif' ></div>";	
		
 makeRequest('http://www.danpilot.dk/Ratecalculator_V1/calculator_functions.php', getstr, objid);
			}
      
  }
  
    function calculate(objid,loa, boa, dra, code, codefrom, codeto) {
    obj = document.getElementById(objid);
	 
	 var getstr = "?";
     var check = 0;
	 
          /*  if (obj.checked) {
			check = 1;
			}*/
				  getstr +="code="+ code + "&codefrom="+codefrom+"&codeto="+codeto+"&loa="+loa+"&"+ "boa="+boa+"&"+ "depth="+dra+"&";
                  getstr += "action=calculate";
		
				obj.innerHTML="<div class='loading' style='text-align:center;position:absolute;left:100px;top:10px;z-index:800;'><img src='images/bigrotation2.gif' ></div>";	
				
// makeRequest('http://danpilot.dk/Ratecalculator_V1/calculator_functions.php', getstr, objid);
    makeRequest('http://www.danpilot.dk/Ratecalculator_V1/calculator_functions.php', getstr, objid);

      
  }
  
      function getfirst(objid,id,code) {
	 
	 var getstr = "?";
				  getstr +="destid="+id+"&first="+ code +"&";
                  getstr += "action=getfirst";

				
 //makeRequest('http://calculator.hjemmesider-fyn.dk/calculator_functions.php', getstr, objid);
   
      
  }
