function str_replace(search, replace, subject) {
	return subject.split(search).join(replace);
}

function open_link_in_parent(addr)
{
	window.opener.location.href = addr;
	window.close();
}

function open_msg(url)
{
	x = (screen.availWidth-300)/2;
	y = (screen.availHeight-100)/2-20;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open(url,'msg','left='+x+',top='+y+',width=300,height=100,location="no",menubar="no",status="no",toolbar="no",resizable="no",scrollbars="no"');
}

function open_pic(pic, width, height)
{
	height = height + 80;
	x = (screen.availWidth-width)/2;
	y = (screen.availHeight-height)/2;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open("",'picture','left='+x+',top='+y+',width='+width+',height='+height+',location="yes",menubar="no",status="no",toolbar="no",resizable="no",scrollbars="yes"');
	newWin.moveTo(x,y);
	newWin.resizeTo(width,height);
	newWin.document.writeln("<html><head><title>"+pic+"</title>");
    	newWin.document.writeln("<style>");
    	newWin.document.writeln("<!--");
    	newWin.document.writeln(".no_border  { border: 0px solid white }");
    	newWin.document.writeln("-->");
    	newWin.document.writeln("</style></head>");
    	newWin.document.writeln("<body bgcolor=#FFFFFF leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>");
    	newWin.document.writeln("<table border=0 width='100%' height='100%'><tr><td valign='center' align='center'>");
    	newWin.document.writeln("<a href='#' class='no_border' title='Щёлкните чтобы закрыть окно' onClick='self.close()'><img class='no_border' src='"+pic+"'></a>");
    	newWin.document.writeln("</td></tr></table>");
    	newWin.document.writeln("</body></html>");
    	newWin.document.close();
	newWin.focus();
}

function open_url(pic)
{
	newWin = window.open(pic,'picture','');
	newWin.focus();
}

/*
function open_pic(pic, width, height)
{
	x = (screen.availWidth-width)/2;
	y = (screen.availHeight-height)/2-20;
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	newWin = window.open("",'picture','left='+x+',top='+y+',width='+width+',height='+height+',location="yes",menubar="no",status="no",toolbar="no",resizable="no",scrollbars="yes"');
	newWin.moveTo(x,y);
	newWin.resizeTo(width,height);
	newWin.document.writeln("<html><head><title>"+pic+"</title>");
    	newWin.document.writeln("<style>");
    	newWin.document.writeln("<!--");
    	newWin.document.writeln(".no_border  { border: 0px solid white }");
    	newWin.document.writeln("-->");
    	newWin.document.writeln("</style></head>");
    	newWin.document.writeln("<body bgcolor=#FFFFFF leftMargin=0 topMargin=0 marginheight=0 marginwidth=0>");
    	newWin.document.writeln("<table border=0 width='100%' height='100%'><tr><td valign='center' align='center'>");
    	newWin.document.writeln("<a href='#' class='no_border' title='Щёлкните чтобы закрыть окно' onClick='self.close()'><img class='no_border' src='"+pic+"'></a>");
    	newWin.document.writeln("</td></tr></table>");
    	newWin.document.writeln("</body></html>");
    	newWin.document.close();
	newWin.focus();
}
*/

function open_window(link) //opens new window
{
	newWin = window.open(link,'newWin','');
	newWin.focus();
}

function confirmDelete(question, where)
{
	temp = window.confirm(question);
	if (temp) //delete
	{
		window.location=where;
	}
}

function validate_order(form)
{
	if (form.first_name.value=="")
	{
		alert("Вы не указали Ваше имя");
		return false;
	}

	if (form.last_name.value=="")
	{
		alert("Вы не указали Вашу фамилию");
		return false;
	}

	if (form.email.value=="")
	{
		alert("Вы не указали EMail адрес");
		return false;
	}

	if (form.phone.value=="")
	{
		alert("Вы не указали телефон");
		return false;
	}

	if (form.transfer_method.value==0)
	{
		alert("Вы не выбрали способ доставки");
		return false;
	}

	if (form.pay_method.value==0)
	{
		alert("Вы не выбрали способ оплаты");
		return false;
	}

	if (form.zip.value=="")
	{
		alert("Вы не указали почтовый индекс");
		return false;
	}

	if (form.country.value=="")
	{
		alert("Вы не указали страну");
		return false;
	}

	if (form.state.value=="")
	{
		alert("Вы не указали область");
		return false;
	}

	if (form.city.value=="")
	{
		alert("Вы не указали город");
		return false;
	}

	if (form.address.value=="")
	{
		alert("Вы не указали адрес доставки");
		return false;
	}

	return true;
}

function WordCount(text)
{
	words=text.split(" ");
	var count= words.length;
	if ((count > 1) && (words[count-1]=="")) count--;
	if ((count > 0) && (words[0]=="")) count--;
	return count;
}
