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);
	}
}
function FixClick(param){
		var img = new Image;
		img.src = 'fix.php?idF=' + param + '&tm=' + Math.random();
}

function show(i) {
    var mainId	=	"main[" + i + "]";
    var subId	=	"sub[" + i + "]";
	var e = document.getElementById(mainId);
	
    var w = e.offsetWidth;
    var h = e.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (e){
        l += e.offsetLeft;
        t += e.offsetTop;
        e = e.offsetParent;
    }
	document.getElementById(mainId).className		=	'menu_over';
	if (document.getElementById(subId)) {
		document.getElementById(subId).style.display	=	'block';
		document.getElementById(subId).style.left		=	l + 'px';
		document.getElementById(subId).style.top		=	(t + h) + 'px';
		if (document.getElementById(subId).offsetWidth < (w - 1))
			document.getElementById(subId).style.width		=	(w) + 'px';
	}
}

function hide(i) {
    var mainId	=	"main[" + i + "]";
    var subId	=	"sub[" + i + "]";
	document.getElementById(mainId).className		=	'menu_pas';
	if (document.getElementById(subId))
		document.getElementById(subId).style.display	=	"none";
}

