// disclaimerclosed variable used to determine if mouse is on tooltip or not (1=not, 0=on)
var disclaimerclosed = 1;

function dropcurrencylist() {
	//drop down currency list]
	var curlist = document.getElementById('currencyselect');
	if(curlist.style.display=='block'){
		curlist.style.display='none';
	}
	else{
		//document.getElementById('curdisclaimer').style.display = "none";
		curlist.style.display='block';
	}
}

function Set_Cookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) +
((expires) ? ";expires=" + expires_date.toGMTString() : "") +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
((secure) ? ";secure" : "");
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie(check_name) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split(';');
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f

    for (i = 0; i < a_all_cookies.length; i++) {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split('=');


        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

        // if the extracted name matches passed check_name
        if (cookie_name == check_name) {
            b_cookie_found = true;
            // we need to handle case where cookie has no value but exists (no = sign, that is):
            if (a_temp_cookie.length > 1) {
                cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
            }
            // note that in cases where cookie is initialized but no value, null is returned
            return cookie_value;
            break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if (!b_cookie_found) {
        return null;
    }
}

function displaycurrency(thecurrency)
{
  //set value into currency combo box and show disclaimer
    var curbox = document.getElementById('currencybox');

    switch (thecurrency.toLowerCase()) {
        case 'eur':
            Set_Cookie('SSCURRENCYNLG', "EUR", "90", "/");
            break;
        case 'gbp':
            Set_Cookie('SSCURRENCYNLG', "GBP", "90", "/");
            break;
        case 'usd':
            Set_Cookie('SSCURRENCYNLG', "USD", "90", "/");
            break;
        default:
            Set_Cookie('SSCURRENCYNLG', "GBP", "90", "/");
    }


    if (curbox != null) {
    
        
    
        switch (thecurrency.toLowerCase()) {
            case 'eur':
                curbox.innerHTML = "<table cellpadding='0' cellspacing='0' border='0'><tr><td width='17' style='width:17px'><img src='/images/flags/16x16/plain/flag_eu.png' id='flagtype' width='16' height='16' align='left' /></td><td>Euro - EUR</td></tr></table>";
                break;
            case 'gbp':
                curbox.innerHTML = "<table cellpadding='0' cellspacing='0' border='0'><tr><td width='17' style='width:17px'><img src='/images/flags/16x16/plain/flag_united_kingdom.png' id='flagtype' width='16' height='16' align='left' /></td><td>British Pound - GBP</td></tr></table>";
                break;
            case 'usd':
                curbox.innerHTML = "<table cellpadding='0' cellspacing='0' border='0'><tr><td width='17' style='width:17px'><img src='/images/flags/16x16/plain/flag_usa.png' id='flagtype' width='16' height='16' align='left' /></td><td>US Dollar - USD</td></tr></table>";
                break;
            default:
                curbox.innerHTML = "<table cellpadding='0' cellspacing='0' border='0'><tr><td width='17' style='width:17px'><img src='/images/flags/16x16/plain/flag_united_kingdom.png' id='flagtype' width='16' height='16' align='left' /></td><td>British Pound - GBP</td></tr></table>";
        }
    }

    if (document.getElementById('currencyselect') != null) {
        document.getElementById('currencyselect').style.display = "none";
    }
}

if (Get_Cookie("SSCURRENCY") == "") {
    Set_Cookie("SSCURRENCY", "GBP", "90", "/");
}

function setcurrency(thecurrency) {
    displaycurrency(thecurrency);

    /*if (thecurrency != 'gbp') 
    {
        // If currency code is set to the session bean correctly, a response object will be returned. The current page should be refreshed.
        disclaimerclosed = 0;
        document.getElementById("curdisclaimer").style.display ="block";
        setTimeout ('closedisclaimer()', 4000);
    }*/
    SetBasketCurrency(thecurrency);
    //location.reload(true);
}

function closedisclaimer() {
	//loop timer until mouse is off disclaimer, if mouse is off (disclaimerclosed = 1) then okay to close it, otherwise continue loop
	if (document.getElementById('curdisclaimer').style.display == "none") {
		//if its already closed
		return;
	}
	else {
		if (disclaimerclosed == 1) {
		    document.getElementById("curdisclaimer").style.display ="none";
			location.reload(true);
			return;
		}
		setTimeout ('closedisclaimer()', 1000);
	}
}

function closenow()
{
    document.getElementById("curdisclaimer").style.display = "none";
	location.reload(true);
}
