$(document).ready(function(){
	if (document.getElementById('fix-image')!=null && document.getElementById('fix-image')!='undefined'){
			$('div.fix-image').pngFix( );
			$('div.main-content').pngFix( );
			$('div.sidebar').pngFix( );
			
	}
});


function InStr(strSearch, charSearchFor)
{
            for (i=0; i < strSearch.length; i++)
            {
                  if (charSearchFor == Mid(strSearch, i, 1))
                  {
                        return i;
                  }
            }
            return -1;
}


function Mid(str, start, len)
{
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}


function checkForm() {	
		var recipe_name 	= $("input#recipe_name").val();	
		var recipe_contents 	= $("#recipe_contents").val();
		var recipe_body 	= $("#recipe_body").val();
		var recipe_body 	= $("#recipe_body").val();
		
		if (recipe_name == "") {
			alert ("Lütfen yemek adı girin");
			$("input#recipe_name").focus();
			return false;
		}
		if (recipe_contents == "") {
			alert ("Lütfen malzemeleri girin");
			$("#recipe_contents").focus();
			return false;
		}
		if (recipe_body == "") {
			alert ("Lütfen tarifi girin");
			$("#recipe_body").focus();
			return false;
		}
		if (InStr(recipe_contents, ",")<1){
				alert ("Lütfen malzemeleri virgül ile ayırarak giriniz.");
				$("#recipe_contents").focus();
				return false;
			
			}
		
		
		recipe_contents = recipe_contents.toLowerCase();
		

	if (recipe_contents.search("tamek")=="-1")
			{
				
				alert ("Malzemelerinizin içinde en az 1 adet Tamek ürünü bulunmak zorundadır.");
				$("#recipe_contents").focus();
				return false;
			
			}
		
			
		if (!($('#katilimOkey').attr('checked'))){
			 alert("Tarif ekleyerek yarışmaya katılmak için Katılım Şartları'nı <br /> kabul etmeniz gerekmektedir.")
			 $("#katilimOkey").focus();
			 return false;
			}

	
	
}
		
function checkForm2() {	
		var file 	= $("input#recipe_image").val();
		var recipe_name 	= $("input#recipe_name").val();	
		var recipe_contents 	= $("#recipe_contents").val();
		var recipe_body 	= $("#recipe_body").val();
		var mime = file.substr(file.lastIndexOf('.'));
		
		
		if (file == "") {
			alert ("Lütfen dosya seçiniz");
			$("input#recipe_image").focus();
			return false;
		}
		
		if (mime!= '.jpg' && mime!= '.JPG'){
			alert ("Göndereceğiniz resmin uzantısı .jpg olmalıdır");
			$("input#recipe_image").focus();
			return false;
		} 


		if (recipe_name == "") {
			alert ("Lütfen yemek adı girin");
			$("input#recipe_name").focus();
			return false;
		}
		if (recipe_contents == "") {
			alert ("Lütfen malzemeleri girin");
			$("#recipe_contents").focus();
			return false;
		}
		if (recipe_body == "") {
			alert ("Lütfen tarifi girin");
			$("#recipe_body").focus();
			return false;
		}
		
		

	
			if (InStr(recipe_contents, ",")<1)
			{
				
				alert ("Lütfen malzemeleri virgül ile ayırarak giriniz.");
				$("#recipe_contents").focus();
				return false;
			
			}
	
	
			recipe_contents = recipe_contents.toLowerCase();
	   if (recipe_contents.search("tamek")=="-1")
			{
				
				alert ("Malzemelerinizin içinde en az 1 adet Tamek ürünü bulunmak zorundadır.");
				$("#recipe_contents").focus();
				return false;
			
			}

			
			
		if (!($('#katilimOkey').attr('checked'))){
			 alert("Tarif ekleyerek yarışmaya katılmak için Katılım Şartları'nı <br /> kabul etmeniz gerekmektedir.")
			 $("#katilimOkey").focus();
			 return false;
			}
		
		
}

function checkForm3() {	
		var recipe_video = $("input#recipe_video").val();	
		var recipe_name 	= $("input#recipe_name").val();	
		var recipe_contents 	= $("#recipe_contents").val();
		var recipe_body 	= $("#recipe_body").val();
	
		
		if (recipe_video == "") {
			alert ("Lütfen videonuzun adresini girin");
			$("input#recipe_video").focus();
			return false;
		}
		
		if (recipe_name == "") {
			alert ("Lütfen yemek adı girin");
			$("input#recipe_name").focus();
			return false;
		}
		if (recipe_contents == "") {
			alert ("Lütfen malzemeleri girin");
			$("#recipe_contents").focus();
			return false;
		}
		if (recipe_body == "") {
			alert ("Lütfen tarifi girin");
			$("#recipe_body").focus();
			return false;
		}
		
		

			if (InStr(recipe_contents, ",")<1)
			{
				
				alert ("Lütfen malzemeleri virgül ile ayırarak giriniz.");
				$("#recipe_contents").focus();
				return false;
			
			}
			
			
					recipe_contents = recipe_contents.toLowerCase();
		
		if (recipe_contents.search("tamek")=="-1")
			{
				
				alert ("Malzemelerinizin içinde en az 1 adet Tamek ürünü bulunmak zorundadır.");
				$("#recipe_contents").focus();
				return false;
			
			}

			
	
		if (!($('#katilimOkey').attr('checked'))){
			 alert("Tarif ekleyerek yarışmaya katılmak için Katılım Şartları'nı <br /> kabul etmeniz gerekmektedir.")
			 $("#katilimOkey").focus();
			 return false;
			}
		
		
}

function checkForm4() {	
		var comment 	= $("#comment").val();
		var id= $("#recipeId").val();
		if (comment == "") {
			alert ("Lütfen yorum girin");
			$("#comment").focus();
			return false;
			
			
		}
	
	
	
			 $.ajax({
		   type: 'POST',
		   url: 'commentProcess.php',
		   data: 'comment='+comment+'&id='+id+'',	   	   
		   success: function(addcomment) { $('.comment-box').html(addcomment); }
		 });	
			 
			 
}

function checkForm5() {	
		var send_name 	= $("#send_name").val();
		var send_email = $("#send_email").val();
	
		if (send_name == "") {
			alert ("Lütfen arkadaşınızın adını ve soyadını girin");
			$("#send_name").focus();
			return false;
		}
		if (send_email == "") {
			alert ("Lütfen e-posta hanesini girin");
			$("#send_email").focus();
			return false;
		}
		if (emailCheck(send_email) == false) {
				alert('Lütfen e-posta adresinizi kontrol edip tekrar giriniz');
				$("input#send_email").focus();
				return false;
		}

	
}


// email adres kontrol

	function emailCheck (emailStr) {
		var emailPat=/^(.+)@(.+)$/
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
		var validChars="\[^\\s" + specialChars + "\]"
		var quotedUser="(\"[^\"]*\")"
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
		var atom=validChars + '+'
		var word="(" + atom + "|" + quotedUser + ")"
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

		var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
				return false
			}
		var user=matchArray[1]
		var domain=matchArray[2]

		if (user.match(userPat)==null) {
			return false
		}

		var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
				for (var i=1;i<=4;i++) {
					if (IPArray[i]>255) {
						return false
					}
				}
				return true
			}

		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			return false
		}

		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
			return false
		}

		if (len<2) {
			return false
		}

		return true;
	}
// email adres kontrol

// numeric control
function IsNumeric(sText){
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }


var ALERT_TITLE = "Hata";
var ALERT_BUTTON_TEXT = "OK";
var ALERT_MEMBER_TEXT = "ÜYE GİRİŞİ";

if(document.getElementById) {
	window.alert = function(txt, val) {
		if (val!= null) 
		createCustomAlert(txt, val);
		else{
			createCustomAlert(txt);	
		}

	}
}

function createCustomAlert(txt, val) {
	d = document;
	if(d.getElementById("modalContainer")) return;
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.height = document.documentElement.scrollHeight + "px";
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	h1 = alertObj.appendChild(d.createElement("h1"));
	//h1.appendChild(d.createTextNode(ALERT_TITLE));
	msg = alertObj.appendChild(d.createElement("p"));
	msg.innerHTML = txt;
	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "javascript:;";
	btn.onclick = function() { removeCustomAlert();return false; }
	
	if (val != null){
		btn2 = alertObj.appendChild(d.createElement("a"));
		btn2.id = "gotoLoginBox";
		btn2.appendChild(d.createTextNode(ALERT_MEMBER_TEXT));
		btn2.onclick = function() { removeCustomAlert();getLoginBox();return false; }
	}

	
}

// removes the custom alert from the DOM
function removeCustomAlert() {
	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}

function getLoginBox(){
		$("#tamekIdLogin").click();	
}
function getLoginBox2(val){
		if (val != null){
			tb_remove();
			$("#tamekIdLogin").click();	
		}
		else{
			$("#tamekIdLogin").click();		
		}
}