var con = new Console();

function Tools(){};

Tools.prototype.el = function(id)
{
	if(id != null)
		return $("#"+id);
}

Tools.prototype.el = function(id)
{
	if(id != null)
		return $("#"+id);
}

Tools.prototype.elval = function (id)
{
	if(id != null)
		return $("#"+id).val();
}

Tools.prototype.debug = function()
{
	if(this.el('debug') != null)
		return this.el('debug');
	else
		return false;
}

Tools.prototype.urlb = function()
{
	if(this.debug())
	{
		if((arguments.legth - 1)%2)
		{
			con.printErr("Tools.url количество аргументов четное, использовать' +" +
					'эту функцию необходимо следующим образом: Tools.url(<URL>, par1, parvalue1, par2, parvalue2, ....)');
			return;
		}
	}
	
	var retunedURL = this.elval(arguments[0]); 
	
	if(arguments.length > 1)
	for(var i = 1; i < arguments.length; i+=2)
	{
		if(i == 1)
			retunedURL += "?";
		else
			retunedURL += "&";
		retunedURL += this.elval(arguments[i]) + "=" + arguments[i + 1];
	}
	return retunedURL;
}

Tools.prototype.checkNewFirmForm = function(id)
{
	var form = $('#'+id)[0];
	var isWrong;
	
	if(form.fbrand.value == "") {this.displayWrong(form.fbrand); isWrong = true};
	if(form.femail.value == "") {this.displayWrong(form.femail) ; isWrong = true};
	if(form.fname.value == "") {this.displayWrong(form.fname); isWrong = true};
	if(form.fphone.value == "") {this.displayWrong(form.fphone); isWrong = true};
	if(form.ftype.value == "") {this.displayWrong(form.ftype); isWrong = true};
	
	if(isWrong)
	{
		alert('Поля отмеченные красным обязательны к заполнению!');
	}
	else if($('#collector')[0].value == "") {alert('Выберите рубрику!'); isWrong = true}; 
	return !isWrong;
}

Tools.prototype.displayWrong = function(element)
{
	if(element != null)
	{
		element.style.border = '4px solid red';
		element.onclick = function()
		{
			element.style.border = '';
		}
	}
}
