function isset(me) {
 if (me == null || me == '')
  return 0;
 else
  return 1;
}

function randomFromTo(from, to){
	return Math.floor(Math.random() * (to - from + 1) + from);
}

function add_alias() { 
	$.post(
			'/',
			{
				action: 'add_alias'				
			},
			function(resp){
				if (resp == 'err') {
					alert('Unable to add an alias! Please contact the site administrator.');	
				}
			}
		);	
}

// forget password function!
function forget_password(){
	var err_mail = 'err';
	var email = $("#inp_email").val();
	if (email != '') {		
		if (!checkmail(email)) { 
			$('#inp_email').removeClass('inp');
			$('#inp_email').addClass('inp_err');
			$("#inp_email").focus();
			err_mail = 'err';
		}
		else { 
			$('#inp_email').removeClass('inp_err');
			$('#inp_email').addClass('inp');
			err_mail = 'ok';
		}
	}
	
	if (err_mail == 'ok') {
		$.post('/',{
			action:'auth_email',
			email:email
		},
		function(resp){
			resp=eval('('+resp+')');
			if(resp.exists=='yes') {
				$('#inp_email').empty();
				document.getElementById('id_obrabotka').style.display = 'block';
				document.getElementById('err').style.display = 'none';
				check_generate_recovery_tail(email);
			}
			else if(resp.exists=='no') {
				$('#inp_email').empty();
				document.getElementById('id_obrabotka').style.display = 'none';
				document.getElementById('err').style.display = 'block';
			}
			else {
				document.getElementById('id_obrabotka').style.display = 'none';
				document.getElementById('err').style.display = 'none';
				alert(resp.error||resp);
			}
		});
	}
	else {
		$('#inp_email').removeClass('inp');
		$('#inp_email').addClass('inp_err');
		$("#inp_email").focus();
	}
}

function check_generate_recovery_tail(email) {
	$.post('/',
	    {
		   action:'chk_gen_recov_tail',
		   email:email
		},
		function(resp){
			if (resp == 1)
			{
			  	$('#inp_email').empty();
			  	document.getElementById('id_obrabotka').style.display = 'none';
				document.getElementById('err').style.display = 'none';
			  	document.getElementById('id_obrabotka1').style.display = 'block';
				document.getElementById('id_bt').style.display = 'none';
				document.getElementById('id_block_1').style.display = 'none';
				document.getElementById('id_block_2').style.display = 'none';
			}
			else
			{
				$('#inp_email').empty();
			   	document.getElementById('id_obrabotka').style.display = 'none';
				document.getElementById('err').style.display = 'none';
			  	document.getElementById('id_obrabotka1').style.display = 'none';
				document.getElementById('err1').style.display = 'block';
			}
		}
		);
}

function editPos(pos){ 
	$(document).ready(function() {
		$("#gallery a").fancybox({
			overlayShow: true,
			overlayOpacity: 0.5,
			itemLoadCallback: getGroupItems,
			itemNum: pos-1
		});
	});
}


//SIGN IN 
function sign_in() {
	var pas = $("#inp_pas").val();
	var email = $("#inp_email").val();
	var login = $("#inp_login").val();
	var err_pas, err_mail, err_login;
	if (login == '' && email == '') {
		$('#inp_email').removeClass('inp');
		$('#inp_email').addClass('inp_err');
		$('#inp_login').removeClass('inp');
		$('#inp_login').addClass('inp_err');
		$("#inp_email").focus();
		err_mail = 'err';
	}
	
	if (email != '') {
		if (!checkmail(email)) { 
			$('#inp_email').removeClass('inp');
			$('#inp_email').addClass('inp_err');
			$("#inp_email").focus();
			err_mail = 'err';
		}
		else { 
			$('#inp_email').removeClass('inp_err');
			$('#inp_email').addClass('inp');
			err_mail = 'ok';
		}
	}
	
	if (login != '') err_login = 'ok';	
	if (login == '' && email != '') err_login = 'ok';
	
	if (pas == '') {		
		$('#inp_pas').removeClass('inp');
		$('#inp_pas').addClass('inp_err');
		$("#inp_pas").focus();
		err_pas = 'err';		
	}
	else {
		$('#inp_name').removeClass('inp_err');
		$('#inp_name').addClass('inp');
		err_name = 'ok';
	}
	if (err_mail == 'err' || err_login == 'err' || err_pas == 'err')  {
		$("#err").html(sign_in_var_1);
		return false;
	}
	var const_1 = 'zsexdfcftrewvgfdsertyujhgfvbnm,kjhgfdsertyuuEnglishmen_travel_not_to_see_far-away_countries_but_to_see_the_sun_dfsjfnffsdfj/fSFDFd'; //big worlds
	var remfl=$('#remember:checked').val();
	if(remfl==undefined) {remfl='';}
	$.post('/',{
			action:'auth_email_pass',
			email:email,
			rem: remfl,
			login: login,
			pass:md5(pas + const_1)
	},
	function(resp){
			resp=eval("("+resp+")");
			if(resp.ok=='yes') {
				core_redirect('/');
			}
			else if(resp.error=='pass' || resp.error=='email' || resp.error=='login'){
				$('#inp_email').removeClass('inp');
				$('#inp_email').addClass('inp_err');
				$('#inp_login').removeClass('inp');
				$('#inp_login').addClass('inp_err');
				$('#inp_pas').removeClass('inp');
				$('#inp_pas').addClass('inp_err');
				$("#inp_pas").focus();
				$("#inp_pas").empty();
				$("#err").html(sign_in_var_1);
			}
			else{
				alert(resp.error||resp);
			}
	}
	);
}
//REGISTRATION
function registration () {
	//checking data
	var email = $("#inp_mail").val();
	var country = $('#inp_country option:selected').val();
	var d = $('#inp_d option:selected').val();
	var m = $('#inp_m option:selected').val();
	var y = $('#inp_y option:selected').val();
	var s, name;
	var birth = '0000-00-00';
	var err_mail, err_country, err_d, err_m, err_y; 
	var rules = 'off'
	if ($('#rules:checked').val() == 'on')
		rules = 'on';
	
	if($("#inp_mw_01:checked").length != 0) s = 0;
	if($("#inp_mw_02:checked").length != 0) s = 1;
	if (s != 1) s = 0; //0-man; 1-woman
	
	if (!checkmail(email)) { 
		$('#inp_mail').removeClass('inp');
		$('#inp_mail').addClass('inp_err');
		$("#inp_mail").focus();
		err_mail = 'err';
	}
	else { 
		$('#inp_mail').removeClass('inp_err');
		$('#inp_mail').addClass('inp');
		err_mail = 'ok';
	}
	
	if (country == '') {		
		$('#inp_country').removeClass('block_select');
		$('#inp_country').addClass('block_select_err');
		err_country = 'err';		
	}
	else {
		$('#inp_country').removeClass('block_select_err');
		$('#inp_country').addClass('block_select');
		err_country = 'ok';
	}	
	
	if (d == '') {		
		$('#inp_d').removeClass('block_select');
		$('#inp_d').addClass('block_select_err');
		err_d = 'err';		
	}
	else {
		$('#inp_d').removeClass('block_select_err');
		$('#inp_d').addClass('block_select');
		err_d = 'ok';
	}
	
	if (m == '') {		
		$('#inp_m').removeClass('block_select');
		$('#inp_m').addClass('block_select_err');
		err_m = 'err';		
	}
	else {
		$('#inp_m').removeClass('block_select_err');
		$('#inp_m').addClass('block_select');
		err_m = 'ok';
	}
	
	if (y == '') {		
		$('#inp_y').removeClass('block_select');
		$('#inp_y').addClass('block_select_err');
		err_y = 'err';		
	}
	else {
		$('#inp_y').removeClass('block_select_err');
		$('#inp_y').addClass('block_select');
		err_y = 'ok';
	}
	
	if (err_d == 'ok' && err_m == 'ok' && err_y == 'ok') {
		birth = y + '-' + m + '-' + d; 
	}	

	var str = email;
	var name_arr =  str.split('@');
	name = name_arr[0];
	if (rules == 'off') alert(error_var_1);
	if (err_d == 'err' || err_m == 'err' || err_y == 'err' ||err_country == 'err' || err_mail == 'err' || name == '' || rules == 'off')  return false;
	$.post('/',{
		action:'registration_user',
		email:email,
		name:name,
		country:country,
		birth: birth,
		d:d,
		m:m,
		y:y,
		s:s
	},
	function(resp){
		resp=eval("("+resp+");");
		if(resp.ok=='yes') {
			alert(registration_var_1);
			core_redirect('/');
		}
		else if(resp.error=='email'){
			$("#inp_email").focus();
			$("#inp_email").empty();
			$('#inp_email').removeClass('inp1');
			$('#inp_email').addClass('inp_err');
		}
		else if(resp.error=='pass'){
			$("#inp_pas").focus();
			$("#inp_pas").empty();
			alert(error_var_2);
		}
		else{
			alert(resp.error||resp);
		}
	}
	);
}

//Проверка на корректность адреса электронной почты
function checkmail(email) {
	var template = /^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z])+$/;
   	email = drop_spaces(email); //функцию drop_spaces() см. выше
    if (template.test(email)) {
        return true;
    }
    return false;	
}

//Удаление всех пробелов
function drop_spaces(str) {
    var newstr = trim(str); //функцию trim() см. выше
    return newstr.replace(/(\s)+/g, ""); 
}

//Аналог функции trim() из PHP
function trim(str) {
    var newstr = str.replace(/^\s*(.+?)\s*$/, "$1");
    if (newstr == " ") {
        return "";
    }
    return newstr;
}

function getGroupItems(opts) {
  jQuery.each(imageList, function(i, val) { 
    opts.itemArray.push(val);
 });
}

function showDivMenu (id) {
	//id - id div который нужно показать или скрыть	
	if (document.getElementById(id).style.display == 'block') {
		document.getElementById(id).style.display = 'none';
	}
	else {
		document.getElementById(id).style.display = 'block';
	}
}
function showDiv (id) {
	document.getElementById(id).style.display = 'block';
}
function hideDiv (id) {
	document.getElementById(id).style.display = 'none';
}

function do_query(){
	var message = "Вы уверены, что хотите выполнить этот "+ $("#text_do").val() +"запрос?";
    var return_value = confirm(message);
    if (return_value == true) {
		$.post(
			'/',
			{
				action:'do_query',
				q: $("#text_do").val()
			},
		function(resp){
				if (resp == 'ok') {
					alert('Все прошло хорошо!!!');
				}
				if (resp == 'err') {
					alert('Такой запрос не выполню!!!');
				}
		}
		);
	}
}

var crop_popup=function(href){
	general_popup(href,'CropWindow','auto',500,500);
}

function delete_comment(comm_id, t) {
	var message = "Вы уверены, что хотите удалить этот комментарий?";
        var return_value = confirm(message);
        if (return_value == true) {
		$.post(
			'/',
		        {
				action:'deleter_2',
			        comment_id: comm_id,
					t:t
		        },
		        function(resp) {
		        	if (resp == 1) {
		              		var comm_identifier = '#comment_' + comm_id;
		              	 	$(''+comm_identifier+'').hide();
		              	 	get_comments_number();
		              	 }
			         else alert('Не удалось удалить комментарий!');			         
		       }
	              );
	 }    	   
}

function delete_ip(comm_id) {
	var message = "Вы уверены, что хотите заблокировать этот IP?";
        var return_value = confirm(message);
        if (return_value == true) {
		$.post(
			'/',
		        {
				action:'deleter_ip',
			        comment_id: comm_id
		        },
		        function(resp) {
		        	if (resp == 1) document.location.reload();
			         else alert('Не удалось заблокировать IP!');			         
		       }
	              );
	 }    	   
}

function showPages (news_id) {
	$.post(
		'/',
		{
			action:'show_pages_for_pic',
			news_id:news_id
		},
		function(resp){
			resp=eval('('+resp+')');
			len = resp.length;
			//alert(resp);
			if (len > 1) {
				$('<span></span>').attr('class', 'aspan2').attr('title', 'Начало').html('&lt;&lt;').appendTo('#pic_pages').click(function() {
					$('.pic_news').hide();
					$('.pic_news:first').show();
					//first page other style
					$('#p_link_1').hide();
					$('#p_1').show();
					$('<span></span>').attr('id','id_1').html('1').appendTo('#pic_pages');
				});

				$('<span></span>').html('&nbsp;&nbsp;&nbsp;').appendTo('#pic_pages');

				$('<span></span>').attr('class', 'aspan2').html('&lt;').appendTo('#pic_pages').click(function() {
					$('.pic_news').hide();
					$('.pic_news:first').show();
					//first page other style
					$('#p_1').hide();
					$('<span></span>').attr('id','id_1').html('1').appendTo('#pic_pages');
				});
				$('<span></span>').html('&nbsp;&nbsp;&nbsp;').appendTo('#pic_pages');

				//pages
				for (i=1; i<=len; i++) {
					//$('<span></span>').attr('class', 'span3').attr('id', 'p_'+resp[i-1]).html(i).appendTo('#pic_pages');
					$('<span></span>').attr('class', 'aspan2').attr('id', 'p_link_'+i).html(i).appendTo('#pic_pages')
					.click(function() {
							//$('#p_link_'+resp[i-1]).hide();
							//$('<span></span>').attr('class', 'span').attr('id', 'p_'+resp[i-1]).html(i).appendTo('#pic_pages');
					});
					//if (i+1 < len)
						$('<span></span>').html('|').appendTo('#pic_pages');
				}
				$('<span></span>').html('&nbsp;&nbsp;&nbsp;').appendTo('#pic_pages');
			}
		}
	);

}

var cur_mod='';
function change_mod(mod){
	document.getElementById('mod_'+cur_mod).className='';
	document.getElementById('mod_'+mod).className='active';
	document.search_form.mod.value=mod;
	cur_mod=mod;
}

function searchsubmit(){
	if(document.search_form.query.value==''){
		return false;
	}
	return true;
}

function prepare_send_db_IMG() { 
      var sendingOK = 0;
      var img_path_input = document.getElementById('file_id').value;
      if (img_path_input.length != 0) {
      	  if (img_path_input.indexOf(".jpg")!=-1 || img_path_input.indexOf(".JPG")!=-1 
				|| img_path_input.indexOf(".gif")!=-1 || img_path_input.indexOf(".GIF")!=-1
				|| img_path_input.indexOf(".jpeg")!=-1 || img_path_input.indexOf(".JPEG")!=-1
				|| img_path_input.indexOf(".png")!=-1 || img_path_input.indexOf(".PNG")!=-1)
          {
          	sendingOK=1;
            return true;
          }
      	  else 
      	  {
      	  	alert (prepare_send_db_IMG_var_1); 
      	  	return false;
      	  }
        }
      else {
       	  alert (prepare_send_db_IMG_var_2);
       	  return false;
       }
}

function getRussianDateTime() {
	dayarray=new Array("Воскресенье","Понедельник","Вторник","Среда","Четверг","Пятница","Суббота")
	montharray=new Array ("января","февраля","марта","апреля","мая","июня","июля","августа","сентября", "октября","ноября","декабря")
	ndata=new Date();
	day=dayarray[ndata.getDay()];
	month=montharray[ndata.getMonth()];
	date=ndata.getDate();
	year=ndata.getFullYear();
	hours = ndata.getHours();
	mins = ndata.getMinutes();
	secs = ndata.getSeconds();
	if (hours < 10) {hours = "0" + hours }
	if (mins < 10) {mins = "0" + mins }
	if (secs < 10) {secs = "0" + secs }
	//datastr = day + ", "+ date +" "+ month +" "+ year +", "+ hours + ":" + mins;
	datastr = date +" "+ month +" "+ year  +", "+ hours + ":" + mins;
	return datastr;
}

function checkLen(field_id, field_to_write_id, max_field_len) {
	var str = document.getElementById(field_id).value;
    var len = max_field_len - str.length;
    if (len<0) {
    	document.getElementById(field_id).value = str.substr(0,max_field_len);
        len = 0;
    }
    document.getElementById(field_to_write_id).innerHTML = len;
} 

//add comment
function add_comment(type)  { 
	var message_text = document.getElementById("commentText").value;
    var url = window.location;
	var name = $("#id_com_name").val();
	var email = $("#id_com_email").val();
    var r = document.getElementById("radio_02").checked;
	url = "'" + url + "'";
	if (type== 'katalog') var a = 'insert_comment_to_db_katalog';
	if (type =='article') var a = 'insert_comment_to_db';
	//проверим заполнение полей
	if (message_text != '' && name != '' && email != '') {
		if (checkmail(email)) {
			$.post(
				'/',
				{
					action: a,
					text: message_text,
					name: name,
					email: email,
					e: r,
					url: url,
					type: type
                 },
             	function(resp) { 
                 	if (resp == 1) {
                  		$(document).ready(function() {
                  			document.getElementById('commentText').value = '';
							document.getElementById('id_com_name').value = '';
							document.getElementById('id_com_email').value = '';
                  		}
                  		);
                       	window.location=url;
                  		window.location.reload();
                  	}
					
					if (resp == 2) alert('Ошибка');
					if (resp == 3) alert('Ошибка');					
        	});
		}
		else {
			alert('Вы указали не верный E-mail!');	
		}
	}
	else {
		alert('Вы не заполнили необходимые поля!');	
	}
}

function show_active_menu() {
	var url, arr_url;
	var t = 0;
	url = location.href;
	arr_url = url.split('/');
	if (arr_url[3] == 'katalog-mary-kay') t = 1;
	if (arr_url[3] == 'podarki-mary-kay' || arr_url[3] == 'podarki-do-100-grn') t = 2;
	if (arr_url[3] == 'how-to-buy-products') t = 3;
	if (arr_url[3] == 'kak-stat-konsultantom-mary-kay') t = 4;
	if (arr_url[3] == 'mary-kay') t = 5;
	if (arr_url[3] == 'about-mary-kay-products') t = 6;
	if (arr_url[3] == 'articles') t = 7;
	if (arr_url[3] == 'discount-40-mary-kay') t = 8;
	if (arr_url[3] == 'make-up-courses') t = 9;
	if (arr_url[3] == 'business-training') t = 10;
	if (arr_url[3] == 'delivery-mary-kay') t = 11;
	if (arr_url[3] == 'novinki-mary-kay') t = 12;
	if (arr_url[3] == 'kak-stat-hozyajkoj-klassa') t = 13;

	//$('#id_mail_menu_' + t).removeClass('fleft menu');
	$('#id_anketa_menu_' + t).addClass('a_active_link');
}

function show_active_menu_katalog() { 
	var url, arr_url;
	var t = 0;
	url = location.href;
	arr_url = url.split('/');
	if (arr_url[3] == 'katalog-mary-kay') {
		if (arr_url[4] == 'anti-aging') t = 1;
		if (arr_url[4] == 'ochischenie') t = 2;
		if (arr_url[4] == 'uvlazhnenie') t = 3;
		if (arr_url[4] == 'osnova') t = 4;
		if (arr_url[4] == 'MKMen') t = 5;
		if (arr_url[4] == 'velocity') t = 6;
		if (arr_url[4] == 'care-lips') t = 7;
		if (arr_url[4] == 'additional-skin-care') t = 8;
		if (arr_url[4] == 'problem-skin') t = 9;
		if (arr_url[4] == 'make-up-eyes') t = 10;
		if (arr_url[4] == 'make-up-lips') t = 11;
		if (arr_url[4] == 'make-up-face') t = 12;
		if (arr_url[4] == 'make-up') t = 13;
		if (arr_url[4] == 'corrective') t = 14;
		if (arr_url[4] == 'pudra') t = 15;
		if (arr_url[4] == 'brushes') t = 16;
		if (arr_url[4] == 'nail-polish') t = 17;
		if (arr_url[4] == 'body') t = 18;
		if (arr_url[4] == 'zhenskie-aromaty') t = 19;
		if (arr_url[4] == 'muzhskie-aromaty') t = 20;
		if (t == 5) $('#id_katalog_22').addClass('active_a');
		if (t == 20) $('#id_katalog_21').addClass('active_a');
		
		$('#id_katalog_' + t).addClass('active_a');		
	}
	if (arr_url[3] == 'podarki-mary-kay') {
		if (!isset(arr_url[4]) || arr_url[4] == '' || arr_url[4] == 0) t = 26;
		else {
			if (arr_url[4] == 'podarki-muzhskie') t = 24;
			if (arr_url[4] == 'podarki-zhenskie') t = 25;
		}		
		$('#id_katalog_' + t).addClass('active_a');
	}
	
	if (arr_url[3] == 'podarki-do-100-grn') $('#id_katalog_23').addClass('active_a');
}


function send() {
	var err_phone, err_name, err_cat, err_title, err_content, err_obl, err_time;
	var email = $("#id_email").val();	
	if (!checkmail(email) && email != '') { 
			$('#id_email').removeClass('inp');
			$('#id_email').addClass('inp_err');
			$("#id_email").focus();
	}
	else { 
			$('#id_email').removeClass('inp_err');
			$('#id_email').addClass('inp');
	}
		
	var name = $("#id_name").val();
	if (name == '') {
			err_name = 'err';
			$('#id_name').removeClass('inp');
			$('#id_name').addClass('inp_err');
	}
	else {
			err_name = 'ok';
			$('#id_name').removeClass('inp_err');
			$('#id_name').addClass('inp');
	}
	
	var obl = $('#id_obl option:selected').val();
	if (obl == '0') {
		err_obl = 'err';
		$('#id_obl').removeClass('block_select');
		$('#id_obl').addClass('block_select_err');
	}
	else {
		err_obl = 'ok';
		$('#id_obl').removeClass('block_select_err');
		$('#id_obl').addClass('block_select');
	}
	
	var skype = $("#id_skype").val();
	var icq = $("#id_icq").val();
	var phone = $("#id_phone").val();
	if (phone == '') {
			err_phone = 'err';
			$('#id_phone').removeClass('inp');
			$('#id_phone').addClass('inp_err');
	}
	else {
			err_phone = 'ok';
			$('#id_phone').removeClass('inp_err');
			$('#id_phone').addClass('inp');
	}
	
	var category = $('#id_category option:selected').val();
	if (category == 0) {
		err_cat = 'err';
		$('#id_category').removeClass('block_select');
		$('#id_category').addClass('block_select_err');
	}
	else {
		err_cat = 'ok';
		$('#id_category').removeClass('block_select_err');
		$('#id_category').addClass('block_select');
	}
	
	var time = $('#id_time option:selected').val();
	if (time == 0) {
		err_time = 'err';
		$('#id_time').removeClass('block_select');
		$('#id_time').addClass('block_select_err');
	}
	else {
		err_time = 'ok';
		$('#id_time').removeClass('block_select_err');
		$('#id_time').addClass('block_select');
	}	
		
	var content = $("#id_content").val();
	if (content == '') {
		err_content = 'err';
		$('#id_content').removeClass('txa_inp');
		$('#id_content').addClass('txa_inp_err');
	}
	else {
		err_content = 'ok';
		$('#id_content').removeClass('txa_inp_err');
		$('#id_content').addClass('txa_inp');
	}
	if (err_name == 'ok' && err_phone == 'ok' && err_cat == 'ok' && err_content == 'ok' && err_time == 'ok') {
		$.post('/',{
			action:'send_to',
			name: name,
			email: email,
			cat: category,
			content: content,			
			obl: obl,
			phone: phone,
			skype: skype,
			icq: icq,
			time: time
		},
		function(resp){
			if (resp == 'ok') {
				alert('Я получила Ваше сообщение и в течении 24 часов Вы получите ответ на свой вопрос. Спасибо, за Ваше время!');
				window.location.reload();
			}
			if (resp == 'err') alert('Ошибка: письмо не было доставлено! Перезвоните по телефону: +38 (095) 392-63-53');
		});
	}
}

function showRandomPic(id) {
	var src, href, title;
	var rand = randomFromTo(1, 4);
	if (rand == 1) 	{
		src = "/images/pic/marykay_ny.jpg";
		href = "/katalog-mary-kay";
		title = "Каталог Mary Kay";
	}
	if (rand == 2) {
		src = "/images/pic/marykay_phrase.png";
		href = "/katalog-mary-kay";
		title = "Каталог Mary Kay";
	}
	if (rand == 3) {
		src = "/images/pic/marykay_tonik.png";
		href = "/katalog-mary-kay/anti-aging/tonik-TimeWise";
		title = "Новый тоник Mary Kay";
	}
	if (rand == 4) {
		src = "/images/pic/marykay_blesk.jpg";
		href = "/katalog-mary-kay/make-up-lips/blesk-NouriShine-rozovyj-glyanec";
		title = "Блеск для губ NouriShine Plus - Латте";
	}
	
	$("#"+id).attr("src", src);
	$("#id_a").attr("href", href).attr("title", title);
}

function zakazat_tovar(kod) {
	if (kod != '' && kod != 0) {
		var name = $('#id_name').val();
		var phone = $('#id_phone').val();
		var email = $('#id_email').val();
		var obl = $('#id_obl').val();
		var cnt = $('#id_cnt').val();
		var err_email = 'ok';
		if (name == '') {
			$('#id_name').removeClass('inp');
			$('#id_name').addClass('inp_err');
		}
		else {
			$('#id_name').removeClass('inp_err');
			$('#id_name').addClass('inp');
		}
		
		if (phone == '') {
			$('#id_phone').removeClass('inp');
			$('#id_phone').addClass('inp_err');
		}
		else {
			$('#id_phone').removeClass('inp_err');
			$('#id_phone').addClass('inp');
		}
		
		if (obl == '') {
			$('#id_obl').removeClass('inp');
			$('#id_obl').addClass('inp_err');
		}
		else {
			$('#id_obl').removeClass('inp_err');
			$('#id_obl').addClass('inp');
		}
		
		if (cnt==0 || cnt=='') {
			$('#id_cnt').removeClass('inp');
			$('#id_cnt').addClass('inp_err');
		}
		else {
			$('#id_cnt').removeClass('inp_err');
			$('#id_cnt').addClass('inp');
		}
		
		if (email != '') {
			if (!checkmail(email)) {
				err_email = 'err';
				$('#id_email').removeClass('inp');
				$('#id_email').addClass('inp_err');
			}
			else {
				err_email = 'ok';
				$('#id_email').removeClass('inp_err');
				$('#id_email').addClass('inp');	
			}
		}
		else {
			err_email = 'ok';
			$('#id_email').removeClass('inp_err');
			$('#id_email').addClass('inp');
		}
		if (cnt!=0 && cnt!='' && name!='' && phone!='' && obl!='' && err_email == 'ok') {
			$.post('/',{
				action:'zakazat_tovar',
				name: name,
				email: email,
				kod: kod,
				phone: phone,			
				cnt: cnt,
				obl: obl
			},
			function(resp){
				if (resp == 'ok') {
					alert('Вы заказали товар! В течении 24 часов мы обсудим с Вами вопрос доставки. Спасибо, за Ваш выбор!');
					window.location.reload();
				}
				if (resp == 'err') alert('Ошибка: письмо не было доставлено! Перезвоните по телефону: +38 (095) 392-63-53');
			});
		}
	}
	else {
		alert('Вы не можете заказать товар, уточните причтну по телефону.');	
	}
}

function showSubMenu(id) {
	if (document.getElementById(id).style.display == 'block') document.getElementById(id).style.display = 'none';
		else document.getElementById(id).style.display = 'block';
	if (id == 'subblock_12') {
		document.getElementById('subblock_13').style.display = 'none';
		document.getElementById('subblock_14').style.display = 'none';
		document.getElementById('subblock_15').style.display = 'none';
		document.getElementById('subblock_16').style.display = 'none';
	}
	if (id == 'subblock_13') {		
		document.getElementById('subblock_12').style.display = 'none';
		document.getElementById('subblock_14').style.display = 'none';
		document.getElementById('subblock_15').style.display = 'none';
		document.getElementById('subblock_16').style.display = 'none';
	}
	if (id == 'subblock_14') {
		document.getElementById('subblock_12').style.display = 'none';
		document.getElementById('subblock_13').style.display = 'none';
		document.getElementById('subblock_15').style.display = 'none';
		document.getElementById('subblock_16').style.display = 'none';
	}
	if (id == 'subblock_15') {
		document.getElementById('subblock_16').style.display = 'none';
		document.getElementById('subblock_12').style.display = 'none';
		document.getElementById('subblock_13').style.display = 'none';
		document.getElementById('subblock_14').style.display = 'none';
	}
	if (id == 'subblock_16') {
		document.getElementById('subblock_12').style.display = 'none';
		document.getElementById('subblock_13').style.display = 'none';
		document.getElementById('subblock_14').style.display = 'none';
		document.getElementById('subblock_15').style.display = 'none';
	}
}

function showActiveSubMenu() {
	var url, arr_url;
	var t, b;
	url = location.href;
	arr_url = url.split('/');
	if (arr_url[3] == 'katalog-mary-kay') {
		if (arr_url[4] == 'anti-aging' || arr_url[4] == 'ochischenie' || arr_url[4] == 'uvlazhnenie' || arr_url[4] == 'osnova' || arr_url[4] == 'MKMen' || arr_url[4] == 'velocity' || arr_url[4] == 'ochischenie' || arr_url[4] == 'ochischenie' || arr_url[4] == 'ochischenie')	{			
			t = 12;
			if (arr_url[4] == 'anti-aging') b = 1;
			if (arr_url[4] == 'ochischenie') b = 2;
			if (arr_url[4] == 'uvlazhnenie') b = 3;
			if (arr_url[4] == 'osnova') b = 4;
			if (arr_url[4] == 'MKMen') b = 5;
			if (arr_url[4] == 'velocity') b = 6;
			if (arr_url[4] == 'care-lips') b = 7;
			if (arr_url[4] == 'additional-skin-care') b = 8;
			if (arr_url[4] == 'problem-skin') b = 9;
		}
		
		if (arr_url[4] == 'make-up-eyes' || arr_url[4] == 'make-up-lips' || arr_url[4] == 'make-up-face' || arr_url[4] == 'make-up' || arr_url[4] == 'corrective' || arr_url[4] == 'pudra' || arr_url[4] == 'brushes' || arr_url[4] == 'nail-polish')	{			
			t = 13;
			if (arr_url[4] == 'make-up-eyes') b = 1;
			if (arr_url[4] == 'make-up-lips') b = 2;
			if (arr_url[4] == 'make-up-face') b = 3;
			if (arr_url[4] == 'make-up') b = 4;
			if (arr_url[4] == 'corrective') b = 5;
			if (arr_url[4] == 'pudra') b = 6;
			if (arr_url[4] == 'brushes') b = 7;
			if (arr_url[4] == 'nail-polish') b = 8;
		}
		
		if (arr_url[4] == 'body')	{			
			t = 14;
			b = 1;			
		}
		
		if (arr_url[4] == 'zhenskie-aromaty' || arr_url[4] == 'muzhskie-aromaty')	{			
			t = 15;
			if (arr_url[4] == 'zhenskie-aromaty') b = 1;
			if (arr_url[4] == 'muzhskie-aromaty') b = 2;		
		}
	}
	document.getElementById('subblock_'+t).style.display = 'block';

	//$('#id_mail_menu_' + t).removeClass('fleft menu');
	$('#id_anketa_menu_' + t + '_' + b).addClass('submenu_active_link');
}
