﻿// Сюда вынесены функции реализация которых различается в разных браузерах



isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && document.readyState //Opera 7+
isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isNetscape4=document.layers //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*

var currentBrowser="IE";

if(isMozilla)
    currentBrowser="Mozilla";
    
if(isMSIE5)
    currentBrowser="IE";


//
// Установить размер контрола
//
function SetSize(control, w, h)
{
   //Под мозилу
   if(currentBrowser=="Mozilla")
   {
       control.style.width=w+"px";
       control.style.height=h+"px";
       return;
   }
   
   //
   control.style.width=w;
   control.style.height=h;
}



//
// Установить ширину контрола
//
function SetWidth(control, w)
{
   //Под мозилу
   if(currentBrowser=="Mozilla")
   {
       control.style.width=w+"px";
       return;
   }
   
   //
   control.style.width=w;
}

//
// Установить высоту контрола
//
function SetHeight(control, h)
{
   //Под мозилу
   if(currentBrowser=="Mozilla")
   {
       control.style.height=h+"px";
       return;
   }
   
   //
   control.style.height=h;
}

//
// Установить позицию контрола 
//
function SetPosition(control, x, y)
{
   //Под мозилу
   if(currentBrowser=="Mozilla")
   {
       control.style.left=x+"px";
       control.style.top=y+"px";
       return;
   }
   
   //
   control.style.left=x;
   control.style.top=y;
}

//
// Установить позицию контрола  по X
//
function SetPositionX(control, x)
{
   //Под мозилу
   if(currentBrowser=="Mozilla")
   {
       control.style.left=x+"px";
       return;
   }
   
   //
   control.style.left=x;
}

//
// Установить позицию контрола  по Y
//
function SetPositionY(control, y)
{
   //Под мозилу
   if(currentBrowser=="Mozilla")
   {
       control.style.top=y+"px";
       return;
   }
   
   //
   control.style.top=y;
}

 //Получить видимость объекта в BOOLEAN формате
    function GetVisible(element)
    {
        var vis=element.style.display;
        
        if(vis==='none')
            return false;
        else
            return true;
    }
    
    //Спрятать/Показать элемент
    function SetVisible(element, show)
    {
        var vis='none';
        if (show)
        {
            vis='block';
        }
        if(element != null)
        {
            element.style.display=vis;
        }
    }
    
    
    //
    //
    //
    function getCookie( name )
    {
	    var start = document.cookie.indexOf( name + '=' );
	    var len = start + name.length + 1;
	    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	    {
		    return null;
	    }
	    if ( start == -1 )
	        return null;
	    var end = document.cookie.indexOf( ';', len );
	    if ( end == -1 ) end = document.cookie.length;
	        return unescape( document.cookie.substring( len, end ) );
    }
	
	//
	//
	//
    function setCookie( name, value, expires, path, domain, secure )
    {
	    var today = new Date();
	    today.setTime( today.getTime());
	    if ( expires )
	    {
		    expires = expires * 1000 * 60 * 60 * 24;
	    }
	    var expires_date = new Date( today.getTime() + (expires) );
	    document.cookie = name+'='+escape( value ) +( ( expires ) ? ';expires='+
	    expires_date.toGMTString() : '' ) +
//expires.toGMTString()
		( ( path ) ? ';path=' + path : '' ) +
		( ( domain ) ? ';domain=' + domain : '' ) +
		( ( secure ) ? ';secure' : '' );
    }
	
	//
	//
	//
    function deleteCookie( name, path, domain )
    {
	    if ( getCookie( name ) ) document.cookie = name + '=' +
			( ( path ) ? ';path=' + path : '') +
			( ( domain ) ? ';domain=' + domain : '' ) +
			';expires=Thu, 01-Jan-1970 00:00:01 GMT';
    }
    
        function get_ww() 
{var frameWidth=800; 
if (self.innerWidth) 
    frameWidth = self.innerWidth; 
else if (document.documentElement && document.documentElement.clientWidth) 
    frameWidth = document.documentElement.clientWidth; 
else if (document.body) 
    frameWidth = document.body.clientWidth; 
return frameWidth; 
} 
function get_wh() 
{var frameHeight=640; 
if (self.innerHeight) 
    frameHeight = self.innerHeight; 
else if (document.documentElement && document.documentElement.clientHeight) 
    frameHeight = document.documentElement.clientHeight; 
else if (document.body) 
    frameHeight = document.body.clientHeight; 
return frameHeight;
}

//
// Проверка числа
//
function CheckValidNumber(control, message) {


    var error = false;
    
        if(control.value=="")
            error=true;
    
        if(!error)
        {
            var number = parseFloat(control.value.replace(',', '.'));
            if (number == 0 || isNaN(number))
                error=true;
        }
                    
    
        if(error)
        {
            MessageBox('Confirmation', message, false, null);
            control.focus()
            return false;
        }
        
        return true;
    
}


