String.prototype.trim = function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

function CheckValidEmail(fieldid){
	Obj=document.getElementById(fieldid);
	var str = Obj.value; 
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,4})(\]?)$/; // valid 
	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid 
		return true; 
	}else{ 
		return false; 
	} 
}

function Validate_ContactUs(){
	
	var department=document.getElementById('department');
	if(department.value.trim().length==0){
		alert("Select Department");
		department.focus();
		return false;
	}
	
	var lname=document.getElementById('lname');
	if(lname.value.trim().length==0){
		alert("Enter your Last Name");
		lname.focus();
		return false;
	}
	
	var Country=document.getElementById('Country');
	if(Country.value.trim().length==0){
		alert("Select Country");
		Country.focus();
		return false;
	}
	
	var email=document.getElementById('email');
	if(!CheckValidEmail('email')){
		alert("enter a valid email");
		email.focus();
		return false;
	}
	
	var cemail=document.getElementById('cemail');
	if(!CheckValidEmail('cemail')){
		alert("enter a valid confirmation email");
		cemail.focus();
		return false;
	}
	
	if(cemail.value.trim()!=email.value.trim()){
		alert("Confirmation email didn't match please check your email address");
		cemail.focus();
		return false;
	}
	
	
	var comment=document.getElementById('comment');
	if(comment.value.trim().length==0){
		alert("enter your comment");
		comment.focus();
		return false;
	}
	
	var user_code=document.getElementById('user_code');
	if(user_code.value.trim().length==0){
		alert("you should fill the VERIFICATION CODE");
		user_code.focus();
		return false;
	}
	
	return true;
}
function Validate_CareerForm(){
	if(document.getElementById("fullname").value.trim().length == 0){
		alert("Name must be filled");
		document.getElementById("fullname").focus();
		return false;
	}
	if(!CheckValidEmail('email')){
		alert("Email must be filled");
		document.getElementById("email").focus();
		return false;
	}
	if(document.getElementById("note").value.trim().length == 0){
		alert("Note must be filled");
		document.getElementById("note").focus()
		return false;
	}			
	if(document.getElementById("userfile").value.trim().length == 0){
		alert("You must upload your CV");
		document.getElementById("userfile").focus();
		return false;
	}
	var user_code=document.getElementById('user_code');
	if(user_code.value.trim().length==0){
		alert("you should fill the VERIFICATION CODE");
		user_code.focus();
		return false;
	}
	return true;
}