// Sätta Cookie för Digiumenterprise
function SetCookie (name, value) {
         var argv = SetCookie.arguments;
         var argc = SetCookie.arguments.length;
         var expires = (argc > 2) ? argv[2] : null;
         var path = (argc > 3) ? argv[3] : null;
         var domain = (argc > 4) ? argv[4] : null;
         var secure = (argc > 5) ? argv[5] : false;
         document.cookie = name + "=" + escape (value) +
         ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
         ((path == null) ? "" : ("; path=" + path)) +
         ((domain == null) ? "" : ("; domain=" + domain)) +
         ((secure == true) ? "; secure" : "");
}

function setC(form) {
   var expdate = new Date ();
   expdate.setTime (expdate.getTime() + (14*24*60*60*1000));
   SetCookie (form.name, form.value, expdate);
}
function locate(url) {
  location = url;
}

function changeTab(cellNb,on)
{
var test = navigator.userAgent;

if (test.indexOf("MSIE 4") == -1)
	{
		if (on.match("activ") == "activ")
		{

				document.getElementById("linkMenu" + cellNb).style.color = "#FFFFFF";
				document.getElementById("headerMenu" + cellNb).style.background = "url(/imagesSE/header_tab"+ on + ".gif)";
		}
		else
		{
			if  (cellNb != 0)
				{
					document.getElementById("linkMenu" + cellNb).style.color = "#ffffff";
					document.getElementById("headerMenu" + cellNb).style.background="url(/imagesSE/header_tab"+ on + ".gif)"
				}
				else
				{
					document.getElementById("linkMenu" + cellNb).style.color = "#ffffff";
					document.getElementById("headerMenu" + cellNb).style.background="url(/imagesSE/header_tab"+ on + ".gif)"
				}
		}

	}
}

function openMailAFriendLayer(sPage)
{
document.getElementById("mailAFriendFrame").src = "/commonSE/mailAFriend.asp?page="+sPage 
top.document.getElementById("mailAFriendLayer").style.visibility ="visible"
}

function closeMailAFriendLayer()
{
top.document.getElementById("mailAFriendLayer").style.visibility = "hidden"
}

function reklamfilmchfose(reklamFilm)
{
document.getElementById("reklamFilmFrame").src = "/contentSE/reklamfilm/"+reklamFilm
top.document.getElementById("reklamfilmLayer").style.visibility ="visible"
}

function reklamfilmClose()
{
top.document.getElementById("reklamFilmLayer").style.visibility = "hidden"
}

function openNetshopLayer()
{
window.open("/netshop/")

}

function closeNetshopLayer()
{
top.document.getElementById("netshopLayer").style.visibility = "hidden"
top.document.getElementById("knapp").style.visibility ="hidden"
top.document.getElementById("openNetShopLink").style.visibility ="visible"
}

function openInfoKryssningsbokning() {	
	newHelpA = window.open("/bokning/instruktioner_kryssning.asp","Information","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=380");
	newHelpA.window.focus();
}
function openInfoHotellbokning() {	
	newHelpA = window.open("/bokning/instruktioner_hotellkryssning.asp","Information","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=380");
	newHelpA.window.focus();
}
//Visar samtliga gemensamma hyttkategorier för valt fartyg i bokningen
function openCabinInfo(fartygCabin) {
   filename = "/commonSE/infopopup.asp?file=" + "/content/svenska/tillhavs/"+fartygCabin.toLowerCase()+"_cabins.inc";
   newcabinInfo = window.open(filename,"Hyttinformation","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=670,height=500");
        newcabinInfo.window.focus();
}

//Kopierad och modifierad från finska siten för att hantera popup fönster för hytter under svenska siten
function picturePopup (pic, alt, lang, width, height) {

  if (!width || width == '' || width < 1) width = 363;
  if (!height || height == '' || height < 1) height = 278;
  var winHeight = height + 48;
  
  window.open ('/commonSE/picturepopup.asp?pic=' + pic + '&alt=' + alt + '&lang=' + lang + '&width=' + width + '&height=' + height, '_blank', 'width=' + width + ',height=' + winHeight + ',innerWidth=' + width + ',innerHeight=' + winHeight + ',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
}
function cabinPicturePopup (pic, alt, fartyg, hytt, lang, width, height) {
  if (!width || width == '' || width < 1) width = 363;
  if (!height || height == '' || height < 1) height = 278;
  var winHeight = height + 150;
  
  window.open ('/commonSE/cabinpopup.asp?pic=' + pic + '&alt=' + alt + '&fartyg=' + fartyg + '&hytt=' + hytt + '&lang=' + lang + '&width=' + width + '&height=' + height, '_blank', 'width=' + width + ',height=' + winHeight + ',innerWidth=' + width + ',innerHeight=' + winHeight + ',directories=no,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no');
}
//Anropas när man byter hyttkategori i dropdown-listan i bokningen, visar "bild" länken om man valt en hytt
function cabinKat() {
   alertQcabin();
   var hytTyp = document.getElementById("hyttKategori").value;
   oLayer=getLayer("hyttLayer");
   oLayer2=getLayer("hyttLayer2");
    if (hytTyp == "" || hytTyp == null) {
	  oLayer.style.visibility = 'hidden';
	  oLayer2.style.visibility = 'visible';
	}
   else {
      oLayer.style.visibility = 'visible';
	  oLayer2.style.visibility = 'hidden';
	  return hytTyp.toLowerCase();
   }
}

var checkQ = 0;

function alertQcabin() {
	var cabinType = document.getElementById("hyttKategori").value; 
	var currentLocation = window.location.href;
	if(checkQ < 1) {
		if(cabinType.charAt(0) == 'Q') {
			checkQ++;
			if(currentLocation.match("/finland/")) {	
				alert("OBS!\n\nHyttkategorin du har valt saknar WC och dusch!\nDessa finns dock tillgängliga i hyttkorridoren.\nQ-hytterna har en lägre standard än våra övriga hytter.");
			}
			else if(currentLocation.match("/suomi/")){
				alert("HUOM!\n\nValitsemassasi hyttiluokassa ei ole suihkua eikä WC:tä,\nvaan ne sijaitsevat hyttikäytävällä.\nQ-hytit ovat tasoltaan muita vaatimattomampia.");
			}
			else if(currentLocation.match("/eesti/")){
				alert("N.B.!\n\nTeie poolt valitud kajutiklassis puudub WC ja dušš!\nNeed asuvad kajutite vahelises koridoris.\nQ-klassi kajutid on madalama standardiga, kui teised kajutid.");
			}
			else {
				alert("\nOBS!\n\nHyttkategorin du har valt saknar WC och dusch!\nDessa finns dock tillgängliga i hyttkorridoren.\nQ-hytterna har en lägre standard än våra övriga hytter.");
			}
		}
	}
}

function openInfoHelpReguljar() {	
	newHelpA = window.open("/bokning/instruktioner_reguljara_resor.asp","Information","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=380");
	newHelpA.window.focus();
}
function openInfoResevillkor() {	
	newHelpA = window.open("/bokning/resevillkor.asp","Information","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=380");
	newHelpA.window.focus();
}
// Hämtar ett lager beroende på browser

function getLayer(sLayer){
	if (document.layers) var NS4 = true; else var NS4 = false;
	if (document.getElementById && !document.all) var NS6 = true; else NS6 = false;
	if (document.all && !window.opera) var IE = true; else var IE = false;
	
	if(NS6){
		sLayer = "document.getElementById('"+sLayer+"')"; 	
	}
	if(IE){
		sLayer = "document.all['"+sLayer+"']";
	}
	if(NS4){
		sLayer = "document.layers[''"+sLayer+"''])";	
	}
	return eval(sLayer);;
}

function showAvgangsInfo(i){
        oLayer=getLayer("avganginfo"+i);
	oLayer.style.visibility = "visible";

}

function hideAvgangsInfo(i){
	oLayer=getLayer("avganginfo"+i);
	oLayer.style.visibility = "hidden";

}  

function isFieldBlank(theField) {
	if(theField.value == "" || isBlank(theField))
		return true;
	else
		return false;
}
// Kontrollera att fältet inte innehåller "white space"

function isBlank(theField) {
   for(var i = 0;i < theField.value.length;i++) {
      var c = theField.value.charAt(i);
      if((c != ' ') && (c != '\n') && (c != '\t')) {
         return false;
      }
   }
   return true;
}
function openStugInfo(sUrl){

	   newStugInfo = window.open(sUrl,"Stuginformation","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=550,height=400");
	   newStugInfo.window.focus();
} 
function openInfoHelp(file_to_open) {
	filename = "/commonSE/infopopup.asp?file=" + file_to_open;
	newHelpA = window.open(filename,"Information","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=435");
        newHelpA.window.focus();
}
function openInfoStugHelp()
{	
	newHelpA = window.open("/Bokning/Stugbokning_info.htm","Information","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=380");
	newHelpA.window.focus();
}
function showresult(a,b,c,d) {
	//Båt,språk,datum,klocka (d används inte längre)
	popupWinSearch = window.open('/common/artister/getShipDateTime.aspx?ShipId=' + a + '&lang=' + b + '&Datum=' + c, 'Result', 'scrollbars=yes,resizable=yes,width=500,height=380');
	popupWinSearch.focus();
}
function showEntertainment(a,b,c) {
	//Öppnar artist popup! Parametrar: Båt,språk,id
	popupWinSearch = window.open('/ArtistSokning/SpecificDeparture.aspx?ferry=' + a + '&lang=' + b + '&id=' + c, 'Result', 'scrollbars=yes,resizable=yes,width=505,height=425');
	popupWinSearch.focus();
}
function checkElement(theValue) {
	if (document.getElementById(theValue) != null) {
		return true;
	} else {
		return false;
	}
}
function underline(element) {
  element.style.textDecoration="underline";
} 
function removeUnderline(element) {
  element.style.textDecoration="none";
}
function getCookie(check_name) {
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; 

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		if (cookie_name == check_name) {
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1) {
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if (!b_cookie_found) {
		return null;
	}
}
function createCookie(name, value, expires) {
	var today = new Date();
	today.setTime( today.getTime() );
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) + (( expires ) ? ";expires=" + expires_date.toGMTString() : "" );

}
function deleteCookie(name, path) {
	if (getCookie( name )) {
		document.cookie = name + "=" + 	( ( path ) ? ";path=" + path : ""); + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}
function checkCookies() {
	createCookie( 'test', 'none', '');
	if (getCookie('test')) {
		cookie_set = true;
		deleteCookie('test', '/', '');
		return true;
	} else {
		cookie_set = false;
		return false;
	}
}
