//Diverses fonctions d'utilité globale
var utcTimer;
var selectedcolor;
var nextcolorindex = 0;
var colorarray = new Array(); // 16 éléments
var isZoomDragging = false; // Gestion du rectangle dragging zoom

colorarray.push("#FF0000"); // red
colorarray.push("#008000"); // green
colorarray.push("#800000"); // maroon
colorarray.push("#FF00FF"); // fuschia
colorarray.push("#FFFF00"); // yellow
colorarray.push("#000080"); // navy
colorarray.push("#800080"); // purple
colorarray.push("#C0C0C0"); // silver
colorarray.push("#008080"); // teal
colorarray.push("#0000FF"); // blue
colorarray.push("#00FFFF"); // aqua
colorarray.push("#00FF00"); // lime
colorarray.push("#808080"); // gray
colorarray.push("#808000"); // olive
colorarray.push("#FFFFFF"); // white
colorarray.push("#000000"); // black

function WebForm_CallbackComplete_SyncFixed()
{
    // SyncFix: the original version uses "i" as global thereby resulting in javascript errors when "i" is used elsewhere in consuming pages
    for (var i = 0; i < __pendingCallbacks.length; i++)
    {
        callbackObject = __pendingCallbacks[i];
        if (callbackObject && callbackObject.xmlRequest && (callbackObject.xmlRequest.readyState == 4))
        {
            // the callback should be executed after releasing all resources 
            // associated with this request. 
            // Originally if the callback gets executed here and the callback 
            // routine makes another ASP.NET ajax request then the pending slots and
            // pending callbacks array gets messed up since the slot is not released
            // before the next ASP.NET request comes.
            // FIX: This statement has been moved below
            // WebForm_ExecuteCallback(callbackObject);
            if (!__pendingCallbacks[i].async)
            {
                __synchronousCallBackIndex = -1;
            }
            __pendingCallbacks[i] = null;

            var callbackFrameID = "__CALLBACKFRAME" + i;
            var xmlRequestFrame = document.getElementById(callbackFrameID);
            if (xmlRequestFrame)
            {
                xmlRequestFrame.parentNode.removeChild(xmlRequestFrame);
            }

            // SyncFix: the following statement has been moved down from above;
            WebForm_ExecuteCallback(callbackObject);
        }
    }
}
//---------------------------------------------------------
function getCookieVal(name)
{
    var retval = "";
    
    var reg = new RegExp("[=&]");
    var datas = document.cookie.split(reg);
    for (var i = 0;i <= datas.length/2;i += 2)
    {
        if (datas[i] == name)
        {
            retval = datas[i+1];
            break;
        }
    }
    
   return unescape(retval);
}
//---------------------------------------------------------
function writeCookie(kind,type)
{
    var echeance = new Date();
    var unmois = echeance.getTime() + (30*24*60*60*1000);
    echeance.setTime(unmois);
    document.cookie= "kindmap=" + escape(kind) + "&mapstyle=" + escape(type) + ";expires=" + echeance.toGMTString();
}//-------------------------------------------------------------------------
function displayUTCDate()
{
    var divdate = document.getElementById("utcdiv");
    var maintenant = new Date();
    divdate.innerText = maintenant.toGMTString();
}
//-------------------------------------------------------------------------
function colorsAll(RGB)
{
   var RR = RGB.substring(0,2);
   var GG = RGB.substring(2,4);
   var BB = RGB.substring(4,6);

   var teststr = document.getElementById("colortest");
   selectedcolor = "#" + RGB;
   teststr.style.color= selectedcolor;
}
//***************************************************************************
//Pour la gestion des héritage avec SuperConstructor prenant un argument
function inherit(subclass,superclass)
{
    var c = function(){};
    c.prototype = superclass.prototype;
    subclass.prototype = new c();
}
//***************************************************************************
// Conversion Lat Long de double vers texte
function gettextPositions(lat,lng)
{
    var text = "Lat : " + getTextPos(lat,true);
    text += (lat>0) ? " N" : " S";
    text += " - " + "Long : " + getTextPos(lng,false);
    text += (lng>0) ? " E" : " W";
    
    return text;
}
//------------------------------------------------------------------
function getTextPos(pos,isLat)
{
    pos = Math.abs(pos);
    var deg = Math.floor(pos);
    var temp = (pos-deg) * 60;
    var min = Math.floor(temp);
    var sec = Math.floor((temp-min)*60);
    
    var text = deg + String.fromCharCode(186);
    if (isLat)
    {
        if (text.length == 2)
            text = "0" + text;    
    }
    else
    {
        if (text.length == 2)
            text = "00" + text;
        else if (text.length == 3)
            text = "0" + text;
    }
    
    var tmp = min + "'";
    if(tmp.length == 2)
        tmp = "0" + tmp;
    
    text += tmp;
    
    if (sec <10)
        text += "0";
    
    
    return  text + sec + "\"";
}
//-----------------------------------------------------
// retourne HH:MM:SS depuis une durée en seconde
function getHMS(duration)
{
    var temp;
    var t2=0;
    var min = "";
    var sec = "";
    var h = Math.floor(duration/3600);
    t2 = duration%3600;
    temp = Math.floor(t2/60);
    if (temp <10)
        min = "0" + temp;
    else
        min = temp;
    temp = Math.floor(t2%60);
    if (temp<10)
        sec = "0" + temp;
    else
        sec = temp;
        
    return h + ":" + min + ":" + sec;   
}
//***************************************************************************
//Pour la gestion du rectangle de zoom par shift click

function DoDragStart()
{
if (window.event.shiftKey)
{
   // alert("Majuscule");
    return false;
    }
else
    alert("A transmettre");
}
//***************************************************************************
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();