function checkname()
	{
	var str=document.getElementById('first_name').value;
	 var filter=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;
	 if (filter.test(str)) {document.getElementById('name_div').style.visibility="hidden"; document.getElementById('name_pic').style.visibility="visible";} else {document.getElementById('name_pic').style.visibility="hidden"; document.getElementById('name_div').style.visibility="visible";}
	}

function checkcity()
	{
	var str=document.getElementById('city').value;
	 var filter=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;
	 if (filter.test(str)) {document.getElementById('city_div').style.visibility="hidden"; document.getElementById('city_pic').style.visibility="visible";} else {document.getElementById('city_pic').style.visibility="hidden"; document.getElementById('city_div').style.visibility="visible";}
	}

function checksurname()
	{var str=document.getElementById('last_name').value;
	 var filter=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;
	 if (filter.test(str)) {document.getElementById('surname_div').style.visibility="hidden"; document.getElementById('surname_pic').style.visibility="visible";} else {document.getElementById('surname_pic').style.visibility="hidden"; document.getElementById('surname_div').style.visibility="visible";}}
function checkmail()
	{var str=document.getElementById('email').value;
	 var filter=/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;
	 if (filter.test(str)) {document.getElementById('mail_div').style.visibility="hidden"; document.getElementById('mail_pic').style.visibility="visible";} else {document.getElementById('mail_pic').style.visibility="hidden"; document.getElementById('mail_div').style.visibility="visible";}
	}
function checkphone()
	{var str=document.getElementById('phone').value;
	 var filter=/^(?:8|\+7)? ?\(\d{1,5}\)? ?\d{1,5}\-\d{2}\-\d{2}$/;
	 if (str != "") {document.getElementById('phone_div').style.visibility="hidden"; document.getElementById('phone_pic').style.visibility="visible";} else {document.getElementById('phone_pic').style.visibility="hidden"; document.getElementById('phone_div').style.visibility="visible";}
	}

function checkphone2()
	{var str=document.getElementById('phone2').value;
	 var filter=/^(?:8|\+7)? ?\(\d{1,5}\)? ?\d{1,5}\-\d{2}\-\d{2}$/;
	 if (str != "") {document.getElementById('phone_div2').style.visibility="hidden"; document.getElementById('phone_pic2').style.visibility="visible";} else {document.getElementById('phone_pic2').style.visibility="hidden"; document.getElementById('phone_div2').style.visibility="visible";}
	}
 
function open_window(link,w,h) //opens new window
	{
	var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
	newWin = window.open(link,'newWin',win);
	newWin.focus();
	}


function confirmDelete() //unsubscription confirmation
	{
	temp = window.confirm(QUESTION_UNSUBSCRIBE);
	if (temp) //delete
		{
		window.location="index.php?killuser=yes";
		}
	}

function validate_price() //validate customer information for price
	{	
	
	var strFName=document.getElementById('first_name').value;
	var filterFName=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;

	if (!filterFName.test(strFName)) 
		{
		alert(ERROR_INPUT_NAME);
		return false;
		}

	var strEmail=document.getElementById('email').value;
	var filterEmail=/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

	if (!filterEmail.test(strEmail)) 
		{
		alert(ERROR_INPUT_EMAIL);
		return false;
		}

	var strCity=document.getElementById('city').value;
	var filterCity=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;

	if (!filterCity.test(strCity)) 
		{
		alert(ERROR_INPUT_CITY);
		return false;
		}

	return true;
	}


function validate_custinfo() //validate customer information
	{	
	
	var strFName=document.getElementById('first_name').value;
	var filterFName=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;

	if (!filterFName.test(strFName)) 
		{
		alert(ERROR_INPUT_NAME);
		return false;
		}

	var strSName=document.getElementById('last_name').value;
	var filterSName=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;

	if (!filterSName.test(strSName)) 
		{
		alert(ERROR_INPUT_NAME);
		return false;
		}

	var strEmail=document.getElementById('email').value;
	var filterEmail=/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

	if (!filterEmail.test(strEmail)) 
		{
		alert(ERROR_INPUT_EMAIL);
		return false;
		}

	var strPhone=document.getElementById('phone').value;
//	var filterPhone=/^(?:8|\+7)? ?\(\d{1,5}\)? ?\d{1,5}\-\d{2}\-\d{2}$/;
	if (strPhone=="" )
		{
		alert(ERROR_INPUT_PHONE);
		return false;
		}
	return true;
	}

function validate_lowpriceinfo() //validate lowprice information
	{	
	
	var strFName=document.getElementById('ifirst_name').value;
	var filterFName=/^[А-ЯA-Z]{2,}( +)?([А-ЯA-Z]{2,})?( +)?$/i;

	if (!filterFName.test(strFName)) 
		{
		alert(ERROR_INPUT_NAME);
		return false;
		}

	var strEmail=document.getElementById('iemail').value;
	var filterEmail=/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i;

	if (!filterEmail.test(strEmail)) 
		{
		alert(ERROR_INPUT_EMAIL);
		return false;
		}

	var strPhone=document.getElementById('iphone').value;
//	var filterPhone=/^(?:8|\+7)? ?\(\d{1,5}\)? ?\d{1,5}\-\d{2}\-\d{2}$/;
	if (strPhone=="" )
		{
		alert(ERROR_INPUT_PHONE);
		return false;
		}

	var strLowUrl=document.getElementById('ilowurl').value;
	if (strLowUrl=="" )
		{
		alert(ERROR_INPUT_LOWURL);
		return false;
		}

	return true;
	}


$(document).ready(function() {
  $('#tabSet').tabs();
      
//ajax cart function
    $('.ajaxcart').click(function () {                //Биндим клик по классу ajxcart
        var curid = this.id.split('_')[1];            //Смотрим id (вида tocard_123) и берем из него код продукта
        poststr="shopping_cart=yes&add2cart="+curid +"&qty=" + document.getElementById(this.id+"_qty").value; //Формируем POST
        document.getElementById(this.id+"_qty").value = "1";
        $.ajax(                            //Отправляем
        {
            type: "GET",
            url: "./ajax_cart.php",
            data: poststr,
            success:
                function (html)                               //Обрабатываем ответ
                    {
                        $('#sci').text(html.split(":")[1]);    //Пишем количество товаров в элемент с id="sci"
                        $('#scs').text(html.split(":")[2]);    //Пишем сумму товаров в элемент с id="scs"
            //Тут же функции анимации и прочих красивостей

				var image = $('#dp'+curid).offset();
				var cart  = $('#module_cart').offset();
	
				$('#dp'+curid).before('<img src="' + $('#dp'+curid).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

				params = {
					top : cart.top + 'px',
					left : cart.left + 'px',
					opacity : 0.0,
					width : $('#module_cart').width(),  
					heigth : $('#module_cart').height()
				};

				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});
                alert('Товар добавлен в корзину!');
                }
        });
	return false;
    });


});

