﻿// JScript File
function hideddls(ddlnum,_visible)
{
    
    if (_visible==0)
        {
            

            if ( (ddlnum==2) && (document.getElementById("ddl2")!=null) )
            {
                if (document.getElementById("ddl3"))
                    document.getElementById("ddl3").style.clip="rect(0px 130px 20px 37px)";
                document.getElementById("ddl2").style.width="92px";
                
            }
                
            if ( (ddlnum==3) && (document.getElementById("ddl3")!=null) )
            {
                if (document.getElementById("ddl4"))
                    document.getElementById("ddl4").style.clip="rect(0px 135px 20px 64px)";
                    
                document.getElementById("ddl3").style.width="17px";
                
                if (document.getElementById("tbp1"))
                        document.getElementById("tbp1").style.display="none";
                
                if (document.getElementById("tbp2"))
                    {
                       document.getElementById("tbp2").style.clip="rect(0px 48px 20px 11px)";   
                       document.getElementById("tbp2").blur();
                    }
            }

            if ( ddlnum==4)
            {
                if (document.getElementById("ddl4"))
                    document.getElementById("ddl4").style.display="none";
                
                if (document.getElementById("tbp1"))
                        document.getElementById("tbp1").style.display="none";
                if (document.getElementById("tbp2"))
                       document.getElementById("tbp2").style.display="none";                      
            }

            
        }
    else
        {
            if ( (ddlnum==2) && (document.getElementById("ddl2")!=null)) 
            {   
                document.getElementById("ddl2").style.width="";
                if (document.getElementById("ddl3"))
                    document.getElementById("ddl3").style.clip="rect(0px 130px 20px 0px)";
            }
            if ( (ddlnum==3) && (document.getElementById("ddl3")!=null) )
            {
                 document.getElementById("ddl3").style.width="";
                 if (document.getElementById("ddl4"))
                    document.getElementById("ddl4").style.clip="rect(0px 135px 20px 0px)";
                    
                 if (document.getElementById("tbp1"))
                        document.getElementById("tbp1").style.display="inline";
                        
                 if (document.getElementById("tbp2"))
                       document.getElementById("tbp2").style.clip="rect(0px 48px 20px 0px)"; 
            }
            
            if (ddlnum==4)  
                {
                    if (document.getElementById("ddl4"))
                        document.getElementById("ddl4").style.display="inline";         
                    if (document.getElementById("tbp1"))
                        document.getElementById("tbp1").style.display="inline";
                    if (document.getElementById("tbp2"))
                       document.getElementById("tbp2").style.display="inline";      
                                       
                }
        }
}

function CheckForHTMLtags(obj)
{
    if (obj)
        {
            var rep = /[<>]/g;
            if (obj.value.match(rep))
                obj.value=(obj.value.replace(rep, ""));
        }
}

function check_for_number(obj)
{
  str=obj.value;
  
  // убираем из строки все симфолы, кроме цифр 
  var rep = /[^\d]/g;
  obj.value=(str.replace(rep, ""));


}

/*
    AJAX ;-)
*/

var xmlHttp;

function CreateXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function UserClickedOnAddToFavs() 
{
    try 
    {
	    CreateXMLHttpRequest();
	    xmlHttp.open("GET", "http://podarki.ru/addtofavlogger.aspx", true);
	    xmlHttp.send(null);
    }
    catch (ex){ }
}

/*
    AddToFavorits
*/
function addBookmarkForBrowser() 
{

    url = location.href;
    title = document.title;
    
    //Gecko
    if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) 
        window.sidebar.addPanel (title, url, "");
    //IE4+
    else if (typeof window.external == "object") 
        window.external.AddFavorite(url, title);
    //Opera7+
    else if (window.opera )
    {
        var a = document.createElement('a');
        if (!a) return false; //IF Opera 6
        
        a.href=url;
        a.title=title;
        a.rel="sidebar";
        a.click();
         
    }
    else
        {
	        alert('Для добавления в Избранное нажмите Ctrl+D');
        }
        
    //logging add-on
    UserClickedOnAddToFavs();        
}


function CheckSearchText(obj)
{
    if (document.getElementById(obj)) 
        if (!document.getElementById(obj).value) 
        { 

            document.getElementById(obj).style.border="1px solid red";
        }
        else
            document.getElementById(obj).style.border="1px solid black";
}

function CheckSearchText2(obj,borderError,borderOk)
{
    if (document.getElementById(obj)) 
        if (!document.getElementById(obj).value) 
        { 

            document.getElementById(obj).style.border=borderError;
            return false
        }
        else
        {
            document.getElementById(obj).style.border=borderOk;
            return true
        }
}


//обработчик нажатий клавиатуры
function __fun_KeyDown(iKeyCode, sFunc, e)
{
	if (e == null)
		e = window.event;

	if (e.keyCode == iKeyCode)
	{
		/*eval(unescape(sFunc));*/
		if (document.getElementById('to_blog')) 
		    document.getElementById('to_blog').value='';
		    
		document.getElementById(sFunc).click();
		return false;
	}
}

// плавное появление и изчезание панелей **************************************************************
var delay_show=5 // Время выполнения эффекта, появление.
var delay_hide=8 // Время выполнения эффекта, исчезновение.
/*----------------------------------------------------------------*/


var timer_show=new Array()
var timer_hide=new Array()


function show_div(i)
{
    document.getElementById(i).style.zIndex='10';
	clearInterval(timer_show[i])
	clearInterval(timer_hide[i])
	document.getElementById(i).style.visibility='visible';
	timer_show[i]=setTimeout("time_show('"+i+"')",delay_show)
}
	  
function hide_div(i)
{
    document.getElementById(i).style.zIndex='1';
	clearInterval(timer_hide[i])
	clearInterval(timer_show[i])
	timer_hide[i]=setTimeout("time_hide('"+i+"')",delay_hide)
}
	
	  
function time_show(i)
{
	

	var $i=0;
	if (!isNaN(parseFloat(document.getElementById(i).style.opacity)))
		{$i=parseFloat(document.getElementById(i).style.opacity);}
		
	$i=$i+0.5;
	document.getElementById(i).style.opacity=$i;
	
	if ($i>=1.0)
		{clearInterval(timer_show[i]);}
	else		
	timer_show[i]=setTimeout("time_show('"+i+"')",delay_show)

}

function time_hide(i)
{
	
	if   (document.getElementById(i).style.opacity>0) 
	{
		var $i=0;
		
		if (!isNaN(parseFloat(document.getElementById(i).style.opacity)))
			{$i=parseFloat(document.getElementById(i).style.opacity);}
		$i=$i-0.5;
		document.getElementById(i).style.opacity=$i;
	}
	
	if ($i<=0.0)
	{
		document.getElementById(i).style.opacity=0;
		document.getElementById(i).style.visibility='hidden';
		clearInterval(timer_hide[i]);		
	}
	else
		timer_hide[i]=setTimeout("time_hide('"+i+"')",delay_hide)
}
//-********************************************************************************

//задержка при и изчезании панелей

var delay_hide_2=10
var delay_show_2=1
var timer_hide_2=new Array()
var timer_show_2=new Array()


	  
function hide_div_2(i)
{
	clearInterval(timer_hide_2[i])
	timer_hide_2[i]=setTimeout("time_hide_2('"+i+"')",delay_hide_2)
}

function show_div_2(i)
{
	clearInterval(timer_show_2[i])
	timer_show_2[i]=setTimeout("time_show_2('"+i+"')",delay_show_2)
}
	
	  
function time_show_2(i)
{
	
    document.getElementById(i).style.visibility='visible';

}

function time_hide_2(i)
{
	
	document.getElementById(i).style.visibility='hidden';
}
//-********************************************************************************

function MakeVisible(obj)
{
    if (document.getElementById(obj)) 
        
        {
        
            document.getElementById(obj).style.visibility="visible";
            document.getElementById(obj).style.display="block";
        }
            

}
function MakeInVisible(obj)
{
    if (document.getElementById(obj)) 
        
        {
            document.getElementById(obj).style.visibility="hidden";
            document.getElementById(obj).style.display="none";
        }
            

}

//*********
// для кнопок через img  - подсветка на onmouseover
function hl_btn(i)
{
    i.style.backgroundPosition='bottom';
}

function un_hl_btn(i)
{
    i.style.backgroundPosition='top';
}

//**********
// для "добавить в блог"

//задержка при и изчезании панелей

var add_to_blog_delay=5

function atb_hide_div(div,inner_div)
{
    h_add=parseInt(document.getElementById(div).style.height.replace("px",""))/10;
    w_add=parseInt(document.getElementById(div).style.width.replace("px",""))/10;   
	setTimeout("atb_t_hide('"+div+"','"+inner_div+"','"+w_add+"','"+h_add+"'"+")",add_to_blog_delay);
}

function atb_show_div(div,inner_div,text_area, width, height)
{
    w_add=parseInt(width)/10;
    h_add=parseInt(height)/10;
    document.getElementById(div).style.height="0px";
    document.getElementById(div).style.width="0px";
	setTimeout("atb_t_show('"+div+"','"+text_area+"','"+inner_div+"','"+width+"','"+height+"','"+w_add+"','"+h_add+"'"+")",add_to_blog_delay);
}

function atb_t_show(div,inner_div,text_area, width, height,w_add,h_add)
{
    $cur_height=0;
    $cur_width=0;
    w_add=parseInt(w_add);
    h_add=parseInt(h_add);
    $cur_height=parseInt(document.getElementById(div).style.height.replace("px",""));
    $cur_width=parseInt(document.getElementById(div).style.width.replace("px",""));
    
    document.getElementById(div).style.visibility="visible";
    document.getElementById(div).style.display="block";    
    
    
    if (($cur_height<height) && ($cur_width<width))
        {
            $cur_height+=h_add;
            $cur_width+=w_add;
            document.getElementById(div).style.height=$cur_height+"px";
            document.getElementById(div).style.width=$cur_width+"px";
            
            setTimeout("atb_t_show('"+div+"','"+text_area+"','"+inner_div+"','"+width+"','"+height+"','"+w_add+"','"+h_add+"')",add_to_blog_delay);
            
        }

    if ($cur_height==height)       
    {
        /*document.getElementById(inner_div).style.visibility="visible";
        document.getElementById(inner_div).style.display="block";*/    
     
     
     
     
        try
        {
            document.getElementById(text_area).select();
        }
        catch(ex){}
        
    } 
}

function atb_t_hide(div,inner_div,w_add,h_add)
{
    $cur_height=0;
    $cur_width=0;
    w_add=parseInt(w_add);
    h_add=parseInt(h_add);
    $cur_height=parseInt(document.getElementById(div).style.height.replace("px",""));
    $cur_width=parseInt(document.getElementById(div).style.width.replace("px",""));
    
              
    /*document.getElementById(inner_div).style.visibility="hidden";
    document.getElementById(inner_div).style.display="none";   */ 
    
    if (($cur_height>0) && ($cur_width>0))
        {
            $cur_height-=h_add;
            $cur_width-=w_add;
            document.getElementById(div).style.height=$cur_height+"px";
            document.getElementById(div).style.width=$cur_width+"px";
            
            setTimeout("atb_t_hide('"+div+"','"+inner_div+"','"+w_add+"','"+h_add+"')",add_to_blog_delay);
            
        }
        else
        {
            
            document.getElementById(div).style.visibility="hidden";
            document.getElementById(div).style.display="none";    
        }
     
}

