
var inner_send='';

function SendFriendLink(form){

if (form.email.value=='Введите e-mail друга'||form.email.value==''){
	alert('Введите Email');
	form.email.focus();
	return false;
	}
	
	if (form.name.value=='От кого'||form.name.value==''){
		alert('Введите ваше имя');
		form.name.focus();
		return false;
	}

	var params=$(form).serialize();
	
	inner_send=$('#send_link').html();
	$('#send_loader').html('<img src="/ajax/img/loader1.gif" alt="Загрузка..."/>');	
	params=params+'&link='+window.location;			
	$.ajax({
		dataType:'html', 
		url: 'ajax/send_friend_link.php',
		cache: false,
		async:true,
		type:"post",
		data: params,
		success:SendLinkOk,
		error:SendLinkError
	}); 

	function SendLinkError(){			
		$('#send_loader').html('');
		$('#send_link').html('<div class="send_message">Произошла ошибка при отправке ссылки. Проверьте введенные данные или попробуйте позже.</div>');		
		setTimeout(function(){$('#send_link').html(inner_send);}, 5000)
	}


	function SendLinkOk(data){	
	$('#send_loader').html('');	
	if (parseInt(data)==1)
		$('#send_link').html('<div class="send_message">Ссылка Вашему другу успешно отправлена!</div>');
		else
		SendLinkError();
	}	
	
 return false;        
}


function zakcallback(){
$("#yes").text("Заказать");
$("#message").text('');
confirm("<form id=callbackform name=callbackform action=cb method=POST enctype=multipart/form-data><table width=100%><tr><td><p>Имя</p><input id=name name=name title=Ваше имя type=text></td></tr><tr><td><p>Телефон</p><input id=phone name=phone title=Ваш телефон type=text></td></tr><tr><td><p>Комментарии</p><textarea id=comment name=comment title=Комментарий></textarea></td></tr></table></form>", function(){sndfrcb();});
 $('#confirm-container').height(300);
 $('#confirm-container').width(270);
}

function sndfrcb(){
var nm = $("#name").val();
var tl = $("#phone").val();
var cm = $("#comment").attr("value");
$.post("cb.php", {nam: nm, tel: tl, comm: cm},
  function(data){
  //  alert("Data Loaded: " + data);
  $("#message").hide();
  $("#message").show();
if(data=='OK'){
$("#message").html('<p style="color: #339933">Заявка отправлена.</p>');
$("#name").val('');
$("#phone").val('');
$("#comment").attr("value",'');
$("#callbackform").hide();
$("#yes").hide();

window.setTimeout(function(){$.modal.close()}, 3000);
//$.modal.delay(2000).close();
}else{
 $('#confirm-container').height(300);

    $("#message").html(data);
}
  }   );
}


function confirm(message, callback) {
	
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["15%",],
        zIndex: [1000],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container',
		onShow: function (dialog) {
			var modal = this;
			$('#confirm-overlay').css("background-color",'#000');
			$('#confirm-overlay').fadeTo("slow",0.8);
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {

				 	callback.apply();
				}
				// close the dialog
				//modal.close(); // or $.modal.close();
			});
		}
	});
}






function getskidka(){
$("#yes").show();
$("#no").show();
$("#zag").show();
$("#yes").text("Узнать");
$("#zag").text('Узнать скидку');
$("#message").text('Оставьте свои контактные данные и мы Вас обязательно известим, как только на этот товар будет скидка');
confirm_skidka("<form id=callbackform name=callbackform action=skidka method=POST enctype=multipart/form-data><table width=100%><tr><td><p>Имя</p><input id=name name=name title=Ваше имя type=text></td></tr><tr><td><p>Телефон</p><input id=phone name=phone title=Ваш телефон type=text></td></tr><tr><td><p>E-mail</p><input type='text' id='email' name='email' value=''></td></tr></table></form>", function(){snd_skidka();});
 $('#confirm-container').height(320);
 $('#confirm-container').width(270);
}

function snd_skidka(){
var nm = $("#name").val();
var tl = $("#phone").val();
var em = $("#email").val();
var pr = $("#content .cpt_product_name").html();
var lk = window.location.href;



$.post("skidka.php", {nam: nm, tel: tl, mail: em, prod:pr,link:lk},
  function(data){
  //  alert("Data Loaded: " + data);
  $("#message").hide();
  $("#message").show();
if(data=='OK'){
$("#message").html('<p style="color: #339933">Заявка отправлена.</p>');
$("#name").val('');
$("#phone").val('');
$("#email").val('');
$("#callbackform").hide();
$("#yes").hide();

window.setTimeout(function(){$.modal.close()}, 3000);
//$.modal.delay(2000).close();
}else{
 $('#confirm-container').height(320);

    $("#message").html(data);
}
  }   );
}


function confirm_skidka(message, callback) {
	
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["15%",],
        zIndex: [1000],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container',
		onShow: function (dialog) {
			var modal = this;
			
			$('#confirm-overlay').css("background-color",'#000');
			$('#confirm-overlay').fadeTo("slow",0.8);
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {

				 	callback.apply();
				}
				// close the dialog
				//modal.close(); // or $.modal.close();
			});
		}
	});
}




function FastOrder() {
			
			var val1=$("#fastorderform input").get(0).value;
			var val2=$("#fastorderform input").get(1).value;
			
			if (val1=='Ваше имя'||val1==''){				
				alert('Необходимо заполнить оба поля');
				$("#fastorderform input").get(0).focus();
				return false;
			}
			
			if (val2=='Ваш телефон'||val2==''){
				alert('Необходимо заполнить оба поля');
				$("#fastorderform input").get(1).focus();
				return false;
			}									
			
			var objForm = $('.product_wrpap form').get(0);
			
			if (!objForm)
				return true;
			var r_productParam = getElementsByClass('product_option', objForm);
			var query = '';
			for (var i = r_productParam.length - 1; i >= 0; i--) {
				if (!parseInt(r_productParam[i].value))
					continue;
				if (r_productParam[i].name)
					query += '&' + r_productParam[i].name + '='
							+ parseInt(r_productParam[i].value);
			}
			var r_productQty = getElementByClass('product_qty', objForm);
			if (r_productQty) {
				r_productQty = parseInt(r_productQty.value);
				if (r_productQty > 1) {
					query += '&product_qty=' + r_productQty;
				}
			}
			var url = ORIG_LANG_URL
					+ set_query('?ukey=cart&view=noframe&action=add_product&'
									+ query + '&productID='
									+ objForm.getAttribute('rel'), '');
			openFadeIFrame(url);
            closeFadeIFrame();
            //$("#message").text('Оставьте свои контактные данные и наш менеджер свяжется с вами после оформления заказа');
            //$("#zag").text("Оформить заказ");
            //$("#yes").text("Оформить заказ");
            //$("#yes").width(140);
            //$("#no").hide();            					
			//confirm("<form id='fastorderform' name=fastorderform action=fastorder method=POST enctype=multipart/form-data><table width=100%><tr><td><p>Имя</p><input id=name name=name title=Ваше имя type=text></td></tr><tr><td><p>Телефон</p><input id=phone name=phone title=Ваш телефон type=text></td></tr></table></form>", function(){fastorder();});
			//$('#confirm-container').height(300);
			//$('#confirm-container').width(300);
			$('#confirm-overlay').css("background-color","#222222");
			//window.setTimeout(function(){$.modal.close();$("#no").show();location.reload();}, 3000);								
			window.setTimeout(fastorder, 1000);
			
		
		}
	
	
	

		function fastorder(){		
			
						
			
			$.post("quick_conf.php",$("#fastorderform").serialize(),ShowAnswer);				
			
		}
	
		function ShowAnswer(data){		
			$("#zag").show();
			$("#yes").hide();
			$("#no").hide();            					
			$("#zag").text('Быстрый заказ');
			$('#confirm-container').width(300);
			
			if (data=='ok') 
				confirm('Спасибо за заказ. Наш менеджер скоро с вами свяжется', function(){$.modal.close()});					
			else
				confirm(data, function(){$.modal.close()});					
			//window.setTimeout(function(){$.modal.close()}, 3000);
		}
	
		
		
		function orderonestep(){
			window.location = '/cart/';
		}
		
		

		
function GoFilter(){

var tagsline='';
$('#leftcol input:checked').each(																	
function() {tagsline=tagsline+(tagsline?(','+encodeURIComponent(this.value.toLowerCase())):encodeURIComponent(this.value.toLowerCase()));							}

);
javascript:location.href='/search/?tag='+tagsline+'&filter=1';
}



function showsizes() {		
	
	$('#sizes-table').modal({
		/*closeHTML: "<a href='#' style='position:absolute;' title='Close' class='modal-close'>x</a>",*/
		position: ["15%",],
		zIndex: [1000],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container',
		minHeight:"80%",
		minWidth:"60%",
		overlayClose:true,
		onShow: function (dialog) {															
			$('#sizes-table').html('<img src="/ajax/img/loader2.gif" alt="Загрузка..."/>');	
			$('#confirm-overlay').css("background-color",'#000');
			$('#confirm-overlay').fadeTo("slow",0.8);						
			$('#confirm-container').css("overflow","auto");									
			$.post("sizes_table.php", {},function(data){$("#sizes-table").html(data);});															
		}
	});
}
