function viewFlash(n, t, w,h) { 
if (!w) w=640;
if (!h) h=480;
win1 = window.open("", "Image", "width="+w+",height="+h+", top="+((screen.height - h) / 2)+", left="+((screen.width - w) / 2)+",toolbar=0,statusbar=0,location=0,scrollbars=0,resizable=0");
win1.document.open();
win1.document.write("<html><head><TITLE>"+t+"</TITLE></head>" + "<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0>");
win1.document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="'+w+'" HEIGHT="'+h+'" ALIGN="">');
win1.document.write('<PARAM NAME=movie VALUE="'+n+'"> <PARAM NAME=quality VALUE=high> <PARAM NAME=wmode VALUE=transparent>');
win1.document.write('<EMBED src="'+n+'" quality=high menu="false"  wmode=transparent bgcolor=#336699  WIDTH="'+w+'" HEIGHT="'+h+'" NAME="" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>');
win1.document.write('</OBJECT>');
win1.document.close(); 
}

function viewPic(url, title) {
    if (url == '') return false;
    width = '300px';
    height = '300px';
    window_top = (screen.height - height) / 2;
    window_left = (screen.width - width) / 2;
    win = window.open(url, 'image', 'width='+width+', height='+height+', top='+window_top+', left='+window_left+', toolbar=0, statusbar=0, location=0, scrollbars=no, resizable=0');
    win.document.open();
    win.document.write('<html><head><title>'+title+'</title>');
    win.document.write('<' + 'script language="Javascript"> ');
    win.document.write('function body_on_load() {document.getElementById("text").innerHTML = ""; document.getElementById("photo").style.visibility = "visible"; window.resizeTo((document.getElementById("photo").scrollWidth+10),(document.getElementById("photo").scrollHeight+29)); window.moveTo((screen.width-document.getElementById("photo").scrollWidth)/2, (screen.height-document.getElementById("photo").scrollHeight)/2); window.focus();}</'+'script>');
    win.document.write('</head><body leftmargin=0 topmargin=0 rightmargin=0 bottommargin=0 marginwidth=0 marginheight=0 onload="body_on_load()">');
    win.document.write('<span id="text"><br><center>Идет загрузка изображения...</center></span><a href="javascript:window.close();"><img id="photo" src="'+url+'" style="visibility: hidden;" border="0"></a>');
    win.document.write('</body></html>');
    win.document.close();    
}

function viewPicPrint(url, title) {
    if (url == '') return false;
    width = '400px';
    height = '400px';
    window_top = (screen.height - height) / 2;
    window_left = (screen.width - width) / 2;
    win = window.open(url, 'image', 'width='+width+', height='+height+', top='+window_top+', left='+window_left+', toolbar=0, statusbar=0, location=0, scrollbars=no, resizable=0');
    win.document.open();
    win.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=koi8-r"><title>'+title+'</title>');
    win.document.write('<' + 'script language="Javascript"> ');
    win.document.write('function body_on_load() {document.getElementById("text").innerHTML = ""; document.getElementById("photo").style.visibility = "visible"; window.resizeTo((document.getElementById("photo").scrollWidth+10),(document.getElementById("photo").scrollHeight+70)); window.moveTo((screen.width-document.getElementById("photo").scrollWidth)/2, (screen.height-document.getElementById("photo").scrollHeight)/2); window.focus();}</'+'script>');
    win.document.write('</head><body leftmargin=0 topmargin=0 rightmargin=0 bottommargin=0 marginwidth=0 marginheight=0 onload="body_on_load()">');
    win.document.write('<span id="text"><br><center>Идет загрузка изображения...</center></span><a href="javascript:window.close();"><img id="photo" src="'+url+'" style="visibility: hidden;" border="0"></a>');
    win.document.write('<style>@media screen { #lp { display:block; font-size: 12px; text-align: center; } #lp a { font-family: sans-serif; //font-family: arial cyr, arial, sans serif; color: #000; } #lp a:hover { color: #969696; } } @media print { #lp { display:none; }}</style><div id="lp" style="padding: 5px;"><a href="javascript:window.print();">Распечатать</a></div>');
    win.document.write('</body></html>');
    win.document.close();    
}

function viewURL(url, width, height, scroll) {
    if (url == '')   return false;
    if (width == null) width = 640;
    if (height == null) height = 480;

    if (scroll == null) scroll = 0;
    win = window.open(url, '', 'width='+width+', height='+height+', toolbar=0, statusbar=0, location=0, scrollbars='+scroll+', resizable=0');
    win.moveTo((screen.width-width)/2, (screen.height-height)/2);
}


function viewURLfull(url, width, height, scroll) {
    if (url == '')   return false;
    if (width == null) width = screen.width;
    if (height == null) height = screen.height;

    if (scroll == null) scroll = 1;
    win = window.open(url, '', 'width='+width+', height='+height+', toolbar=1, statusbar=1, location=1, scrollbars=yes, resizable=0, menubar=1, title=1');
    win.moveTo((screen.width-width)/2, (screen.height-height)/2);
}

function set_per_page () {
    if (oElement = document.getElementById('per_page')) {
        SetCookie('per_page', oElement.value);
        window.location.reload();
    }
}

function SetCookie(name, value) {
    var expiry = new Date();
        expiry.setTime(expiry.getTime() + 24 * 60 * 60 * 1000 * 10000);
        document.cookie = name + '=' + value + '; path=/; expires=' + expiry.toGMTString();
}
function on_change_form_topic( topic ){
    topic = $( 'topic' );
    if (!topic) return;
    var topic_option = topic.options[ topic.selectedIndex ];
    var additional_fields_group;
    var i;
    if ( additional_fields_group = topic_option.readAttribute('fields_group') ){
        var addf = $$('[addfields='+parseInt(additional_fields_group)+']');
        for(i=0;i<addf.length;i++){ addf[i].show(); }
    }
    addf = $$('[addfields!='+parseInt('0'+additional_fields_group)+']'); // if additional_fields_group, then will be [addfields!=0]
    for(i=0;i<addf.length;i++){ $(addf[i]).hide(); }

}
function send_form() {
    var failed  = "1px solid #e83b10"; // красное обрамление
    var name    = $('name');
    var phone   = $('phone');
    var email   = $('email');
    var topic   = $('topic');
    var comment = $('comment');
    var code    = $('user_image_kod');
    var current_menu = $('current_menu');
    var flag    = true;      
    var topic_option = topic.options[ topic.selectedIndex ];
    var validate_url = '/ajax/validate_form/';
    var validate_pars = "user_image_kod=" + code.value;
    var validate_ajax = new Ajax.Request( validate_url, {method: 'get', parameters: validate_pars,
        onComplete: function(transport) { 
            var  additional_fields_group;

            eval(transport.responseText);
            if (kod_valid == 0 ) {
                $('user_image_kod').style.border = failed;
                flag = false;
            } else {
                $('user_image_kod').style.border='';
            }


            // проверка введенных данных
            if ($F(name).replace(' ', '') == '') {
                name.style.border = failed;
                flag = false;
            } else {
                name.style.border = '';
            }

            if ($F(phone).replace(' ', '') == '') {
                phone.style.border = failed;
                flag = false;
            } else {
                phone.style.border = '';
            }

            if ($F(email).replace(' ', '') == '') {
                email.style.border = failed;
                flag = false;
            } else {
                email.style.border = '';
            }

            if ($F(comment).replace(' ', '') == '') {
                comment.style.border = failed;
                flag = false;
            } else {
                comment.style.border = '';
            }

            var addf_params = '';
            if ( additional_fields_group = topic_option.readAttribute('fields_group') ){
                var addf = $$('[addfields='+parseInt(additional_fields_group)+'] input');
                for(var i=0;i<addf.length;i++){ 
                    if ($F(addf[i]).replace(' ', '') == '') {
                        addf[i].style.border = failed;
                        flag = false;
                    } else {
                        addf[i].style.border = '';
                        addf_params += '&' + addf[i].readAttribute('name') + '=' + addf[i].value;
                    }
                }
            }

            if (flag) {
                var url = '/ajax/send_form/contact/';
                /**
                 * def@spider.ru
                 * добавил в параметры передавать код из капчи 
                 * далее в аякс обработчике ее обрабатывать
                 */
                var pars = "code=" + code.value + "&name=" + name.value + "&phone=" + phone.value + "&email=" + email.value + "&comment=" + comment.value + '&topic=' + topic.value + '&current_menu='+current_menu.value;
                if (addf_params ) pars += addf_params;


                var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars} );
                Element.hide('div_form_contact');
                        $('msg_send_form').style.visibility = 'visible';
                //Element.show('msg_send_form');
            }
        } 
    } );
}

var MainMenu = {
    create: function (element_id) {
        this.anchors = document.getElementById(element_id).getElementsByTagName("a");
        for(i = 0; i < this.anchors.length; i++) {
            this.anchors[i].onmouseover = this.on;
            this.anchors[i].onmouseout  = this.off;
        }
    },
    on: function () {
        this.parentNode.style.background="url(/all/" + this.parentNode.id + ".gif) top left no-repeat";
        MainMenu.setColor('#969696', this.id);
    },
    off: function () {
        this.parentNode.style.backgroundImage= "none";
        MainMenu.setColor('black', this.id);
    },
    setColor: function (color, cur_id) {
        for(i = 0; i < this.anchors.length; i++) {
            if (this.anchors[i].id != cur_id) { this.anchors[i].style.color = color; }
        }
    }
}

window.FF = 
    function(e, mes) {
        if (document.getElementById('hide').style.display=='none') {
            document.getElementById('hide').style.display='inline'
            document.getElementById('text').innerHTML=mes;
        }
        e = e || window.event;
        if (navigator.userAgent.indexOf('Opera')>=0) {
            document.getElementById('hide').style.left = e.clientX * 1 + document.documentElement.scrollLeft -1
            document.getElementById('hide').style.top =  e.clientY * 1 +  document.documentElement.scrollTop-document.getElementById('hide').clientHeight-5
        } else {
            document.getElementById('hide').style.left = e.clientX * 1 + document.body.scrollLeft + document.documentElement.scrollLeft -1
            document.getElementById('hide').style.top =  e.clientY * 1 + document.body.scrollTop +  document.documentElement.scrollTop-document.getElementById('hide').clientHeight-5
        }
    }

