window.onresize=resize;

function check_email(email)
        {
re = /^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;
return re.test(email);
        }


function reload_img()
	{
MyImage=document.getElementById("auth_img");
MyImage.style.width=16;
MyImage.style.height=16;
MyImage.src=load_image;
setTimeout("load_new_auth_img()",1000);
	}


function load_new_auth_img()
	{
k1=Math.random();
k2=Math.random();
k=k1+''+k2;
MyImage=document.getElementById("auth_img");
MyImage.src=home+"/auth.image?"+k;
MyImage.style.width=50;
MyImage.style.height=25;
	}


function check_contacts()
	{
var MyMail=document.getElementById("email").value;
var MyMess=document.getElementById("descr").value;
var MyCode=document.getElementById("img_code").value;


var error=0;
if(MyMail.length>2 && !check_email(MyMail) && error==0)	{alert('Наверно Вы опечатались, когда вписывали свой e-mail'); error=1;}
if(MyMess.length<2 && error==0)				{alert('К сожалению, наш штатный телепат сейчас в отпуске, поэтому придется изложить свои мысли в письменной форме.'); error=1;}
if(MyCode.length<1 && error==0)				{alert('Вы забыли про код на картинке'); error=1;}

if(error==0)
	{
show_c_div('load_contacts');
document.getElementById("cnts_form").submit();
	}
	}




function show_c_div(id)
	{
document.getElementById("contact_form").style.display='none';
document.getElementById("load_contacts").style.display='none';
document.getElementById("error_contacts").style.display='none';
document.getElementById("ok_contacts").style.display='none';
document.getElementById(id).style.display=set_display_block();
	}


function write_error(txt)
	{
document.getElementById("error_txt").innerHTML=txt;
show_c_div("error_contacts");
	}




function get_positions(obj)
	{
var x = y = 0; 
while(obj)
	{
x += obj.offsetLeft; 
y += obj.offsetTop; 
obj = obj.offsetParent; 
	} 
return {x:x, y:y};
	} 





function set_display_block()
	{
if(browser=="opera" || browser=="mozilla")
	{
return "table-row";
	}else{
return "block";
	}
	}





var CUR_TOUT = null;
function good_info(action,id)
	{

var mydescr=document.getElementById('info_'+id);




if(action=='show')
	{
funcking_hide(0);
var width=240;
var myobj=document.getElementById('good_'+id);

show_now=id;
need2hide=false;

//// Определяем координаты дива
var top=get_positions(myobj).y;
var left=get_positions(myobj).x-width+1;


//// Определяем размеры дива
var dWidth=myobj.scrollWidth;
var dHeight=myobj.scrollHeight;


mydescr.style.top=top;
mydescr.style.left=left;
mydescr.style.display=set_display_block();

	}else{
need2hide=true;
if(CUR_TOUT) clearTimeout(CUR_TOUT);
CUR_TOUT = setTimeout("funcking_hide('"+id+"');",100);
	}
	}




function funcking_hide(id)
	{
if(show_now && need2hide==true)
	{
var mydescr=document.getElementById('info_'+show_now);
mydescr.style.display='none';
	}
	}












function help(id)
	{
answer=document.getElementById(id);
var check=answer.style.display;
if(check=="block")
	{
answer.style.display='none';
	}else{
answer.style.display='block';
	}
	}






function press_key()
	{
t=event.keyCode;
if(t==27){hide_cart();}
	}












function hide_cart()
	{
MyForm=top.document.getElementById("cart");
MyForm.style.display='none';
self.location='cart.jw';
grey('hide');
	}







function cart(id,fast)
	{
if(fast==1)
	{
include_cart.location='cart.jw?id='+id+'&fast';
	}else{
include_cart.location='cart.jw?id='+id;
	}
grey('show');
cart_position();
	}







function cart_position()
	{
box_width=273;
box_height=141;
width=top.document.body.clientWidth;
height=top.document.body.clientHeight;
y=top.document.body.scrollTop;
y=height/2+y-(box_height/2);
x=width/2-((box_height/2)+10);
MyForm=top.document.getElementById("cart");
MyForm.style.top=y;
MyForm.style.left=x;
MyForm.style.display=set_display_block();
	}





function resize()
	{
GREY=top.document.getElementById("cart");
var t=GREY.style.display;


if(t!=="none")
	{
width=top.document.body.clientWidth;
height=top.document.body.clientHeight;
scroll_left=top.document.body.scrollLeft;
scroll_top=top.document.body.scrollTop;
SPACER=top.document.getElementById("grey_spacer");
SPACER.style.width=width+scroll_left;
SPACER.style.height=height+scroll_top;
cart_position();
	}
	}






function grey(action)
	{
////if(browser=="iexplorer" || browser=="iexplorer7")
	////{
if(action=="show")
	{
top.document.body.style.overflowX='hidden';
top.document.body.style.overflowY='hidden';
top.document.body.style.margin='0 17px 0 0';
width=top.document.body.clientWidth;
height=top.document.body.clientHeight;
scroll_top=top.document.body.scrollTop;
scroll_left=top.document.body.scrollLeft;
GREY=top.document.getElementById("grey");
GREY.style.display=set_display_block();
SPACER=top.document.getElementById("grey_spacer");
SPACER.style.width=width+scroll_left;
SPACER.style.height=height+scroll_top;
	}
if(action=="hide")
	{
top.document.body.style.overflowY='scroll';
top.document.body.style.overflowX='auto';
top.document.body.style.margin='0';
SPACER=top.document.getElementById("grey_spacer");
SPACER.style.width='0';
SPACER.style.height='0';
///SPACER.style.display='none';
	}
////	}
	}




























function news(id)
	{
ShortNews=document.getElementById('short_'+id);
FullNews=document.getElementById('full_'+id);
var check=ShortNews.style.display;
if(check=="block")
	{
ShortNews.style.display='none';
FullNews.style.display=set_display_block();
	}else{
FullNews.style.display='none';
ShortNews.style.display=set_display_block();
	}
	}









function long_load()
	{
setTimeout("load_page()",5000);
	}






function load_page()
	{
LOAD=document.getElementById("loading");
LOAD.style.display='none';
document.body.style.overflowY='auto';
document.body.style.overflowX='auto';
document.body.style.margin='0';
	}







function replace(id,what)
	{
insert_into=document.getElementById(id);
insert_into.innerHTML=what;
	}







function preload() 
	{
var d=document;
if(d.images)
	{
if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=preload.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}
	}
	}
function back() 
	{
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
function find(n, d) 
	{
var p,i,x;
if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
if(!(x=d[n])&&d.all) x=d.all[n];
for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n);
return x;
	}
function change()
	{
var i,j=0,x,a=change.arguments;
document.MM_sr=new Array;
for(i=0;i<(a.length-2);i+=3)
if ((x=find(a[i]))!=null)
	{
document.MM_sr[j++]=x;
if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
	}
	}












function show_page(inc_path,inc_width,inc_height,inc_scroll)
	{
if(browser=="iexplorer"){inc_width=parseInt(inc_width)+10;inc_height=parseInt(inc_height)+50;}
if(browser=="iexplorer" || browser=="iexplorer7")
	{
var sFeatures="dialogHeight: " + inc_height + "px; dialogWidth: " + inc_width + "px;edge:sunken;status:yes;scroll:"+inc_scroll;
window.showModalDialog(inc_path, "", sFeatures);
	}else{
window.open(inc_path,'newwin','top=0, left=0, menubar=0, toolbar=0, location=0, directories=0, status=0, scrollbars='+inc_scroll+', resizable=0, width='+inc_width+', height='+inc_height);
	}
	}














function number_format(a, b, c, d)
	{
a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
e = a + '';
f = e.split('.');
if(!f[0])				{f[0] = '0';	}
if(!f[1])				{f[1] = ''; 	}
if(f[1].length < b)			{g = f[1];
for (i=f[1].length + 1; i <= b; i++)	{g += '0';	}
					 f[1] = g;	}
if(d != '' && f[0].length > 3)
	{
h = f[0];
f[0] = '';
for(j = 3; j < h.length; j+=3)
	{
i = h.slice(h.length - j, h.length - j + 3);
f[0] = d + i +  f[0] + '';
	}
j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
f[0] = j + f[0];
	}
c = (b <= 0) ? '' : c;
return f[0] + c + f[1];
	}


