$(document).ready(function(){
	
	$(window).bind("load",function(){
		if($('.cycleAni').length>0){
			$('.cycleAni').imgCrossFade({aniDuration:600,aniInterval:4000});
		}						   
	});
	
	
	$('.frmWineOffer p').formValidate().parent().submit(function(){
		thsForm=$(this).children('p');
		if(thsForm.frmSubmit()){
			$('.woReturn').text("Processing...");
			expStr="";
			$('.frmWineOffer input[type="text"]').each(function(){expStr=expStr+$(this).val()+"{spl}";});
			console.log(expStr);
			$.ajax({ 
			  type: "POST", 
			  url: "media/scripts/baf.php", 
			  data: "func=sndFunction&inpVal="+expStr, 
			  success: function(data){ 
				if(data=="ok"){window.location="thankyou.php?dv=1";}
				else{$('.woReturn').text(data);}
			  } 
			});
		}
		else{
			$('.woReturn').text("Please ensure mandatory fields are fill in correctly.");	
		}
		return false;
	});
	
	
	$('.functionForm p').formValidate().parent().submit(function(){
		thsForm=$(this).children('p');
		if(thsForm.frmSubmit()){
			$('.fincReturnFrm').text("Processing...");
			expStr="";
			$('.functionForm input[type="text"]').each(function(){expStr=expStr+$(this).val()+"{spl}";});
			$('.functionForm select').each(function(){expStr=expStr+$(this).val()+"{spl}";});
			$('.functionForm input[type="radio"]:checked').each(function(){expStr=expStr+$(this).val()+"{spl}";});
			$.ajax({ 
			  type: "POST", 
			  url: "media/scripts/jqFunctions.php", 
			  data: "func=sndFunction&inpVal="+expStr, 
			  success: function(data){ 
				$('.fincReturnFrm').text(data);
				$('.functionForm input[type="text"]').val("");
			  } 
			});

		}
		else{
			$('.fincReturnFrm').text("Please ensure mandatory fields are fill in correctly.");	
		}
		return false;
	});
	
	
	$('a').click(function(){
		thisLink=$(this).attr('href');
		thisRel=$(this).attr('rel');
		if(thisLink!="" && thisLink!=" " && thisLink!="#")
		{
			if(thisRel=="nw"){window.open(thisLink);}
			else{window.location=thisLink;}
		}
		return false;
	});
	
});

function CheckEmail(inputemail) {
	AtPos = inputemail.indexOf("@");
	StopPos = inputemail.lastIndexOf(".");
	if (AtPos == -1 || StopPos == -1){return false;}
	else{return true;}
}