var ie=(document.all && document.all.item && !window.opera)?1:0;

function checkf() {
	a=checkf.arguments;
	form=a[0];
	noerror=true;
	for (i=1;i<a.length;i++) if (form[a[i]].value.length==0) noerror=false;
		if (!noerror) alert('Не заполены все требуемые поля!');
	return noerror;
}

function deleteMe(what, id){
	MM_findObj('make_do').value = 'delete';
	MM_findObj('make_what').value = what;
	MM_findObj('make_id').value = id;
	MM_findObj('make').submit();
}

function showMe(what, id)
{
	if (!what&&!id)
		for (key in data)
		{
			what = key;
			break;
		}	

	if (!id) {
		var stats = new Array;
		stats[0] = 'current';
		stats[1] = 'order';
		stats[2] = 'paid';
		stats[3] = 'accepted';
		stats[4] = 'canceled';
		for (elem in stats)
		{
			for (i = 1; i<4; i++)
			{
				if (stats[elem] == what){
					obj = MM_findObj('td_'+stats[elem]+'_'+i);
					if (obj) obj.style.borderBottom = '0px';
				}else {
					obj = MM_findObj('td_'+stats[elem]+'_'+i);
					if (obj) obj.style.borderBottom = '1px solid #333333';
				}
			}
				
		}
	}
	if (what == 'current') MM_findObj('make_order').style.display = 'block';
	else MM_findObj('make_order').style.display = 'none';

	is = 0;	
	for (key in data)
	{
		for (order in data[key])
		{
			if (!is) is = 1;
			MM_findObj('menu_'+key+'_'+order).style.display = 'none';
			MM_findObj(key+'_name_'+order).style.display = 'none';
			MM_findObj(key+'_sum_'+order).style.display = 'none';
			MM_findObj(key+'_price_'+order).style.display = 'none';
			MM_findObj(key+'_quantity_'+order).style.display = 'none';
			
			MM_findObj('tsum_'+order).style.display = 'none';

			if (what == key){
				MM_findObj('menu_'+key+'_'+order).style.display = 'block';
				if (order == id||!id){
					if (!id) id = order;
					MM_findObj('tsum_'+id).style.display = 'block';
					if (last_id!=id)
					for (j=0; j<2; j++)
					{
						obj = MM_findObj('td'+j+'_menu_'+key+'_'+order);
						if (obj) obj.style.backgroundColor = '#E3D0B0'
						obj = null;
						obj = MM_findObj('td'+j+'_menu_'+last_what+'_'+last_id);
						if (obj) obj.style.backgroundColor = '#FFFFFF';
						obj = null;
					}
					MM_findObj(key+'_name_'+order).style.display = 'block';
					MM_findObj(key+'_sum_'+order).style.display = 'block';
					MM_findObj(key+'_price_'+order).style.display = 'block';
					MM_findObj(key+'_quantity_'+order).style.display = 'block';
					last_what = key;
					last_id = order;
				}
			}
		}
	}
	if (!is) 
	{
		MM_findObj('cab_main').style.display = 'none';
		MM_findObj('cab_no_main').style.display = 'block';
	}
	return false;	
}

function MM_findObj(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 && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}
function ShowMail(user, domain1, domain2) {
	var email = user+'&#64;'+domain1+'&#46;'+domain2;
	if (ShowMail.arguments[3]) name = ShowMail.arguments[3];
	else name = email;
	document.writeln('<a href="mailto:'+email+'">'+name+'</a>');
}

function OpenPrint(link_name) {
	window.open("/view/"+link_name, "OpenPrint", "scrollbars=1, resizable=1, width=600, height=500").focus();
}

function changeHeight(){
	for (i=1; i<=top.frames['infoFrame'].imax; i++)
	{
		obj_menu = MM_findObj('td_'+i, top.frames['leftFrame'].document);
		obj = MM_findObj('td_'+i+'_1', top.frames['infoFrame'].document);
		if (obj_menu) obj_menu.height = 24;
		if (obj) obj.height = 24;
		if (obj&&obj_menu)
		{
			if (obj_menu.clientHeight > obj.clientHeight)
				obj.height = obj_menu.clientHeight;
			else obj_menu.height = obj.clientHeight;
		}
	}
}

function changeWith(elem1, elem2){
	var tmp = elem1.innerText;
	if (elem1.filters[0]) elem1.filters[0].Apply();
	if (elem2.filters[0]) elem2.filters[0].Apply();
	elem1.innerText = elem2.innerText;
	elem2.innerText = tmp;
	if (elem1.filters[0]) elem1.filters[0].Play();
	if (elem2.filters[0]) elem2.filters[0].Play();

}

function changeInfoRows(elem1, elem2){
	for (i=1; i<=top.frames['infoFrame'].jmax; i++)
	{
		obj1 = MM_findObj('info_'+elem1+'_'+i, top.frames['infoFrame'].document);
		obj2 = MM_findObj('info_'+elem2+'_'+i, top.frames['infoFrame'].document);
		if (obj1.filters[0]) obj1.filters[0].Apply();
		if (obj2.filters[0]) obj2.filters[0].Apply();
		tmp = obj1.innerText;
		obj1.innerText = obj2.innerText;
		obj2.innerText = tmp;
		if (obj1.filters[0]) obj1.filters[0].Play();
		if (obj2.filters[0]) obj2.filters[0].Play();
	}
	changeHeight();
}

function changeInfoCols(elem1, elem2){
	for (i=1; i<=top.frames['infoFrame'].imax; i++)
	{
		obj1 = MM_findObj('info_'+i+'_'+elem1, top.frames['infoFrame'].document);
		obj2 = MM_findObj('info_'+i+'_'+elem2, top.frames['infoFrame'].document);
		if (obj1.filters[1]) obj1.filters[1].Apply();
		if (obj2.filters[1]) obj2.filters[1].Apply();
		tmp = obj1.innerText;
		obj1.innerText = obj2.innerText;
		obj2.innerText = tmp;
		if (obj1.filters[1]) obj1.filters[1].Play();
		if (obj2.filters[1]) obj2.filters[1].Play();

	}
}

function getInfoData(){
	data = new Array();
	str = '';
	for (i=1; i<=top.frames['infoFrame'].imax; i++)
	{
		data[i] = new Array();
		for(j=1; j<=top.frames['infoFrame'].jmax; j++)
		{
			str = str + MM_findObj('info_'+i+'_'+j, top.frames['infoFrame'].document).innerText;
			if (j!=top.frames['infoFrame'].jmax) str = str+'<col>';
		}
		if (i!=top.frames['infoFrame'].imax) str = str+'<row>';
	}
	return str;
}

function show_div(id)
{
	if (!divs||print_id == id) return true;
	for (key in divs){
		Obj = MM_findObj(divs[key]);
		Obj.className = 'invisible';
		Obj2 = MM_findObj('a_'+divs[key]);
		Obj2.className = 'pmenu';
	}
	obj = MM_findObj(id);
	if (obj) {
		obj.className='visible'; 
		obj2 = MM_findObj('a_'+id);
		obj2.className = 'redlink';
		window.location = '#info';
		return false;
	}
	else return true;
}

function ShowDiv(hide_name_mask, unhide_name)
{
	for (i in document.all)
	{
		if (i == unhide_name) 
		{
			var obj = document.all[i];
			obj.style.display = 'inline';
			continue;
		}
		if (i.substring(0, hide_name_mask.length) == hide_name_mask)
        { 
			var obj = document.all[i];
			obj.style.display = 'none';
			continue;
	    }
	}
}

function SetStyle(name_mask, class_name)
{
	for (i in document.all)
		if (i.substring(0, name_mask.length) == name_mask)
        { 
			var obj = document.all[i];
			obj.className = class_name;
			continue;
	    }
	return false;		
}

function SetHiddenVar(variable,val) {
	var forma = document.forms['search'];
	forma.elements[variable].value = val;
	forma.submit();
	return false;
}

var options = Array();
function show_option(id){

 for(i in options) 
  {
 	document.all[i].style.display = 'none'; 
  }

 options[id] = 1;
 document.all[id].style.display = 'block';
 return false;
}

function openImage(image) {
	window.open("/popup.php?img="+image, "popupimage", "scrollbars=0, resizable=1, width=520, height=450").focus();
}
function rusoft() {
  window.open('http://www.rusoft.ru');
}
