function viewImageInNewWindow(img_name, width, height)
{
    var args = 'width=' + width + ', height=' + height +', toolbar=0,';
        args += 'location=0, status=0, menubar=0, scrollbars=0, resizable=0';  
    var win = window.open("", "", args); 

    win.document.open();
    win.document.writeln('<img src="' + img_name +'" alt="">');
    win.document.close();
}

function viewCertInNewWindow(img_name, width, height)
{
    var args = 'width=' + width + ', height=' + height +', toolbar=0,';
        args += 'location=0, status=0, menubar=0, scrollbars=1, resizable=0';  
    var win = window.open("", "", args); 

    win.document.open();
    win.document.writeln('<img src="' + img_name +'" alt="">');
    win.document.close();
}

function GetNewUrl(url, page)
{
//    var tmp = new String(url);
//    var tmpUrl = tmp.substring(0, GetLastPosition(url, "/"));
//    return tmpUrl + "/" + page;
return page;
}

function openLinkInNewWindow(page, width, height, loc)
{
    var args = 'width=' + width + ', height=' + height +', toolbar=0,';
        args += 'location=0, status=0, menubar=0, scrollbars=1, resizable=0';  
    var win = window.open("", "", args); 

    win.location = GetNewUrl(loc, page);
}

function OpenFlash(page, width, height, loc, flashId)
{
    openLinkInNewWindow(page + "?flash_id=" + flashId, width, height, loc);
}

function openLinkInNewWindowEx(page, width, height, loc)
{
    var args = 'width=' + width + ', height=' + height +', toolbar=0,';
        args += 'location=0, status=0, menubar=1, scrollbars=1, resizable=1';  
    var win = window.open("", "", args); 

    win.location = GetNewUrl(loc, page);
}

function viewFlashMovieInNewWindow(width, height, mName, mWidth, mHeight, objName, divId)
{
    var args = 'width=' + width + ', height=' + height +', toolbar=0,';
        args += 'location=0, status=0, menubar=0, scrollbars=0, resizable=0';  
    var win = window.open("", "", args); 

    var divTag = '<div id="' + divId + '" style="margin: 0; padding: 0; vertical-align: top;" align="center"></div>';
    var flashMovie = GetFlashBanner(mName, mWidth, mHeight, objName);
    //var bannerFunc = 'CreateBanner("' + divId + '", "' + mName + '",' + mWidth + ',' + mHeight + ',"' + objName + '");';
    //var htmlDoc = GetHtmlDocument(divTag + '\n' + '<script language=\"javascript\">' + bannerFunc + '</script>' + '\n<noscript>\n' + flashMovie  + '\n</noscript>\n');

    var bannerFunc = 'CreateBanner("' + divId + '", "' + mName + '",' + mWidth + ',' + mHeight + ', "' + objName + '");';
    var htmlDoc = GetHtmlDocument(divTag + '\n' + '<script type=\"text/javascript\">' + bannerFunc + '</script>' + '\n<noscript>\n' + flashMovie  + '\n</noscript>\n');

    //alert(htmlDoc);

    win.document.open();
    win.document.writeln(htmlDoc);
    win.document.close();
    
    //win.location.reload(true);
}

function GetHtmlDocument(content)
{
    var htmlBody = "";
    
    htmlBody += "<html>"  + "\n";
    htmlBody += "<head>"  + "\n";
    htmlBody += "<script language=\"javascript\" src=\"js/image_view.js\"></script>"  + "\n";
    htmlBody += "<script language=\"javascript\" src=\"js/screenshot.js\"></script>"  + "\n";
    //htmlBody += "<script language=\"javascript\" >AC_FL_RunContent = 0;</script>"  + "\n";
    //htmlBody += "<script language=\"javascript\" src=\"js/AC_RunActiveContent.js\"></script>"  + "\n";
    htmlBody += "<head>"  + "\n";
    htmlBody += "<body style=\"margin: 0; padding: 0;\">"  + "\n";
    htmlBody += content   + "\n";
    htmlBody += "</body>" + "\n";
    htmlBody += "<html>"  + "\n";
    
    return htmlBody;
}

function viewBlockInNewWindow(blockContent, width, height)
{
    var args = 'width=' + width + ', height=' + height +', toolbar=0,';
        args += 'location=0, status=0, menubar=0, scrollbars=0, resizable=0';  
    var win = window.open("", "", args); 

    win.document.open();
    win.document.writeln(blockContent);
    win.document.close();
}

function GetLastPosition(str, searchValue)
{
    if (str || str == '')
    {
        var tmp = new String(str);
        var lastPos = tmp.lastIndexOf(searchValue);

        /*if (lastPos == -1)
        {
            lastPos = 0;//tmp.length + 1;
        }*/

        return lastPos;
    }
    else
    {
        alert ("Function GetLastPosition: str is not set!");
    }
}

function CreateTableWithImage(tW, tH, iW, iH, img_name)
{
    var result = "";
    
    result += "<table cellspacing=\"0\" cellpadding=\"0\" style=\"width: " + tW +"px; height: " + tH + "; margin: 0; padding: 0;\">\n";
    result += "  <tr>\n";
    result += "    <td style=\"width: 200px; vertical-align: top; padding: 7px 10px 0 0;\">\n";
    
    result += "      <table cellspacing=\"0\" cellpadding=\"0\" style=\"width: 100%; height: auto; font-family: margin: 5px 10px 0 0; Verdana; vertical-align: top;\">\n";
    result += "        <tr>\n";
    result += "          <td colspan=\"3\" style=\"font-size: 14px;\">\n";
    result += "            <h4>Дверь ДС 3 с бронепакетом</h4> ";
    result += "          </td>\n";
    result += "        </tr>\n";
    
    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            1";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 дверная коробка ";
    result += "          </td>\n";
    result += "        </tr>\n";
    
    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            2";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "            петля (2 шт.)";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            3";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 противосъемный фиксатор (5 шт.) ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            4";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "              	 внутренняя панель";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            5";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 отделочный уголок ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            6";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "            ребра жесткости (5 шт.) ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            7";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "            дверное полотно ";
    result += "          </td>\n";
    result += "        </tr>\n";

    
    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            8";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 уплотнитель";
    result += "          </td>\n";
    result += "        </tr>\n";
    
    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            9";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 ригель вертикального запирания (2 шт.)";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            10";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 задвижка ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            11";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "            замок с ручкой ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            12";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "            минералоплита ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            13";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 монтажный стержень (10шт.) ";
    result += "          </td>\n";
    result += "        </tr>\n";

    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            14";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "             	 внутренний лист металла ";
    result += "          </td>\n";
    result += "        </tr>\n";    
    
    result += "        <tr style=\"font-size: 16px; height: 20px;\">\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            15";
    result += "          </td>\n";
    result += "          <td style=\"width: 20px; vertical-align: top;\" align=\"left\">\n";
    result += "            -";
    result += "          </td>\n";
    result += "          <td>\n";
    result += "            крепежные пластины(10 шт.) ";
    result += "          </td>\n";
    result += "        </tr>\n";    
    
    result += "      </table>\n";
    
    result += "    <td>\n";
    result += "      <img src=\"" + img_name + "\" alt=\"\">\n";
    result += "    </td>\n";
    
    result += "  </tr>\n";
    result += "</table>";
    
    return result;
}