﻿// JScript File
var baseUrl = "GetData.aspx";



function getXMLHTTP()
{   
    //alert('in getXMLHTTP');
    var A=null;
    try
    {
        A=new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch(e)
    {
        try
        {   
            A=new ActiveXObject('Microsoft.XMLHTTP');
        }
        catch(oc){A=null;}
    }
    if(!A&&typeof XMLHttpRequest!='undefined')
        {
        A=new XMLHttpRequest();
        }
    return A;
}




function getSource(site,productId) 
{
    //alert("in getSource"+ productId);
    //var alertstring = 'in getSource filter filter = '+filter;
    //alert(alertstring); 
    if(productId != "0")
    {
        //alert('productId voor: '+productId);
        productId = doks[productId];
        site = "product";
        //alert('productId na: '+productId);
    }
//    else
//    {
//        //alert('hier');
//        
//    }
    
    var requestUrl=baseUrl+'?site='+site;
    if(productId!=undefined&&productId!='')
    {
        requestUrl+='&productId='+productId;
    }
    //alert('requestUrl = '+requestUrl);
    xmlHttpSource=getXMLHTTP();
    if(xmlHttpSource)
    {
        xmlHttpSource.onreadystatechange=doReadyStateChange;
        xmlHttpSource.open('POST',requestUrl,true);
        xmlHttpSource.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
     xmlHttpSource.setRequestHeader('Content-length', '0');

        xmlHttpSource.send('');
    }
}





    
function doReadyStateChange()
{
    //alert('in doReadyStateChange');
    if(xmlHttpSource.readyState==4)
    {
        if(xmlHttpSource.status==200 )
        {
            eval('var d='+xmlHttpSource.responseText);
            //alert("doready1");
            if(d!=null)
            {   
                 //alert("doready2");
                 populateList(d);
            }

            
        }
        else
        {
            alert('doReadyStateChange: xmlHttpSource.status = '+ xmlHttpSource.status+ ' There was a problem retrieving the data:\n'+xmlHttpSource.statusText);
            //alert('Error klik ok om verder te gaan');
            
           
        }
    }
}


function populateList(namevalue)
{
    //alert('in populateList');
    for(var i=0;i<namevalue.length;i++)
    {
        //alert('namevalue = '+ namevalue[i].id + '  ' + namevalue[i].name + '  ' + namevalue[i].value);
        switch (namevalue[i].id)
        {
            case "titleGreen":
                //alert('titleGreen'); 
                document.getElementById('spanTitleGreen').innerHTML = namevalue[i].value;
                //alert(document.getElementById('spanTitleGreen').innerHTML); 
                break;
            case "titleRed": 
                document.getElementById('spanTitleRed').innerHTML = namevalue[i].value;
                break;
//            case "subtitle": 
//                document.getElementById('spanSubTitle').innerHTML = namevalue[i].value;
//                break;
            case "innerHTML": 
                document.getElementById('spanText').innerHTML = namevalue[i].value;
                break;
            case "image": 
                document.getElementById('divBodyLeft').innerHTML = namevalue[i].value;
                break;    
            case "productInfo":
                document.getElementById('divBodyLeft').innerHTML = namevalue[i].value;
                break;    
            
                
            default : 
                //alert("I\'m sure it was great");
        }
    }

}

function HideDottedLine()
{
    //alert('hide dotted line');
    //document.getElementById('divDottedLine').style.visibility="hidden";
}



function SendEmail()
{
    //alert('SendEmail');
    
    var requestUrl="GetEmail.aspx";
    
     //alert('requestUrl = '+requestUrl);
    xmlHttpSource=getXMLHTTP();
    if(xmlHttpSource)
    {
        xmlHttpSource.onreadystatechange=EmailIsSend;
        xmlHttpSource.open('POST',requestUrl,true);
        xmlHttpSource.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
     xmlHttpSource.setRequestHeader('Content-length', '0');

        xmlHttpSource.send('');
        }
}

function EmailIsSend()
{
    //alert('in EmailIsSend');
    if(xmlHttpSource.readyState==4)
    {
        if(xmlHttpSource.status==200 )
        {
            eval('var d='+xmlHttpSource.responseText);
            //alert("doready1");
            if(d!=null)
            {   
                 //alert("doready2");
                 //populateList(d);
                 document.forms[0].submit();
            }

            
        }
        else
        {
            alert('doReadyStateChange: xmlHttpSource.status = '+ xmlHttpSource.status+ ' There was a problem retrieving the data:\n'+xmlHttpSource.statusText);
            //alert('Error klik ok om verder te gaan');
            
           
        }
    }
}
