/*
 function OpenCME(){
 win=window.open('/viewCME.do?indexPageURL='+location,'CME','status=yes,height=600,width=580,scrollbars')
 win.focus()
 }

 function viewSlide(slide){
 win=window.open('/documents/sponsorededucation/educationalprograms/854925/images/'+slide+'.html','SLIDE','status=yes,height=725,width=980,scrollbars')
 win.focus()
 }
 */

function custwindow(wname, loc, wx, wy, px, py, opt) {
//THO-JANB MOD      

//possibly use this to add base href check :  document.getElementsByTagName('base')[0].href + 

    redirectaction = '/viewDocument.do?document=';


    /*  Author: Sean Mollitt
     Custom version for THO - Uses var <redirectaction>

     wname = name for window (>>>> no spaces <<<<<)
     loc   = url OR string of html
     wx    = width of window
     wy    = height of window
     px    = position x
     py    = position y

     opt   = string of characters enables options for window
     r = enable resize on window
     c = center window
     s = enable scrollbar
     t = enable status bar
     v = dont use viewdocument.do
     no opts = use default window specs

     Examples:
     custwindow('PowerPoint','/education/AuCoeurDuDebat/397491/slides.ppt',640,480,0,0,'cst') <-- will use viewdocument
     custwindow('Text_Message','<p style="font-family:verdana;">This is some html text to open in a <b>window</b></p>',300,300,0,0,'cst')<-- <-- will NOT use viewdocument
     custwindow('/education/AuCoeurDuDebat/397491/slides.ppt') <-- this will work also AND use viewdocument
     custwindow('IMAGE','/documents/skin/images/header/logo.jpg',640,480,0,0,'vic') <-- this will work with images

     */
    var scrol = 'no';
    var resiz = 0;
    var cent = 0;
    var stat = 0;
    largeImage = 0;
    if (!px || !py) {
        px = 10;
        py = 10
    }
    if (opt) {
        if (opt.indexOf('r') != -1) {
            resiz = 1
        }
        if (opt.indexOf('c') != -1) {
            cent = 1
        }
        if (opt.indexOf('s') != -1) {
            scrol = 1
        }
        if (opt.indexOf('t') != -1) {
            stat = 1
        }
        if (opt.indexOf('i') != -1) {
            largeImage = 1
        }
    }
    else {
        opt = ''
    }

    if (cent) {
        var ww = screen.availWidth
        var wh = screen.availHeight
        px = Math.round((ww / 2) - (wx / 2))
        py = Math.round((wh / 2) - (wy / 2))
    }

    if (!loc) {
        loc = wname;
        wname = 'New_window'
    }
    var isfile = true
    if (loc.indexOf(' ') != -1) {
        isfile = false
    }
    if (loc.indexOf('<') != -1 && loc.indexOf('>') != -1) {
        isfile = false
    }

    if (!wx || !wy) {
        winwh = ''
    } else {
        winwh = 'width=' + wx + ',height=' + wy + ','
    }

    windowstr = '"toolbar=no,' + winwh + 'directories=no,status=' + stat + ',scrollbars=' + scrol + ',center=' + cent + ',resizable=' + resiz + ',menubar=no,screenX=' + px + ',screenY=' + py + ',left=' + px + ',top=' + py + '"'
    if (wname == 'New_window' || !opt || opt == 'v') {
        windowstr = winwh.substring(0, winwh.length - 1)
    }
    if (!wname) {
        wname = 'New_window'
    }

    if (isfile && opt.indexOf('v') != -1 && largeImage == 1) {
        var imag = new Image();
        imag.src = loc;
        eval(wname + '= window.open("",wname,windowstr)');
        if (!imag.height) {
            wx = 50;
            wy = 50
        } else {
            wy = imag.height;
            wx = imag.width
        }
        htmlx = '<html><body marginheight="0" marginwidth="0" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" bgcolor="#ffffff">'
        htmlx += '<div align="center"><a href="javascript:window.close();"><img vspace="0" hspace="0" border="0" src="' + loc + '" onload="window.resizeTo(this.width,this.height)"></a></div></body></html>'
        eval(wname + '.document.write(htmlx)');
        eval(wname + '.document.close()');
    }
    else if (isfile && largeImage == 0) {
        if (loc.indexOf(redirectaction) == -1 && opt.indexOf('v') == -1) {
            loc = escape(loc); //Added by mpaquette 20060719            
            loc = redirectaction + loc;
        }
        eval(wname + '= window.open(loc,wname,windowstr)');
    }
    else {
        eval(wname + '= window.open("",wname,windowstr)');
        eval(wname + '.document.write(loc)')
        eval(wname + '.document.close()')
    }
    eval(wname + '.focus()')
}

/*--------------------------------------------------------*/
/* MEDIAPLAY START */
/*--------------------------------------------------------*/

function mediaplay(docid, clipid, wx, wy) {

    //cmsaction returns the xml string for the player
    var cmsaction = document.getElementsByTagName('base')[0].href + 'viewMMComponent.do?mmpid=' + docid + '&speaker=' + clipid
    var playerloc = '/documents/mediaplay_v2/mediaplay.swf'

    if (!clipid) {
        cmsaction = '/viewMMComponent.do?mmpid=' + docid + '&mmcname=1';
        clipid = '1';
    }
    cmsaction = escape(cmsaction);

    if (!wx || !wy) {
        winwh = 'width=375,height=425,'
    } else {
        winwh = 'width=' + wx + ',height=' + wy + ','
    }
    windowstr = '"toolbar=no,' + winwh + 'directories=no,status=no,scrollbars=no,center=yes,resizable=no,menubar=no"'

    htm = '<html><head><title>MediaPlayer</title></head><body bgcolor="#C0C0C0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0">'
    htm += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"  width="100%" height="100%"  id="mediaplay" align="middle">';
    htm += '<param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + playerloc + '" /><param name="quality" value="high" /><param name="scale" value="noscale" />';
    htm += '<param name="salign" value="lt" /><param name="bgcolor" value="#878787" /><param name="FlashVars" value="configFile=' + cmsaction + '&speaker=' + clipid + '" /><embed src="' + playerloc + '" quality="high" scale="noscale" salign="lt" bgcolor="#878787"  width="100%" height="100%"  name="mediaplay" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" FlashVars="configFile=' + cmsaction + '&speaker=' + clipid + '" /></object>';
    htm += '</body></html>'

    medplay = window.open("", "Mediaplayer", windowstr);
    medplay.document.write(htm);
    medplay.document.close();
    medplay.focus();
}

/*--------------------------------------------------------*/
/* MEDIAPLAY END */
/*--------------------------------------------------------*/

// toggle the question and results div for questionnaires

function toggleQuestionAndResult() {
    if ($("#questionFormImage").css('display') == "block") {
        $("#questionFormImage").css('cssText', 'display: none !important');
        $("#questionResultImage").css('cssText', 'display: block !important');
    } else {
        $("#questionFormImage").css('cssText', 'display: block !important');
        $("#questionResultImage").css('cssText', 'display: none !important');
    }
}
