function Show(fname, width, height) {
	if (screen.height<=550 && screen.width<=700) { 
		document.location = fname;
	} else {
		if(!height) height = 800;
		if(!width) width = 600;		
		newHeight = height + 20;
		PopupWin = window.open(fname, "_blank", "height="+newHeight+",width="+width+",menubar=no,status=no,titlebar=no,toolbar=no,location=no,resizable=no,scrollbars=yes"); }
	return false;
}

function checkStrSearch(str) {
   if((str.length) < 3) {
        alert('Строка поиска должна быть не менее 3 символов');
        return false;
    } else return true;
}
function trim(str) {
	while (str.substr(0, 1) == ' ') {str = str.substr(1);};
	while (str.substr(str.length - 1, 1) == ' ') {str = str.substr(0, str.length - 1);};
	return str;
};

function checkForm() {
	input = document.getElementById('str');
	input.value = trim(input.value);

	if(input.value == default_value) input.value = ''; 
	fill = checkStrSearch(input.value);
	if(!fill && input.value == '') {
		input.value = default_value;
		return false;
	} else if(input.value != '' && !fill) return false;

};

function isInt(num, chara)
{
	if(((num >= 48) && (num <= 57)) || num == 37 || num == 8)
	{
		event.keyCode = num;
		return event.keyCode;
	}
	if(((chara >= 48) && (chara <= 57)) || chara == 37 || chara == 8)
	{
		event.charCode = chara;
		return event.charCode;
	}
	else
	{
		return false;
	}
}

function checkFeedbackForm() {
	var required = {
		"fio"		:	"Вы не ввели Ваше ФИО",
		"tel"		:	"Вы не ввели номер телефона",
		"msg"		:	"Вы не ввели сообщение"
	};
	for (var i in required) {
		var el = document.getElementById(i);
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function preloadImg(src) {
	if (document.images) {
		var image = new Image();
		image.src = src;
		images.push(image);
	}
}

function auto_form_check(required) {
	if(!required) return true;
	for (var i in required) {
		var el = document.getElementById(i);
		if (!el.value) {
			alert(required[i]);
			el.focus();
			return false;
		}
	}
	return true;
}

function checkEmail(email) {
	if(!email) return email;
	if(!email.match(/^[\w\.\-]+@[\w\.\-]+\.[a-zA-Z]{2,}$/i, "")) return false;
	return true;
}

function showHiddenElem(id) {
	if(!document.getElementById(id)) {
		return false;
	}
	elem = document.getElementById(id);
	if(elem.style.display == 'block') elem.style.display = 'none';
	else elem.style.display = 'block';
}

function getElem(id) {
	return document.getElementById(id);
}

function preloadImages() {
	var d = document; 
	
	if(d.images) {
		var i, a = preloadImages.arguments;
		for(i = 0; i < a.length; i++) {
			d.preloadedImages[a[i]] = new Image;
			d.preloadedImages[a[i]].src = a[i];
		}
	}
}

function changeImg(img_name, image) {
	if (image.className == 'std')
	{
		image.src = site_url+'buttons/'+img_name+'_hover.gif';
		image.height = 81;
		image.className = '';
	}
	else
	{
		image.src = site_url+'buttons/'+img_name+'.gif';
		image.height = 65;
		image.className = 'std';
	}
}
