
var roomarray=new Array(8);
roomarray[1] = "Single(sleeps 1)";
roomarray[6] = "Twin(sleeps 2)";
roomarray[5] = "Twin single use(sleeps 1)";
roomarray[7] = "Twin plus child(sleeps 3)";
roomarray[3] = "Double(sleeps 2)";
roomarray[2] = "Double single use(sleeps 1)";
roomarray[4] = "Double plus child(sleeps 3)";
roomarray[9] = "Quadruple(sleeps 4)";

var MealPlanCodes=new Array(4);
 MealPlanCodes[1] = "Breakfast",
 MealPlanCodes[2]  = "Halfboard",
 MealPlanCodes[3]   = "Fullboard ",
 MealPlanCodes[4]  = "Rom Only"; 

var BreakFastCodes=new Array(7);
BreakFastCodes['CB']="Continental Breakfast",
BreakFastCodes['BB']="Buffet Breakfast",
BreakFastCodes['AB']="American Breakfast", 
BreakFastCodes['JB']="Japanese Breakfast",
BreakFastCodes['IB']="Irish Breakfast",
BreakFastCodes['EB']="English Breakfast",
BreakFastCodes['SB']="Scandinavian Buffet Breakfast";

var month=new Array(12);
month['0']="01";
month['1']="02";
month['2']="03";
month['3']="04";
month['4']="05";
month['5']="06";
month['6']="07";
month['7']="08";
month['8']="09";
month['9']="10";
month['10']="11";
month['11']="12";

var Days= new Array();
Days['1'] ="01";Days['2'] ="02";Days['3'] ="03";Days['4'] ="04";Days['5'] ="05";Days['6'] ="06";Days['7'] ="07";Days['8'] ="08";Days['9'] ="09";
Days['10'] ="10";Days['11'] ="1";Days['12'] ="12";Days['13'] ="13";Days['14'] ="14";Days['15'] ="15";Days['16'] ="16";Days['17'] ="17";
Days['18'] ="18";Days['19'] ="19";Days['20'] ="20";Days['21'] ="21";Days['22'] ="22";Days['23'] ="23";Days['24'] ="24";Days['25'] ="25";Days['26'] ="26";
Days['27'] ="27";Days['28'] ="28";Days['29'] ="29";Days['30'] ="30";Days['31'] ="31";

function popcal(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, 'cal', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=335,height=430,left = 100,top = 50');");
}

function enterTipField(fld, tipText, normalColor)
{
  if (fld.value == tipText)
  {
    fld.value = ''
    if (fld.style)
	    fld.style.color = normalColor
  }
}

//storby
function valid()
{
	if(document.getElementById("country").value == 0)
{
	alert ("Vennligst velg land først");
	document.getElementById("country").focus();
	return false;
}
if(document.city.dato1.value == "Avreisedato")
{
	alert ("Velg Avreisedato");
	document.city.dato1.focus();
	return false;
}

}
//storby
function setPage(sPage)
{
   if(sPage == 7 || sPage == 4)
    var sPage=7;

  showPage('7', sPage == '7');
  document.city.rooms.value="1";
  
} 

function showPage(sPage, bShow)
{
  var div = document.getElementById(sPage);
  div.style.visibility = bShow ? 'visible' : 'hidden';
  div.style.position = bShow ? 'static' : 'absolute';


document.getElementById("childage1").style.display="block";
document.getElementById("childage2").style.display="none";
document.getElementById("childage3").style.display="none";

 
}
//storby
function Check_Room()
{
	if((document.city.roomtype.value=='7') || (document.city.roomtype.value=='4'))
		if((document.city.rooms.value=='4')||(document.city.rooms.value=='5')||(document.city.rooms.value=='6') ||(document.city.rooms.value=='7') ||(document.city.rooms.value=='8') ||(document.city.rooms.value=='9'))
	{
        alert("Du kan bestille for totalt 9 personer i maksimalt 4 rom")
		document.city.rooms.selectedIndex=0;
		return (false)
	}
}



function showromtype()
{
	var romtype = document.getElementById("roomtype").value;
	//alert(romtype);
    document.getElementById("roomtypediv").innerHTML = '<span class="textbold"><u>Romtype:</u> </span>'+roomarray[romtype];
}

//storby
function showrom()
{
	
	if(document.getElementById("roomtype").value == "4" || document.getElementById("roomtype").value == "7")
		var type=7;
	else
		var type=1;

	if(document.city.rooms.value=="1" && type=="7")
	{
	
	document.getElementById("childage1").style.display="block";
	document.getElementById("childage2").style.display="none";
	document.getElementById("childage3").style.display="none";
	}
	if(document.city.rooms.value=="2" && type=="7")
	{
	document.getElementById("childage1").style.display="block";
	document.getElementById("childage2").style.display="block";
	document.getElementById("childage3").style.display="none";
	}
	if(document.city.rooms.value=="3" && type=="7")
	{
	document.getElementById("childage1").style.display="block";
	document.getElementById("childage2").style.display="block";
	document.getElementById("childage3").style.display="block";
	}
}

//validation Motta nyhetsbrev
function ValidateForm(){
	var emailID=document.member.mailer_addr
		
	if ((emailID.value==null)||(emailID.value=="") || (emailID.value=="Legg inn e-post")){
		alert("Vennligst legg inn din e-postadresse igjen")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

function clear_textbox()
{
if (document.member.mailer_addr.value == "Legg inn e-post")
document.member.mailer_addr.value = "";
} 
function fill_textbox()
{
if (document.member.mailer_addr.value == "")
document.member.mailer_addr.value = "Legg inn e-post";
} 

var MidWindow = null
function OpenWindow(winURL)
{
	var POP_WIDTH = 700
	var POP_HEIGHT = 600
	var leftpos = (screen.width - POP_WIDTH) / 2; 
	var toppos = (screen.height - POP_HEIGHT) / 2;
	var features = "scrollbars=yes, resizable=yes";
	features = features +",width="  + POP_WIDTH;
	features = features +",height=" + POP_HEIGHT;
	features = features + ",left=" +leftpos;
	features = features + ",top=" +toppos;

	MidWindow=open(winURL,"MidWindow",features);
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Fyll inn korrekt e-post adresse")			  
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Fyll inn korrekt e-post adresse")			   
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Fyll inn korrekt e-post adresse")				
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Fyll inn korrekt e-post adresse")				
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Fyll inn korrekt e-post adresse")				
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Fyll inn korrekt e-post adresse")				
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Fyll inn korrekt e-post adresse")				
		    return false
		 }

 		 return true					
	}

//validation script gruppbooking

function validatefield(){
	
	if (document.grup_form.fname.value=="")
	{
			alert ("Vennligst fyll inn fornavn");
			document.grup_form.fname.focus();
			return false;		
	}if (document.grup_form.lname.value=="")
	{
			alert ("Vennligst fyll inn etternavn");
			document.grup_form.lname.focus();
			return false;			
	}if (document.grup_form.telephoned.value==""){
			alert ("Vennligst fyll inn telefonnummer (dagtid)");
			document.grup_form.telephoned.focus();
			return false;			
				
	}
	if (document.grup_form.email.value==""){
			alert ("Vennligst fyll inn e-post adresse");
			document.grup_form.email.focus();
			return false;			
				
	}
	if (document.grup_form.email.value!=""){
			var temp=document.grup_form.email.value;
			var chk=echeck(temp);	
			if(chk == false)
		{
				document.grup_form.email.focus();
				return false;
		}
	}
	if (document.grup_form.dest.value=="")
	{
		alert ("Fyll inn ønsket reisemål");
		document.grup_form.dest.focus();
		return false;	
	}
	if (document.grup_form.budget.value=="")
	{
		alert ("Vennligst fyll inn Budsjett (per person, per natt");
		document.grup_form.budget.focus();
		return false;	
	}
	if (document.grup_form.Enkeltrom.value=="" && document.grup_form.Dobbeltrom.value=="" && document.grup_form.Tomannsrom.value=="" && document.grup_form.Tremannsrom.value=="")
	{
		alert ("Vennligst velg minst en romtype og antall ønsket rom");
		document.grup_form.Enkeltrom.focus();
		return false;	
	}
}

function storbynexttrigger() {
var cage="";
if(document.city.roomtype.value == 4 | document.city.roomtype.value == 7) {
	for(i=1;i<=document.city.rooms.value;i++)
	{      
       var cing='childage'+i;
	  		  cage = cage+document.getElementById(cing).value+":";
	 }
}

var currdate = document.getElementById("dato1").value;
var nextval = "http://www.hotelltorget.no/storby/search.php?cntr="+document.city.country.value+"&city="+document.city.code.value+"&dato="+currdate+"&len="+document.city.len.value+"&lc="+document.city.lc.value+"&star="+document.city.star.value+"&rt="+document.city.roomtype.value+"&rooms="+document.city.rooms.value+"&cage="+cage;

var quote="";
var exdate=new Date();
var expiredays=365;
exdate.setDate(exdate.getDate()+expiredays);
document.cookie="testcookie=" +escape(quote)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())

document.location=nextval;
return false;

}


function passval() 
{
	//alert("in");
    var cinn = document.getElementById('dato1').value;

	var cin = cinn.split("-");

	var hname = document.getElementById('hname').value;
    var cityname = document.getElementById('cityname').value;
	var rooms = document.getElementById('rooms').value;
	var roomtype= document.getElementById('roomtype').value;
    var hc= document.getElementById('hc').value;
	var cc= document.getElementById('cc').value;
    var len= document.getElementById('len').value;
	var total= document.getElementById('total').value;
	var bc= document.getElementById('bc').value;
	var mc= document.getElementById('mc').value;
	
    var newdate = new Date(cin[0],cin[1]-1,cin[2]);
	
	var cout = new Date(newdate.getTime() + (86400000*len));
	
	var Month1 = month[cout.getMonth()]; 
	var coutt = cout.getFullYear()+"-"+Month1+"-"+Days[cout.getDate()];
	//alert(coutt);
	
//date1.setTime(date1.getTime() + millisecondsPerDay);

    var cage;
    if(document.getElementById('roomtype').value == 4 || document.getElementById('roomtype').value == 7)
	{
		var rooms = document.getElementById('rooms').value;
		
		for(i=1;i<=rooms;i++)
		{
			var id='childage'+i;
			//alert(id);
		if(i==1)
		    cage = document.getElementById(id).value;
		else
			cage = cage+";"+document.getElementById(id).value;
		
		}
	}
	else
		cage = ";;";
  //alert(cage);
var val = hname+";"+cityname+";"+rooms+";"+roomarray[roomtype]+";"+cinn+";"+coutt+";"+total+";"+roomtype+";"+cage+";"+hc+";"+cc+";"+MealPlanCodes[mc]+":"+BreakFastCodes[bc];

document.passv.f.value=val;
document.passv.submit();
}

