function isNumberKey( evt )
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

 return true;
}

function toggleActiveRadio( prefix, number )
{
    var n = 1;
    var id;
    
    while( id = document.getElementById(prefix + n) )
    {
        if(n != number)
        {
            id.checked = false;
        }
        else
        {
            id.checked = true;
        }
        
        n++;
    }

    return true;
}

function removeText( id, text )
{
    if ( id.value == text )
        id.value = '';

    return true;
}

function restoreText( id, text )
{
    if (id.value == '')
        id.value = text;
        
    return true;
}

//function openBuyWindow( page, qty )
//{
//   //window.showModelessDialog(page, '', 'dialogHeight: 350px; dialogWidth: 350px; status: no;')
//   // window.dialogArguments.location.reload(true);

//    var x = (screen.width-350)/2;
//    var y = (screen.height-350)/2;

//    popupWindow = window.open(page + '&qty=' + qty, '_blank', 'height=300px, width=350px, resizable=no, menubar=no, scrollbars=yes, status=no, titlebar=no, toolbar=no, left=' + x + ', top=' + y);
//    if (!popupWindow)
//    {
//        alert('Pop-up needed... ()')
//    }
//   
//    return true;
//}

function toggleDisplay(theId){
    if(document.getElementById){
        var element = document.getElementById(theId);
        if(element.style.display == 'none' || element.style.display == '') {
            element.style.display = 'block';
        } else {
            element.style.display = 'none';        
        }
    }
}

function showElement( theId )
{
    if (document.getElementById)
    {
        document.getElementById(theId).className = 'show';
        document.getElementById(theId).style.display = 'block';            
    }
//    return false;         
}

function hideElement( theId )
{
    if (document.getElementById)
    {
        document.getElementById(theId).className = 'hide';
        document.getElementById(theId).style.display = 'none';            
    }
    //return false;         
}

/* imported... */
function getKeyCode(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

function keyRestrict(e, validchars)
{
	var key = getKeyCode(e);
	if (key == null)
		return true;
	var keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if (key==0 || key==8 || key==9 || key==13 || key==27)
		return true;
	return false;
}

function zoomBox(oContainer, oImage, sUrl){
    if(document.getElementById){
        var img = document.getElementById(oImage);
        
        img.src = sUrl;
//        var cont = document.getElementById(oContainer);
//        cont.style.width = img.width +'px';
        toggleDisplay(oContainer);
    } else {
        return false;
    }
}

function showStockinfo(e){
    alert('1');
     e.style.display = 'none';
     document.getElementById('stockinfo').style.display = 'block';
     alert('2');
}

function showDeliveryChoice(newCtrl, oldCtrl, newCtrlParentId)
{
    document.getElementById(newCtrl).value = document.getElementById(oldCtrl).value;
    showElement(newCtrlParentId);
    return false;
}

//function countdown_clock(year, month, day, hour, minute, format)
//{
//     //I chose a div as the container for the timer, but
//     //it can be an input tag inside a form, or anything
//     //who's displayed content can be changed through
//     //client-side scripting.
//     html_code = '<div id='countdown'></div>';
//     
//     document.write(html_code);
//     
//     countdown(year, month, day, hour, minute, format);                
//}
     
function countdown(year, month, day, hour, minute, format)
{
     Today = new Date();
     Todays_Year = Today.getFullYear() - 2000;
     Todays_Month = Today.getMonth() + 1;                  
     
     //Convert both today's date and the target date into miliseconds.                           
     Todays_Date = (new Date(Todays_Year, Todays_Month, Today.getDate(), 
                             Today.getHours(), Today.getMinutes(), Today.getSeconds())).getTime();                                 
     Target_Date = (new Date(year, month, day, hour, minute, 00)).getTime();                  
     
     //Find their difference, and convert that into seconds.                  
     Time_Left = Math.round((Target_Date - Todays_Date) / 1000);
     
     if(Time_Left < 0)
        Time_Left = 0;
     
     switch(format)
           {
           case 0:
                //The simplest way to display the time left.
                document.getElementById('countdown_s').innerHTML = Time_Left + '';
                break;
           case 1:
                //More datailed.
                days = Math.floor(Time_Left / (60 * 60 * 24));
                Time_Left %= (60 * 60 * 24);
                hours = Math.floor(Time_Left / (60 * 60));
                Time_Left %= (60 * 60);
                minutes = Math.floor(Time_Left / 60);
                Time_Left %= 60;
                seconds = Time_Left;
                
                //dps = ''; hps = ''; mps = ''; sps = '';
                ////ps is short for plural suffix.
                //if(days == 1) dps ='';
                //if(hours == 1) hps ='';
                //if(minutes == 1) mps ='';
                //if(seconds == 1) sps ='';
                
                //document.getElementById('countdown').innerHTML = days + '' + dps + ' ';
                //document.getElementById('countdown').innerHTML += hours + '' + hps + ' ';
                //document.getElementById('countdown').innerHTML += minutes + '' + mps + ' ';
                //document.getElementById('countdown').innerHTML += seconds + '' + sps;

                document.getElementById('countdown_d').innerHTML = days > 9 ? days : '0' + days;
                document.getElementById('countdown_h').innerHTML = hours > 9 ? hours : '0' + hours;
                document.getElementById('countdown_m').innerHTML = minutes > 9 ? minutes : '0' + minutes;
                document.getElementById('countdown_s').innerHTML = seconds > 9 ? seconds : '0' + seconds;
                break;
           default: 
                document.getElementById('countdown_s').innerHTML = Time_Left + '';
           }
           
     //Recursive call, keeps the clock ticking.
     setTimeout(function(){countdown(year, month, day, hour, minute, format);}, 1000);
}
