﻿var xmlHttp

var departments = new Array();
departments['dk'] = new Array();
departments['no'] = new Array();
departments['se'] = new Array();
departments['fi'] = new Array();

departments['dk'][0] = 'Administration';
departments['dk'][1] = 'Cinema';
departments['dk'][2] = 'Sales';
departments['dk'][3] = 'Marketing';
departments['dk'][4] = 'IT';
departments['dk'][5] = 'Product development';
departments['dk'][6] = 'Logistics';
departments['dk'][7] = 'Warehouse';
departments['dk'][8] = 'Royalty';
departments['no'][0] = 'Sales';
departments['no'][1] = 'Marketing';
departments['no'][2] = 'Customer service';
departments['no'][3] = 'Theatrical';
departments['se'][0] = 'Managing Director';
departments['se'][1] = 'Sales';
departments['se'][2] = 'Marketing';
departments['fi'][0] = 'DVD';
departments['fi'][1] = 'Orders';
departments['fi'][2] = 'Theatrical';

function selectcountry(country)
{
    var obj=document.getElementById('contactdepartment');
    while (obj.options.length > 0)
    {
        obj.options[0] = null;
    }
    
    for (x in departments[country])
    {
        var optionObject = new Option(departments[country][x],departments[country][x])
        var optionRank = obj.options.length
        obj.options[optionRank]=optionObject
    }
}

function contact()
{
    document.getElementById('contactform').style.display = 'block';
}

function contactcancel()
{
    document.getElementById('contactform').style.display = 'none';
}

function contactsend()
{
    document.getElementById('loadingblue').style.display = 'block';
	    
    // Make our POST parameters string
  	var params = "country=" + encodeURI(document.getElementById('contactcountry').value);
  	params = params + "&department=" + encodeURI(document.getElementById('contactdepartment').value);
  	params = params + "&name=" + encodeURI(document.getElementById('contactname').value);
  	params = params + "&email=" + encodeURI(document.getElementById('contactemail').value);
  	params = params + "&msg=" + encodeURI(document.getElementById('contactmsg').value);
  	xmlHttp = null;
	xmlHttp = GetXmlHttpObject();
	
  	xmlHttp.open("POST", "SubmitContact.aspx", true);
  	xmlHttp.onreadystatechange = contactChanged
  	
  	// Set our POST header correctly…
  	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	xmlHttp.setRequestHeader("Content-length", params.length);
  	xmlHttp.setRequestHeader("Connection", "close");
  	
  	// Send the parms data…
  	if (callInProgress(xmlHttp))
  	    xmlHttp.abort();
  	    
  	xmlHttp.send(params);
}
/*
function ok()
{
    document.getElementById('message').style.display = 'none'
    document.getElementById('ctl00_ContentMain_plTransbg').className = '';
}
*/
function contactChanged() 
{
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
    { 
        document.getElementById('loadingblue').style.display = 'none';
        document.getElementById('contactform').style.display = 'none';
        document.getElementById('ctl00_plMessage').className = 'message messageshow';
        document.getElementById('ctl00_plTransbg').className = 'transbg';
        var result = xmlHttp.responseText;
        if (result == 1)
            document.getElementById('ctl00_lblMsg').innerHTML = 'The form was sent';
        else if(result == 0)
            document.getElementById('ctl00_lblMsg').innerHTML = 'An error occured while sending form!';
        else if(result == 2)
            document.getElementById('ctl00_lblMsg').innerHTML = 'An error occured while sending form!<br>- Invalid E-Mail address';
        else if(result == 3)
            document.getElementById('ctl00_lblMsg').innerHTML = 'An error occured while sending form!<br>- Nothing reasonable to send';
        else
            document.getElementById('ctl00_lblMsg').innerHTML = 'An error occured while sending form!<br>- Undefined';
            
        xmlHttp.close;
    }
}

function GetXmlHttpObject()
{
    var l_xmlHttp=null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        l_xmlHttp=new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            l_xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            l_xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return l_xmlHttp;
}

function callInProgress(l_xmlhttp)
{
    switch ( l_xmlhttp.readyState )
    {
        case 1, 2, 3:
            return true;
            break;
        // Case 4 and 0
        default:
            return false;
        break;
    }
}
