// JavaScript Document
// copyright 2000, a.i. Design Group, Inc.
  //open preview window 
  var winPreview = null;
  intPreviewWindowWidth = 800; 
  intPreviewWindowHeigth = 700;
  imgClearDot = new Image(1,1);
  imgClearDot.src = "../common/cleardot.gif";
function openWin(url, width, height)
{ 
    windowName = "preview";
    params = "toolbar=0,";
    params += "location=1,";
    params += "directories=0,";
    params += "status=1,";
    params += "menubar=0,";
    params += "scrollbars=1,";
    params += "resizable=1,"; 
    
    params += "width="+width+",";
    params += "height="+height;
    
    win = window.open(url, windowName, params);
    win.opener.name = "master";
    win.focus();
    return win;
}
function rightmost(aString, aNum)
{
    var tmp = ""+aString;
    if (aNum > tmp.length) return tmp;
    return (tmp.substring(tmp.length - aNum, tmp.length));
}
function leftmost(aString, aNum)
{
    var tmp = ""+aString

    if (aNum > tmp.length) return tmp
    return (tmp.substring(0, aNum))
}
function fnFormatCurrency(num)
{
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num) || num=="")

        return ("Call fo pricing");

//    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function sbDisplayDivider(o)
{   
    var bolImg0 = true;
    var bolImg1 = true;
    var bolImg2 = true;
    var bolImg3 = true;
     
  //if no images are selected, default is cleardot.gif
    if(o.document.getElementById("EQ_img0").value.length == 0)  //if blank
    {
        document.getElementById("img0").src = o.document.getElementById("EQ_img0_hidden").value; //get src from web site
        strTemp = " " + o.document.getElementById("EQ_img0_hidden").value;
        if(strTemp.indexOf("common/cleardot.gif") > -1) //if "common/cleardot.gif"
        {
            document.getElementById("img0").className = "imgCollapsed"; //set width and heigth = 1x1
            bolImg0 = false;
        }
        else
        {
            document.getElementById("img0").className = "imgMain";  //set width and heigth = 480x319
        }
    }
    else
    {
        document.getElementById("img0").src = o.document.getElementById("EQ_img0").value;//set to new image
        document.getElementById("img0").className = "imgMain";
    }
    if(o.document.getElementById("EQ_img1").value.length == 0)  //if blank
    {
        document.getElementById("img1").src = o.document.getElementById("EQ_img1_hidden").value; //get src from web site
        strTemp = " " + o.document.getElementById("EQ_img1_hidden").value;
        if(strTemp.indexOf("common/cleardot.gif") > -1) //if "common/cleardot.gif"
        {
            document.getElementById("img1").className = "imgCollapsed";//set width and heigth = 1x1
            bolImg1 = false;
        }
        else
        {
            document.getElementById("img1").className = "imgSmall"; //set width and heigth = 151x100
        }
    }
    else
    {
        document.getElementById("img1").src = o.document.getElementById("EQ_img1").value;//set to new image
        document.getElementById("img1").className = "imgSmall";
    }
    if(o.document.getElementById("EQ_img2").value.length == 0)  //if blank
    {
        document.getElementById("img2").src = o.document.getElementById("EQ_img2_hidden").value; //get src from web
        strTemp = " " + o.document.getElementById("EQ_img2_hidden").value;
        if(strTemp.indexOf("common/cleardot.gif") > -1) //if "common/cleardot.gif"
        {
            document.getElementById("img2").className = "imgCollapsed";//set width and heigth = 1x1
            bolImg2 = false;
        }
        else
        {
            document.getElementById("img2").className = "imgSmall"; //set width and heigth = 151x100
        }
    }
    else
    {
        document.getElementById("img2").src = o.document.getElementById("EQ_img2").value;
        document.getElementById("img2").className = "imgSmall";
    }
    if(o.document.getElementById("EQ_img3").value.length == 0)  //if blank
    {
        document.getElementById("img3").src = o.document.getElementById("EQ_img3_hidden").value; //get src from web
        strTemp = " " + o.document.getElementById("EQ_img3_hidden").value;
        if(strTemp.indexOf("common/cleardot.gif") > -1) //if "common/cleardot.gif"
        {
            document.getElementById("img3").className = "imgCollapsed";//set width and heigth = 1x1
            bolImg3 = false;
        }
        else
        {
            
            document.getElementById("img3").className = "imgSmall"; //set width and heigth = 151x100
        }
    }
    else
    {
        document.getElementById("img3").src = o.document.getElementById("EQ_img3").value;
        document.getElementById("img3").className = "imgSmall";
    }
    sbDisplayCLickForLarger(bolImg1 || bolImg2 || bolImg3);
}

function ClearError()
{
    return true;
}

function sbDisplayCLickForLarger(bolX) 
{
    window.onerror = ClearError;
    if(bolX)
        document.getElementById("idClickForLarger").style.display = "block";

}

function sbOpenPreview()
{
  //set values for querystring from values in "admin.asp"
    var strType = document.getElementById("EQ_Type").value;
    var strName = document.getElementById("EQ_Make").value +" "+ document.getElementById("EQ_Model").value +" ("+ document.getElementById("EQ_Year").value +")";
    var strDescription = "";
  //open preview window
    winPreview = openWin("../equipment/equipment.asp?type="+ strType +"&name="+ strName +"&preview=True", intPreviewWindowWidth, intPreviewWindowHeigth);
  //move preview window to far right of screen
    winPreview.moveTo(screen.width-intPreviewWindowWidth-15,25);
}

function sbUpdatePreview()
{  
    var strDescription = "";
    if (window.opener.name == "master")
    {
        winMaster = window.opener
      //hide "idClickForLarger" by default
//        document.getElementById("idClickForLarger").style.display = "none";
      //display images and seperator bar
        sbDisplayDivider(winMaster);
      //display name
        document.getElementById("idMake").innerHTML = winMaster.document.getElementById("EQ_Make").value;
        document.getElementById("idModel").innerHTML = winMaster.document.getElementById("EQ_Model").value;
        document.getElementById("idYear").innerHTML = winMaster.document.getElementById("EQ_Year").value;
        document.getElementById("idSN").innerHTML = winMaster.document.getElementById("EQ_SN").value;
      //display price with dollar sign
        document.getElementById("idPrice").innerHTML = fnFormatCurrency(winMaster.document.getElementById("EQ_Price").value);

      //build description
        for(i=1;i<10;i++)
        {
            strTemp = "EQ_Discription"+ rightmost("0"+i, 2);  //create strings "EQ_Discription01","EQ_Discription02","EQ_Discription03"...
            if(winMaster.document.getElementById(strTemp).value.length !=0) //use strings as names here
            {
                strDescription = strDescription + winMaster.document.getElementById(strTemp).value +"<br>"; //and here
            }   
        }
      //display description      
        if(strDescription.length >0)
            strDescription = "<span class='moreInfo'>Additional Information</span><br>" + strDescription;
        document.getElementById("idDescription").innerHTML = strDescription;
    }
}

function sbCopyFilePositions()
{
    for(i=0; i<4; i++)
    {
        strFilePositionID = "filePosition" + i;
        strImageID = "EQ_img" + i;
        document.getElementById(strFilePositionID).value = document.getElementById(strImageID).value;
    }
}



