﻿function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
		 }
	catch (e) {
		 // Internet Explorer
		 try  {
		  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		  }
		 catch (e) {
		  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }
		 }
	return xmlHttp;
}
function setImage(name, variable) {
	document.getElementById(variable).src=name;
}


function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		document.getElementById("time").innerHTML = xmlHttp.responseText;
	} 
}



function AddTime(value) {
var url="gettime.aspx";
url=url+"?id="+value;
 var client = GetXmlHttpObject();
 if (client==null) {
		 alert ("Browser does not support HTTP Request");
		 return;
		 }
 client.onreadystatechange = function() {
  // in case of network errors this might not give reliable results
  if(client.readyState == 4 || client.readyState=="complete")
  document.getElementById("time").innerHTML = client.responseText;
  
 }
 client.open("GET", url, true);
 client.send(null);
}

function AddHotel(value) {
var url="gethotel.aspx";
url=url+"?date="+value;

 var client = GetXmlHttpObject();
 if (client==null) {
		 alert ("Browser does not support HTTP Request");
		 return;
		 }
 client.onreadystatechange = function() {
  // in case of network errors this might not give reliable results
  if(client.readyState == 4 || client.readyState=="complete")
  document.getElementById("hotel").innerHTML = client.responseText;
 }
 client.open("GET", url, true);
 client.send(null);
}

function fetchStatus(address) {
 var client = GetXmlHttpObject();
 if (client==null) {
		 alert ("Browser does not support HTTP Request");
		 return;
		 }
 client.onreadystatechange = function() {
  // in case of network errors this might not give reliable results
  if(this.readyState == 4)
   returnStatus(this.status);
 }
 client.open("HEAD", address);
 client.send();
}

function stepTwo() {

	if(document.getElementById("time")!=null){
	AddHotel(document.form.time.options[document.form.time.selectedIndex].value);
	}
	document.getElementById("first").style.display='none';
	document.getElementById("second").style.display='block';

}
function stepOne() {
	document.getElementById("second").style.display='none';
	document.getElementById("first").style.display='block';
}
tall = 0;
function tickerStart(antall) {
			tall = tall + 1
			if(tall > antall) {
				tall = 1;
			}
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null) {
				 alert ("Browser does not support HTTP Request")
				 return
				 } 
			var url="ticker.php"
			url=url+"?tall="+tall;
			xmlHttp.onreadystatechange=stateChange;
			xmlHttp.open("GET",url,true)
			xmlHttp.send(null)
			t=setTimeout("tickerStart("+antall+")",5000);
}
function stateChange() { 
	 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		 document.getElementById("theStuff").innerHTML = xmlHttp.responseText;		 
	 } 
}
function checkForm() {
	warning = "";
	if(document.form.FNavn.value == "") {
		warning = warning+"Fyll ut Fornavn\n";
	}
	if(document.form.Enavn.value == "") {
		warning = warning+"Fyll ut Etternavn\n";
	}
	if(document.form.Epost.value == "") {
		warning = warning+"Fyll ut navn\n";
	}
	if(document.form.Epost.value != document.form.Epost2.value) {
		warning = warning+"Epostene stemmer ikke med hverandre\n";
	}
	if(document.form.Telefon.value == "") {
		warning = warning+"Fyll ut et telefonnummer\n";
	}
	if(document.form.Adresse.value == "") {
		warning = warning+"Fyll ut en adresse\n";
	}
	if(document.form.Postnr.value == "") {
		warning = warning+"Fyll ut postnummer\n";
	}
	if(document.form.PostSted.value == "") {
		warning = warning+"Fyll ut Poststed\n";
	}
	if(document.form.AnkDato.value == "") {
		warning = warning+"Fyll ut ankomst dato\n";
	}
	if(document.form.AvrDato.value == "") {
		warning = warning+"Fyll ut avreise dato\n";
	}
	
	if(document.form.AntRom.value == "") {
		warning = warning+"Fyll ut antall rom\n";
	}

	if(warning != "") {
		alert(warning);
		stepOne();
		return false

	} else {
		return true;
	}
}
function addText(antall, diven) {
	output = "";
	for(i=0; i<antall; i++) {
		output = output+"<p style='padding-top:5px;'><input type='text' name='"+diven+i+"' /> - Fyll inn navn</p>";
	}

	document.getElementById(diven).innerHTML=output;
}
function CheckingForm(form) {
	var show = document.form.show.value;
	var time = document.form.time.value;
	var navn = document.form.navn.value;
	var mobil = document.form.mobil.value;
	var epost = document.form.epost.value;
	var epost2 = document.form.epost2.value;
	var warning = "";
	if(epost != epost2) {
		warning = warning+"E-postene må stemme med hverandre.\n";
	}
	if(epost == "") {
		warning = warning+"Du må fylle inn en e-post\n";
	}
	if(navn == "") {
		warning = warning+"Du må fylle inn et navn bestillingen skal stå på\n";
	}
	if(show == "") {
		warning = warning+"Du må velge et show du vil bestille\n";
	}
	if(time == "") {
		warning = warning+"Du må velge et tidspunkt på showet\n";
	}
	if(mobil == "") {
		warning = warning+"Du må fylle inn et mobilnummer vi kan nå deg på\n";
	}
	if(warning != "") {
		alert(warning);
		return false;
	} else {
		return true;
	}
}



