var global_octet_current = 1;



function getObjectByID( id, o, level )
{
	var c, el, els, f, m, n;

	if ( !level )
	{
		level = 0;
	}; //if

	if ( level > 10 )
	{
		return null;
	}; //if

	if ( !o )
	{
		o = document;
	}; //if
	if ( o.getElementById )
	{
		el = o.getElementById( id );
	} else 
	if ( o.layers )
	{
		c = o.layers;
	} else
	if ( o.all )
	{
		el = o.all[id];
	}; //if
	if ( el )
	{
		return el;
	}; //if
	if ( o.id == id || o.name == id )
	{
		return o;
	}; //if
	if ( o.childNodes )
	{
		c = o.childNodes;
	}; //if
	if ( c )
	{
		for ( n = 0; n < c.length; n++ )
		{
			el = getObjectByID( id, c[n], level + 1 );
			if ( el )
			{
				return el;
			}; //if
		}; //for
	}; //if
	f = o.forms;
	if ( f )
	{
		for ( n = 0; n < f.length; n++ )
		{
			els = f[n].elements;
			for ( m = 0; m < els.length; m++ )
			{
				el = getObjectByID( id, els[n], level + 1  );
				if ( el )
				{
					return el;
				}; //if
			}; //for
		}; //for
	}; //if
	return null;
}; //func

function setInnerHtml( id, text )
{
	obj = getObjectByID( id );
	if ( obj != null )
	{
		obj.innerHTML = text;
	}; //if
}; //func

function copyInnerHtml( sid, did )
{
	sobj = getObjectByID( sid );
	if ( sobj != null )
	{
		setInnerHtml( did, sobj.innerHTML );
	}; //if
}; //func

function setClassName( id, className, clean )
{
	obj = getObjectByID( id );
	if ( obj != null )
	{
		if ( clean )
		{
			setInnerHtml( id, '' );
		}; //if
		if ( obj.className != "undefined" )
		{
			obj.className = className;
		}; //if
	}; //if
}; //func

function getClassName( id )
{
	obj = getObjectByID( id );
	if ( obj != null )
	{
		if ( obj.className )
		{
			return obj.className;
		}; //if
	}; //if
}; //func

function set1of2ClassName( id, class1, class2 )
{
	if ( getClassName( id ) != class1 )
	{
		setClassName( id, class1 );
	} else
	{
		setClassName( id, class2 );
	}; //func
}; //func

function showObjectSlide( id, width, height )
{
	obj = getObjectByID( id );
	if ( ( obj ) && ( obj.style ) )
	{
		var _height = obj.style.height.substr( 0, obj.style.height.length - 2 );
		var _width = obj.style.width.substr( 0, obj.style.width.length - 2 );
		var _continue = false;

		_height = _height * 1 + 10;
		_width = _width * 1 + 10;

		obj.style.top = 0;		

		if ( height )
		{
			
			obj.style.height = _height;
			if ( _height < height )
			{
				_continue = true;
			}; //if
		}; //if

		if ( width )
		{
			obj.style.width = _width;
			if ( _width < width )
			{
				_continue = true;
			}; //if
		}; //if

		if ( _continue )
		{
			window.setTimeout( "showObjectSlide( '" + id + "', " + width + ", " + height + " )", 20 );
		}; //if
	}; //if
}; //func

function showObject( id, className, width, height )
{
	if ( !className )
	{
		className = "visible";
	}; //if

	obj = getObjectByID( id );
	if ( ( obj ) && ( obj.className ) )
	{
		obj.className = className;

		if ( ( height ) || ( width ) )
		{
			if ( height )
			{
				if ( obj.style )
				{	
					obj.style.height = "0";
					obj.style.top = -10;
				}; //if
			}; //if

			if ( width )
			{
				if ( obj.style )
				{	
					obj.style.width = "0";
					obj.style.top = -10;
				}; //if
			}; //if

			window.setTimeout( "showObjectSlide( '" + id + "', " + width + ", " + height + " )", 20 );
		}; //if
	}; //if
}; //func

function hideObject( id, className )
{
	if ( !className )
	{
		className = "hidden";
	}; //if
	obj = getObjectByID( id );
	if ( ( obj ) && ( obj.className ) )
	{
		obj.className = className;
	}; //if
}; //func

function getCheckedValue( obj )
{
	if ( !obj )
	{
		return "";
	}; //if

	var radioLength = obj.length;

	if ( radioLength == undefined )
	{
		if ( obj.checked )
		{
			return obj.value;
		} else
		{
			return "";
		}; //if
	}; //if

	for ( var i = 0; i < radioLength; i++ )
	{
		if ( obj[i].checked )
		{
			return obj[i].value;
		}; //if
	}; //for

	return "";
}; //func


function ucode_check( f, _msg_id, _process_id, _container_id, _template )
{
	var ucode = "";
	var phone = "";

	ucode = f.ucode.value;
	phone = f.phone.value;

	//
	// Поиск по ИТ-номеру
	//
	if ( f.type.value == "0" )
	{
		phone = "";
	} else
	//
	// Поиск по номеру телефона
	//
	if ( f.type.value == "1" )
	{
		ucode = "00000-00000-00000-00000";
	}; //if


	if ( ucode == "00000-00000-00000-00000" )
	{
		ucode = "";
	}; //if


	//
	// Если поиск по ИТ-номеру - проверяем задан ли он
	//
	if (
		( f.type.value == "0" ) &&
		(
			( !ucode ) ||
			( ucode.length == 0 )
		)
	)
	{
		if ( LANG_CODE == "en" )
		{
			alert( "No IT-number specified!" );
		} else
		{
			alert( "ИТ-номер не указан!" );
		}; //if
		return;
	}; //if


	if (
		( f.type.value == "1" ) &&
		(
			( !phone ) ||
			( phone.length < 10 )
		)
	)
	{
		if ( LANG_CODE == "en" )
		{
			alert( "No phone number specified!\nPhone number must be in international format." );
		} else
		{
			alert( "Номер телефона не указан!\nНомер телефона должен быть указан в международном формате." );
		}; //if
		return;
	}; //if


	if (
		( f.type.value == "1" ) &&
		(
			( !f.email.value ) ||
			( f.email.value.length == 0 )
		)
	)
	{
		if ( LANG_CODE == "en" )
		{
			alert( "E-mail field is incorrect!" );
		} else
		{
			alert( "Адрес электронной почты заполнено неправильно!" );
		}; //if
		return;
	}; //if

	//
	// В каком режиме запрашивать данные у сервера
	//
	if ( f.demo.checked )
	{
		demo = 1;
	} else
	{
		demo = 0;
	}; //if

	_ajax( _process_id );

	xajax_ajax_get_ucode_info( _msg_id, _process_id, _container_id, ucode, phone, f.email.value, demo, _template );

	return;
}; //func

function _ajax( id )
{
	if ( LANG_CODE == "en" )
	{
		setInnerHtml( id, "data loading...<br/><img src='/img/i-transfer/it-loading.gif' alt='Send/receive data...' border='0' />" );
	} else
	{
		setInnerHtml( id, "данные загружаются...<br/><img src='/img/i-transfer/it-loading.gif' alt='Получение/отправка данных...' border='0' />" );
	}; //if
}; //func

function onBodyLoad()
{
	var ph_title = "";
	if ( LANG_CODE == "en" )
	{
		ph_title = "enter query";
	} else
	{
		ph_title = "введите запрос";
	}; //if
	var ph = new InputPlaceholder( getObjectByID('SearchField'), ph_title, '', 'emptySearch' );
}; //func

function addEvent( obj, evType, fn )
{
	if ( obj.addEventListener )
	{
		obj.addEventListener( evType, fn, false );
		return true;
	} else
	if ( obj.attachEvent )
	{
		var r = obj.attachEvent( "on" + evType, fn );
		return r;
	} else
	{
		return false;
	}; //if
}; //func

function checkEmail( frm, elname )
{
	var email = frm.elements[elname].value;
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if ( !filter.test( email ) )
	{
		if ( LANG_CODE == "en" )
		{
			alert( 'Enter correct e-mail!' );
		} else
		{
			alert( 'Введите корректный адрес электронной почты!' );
		}; //if
		return false;
	} else
	{
		frm.submit();
	}; //if
}; //func
