$(function(){
	
	$("#pur_but").click(function(){
		errors = '';
		
		if($("#uname").val()==""){
			errors = errors+'- You must enter your name.\n';
		}
		if($("#address").val()==""){
			errors = errors+'- You must enter your address.\n';
		}
		if($("#phone").val()==""){
			errors = errors+'- You must enter your phone.\n';
		}
		if($("#email").val()==""){
			errors = errors+'- You must enter your email.\n';
		}else{
			//check for valid email
			if(isValidEmailAddress($("#email").val())){
			}else{
				errors = errors+'- You must enter a valid email.\n';
			}
		}
		if($("#installer").val()==""){
			errors = errors+'- You must enter the name of your supplier.\n';
		}
		if($("#suptel").val()==""){
			errors = errors+'- You must enter your suppliers phone number.\n';
		}
		if($("#totprice").val()==""){
			errors = errors+'- You must enter the total price you paid.\n';
		}else{
			var intRegex = /^\d+$/;
var floatRegex = /^((\d+(\.\d *)?)|((\d*\.)?\d+))$/;
			if(intRegex.test($("#totprice").val()) || floatRegex.test($("#totprice").val())) {
			}else{
				errors = errors+'- The total price you paid must be a number.\n';
			}
		}
		if($("#cond").is(':checked')){
			
		}else{
			errors = errors+'- You must agree to the conditions.\n';
		}
		
		if(errors==''){
			$("#pformdiv").hide("blind",function(){
			$.post("pro_claim.php", $("#pform").serialize(), function(data){
			$("#pformdiv").html(data);
			$("#pformdiv").show("blind");	
			});
		});
		}else{
			alert(errors);
		}
		
	});
	
});



//function subo(){
//if($("#cond").is(':checked')){
// if($("#uname").val()==""){
//  alert("You must enter your name.");
// }else{
//  $.post("pur.php", $("#pform").serialize(), function(data){
//   $("#former").hide("blind", function(){
//    $("#thanksshow").show("blind");
//   });
//  });
// }
// }else{
// alert("You must agree to the conditions to continue.");
//}
//}
function show_conde(){
 $("#conds").toggle("blind");
}

function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
return pattern.test(emailAddress);
}

function correct_email(){
	cem = $("#corremail").val();
	cid = $("#corrid").val();
	$.post("correct_email.php", {xem: cem, xid: cid}, function(data){
		$("#pformdiv").hide("blind", function(){
			$("#pformdiv").html(data);
			$("#pformdiv").show("blind");			
		});
	});
	
}

var scrollSpeed = 20;
    var step = 1;
    var current = 0;
    var imageWidth = 3750000;
    var headerWidth = 660;      
 
    var restartPosition = -(imageWidth - headerWidth);
 
    function scrollBg(){
        current -= step;
        if (current == restartPosition){
            current = 0;
        }
 
        $('#runner').css("background-position",current+"px 0");
    }
 
    var init = setInterval("scrollBg()", scrollSpeed);
