$(document).ready(function() { 
	var tips = $('.validateTips');
	function callback() {
			setTimeout(function() {
				$( "#effect" ).removeClass( "newClass" );
			}, 1500 );
		}

	$("#sepeteekle").click(function() { 
							if (document.getElementById('stokdurum').className=='Yok')
							{alert('Bu ürün stoklarda bulunmamaktadır.');  return;};
							  var http, ssnc;
							  var params='sp_id=' + document.getElementById('sp_id').value + '&sp_tanimi=' + document.getElementById('sp_tanimi').value + '&sp_fiyat=' + document.getElementById('sp_fiyat').value;
							  var browser = navigator.appName;
							  if(browser == "Microsoft Internet Explorer"){
								  http = new ActiveXObject("Microsoft.XMLHTTP");
							  }else{http = new XMLHttpRequest();}	
								
								  http.open('post', 'sepet/sepeto.php',true);
								  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
								  http.setRequestHeader("Content-length", params.length);
								  http.send(params);
								$("#sepeteekle" ).addClass( "wait");
								  http.onreadystatechange  = function() {
									  if(http.readyState == 4){
										 $("#sepeteekle" ).removeClass("wait");
										 document.getElementById('hint').innerHTML='&Uuml;r&uuml;n sepetinize eklendi..';
									  }
								  } //degisiklik.
							//	 http.send(null);
						})
	
	
		$("#yenile").click(function() { 
						 $('#fyenile').submit();
		})
		$(".oyontem").click(function() { 
						 $('#fyenile').submit();
		})

	$("#sepets #x").click(function() { 
								 //  	alert($(this).parent().parent().attr('id'));										
							  var http, ssnc, ssnc1;
							  var params='sp_num=' + $(this).parent().parent().attr('id');
							  var browser = navigator.appName;
							  if(browser == "Microsoft Internet Explorer"){
								  http = new ActiveXObject("Microsoft.XMLHTTP");
							  }else{http = new XMLHttpRequest();}	
								$(this).parent().parent().remove();
								  http.open('post', 'sepet/sepetc.php',true);
								  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
								  http.setRequestHeader("Content-length", params.length);
								  http.send(params);
								  http.onreadystatechange  = function() {
									  if(http.readyState == 2){
										document.getElementById('total').innerHTML= '&nbsp;';
									 //  document.getElementById('kdv').innerHTML= '&nbsp;';
									  //  document.getElementById('toplam').innerHTML= '&nbsp;';
									  }
									  if(http.readyState == 4  || http.readyState == 200){
										  $ssnc=http.responseText;
										  if ($ssnc==77)
										  	{ document.getElementById('sepetim').innerHTML='Sepetiniz bos'; }
										  else 
										  	{
												  $ssnc1 = $ssnc.split(',,');
												  document.getElementById('total').innerHTML= $ssnc1[0];
												 // document.getElementById('kdv').innerHTML= $ssnc1[1];
												 // document.getElementById('toplam').innerHTML= $ssnc1[2];
											}
										 // alert(http.responseText);
									  }
								  } //degisiklik.
							//	 http.send(null);
	})
	
	$('#devamet1').button().click(function (){

			if ($("#u1").val()=='') {
					document.getElementById("uyelogin").style.visibility="visible";  			
					$("#uyelogin").dialog('open');
					return;
					}
		
			if (document.getElementById('oye1').checked ) yontem = 1;
			if (document.getElementById('oye2').checked ) yontem = 2;
			if (document.getElementById('oye3').checked ) yontem = 3;
			
			switch (yontem)
				{
					case 1:
						location.href='?ynt=sepet&eyl=havale';
					break;
					case 2:
						location.href='?ynt=sepet&eyl=kkarti';
					break;
					case 3:
						location.href='?ynt=sepet&eyl=kkarti&id';
					break;
				}
				

		}
	
	)
	$("#havale").click(function() { 
			if ($("#u1").val()=='') {
					document.getElementById("nexttag").value="havale";
					document.getElementById("uyelogin").style.visibility="visible";  			
					$("#uyelogin").dialog('open');
					}
			else {location.href='?ynt=sepet&eyl=havale';}			
	});
	
	$("#kkarti").click(function() { 
			if ($("#u1").val()=='') {
					document.getElementById("nexttag").value="kkarti";
					document.getElementById("uyelogin").style.visibility="visible";  			
					$("#uyelogin").dialog('open');
					}
			else {
				location.href='?ynt=sepet&eyl=kkarti';
			}			
	});
	
	function checkLength1(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips(n + " uzunlugu en az "+min+" en fazla "+max+" olmalidir.");
				return false;
			} else {
				return true;
			}
	}
			
	
	function updateTips(t) {
			tips
				.text(t)
				.addClass('ui-state-highlight');
			setTimeout(function() {
				tips.removeClass('ui-state-highlight', 1500);
			}, 500);
		}

	$('#devamet').button().click(function(){
					var bValid = true;
					allFields = $([]).add('#s-isim').add('#s-soyisim').add('#s-adres').add('#s-sehir').add('#s-ulke').add('#-vergino').add('#s-vergidaire');

					allFields.removeClass('ui-state-error');
										
					bValid = bValid && checkLength1($('#s-isim'),"İsim",3,30);
					bValid = bValid && checkLength1($('#s-soyisim'),"Soyisim",3,30);
					bValid = bValid && checkLength1($('#s-adres'),"Adres",3,255);
					bValid = bValid && checkLength1($('#s-sehir'),"Şehir",3,30);
					
					bValid = bValid && checkLength1($('#s-vergino'),"TC.Kimlik / Vergi No",3,30);					
				
					if (bValid) {$('#siparis').submit();}
								}
	 )
}); //ready...
 
 
