﻿// IFrame automatic resizing       
function ResizeIFrames()
{
    if (window.parent == null) return;
    var par = window.parent.document;
    var iFrameList = par.getElementsByTagName('iframe');
    if (iFrameList == null || iFrameList.length == 0) return;
    for (var i = 0; i<iFrameList.length; i++)
    {
        var iFrame = iFrameList[i];
        if (iFrame != null) {
            iFrame.style.height = iFrame.contentWindow.document.body.scrollHeight + 'px';
        }
    }
}

$(document).ready(function () {
    window.setInterval(ResizeIFrames, 50);
    //$('.corner').corner();
    //$(".divHeadDomain").click(function () { $(this).next(".divContent").slideToggle("fast"); });

});
// =========================


// ChangeUrl(http://localhost/mysite/mypage.aspx,mynewpage.aspx) > http://localhost/mysite/mynewpage.aspx
function ChangeUrl(oldUrl,newPage)
{
    var i =  oldUrl.toString().lastIndexOf("/",oldUrl.toString().length - 1);
    var newUrl = oldUrl.toString().substring(0,i+1);
    return newUrl + newPage;
}


// If a parent window exists > change parent location to newParentLocation
// Else change current location to current location
function Redirect(path, newParentLocation, defaultLocation)
{
    if(path == null) path = '';
    if(window.parent != null && window.parent.document.location != document.location)
        window.parent.document.location = ChangeUrl(window.parent.document.location,path+newParentLocation);
    else
        document.location = defaultLocation;
    return false;
}


function RedirectDetail(id, path)
{
    Redirect(path,'Course.aspx?formationid='+id,'DetailFormation.aspx?formationid='+id);
}

function RedirectDetailFromSession(id, path)
{
    Redirect(path,'Course.aspx?sessionid='+id,'DetailFormation.aspx?sessionid='+id);
}

function RedirectDomain(id,path)
{
    Redirect(path,'Cours.aspx?formationid='+id,'Formations.aspx?formationid='+id);
}

function RedirectKeywords(val, path)
{
    Redirect(path,'Cours.aspx?keywords='+encodeURIComponent(val), 'Formations.aspx?keywords='+encodeURIComponent(val));
}

function RedirectAllDomains(path)
{
    Redirect(path,'Cours.aspx','Formations.aspx');
}

function RedirectSessions(path)
{
    Redirect(path,'planning.aspx','Sessions.aspx');
}

function RedirectQuote(id, path)
{
    Redirect(path,'Estimate.aspx?id='+id,'Sessions.aspx');
}
