$(window).load(function(){
    $("#slider").easySlider();
    var serchText = $('input[name="queryField"]').val();
    $('input[name="queryField"]').focus(function(){$(this).val('')});
    $('input[name="queryField"]').focusout(function(){if($(this).val().length==0)$(this).val(serchText)});
    
    $('#menu > LI').mouseenter(function(){
        var el = $(this).children('.submenu_1');
		if(!$(el).is(':animated')) $(el).slideDown();
    }).mouseleave(function(){
        $(this).children('.submenu_1').slideUp();
    });
    
    $('.back_phone').click(function(){
        $('.callbackFormBlock').toggle();
        return false;
    });
});

function searchValid(obj){
    if(TrimStr(obj.queryField.value).length<3){
        alert('Запрс должен состоять минимум из 3-ех символов');
        return false;
    }
    return true;
}
function TrimStr(s) {
  s = s.replace( /^\s+/g, '');
  return s.replace( /\s+$/g, '');
}


function showOrderForm(deviceName,linkObj){
    var oel = document.getElementById('orderFormDiv');
    document.getElementById('persontext').value = 'Мой заказ:\n- '+deviceName;
    var objPos = $(linkObj).position();
    oel.style.top = Math.round(objPos.top)-155+'px';
    oel.style.left = Math.round(objPos.left)-50+'px';
    oel.style.display = 'block';
}
function closeOrderForm(){
	var oel = document.getElementById('orderFormDiv');
	oel.style.display = 'none';
	document.getElementById('persontext').value = '';
}

function submitOrderForm(f){
    if(document.getElementById('personname').value=='')
    {
        alert('Пожалуйста, введите ваше имя!');
        return false;
    }
    else if(document.getElementById('personcontact').value=='')
    {
        alert('Пожалуйста, введите контактную информацию!');
        return false;
    }
    else if(document.getElementById('persontext').value==''){
        alert('Пожалуйста, введите текст сообщения!');
        return false;
    }
    else{
        var textareaOrderVal = $('#persontext').val();
        $('#persontext').val(textareaOrderVal+'@');
        f.submit();
    }
}
function callbackValid(formObj){
    if(document.getElementById('callback_client_name').value==''){
        alert('Пожалуйста, введите ваше имя!');
        return false;
    }
    else if(document.getElementById('callback_client_phone').value==''){
        alert('Пожалуйста, введите ваш номер телефона!');
        return false;
    }
    return true;
}

