function frmSubscribe_onFocus(o)
{
    if (o.value == o.title)
    {
        o.style.color = '#000000';
        o.value = '';
    }
}

function frmSubscribe_onBlur(o)
{
    if ('' == o.value)
    {
        o.style.color = '#999999';
        o.value = o.title;
    }
}

var checkWindowFlag = 'next';
function checkWeek()
{
	var t = document.getElementById('weekMenuRow');
	if(!t || typeof(t) == 'undefined')
		return;
	var cs = t.getElementsByTagName('td');
	for(var i=0; i < cs.length; i++)
	{
		if(checkWindowFlag == 'next')
			cs[i].style.display = (cs[i].className == 'nextWeek')?'':'none';
		else
			cs[i].style.display = (cs[i].className == 'currentWeek')?'':'none';
	}
	checkWindowFlag = (checkWindowFlag == 'next')?'current':'next';
	document.getElementById('weekLinker').innerHTML = (checkWindowFlag == 'current')?'текущая неделя':'следующая неделя';
}

function frmSubscribe_onSubmit(f)
{
    var sFocus = '';
    var sError = '';

    if (typeof(f.persone) != 'undefined' &&
        ('' == f.persone.value || f.persone.value == f.persone.title)
    )
    {
        sError = f.persone.title;
        sFocus = 'persone';
    }
    else if ('' == f.email.value || f.email.value == f.email.title)
    {
        sError = f.email.title;
        sFocus = 'email';
    }
    else if (false == validateEmail(f.email.value))
    {
        sError = 'Введен неверный Email (шаблон: имя@домен.зона)';
        sFocus = 'email';
    }
    else if (typeof(f.format) != 'undefined' && '' == f.format.value)
    {
        sError = 'Выберите формат рассылки';
        sFocus = 'format';
    }

    if ('' != sError)
    {
        alert(sError);
        f.elements[sFocus].focus();
        return false;
    }

    return true;
}

function frmLogin_onSubmit(f)
{
    var sFocus = '';
    var sError = '';

    if (typeof(f.login) != 'undefined' &&
        ('' == f.login.value || f.login.value == f.login.title)
    )
    {
        sError = f.login.title;
        sFocus = 'login';
    }
    else if ('' == f.pswd.value || f.pswd.value == f.pswd.title)
    {
        sError = f.pswd.title;
        sFocus = 'pswd';
    }

    if ('' != sError)
    {
        alert(sError);
        f.elements[sFocus].focus();
        return false;
    }

    return true;
}

function frmSearch_onSubmit(f)
{
    if ('' == f.q.value)
    {
        alert(f.q.title);
        f.q.focus();
        return false;
    }
    return true;
    
}

function mailus()
{
    self.location = 'mailto:editor@nakormim.spb.ru';
}

function validateEmail(sEmail)
{
    if (null == sEmail.match(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/))
        return false;
    else
        return true;
}

function onChangeCity(sel)
{
    location.href=sel.value;
}

function frmOpros_onSubmit(f)
{
    var sFocus = '';
    var sError = '';
    if (typeof(f.email) != 'undefined' &&
        ('' == f.email.value || f.email.value == f.email.title)
    )
    {
        sError = f.email.title;
        sFocus = 'email';
    }
    if (typeof(f.fio) != 'undefined' &&
        ('' == f.fio.value || f.fio.value == f.fio.title)
    )
    {
        sError = f.fio.title;
        sFocus = 'fio';
    }
    if ('' != sError)
    {
        alert(sError);
        f.elements[sFocus].focus();
        return false;
    }
    return true;
}

function frmOrder_onSubmit(f)
{
    var sFocus = '';
    var sError = '';
    if (typeof(f.address) != 'undefined' &&
        ('' == f.address.value || f.address.value == f.address.title)
    )
    {
        sError = f.address.title;
        sFocus = 'address';
    }
    if (typeof(f.phone) != 'undefined' &&
        ('' == f.phone.value || f.phone.value == f.phone.title)
    )
    {
        sError = f.phone.title;
        sFocus = 'phone';
    }
    if (typeof(f.fullName) != 'undefined' &&
        ('' == f.fullName.value || f.fullName.value == f.fullName.title)
    )
    {
        sError = f.fullName.title;
        sFocus = 'fullName';
    }
    if ('' != sError)
    {
        alert(sError);
        f.elements[sFocus].focus();
        return false;
    }
    return true;
}

var ky_price=new Array();

function addPrice(id,price) {
    ky_price[id]=price;
}

function recalc(id) {

    var c = document.getElementById("count"+id);
    //var r = document.getElementById("costs"+id);
    var rl = document.getElementById("costs"+id+"_label");
    var s = document.getElementById("summa");

    if(c.value=='' || c.value=='NaN')
        c.value=0;

    var v=ky_price[id]*parseInt(c.value);
    if(v=='NaN')
        v=0;

    v=v.toString();

    if(v.lastIndexOf('.')>0) {
        v=v.substring(0,v.lastIndexOf('.')+3);
    }
    
    //r.value=v;
    rl.innerHTML=v;

    var j=0;

	for(i in ky_price) 
	{
		//j+=parseFloat(document.getElementById("costs"+i).value);
		if(parseInt(document.getElementById("count"+i).value)<1)
			continue;
		j+=(parseFloat(ky_price[i])*parseInt(document.getElementById("count"+i).value));
	}

    j=j.toString();

    if(j.lastIndexOf('.')>0) {
        j=j.substring(0,j.lastIndexOf('.')+3);
    }

    s.innerHTML=j;
    document.getElementById('summ').value=j;

    //return true;

}

function plus(id) {
    var o=document.getElementById("count"+id);
    o.value=parseInt(o.value)+1;
    document.getElementById('tableRow_'+id).className='selectedRow';
    recalc(id);
}

function minus(id) {
    var o=document.getElementById("count"+id);
    var v=o.value;
    if(parseInt(o.value)>0) 
        o.value=parseInt(o.value)-1;
    if(parseInt(o.value)>0) 
        document.getElementById('tableRow_'+id).className='selectedRow';
    else 
        document.getElementById('tableRow_'+id).className='';
    recalc(id);
}

function keypress(e, o) 
{
	var keyn;
	if(window.event)
		keyn = e.keyCode;
	else if(e.which)
		keyn = e.which;
	if(keyn == 38 || keyn == 39)
	{
		plus(o.id.substring(5));
		return false;
	}
	else if(keyn == 37 || keyn == 40)
	{
		minus(o.id.substring(5));
		return false;
	}
	if(parseInt(o.value)>0) 
		document.getElementById('tableRow_'+o.id.substring(5)).className='selectedRow';
	else 
		document.getElementById('tableRow_'+o.id.substring(5)).className='';
	recalc(o.id.substring(5));
	return true;
}

if(typeof(ky_minimal_order) == 'undefined')
	ky_minimal_order = 0;

function onOrder() {
	if(document.getElementById('order_reservation') && document.getElementById('order_reservation').checked)
		return true;
	if(parseFloat(document.getElementById('summ').value) < ky_minimal_order) {
		alert("Минимальный заказ на сайте " + ky_minimal_order +" рублей.\n\nЗаказ обедов на сумму меньше " + ky_minimal_order +" рублей по телефонам:\n291-12-20, 544-1-911");
		return false;
	}
	return true;
}

function mailto() {
    window.location.href='mai'+'lto:i'+"nfo"+'z@kyl'+"inarov."+'ru';
}

function bookMark() {
    var tempAgent = navigator.userAgent;
    if(tempAgent.indexOf('MSIE')>=0) {
        window.external.AddFavorite(location.href,document.title);
        return false;
    }
}