$(document).ready(function() {	
	//select all the a tag with name equal to modal
	$('img[name=modal]').click(function() {
//	e.preventDefault;
    $("#mydiv").load("/tender/tender.template.php", {'data': $(this).attr('id')}, function(){
		window.scroll(0,0);
		//Get the screen height and width
		var maskHeight = $(document).height();
		var maskWidth = $(window).width();
	
		//Set heigth and width to mask to fill up the whole screen
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		
		//transition effect		
		$('#mask').fadeIn(1000);	
	
		//Get the window height and width
		var winH = $(window).height();
		var winW = $(window).width();
              
		//Set the popup window to center
		$('#dialog').css('top',  winH/2-$('#dialog').height()/2);
		$('#dialog').css('left', winW/2-$('#dialog').width()/2);
	
		//transition effect
		$('#dialog').fadeIn(2000); 
	//if close button is clicked
	$('.window .close').click(function () {
		//Cancel the link behavior
		$('#mask, .window').hide();
		$('#requirements').val('нет');
		$('#fio').val('');
		$('#tel').val('');
		$('#email').val('');
		$('#max_price').val('0');
	});		
	
	//if mask is clicked
	$('#mask').click(function () {
		$(this).hide();
		$('.window').hide();
		$('#requirements').val('нет');
		$('#fio').val('');
		$('#tel').val('');
		$('#email').val('');	
		$('#max_price').val('0');
	});			

	$('#sendtender').click(function () {		
       var tovar = $('#tovar').val();
       var misto = $('#misto').val();
       var quantity = $('#tovar_quantity').val();
       var delivery = $('#delivery').val();
       var max_price = $('#max_price').val();
       var requirements = $('#requirements').val();
       var fio = $('#fio').val();
       var tel = $('#tel').val();
       var s_vr = $('#s').val();
       var do_vr = $('#do').val();
       var checked1 = $('#curent_firm').attr("checked");
       var checked = $('#all_firm1').attr("checked");
	   var email = $('#email').val();
       var word = $('#word').val();
	   var idfirmatov = $('#tovfirm').val();
	   var check = 0;
	   var error = '';
	   if (tovar == '')
	      {
		     error = error + 'товар';
		  }
          else 
		  {
		      check = check + 1;
		  }
	   if (misto == '')
	      {
		     error = error + ', город';
		  }
          else 
		  {
		      check = check + 1;
		  }
	   if (fio == '')
	      {
		     error = error + ', ФИО';
		  }
          else 
		  {
		      check = check + 1;
		  }
		if (check == 3)
		 {
		    $.ajax({type: 'POST',
			        url: '/tender/send_mail.php',
					data: "tovar="+tovar+"&misto="+misto+"&quantity="+quantity+"&delivery="+delivery+"&max_price="+max_price+"&requirements="+requirements+"&fio="+fio+"&tel="+tel+"&s_vr="+s_vr+"&do_vr="+do_vr+"&email="+email+"&word="+word+"&idfirmatov="+idfirmatov
					+"&checkall="+checked+"&checkfirm="+checked1
					});	 
		    		$('#mask').hide();
					$('.window').hide();
		 }
		 else 
		 {
		     alert('Вы не ввели ' + error);
		 } 
	 });
	
	 });
	 });
});


function InsertMailToTag( userName, domainName)
{
var EmailId;
var atSign = "&#64;"
var fullStop = "&#46";

EmailId = userName;
EmailId = "" + EmailId + atSign; 
EmailId = EmailId + domainName;

document.write( "<a href='mail" + "to:" + EmailId + "'>" + EmailId
+"</a>" );
}







