﻿var infoPanFadeDir = 0;
var infoPanOpacity = 0;
var infoPanFadeT;
var copyMaxWidth=0;

function showBorderPanel(fCode,oCode,iCode,pCode,floor) 
{
    infoPanFadeDir = 0.2;
    infoPanFade();
    var rugInfoPanel= document.getElementById("rugInfoPanel");
    rugInfoPanel.style.display="block";
    /*
    rugInfoPanel.getElementsByTagName("div")[1].getElementsByTagName("div")[1].innerHTML=
    "<h5>" + borderName + "</h5>";*/
    
    document.getElementById( "rugInfoPanel" ).style.height = "300px";
    document.getElementById( "rugInfoPanel" ).style.width = "300px";
    document.getElementById( "infoPanBack" ).style.height = "300px";
    document.getElementById( "infoPanBack" ).style.width = "300px";
    document.getElementById( "infoPanImage" ).style.height = "290px";
    document.getElementById( "infoPanImage" ).style.width = "290px";
    //document.getElementById( "image" )
    document.getElementById( "infoPanInfo" ).style.display="none";
    
    var rugInfoPanel= document.getElementById("rugInfoPanel");
    if( oCode != "" ) {
    rugInfoPanel.getElementsByTagName("div")[1].getElementsByTagName("div")[0].style.backgroundImage = "url(../CreateARugImage.aspx?outborder=" + oCode + "&inborder=" +iCode + "&piping=" + pCode + "&floorcovering=" + fCode+ "&floor=" + floor+ ")";
    }
    else {
        rugInfoPanel.getElementsByTagName("div")[1].getElementsByTagName("div")[0].style.backgroundImage = "url(../Resources/FloorCoverings/350_350/"+ fCode+".jpg)";
    }
    
}

function hideInfoPanel() 
{
    infoPanFadeDir = -0.2;
    infoPanFade();
}

function infoPanFade() 
{
   clearTimeout( infoPanFadeT );
   infoPanFadeT = setTimeout( "infoPanFadeGo()", 100);
}

function infoPanFadeGo() 
{
        
    if(infoPanOpacity <= 0 &&  infoPanFadeDir < 0) 
    {
    }
    else if (infoPanOpacity >= 1 && infoPanFadeDir > 0)
    {
    }
    else 
    {
        infoPanOpacity += infoPanFadeDir;
        if( document.getElementById("rugInfoPanel").style.filter == null )
            document.getElementById("rugInfoPanel").style.opacity=infoPanOpacity;
        else
            document.getElementById("rugInfoPanel").style.filter= "alpha(opacity=" +(infoPanOpacity*100) + ")";
        infoPanFadeT = setTimeout( "infoPanFadeGo()", 10);
    }
    
    if(infoPanOpacity > 0 ) {
        document.getElementById("rugInfoPanel").style.display="block";        
    } else {
        document.getElementById("rugInfoPanel").style.display="none";       
    }
    
    
}

function copyWithNewSizeClick( basketItemIndex, hiddenField, maxWidth ) 
{
    document.getElementById("popupBox1").style.display = "block";
    hiddenField.value = basketItemIndex;
    copyMaxWidth = maxWidth;
}


function validateSize( widthBox, lengthBox, maxWidth ) 
{
    txtWidth = document.getElementById(widthBox);
    txtLength = document.getElementById(lengthBox); 
    cWidth = Number(txtWidth.value);
    cLength =  Number(txtLength.value);        
       
    if( checknumber(txtWidth.value)) 
    {
        if( cWidth > maxWidth ) {
            alert( "The maximum width for this floorcovering is " + maxWidth + "m" );
            txtWidth.value = maxWidth;
            cWidth = maxWidth;
        }
        
        txtWidth.value = Math.round(cWidth*100)/100
    }    
    if( checknumber(txtLength.value)) 
    {
        if( cLength > 7 ) 
        {
            alert( "The maximum length for any rug is 7m" );
            txtLength.value = "7";
            cLength = 7;
        }
        txtLength.value = Math.round(cLength*100)/100
    } 
    
}

function checknumber(x)
{
    var anum=/(^\d+$)|(^\d+\.\d+$)/;
    if (anum.test(x))
        testresult=true;
    else{
        testresult=false;
    }
    return (testresult);
}
