function flash(version, filename, name, width, height, wmode, bgcolor, menu, flashvars) {
	document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version="+version+"' width='"+width+"' height='"+height+"' id='"+name+"' align='middle'>");
	document.write("<param name='allowScriptAccess' value='sameDomain' />");
	document.write("<param name='wmode' value='"+wmode+"' />");
	document.write("<!-- Flash FIX v0.2 | www.mega.by -->");
	document.write("<param name='bgcolor' value='"+bgcolor+"' />");
	document.write("<param name='salign' value='lt' />");
	document.write("<param name='movie' value='"+filename+"' />");
	document.write("<param name='menu' value='"+menu+"' />");
	document.write("<param name='quality' value='high' />");
	document.write("<param name='flashvars' value='"+flashvars+"' />");
	document.write("<embed src='"+filename+"' wmode='"+wmode+"' menu='"+menu+"' quality='high' flashvars='"+flashvars+"' salign='lt' width='"+width+"' height='"+height+"' bgcolor='"+bgcolor+"' name='"+name+"' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />");
	document.write("</object>");
}

function showimg(dep, id, img, sx, sy) {
	document.getElementById('p_img_'+id).src = 'img.php?dep='+dep+'&img='+img+'&w=250';
	document.getElementById('imghref_'+id).href = "javascript: get_photo('"+dep+"', '"+img+"', "+sx+", "+sy+")";
}

function get_photo(dep, img, sx, sy) {
	sx = sx+20;
	sy = sy+20;
	zoomw=window.open("about:blank", "_blank", "width="+sx+", height="+sy);
	zoomw.document.write("<html><head><title>Фото</title></head><body style='margin:0px; background:#ffffff;'>");
	zoomw.document.write("<center><table cellpadding='0' cellpading='0' width='100%' height='100%'><tr><td width='100%' height='100%' align='center' valign='middle'>");
	zoomw.document.write("<img src='/img.php?dep="+dep+"&img="+img+"&w="+sx+"' width='"+sx+"' height='"+sy+"'>");
	zoomw.document.write("</td></tr></table>");
	zoomw.document.write("</center></body></html>");
}

function get_pic(img) {
	var im = new Image();
	im.src = "Files/Image/"+img;
	
	sx = im.width+20;
	sy = im.height+30;
	
	wnd = window.open("Files/Image/"+img,"_blank",
	"toolbar=no,location=no,directoties=no,"+
	"status=no,menubar=no,scrollbars=no,resizable=no,"+
	"width="+sx+","+"height="+sy+",left=0,top=0");
}

function set_border(id) {
	if (document.getElementById('onoff_'+id).checked)
	{
		document.getElementById('border_'+id).style.border='1px solid #ff0000';
		document.getElementById('count_'+id).disabled = false;
	}
	else
	{
		document.getElementById('border_'+id).style.border='1px solid #c4c4c4';
		document.getElementById('count_'+id).disabled = true;
	}
	recount_basket('personal');
}

function my_round(val) {
	var n,a,b,c;
	n=val.toString();
	if (n.indexOf('.')!=-1) {
		var temp=new Array();
		temp=null;
		temp=n.split('.');
		a=temp[0];
		b=temp[1];
		c=temp[1].substr(0,2);
		return (parseFloat(a+'.'+c));
	} else return val;
}

function recount_basket(complect) {
	var total = 0;
	var elts = document.getElementById("order_form").elements;
	for (i = 0; i<elts.length; i++)
	{
		if (complect == "personal")
		{
			if (elts[i].type == 'checkbox' && elts[i].checked)
			{
				var id = elts[i].name.substr(6, (elts[i].name.length-1));
				total += document.getElementById('price_'+id).value*document.getElementById('count_'+id).value;
			}
		}
		else
		{
			var nm = elts[i].name.substr(0, 5);
			if (nm == "price")
			{
				var id = elts[i].name.substr(6, (elts[i].name.length-1));
				total += document.getElementById('price_'+id).value*document.getElementById('count_'+id).value;
			}
		}
	}
	document.getElementById('total_summ').innerHTML = my_round(total);
}

function isInteger(value) {
	var re = new RegExp("^[0-9]+$");
	return re.test(value);
}

function checkinputfield(i) {
	if (!isInteger(document.getElementById('count').value))
	{
		alert('В поле количеста введите целочисленное значение');
	}
	else
	{
		document.getElementById('buy_form_'+i).submit();
	}
}


function feedback_form(id) {
	var error=0;
	emailTest = "^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$";
	var regex = new RegExp(emailTest);
	if(!document.getElementById(id).name.value) {
		error++;
		alert("Введите Ваше Имя!");	
	}
	if(!regex.test(document.getElementById(id).email.value)) {
		error++;
		alert("Указан неверный E-mail!");	
	}
	if(!document.getElementById(id).message.value) {
		error++;
		alert("Введите Ваше сообщение!");	
	}
	if(!error) {
		document.getElementById(id).submit();
	}
}

function order_form(id) {
	var error=0;
	emailTest = "^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$";
	var regex = new RegExp(emailTest);
	if(!document.getElementById(id).customer.value) {
		error++;
		alert("Введите Ваше Имя!");	
	}
	if(!regex.test(document.getElementById(id).email.value)) {
		error++;
		alert("Указан неверный E-mail!");	
	}
	if(!document.getElementById(id).contacts.value) {
		error++;
		alert("Введите Ваши контактные данные!");	
	}
	if(!error) {
		document.getElementById(id).submit();
	}
}