function isNotEmpty(elem){
	var str = elem.value;
	var re = /.+/;
	
	if(!str.match(re)){
		alert("Пожалуйста, заполните все поля!");
		return false;
		}
	else{
		return true;
	}
}


function isEMailAddr(elem){
	var str = elem.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	
	if(!str.match(re)){
		alert("Неправильно введен адрес электронной почты!");
		return false;
		}
	else{
		return true;
	}
}

function validateForm(form){
	if(isNotEmpty(form.nameF)){
		if(isNotEmpty(form.questionF)){
			if(isNotEmpty(form.email) && isEMailAddr(form.email)){
				return true;
			}
		}
	}
	return false		
}

function validateFormcontact(form){
	if(isNotEmpty(form.name)){
		if(isNotEmpty(form.question)){
			if(isNotEmpty(form.email) && isEMailAddr(form.email)){
					return true;
			}
		}
	}
	return false		
}

function Resize(width, height){
		window.resizeTo(width, height);
	
}
function windowsOpen(url,width,height){
	width+=17; height+=3;
	var status = 'Toolbar=0, Location=0, Directories=0, Status=0, Menubar=0, scrollbars=1, Resizable=0, Copyhistory=0, Width=' + width + ',Height=' + height;
	window.open(url, 'newWin', status);
}

function Rezalt(){
	var price_base = 174;	
	var rebateArray =  [[0.20, 0.18, 0.22, 0.26],
						[0.20, 0.25, 0.30, 0.35],];
	var val1 = parseFloat(document.raschet.name1.value);
	var val2 = parseFloat(document.raschet.name2.value);
	var val3 = parseFloat(document.raschet.polosa.value);
	var val4 = parseInt(document.raschet.predop.value);
	var pn = document.getElementById('pn').checked;
	var sr = document.getElementById('sr').checked;
	var pt = document.getElementById('pt').checked;
	var place = document.getElementById('place').checked;
	var price_base_end = price_base;
/*	if(pn == true && sr == true && pt == true){
		price_base_end = 174;
	}
	else{
		var count = 0;
		if(pn == true){
			count++;
		}
		if(sr == true){
			count++;
		}
		if(pt == true){
			count++;
		}
		price_base_end = price_base*count;
	}*/
	if(!isNaN(val1) && !isNaN(val2) && (pn == true || sr == true || pt == true)){
		var rebate_mod = 0;
		var pub = -1;
		if(val1 >= 8 && val1 < 10) rebate_mod = 0.08;
		if(val1 >= 10 && val1 < 12) rebate_mod = 0.10;
		if(val1 >= 12 && val1 < 15) rebate_mod = 0.12;
		if(val1 >= 15 && val1 < 20) rebate_mod = 0.16;
		if(val1 >= 20 && val1 < 30) rebate_mod = 0.18;
		if(val1 >= 30 && val1 < 60) rebate_mod = 0.20;
		if(val1 >= 60 && val1 < 138) rebate_mod = 0.24;
		if(val1 >= 138) rebate_mod = 0.28;
		if(val2 >= 5 && val2 < 15) pub = 0;
		if(val2 >= 15 && val2 < 25) pub = 1;
		if(val2 >= 25 && val2 < 50) pub = 2;
		if(val2 >= 50) pub = 3;
		var rebate_place = 0;
		if(place == true) rebate_place = 0.20;
		rebate_pub = 0;
		if(pub != -1)
			rebate_pub = rebateArray[parseInt(val4)][pub];
		var sum =  price_base_end*val1*val2;
		sum = sum*(1 - rebate_mod);
		sum = sum*(1 - rebate_pub);
		sum = sum*(1 + val3);
		sum = sum*(1 + rebate_place);
		var rebate = rebate_mod + rebate_pub;
		var rebate = parseInt(rebate*100);
		document.raschet.rebate.value = rebate+"%";
		document.raschet.name3.value = sum.toFixed(2);
	}
}

var timeOn	=	null;
var lastId	=	null;

function showMenu(id) {
	lastId	=	id;
	if (document.getElementById("menu" + id)) {
		document.getElementById("menu" + id).style.visibility	=	"visible";
		document.getElementById("menu" + id).style.marginTop	=	- document.getElementById("link" + id).offsetHeight + "px";
		document.getElementById("menu" + id).style.marginLeft	=	document.getElementById("link" + id).offsetWidth + "px";
	}
	document.getElementById("main_menu" + id).style.backgroundColor	=	"#00114b";
	document.getElementById("link" + id).style.color	=	"#D9D9D9";
}

function hideMenu(id) {
	lastId	=	null;
	if (document.getElementById("menu" + id))	
		document.getElementById("menu" + id).style.visibility	=	"hidden";
	document.getElementById("main_menu" + id).style.backgroundColor	=	"";
	document.getElementById("link" + id).style.color	=	"";
}

function show(id) {
	clearTimeout(timeOn);
	if (id != lastId) {
		if (lastId != null)
			hideMenu(lastId);
		showMenu(id);
	}
}

function hide() {
	timeOn	=	setTimeout("hideMenu(" + lastId + ")",500);
}

function addToFavorites(url,title) {
	if (window.sidebar) {
		// Firefox
		window.sidebar.addPanel(title, url, '');
	} else if (window.opera && window.print) {
		// Opera
		var t = document.createElement('a');
		t.setAttribute('rel', 'sidebar');
		t.setAttribute('href', url);
		t.setAttribute('title', title);
		t.click();
	} else {
		// IE
		window.external.AddFavorite(url, title);
	}
}

function sendEmail(id,name) {
	var	e	=	document.getElementById("hiddenTo");
	if (e.style.display == "none")
		e.style.display = "block";
	document.getElementById("to_name").value	=	name;
	document.getElementById("to_id").value	=	id;
	document.getElementById("name").focus();
}
function closeEmail() {
	var	e	=	document.getElementById("hiddenTo");
	e.style.display = "none";
	document.getElementById("to_name").value	=	"";
	document.getElementById("to_id").value	=	0;
}
function sendRequest(id) {
	document.getElementById("doc["+id+"]").selected	=	true;
	document.getElementById("name").focus();
}
