var previousColor = "";

function openNew(url, width, height)
{
	var _x = (screen.width / 2 ) - (width / 2);
	var _y = (screen.height / 2) - (height /2);
	
	SelectWindow = window.open(url, "newwindow", "scrollbars, width=" + width + ", height=" + height + ", left=" + _x + ", top=" + _y);
	if(!SelectWindow.opener) SelectWindow.opener = self;
	SelectWindow.focus();
}
function highliteRow(row)
{
    previousColor = row.style.backgroundColor;
    row.style.backgroundColor = "yellow";
}
function unhighliteRow(row)
{
    row.style.backgroundColor = previousColor;
    previousColor = "";
}
function togglePanel(chk, elId)
{
    var pnl;
    if(document.getElementById(elId))
        pnl=document.getElementById(elId);
    
    if(typeof pnl !="undefined")
    {
        if(chk.checked)
            pnl.style.display="inline";
        else
            pnl.style.display="none";
    }
}
function showPictures(obj, partNo, mfg)
{
    createModalWindow("Picture Viewer",390,300);
}
function getParentOffset(obj)
{
    var left=0;
    var top=0;
    while(obj.offsetParent)
    {
        left += obj.offsetLeft;
        top  += obj.offsetTop;
        obj   = obj.offsetParent;
    }
    
    return {x:left, y:top};
}
function createModalBackground()
{
    var site = document.getElementById('Site');
    var div = document.createElement("div");
    div.style.position = "absolute";
    div.id = "modal_background";
    div.style.left = 0;
    div.style.top = 0;
    div.style.width = "100%";
    div.style.height = document.body.offsetHeight;
    div.style.filter = "alpha(opacity=75);";
    div.style.MozOpacity = 75/100;
    div.style.backgroundColor="black";
    div.style.display="block";
    site.appendChild(div);        
}
function destroyModalBackground()
{
    var site = document.getElementById('Site');
    var div;
    if(document.getElementById('modal_background'))
        div = document.getElementById('modal_background');
    if(typeof div !="undefined")
        site.removeChild(div);
    else
        alert("failed to locate background object.");
}
function createModalWindow(m_title, m_width, m_height)
{
    createModalBackground();
    var site = document.getElementById('Site');
    
    m_height = m_height + 30;
    //var c_left = (document.body.clientWidth/2) - (m_width/2);
    //var c_top = (document.body.clientHeight/2) - (m_height/2)-200;
    var c_left = 10;
    var c_top = 10;
    var m_window = document.createElement("div");
    m_window.style.display = "block";
    m_window.style.position = "fixed";
    m_window.style.left = c_left;
    m_window.style.top = c_top;
    m_window.style.padding = "1px";
    m_window.style.backgroundColor = "white";
    m_window.style.fontFamily = "arial,verdana,tahoma";
    m_window.style.fontSize = "10pt";
    m_window.style.fontWeight = "normal";
    m_window.style.width = m_width;
    m_window.style.height = m_height;
    m_window.style.verticalAlign = "top";
    m_window.style.textAlign = "left";
    m_window.style.zIndex = 1000;
    m_window.style.overflow = "auto";
    m_window.id = "m_window";
    
    var m_window_title = document.createElement("div");
    m_window_title.style.display = "block";
    m_window_title.style.backgroundColor = "blue";
    m_window_title.style.color="white";
    m_window_title.style.fontFamily = "arial,verdana,tahoma";
    m_window_title.style.fontSize = "10pt";
    m_window_title.style.padding="5px";
    m_window_title.style.textAlign="left";
    m_window_title.style.verticalAlign="middle";
    m_window_title.style.fontWeight="bold";
    m_window_title.id = "m_window_title";
    m_window_title.innerHTML = m_title + " | " + "<a style='color: white;' href=\"javascript:destroyModalWindow('m_window');\">[Close this window]";
    
    //create table
    var m_window_table = document.createElement("table");
    m_window_table.cellPadding="0";
    m_window_table.cellSpacing="1";
    m_window_table.style.border="none";
    m_window_table.id="tbl";
    
    //create new row
    var newRowIndex = m_window_table.rows.length;
    var m_window_table_row0 = m_window_table.insertRow(newRowIndex);
    
    //create 3 new cells
    var m_window_table_row0_cell0 = m_window_table_row0.insertCell(0);
    var m_window_table_row0_cell1 = m_window_table_row0.insertCell(1);
    var m_window_table_row0_cell2 = m_window_table_row0.insertCell(2);
    
    //create 3 images to fill those cells.
    var m_window_image1 = document.createElement("img");
    var m_window_image2 = document.createElement("img");
    var m_window_image3 = document.createElement("img");
    m_window_image1.src="images/elec_001.gif";
    m_window_image2.src="images/elec_002.gif";
    m_window_image3.src="images/elec_003.gif";
    
    //add the images to the cells.
    m_window_table_row0_cell0.appendChild(m_window_image1);
    m_window_table_row0_cell1.appendChild(m_window_image2);
    m_window_table_row0_cell2.appendChild(m_window_image3);
    
    m_window.appendChild(m_window_title);
    m_window.appendChild(m_window_table);
    site.appendChild(m_window);
}
function destroyModalWindow(m_windowid)
{
    var site = document.getElementById('Site');
    var m_window;
    if(document.getElementById(m_windowid))
        m_window = document.getElementById(m_windowid);
        
    if(typeof m_window != "undefined")
    {
        site.removeChild(m_window);
    }
    destroyModalBackground();
}
function UpgradeAccount()
{
    createModalBackground();
    openNew('SellerAgreement.aspx',640,480);
}