jQuery(document).ready(function() {
	
	jQuery("#got_question").submit(function(){
		var reg		= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var email	= trim( $('#email').val() );
		var name	= trim( $('#name').val() );
		
		var msg		= trim( $('#message').val() );
		
		if( name == "" || name == "Name" || name == null ){
			//$('.error_msg').text( 'Please fill in your name!' );
			alert('Please fill in your name.');
				$('#name').focus();
			
			return false;
		}
		if( email == '' || email == 'Email' || email == null ){
			//$('.error_msg').text( 'Please fill in your email!' );
			alert('Please fill in your email.')
				$('#email').focus();
			//});
			
			return false;
		}else if( reg.test( email ) == false ){
			//$('.error_msg').text( 'Invalid Email!' );
			alert('Invalid Email.')
				$('#email').focus();
			//});
			
			return false;
		}if( msg == '' || msg == 'Message' || msg == null ){
			//$('.error_msg').text( 'Pleas fill in your message!' );
			alert('Pleas fill in your message.')
				$('#message').focus();
			//});
			
			return false;
		}else{
			//$('form#sendmail').get(0).reset();
			$.post('sendmail.php',
				   {
					   'name'		: name,
					   'cemail'		: email,
					   'message'	: msg,
					   'action'		: 'question'
					},function(data){
						//$('#got-question input:text').attr("disabled",true);
						//$('#got-question textarea').attr("disabled",true);
						
						if(data.status == 1){
							//$('.error_msg').text( data.msg );
							
							/*alert(data.msg, function(){
								$('form#got_question').get(0).reset();
							});*/
							$('#email').val('');
							$('#name').val('');
							$('#message').val('');
						}else{
							$('form#got_question input').attr("disabled",true);
							//$('.error_msg').text( data.msg );
						}
					},'json');
		}
		return false;
	});
	
	jQuery("#contact").submit(function(){
		var reg		= /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		var name		= trim( $('#Name').val() );
		var phone		= trim( $('#Phone').val() );
		var email		= trim( $('#Email').val() );
		var subj		= trim( $('#Company').val() );
		var msg			= trim( $('#Message').val() );
		
		if( name == "" || name == "Name" || name == null ){
			$('.error_msg').text( 'Please fill in your name!' );
			//alert('Please fill in your name.', function(){
				$('#Name').focus();//
			//});
			
		return false;
		}if( subj == "" || subj == "Company" || subj == null ){
			$('.error_msg').text( 'Please fill in your company!' );
			//alert('Please fill in your name.', function(){
				$('#Company').focus();//
			//});
			
			return false;
		}if( email == '' || email == 'Email' || email == null ){
			$('.error_msg').text( 'Please fill in your email!' );
			//alert('Please fill in your email.',function(){
				$('#Email').focus();
			//});
			
			return false;
		}else if( reg.test( email ) == false ){
			$('.error_msg').text( 'Invalid Email!' );
			//alert('Invalid Email.',function(){
				$('#Email').focus();
			//});
			
			
			return false;
		}if( msg == "" || msg == "Subject" || msg == null ){
			$('.error_msg').text( 'Please fill in your message!' );
			//alert('Please fill in your name.', function(){
				$('#Message').focus();//
			//});
			
			return false;
		}else{
			$.post('sendmail.php',
				   {
					   'Name'		: name,
					   'Company'	: subj,
					   'Email'		: email,
					   'Phone'		: phone,
					   'Message'	: msg,
					   'action'		: 'contact'
					},function(data){
						if(data.status == 1){
							//$('.error_msg').text( data.msg );
							$('form#contact').html( data.msg );
							//alert(data.msg, function(){
								$('form#contact').get(0).reset();
							//});
							//$('form#got-question').get(0).reset();
							
						}else{
							//$('form#got-question input').attr("disabled",true);
							$('.error_msg').text( data.msg );
						}
					},'json');
		}
		return false;
	});
	
});

function trim(str){
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}

function SymError(){
 return true;
}

window.onerror = SymError;
var SymRealWinOpen = window.open;

function SymWinOpen(url, name, attributes)
{
	return (new Object());
}

window.open = SymWinOpen;
