//Front end Java Script File

$(document).ready(function() {
    /*	var val_menu ="";
    $(".menu ul li").hover(
    function () {	
    var val_menu=$(this).attr("class");
								   
    $("."+val_menu).prepend("<span id='menu_id'></span>");
    },
    function () {
    $("#menu_id").remove();
    }
    );*/

    $(".footer_bottom_black").click(function(){
        window.location= 'http://renoveermijnkeuken.nl/afspraak_maken/';
       
    });
    var i = 0;
    jTextFlip(i);

    if($('#mycarousel').length>0)
    $('#mycarousel').jcarousel();
    $(".jcarousel-prev").css("display","none");
    $(".jcarousel-prev").bind('click', function() {
        $(".carousel_txt_right").fadeOut(10, function() { $(".carousel_txt_right").show(700); });
        $(".carousel_txt_left").fadeOut(10, function() { $(".carousel_txt_left").show(700); });
       if($("#voorbeeld").attr("href")=='../voorbeeld-detail3'){
            $("#voorbeeld").attr("href", "../voorbeeld-detail2");
       }else if($("#voorbeeld").attr("href")=='../voorbeeld-detail2'){
           $("#voorbeeld").attr("href", "../voorbeeld-detail");
           $(".jcarousel-prev").css("display","none");
       }
        //$(".jcarousel-prev").css("display","none");
        $(".jcarousel-next").css("display","block");
    });

    $(".jcarousel-next").bind('click', function() {
        $(".carousel_txt_right").fadeOut(10, function() { $(".carousel_txt_right").show(700); });
        $(".carousel_txt_left").fadeOut(10, function() { $(".carousel_txt_left").show(700); });
       if($("#voorbeeld").attr("href")=='../voorbeeld-detail'){
            $("#voorbeeld").attr("href", "../voorbeeld-detail2");
       }else if($("#voorbeeld").attr("href")=='../voorbeeld-detail2'){
           $("#voorbeeld").attr("href", "../voorbeeld-detail3");
           $(".jcarousel-next").css("display","none");
       }
        
        $(".jcarousel-prev").css("display","block");
        //$(".jcarousel-next").css("display","none");

    });
    $(".popup_close").bind('click', function() {

        $("#popup_open").css({ "display": "none" });

    });

    $("#search_overlay_close").bind('click', function() {

        $("#search_overlay").css({ "display": "none" });

    });


    $('#uw_postcode').keypress(function(e) {

        if (e.which == 13) {
            validatezipform();
        }

    });
});

function jTextFlip(i) {
    if (i == 2) {
        i = 0;
    }
    $("#jText span").css("display", "none");
    $("#jText span").eq(i).css("display", "block");
    i++;
    
    setTimeout("jTextFlip("+ i +")", 5000);
  

}
	
function validatezipform()
{
	

   var flag=true;
   if(!checkTextBox("uw_postcode"))
	    flag=false; 
   
   if(!flag)
   {
	  return flag;
   }
   else
	{
	var post=$("#uw_postcode").val();
	
	   $.ajax(
			   {
			   type: "POST",
			   url: "/postcodesearch.php",
			   data:{post:post},
			   success: function(msg)
			   {
				  
				   var response = msg;
					// alert(response);
					$("#search_overlay").css({"display":"block"})
					$("#zip_search").html(response);
			   }
			   });
	   
	}
 
}


function validateForm()
{

   var flag=true;
   if(!checkTextBox("naam"))
	    flag=false; 
   if(!checkTextBox("adres"))
	    flag=false; 
   if(!checkTextBox("nr"))
	    flag=false; 
   if(!checkTextBox("postcode"))
	    flag=false; 
   if(!checkTextBox("woonplaats"))
	    flag=false; 
   if(!checkTextBox("telefone"))
	    flag=false;
   if(!checkPhoneFormat("telefone"))
	   flag=false;
   if(!checkTextBox("mobiel"))
	    flag=false;
   if(!checkPhoneFormat("mobiel"))
	   flag=false;		
   if(!checkTextBox("email"))
	    flag=false;
   if(!checkEmailFormat("email"))
	    flag=false;
   if(!flag)
   {

	  return flag;
	  
   } 
   else
   {
	   naam=$("#naam").val();
	   adres=$("#adres").val();
	   nr=$("#nr").val();
	   postcode=$("#postcode").val();
	   woonplaats=$("#woonplaats").val();
	   mobiel=$("#mobiel").val();
	   email=$("#email").val();
	   toemail=$("#toemail").val();
	
	   $.ajax(
			   {
			   type: "POST",
			   url: "thankyou.php",
			   data:{naam:naam,adres:adres,nr:nr,postcode:postcode,woonplaats:woonplaats,mobiel:mobiel,email:email,toemail:toemail},
			   success: function(msg)
			   {
				   var response = msg;
				   
					document.contactus.reset()
					 $("#thanks_mssg").css({"display":"block"});

			   }
			   });
	
   }
   
  
   return false;
}




function validateFormcontact()
{
   store=$("input[name=store]:checked").val();	
   var flag=true;
   if(!checkTextBox("naam"))
	    flag=false; 
   if(!checkTextBox("adres"))
	    flag=false; 
   //if(!checkTextBox("nr"))
	//    flag=false; 
   if(!checkTextBox("postcode"))
	    flag=false; 
   if(!checkTextBox("woonplaats"))
	    flag=false; 
   if(!checkTextBox("telefone"))
	    flag=false;
   if(!checkPhoneFormat("telefone"))
	   flag=false;
  // if(!checkTextBox("mobiel"))
	//    flag=false;
   //if(!checkPhoneFormat("mobiel"))
	//   flag=false;		
   if(!checkTextBox("email"))
	    flag=false;
   if(!checkEmailFormat("email"))
	    flag=false;
	if(checkRadioGroup("store"))
		flag=false;
    if(typeof(store)=="undefined")
	   {
		 $("#postcode").addClass("error_text");
		 flag=false;		  
	   }	
   if(!flag)
   {

	  return flag;
	  
   } 
   else
   {
	   naam=$("#naam").val();
	   salutation=$("#salutation").val();
	   adres=$("#adres").val();
	   nr=$("#nr").val();
	   postcode=$("#postcode").val();
	   woonplaats=$("#woonplaats").val();
	   telefone=$("#telefone").val();
	   mobiel=$("#mobiel").val();
	   email=$("#email").val();
	   toemail=$("#toemail").val();
	   newsletter=$('input:checkbox[name=newsletter]:checked').val();
	   
	   
	
	   
	   $.ajax(
			   {
			   type: "POST",
			   url: "mail_contact.php",
			   data:{salutation:salutation,naam:naam,adres:adres,nr:nr,postcode:postcode,woonplaats:woonplaats,telefone:telefone,mobiel:mobiel,email:email,toemail:toemail,newsletter:newsletter,store:store},
			   success: function(msg)
					{
						var response = msg;
						document.contactus.reset()
						$("#thanks_mssg").css({
							"display":"block"
						});
						$("#conversion_code").append('<iframe src="googleservices.php" width="1" height="1" style="width:1px; height:1px; border:0px; z-index: -1000; position: absolute; top:-5000px; left:-5000px;"></iframe>');
					}
			   
			   });
	
   }
   
  
   return false;
}
function close_cont()
{
	//alert("JERe");	
	 $("#thanks_mssg").css({"display":"none"});
}

function checkTextBox(textidval)
{
	var textvalue=$("#"+textidval).val();
	if(textvalue=="")
	{
		//$("#"+textidval).css({"background":"#FF99CC","border":"1px dashed red"});
		$("#"+textidval).addClass("error_text");
		
		return false;
	}
	else if(textvalue=="uw postcode")
	{
		$("#"+textidval).addClass("error_text");
		return false;
	}
	else
	{
		$("#"+textidval).removeClass("error_text");
		
		return true;
	}
}

function checkRadioGroup(frm,radioval)
{
	var radiolength=frm.length;
	//alert(radiolength);
	var checkval='';
	for(var i=0;i<radiolength;i++)
	{
		if (frm[i].checked)
		{
			checkval=frm[i].value;
		} 
		
	}
	$("#"+radioval+"_container").removeClass("error_group");
	//$("#"+radioval+"_container").css({"border":"none"});
	$("#"+radioval+"_text").removeClass().addClass("other_text_content");
	
	if(checkval=="")
	{
		
		$("#"+radioval+"_container").addClass("error_group");
		//$("#"+radioval+"_container").css({"border":"1px dashed red"})
		$("#"+radioval+"_text").removeClass().addClass("other_text_content");
		
		return false;
	}
	else
	{
		$("#"+radioval+"_container").removeClass("error_group");
		//$("#"+radioval+"_container").css({"border":"none"});
		$("#"+radioval+"_text").removeClass().addClass("other_text_content");
		
		if(checkval=="anders")
		{
			var txtval=$("#"+radioval+"_text").val();
			if(txtval=="")
			{
				$("#"+radioval+"_text").addClass("other_text_content error_text");
				
				return false;
			}
			else
			{
				$("#"+radioval+"_container").removeClass("error_group");
				//$("#"+radioval+"_container").css({"border":"none"});
				$("#"+radioval+"_text").removeClass().addClass("other_text_content");
				
				return true;
			}
		}
		return true; 
	}
	
}

function checkPhoneFormat(textidval)
{
	var phonePattern = /^((\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$)/i;
	var elementValue=$("#"+textidval).val();
	   if(!phonePattern.test(elementValue))
	   {
		   $("#"+textidval).addClass("error_text");
		  
		   return false;
	   }
	   else
	   {
		   return true;
	   }
}

function checkEmailFormat(textidval)
{
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
   var elementValue=$("#"+textidval).val();
   if(!emailPattern.test(elementValue))
   {
	   $("#"+textidval).addClass("error_text");
	  
	   return false;
   }
   else
   {
	   return true;
   }
}
$(document).ready(function() 
	{
		$(".pagenav ul li").bind('click',function() { 
			
			var idv = $(this).attr("id");
			
			var temp = idv.split("_");
			idv = temp[1];
			
			door_gallery(idv);
		});
		door_gallery("1");
	});
function door_gallery(idv)
{
	//console.log(idv);
	if(idv=='prev')
	{	
		var temp = $(".act").attr("id");
		temp = temp.split("_");
		temp = parseInt(temp[1]);
		if(temp<=1)
		{
			return ;
		}
		else
		{
			idv=temp-1;
		}
	}	
	if(idv=='next')
	{
		var temp = $(".act").attr("id");
		temp = temp.split("_");
		temp = parseInt(temp[1]);
		var tem = $(".pagenav ul li").length;
		tem = parseInt(tem)-2;
		if(temp>=tem)
		{
			return ;
		}
		else
		{
			idv=temp+1;
		}
	}
	
	$(".pagenav ul li").removeClass("act");
	$(".img_pagenav").css({"display":"none"});	
	$("#gal_"+idv).css({"display":"inline"});
	$("#pag_"+idv).addClass("act");
}


$(document).ready(function() 
		{
			$(".pagenav_gal ul li").bind('click',function() { 
				var idv = $(this).attr("id");
				var temp = idv.split("_");
				idv = temp[1];
				surface_gallery(idv,"gal");
			});
			$(".pagenav_kun ul li").bind('click',function() { 
							var idv = $(this).attr("id");
							var temp = idv.split("_");
							idv = temp[1];
							surface_gallery(idv,"kun");
						});
			$(".pagenav_com ul li").bind('click',function() { 
				var idv = $(this).attr("id");
				var temp = idv.split("_");
				idv = temp[1];
				surface_gallery(idv,"com");
			});
			
			$("#surfaces_tabs ul li").bind("click",function(){ 
				var sur =$(this).attr("id");
				$(".tabs_class").css({"display":"none"});
				if(sur=="kun")  
				{
				  $("#kun").addClass("act");
				  $("#gal").removeClass("act");
				  $("#com").removeClass("act");
				  surface_gallery("1","kun");
				}
				if(sur=="gal")  
				{
					$("#gal").addClass("act");
				    $("#kun").removeClass("act");
				    $("#com").removeClass("act");	
					  surface_gallery("1","gal");
				}
				if(sur=="com")  
				{
					$("#com").addClass("act");
				    $("#gal").removeClass("act");
				    $("#kun").removeClass("act");
					surface_gallery("1","com");
				}
			});
			surface_gallery("1","gal");

		});

	function surface_gallery(idv,gal)
	{
		//console.log(idv);
		$("#tab_"+gal).css({"display":"inline"});
		if(idv=='prev')
		{	
			var temp = $(".pagenav_"+gal+" .act").attr("id");
			temp = temp.split("_");
			temp = parseInt(temp[1]);
			if(temp<=1)
			{
				return ;
			}
			else
			{
				idv=temp-1;
			}
		}	
		if(idv=='next')
		{
			var temp = $(".pagenav_"+gal+" .act").attr("id");
			temp = temp.split("_");
			temp = parseInt(temp[1]);
			var tem = $(".pagenav_"+gal+" ul li").length;
			tem = parseInt(tem)-2;
			if(temp>=tem)
			{
				return ;
			}
			else
			{
				idv=temp+1;
			}
		}
		
		$(".pagenav_"+gal+" ul li").removeClass("act");
		$(".img_pagenav_werk").css({"display":"none"});	
		$("#"+gal+"_"+idv).css({"display":"inline"});
		$("#pag1"+gal+"_"+idv).addClass("act");
	}



function animatescroll(textidval)
{
	$('html, body').animate({
		scrollTop: $("#"+textidval).offset().top
		}, 2000);
}


function getpostcode()
{
	var post=$("#postcode").val();
	
	if(post.length>=4)
	{
 $.ajax(
			   {
			   type: "POST",
			   url: "postcode.php",
			   data:{post:post},
			   success: function(msg)
			   {
				   var response = msg;
					// alert(response);
					//document.contactus.reset()
					// $("#thanks_mssg").css({"display":"block"});
					$("#getstorelist").html(response);
			   }
			   });
	}
	else
	{
		//$("#getstorelist").html("Please enter min of 4 chars");
	}
}

