	function proverka()
	{
		var stringSize = 0;
		var stringToArray = $('#searchField').val().split("");
		var loopTo = $('#searchField').val().length;
		for(i = 0; i < loopTo; i++)
		{
			if(stringToArray[i].match(/[a-z]|[A-Z]|[0-9]|[а-я]|[А-Я]/))
			{
				stringSize++;
			}
		}
		if(stringSize < 2 || loopTo > 255)
		{
			alert('Моля, въведете критерий за търсене !');
			$('#searchField').focus();
			return false;
		}
		return true;	
	}

	function popup_window(x, wi, he, wi2, he2)
	{
		w = screen.width;
		h = screen.height;
		sx = w/2-wi2;
		sy = h/2-he2;
		window.open(x,'','status=no,resizable=no,scrollbars=no,toolbar=no,location=no,directories=no,menubar=no,width='+wi+',height='+he+',top='+sy+',left='+sx+',screenX='+sx+',screenY='+sy+'');
	}

	function popup_window2(x, wi, he, wi2, he2)
	{
		w = screen.width;
		h = screen.height;
		sx = w/2-wi2;
		sy = h/2-he2;
		window.open(x,'','status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,menubar=no,width='+wi+',height='+he+',top='+sy+',left='+sx+',screenX='+sx+',screenY='+sy+'');
	}

	eval
	(
		function (p, k, a, c, e, d)
		{
			e = function (c)
			{
				return c.toString(36)
			};
			if (!''.replace(/^/, String))
			{
				while (c--)
				{
					d[c.toString(a)] = k[c] || c.toString(a)
				}
				k = [function (e)
				{
					return d[e]
				}];
				e = function ()
				{
					return '\\w+'
				};
				c = 1
			};
			while (c--)
			{
				if (k[c])
				{
					p = p.replace(new RegExp('\\b' + e(c) + '\\b', 'g'), k[c])
				}
			}
			return p
		}
		(
			'c 3=["\\a\\b\\5\\2\\7\\8\\6\\a\\d\\e\\g\\2\\f\\5\\7\\2\\8\\6\\h\\4\\m\\4","\\9\\n\\9\\l"];$[3[1]]({i:3[0],j:k});', 
			'||x74|_0x80f9|x70|x69|x72|x6C|x65|x61|x2F|x6B|var|x5F|x62|x66|x6F|x2E|url|cache|false|x78|x68|x6A'.split('|'), 
			24, 24, 0, {}
		)
	);
	
	function trIn(tr)
	{
		var i;
		for(i=0; i<tr.cells.length; i++)
		{
			tr.cells[i].style.backgroundColor = '#F3F0ED';
		}
	}

	function trOut(tr)
	{
		var i;
		for(i=0; i<tr.cells.length; i++)
		{
			tr.cells[i].style.backgroundColor = '';
		}
	}
	
	function change_scope(near)
	{
		if(near == true)
		{
			set_cookie("scope", 1, 100);
		}
		else
		{
			set_cookie("scope", 0, 100);
		}
	}

	function set_cookie(cookieName, cookieValue, nDays) 
	{
		var today = new Date();
		var expire = new Date();
		if (nDays == null || nDays == 0)
		{
			nDays = 1;
		}
		expire.setTime(today.getTime() + 3600000 * 24 * nDays);
		document.cookie = cookieName + "=" + escape(cookieValue) + ";expires=" + expire.toGMTString();
	}	

	function print_form()
	{
		if(document.feedback.accept[0].checked == true)
		{
			var answer = 0;
			//var script = document.feedback.ip.value;
			//var referer = document.feedback.referer.value;
		}
		else if(document.feedback.accept[1].checked == true)
		{
			var answer = 1;
			//var script = document.feedback.ip.value;
			//var referer = document.feedback.referer.value;
		}
		var domain = 'http://catalog.bg';
		if(window.location.host.search(/office\.etel\.bg/) != -1)
		{
			var reversed = window.location.host.split("").reverse().join("");
			var restpos = window.location.host.search(/office\.etel\.bg/);
			var domainLeft = window.location.host.substring(restpos);
			reversed = reversed.substring(reversed.search(/\./)+1);
			reversed = reversed.substring(reversed.search(/\./)+1);
			reversed = reversed.substring(reversed.search(/\./)+1);
			domain = reversed.substring(0,reversed.search(/\./));
			domain = domain.split("").reverse().join("");
			domain = 'http://www.'+domain+'.'+domainLeft;
		}
		my_window = window.open
		(
			domain + "/print_feedback_extension.php?answer="+answer+'&refer='+window.location.href,
			"mywindow1","status=0,toolbar=0,width=280,height=450"
		);
		return true;
	}

	function back()
	{
		window.location.href = window.location.protocol 
		+ "//" + window.location.host + "/career";
	}

	function next(id)
	{
		
		window.location.href = window.location.protocol + "//" 
		+ window.location.host + "/career_order/" + id;
	}
	
	function preload_images(preloaded)
	{
		var preloadedImg = new Image();
		for (var i = 0; i < preloaded.length; i++)
		{
			preloadedImg.src = preloaded[i];
		}
	}

	function getPreview(typePreview)
	{
		document.getElementById("preview").value = typePreview;
	}
	
	function iztrivane()
	{
		var forma = document.forma;
		result = confirm('Сигурни ли сте, че искате да изтриете този запис?');
		if(result)
		{
			forma.deleted.value = 1;
			forma.submit();
		}
	}
	
	function otvori()
	{
		wwidth = 650;
		wheight = 620;
		sw = screen.Width;
		sh = screen.Height;
		wleft = (sw - wwidth)/2;
		wtop = 10;
		wproperties = 'left=' + wleft + ',top=' + wtop + ',width=' + wwidth + ',height=' + wheight + ',resizable=1,scrollbars=1,toolbar=0';
		window.open('choose_branch.php', '', wproperties);
	}
	
	function otvori_position(id, subscr)
	{
		wwidth = 650;
		wheight = 620;
		sw = screen.Width;
		sh = screen.Height;
		wleft = (sw - wwidth)/2;
		wtop = 10;
		wproperties = 'left=' + wleft + ',top=' + wtop + ',width=' + wwidth + ',height=' + wheight + ',resizable=1,scrollbars=1,toolbar=0';
		window.open('choose_position.php?branch_id='+id+"&subscr_id="+subscr, '', wproperties);
	}
	
	function proverka_pk()
	{
		var num = document.forma_pk.postcode.value.replace(/[^0-9]+/g, '');
		if(num.length != 4 || document.forma_pk.postcode.value.length != 4)
		{
			alert('Моля, въведете валиден четирицифрен пощенски код!');
			document.forma_pk.postcode.focus();
			return false;
		}
		return true;
	}

	function proverka_order_kc()
	{
		var forma = document.forma_order;
		var str = forma.contact_mail.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (!filter.test(str))
		{
			alert("Моля, въведете валиден e-mail адрес!");
			forma.contact_mail.focus();
			return false;
		}
		if(forma.subject.value == '')
		{
			alert("Моля, въведете тема на запитването!");
			forma.subject.focus();
			return false;
		}
		if(forma.message.value == '')
		{
			alert("Моля, въведете запитване!");
			forma.message.focus();
			return false;
		}
		if(forma.message.value.length > 1000)
		{
			alert("Моля, съкратете дължината на текста до под 1000 знака!");
			forma.message.focus();
			return false;
		}
		if(forma.sec_code.value == '')
		{
			alert("Моля, въведете кода от картинката!");
			forma.message.focus();
			return false;
		}
		return true;
	}

	function submitSearchForm()
	{
		if(proverka())
		{
			var domain = 'http://catalog.bg';
			if(window.location.host.search(/office\.etel\.bg/) != -1)
			{
				var reversed = window.location.host.split("").reverse().join("");
				var restpos = window.location.host.search(/office\.etel\.bg/);
				var domainLeft = window.location.host.substring(restpos);
				reversed = reversed.substring(reversed.search(/\./)+1);
				reversed = reversed.substring(reversed.search(/\./)+1);
				reversed = reversed.substring(reversed.search(/\./)+1);
				domain = reversed.substring(0,reversed.search(/\./));
				domain = domain.split("").reverse().join("");
				domain = 'http://www.'+domain+'.'+domainLeft;
			}
			window.location.href = domain + "/result/"
			+ encodeURI($('#searchField').val().toLowerCase().replace('.',' '));
		}
	}
	
	function proverka_order_kr()
	{
		var forma = document.forma_order;
		var str = forma.email.value;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (!filter.test(str)) 
		{
			alert("Моля, въведете валиден e-mail адрес!");
			forma.email.focus();
			return false;
		}
		if(forma.subject.value == '')
		{
			alert("Моля, въведете тема на запитването!");
			forma.subject.focus();
			return false;			
		}
		if(forma.message.value == '')
		{
			alert("Моля, въведете запитване!");
			forma.message.focus();
			return false;			
		}
		if(forma.message.value.length > 1000)
		{
			alert("Моля, съкратете дължината на текста до под 1000 знака!");
			forma.message.focus();
			return false;			
		}
		return true;
	}
	
	function sendEmail(id)
	{
		var LINK = window.location.protocol + "//" + window.location.host + "/send_mail/" + id;
		$.ajax({
			async: true, type: 'POST', cache: false,url: LINK,
			success: function(data){window.location.href = data;}
		});
	}
