$(document).ready(function(){

$("p.linka").hover(function(){

		//alert("Hello");
		$(this).css("background","url(/images/dealer_hover.jpg) no-repeat 13px 10px");
		},function(){

		//alert("Hello");
		$(this).css("background","url(/images/dealer1.jpg) no-repeat 13px 10px");
	});

$("p.linkb").hover(function(){

		//alert("Hello");
		$(this).css("background","url(/images/find_store_hover.jpg) no-repeat 13px 10px");
		},function(){

		//alert("Hello");
		$(this).css("background","url(/images/find_store.jpg) no-repeat 13px 10px");
	});

$("p.linkc").hover(function(){

		//alert("Hello");
		$(this).css("background","url(/images/comercial_hover.jpg) no-repeat 13px 10px");
		},function(){

		//alert("Hello");
		$(this).css("background","url(/images/comercial.jpg) no-repeat 13px 10px");
	});

$("p.linkd").hover(function(){

		//alert("Hello");
		$(this).css("background","url(/images/customer_hover.jpg) no-repeat 13px 10px");
		},function(){

		//alert("Hello");
		$(this).css("background","url(/images/customer.jpg) no-repeat 13px 10px");
	});
	
/*	$("form").find(".required").keyup(function(){
		if(this.value == "")
		{
    		$(this).css("border","none");
			$(this).css("border","1px solid #F00");
			//$(this).after("<span class='error'>Required.</span>");
		}else{
			//$(this).siblings(".error").remove();
			$(this).css("border","none");
		}
   });*/
	



});


function valid_email(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false;
	 }
	 if (str.indexOf(dot,(lat+2))==-1){
		return false;
	 }
	 if (str.indexOf(" ")!=-1){
		return false;
	 }
	 return true
}

function validateForm(thisform){
var msg = "";
var ok = true;
//field = "";
	$(thisform).find(".required").each(function(){
		if(this.value == "")
		{
            ok = false;
            msg = 'Please fill the required fields property\n';
        }

	});

	$(thisform).find(".email").filter(".required").each(function(){
		if(!valid_email(this.value))
		{
            ok = false;
            msg += 'Bad email, please verify it sintax\n';
        }
	});
	
	$(thisform).find(".password").each(function(){
		if(this.value.length < 4 || this.value.length > 20)
		{
            ok = false;
            msg += 'Bad password, between 4 and 20 chars of length\n';
        }
        
	});

    $(thisform).find(".confpass").each(function(){
		if(this.value.length < 4 || this.value.length > 20)
		{
            ok = false;
            msg += 'Bad confirm password, between 4 and 20 chars of length\n';
        }
        else if(this.value != $(thisform).find(".password").val())
        {
                ok = false;
                msg += 'Bad confirm password, password and confirm password is not equal \n';
        }
	});
	
    if(ok == true) $(thisform).submit();
    else
    {
        alert(msg);
    }
    
}