﻿// JScript File
/**************************************************************************/
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toLowerCase()
if (imgName.substring(imgName.length-3, imgName.length) == "png")
{
//alert("png:" + i + ": " + imgName);
var imgID = (img.id) ? "id='" + img.id + "' " : ""
var imgClass = (img.className) ? "class='" + img.className + "' " : ""
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
var imgStyle = "display:inline-block;" + img.style.cssText
if (img.align == "left") imgStyle = "float:left;" + imgStyle
if (img.align == "right") imgStyle = "float:right;" + imgStyle
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
if(navigator.userAgent.indexOf("MSIE")>=0)
{
    window.attachEvent("onload", correctPNG);
}
else
{
    window.addEventListener("onload", correctPNG, true);
}
/**************************************************************************/

// This method takes the elementId and returns the element
function $(elementId) {
    if (document.getElementById(elementId))
    {
        return document.getElementById(elementId);
    }
    else if (document.getElementById(masterID + elementId))
    {
        return document.getElementById(masterID + elementId);   
    }
    else if (document.getElementById(otherFormID + elementId))
    {
        return document.getElementById(otherFormID + elementId);
    }        
}

function DispDivs(elmt)
{
    var dispVal;
    //alert("Hi");
    var elmtId = elmt.id;
    //alert(elmtId);
    for(i=1;i<100;i++)
    {
        if(elmt.checked == 1)
        {
            dispVal='';
        }
        else
        {
            dispVal = 'none';
        }

        var e = $('Row'+elmtId+''+i);
        
        if(e != null)
            e.style.display = dispVal;
        else
            break;
    }
}

function DispDiv(divId) {
    if (null != divId && divId.length > 3) {
        var checkId = divId.substring(3, 4);

        var elemt = $(divId);
        var chkElemt = $(checkId);
        if (elemt.style.display.toString() == 'none') {
            elemt.style.display = '';

        }
        else {
            elemt.style.display = 'none';
            chkElemt.checked = 0;
        }
    }
}
   
function DisplayDetails(mainElementId, childElementId) {
    if($(mainElementId).className == "collapsed")
    {
        $(mainElementId).className = "expanded";
        //document.getElementById(childElementId).className = "showDiv";
        $(childElementId).style.display = "";
        return;
    }
    if($(mainElementId).className == "expanded")
    {
        $(mainElementId).className = "collapsed";
        //document.getElementById(childElementId).className = "hideDiv";
        $(childElementId).style.display = "none";
        return;
    }
}

function OnGetResultButtonClick()
{
    var coaResult;
    //document.aspnetForm.quizType.value = 'coa';
        if (document.aspnetForm['quizType'].value == 'coa')
        {
            //coa processing here!
            
            var val=document.aspnetForm['coaPageResult'].value; 
            if(val == '0')
            {
                coaResult = 'coa_result=failure';
            }
            else if(val == '-1')
            {
                coaResult = 'coa_result=inconclusive';
            }
            else if(val == 'vlk')
            {
                coaResult = 'coa_result=vlk';
            }
            else
            {
                if(GetResultFromHidden()==true)
                {
                    coaResult = 'coa_result=success';
                    
                }
                else
                {
                    coaResult = 'coa_result=failure';
                    
                }  
            }
            
            document.aspnetForm.action = 'office/results.aspx?' + AppendQuizParameters(coaResult);         
            
        }
        else if($('quizType').value == 'cd')
        {            
            //logic for cd comes here!
            result = document.aspnetForm['cdresult'].value;
            
            if(result == -1)
            {
                document.aspnetForm.action = 'office/results.aspx?' + AppendQuizParameters('cd_result=inconclusive');
            }
            else if(result == 0)
            {
                document.aspnetForm.action = 'office/results.aspx?' + AppendQuizParameters('cd_result=failure');
            }
            // office - disc not included
            else if (result == -2)
            {
                document.aspnetForm.action = 'office/results.aspx?' + AppendQuizParameters('cd_result=discnotincluded');
            }
            else if(GetResultFromHidden()==true)
            {
                document.aspnetForm.action = 'office/results.aspx?' + AppendQuizParameters('cd_result=success');
            }
            else
            {
                document.aspnetForm.action = 'office/results.aspx?' + AppendQuizParameters('cd_result=failure');
            }       
        }   
    
        document.aspnetForm.submit();
}

function GetResultFromHidden()
{
    var f1,f2,f3,f4;
    f1 = document.aspnetForm['feature1'].value;
    f2 = document.aspnetForm['feature2'].value;
    f3 = document.aspnetForm['feature3'].value;
    f4 = document.aspnetForm['feature4'].value;
    
    if(f1=="no" || f2=="no" || f3=="no" || f4=="no")
    {
        return false;
    }
    else
    {
        return true;
    }
}

//opens the popup window for more details
function ShowPopup(url){
    //TODO: Replace 2nd parameter with window title?
    var obj=window.open(url,null,'width=560,height=400,resizable=yes,toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no');
    obj.focus();
}

//opens the popup window for more details with height and width
function ShowPopupWithHW(url,ht,wt){
    //TODO: Replace 2nd parameter with window title?
    //alert("called")
    var obj=window.open(url,null,'width=' + wt + ',height='+ ht +',resizable=yes,toolbar=no,status=no,scrollbars=yes,location=no,menubar=no,directories=no,left=300,top=10');
    obj.focus();
}

function imageOn1()
{
    $('top1').src='static/images/btn_top_on.jpg';
    $('icon1').src='static/images/btn_icon1_on.jpg';
    $('bottom1').src='static/images/btn_bt_on.jpg';
    $('icon1_bg').className='btn_icon1_on';
    $('txt_bg').className='btn_txt_on';
}

function imageOff1()
{
    $('top1').src='static/images/btn_top.jpg';
    $('icon1').src='static/images/btn_icon1.jpg';
    $('bottom1').src='static/images/btn_bt.jpg';
    $('icon1_bg').className='btn_icon1';
    $('txt_bg').className='btn_txt';
}

function imageOn2()
{
    $('top2').src='static/images/btn_top_on.jpg';
    $('icon2').src='static/images/btn_icon2_on.jpg';
    $('bottom2').src='static/images/btn_bt_on.jpg';
    $('icon2_bg').className='btn_icon2_on';
    $('txt2_bg').className='btn_txt_on';
}

function imageOff2()
{
    $('top2').src='static/images/btn_top.jpg';
    $('icon2').src='static/images/btn_icon2.jpg';
    $('bottom2').src='static/images/btn_bt.jpg';
    $('icon2_bg').className='btn_icon2';
    $('txt2_bg').className='btn_txt';
}

function imageOn3()
{
    $('top3').src='static/images/btn_top2_on.jpg';
    $('icon3').src='static/images/btn_icon1_on.jpg';
    $('bottom3').src='static/images/btn_bt2_on.jpg';
    $('icon3_bg').className='btn_icon3_on';
    $('txt3_bg').className='btn_txt2_on';
}

function imageOff3()
{
    $('top3').src='static/images/btn_top2.jpg';
    $('icon3').src='static/images/btn_icon1.jpg';
    $('bottom3').src='static/images/btn_bt2.jpg';
    $('icon3_bg').className='btn_icon3';
    $('txt3_bg').className='btn_txt2';
}

function AddtoFavorites(url)
{
    if (window.external)
    {
        window.external.AddFavorite(location.href, "Purchasing Genuine Microsoft Software");
    }
}

function btnContinue_OpenClientEmail(sourceId)
{
    window.open("mailto:gensub@microsoft.com?Subject=Submission to Microsoft Genuine program&body=SourceID = " + sourceId + " %0D%0DPlease attach your image file(s) to this email. Thank you.");   
}

function SubmitData(formname,url)
{
var myForm = document.forms[formname];
myForm.action = url;
myForm.method = "post";
myForm.submit();
}
