/* 
        (c) 2007, Mediaweb Studio 
*/

function get_browser()
{
var bver=null;
if(document.layers)
{bver='nn4';
}
else if(document.all)
{
if(window.opera)
        {bver='opera';
        }
else
        {bver='ie4';
        }
}
else if(document.getElementById)
{
if(navigator.userAgent.indexOf('gecko')>-1)
        {bver='mozilla';
        }
else
        {bver='nn6';
        }
}
if((window.opera)&&((navigator.appVersion.indexOf('MSIE 5.0')>-1)||(parseInt(navigator.appVersion)==6)))
{
bver='opera6';
}
return bver;
}

function replace_tags(STR,STR1,STR2)
{
var rexp,S;
S=STR;
rexp=new RegExp(STR1,"gi");
S=S.replace(rexp,STR2);
return S;
}

var BROWSER_ID = get_browser();

function preloadImg(file) {
        img = new Image();
        img.src = file;
}

function change_image(elname, srcname) {
if (srcname=='1') {
  elname.src=replace_tags(elname.src,'\.gif','_over.gif');
}
else {
  elname.src=replace_tags(elname.src,'_over.gif','\.gif');
}
}

function NewWindow(w,v,s,d)
{
eval("window.open('"+v+"','"+w+"','height="+s+",width="+d+",status=no,location=no,toolbar=no,directories=no,menubar=no');");
}

function NewWindow2(w,v,s,d)
{
eval("window.open('"+v+"','"+w+"','height="+s+",width="+d+",status=no,location=no,toolbar=no,directories=no,menubar=yes');");
}
function NewWindow3(w,v,s,d)
{
eval("window.open('"+v+"','"+w+"','height="+s+",width="+d+",status=no,location=no,toolbar=no,directories=yes,menubar=yes');");
}

function CheckEmailFormat( email )
{
        var s = '[A-Za-z0-9][-\\w]*(\\.[A-Za-z0-9][-\\w]*)*'
        var re = new RegExp( '^'+s+'@'+s+'\\.[a-zA-Z]{2,4}$')
        email = email.replace( new RegExp('/\(.*?\)/'), '' )
        return re.test(email)
}


function get_document_object(ElName)
{
if((ElName=="")||(ElName==null))
        {return null;
        }
if(ElName.indexOf('-')>-1)
        {return null;
        }
var El;
if((BROWSER_ID=='ie4')||(BROWSER_ID=='opera'))
{
El=eval("document.all."+ElName);
}
else if((BROWSER_ID=='mozilla')||(BROWSER_ID=='nn6'))
{
El=document.getElementById(ElName);
}
else if(BROWSER_ID=='opera6')
{
if(OPERA_AS_IE==false)
{
El=document.getElementById(ElName);
}
else
{
El=eval("document.all."+ElName);
}
}
return El;
}

function show_hide(id){
elem = document.getElementById(id);
if (elem.style.display=='none'){
elem.style.display='block';
}else{
elem.style.display='none';
}
}

//cookies

// Извлекаем "Плюшку"
function extractCookieValue(val) {
    if ((endOfCookie = document.cookie.indexOf(";", val)) == -1) {
        endOfCookie = document.cookie.length;
    }
    var s = unescape(document.cookie.substring(val, endOfCookie));
    if (s == '') {
        s = '0';
    }
    return s;  
}

// Читаем "Плюшку"
function ReadCookie(cookiename) {
    var numOfCookies = document.cookie.length;
    var nameOfCookie = cookiename + '=';
    var cookieLen = nameOfCookie.length;
    var x = 0 ;
    while (x <= numOfCookies) {
        var y = (x + cookieLen);
        if (document.cookie.substring(x, y) == nameOfCookie) { 
            return (extractCookieValue(y)); 
        }  
        x = document.cookie.indexOf(' ', x) + 1;
        if (x == 0) { 
            break;
        }  
    }
    return '0';
}

// Удаляем "Плюшку"
function  DeleteCookie(name) {
    CreateCookie(name, '', -1);
}


// Создем "Плюшку"
function CreateCookie(name, value, expiredays) {
var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + '=' + value + '; path=/; expires=' + todayDate.toGMTString() + ';';
}

//bookmarks
function bookmarksite(title){
var host = window.location.host;
if (window.sidebar) // firefox
        window.sidebar.addPanel(title, 'http://'+host, "");
else if(window.opera && window.print){ // opera
        var elem = document.createElement('a');
        elem.setAttribute('href','http://'+host);
        elem.setAttribute('title',title);
        elem.setAttribute('rel','sidebar');
        elem.click();
}
else if(document.all)// ie
        window.external.AddFavorite('http://'+host, title);
}


function mgal_switch_image(POS)
{
var imobj=get_document_object("mgal_cbimage");
var imlabel=get_document_object("mgal_cblabel");
var bklink=get_document_object("mgal_bklink");
var fwlink=get_document_object("mgal_fwlink");
T_MGAL_POS=POS;
imobj.src=T_MGAL_BIG_IMAGE[POS];
if(imlabel)
{
imlabel.innerHTML=T_MGAL_IMAGE_LABEL[POS];
}
if(bklink)
{
if(POS<1)
        {bklink.style.display='none';
        }
else
        {bklink.style.display='inline';
        }
}
if(fwlink)
{
if(POS>=(T_MGAL_BIG_IMAGE.length-1))
        {fwlink.style.display='none';
        }
else
        {fwlink.style.display='inline';
        }
}
if((T_MGAL_IMAGE_WIDTH[POS]>MGAL_CBIMAGE_WIDTH)||(T_MGAL_IMAGE_HEIGHT[POS]>MGAL_CBIMAGE_HEIGHT))
{
imobj.style.cursor='pointer';
imobj.onclick=function() {NewWindow('mgal_cbimage_window','/bigimg.cgi?id='+T_MGAL_IMAGE_ID[POS],T_MGAL_IMAGE_HEIGHT[POS],T_MGAL_IMAGE_WIDTH[POS]);};
}
else
{
imobj.style.cursor='none';
imobj.onclick=null;
}
}

function mgal_back()
{
mgal_switch_image(T_MGAL_POS-1);
}

function mgal_forward()
{
mgal_switch_image(T_MGAL_POS+1);
}


var now = new Date();
var year = now.getFullYear();


