// JavaScript Document//clear text box on click
function clearText(field){

if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;

}


function setVisibility(id, value){

document.getElementById(id).style.display=value
	//$(id).css('visibility',value);
}




// Products Slide
$(document).ready(function(){  
        //To switch directions up/down and left/right just place a "-" in front of the top/left attribute  
        //Vertical Sliding  
        $('.boxgrid.slidedown').hover(function(){  
            $(".cover", this).stop().animate({top:'30px'},{queue:false,duration:300});  
        }, function() {  
            $(".cover", this).stop().animate({top:'0px'},{queue:false,duration:300});  
        }); 
		
		$('.eachprod-box.slidedown').hover(function(){  
            $(".cover", this).stop().animate({bottom:'0px'},{queue:false,duration:300});  
        }, function() {  
            $(".cover", this).stop().animate({bottom:'-25px'},{queue:false,duration:300});  
        }); 
       
    });  
		


Cufon.replace('.cufon-font', {hover:true});
Cufon.replace('h1', {hover:true});
Cufon.replace('h2', {hover:true});
Cufon.replace('h3', {hover:true});


$(document).ready(function(){
	$('.eachprod-box').click(function(){
		window.location.href = $(this).find(".slidedown_a").attr('href');
	});
});

function fixImage(img){
	img.src="/template_images/no_image.jpg";
}

function fixAnchorImage(a){	
	$(a).css('background','url("/template_images/no_image.jpg") no-repeat scroll center center transparent;');
}

$(document).ready(function(){
	$('.slider_hidden').each(function(){
		$(this).slideUp(10);
	});
	
	$('.slidedown').hover(function(){
		$('.slider_hidden',this).slideDown(100);
	},function(){
		$('.slider_hidden',this).slideUp(100);
	});
	
	$(".slider_ctn").click(function(){
		var href = $(this).parent().find("a.slider_img").attr("href");
		
		if(href)
			window.location.href=href;
	}); 
	
});


/* Quantity field validation  */


function IsNumeric(input){
    var RE = /^-{0,1}\d*\d+$/;
    return (RE.test(input));
}


function validate()
{
	var quantity=document.mycart.cart_quantity.value;
    if (!IsNumeric(quantity)) 
    {   
    alert("Enter a valid number");
    document.mycart.cart_quantity.focus();
    return false;
    }
    return true;
} 

$(document).ready(function(){
	var count = $("#latest_prod_ctn .eachprod-box").size();
	
	if(count>0){
		$("#latest_prod_ctn").removeClass("hide");
	}
	
	count = $("#latest_specials_ctn .eachprod-box").size();
	
		
	if(count>0){
		$("#latest_specials_ctn").removeClass("hide");
	}	
	
});


//scroller
$(document).ready(function() {
	$('.horizontal_scroller').SetScroller({	velocity: 	 240,
		direction: 	 'horizontal',
			startfrom: 	 'right',
			loop:		 'infinite',
			movetype: 	 'linear',
			onmouseover: 'pause',
			onmouseout:  'play',
			onstartup: 	 'play',
			cursor: 	 'pointer'
		});
});

$(window).load(function() {
	$('#slider').nivoSlider({
		effect:'slideInLeft' // Specify sets like: 'fold,fade,sliceDown'
	});
});



/*//slider corner
$(document).ready(function() {
	$('.boxcaption').corner("bl 10px");
	$('.boxcaption').corner("br 10px");
});*/

$(document).ready(function(){
	$("#salesforce_form").submit(function(){
		return check_required_fields(this);		 
	});
});

function check_required_fields(form1){
	var required=form1.require.value.split(",");
	var i;
	flag=true;
	$("input",form1).each(function(){
		if(required.indexOf(this.name) >= 0){
			if(flag!=false)
			{
				var field = this.name;				
				field = field.replace(/_/g," ");				
				/*field = field.charAt(0).toUpperCase() + field.slice(1);*/				
				if((this.name.indexOf('email') >= 0) && (this.value.search(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/)==-1)){					
					alert("Please enter valid "+field);
					flag=false;
					this.focus();
				}
				if((this.name.indexOf('phone') >= 0) && (this.value.search(/[^\d]/)!=-1)){
					alert("Please enter valid "+field);
					flag=false;
					this.focus();
				}
				if((this.name.indexOf('postcode') >= 0) && (this.value.search(/[^\d]/)!=-1)){
					alert("Please enter valid "+field);
					flag=false;
					this.focus();
				}
				if (this.value=="") {				
					flag=false;
					alert("Please Enter "+field);
					this.focus();
				}
				if(this.type == "checkbox")
				{
					if(this.checked == false)
					{
						flag=false;
						alert("Please check required checkbox");
						this.focus();
					}
				}
			}
			
		}
		
	});
	if(flag){
		$("textarea",form1).each(function(){
			if(required.indexOf(this.name) >= 0){
				var field = this.name;				
				field = field.replace(/_/g," ");				
				if (this.value=="") {				
					flag=false;
					alert("Please Enter "+field);
					this.focus();
					return false;
				}
			}
		});
	}
	
	return flag;
}

