//Specify affected tags. Add or remove from list:
var tgs = new Array( 'td','select','input','div','a');

//Specify spectrum of different font sizes:
var szs = new Array( '10','11','12','13','14','15','16','17','18' );

var startSz = 2;

function ts( trgt,inc ) 
{
	if (!document.getElementById) 
		return;
		
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	
	if ( sz < 0 ) 
	{
		sz = 0;
	}
	
	if ( sz > 6 ) 
	{
		sz = 6;
	}
		
	startSz = sz;
	
	if ( !( cEl = d.getElementById( trgt ) ) ) 
	{
		cEl = d.getElementsByTagName( trgt )[ 0 ];
	}
		
	cEl.style.fontSize = szs[ sz ];
	
	for ( i = 0 ; i < tgs.length ; i++ ) 
	{
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) 
		{
			cTags[ j ].style.fontSize = szs[ sz ];
		}
	}
}

function MM_findObj(n, d) 
{ //v4.0
	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 show_hide(obj,action)
{
	obj=MM_findObj(obj);
	action=(action=='show')?"visible":"hidden";
	if(obj)
	{
		obj.style.visibility=action
	};
}

function show_hide_filial(action)
{
	obj=MM_findObj("layer_filialwahl");
	if(obj)
	{
		action=(action=='show')?"visible":"hidden";
		if(obj.style)
		{
			obj.style.visibility=action
		};
	}
}

function hide_all()
{
	for(var i=0;i<=7;i++)
	{
		show_hide("layer"+i,"hide");
	}
	show_hide_filial('show');
}

function change_image(obj,newsrc)
{
  obj=MM_findObj(obj);
  if(obj)
  {
	obj.src=newsrc
	};
}

var l = (screen.width - w) / 2;
var t = (screen.height - h) / 2;
var w = 700;
var h = 331;

function openConfiguredWin(url, params, w, h)
{
	var thisTemp = params.split(":");
	var thisYesNo = thisTemp[0];
	var thisZeroOne = thisTemp[1];
	//windows conf variables
	var winStatus = thisZeroOne;
	var winToolbar = thisYesNo;
	var winLocation = thisYesNo;
	var winScrollbars = thisZeroOne;
	var winResizable = thisYesNo;
	//to center window on screen
	var l = (screen.width - this.w) / 2;
	var t = (screen.height - this.h) / 2;
	l = 0;
	t = 0;
	var scrW = screen.width;
	var scrH = screen.height;

	var maxWidth = screen.width - 50;
	var maxHeight = screen.height - 50;
	var desirableWidth = w;
	var desirableHeight = h;
	var newWidth = (desirableWidth > maxWidth) ? maxWidth : desirableWidth;
	var newHeight = (desirableHeight > maxHeight) ? maxHeight : desirableHeight;
	if (desirableHeight > maxHeight)
	{
		var winScrollbars = "1";
	}
	
	if (desirableWidth > maxWidth)
	{
		var winScrollbars = "1";
	}
	
	if (desirableHeight > maxHeight)
	{
		var winResizable = "yes";
	}
	
	if (desirableWidth > maxWidth)
	{
		var winResizable = "yes";
	}

	var a = window.open( 	url, '', 'status='+ winStatus +', toolbar='+ 
							winToolbar +', location='+ winLocation +', scrollbars='+ 
							winScrollbars +', resizable='+ winResizable +', top='+ 
							t +',left='+ l +', height='+ newHeight +', width='+ newWidth );
}//end function openConfiguredWin(url, params, w, h)

function winop()
{
	windop=window.open("sestyle.php", "mywin", "height=200,width=486,left=100,top=30");
}

function hBack()
{
	history.back();
	return false;
}

function changeUnit()
{
	var info1 = document.getElementById("upd_info1");
	var info2 = document.getElementById("upd_info2");
	var unt  = document.getElementById("unit");
	var p = document.getElementById("pay");
	
	var rrate = document.getElementById("r_rate");
	var rpay = document.getElementById("r_pay");
			
	//switch (unt.value)
	switch (unt.options[unt.selectedIndex].value)
	{
		case "WMU":
		{
			info1.style.visibility = "hidden";
			info2.style.visibility = "hidden";
		}
		break;
		
		case "WMZ":
		{
			info1.style.visibility = "visible";
			info2.style.visibility = "visible";

			var wmzrate = document.getElementById('wmz_rate');
			
			rrate.value = wmzrate.value;
			rpay.value =  Math.round((wmzrate.value * p.value)*100)/100;
		}
		break;
		
		case "WMR":
		{
			info1.style.visibility = "visible";
			info2.style.visibility = "visible";

			var wmrrate = document.getElementById('wmr_rate');
			
			rrate.value = wmrrate.value;
			rpay.value =  Math.round((wmrrate.value * p.value)*100)/100;
		}
		break;
		
		case "WME":
		{
			info1.style.visibility = "visible";
			info2.style.visibility = "visible";

			var wmerate = document.getElementById('wme_rate');
			
			rrate.value = wmerate.value;
			rpay.value =  Math.round((wmerate.value * p.value)*100)/100;
		}
		break;
	}
}

function page_load()
{
	changeUnit();
}

var lines_per_page_temp = 0;

function changeRange(index)
{
	var __range = document.getElementById('_range');
	var __month = document.getElementById('_month');
	
	if (index == 2)
	{
		__month.style.visibility = "hidden";
		__month.disabled = "disabled";
		__range.style.visibility = "visible";
		__range.disabled = null;
		
		
		
		//var __pl = document.getElementById('_page_limit');
		var __pl = document.getElementById('page_limit');
		
		lines_per_page_temp = __pl.value;
		
		__pl.value = 0;
		
		
		
	}
	else if(index == 1)
	{
		__range.style.visibility = "hidden";
		__range.disabled = "disabled";
		__month.style.visibility = "visible";
		__month.disabled = null;
		
		//var __pl = document.getElementById('_page_limit');
		var __pl = document.getElementById('page_limit');
		
		lines_per_page_temp = __pl.value;
		
		__pl.value = 0;
	}
	else if(index == 0)
	{
		__month.style.visibility = "hidden";
		__month.disabled = "disabled";
		__range.style.visibility = "hidden";
		__range.disabled = "disabled";
		
		//var __pl = document.getElementById('_page_limit');
		var __pl = document.getElementById('page_limit');
		var _dpl = document.getElementById('defpl');
		
		if (lines_per_page_temp)
		{
			__pl.value = _dpl.value;
		}
		
	}
	
}


function calc_m3ks()
{
	var __rate = document.getElementById('coin_rate');
	var __pay_hrn = document.getElementById('l2pay');
	var __coins = document.getElementById('coins');
	
	__coins.value = parseInt(__pay_hrn.value/__rate.value);
}

function check_sms_msg(el, cid)
{
	if (el.value.length > 70)
	{
		el.value = el.value.substr(0, 70);
	}
	
	var counter = document.getElementById(cid);
	
	counter.value = 70 - el.value.length;
}

function chOrder(elm)
{
	var id = elm.value;
	
	location.href = "/orders/id."+id+".html";
}

function conf(id)
{
	return confirm("Вы уверены?");
}

function mhover(id, image)
{
    var elm = document.getElementById(id);
    
    elm.src = "/images/"+image;
}
