
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

        var at="@";
        var dot=".";
        var lat=str.indexOf(at);
        var lstr=str.length;
        var ldot=str.indexOf(dot);
        if (str.indexOf(at)==-1){
           //alert("Invalid E-mail ID");
           return false;
        }

        if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
           //alert("Invalid E-mail ID");
           return false;
        }

        if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
            //alert("Invalid E-mail ID");
            return false;
        }

         if (str.indexOf(at,(lat+1))!=-1){
            //alert("Invalid E-mail ID");
            return false;
         }

         if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
            ////alert("Invalid E-mail ID");
            return false;
         }

         if (str.indexOf(dot,(lat+2))==-1){
            ////alert("Invalid E-mail ID");
            return false;
         }
        
         if (str.indexOf(" ")!=-1){
            ////alert("Invalid E-mail ID");
            return false;
         }

         return true;					
}


$().ready(function() {
	
	// validate signup form on keyup and submit
	$("#orderform").validate({
		rules: {	
			fname: {
				required: true,
				minlength: 2
			},
			lname: {
				required: true,
				minlength: 2
			},
			email: {
				required: true,
				email: true
			},
			telephone: {
				required: true,
				minlength: 10
			}
		},
		messages: {		
			fname: {
				required: "<font color='#e43b05'>*</font>",
				minlength: "<font color='#e43b05'>*</font>"
			},
			lname: {
				required: "<font color='#e43b05'>*</font>",
				minlength: "<font color='#e43b05'>*</font>"
			},
			email: "<font color='#e43b05'>*</font>",
			telephone: {
				required: "<font color='#e43b05'>*</font>",
				digits: "<font color='#e43b05'>*</font>",
				minlength: "<font color='#e43b05'>*</font>",
			},
		}
	});
	
	// validate signup form on keyup and submit
	$("#contactform").validate({
		rules: {	
			fname: {
				required: true,
				minlength: 2
			},
			lname: {
				required: true,
				minlength: 2
			},
			email: {
				required: true,
				email: true
			}
		},
		messages: {		
			fname: {
				required: "<font color='#e43b05'>*</font>",
				minlength: "<font color='#e43b05'>*</font>"
			},
			lname: {
				required: "<font color='#e43b05'>*</font>",
				minlength: "<font color='#e43b05'>*</font>"
			},
			email: "<font color='#e43b05'>*</font>",
		}
	});
	
	$("#loginform").validate({
		rules: {	
			log: {
				required: true,
				minlength: 2
			},
			pwd: {
				required: true,
				minlength: 5
			}
		},
		messages: {		
			log: {
				required: "<br/><font color='#e43b05'>Enter a username</font>",
				minlength: "<br/><font color='#e43b05'>Your username must consist of at least 2 characters</font>"
			},
			pwd: {
				required: "<br/><font color='#e43b05'>Please provide a password</font>",
				minlength: "<br/><font color='#e43b05'>Your password must be at least 5 characters long</font>"
			}
		}
	});
	
});

