function setLocation(url){
    window.location.href = url;
}

$(document).ready(function(){
	
	$.validator.addMethod('password', function(value, element) {
		var pass = $.trim(value);
		
        return !(pass.length>0 && pass.length < 6) || this.optional(element);
	});
	
	$.validator.setDefaults({
		submitHandler: 
			function(form) { form.submit(); 
		},
		
		/*set events*/
		onfocusout: false,
		onkeyup: false,
		onclick: false,
		
		ignoreTitle: true,
		
		/*error to show*/
		errorClass: "invalid",
		errorElement: "div",
		
		rules: {
			firstname: {required: true},
			lastname: {required: true},
			street_address: {required: true},
			city: {required: true},
			postcode: {required: true},
			phone: {required: true},
			account: {required: true, email:true},
			email_address: {required: true, email:true},
			pwd: {required: true, password: true},
			cofpwd: {required: true},
			zone_country_id: {required: true},
			gender: {required: true},
			size: {required: true},
			name: {required: true},
			email: {required: true, email:true}
		},
		messages: {
			required: "This field is required.",
			remote: "Please fix this field.",
			email: "Please enter a valid email address.",
			url: "Please enter a valid URL.",
			date: "Please enter a valid date.",
			dateISO: "Please enter a valid date (ISO).",
			number: "Please enter a valid number.",
			digits: "Please enter only digits.",
			creditcard: "Please enter a valid credit card number.",
			accept: "Please enter a value with a valid extension.",
			maxlength: $.validator.format("Please enter no more than {0} characters."),
			minlength: $.validator.format("Please enter at least {0} characters."),
			rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
			range: $.validator.format("Please enter a value between {0} and {1}."),
			max: $.validator.format("Please enter a value less than or equal to {0}."),
			min: $.validator.format("Please enter a value greater than or equal to {0}."),
			equalTo: "Please make sure your passwords match.",
			password: "Please enter 6 or more characters. Leading or trailing spaces will be ignored."
		}
		
	});
});

jQuery.validator.addMethod("isAMRZipCode", function(value, element) {   
var tel = /^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/;
return this.optional(element) || (tel.test(value));
}, "Incorrect Format! Corrent format is NNNNN or NNNNN-NNNN");

jQuery.validator.addMethod("isCANZipCode", function(value, element) {   
var tel = /^[a-zA-Z]{1}[0-9]{1}[a-zA-Z]{1} [0-9]{1}[a-zA-Z]{1}[0-9]{1}$/;
return this.optional(element) || (tel.test(value));
}, "Incorrect Format! Corrent format is ANA NAN");

function pressCaptcha(obj)
{
obj.value = obj.value.toUpperCase();
}


var flag=false; 
function DrawImage(ImgD, w, h){ 
	var image=new Image(); 
	image.src=ImgD.src; 
	if(w > 0 && h > 0) {
		if(image.width>0 && image.height>0){ 
			flag=true; 
			if(image.width/image.height>= w/h){
				if(image.width > w){
					ImgD.width=w;
					ImgD.height=(image.height*w)/image.width;
				}else{
					ImgD.width=image.width;
					ImgD.height=image.height;
				}
			}else{
				if(image.height>h){
					ImgD.height=h;
					ImgD.width=(image.width*h)/image.height;
				}else{
					ImgD.width=image.width;
					ImgD.height=image.height;
				}
			}
		}
	} else if(w <=0 && h > 0) {
		if(image.height > h){
			ImgD.height=h;
			ImgD.width=(image.width*h)/image.height;
		}else{
			ImgD.width=image.width;
			ImgD.height=image.height;
		}
	}else if(w > 0 && h <= 0){
		if(image.width > w){
			ImgD.height = (image.height * w)/image.width;
			ImgD.width = w;
		}else{
			ImgD.width=image.width;
			ImgD.height=image.height;
		}
	}else{
		ImgD.width=image.width;
		ImgD.height=image.height;
	}
}
