﻿


    var cX = 0;
    var cY = 0;
    var rX = 0;
    var rY = 0;
    function UpdateCursorPosition(e) {
        cX = e.pageX; cY = e.pageY;
    }
    function UpdateCursorPositionDocAll(e) {
        cX = event.clientX; cY = event.clientY;
    }
    if (document.all) {
        document.onmousemove = UpdateCursorPositionDocAll;
    } else {
        document.onmousemove = UpdateCursorPosition;
    }
    function AssignPosition(d) {
        if (self.pageYOffset) {
            rX = self.pageXOffset; rY = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            rX = document.documentElement.scrollLeft;
            rY = document.documentElement.scrollTop;
        } else if (document.body) {
            rX = document.body.scrollLeft;
            rY = document.body.scrollTop;
        }
        if (document.all) {
            cX += rX; cY += rY;
        }

        d.style.left = (cX + 10) + "px";
        d.style.top = (cY + 10) + "px";
    }

    function HideContent(d) {
        if (d.length < 1) {
            return;
        }
        document.getElementById(d).style.display = "none";
    }

    function ShowContent(d) {
        if (d.length < 1) {
            return;
        }
        var dd = document.getElementById(d);
        AssignPosition(dd);
        dd.style.display = "block";
    }

    function ReverseContentDisplay(d) {
        if (d.length < 1) {
            return;
        }
        var dd = document.getElementById(d);
        AssignPosition(dd);
        if (dd.style.display == "none") {
            dd.style.display = "block";
        } else {
            dd.style.display = "none";
        }
    }

    function popOverAir(city1, city2, city3, city4, date1, date2, adults, children, price, carrierCode, carrierName, oneWay, flex, openJaw, CSS) {

        var childArr = new Array();
        if (children.toString().length > 0) {
            childArr = children.toString().split('/');
        }

        var tempHTML = '<div class="' + CSS + '"><div class="top"><div class="bottomTop">';
        if (openJaw) {
            tempHTML += '<b class="popupHeaderText">' + city1 + '/' + city3 + ' - ' + city2 + '/' + city4 + '</b>';
        } else {
            tempHTML += '<b class="popupHeaderText">' + city1 + ' - ' + city2 + '</b>';
        }
        tempHTML += '<span class="popupHeaderCarrierText"> med ' + carrierName + '</span><br />';
        tempHTML += '</div>';
        tempHTML += '<div class="bottom">';
        tempHTML += '<div style="padding: 8px 0px 5px 0px; color: #666666;">';
        tempHTML += '  <table>';
        tempHTML += '    <tr>';


        tempHTML += '      <td style="padding: 5px 0px 0px 1px; width:45px; height:45px; background-repeat: no-repeat; background-position:center center; background-image: url(\'/images/logos/' + carrierCode + '.gif\');">';
        tempHTML += '        <img src="/img/carrier_font_image.png" style="width: 45px; height: 45px;" />';
        tempHTML += '      </td>';

        tempHTML += '      <td style="width: 162px; padding: 2px 12px 0px 12px;">';
        tempHTML += '        <table width="100%">';
        tempHTML += '          <tr>';
        tempHTML += '            <td width="55%" style="padding: 0px 0px 4px 0px;">';
        tempHTML += '              <b>Avresa:</b><br />' + date1;
        tempHTML += '            </td>';
        tempHTML += '            <td width="45%">';
        if (oneWay) {
            tempHTML += '              <b>Ankomst:</b><br />' + date2;
        } else {
            tempHTML += '              <b>Hemresa:</b><br />' + date2;
        }
        tempHTML += '            </td>';
        tempHTML += '          </tr>';
        tempHTML += '          <tr>';
        tempHTML += '            <td width="100%" colspan="2" style="border-top: 1px solid #DDDDDD; padding: 2px 0px 0px 0px; ">';
        tempHTML += '              <b>Vuxna</b> ' + adults + 'st';
        if (childArr.length > 0) {
            tempHTML += '          <b>, barn</b> ' + childArr.length + 'st';
        }
        tempHTML += '            </td>';
        tempHTML += '          </tr>';
        tempHTML += '        </table>';
        tempHTML += '      </td>';
        tempHTML += '      <td align="center">';
        tempHTML += '        <b class="big_price_Toplist" style="font-family: Arial, Helvetica, sans-serif;">' + price + 'kr</b><br />';
        tempHTML += '        <b style="color: #666666;">&nbsp;inkl. skatter</b>';
        tempHTML += '      </td>';
        tempHTML += '    </tr>';
        tempHTML += '  </table>';
        tempHTML += '</div>';
        tempHTML += '</div>';


        tempHTML += '</div></div></div>';

        var MouseoverDiv = document.getElementById('mouseOver_yui');

        MouseoverDiv.innerHTML = tempHTML;

        ShowContent('mouseOver_yui');
        return true;
        //Tip(tempHTML);
    }

    function UnTip() {
        HideContent('mouseOver_yui');
        return true;
    }
    
    function popFlightCampaign(header, text) {
        var tempHTML = '<div style="background-color: #FFFFFF; border: dotted 1px #444444; padding: 10px;">';
        tempHTML += '<b>' + header + '</b><br />';
        tempHTML += text;
        tempHTML += '</div>';
        
        var MouseoverDiv = document.getElementById('mouseOver_yui');
        MouseoverDiv.innerHTML = tempHTML;
        ShowContent('mouseOver_yui');
        return true;
        //Tip(tempHTML);

    }

    function popOverCar(city1, description, imageUrl, price, CSS) {

        var tempHTML = '<div class="' + CSS + '"><div class="top"><div class="bottomTop">';
        //tempHTML += '<b class="popupHeaderText">Hyrbil i ' + city1 + '</b>';

        tempHTML += '<b class="popupHeaderText">' + description + '</b>';

        tempHTML += '<span class="popupHeaderCarrierText"> eller liknande</span><br />';
        tempHTML += '</div>';
        tempHTML += '<div class="bottom">';
        tempHTML += '<div style="padding: 8px 0px 0px 0px; color: #666666;">';
        tempHTML += '  <table width="100%">';
        tempHTML += '    <tr>';


        tempHTML += '      <td style="padding: 0px; width:92px;">';
        tempHTML += '        <img src="' + imageUrl + '" style="width: 92px; height: 55px; " />';
        tempHTML += '      </td>';

        tempHTML += '      <td style="width: 135px; padding: 2px 0px 0px 2px;">';
        tempHTML += '        <table width="100%">';
        tempHTML += '          <tr>';
        tempHTML += '            <td width="100%" style="padding: 2px 0px 0px 10px;">';
        tempHTML += '              <b>Hyrbil i ' + city1 + '</b><br />';
        tempHTML += '                 pris för en vecka,<br />';
        tempHTML += '                 inkl. fria mil<br />';
        tempHTML += '            </td>';
        tempHTML += '          </tr>';
        tempHTML += '        </table>';
        tempHTML += '      </td>';
        tempHTML += '      <td align="center">';
        tempHTML += '        <b class="big_price_Toplist" style="font-family: Arial, Helvetica, sans-serif;">' + price + 'kr</b><br />';
        tempHTML += '        <b style="color: #666666;">&nbsp;inkl. skatter</b>';
        tempHTML += '      </td>';
        tempHTML += '    </tr>';
        tempHTML += '  </table>';
        tempHTML += '</div>';
        tempHTML += '</div>';


        tempHTML += '</div></div></div>';

        var MouseoverDiv = document.getElementById('mouseOver_yui');

        MouseoverDiv.innerHTML = tempHTML;

        ShowContent('mouseOver_yui');
        return true;
        //Tip(tempHTML);
    }

    function popOverHotel(name, resort, stars, price_per_night, headline, imageId, CSS) {

        var tempHTML = '<div class="' + CSS + '"><div class="top"><div class="bottomTop">';
        tempHTML += '<b class="popupHeaderText">' + name + '</b>';

        tempHTML += '<span class="popupHeaderCarrierText"> ' + resort + '</span><br />';
        tempHTML += '</div>';
        tempHTML += '<div class="bottom">';
        tempHTML += '<div style="padding: 8px 0px 0px 0px; color: #666666;">';
        tempHTML += '  <table width="100%">';
        tempHTML += '    <tr>';

        tempHTML += '      <td style="padding: 2px; border: 1px solid #DDDDDD; width:75px;">';
        tempHTML += '        <img src="http://www.flygstolen.se/images/sun_images/' + imageId + '.jpg" style="width: 75px; height:60px" />';
        tempHTML += '      </td>';

        tempHTML += '      <td style="width: 205px; padding: 2px 0px 0px 15px;">';
        tempHTML += '        <table width="100%">';
        tempHTML += '          <tr>';
        tempHTML += '            <td>';
        tempHTML += '              <img src="/images/hotels/stars/' + stars + 's_stars.png" />';
        tempHTML += '            </td>';
        tempHTML += '            <td style=" text-align:right;">';
        tempHTML += '              <b style="color:#E60E63;">' + price_per_night + 'kr/natt</b><br />';
        tempHTML += '            </td>';
        tempHTML += '          </tr>';
        tempHTML += '          <tr>';
        tempHTML += '            <td colspan="2">'+headline+'</td>';
        tempHTML += '          </tr>';
        tempHTML += '        </table>';
        tempHTML += '      </td>';
        tempHTML += '    </tr>';
        tempHTML += '  </table>';
        tempHTML += '</div>';
        tempHTML += '</div>';


        tempHTML += '</div></div></div>';

        var MouseoverDiv = document.getElementById('mouseOver_yui');

        MouseoverDiv.innerHTML = tempHTML;

        ShowContent('mouseOver_yui');
        return true;
        //Tip(tempHTML);
    }

    function popOverTwitter(text, created) {

        var tempHTML = '<div class="popupTwitter"><div class="top"><div class="bottomTop" style=" border-bottom: 1px solid #DDDDDD;">';
        tempHTML += '<img src="/images/icons/twitter_logo.png" >&nbsp;&nbsp;';
        tempHTML += ' <span style=" color:#666666; ">' + created + '</span><br />';
        tempHTML += '</div>';
        tempHTML += '<div class="bottom">';
        tempHTML += '<div style="padding: 3px 0px 0px 8px; color: #666666;">';
        tempHTML += '<b>'+  FormatUrls(text) +'</b>';
        tempHTML += '</div>';
        tempHTML += '</div>';


        tempHTML += '</div></div></div>';

        var MouseoverDiv = document.getElementById('mouseOver_yui');

        MouseoverDiv.innerHTML = tempHTML;

        ShowContent('mouseOver_yui');
        return true;
    }
    


function FormatUrls(txt) {
    var regUrl = /(^|[^>\"\/])(http:\/\/|www\.)(?:[^\"])\S*([\s\)\!]|$)/gi;
    var aTag = '<a href="{0}">{1}</a>';
    var regUrlTail = /[\!\)\]\.\?]+$/g; // capture trailing non-url, non-space characters from the end of a string.
    
    txt = txt.replace(regUrl, function($href,$start,$urlStart,$end,$pos,$txt){
        if(!$href) // no match
            return ''; // nothing to replace
        if($start) // a character (not just the begining of the txt)
            $href=$href.substr(1,$href.length-1); // remove start character
        if($end) // end will be one character but might include an extra trailing characters (such as '!!!')
            $href=$href.substr(0,$href.length-1); // remove end character
        // capture trailing non-space, non-url characters (matched as part of \S*
        var trail = $href.match(regUrlTail);
        if(trail) $href = $href.replace(regUrlTail,''); // strip trail from link
        if($href.search(/http/i)!=0) $href = 'http://' + $href; // must start with http://
        var lnk = $href; //ellipsis($href,45); // keep visible link short
        return $start + String.format(aTag,stripMal($href),stripMal(lnk)) + (trail?trail[0]:'') + $end; // add the start and trail+end back on
    });
    return txt;
}

function stripMal(txt) {
    return txt.replace(/(?:java|vb)?(?:script|data):/gi,'');
}


