// JavaScript Document

		$( function() {
			$( '#contactForm' ).ipValidate( {

				required : { //required is a class
					rule : function() {
						return $( this ).val() == '' ? false : true;
					},
					onError : function() {
						if( !$( this ).parent().hasClass( 'element_container' ) ) {
							$( this ).parent().addClass( 'error' );
							showmessage("* Please fill your information");
						} 
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				
				fname: { //required is a class
					rule : function() {
						return $( this ).val() == 'Enter your name here' ? false : true;
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						showmessage("* Please fill your information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				email: { // is a class
					rule : function() {
						//return $( this ).val() == 'Email Address' ? false : true;
						return isValidEmailAddress( $(this).val() );
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						showmessage("* Please fill your information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				selectmenu: { // is a class
					rule : function() {
						return $( this ).val() == 'Please Select' ? false : true;
					},
					onError : function() {
						$(this).parent().toggleClass("error");
						showmessage("* Please fill your information");
					},
					onValid : function() {
						$(this).parent().toggleClass("error");
						$(this).focus();
					}
				},
				
				submitHandler : function() {
					//$('.holder').hide();
					//$('#loading').show();
					$.post('mail.php',{name:$('#nameenq').val(), email:$('#emailenq').val() ,projecttype:$('#projecttypeenq').val(), projectbudget:$('#projectbudgetenq').val(), projectdetails:$('#projectdetailsenq').val()},
					function(data){
						$('#loading').css({display:'none'}); 
						if( data.indexOf('success')>=0 ) {
							showmessage("Thankyou for your message");
							$('#nameenq').val("");
							$('#emailenq').val("");
							$('#projecttypeenq').val("");
							$('#projectbudgetenq').val("");
							$('#projectdetailsenq').val("");							
							//$('li.none').append("Thankyou for your message");
							if(defaults.hideOnSubmit == true) {
								//hide the tab after successful submition if requested
							}
						} else {
							//$('li.none').append("Sorry but your message could not be sent, try again later");
							showmessage("Sorry but your message could not be sent, try again later");
						}
					});		
					
					return false;																																		 
				}
			});
		});
		
		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 showmessage(text) {
		//$('li.none').append(" ");
		alert("hii");
		$('li.none font').replaceWith("<font>"+text+"</font>");
		
	}
