var isDOM = document.getElementById ? true : false;
var isIE = document.all ? true : false;

function getNode(id) {
    if (isDOM) {
        return document.getElementById(id);
    } else if (isIE) {
        return document.all[id];
    } else {
        return document.layers[id];
    }
}

function getStyle(id) {
    if (isDOM) {
        return document.getElementById(id).style;
    } else if (isIE) {
        return document.all[id].style;
    } else {
        return document.layers[id];
    }
}

function hideDiv(id) {
    getStyle(id).display="none";
}

function showDiv(id) {
    getStyle(id).display="block";
}

//------------------------------------------------------------
// open new window
//------------------------------------------------------------
function openWindow(loc, name, width, height, features) {
    leftPos = (screen.width) ? (screen.width - width) / 2 : 0;
    topPos = (screen.height) ? ((screen.height- height) / 2) - 100 : 0;
    var win = window.open(loc, name, 'width=' + width + ', height=' + height + ', top=' + topPos + ', left=' + leftPos + ', ' + features);
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

//------------------------------------------------------------
// textarea character counter
//------------------------------------------------------------
function textCounter(field, countfield, maxlimit) {
    if (field.value.length > maxlimit) {
        field.value = field.value.substring(0, maxlimit);
        field.blur();
        field.focus();
        return false;
    } else {
        countfield.value = maxlimit - field.value.length;
    }
}

function launchOffer(act){
     openWindow(act, "ChildWindow", 650, 480, 'scrollbars=yes,resizable=yes,toolbar=1')
     win.focus();
}

//------------------------------------------------------------
// Show a spinner for smartwatch.
//------------------------------------------------------------
function waitForSmartWatch(){
	if(!$('sw-loading')) return;
	loadingSpan = $('sw-loading');
	loadingSpan.className="sw-show";
	loadingSpan.innerHTML = '<img src="/images/smartwatch/loading-transparent.gif"/><br/>Loading your SmartWatch report...';
}