// Browser
version = parseInt(navigator.appVersion);
if (navigator.appVersion.indexOf('6.')>-1) {version=5};
if (navigator.appName=='Netscape') {browser='NS'+version;}
if (navigator.appName=='Opera') {browser='OP'+version;}
if (navigator.appName=='Microsoft Internet Explorer') {browser='MSIE'+version;}
// Browser, end

//Define the selected menu item
var currentMenu = 0

// Netscape 4 resize bug fix
function reDo(){ 
    if (browser=='NS4') 
    {
        window.location.reload()
    }
}
window.onresize = reDo;
// Netscape 4 resize bug fix, end

function checkBrowserHeight() {
    if(navigator.appName.indexOf('Microsoft Internet Explorer')!=-1)
        var height = document.body.clientHeight - 200;
    else if(navigator.appName.indexOf('Opera')!=-1)
        var height = window.innerHeight - 200;
    else if(navigator.appName.indexOf('Netscape')!=-1)
        var height = window.innerHeight - 200;
    return height;
}

function checkBrowserWidth() {
    if(navigator.appName.indexOf('Microsoft Internet Explorer')!=-1)
        var width = document.body.clientWidth - 15;
    else if(navigator.appName.indexOf('Opera')!=-1)
        var width = window.innerWidth - 55;
    else if(navigator.appName.indexOf('Netscape')!=-1)
        var width = window.innerWidth - 30;
        
    return width;
}

// Menu scriptet!!!
// Open menu layer
var timerID;

function changeLayer(nummer) 
{
    //if(timerID != "")
    //    clearTimeout(timerID);
	 
    hideAll();
   
    if (browser=='MSIE4' || browser=='MSIE5') {
    	
        if (document.all['lag'+nummer] != null)
            document.all['lag'+nummer].style.visibility = "visible";

        if (document.all['sel'+nummer] != null)         
            document.all['sel'+nummer].style.visibility = "visible";

        if (document.all['menuitem' + nummer] != null)
            document.all['menuitem' + nummer].style.color = "#0099CC";

        if (document.all['cell' + nummer] != null)
            document.all['cell' + nummer].bgColor = "#000033";
            
        if (document.all['layer' + nummer] != null)
        {
            document.all['layer' + nummer].style.display = "";
            document.all['layer'+ nummer].style.visibility = "visible";
        }
            

    }

    if (browser=='NS4') {
        document.layers['lag'+nummer].visibility = "show";
        document.layers['sel'+nummer].visibility = "show";
        
        if (document.layers['menuitem' + nummer] != null)
            document.layers['menuitem' + nummer].style.color = "#0099CC";

        if (document.layers['cell' + nummer] != null)
            document.layers['cell' + nummer].bgColor = "#000033";        
    }
    
    //alert("browser " + browser)
    if (browser=='NS5') {
        //document.getElementById('lag'+nummer).style.visibility = "visible";
        //document.getElementById('sel'+nummer).style.visibility = "visible";
        
        //alert("am here " + document.getElementById('lag'+nummer)); 

        if (document.getElementById('lag'+nummer) != null)
            document.getElementById('lag'+nummer).style.visibility = "visible";

        if (document.getElementById('sel'+nummer) != null)         
            document.getElementById('sel'+nummer).style.visibility = "visible";

        if (document.getElementById('menuitem' + nummer) != null)
            document.getElementById('menuitem' + nummer).style.color = "#0099CC";

        if (document.getElementById('cell' + nummer) != null)
            document.getElementById('cell' + nummer).bgColor = "#000033";
            
        if (document.getElementById('layer' + nummer) != null)
        {
            document.getElementById('layer' + nummer).style.display = "";
            document.getElementById('layer'+ nummer).style.visibility = "visible";
        }
        
    }
    
    
    //Make sure not yo run this in http://maersk.mondosearch.com
    //if(location.href.indexOf("mondo")==-1)
    //{
    //    if(nummer != currentMenu)
    //        timerID = setTimeout("returnLayer()",4000);
    //}

}
// Open menu layer, end

// Close all menu layers
function hideAll() {


    if (browser=='MSIE4' || browser=='MSIE5') {
     
        for (i = 1; i < 8; i++) {
            
            if (document.all['lag'+i] != null) 
                document.all['lag'+i].style.visibility = "hidden";
            
            if (document.all['sel'+i] != null) 
                document.all['sel'+i].style.visibility = "hidden";

            if (document.all['layer'+i] != null) 
            {
                document.all['layer'+i].style.visibility = "hidden";
                document.all['layer'+i].style.display = "none";
            }
               
                
            if (document.all['menuitem' + i] != null)
                document.all['menuitem' + i].style.color = "white";
                
            if (document.all['cell' + i] != null)
                document.all['cell' + i].bgColor = "";
                
        }
         
    }

    if (browser=='NS4') {
        for (i = 1; i < 8; i++) {
            document.layers['lag'+i].visibility = "hide";
            document.layers['sel'+i].visibility = "hide";
            
            if (document.layers['menuitem' + i] != null)
                document.layers['menuitem' + i].style.color = "white";
                
            if (document.layers['cell' + i] != null)
                document.layers['cell' + i].bgColor = "";
            
        }
    }
        
    if(browser=='NS5') {
     
     
        for (i = 1; i < 8; i++) {
        	
            if (document.getElementById('lag'+i) != null)
     	    	document.getElementById('lag'+i).style.visibility="hidden";
     		
     
     	    if (document.getElementById('sel'+i) != null)  
            	document.getElementById('sel'+i).style.visibility="hidden";
            	
            if (document.getElementById('layer'+i) != null) 
	    {
		document.getElementById('layer'+i).style.visibility = "hidden";
		document.getElementById('layer'+i).style.display = "none";
            }
            
            if (document.getElementById('menuitem' + i) != null)
                document.getElementById('menuitem' + i).style.color = "white";
            
            if (document.getElementById('cell' + i) != null)
                document.getElementById('cell' + i).bgColor = "";
        
        }
         
    }
}
// Close all menu layers, end
// Menu scriptet!!! end

function returnLayer()
{
    changeLayer(currentMenu);
}


function MM_jumpMenu(targ,selObj,restore){
  window.open (selObj.options[selObj.selectedIndex].value);
  if (restore) selObj.selectedIndex=0;
}

function setLang(selObj,hvorfra) {
    lang = selObj.options[selObj.selectedIndex].value;
//  alert(lang + ' ' + hvorfra); 
    location.href="setcookie.asp?lang=" +lang + "&hvorfra=" + hvorfra;
}

function lang(lang,hvorfra) {
//  alert(lang + ' ' + hvorfra);
    location.href="setcookie.asp?lang=" +lang + "&hvorfra=" + hvorfra;
}
//-->

        //Function to change the top image on the left corner at a regular interval
        var topImgTimerID;
        var imgArrayCounter = -1

        var imgArray = new Array()
        var cachedImagePrefix = "";

        imgArray[0] = "car carrier.jpg";
        imgArray[1] = "car carrier.jpg";
        imgArray[2] = "car carrier.jpg";
        imgArray[3] = "car carrier.jpg";
        imgArray[4] = "car carrier.jpg";
        imgArray[5] = "car carrier.jpg";
        imgArray[6] = "car carrier.jpg";
        imgArray[7] = "car carrier.jpg";

        function changeTopImage(imagePrefix)
        {
                if (imagePrefix != null && imagePrefix != "")
                    cachedImagePrefix = imagePrefix

                if(topImgTimerID != "")
                    clearTimeout(topImgTimerID);

                var topRightImg = document.all("topRightImg");

                if (topRightImg != null)
                {
                    topRightImg.filters[0].apply();

                    imgArrayCounter = imgArrayCounter + 1

                    //reset the image array counter
                    if (imgArrayCounter > 7)
                        imgArrayCounter = 0

                    topRightImg.src = cachedImagePrefix + imgArray[imgArrayCounter];

                    topRightImg.filters[0].play();
                }

                topImgTimerID = setTimeout("changeTopImage('')",3000);
        }


function trim(untrimmed)
{ 
    var trimmed = untrimmed;
    
    if(!trimmed)
        ;//do nothing
    else
    {
        while (trimmed.length != 0 && trimmed.substr(0,1) == " ") 
            trimmed = trimmed.substr(1); 
  
        while (trimmed.length != 0 && trimmed.substr(trimmed.length-1,1) == " ") 
            trimmed = trimmed.substr(0,trimmed.length-1); 
    }   
    return trimmed; 
} 

//to check the length of the Text Area Control
function ChkTextAreaLen(ctrl,len)
{
    if(ctrl.value.length>=Number(len))  
    {
        window.event.keyCode=0
        return false;
    }
    
    return true;
}



/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
    var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
        if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
    var returnString = ""
    var daysInMonth = DaysArray(12)
    var pos1=dtStr.indexOf(dtCh)
    var pos2=dtStr.indexOf(dtCh,pos1+1)
    var strDay=dtStr.substring(0,pos1)
    var strMonth=dtStr.substring(pos1+1,pos2)
    var strYear=dtStr.substring(pos2+1)
    strYr=strYear
    if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
    if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
    }
    month=parseInt(strMonth)
    day=parseInt(strDay)
    year=parseInt(strYr)
    if (pos1==-1 || pos2==-1){
        returnString = "format should be : dd/mm/yyyy"
        return returnString
    }
    if (strMonth.length<1 || month<1 || month>12){
        returnString = "month is invalid"
        return returnString
    }
    if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
        returnString = "day is invalid"
        return returnString
    }
    if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
        returnString = "Year is invalid. Enter a 4 digit year between "+minYear+" and "+maxYear
        return returnString
    }
    if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
        returnString = "enter a valid date"
        return returnString
    }
    return returnString
}

function ValidateForm(){
    var dt=document.frmSample.txtDate
    if (isDate(dt.value)==false){
        dt.focus()
        return false
    }
    return true
 }



function CompareDates(fromDate, toDate) 
{ 
   
    //compare the two dates by taking the date values and 
    //then comparing
    // returns -:
    //   1   -  if fromDate > toDate
    //   0   -  if fromDate = toDate
    //   -1  -  if fromDate < toDate
    
    var d1_str = fromDate;
    var d2_str = toDate;

    var d1 = new Date(d1_str.split('/')[2],parseInt(d1_str.split('/')[1])-1,d1_str.split('/')[0]);
    var d2 = new Date(d2_str.split('/')[2],parseInt(d2_str.split('/')[1])-1,d2_str.split('/')[0]);

    if (d1.getTime() == d2.getTime())
    {
        return 0;
    }
    if (d1.getTime()<d2.getTime()) {
      return -1;
    }

    return 1;
    

} 

