﻿
//============
// AutoView
//============

 //<!CDATA[
 
var isMac = navigator.userAgent.toUpperCase().indexOf("MAC") != -1
var _elem_Root = null;
var _arr_ContFile = null;
var  _MultiArray = new Array(11);
var _intervalID = 0;
var _sTmpNo = "";
var _currElem=null;

//Be nice to the client
window.onunload=function(){
    clearInterval(_intervalID);
}

function MouseOver(othis) {
    
    if (othis.style.backgroundColor != null) {
        _sTmpNo = othis.innerHTML;
        othis.innerHTML = "X";
    }
}

function MouseOut(othis) {
    if (othis.style.backgroundColor != null) {
        othis.innerHTML = _sTmpNo;
    }
}

function GetCurrRecID(sID) {
   
    if (sID != "") {
        var arrTmp = sID.split("_");
        return arrTmp[1];
    } else {
        return "0";
    }
}

function getImageType(imageUrlBase) {

    var imageType = 0;
    if (imageUrlBase != "") {
        if (imageUrlBase.toUpperCase().indexOf(".SWF") != -1) {
            imageType = 1;
        }
        else if (imageUrlBase.toUpperCase().indexOf(".MPG") != -1 ||
                imageUrlBase.toUpperCase().indexOf(".MPEG") != -1 ||
                imageUrlBase.toUpperCase().indexOf(".WMV") != -1 ||
                imageUrlBase.toUpperCase().indexOf(".MOV") != -1 ||
                imageUrlBase.toUpperCase().indexOf(".3GP") != -1 ||
                imageUrlBase.toUpperCase().indexOf(".MP3") != -1) {

            if (imageUrlBase.toUpperCase().indexOf(".WMV") != -1 || imageUrlBase.toUpperCase().indexOf(".WMA") != -1 || imageUrlBase.toUpperCase().indexOf(".MP3") != -1) {
                imageType = 2;
            }
            else {
                imageType = 3;
            }

        }
        else if (imageUrlBase.toUpperCase().indexOf(".FLV") != -1) {
            imageType = 4;
        }
        else if (imageUrlBase.toUpperCase().indexOf(".PDF") != -1) {
            imageType = 6;
        }
        else if (imageUrlBase.toUpperCase().indexOf(".TXT") != -1) {
            imageType = 7;
        }
    }

    return imageType;
}

function getAdObjectType_0(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {
    var strAdObj = "<a id='AdFile_" + sRecID + "' href=" + sHref + " target='_blank'>";

    strAdObj += "<img src=" + sImgSrc + " alt='" + sTitle + "' title='" + sTitle + "' style='height:" + sHeight + "px;width:" + sWidth + "px;border-width:0px;'/>";
    strAdObj += "</a>";
    return strAdObj;
}

//Flash
function getAdObjectType_1(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {

    var strAdObj = "<div id='AdFile_" + sRecID + "' style='position:relative;width:" + sWidth + "px;height:" + sHeight + "px;display:block'>";
    if(sBgColor==""){
        sBgColor="Transparent";
    }
    strAdObj += "<a id='NavigateUrl_" + sRecID + "' href='" + sHref + "' target='_blank' style='background-color:" + sBgColor + ";display:inline'>";
    strAdObj += "<img src='App_Themes/Image/blank.gif' alt='" + sTitle + "' title='" + sTitle + "' style='width:100%;height:100%;position:absolute;top:0;left:0;cursor:pointer;'/></a>";
    strAdObj += "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' ";
    strAdObj += "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0' ";
    strAdObj += "id='Flash_" + sRecID + "' width='" + sWidth + " px' height='" + sHeight + "px' >";

    strAdObj += "<param name='allowScriptAccess' value='sameDomain' />";
    strAdObj += "<param name='wmode' value='opaque' />";
    strAdObj += "<param name='movie' value='" + sImgSrc + "' />";
    strAdObj += "<param name='quality' value='high' />";
    strAdObj += "<param name='bgcolor' value='" + sBgColor + "' />";
    strAdObj += "<param name='align' value='middle' />";
    strAdObj += "<param name='enabled' value='false' />";
    strAdObj += "<param name='enableContextMenu' value='false' />";

    strAdObj += "<embed id='Flash_" + sRecID + "' width='" + sWidth + "px' height='" + sHeight + "px' ";
    strAdObj += "src='" + sImgSrc + "' bgcolor='" + sBgColor + "' ";
    strAdObj += "quality='high' wmode ='opaque' align='middle' ";
    strAdObj += "enabled='0' ";
    strAdObj += "enableContextMenu='0' ";
    strAdObj += "allowscriptaccess='sameDomain' ";
    strAdObj += "type='application/x-shockwave-flash' ";
    strAdObj += "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></embed>";
    strAdObj += "</object></div>";
    return strAdObj;
}

//Silverlight / Windows Media
function getAdObjectType_2(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {
    
    var videoHeight = (parseInt(sHeight) - 15);
    videoHeight = videoHeight + "px";
    if(sBgColor==""){
        sBgColor="Transparent";
    }
    var strAdObj = "<div id='AdFile_" + sRecID + "' style='background-color:" + sBgColor + ";position:relative;width:" + sWidth + ";height:" + sHeight + ";display:block;' >";
    strAdObj += "<a id='NavigateUrl_" + sRecID + "' href='" + sHref + " target='_blank' style='display:block'>";
    strAdObj += "<img src='App_Themes/Image/blank.gif' alt='" + sTitle + "' title='" + sTitle + "' style='z-index:2;width:100%;height:" + videoHeight + ";position:absolute;top:0;left:0;cursor:pointer;' /></a>";

    strAdObj += "<object id='MediaPlayer_" + sRecID + "' data='data:application/x-silverlight-2,' type='application/x-silverlight-2' width='" + sWidth + "' height='" + sHeight + "' bgColor='" + sBgColor + "' align='middle' >";
    strAdObj += "<param name='source' value='VideoPlayer.xap'/>";
    strAdObj += "<param name='initParams' value='file=" + sImgSrc + ",autoplay=true,maximize=false'/>";
    strAdObj += "<param name='minRuntimeVersion' value='2.0.31005.0'/>";
    strAdObj += "<param name='autoUpgrade' value='true'/>";
    strAdObj += "<param name='Windowless' value='true'/>";
    strAdObj += "<param name='Autostart' value='true'/>";
    strAdObj += "<param name='EnableScrubbing' value='true'/>";

    strAdObj += "<embed type='application/x-silverlight-2'";
    strAdObj += "pluginspage='http://www.microsoft.com/netshow/download/player.htm'";
    strAdObj += "id='MediaPlayer_Embed_" + sRecID + "' width ='" + sWidth + "' height ='" + sHeight + "' bgColor='" + sBgColor + "' align='middle'";
    strAdObj += "src='" + sImgSrc + "'initParams='file=" + sImgSrc + ",autoplay=true,maximize=false' source='VideoPlayer.xap' ";
    strAdObj += "uiMode='None'";
    strAdObj += "Autostart='1' ";
    strAdObj += "autoUpgrade='1' ";
    strAdObj += "WindowlessVideo='1' ";
    strAdObj += "EnableContextMenu='0' ";
    strAdObj += "ShowControls='0'";
    strAdObj += "ShowDisplay='0'";
    strAdObj += "ShowStatusBar='0' ></embed>";

    strAdObj += "</object></div>";
    strAdObj += "<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>";
    return strAdObj;
}

//QuickTime
function getAdObjectType_3(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {

    var videoHeight = (parseInt(sHeight) - 15);
    videoHeight = videoHeight + "px";
    
    var isEmbeded = "0";
    var browsertype = "0";
    if(sBgColor==""){
        sBgColor="Transparent";
    }
    if (navigator.userAgent.toUpperCase().indexOf('MSIE') == -1) {
        browsertype = "1";
    }
    
    var strAdObj = "<div id='AdFile_" + sRecID + "' style='background-color:" + sBgColor + ";position:relative;width:" + sWidth + ";height:" + sHeight + ";display:block' >";
    //IExplorer
    if (browsertype == "0") {
        strAdObj += "<a id='NavigateUrl_" + sRecID + "' href='" + sHref + "' target='_blank' style='display:inline'>";
        strAdObj += "<img src='App_Themes/Image/blank.gif' alt='" + sTitle + "' title='" + sTitle + "' style='z-index:1;width:100%;height:" + videoHeight + ";position:absolute;top:0;left:0;cursor:pointer;' /></a>";
    }
    else {
        strAdObj += "<img src='App_Themes/Image/glow.png' alt='" + sTitle + "' title='" + sTitle + "' style='z-index:1;width:100%;height:" + sHeight + ";position:absolute;top:0;left:0;cursor:pointer;' />";
    }

    strAdObj += "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' ";
    strAdObj += "codebase='http://www.apple.com/qtactivex/qtplugin.cab#version=7,2,1,0' ";
    strAdObj += "id='QuickTime_" + sRecID + "' width='" + sWidth + "' height='" + sHeight + "' bgcolor='" + sBgColor + "' align='middle'>";

    strAdObj += "<param name='type' value='video/quicktime'/>";
    strAdObj += "<param name='src' value='" + sImgSrc + "'/>";
    strAdObj += "<param name='enableContextMenu' value='false'/>";

    strAdObj += "<param name='scale' value='tofit'/>";
    strAdObj += "<param name='controller' value='true'/>";

    strAdObj += "<param name='enabled' value='true' /> ";
    strAdObj += "<param name='enableJavascript' value='false'/>";
    strAdObj += "<param name='showlogo' value='false' />";
    strAdObj += "<param name='kioskMode' value='true'/>";
    strAdObj += "<param name='wmode' value='transparent'/>";
    strAdObj += "<param name='postdomevents' value='true'/>";
    strAdObj += "<embed type='video/quicktime'";
    strAdObj += "pluginspage='www.apple.com/quicktime/download' type='video/quicktime' ";
    strAdObj += "width='" + sWidth + "px' height='" + sHeight + "px' align='middle' ";
    strAdObj += "scale='tofit' controller='0' showlogo='false'";
    strAdObj += "enableContextMenu='0' enabled='1' postdomevents='1'";
    strAdObj += "src='" + sImgSrc + "' kioskMode='1' enableJavascript='0' ";

    //IExplorer
    if (browsertype == "0") {
        strAdObj += "wmode='transparent'>";
    }
    else {
        strAdObj += "href='<" + sHref + "> T<_blank>'>";
    }

    strAdObj += "</embed></object></div>";
    //Dummy to make quicktime visible in Internet Explorer 8
    
    if (browsertype == "0" && isEmbeded == "0") {
        isEmbeded = "1";
        strAdObj += "<div style='background-color:" + sBgColor + ";display:none;widht:0;height:0'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'";
        strAdObj += "id='FlashDummy3_" + sRecID + "' width='0px' height='0px' >";
        strAdObj += "<param name='wmode' value='opaque' />";
        strAdObj += "<param name='movie' value='#' />";
        strAdObj += "<embed id='Flash_" + sRecID + "' src='#' width='0' height='0'/> ";
        strAdObj += "</object></div>";
    }

    return strAdObj;
}

//FlashMovie
function getAdObjectType_4(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {
    
    var videoHeight = (parseInt(sHeight) - 15);
    videoHeight = videoHeight + "px";
    if(sBgColor==""){
        sBgColor="Transparent";
    }
    var strAdObj = "<div id='AdFile_" + sRecID + "' style='background-color:" + sBgColor + ";position:relative;width:" + sWidth + ";height:" + sHeight + ";display:block' >";
    strAdObj += "<a id='NavigateUrl_" + sRecID + "' href='" + sHref + "' target='_blank' style='display:block'>";
    strAdObj += "<img src='App_Themes/Image/blank.gif' alt='" + sTitle + "' title='" + sTitle + "' style='z-index:2;width:100%;height:" + videoHeight + ";position:absolute;top:0;left:0;cursor:pointer;' /></a>";

    strAdObj += "<object id='FlashPlayer_" + sRecID + "' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'";
    strAdObj += "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0'";
    strAdObj += "width='" + sWidth + "' height='" + sHeight + "' >";

    strAdObj += "<param name='flashvars' value='skin=Skin.swf&file=" + sImgSrc + "&autostart=true&overstretch=true&displayclick=none' />";
    strAdObj += "<param name='movie' value='player.swf' />";
    strAdObj += "<param name='allowscriptaccess' value='sameDomain' />";
    strAdObj += "<param name='wmode' value='opaque' />";
    strAdObj += "<param name='bgcolor' value='" + sBgColor + "' />";
    strAdObj += "<param name='align' value='middle' />";
    strAdObj += "<param name='allowfullscreen' value='true' />";
    strAdObj += "<embed id='FlashPlayerEmbed_" + sRecID + "' type='application/x-shockwave-flash'";
    strAdObj += "pluginspage='http://www.macromedia.com/shockwave/download/index.cgi/p1_prod_version=shockwaveflash' ";
    strAdObj += "width='" + sWidth + "' height='" + sHeight + "' bgcolor='" + sBgColor + "' ";
    strAdObj += "wmode='opaque' allowscriptaccess='sameDomain' align='middle' ";
    strAdObj += "src='player.swf' allowfullscreen='true' ";
    strAdObj += "flashvars='skin=Skin.swf&file=" + sImgSrc + "&autostart=true&overstretch=true&displayclick=none' />";
    strAdObj += "</object></div>";

    return strAdObj;
}

//View Image
function getAdObjectType_5(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {
     if(sBgColor==""){
        sBgColor="#FFFFFF";
    }
    var strAdObj = "<a id='AdFile_" + sRecID + "' href=" + sHref + " target='_blank'><center>";
    strAdObj += "<img src=" + sImgSrc + " alt='" + sTitle + "' title='" + sTitle + "' style='background-color:" + sBgColor + "; border-width:0px;' />";
    strAdObj += "</center></a>";
    return strAdObj;
}

//Pdf file
function getAdObjectType_6(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {

    if (sBgColor == "") {
        sBgColor = "Transparent";
    }
    var strAdObj = "<div id='AdFile_" + sRecID + "' style=background-color:" + sBgColor + ";'position:relative;width:" + sWidth + ";height:" + sHeight + ";display:block' >";
    strAdObj += "<a id='NavigateUrl_" + sRecID + "' href='" + sHref + "' target='_blank' style='display:block'>";
    strAdObj += "<img src='App_Themes/Image/blank.gif' alt='" + sTitle + "' title='" + sTitle + "' style='z-index:2;width:100%;height:" + sHeight + ";position:absolute;top:0;left:0;cursor:pointer;' /></a>";

    strAdObj += "<object type='application/pdf' data='" + sImgSrc + "#toolbar=0&navpanes=0&scrollbar=0'";
    strAdObj += "width='" + sWidth + "' height='" + sHeight + "' >";
    strAdObj += " style='overflow:hidden;background-color:" + sBgColor + "' />";
    strAdObj += "<embed type='application/pdf' data='" + sImgSrc + "#toolbar=0&navpanes=0&scrollbar=0'";
    strAdObj += "width='" + sWidth + "' height='" + sHeight + "' style='overflow:hidden;background-color:" + sBgColor + "' ></embed>";
    strAdObj += "</object></div>";

    return strAdObj;
}

//Plain text
function getAdObjectType_7(sRecID, sTitle, sImgSrc, sHref, sWidth, sHeight, sBgColor) {

    if (sBgColor == "") {
        sBgColor = "Transparent";
    }
    var strAdObj = "<div id='AdFile_" + sRecID + "' style='background-color:" + sBgColor + ";position:relative;width:" + sWidth + ";height:" + sHeight + ";display:block' >";
    strAdObj += "<a id='NavigateUrl_" + sRecID + "' href='" + sHref + "' target='_blank' style='display:block'>";
    strAdObj += "<img src='App_Themes/Image/blank.gif' alt='" + sTitle + "' title='" + sTitle + "' style='z-index:2;width:100%;height:" + sHeight + ";position:absolute;top:0;left:0;cursor:pointer;' /></a>";

    strAdObj += "<object type='text/plain' data='" + sImgSrc + "'";
    strAdObj += "width='" + sWidth + "' height='" + sHeight + "' >";
    strAdObj += " style='overflow:hidden;background-color:" + sBgColor + "' />";
    strAdObj += "<embed type='text/plain'  data='" + sImgSrc + "'";
    strAdObj += "width='" + sWidth + "' height='" + sHeight + "' style='overflow:hidden;background-color:" + sBgColor + "' ></embed>";
    strAdObj += "</object></div>";

    return strAdObj;
}

//View Image
//var elem = othis.parentNode.childNodes[index];
//clearTimeout ( alertTimerId );

function SetMultiArray(){

   //Globals
   _elem_Root = document.getElementById("txtFileContent");
   _arr_ContFile = _elem_Root.value.split(";");
   //
   var iRows = (_arr_ContFile.length - 1) / 11;
   var iCounter=1;
   
   // Load multi array with image from selected ad_index
   for (var i = 0; i < iRows; i++) {
        _MultiArray[i] = new Array(11);
        for (var j = 0; j < 11; j++) {
            _MultiArray[i][j] = _arr_ContFile[iCounter];
            iCounter++;
        }
   }     
}

function TimerTick() {

    var elem = document.getElementById("AdContent_" + _arr_ContFile[0]);
    var sCurrRecID = GetCurrRecID(elem.childNodes[0].id);
    var iRows = (_arr_ContFile.length - 1) / 11;
    var iCurrIndex = -1;
    var iCounter = 1;
   
    //Get current index number from visible image
    for (var i = 0; i < iRows; i++) {
        if (_MultiArray[i][0] == sCurrRecID) {
          iCurrIndex=i;
          break;
        }
    }
    
    var imgType = parseInt(getImageType(_MultiArray[iCurrIndex][0]));
    PlayImageShow(-1);
}

function SupportOpacity(elem){
    var isMatch=false;
    if(elem.style.filter!=null){
        isMatch=true;
     }
     else if(elem.style.MozOpacity!=null){
        isMatch=true;
     }
     else if(elem.style.KhtmlOpacity!=null){
        isMatch=true;
     }
     else if(elem.style.opacity!=null){
        isMatch=true;
     }
     return isMatch;
}


//Loaded by serverpage PubpProd.aspx.cs at event Page_LoadComplete
//Initialize
function LoadPlayImageShow() {
    var intervalAutoView = document.getElementById("txtAutoViewInterval").value;
    
    if(intervalAutoView==""){
        intervalAutoView=0;
    }

    if(parseInt(intervalAutoView)>0){
    
        if (document.getElementById("adImgSelector") != null) {
            // File is corrupt with invalid items like  underscore '_' etc.
            if(document.getElementById("txtFileContent").value=="false"){
                return;
            }
           
            SetMultiArray();
           
            var elem = document.getElementById("AdContent_" + _arr_ContFile[0]);
            var iRows = (_arr_ContFile.length - 1) / 11;
            var sCurrRecID = GetCurrRecID(elem.childNodes[0].id);
            var iCurrIndex = -1;
            var iCounter = 1;
            var imgType = 0;
            
            var strStyle = "";
            var strCellContent = "";
            
            //Get current index number from visible image
            for (var i = 0; i < iRows; i++) {

                if (_MultiArray[i][0] == sCurrRecID) {
                  iCurrIndex=i;
                  break;
                }
            }
                      
            imgType = getImageType(_MultiArray[iCurrIndex][2]);
            
            ////
            //Insert ADSelector on page
            //
            if (iCurrIndex > -1) {
                for (var i = 0; i < iRows; i++) {
                    if (i == iCurrIndex) {
                        if (i > (iRows - 2)) {
                            strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#B40810";
                        } else {
                            strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#B40810;border-right:1px solid #706F6F";
                        }
                        strCellContent += "<td align='center' onclick='PlayImageShow(" + i + ")' onmouseout='MouseOut(this)' onmouseover='MouseOver(this)' style='" + strStyle + "'>X</td>";

                    } else {
                        if (i > (iRows - 2)) {
                            strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#3C3B3B";
                        } else {
                            strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#3C3B3B;border-right:1px solid #706F6F";
                        }
                        strCellContent += "<td align='center' onclick='PlayImageShow(" + i + ")' onmouseout='MouseOut(this)' onmouseover='MouseOver(this)' style='" + strStyle + "'>" + (i + 1).toString() + "</td>";
                    }

                }
            }
            
            /////
            //Initialize AD Selector
            //
            if (document.getElementById("adImgSelector") != null) {
                var oElem = document.getElementById("adImgSelector");
                oElem.style.display="none";
                
                // Positioning ADSelector
                oElem.style.left=findPos(getNextSibling(oElem));
                oEl=oElem.parentNode.parentNode;
                //oElem.style.left= parseInt(getNextSibling(oElem).offsetLeft) + "px";
               
                
                //Hide imageselector
                oEl.onmouseout=function(){ 
                    oElem.style.display="none";
                }
                
                //View imageselector
                oEl.onmouseover=function(){
                    oElem.style.display="block";
                }
          
                oElem.innerHTML = "<table cellspacing='1px' cellpadding='0px'><tr>" + strCellContent + "</tr></table>";

                //Register records collected by statistics att startup
                document.getElementById("txtAutoViewID").value = iCurrIndex;
                
            }

            //clearInterval(_intervalID);
            _intervalID = setInterval(function() { TimerTick(); }, intervalAutoView);
        }
    }
}

function findPos(obj) {
	var curleft=0;
	var curtop=0;
	if (obj.offsetParent) {
        do {
		    curleft += obj.offsetLeft;
		    curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return curleft  + "px";
}

function RegisterPlayedImageIndex(Index, iCounter) {

    var isMatch = false;

    if (Index == null)
        return false;

    //ALL IMAGES HAVE BEEN VIEWED ONES AND REGISTRED BY STATISTICS
    if (document.getElementById("txtRegStatAutoViewDone").value == "1") {
        return false;
    }

    var elemSavedIndexItems = document.getElementById("txtAutoViewID");
    
    //No items have been Registered, Register the first item
    if (elemSavedIndexItems.value == null) {
        elemSavedIndexItems.value = Index;
        return true;
    }

    //Get Registered Items
    var arrSavedIndexItems = elemSavedIndexItems.value.toString().split(';');

    //Check if index is registered
    for (var i = 0; i < arrSavedIndexItems.length; i++) {
        if (arrSavedIndexItems[i] == Index) {
            isMatch = true;
            break;
        }
    }

    //Register Index
    if (!isMatch) {
        //Check if all items have been saved
        if ((arrSavedIndexItems.length + 1) == iCounter) {
            document.getElementById("txtRegStatAutoViewDone").value = "1";
        }
        elemSavedIndexItems.value = elemSavedIndexItems.value + ";" + Index;
        return true;
       
    } else {  //Index  has been registered
        return false;
    }
}

function PlayImageShow(index){

    var elem = document.getElementById("AdContent_" +  _arr_ContFile[0]);
    var iRows = (_arr_ContFile.length - 1) / 11;
    var arrViewedImage = new Object;
    var sCurrRecID = GetCurrRecID(elem.childNodes[0].id);
    var iCurrIndex = -1;
    var strStyle = "";
    var strCellContent = "";
    var imgType = 0;
    var isMatch=false;

    //Get current index number from visible image
    for (var i = 0; i < iRows; i++) {
        if (_MultiArray[i][0] == sCurrRecID) {
            iCurrIndex = i;
            break;
        }
    }

    // All items will be registered once when played
    if (document.getElementById("txtRegStatAutoViewDone").value != "1") {
        //Check before register viewed record statistic
        if (RegisterPlayedImageIndex(iCurrIndex, iRows)) {
            setTimeout(function() { adStatistic.Register(0, sCurrRecID); }, 50);
        } 
    } 
    
    ////    
    //Image have been selected
    ////
    if (index > -1) {
        iCurrIndex = index;
    }else{
        //Get the next image to show. If current image is last item 
        //Begin from picture one in array
        if ((iCurrIndex+1) == iRows) {
            iCurrIndex = 0;
        } else {
            iCurrIndex++;
        }
    }
  
    imgType = getImageType(_MultiArray[iCurrIndex][2]);
    
    //
    //Change image selector on page
    //

    if (iCurrIndex > -1) {
        for (var i = 0; i < iRows; i++) {
            if (i == iCurrIndex) {
                if (i > (iRows - 2)) {
                    strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#B40810";
                } else {
                    strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#B40810;border-right:1px solid #706F6F";
                }
                strCellContent += "<td align='center' onclick='PlayImageShow(" + i + ")' onmouseout='MouseOut(this)' onmouseover='MouseOver(this)' style='" + strStyle + "'>X</td>";
            } else {
                if (i > (iRows - 2)) {
                    strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#3C3B3B";
                } else {
                    strStyle = "width:10px;height:16px;font-size:10px;font-family:Arial;color:#3C3B3B;border-right:1px solid #706F6F";
                }
                strCellContent += "<td align='center' onclick='PlayImageShow(" + i + ")' onmouseout='MouseOut(this)' onmouseover='MouseOver(this)' style='" + strStyle + "'>" + (i + 1).toString() + "</td>";
            }
        }
    }

    if (document.getElementById("adImgSelector") != null) {
        var oElem = document.getElementById("adImgSelector");
        oElem.innerHTML = "<table cellspacing='1px' cellpadding='0px'><tr>" + strCellContent + "</tr></table>";
    }

    switch (imgType.toString()) {
        case "0"://Img
            elem.innerHTML = getAdObjectType_0(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1], encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            break;
        case "1": //Flash
            elem.innerHTML = getAdObjectType_1(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1], encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            break;
        case "2": //Silverlight Windws Media
            elem.innerHTML = getAdObjectType_2(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1],encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            break;
        case "3"://QuickTime
            elem.innerHTML = getAdObjectType_3(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1],encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            break;
        case "4"://Flash Movie
            elem.innerHTML = getAdObjectType_4(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1],encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            break;
        case "6": //PDf File
            elem.innerHTML = getAdObjectType_6(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1], encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            if (document.getElementById("txtRegStatAutoViewDone").value == 0) {
                setTimeout(function() { adStatistic.Register(0, _MultiArray[iCurrIndex][0]); }, 50);
            }
            break;
        case "7": //Plain text doc
            elem.innerHTML = getAdObjectType_7(_MultiArray[iCurrIndex][0], _MultiArray[iCurrIndex][1],encodeURI(_MultiArray[iCurrIndex][2]), _MultiArray[iCurrIndex][3], _MultiArray[iCurrIndex][8], _MultiArray[iCurrIndex][9], _MultiArray[iCurrIndex][10]);
            if (document.getElementById("txtRegStatAutoViewDone").value == 0) {
                setTimeout(function() { adStatistic.Register(0, _MultiArray[iCurrIndex][0]); }, 50);
            }
            break;
    }
    
    //Don't slide movies and flash animation
    if (imgType != 1 && imgType != 2 && imgType != 3 && imgType != 4) {
        slideEffect(elem,1);
    }
    
    /*
    if(SupportOpacity(elem)){
        //FadeIn(elem,0);
    }
    */
}

function slideEffect(elem,effect) {
    var pos=0;
    var orgValue=0;
    
    // Get object
    elem=elem.childNodes[0];
    elem=elem.childNodes[0];
    // Find the full, potential, height of the element
    if(effect==0){
        orgValue = parseInt(elem.style.height);
        elem.style.height = '0px';
    }else{
        orgValue = parseInt(elem.style.width);
        elem.style.width = '0px';    
    }
    //Animation that takes place over one second
    for (var i = 1; i <= 100; i += 10 ) {
         // A closure to make sure that we have the right 'i'
        (function(){
            var pos = i;
            // Set the timeout to occur at the specified time in the future
            setTimeout(function(){setSlideValue(elem,pos,orgValue,effect);}, ( pos + 1 ) * 5 );})
        ();
    }

}

function setSlideValue(elem,pos,orgValue,effect){
    var iVal = (pos / 100 ) * orgValue ;
    if(effect==0){
        elem.style.height = iVal + "px";
    }else{
        elem.style.width = iVal + "px";
    }
    
    if (pos > 90){
         if(effect==0){
            elem.style.height= orgValueorgValue + "px";
         }else{
            elem.style.width = orgValue + "px";
         }
    }
}


function FadeIn( elem ) {
    // Start the opacity at 0
    setOpacity( elem, 0 );
    // We're going to do a 20 'frame' animation that takes
    // place over one second
    for ( var i = 0; i <= 100; i += 10 ) {
        // A closure to make sure that we have the right 'i'
        (function(){
            var pos = i;
            // Set the timeout to occur at the specified time in the future
            setTimeout(function(){setOpacity( elem, pos );}, ( pos + 1 ) * 5 );})
        ();
    }
}

function setOpacity(elem,iValue){
    if(iValue==0){
         if(elem.style.opacity!=null){
            elem.style.opacity = 0;
         }
         else if(elem.style.filter!=null){
            elem.style.filter = "alpha(opacity=0)";
         }
         else if(elem.style.MozOpacity!=null){
            elem.style.MozOpacity = 0;
         }
         else if(elem.style.KhtmlOpacity!=null){
            elem.style.KhtmlOpacity = 0;
         }
    }else if (iValue>90){
        if(elem.style.opacity != null){
            elem.style.opacity = 1;
        }
        else if(elem.style.filter!=null){
            elem.style.filter = "alpha(opacity=100)";
        }
        else if(elem.style.MozOpacity != null){
            elem.style.MozOpacity =1;
        }
        else if(elem.style.KhtmlOpacity != null){
            elem.style.KhtmlOpacity = 1;
        } 
    }else{
        if(elem.style.opacity != null){
            elem.style.opacity = parseFloat (iValue/100);
        }
        else if(elem.style.filter!=null){
            elem.style.filter = "alpha(opacity=" + iValue.toString() + ")";
        }
        else if(elem.style.MozOpacity != null){
            elem.style.MozOpacity = parseFloat (iValue/100);
        }
        else if(elem.style.KhtmlOpacity != null){
            elem.style.KhtmlOpacity = parseFloat (iValue/100);
        }
    }
}

function ViewImageFileUpload() {
    var sTitle = "";
    var sHref ="Inform_2.html";
    var _sContentID = "ctl00_ContentPlaceMain_";
    var imgSrc = document.getElementById(_sContentID + "txtViewImage");
    var elem = document.getElementById("viewPicture");

    var sWidth="250px";
    var sHeight = "208px";
    
    var imgType = getImageType(imgSrc.value);

    if (imgSrc.value == "") {
        alert("Välj en annonsfil från listan först.");
        return (true);
    }

    sTitle = "Bildskalning : " + sWidth + " x " + sHeight;
    
    switch (imgType.toString()) {
        case "0"://Image
            elem.innerHTML = getAdObjectType_5("Previev_0", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            autoSizeImage(elem);
            break;
        case "1"://Flash
            elem.innerHTML = getAdObjectType_1("Previev_1", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            break;
        case "2"://silverlight Windows Media
            elem.innerHTML = getAdObjectType_2("Previev_2", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            break;
        case "3"://QuickTime
            elem.innerHTML = getAdObjectType_3("Previev_3", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            break;
        case "4"://Flash Movie
            elem.innerHTML = getAdObjectType_4("Previev_4", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            break;
        case "6": //Flash Movie
            elem.innerHTML = getAdObjectType_4("Previev_6", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            break;
        case "7": //Flash Movie
            elem.innerHTML = getAdObjectType_4("Previev_7", sTitle, imgSrc.value, sHref, sWidth, sHeight, "#FFFFFF");
            break;
    }

    return (false);
}

function autoSizeImage(elem) 
{
    var sWidth = "";
    var sHeight = "";
    var sTitle = "Narturlig storlek : ";
    var img = new Image();
    img.height = 200;

    elem = elem.childNodes[0];
    elem = elem.childNodes[0];
    elem = elem.childNodes[0];

    if (parseInt(elem.width) > 278 || parseInt(elem.style.width) > 278) {
        elem.width = 0;
        elem.style.width = "278px";
        sWidth = elem.style.width;
        sTitle = "Bild är skalad : ";
    } else {
        sWidth = elem.width;
    }

    if (parseInt(elem.height) > 210 || parseInt(elem.style.height) > 210) {
        elem.height = 0;
        elem.style.height = "210px";
        sHeight = elem.style.height;
        sTitle = "Bild är skalad : ";
    } else {
        sHeight = elem.height;
    }

    elem.title = sTitle + sWidth + " x " + sHeight;
    elem.alt = sTitle + sWidth + " x " + sHeight;
}


if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

// ]]>


