﻿/*
    Functions relating to the UDesign pages
*/

var chk_on  = "project/webimages/check_on.jpg";
var chk_off = "project/webimages/check_off.jpg";
function checkChange(element_id) {
    var chk_element = document.getElementById(element_id.replace('img_', ''));
    chk_element.click()
    inputs = document.getElementsByName(chk_element.name);
    for (var i = 0; i < inputs.length; i++) {
        if (document.getElementById(inputs[i].id).checked) {
            document.getElementById('img_' + inputs[i].id).src = chk_on;
        } else {
            document.getElementById('img_' + inputs[i].id).src = chk_off;
        }
    }
}

function showImg(element_id,type)
{
    try{
        var toHide = document.getElementById(type);
            toHide.setAttribute('id',toHide.getAttribute('orig'));
            toHide.style.display = "none";
    }catch(Error){}
    try{
        var toShow = document.getElementById(element_id);
            toShow.setAttribute('orig',element_id);
            toShow.setAttribute('id',type);
            toShow.style.display = "inline";
    }catch(Error){}
}

function requestInformation(){
    try{
        var spa_type = encodeURI(document.getElementById('spa_type').value);

        switch (spa_type) {
            case "tropic":
                var usize               = encodeURI(getValue('usize'));
                //var ucolour_mos_benches = encodeURI(getValue('check_mos_benches'));
                //var ucolour_tiled_walls = encodeURI(getValue('check_tiled_walls'));
                var utile               = encodeURI(getValue('tiles'));
                var ulight_sound        = encodeURI(getValue('light_sound'));
                var ustyle              = encodeURI(getValue('style'));
                var uheat_scent         = encodeURI(getValue('check_heat_scent'));
                var umud                = encodeURI(getValue('check_mud'));
                var ubrine              = encodeURI(getValue('check_brine'));
                var uglass              = encodeURI(getValue('check_glass'));

                /*VALIDATION*/
                var valid = true;
                /*if ((ucolour_mos_benches.toUpperCase() == 'YES') || (ucolour_tiled_walls.toUpperCase() == 'YES')) {
                    if (utile == "NONE") {
                        valid = false;
                        alert("Please select a tile.");
                    } else {
                        if (ucolour_mos_benches.toUpperCase() == 'YES') { ucolour_mos_benches = utile.split(':')[0]; }
                        if (ucolour_tiled_walls.toUpperCase() == 'YES') { ucolour_tiled_walls = utile.split(':')[0]; }
                        utile = utile.split(':')[1];
                    }
                }
                if ((ucolour_mos_benches.toUpperCase() == 'NO') && (ucolour_tiled_walls.toUpperCase() == 'NO')) {
                    utile = "NONE";
                }*/

                if (valid) {
                    //var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&ucolour_mos_benches=' + ucolour_mos_benches + '&ucolour_tiled_walls=' + ucolour_tiled_walls + '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uheat_scent=' + uheat_scent + '&umud=' + umud + '&ubrine=' + ubrine + '&uglass=' + uglass;
                    var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize +  '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uheat_scent=' + uheat_scent + '&umud=' + umud + '&ubrine=' + ubrine + '&uglass=' + uglass;
                    var top = 100;
                    var left = 100;
                    var windowWidth = window.screen.width - 200;
                    var windowHeight = window.screen.height - 200;

                    window.open(popup_url, 'NEWWINDOW', "top=" + top + ",left=" + left + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar=false,toolbar=false,location,resizable,scrollbars,status");
                }
                break;
            case "orient":
                var usize               = encodeURI(getValue('usize'));
                //var ucolour_mos_benches = encodeURI(getValue('check_mos_benches'));
                //var ucolour_tiled_walls = encodeURI(getValue('check_tiled_walls'));
                var utile               = encodeURI(getValue('tiles'));
                var ulight_sound        = encodeURI(getValue('light_sound'));
                var ustyle              = encodeURI(getValue('style'));
                var uheat_scent         = encodeURI(getValue('check_heat_scent'));
                var ubrine              = encodeURI(getValue('check_brine'));
                var uglass              = encodeURI(getValue('check_glass'));

                /*VALIDATION*/
                var valid = true;
                /*
                if ((ucolour_mos_benches.toUpperCase() == 'YES') || (ucolour_tiled_walls.toUpperCase() == 'YES')) {
                    if (utile == "NONE") {
                        valid = false;
                        alert("Please select a tile.");
                    } else {
                        if (ucolour_mos_benches.toUpperCase() == 'YES') { ucolour_mos_benches = utile.split(':')[0]; }
                        if (ucolour_tiled_walls.toUpperCase() == 'YES') { ucolour_tiled_walls = utile.split(':')[0]; }
                        utile = utile.split(':')[1];
                    }
                }
                if ((ucolour_mos_benches.toUpperCase() == 'NO') && (ucolour_tiled_walls.toUpperCase() == 'NO')) {
                    utile = "NONE";
                }*/

                if (valid) {
                    //var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&ucolour_mos_benches=' + ucolour_mos_benches + '&ucolour_tiled_walls=' + ucolour_tiled_walls + '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uheat_scent=' + uheat_scent + '&ubrine=' + ubrine + '&uglass=' + uglass;
                    var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uheat_scent=' + uheat_scent + '&ubrine=' + ubrine + '&uglass=' + uglass;
                    var top = 100;
                    var left = 100;
                    var windowWidth = window.screen.width - 200;
                    var windowHeight = window.screen.height - 200;

                    window.open(popup_url, 'NEWWINDOW', "top=" + top + ",left=" + left + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar=false,toolbar=false,location,resizable,scrollbars,status");
                }
                break;
            case "arctic":
                var usize               = encodeURI(getValue('usize'));
                //var ucolour_benches     = encodeURI(getValue('check_benches'));
                //var ucolour_tiled_walls = encodeURI(getValue('check_tiled_walls'));
                var utile               = encodeURI(getValue('tiles'));
                var ulight_sound        = encodeURI(getValue('light_sound'));
                var ustyle              = encodeURI(getValue('check_style'));
                var uice_wall           = encodeURI(getValue('check_ice_wall'));
                
                /*VALIDATION*/
                var valid = true;
                /*
                if ((ucolour_benches.toUpperCase() == 'YES') || (ucolour_tiled_walls.toUpperCase() == 'YES')) {
                    if (utile == "NONE") {
                        valid = false;
                        alert("Please select a tile.");
                    } else {
                        if (ucolour_benches.toUpperCase() == 'YES') { ucolour_benches = utile.split(':')[0]; }
                        if (ucolour_tiled_walls.toUpperCase() == 'YES') { ucolour_tiled_walls = utile.split(':')[0]; }
                        utile = utile.split(':')[1];
                    }
                }
                if ((ucolour_benches.toUpperCase() == 'NO') && (ucolour_tiled_walls.toUpperCase() == 'NO')) {
                    utile = "NONE";
                }*/

                if (valid) {
                    //var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&ucolour_benches=' + ucolour_benches + '&ucolour_tiled_walls=' + ucolour_tiled_walls + '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uice_wall=' + uice_wall;
                    var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uice_wall=' + uice_wall;
                    var top = 100;
                    var left = 100;
                    var windowWidth = window.screen.width - 200;
                    var windowHeight = window.screen.height - 200;

                    window.open(popup_url, 'NEWWINDOW', "top=" + top + ",left=" + left + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar=false,toolbar=false,location,resizable,scrollbars,status");
                }
                break;
            case "monsoon":
                var usize           = encodeURI(getValue('usize'));
                var uloungers       = encodeURI(getValue('uloungers'));
                var utile           = encodeURI(getValue('tiles'));
                var uaqua_light     = encodeURI(getValue('check_aqua_light'));
                var urevive_refresh = encodeURI(getValue('check_revive_refresh'));

                /*VALIDATION*/
                var valid = true;
                if (utile == "NONE") {
                    valid = false;
                    alert("Please select a tile.");
                } else {
                    utile = utile.split(':')[1];
                }

                if (valid) {
                    var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&uloungers=' + uloungers + '&utile=' + utile + '&uaqua_light=' + uaqua_light + '&urevive_refresh=' + urevive_refresh;
                    var top = 100;
                    var left = 100;
                    var windowWidth = window.screen.width - 200;
                    var windowHeight = window.screen.height - 200;

                    window.open(popup_url, 'NEWWINDOW', "top=" + top + ",left=" + left + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar=false,toolbar=false,location,resizable,scrollbars,status");
                }
                break;
            case "shore":
                var usize       = encodeURI(getValue('usize'));
                var uloungers   = encodeURI(getValue('uloungers'));
                var utile       = encodeURI(getValue('tiles'));
                
                /*VALIDATION*/
                var valid = true;
                if (utile == "NONE") {
                    valid = false;
                    alert("Please select a tile.");
                } else {
                    utile = utile.split(':')[1];
                }

                if (valid) {
                    var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&uloungers=' + uloungers + '&utile=' + utile ;
                    var top = 100;
                    var left = 100;
                    var windowWidth = window.screen.width - 200;
                    var windowHeight = window.screen.height - 200;

                    window.open(popup_url, 'NEWWINDOW', "top=" + top + ",left=" + left + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar=false,toolbar=false,location,resizable,scrollbars,status");
                }
                break;
            case "sahara":
                var usize               = encodeURI(getValue('usize'));
                var ucolour_benches     = encodeURI(getValue('check_lime_benches'));
                var ucolour_interiors   = encodeURI(getValue('check_interiors'));
                var utile               = encodeURI(getValue('tiles'));
                var ulight_sound        = encodeURI(getValue('light_sound'));
                var ustyle              = encodeURI(getValue('check_style'));
                var uglass              = encodeURI(getValue('check_glass'));
                
                /*VALIDATION*/
                var valid = true;
                if ((ucolour_interiors.toUpperCase() == 'YES')) {
                    if (utile == "NONE") {
                        valid = false;
                        alert("Please select a tile.");
                    }
                }
                if ((ucolour_interiors.toUpperCase() == 'NO')) {
                    utile = "NONE";
                }

                if (valid) {
                    var popup_url = 'contactdetails.asp?spa_type=' + spa_type + '&usize=' + usize + '&ucolour_benches=' + ucolour_benches + '&ucolour_interiors=' + ucolour_interiors + '&utile=' + utile + '&ulight_sound=' + ulight_sound + '&ustyle=' + ustyle + '&uglass=' + uglass;
                    var top = 100;
                    var left = 100;
                    var windowWidth = window.screen.width - 200;
                    var windowHeight = window.screen.height - 200;

                    window.open(popup_url, 'NEWWINDOW', "top=" + top + ",left=" + left + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar=false,toolbar=false,location,resizable,scrollbars,status");
                }
                break;
            default:
                alert('unknown type ' + spa_type);
        }        
    }catch(Error){alert(Error);}
}

function getValue(element_id)
{
    var element     = document.getElementsByName(element_id);
    var type        = element[0].getAttribute('type');
    var return_val  = "NONE";
    switch(type)
    {
        case "radio":
            for (var i=0;i < element.length; i++)
            {
                if (element[i].checked)
                {
                    return_val = element[i].value;
                    break;
                }
            }
            break;
        case "checkbox":
            if (element[0].checked)
            {
                return_val = "Yes";
            }else{
                return_val = "No";
            }
            break;
        default:
            alert("element.type "+ type);
    }
    return return_val;
}