var ContentHeight = 100;
var TimeToSlide = 800.0;

var openAccordion = 'accordion1content';

//run accordion
function runAccordion(index) {
    var nID = 'accordion' + index + 'content';
    if (openAccordion == nID)
        nID = '';

    setTimeout('animate(' + new Date().getTime() + ',' + TimeToSlide + ',\'' + openAccordion + '\',\'' + nID + '\')', 33);

    openAccordion = nID;
}

//animate
function animate(lastTick, timeLeft, closingId, openingId) {
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var opening = (openingId == '') ? null : document.getElementById(openingId);
    var closing = (closingId == '') ? null : document.getElementById(closingId);

    if (timeLeft <= elapsedTicks) {
        if (opening != null)
            opening.style.height = ContentHeight + 'px';

        if (closing != null) {
            closing.style.display = 'none';
            closing.style.height = '0px';
        }
        return;
    }

    timeLeft -= elapsedTicks;
    var newClosedHeight = Math.round((timeLeft / TimeToSlide) * ContentHeight);

    if (opening != null) {
        if (opening.style.display != 'block')
            opening.style.display = 'block';
        opening.style.height = (ContentHeight - newClosedHeight) + 'px';
      
        //set opacity
        opening.style.opacity = (ContentHeight - newClosedHeight) / ContentHeight;    
        opening.style.filter = 'alpha(opacity=' + ((ContentHeight - newClosedHeight) * 100 / ContentHeight) + ')';
    }

    if (closing != null) {
        closing.style.height = newClosedHeight + 'px';      
        
        //set opacity
        closing.style.opacity = newClosedHeight / ContentHeight;
        closing.style.filter = 'alpha(opacity=' + (newClosedHeight * 100 / ContentHeight) + ')';
    }

    setTimeout('animate(' + curTick + ',' + timeLeft + ',\'' + closingId + '\',\'' + openingId + '\')', 33);
}

function openAccordionDiv(position) {
    if (document.getElementById('accordion' + position + 'content').style.display != 'block') {
        showHideInteractiveFrameContent(position);
        runAccordion(position);
    }
}

//on input leftbar click
function onInputClick(input)
{
    if (input.className == 'SEARCHFORMSGRAY')
    {
        input.value = '';
        input.className = 'FORMS';
    }
}

//key: only numeric 
function keyOnlyNumeric(e)
{
    //validate input
    if (navigator.appName == 'Netscape') 
        var keyIndex = e.which; //for netscape
    else 
        var keyIndex = window.event.keyCode; //other

    // only allow numbers and backspace
    if((keyIndex>47 && keyIndex<58) || keyIndex==0 || keyIndex==8 || keyIndex==46 || keyIndex==44)
        return true;
    else
        return false;
}

//key: only numeric 
function keyOnlyNumericWEnter(e)
{
    //validate input
    if (navigator.appName == 'Netscape') 
        var keyIndex = e.which; //for netscape
    else 
        var keyIndex = window.event.keyCode; //other

    // only allow numbers and backspace
    if((keyIndex>47 && keyIndex<58) || keyIndex==0 || keyIndex==8 || keyIndex==46 || keyIndex==44 || keyIndex==13)
        return true;
    else
        return false;
}

//key: only numeric 
function keyOnlyNumericWEnterWoCommaWoDot(e)
{
    //validate input
    if (navigator.appName == 'Netscape') 
        var keyIndex = e.which; //for netscape
    else 
        var keyIndex = window.event.keyCode; //other
        
    // only allow numbers and backspace
    if((keyIndex>47 && keyIndex<58) || keyIndex==0 || keyIndex==8 || keyIndex==13)
        return true;
    else
        return false;
}

//key: only numeric 
function keyOnlyNumericWEnterOnlyWoComma(e)
{
    //validate input
    if (navigator.appName == 'Netscape') 
        var keyIndex = e.which; //for netscape
    else 
        var keyIndex = window.event.keyCode; //other
        
    // only allow numbers and backspace
    if((keyIndex>47 && keyIndex<58) || keyIndex==0 || keyIndex==8 || keyIndex==13 || keyIndex==46)
        return true;
    else
        return false;
}


//currency format 
function formatCurrency(name,dec)   
{
    //init variables
    inp=name.value;
    comma=0; 
    sign = ""

    //get sign
    if (inp.substring(0,1) == '-') 
    {
        sign = '-';
        inp = inp.substring(1, inp.length);
    };

    //validate input value
    if (inp=='') 
        return;
    outt='';
    
    //loop characters
    for (var i=0; i<inp.length; i++) 
    {
        //get character
        sChar=inp.charAt(i);
        if (sChar=='.') 
            continue;
        else if (sChar==',') 
        {      
            if (dec==0) 
                break;
            if (comma>0) 
                break;
            comma=1;
            outt=outt+sChar;
        }
        else if (sChar<'0' || sChar>'9') 
            break;
        else 
        outt=outt+sChar;    
    }
    
    //get value with zeros
    out='';
    if (dec) 
    {
        zeros='000000000'; 
        out=',';
        pos1=outt.indexOf(',');
        if (pos1!=-1) 
        {
            pos2=outt.length;
            if (pos2-pos1-1>dec) 
                pos2=pos1+dec+1;
            out=out+outt.substring(pos1+1,pos2);
            outt=outt.substring(0,pos1);
        }  
        out=out+zeros.substring(0,3-out.length); 
    }
    //format value with separators
    for (i=outt.length; i>3; i-=3) 
        out="." + outt.substring(i-3,i) + out;
        
    //return formated value
    out=outt.substring(0,i)+out;
    name.value=sign+out;

}

//show / hide divs - faq
function showDiv(index, divCount) {
    //loop divs
    for (i = 1; i < divCount + 1; i++) {
        //selected div
        if (i == index) {
            var display = document.getElementById("div" + i).style.display;

            if (display == "none") {
                document.getElementById("div" + i).style.display = "block";
                document.getElementById("question" + i).className = "sansseriforange12b";
                document.getElementById("questionpos" + i).className = "sansseriforange12b";
                document.getElementById("imgquestion" + i).src = "images/arr_down_orange.gif";
            }
            if (display == "block") {
                document.getElementById("div" + i).style.display = "none";
                document.getElementById("question" + i).className = "sansserifblack12b";
                document.getElementById("questionpos" + i).className = "sansserifblack12b";
                document.getElementById("imgquestion" + i).src = "images/arr_right_silver.gif";
            }
        }
        else {
            //hide div
            document.getElementById("div" + i).style.display = "none";
            document.getElementById("question" + i).className = "sansserifblack12b";
            document.getElementById("questionpos" + i).className = "sansserifblack12b";
            document.getElementById("imgquestion" + i).src = "images/arr_right_silver.gif";
        }
    }
}

//add load event on page load. example: addLoadEvent(function() { alert('loaded!'); });
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

//refresh order basket
function ajaxOrderBasketItems(paymenttypeid, comment) {
    //send ajax request
    sendAjaxRequest(rooturl + 'ajaxorderbasket.aspx?paymenttypeid=' + paymenttypeid + '&comment=' + comment, 'basketarticles', '');
}

//validate comment
function ajaxOrderBasketItemsComment(comment) {
    //send ajax request
    sendAjaxRequest(rooturl + 'ajaxorderbasket.aspx?comment=' + escape(comment) + '&validate=1', 'basketarticles', '');
}

function getOrderItems(deliverytypeid, comment) {
    //send ajax request
    sendAjaxRequest(rooturl + 'ajaxorderitems.aspx?deliverytypeid=' + deliverytypeid + '&comment=' + escape(comment), 'basketarticles', '');
}

//show or hide artcile related group
function showHideArticleRelatedGroup(relatedartciletypeid) {

    var display = document.getElementById("articlerelatedtypeid_" + relatedartciletypeid).style.display;  

    if (display == "none") {
        document.getElementById("articlerelatedtypeid_" + relatedartciletypeid).style.display = "block";
        document.getElementById("openindicator_" + relatedartciletypeid).style.display = "none";
        document.getElementById("closeindicator_" + relatedartciletypeid).style.display = "block";        
    }
    else {
        document.getElementById("articlerelatedtypeid_" + relatedartciletypeid).style.display = "none";
        document.getElementById("openindicator_" + relatedartciletypeid).style.display = "block";
        document.getElementById("closeindicator_" + relatedartciletypeid).style.display = "none";        
    }   
}
