// Javascript Document
$(document).ready(function() {			
   $('.titletovalue').attr('value', function() {
		return (this.value == '' ? this.title : this.value);
   });    

   $('.titletovalue').blur(function() {
		$(this).attr('value', function() {
		 return (this.value == '' ? this.title : this.value);
	 });
   });

   $('.titletovalue').focus(function() {
	 $(this).attr('value', function() {
		 return (this.value == this.title ? '' : this.value);
	 });
   });
   
   $(".allprcatlinks").hover(
		function () {					
			$("#catthumb").attr("src",$(this).attr("name"));
			$("#all-prducts-img-preview").show();			
  		}, 
		function () {
			$("#catthumb").attr("src","images/empty.png");
			$("#all-prducts-img-preview").hide();
	});
   
   $(".mmAllPr").hover(
		function () {				
		$("#menubelirtgec").css("display", "block" );
			//$("#products-content").css("filter:alpha",opacity=30);
  	}, 
  	function () {
		$("#menubelirtgec").css("display", "none" );
	});
   
});
var listItemHeight = 22;	
function setSubMenuTop(index,total) {
	mm = document.getElementById("sm"+index);				
	itemCount =  mm.childNodes.length;				
	
	imgPrevPos =  index * listItemHeight;
	
	if (index+itemCount > total) {
		//alert(total-index-itemCount);
		mm.style.marginTop = (total-index-itemCount-1) * listItemHeight +"px";
		imgPrevPos = (total-itemCount) * listItemHeight;
	}				
	
	fark = (total * listItemHeight) - (imgPrevPos + 184);				

	if (fark < 0) imgPrevPos = imgPrevPos+fark;			
	document.getElementById("all-prducts-img-preview").style.marginTop = imgPrevPos +"px";		
}	

function contactFormSubmit() {
	$("#contactformresult").html("<img src='images/loading.gif' alt='Yükleniyor'>");
	var name	=	document.getElementById("contactname").value;
	var cmail	=   document.getElementById("contactmail").value;
	var cmessage	=   document.getElementById("contactmessage").value;
	var lang = "tr";
	$.ajax({									
		url: "ajax/sendmessage.php",	
		data: "lang="+lang+"&name="+name+"&email="+cmail+"&message="+cmessage,
		cache: false,
		success: function(html) {
			$("#contactformresult").html(html);
		}
	});
}


function checkForm() {
	t_name = document.getElementById("name").value;
	t_email = document.getElementById("mail").value;
	t_messsage = document.getElementById("ttmessage").value;
	
	if (!t_name) {
		alert("Lütfen adınızı giriniz.");
		document.getElementById("name").focus();
		return false;
	}
	if (!isValidEmail(t_email)) {
		alert("Lütfen geçerli bir e-posta adresi belirtiniz.");
		document.getElementById("mail").focus();
		return false;
	}
	if (!t_messsage) {
		alert("Lütfen iletinizi giriniz.");
		document.getElementById("ttmessage").focus();
		return false;
	}	
	return true;
}

	function suggestToAFriend() {
		lang	=   document.getElementById("sitelang").value;		
		var bDir = "";
		var name	=	document.getElementById("frename").value;
		var	cmail	=   document.getElementById("fremail").value;		
		var pname	=   document.getElementById("p_name").value;
		var pimg	=   document.getElementById("p_img").value;
		var plink	=   document.getElementById("p_link").value;
		
		if (!isValidEmail(cmail)) {
			alert("Arkadaşınızın e-posta adresi geçerli bir e-posta adresi değil.");
			return false;
		}
		
		if (!name) {
			alert("İsminizi girmemişsiniz.");
			return false;
		}
		
		$("#suggest-internal").html("<img src='"+bDir+"images/loading.gif' alt='Yükleniyor'>");
		$.ajax({									
			url: bDir+"ajax/sendsuggestion.php",	
			data: "lang="+lang+"&2name="+name+"&email="+cmail+"&p_name="+pname+"&p_img="+pimg+"&p_link="+plink,
			cache: false,
			success: function(html) {
				$("#suggest-internal").html(html);
			}
		});
	}
	function isValidEmail(strEmail){
	  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	  //strEmail = document.forms[0].email.value;
	
	   // search email text for regular exp matches
		if (strEmail.search(validRegExp) == -1) 
	   {
		//  alert('A valid e-mail address is required.\nPlease amend and retry');
		  return false;
		} 
    return true; 
}

