// Web form validation

	$(function() {

		$('.webform-link a').click(function() {		
			$('.webform').slideDown(500);			
		});
		
		$('.close-btn').click(function() {
			closeForm();
		});
	});	

	function closeForm() {	
		$('.webform').slideUp(500);
		$('.arrow-name').css('display','none');
		$('.arrow-email').css('display','none');
		$('.arrow-message').css('display','none');
		$('.form-textbox').css('background-color','#FFF');
		clearForm();		
	}
		
	function clearForm() {	
		$(':input').each(function() {
			var type = this.type;
			if (type == 'text' || type == 'password' || type == 'textarea')
			this.value = "";
		});
	}
	
	function validateForm()	{			
		var name = document.getElementById('name').value;
		var email = document.getElementById('email').value;
		var company = document.getElementById('company').value;
		var contact = document.getElementById('contact').value;
		var message = document.getElementById('message').value;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var hasError = false;
		
		$('.form-textbox').css('background-color','#FFF');
		$('.arrow-name').css('display','none');
		$('.arrow-email').css('display','none');
		$('.arrow-message').css('display','none');
			
		if (name == "") {		
			$('.arrow-name').css('display','inline');
			$('.webform #name').css('background-color','#FFFFCC');
			hasError = true;
		} 
		
		if (email == "") {		
			$('.arrow-email').css('display','inline');
			$('.webform #email').css('background-color','#FFFFCC');
			hasError = true;
		}
		
		else if (!emailReg.test(email)) {
			  $('.arrow-email').css('display', 'inline');
			  $('.webform #email').css('background-color', '#FFFFCC');
			  hasError = true;
		}
		
		if (message == "") {		
			$('.arrow-message').css('display','inline');
			$('.webform #message').css('background-color','#FFFFCC');
			hasError = true;
		}
		
		if (hasError == false) {			
			sendEmail(name, email, company, contact, message)			
		}	
	}
	
	function sendEmail(name, email, company, contact, message) {
		$('.loading').append('<img src="post/loading.gif"/>');
		$.post("/post/sendemail.php",
   				{ _name: name, _email: email, _company: company, _contact: contact, _message: message },
   					function(data){
						$('.loading').html('');
						closeForm();						
   					}
				 );		
	}


// Client login validation
function CmtCheckInput()
        {

          if (document.CmtForm.CmtUsrNamePrm.value=="" )
          {
            alert('Please enter your user name');
            document.CmtForm.CmtUsrNamePrm.focus();
            return false;
          }
          else if (document.CmtForm.CmtUsrPWPrm.value=="")
          {
            alert('Please enter your password');
            document.CmtForm.CmtUsrPWPrm.focus();
            return false;
          }
          else
          {
            aWinSize = ",width="+screen.width+",Height="+(screen.Height-100)+",Top=0,Left=0";
            aNewWin = window.open("","CmtNewWindow","toolbar=0,menubar=0,scrollbars=1,resizable=1,status=0,directories=0,location=0"+aWinSize);
            aNewWin.name = "CmtNewWindow";
            return true;
          }
        }

        function cmtLogin()
        {
          if (CmtCheckInput()) {

              if (document.CmtForm.ddLoginTo.value == 1) {
                  document.CmtForm.action = "http://brx.mine.nu:4999";
              }
              else {
                  document.CmtForm.action = "http://backup01.idrive.net.au/obs/user/logon.do;jsessionid=478004A83D04C985A4205CFAE52F5070";
              }            
          
            document.CmtForm.submit();
            document.CmtForm.CmtUsrPWPrm.value = "";
          }
        }