﻿
//*************** Web Designer's scripts (Tomek) *******************************

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//**************** Web Developer's scripts (Dywayne) **********************


// This next little bit of code tests whether the user accepts cookies.

function myBrowserAcceptsCookies()
{
    var WM_acceptsCookies = false;
    if(document.cookie == '') 
    {
        document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
        if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) 
        {
	        WM_acceptsCookies = true; 
        }
        // If it succeeds, set variable
    } 
    else 
    { 
        // there was already a cookie
        WM_acceptsCookies = true;
    }
    
    return WM_acceptsCookies 
}


function openWin( windowURL, windowName, windowFeatures) {
     window.open( windowURL, windowName, windowFeatures ) ;
}

function popupNewEvidence(categoryId, conditionId, treatmentId)
{
	mywindow = window.open('Edit_Evidence.aspx?categoryid=' + categoryId + "&conditionid=" + conditionId + "&treatmentid=" + treatmentId ,'pop_up_evidence','menubar=0,resizable=1,width=790,height=700,scrollbars=1');
}

function suggestEvidence(categoryId, conditionId, treatmentId)
{
	var mywindow = window.open('Suggest_Evidence.aspx?categoryid=' + categoryId + "&conditionid=" + conditionId + "&treatmentid=" + treatmentId ,'pop_up_evidence','menubar=0,resizable=1,width=790,height=700,scrollbars=1');
    if (window.focus) {mywindow.focus()}
}
function suggestNewEvidence(conditionId, treatmentId)
{
	var mywindow = window.open('Suggest.aspx?conditionid=' + conditionId + "&treatmentid=" + treatmentId ,'pop_up_evidence','menubar=0,resizable=1,width=790,height=700,scrollbars=1');
    if (window.focus) {mywindow.focus()}
}

function popupResearcherEvidence(ratingSurveyId, ratingId, categoryId, conditionId, treatmentId)
{
	var mywindow = window.open("Evidence_Review_Popup.aspx?ratingsurveyid=" + ratingSurveyId + 
	    "&ratingid=" + ratingId + 
	    "&categoryid=" + categoryId + 
	    "&conditionid=" + conditionId + 
	    "&treatmentid=" + treatmentId ,
	    'pop_up_evidence',
	    'status=0,menubar=0,resizable=0,width=780,height=500,scrollbars=0');
	
	if (window.focus) {mywindow.focus()}
	
}


function popupGuidelines(conditionId)
{
	var mywindow = window.open("Rating_Guidelines_Popup.aspx?conditionid=" + conditionId,
	    'pop_up_guidelines',
	    'status=0,menubar=0,resizable=0,width=801,height=600,scrollbars=1');
	
	

	if (window.focus) {mywindow.focus()}
	
}

//************************ Time & Timer Functions **************************************

function two(x) {return ((x>9)?"":"0")+x}
function three(x) {return ((x>99)?"":"0")+((x>9)?"":"0")+x}

function GetMinutesAndSeconds(ms) 
{
    var sec = Math.floor(ms/1000)
    ms = ms % 1000
    t = three(ms)

    var min = Math.floor(sec/60)
    sec = sec % 60
    t = two(sec) + ":" + t

    var hr = Math.floor(min/60)
    min = min % 60
    t = two(min) + ":" + t

    var day = Math.floor(hr/60)
    hr = hr % 60
    t = two(hr) + ":" + t
    t = day + ":" + t

    //just return min : sec
    t = min + ":" + two(sec)

    return t
}


function FormatDateTime(d)
{
    
    var a_p = "";

    var curr_hour = d.getHours();
    if (curr_hour < 12)
       {
       a_p = "AM";
       }
    else
       {
       a_p = "PM";
       }
    
    if (curr_hour == 0)
       {
       curr_hour = 12;
       }
    
    if (curr_hour > 12)
       {
       curr_hour = curr_hour - 12;
       }

    var curr_min = d.getMinutes();

    curr_min = curr_min + "";

    if (curr_min.length == 1)
       {
       curr_min = "0" + curr_min;
       }

    return curr_hour + ":" + curr_min + " " + a_p;


}
