﻿/*Used for search box on seaways master */
function searchClick()
{
    document.location.href = '/pages/search.aspx?k=' + document.getElementById('searchinput').value;				
}
function IsEnter()
{
	if(event.keyCode && event.keyCode == 13)
		searchClick();
}

var Browser = { 
    Version: function() {    
        var version = 999; // we assume a sane browser    
        if (navigator.appVersion.indexOf("MSIE") != -1)
            // bah, IE again, lets downgrade version number
            version = parseFloat(navigator.appVersion.split("MSIE")[1]);
        return version;
    }
}

/*Used to add specifc stylesheet for IE*/
function InsertIEStylesheet()
{
    if (Browser.Version() < 7)
        document.createStyleSheet('/_layouts/dfds/styles/dfdsie6.css');
}

/*Used on all "More Text" links*/
var action;
var actionArray = new Array();
var actionTextArray = new Array();


function ToggleText(linkelement,moretext,lesstext)
{
     var linkobject;  
     
     if( document.getElementById ) 
     {            
        linkobject = document.getElementById( linkelement );  
     }   
     else if( document.all )       
     {            
		linkobject = document.all[linkelement]; 
     }
     else if( document.layers ) 
     {
		linkobject = document.layers[linkelement]; 
     } 
     
	 if(actionTextArray[GetToggleTextIndex(linkelement)] == 'close')
	 {	
		linkobject.innerHTML = moretext;
		actionTextArray[GetToggleTextIndex(linkelement)] = 'open';
	 }
	 else
	 {	
		linkobject.innerHTML = lesstext;
		actionTextArray[GetToggleTextIndex(linkelement)] = 'close';
	 }
}

function GetToggleTextIndex(linkelement) {
    
    var arLen=actionArray.length;
    var index = -1;
    
    for (var i = 0, len = arLen; i < len; ++i) {
        if (actionArray[i] == linkelement) {
            index = i;
        }            
    }

    if (index == -1) {
        actionArray[arLen] = linkelement;
        index = arLen;
    }
    
    return index;
}

var subdomain = ".dk.";
function SetDomain()
{
    if(document.domain.indexOf('dfds.root',0) > -1 )
    {
        document.domain = "dfds.root";
        subdomain = ".dk.";
    }
    else
    {
        document.domain = "dfds.ext";
        subdomain = ".dmz1.";
    }
}

var RadE_HasRules = false;
if (typeof(RadEditorCommandList) == "undefined")
{
	RadEditorCommandList = new Array();
}

RadEditorCommandList["DFDS MediaBank"] = function DFDSMediaBank(RadEditorContentArea)
{
         SetDomain();

		// Get the chosen image from the Modal Dialog
		var values = showModalDialog("http://mediabank"  + subdomain + document.domain + "/SelectMediaFileBrowser.aspx", "", "status: no; dialogHeight: 730px; scroll: no; dialogWidth: 1000px; center: yes;");


		//If a image was selected
		if(values != null && values[0] != null && values[0] != "")
		{
			// Concat the image URL
			var imageURL = values[0];

			// Create the image tag to insert in the editor
			var imageTag = "<img src=\"" + imageURL + "\" height=\"" + values[2] + "\" width=\"" + values[1] + "\" border=\"0\">";

			// Insert the image tag
			var range = document.selection.createRange();
			range.pasteHTML(imageTag);
		}
}

// Opens a Modal dialog with the Image Bank and inserts the selected image into the objImageTag 
function InsertImageFromImageBank(objImageTag, minX, maxX, minY, maxY)
{
		var startpath = "";
         SetDomain();

		// Get the chosen image from the Modal Dialog
		var values = showModalDialog("http://mediabank"  + subdomain + document.domain + "/SelectMediaFileBrowser.aspx?minX="+minX+"&maxX="+maxX+"&minY="+minY+"&maxY="+maxY, "", "status: no; dialogHeight: 730px; scroll: no; dialogWidth: 1000px; center: yes;");
		
		//If a image was selected
		if(values[0] != "" && values[0] != null)
		{
			// Concat the image URL
			var imageURL = startpath + values[0];

			// Create the image tag to insert in the editor
			if (objImageTag != undefined) 
			{				
				objImageTag.src=imageURL;
				objImageTag.width = values[1];
				objImageTag.style.width = values[1];
				objImageTag.height = values[2];
				objImageTag.style.height = values[2];
			}
		}
	return values;
}

function openSelectMediaFileDialog(minX, maxX, minY, maxY, groupid, prefieldname) {
    //minX				: minmum width of picture.
    //maxX				: maximum width of picture.
    //minY				: minmum height of picture.
    //maxY				: maximum height of picture.
    //groupid			: Allowed group type of pictures ( web pictures or document ).
    //prefieldname		: Prename of all the fields.
    //startpath			: Virtual start path.

    //alert(prefieldname);
    var of = eval("document.all['" + prefieldname + "']");

    if (of == undefined) {
        alert("Unable to find the Html input field for the path name.");
    }
    var usedpath = of.value;
    var querystring = "filepath=" + usedpath;

    // Get values from the modal dialog
    SetDomain();

    // Get the chosen image from the Modal Dialog
    var values = showModalDialog("http://mediabank" + subdomain + document.domain + "/SelectMediaFileBrowser.aspx?minX=" + minX + "&maxX=" + maxX + "&minY=" + minY + "&maxY=" + maxY, "", "status: no; dialogHeight: 730px; scroll: no; dialogWidth: 1000px; center: yes;");
    //var values = showModalDialog("/mediabank/SelectMediaFileBrowser.aspx?" + querystring, "", "status: no; dialogHeight: 730px; scroll: no; dialogWidth: 1000px; center: yes;");

    if (values != null && values[0] != null && values[0] != "") {

        var strPath = new String(values[0]);

        if ((strPath.length > 0) && (strPath.toLowerCase() != "undefined")) {
            var hidden_width = eval("document.all['" + prefieldname + "width']");
            var hidden_height = eval("document.all['" + prefieldname + "height']");

            // width object found
            if (hidden_width != undefined) {
                hidden_width.value = values[1];
            }

            // height object found
            if (hidden_height != undefined) {
                hidden_height.value = values[2];
            }

            of.value = strPath;

            // setting picture src, width and height.

            var opf = eval("document.all['" + prefieldname + "pic']");

            //mplu was here

            // image object found
            if (opf != undefined) {
                // testvales
                opf.src = startpath + strPath;


                opf.width = values[1];
                opf.height = values[2];
            }
        }
    }

}


// Optimized by PRI
function getMediabankUrl(fieldname)
{

	//GUID				:We do not use...
	//groupid			: Allowed group type of pictures ( web pictures or document ).
	//fieldname			: Name of all the field.
	//startpath			: Virtual start path.

	// Get values from the modal dialog
    SetDomain();

	// Get the chosen image from the Modal Dialog
    var values = showModalDialog("http://mediabank"  + subdomain + document.domain + "/SelectMediaFileBrowser.aspx", "", "status: no; dialogHeight: 730px; scroll: no; dialogWidth: 1000px; center: yes;");

    if(values[0] != "" && values[0] != null)
    {	
	    document.getElementById(fieldname).value = new String(values[0]);
	}
	else
	{
	    document.getElementById(fieldname).value = "";
	}
}

// Remove hostname from url, to get relative urls
function RemoveHostFromUrl(url)
{
	if(url.indexOf("://") > -1)
	{
		url = url.substring((url.indexOf("://") + 3), url.length);
		url = url.substring(url.indexOf("/"), url.length);		
	}
	
	return url;
}

function writeFlashObject(flashClassid, flashWidth, flashHeight, flashAlign, flashMovie, flashMovieParam, flashBgColor)
{
		document.writeln('<OBJECT classid="' +flashClassid +'"');
		document.writeln('codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"');
		document.writeln('ID="DfdsFlash"');
  		document.writeln('WIDTH=' + flashWidth);
  		document.writeln('HEIGHT=' + flashHeight);
  		document.writeln('ALIGN="left">');
  		document.writeln('<PARAM NAME=salign VALUE="lt"/>');
  		document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
  		document.writeln('<PARAM NAME=movie VALUE="' + flashMovie + '">');
  		document.writeln('<PARAM NAME=quality VALUE=high>');
  		document.writeln('<PARAM NAME=menu VALUE=false>');
  		document.writeln('<PARAM NAME=scale VALUE=noscale>'); 
  		document.writeln('<PARAM NAME=bgcolor VALUE=#' + flashBgColor + '>');
  		document.writeln('<PARAM NAME=FlashVars VALUE="' + flashMovieParam + '">'); 
  		
  		document.writeln('<EMBED src="' + flashMovie +'"');
    	document.writeln('FlashVars="' + flashMovieParam + '"');
    	document.writeln('menu=false');
    	document.writeln('quality=high');
    	document.writeln('scale=noscale');
    	document.writeln('bgcolor=#" + flashBgColor + "');
    	document.writeln('swLiveConnect=FALSE');
    	document.writeln('WIDTH=' + flashWidth );
    	document.writeln('HEIGHT=' + flashHeight );
    	document.writeln('NAME="slideshow_as2_t"');
    	document.writeln('SALIGN="' + flashAlign + '"');
    	document.writeln('ALIGN="left"');
    	document.writeln('TYPE="application/x-shockwave-flash"');
    	document.writeln('PLUGINSPAGE="https://www.macromedia.com/go/getflashplayer">');
  		document.writeln('</EMBED>');
		
		document.writeln('</OBJECT>');
}

function writeFlashObject(flashClassid, flashWidth, flashHeight, flashAlign, flashMovie, flashMovieParam, flashBgColor, xmlFile) {
    document.writeln('<OBJECT classid="' + flashClassid + '"');
    document.writeln('codebase="https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"');
    document.writeln('ID="DfdsFlash"');
    document.writeln('WIDTH=' + flashWidth);
    document.writeln('HEIGHT=' + flashHeight);
    document.writeln('ALIGN="left">');
    document.writeln('<PARAM NAME=salign VALUE="lt"/>');
    document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
    document.writeln('<PARAM NAME=movie VALUE="' + flashMovie + '">');
    document.writeln('<PARAM NAME=quality VALUE=high>');
    document.writeln('<PARAM NAME=menu VALUE=false>');
    document.writeln('<PARAM NAME=scale VALUE=noscale>');
    document.writeln('<PARAM NAME=bgcolor VALUE=#' + flashBgColor + '>');
    document.writeln('<PARAM NAME=FlashVars VALUE="' + xmlFile + '">');

    document.writeln('<EMBED src="' + flashMovie + '"');
    document.writeln('FlashVars="' + xmlFile + '"');
    document.writeln('menu=false');
    document.writeln('quality=high');
    document.writeln('scale=noscale');
    document.writeln('bgcolor=#" + flashBgColor + "');
    document.writeln('swLiveConnect=FALSE');
    document.writeln('WIDTH=' + flashWidth);
    document.writeln('HEIGHT=' + flashHeight);
    document.writeln('NAME="slideshow_as2_t"');
    document.writeln('SALIGN="' + flashAlign + '"');
    document.writeln('ALIGN="left"');
    document.writeln('TYPE="application/x-shockwave-flash"');
    document.writeln('PLUGINSPAGE="https://www.macromedia.com/go/getflashplayer">');
    document.writeln('</EMBED>');

    document.writeln('</OBJECT>');
}

function settimetablecontroltexts(linkid, shipcontrolid, shiptext, arrivalcontrolid, arrivaltext, departurecontrolid, departuretext, bookingcontrolid, bookingurl)
{
    if (document.getElementById(shipcontrolid) != null)
        document.getElementById(shipcontrolid).firstChild.nodeValue = shiptext;
    	//document.getElementById(shipcontrolid).innerText = shiptext; //will not work with .innerText in Mozilla!

    if (document.getElementById(arrivalcontrolid) != null)
    	document.getElementById(arrivalcontrolid).firstChild.nodeValue = arrivaltext;
    
    if(document.getElementById(departurecontrolid) != null)
        document.getElementById(departurecontrolid).firstChild.nodeValue = departuretext;

    if(document.getElementById(bookingcontrolid) != null)
    	document.getElementById(bookingcontrolid).href = bookingurl;
    
    //if(document.getElementById(linkid) != null)
    //{
    //    document.getElementById(linkid).setAttribute("class","timetable_selectedlink");
    //}
}

function SetMonthDivVisible(oList, hiddenfieldcontrolid)
{
	document.getElementById(hiddenfieldcontrolid.value).style.display = "none";;
	
	if(document.getElementById(oList.options[oList.selectedIndex].value) != null)
	{
	    document.getElementById(oList.options[oList.selectedIndex].value).style.display = "block";
	    hiddenfieldcontrolid.value = oList.options[oList.selectedIndex].value;
	}
}

/*google analytics NB: This is dublicated in booking pages*/
function getSilverlightVersion() { 
            var version = ''; 
            var container = null; 
            try { 
                         var control = null; 
                         if (window.ActiveXObject) { 
                                     control = new ActiveXObject('AgControl.AgControl'); 
                         }
                         else { 
                                     if (navigator.plugins['Silverlight Plug-In']) { 
                                                  container = document.createElement('div'); 
                                                  document.body.appendChild(container); 
                                                  container.innerHTML= '<embed type="application/x-silverlight" src="data:," />'; 
                                                  control = container.childNodes[0]; 
                                     } 
                         }
                         if (control) { 
                                     if (control.isVersionSupported('4.0')) { version = 'Silverlight/4.0'; } 
                                     else if (control.isVersionSupported('3.0')) { version = 'Silverlight/3.0'; } 
                                     else if (control.isVersionSupported('2.0')) { version = 'Silverlight/2.0'; } 
                                     else if (control.isVersionSupported('1.0')) { version = 'Silverlight/1.0'; } 
                         }
            }
            catch (e) { } 
            if (container) {
                         document.body.removeChild(container); 
            }
            return version; 
}
