function  contact_us(){
	var f  = document.contact_form;
	//var a = document.getElementById("yourmessage").value;
    var n  = f.firstname;
	var l  = f.lastname;
    var e  = f.companyemail;
	var cn = f.companyname; 
	var m  = f.msge;
	var req = f.yourrequest;
	
	 if(n.value == ""){
		 load_error(n,'Name is empty!');
		 return false;
	 }else{
	 	remove_error(n);
	 }
	 if(!echeck(e.value)){
	 	load_error(e,'Invalid email!')
	 	return false;
	 }else{
	 	remove_error(e);
	 }
	 if(m.value == ""){
	 	load_error(m,'Empty message!');
		
	 	return false;
	 }else{
	 	remove_error(m);
	 }
	$.ajax({
 	 			url: 'contact_us.php',

 	 			type : "post",
 	 			cache: false,
				data: "firstname="+n.value+"&lastname="+l.value+"&companyemail="+e.value+"&companyname="+cn.value+"&msge="+m.value+"&yourrequest="+req,
 	 			success: function(html){
 	 				if(html !== ''){
						$('#aftersend').append('<b class="msuc"> Your message has been sent successfully! </b>');
 	 				
 	 				}else{
 	 					alert("Error !")
 	 				}
 	 			}
 	 		});
}


//feed back validation function
function  feed_back(){
	var f  = document.feed;
	//var a = document.getElementById("yourmessage").value;
    var n  = f.firstname;

    var e  = f.companyemail;
	var m  = f.msge;
	
	 if(n.value == ""){
		 load_error(n,'Name is empty!');
		 return false;
	 }else{
	 	remove_error(n);
	 }
	 if(!echeck(e.value)){
	 	load_error(e,'Invalid email!')
	 	return false;
	 }else{
	 	remove_error(e);
	 }
	 if(m.value == ""){
	 	load_error(m,'Empty message!');
		
	 	return false;
	 }else{
	 	remove_error(m);
	 }
	$.ajax({
 	 			url: 'feed_back.php',

 	 			type : "post",
 	 			cache: false,
				data: "firstname="+n.value+"&companyemail="+e.value+"&msge="+m.value,
 	 			success: function(html){
 	 				if(html !== ''){
						$('#aftersend').append('<b class="msuc"> Your message has been sent successfully! </b>');
 	 				
 	 				}else{
 	 					alert("Error !")
 	 				}
 	 			}
 	 		});
}


function send_update()
{
	var f  = document.sendupdate;
    var e  = f.companyemail;
	if(!echeck(e.value)){
	 	load_error(e,'Invalid email!')
	 	return false;
	 }else{
	 	remove_error(e);
	 }
	 
	 $.ajax({
 	 			url: 'updates.php',

 	 			type : "post",
 	 			cache: false,
				data: "companyemail="+e.value,
 	 			success: function(html){
 	 				if(html !== ''){
						$('#aftersend').append('<b class="msuc"> Your email has been sent successfully! </b>');
 	 				
 	 				}else{
 	 					alert("Error !")
 	 				}
 	 			}
 	 		});
}

function load_error(obj,msg){
    $(obj).css("border","2px dotted #FFBFBF");
	$(obj).animate( { backgroundColor: '#FFBFBF' }, 200).animate( { backgroundColor: '#fff' }, 200).animate( { backgroundColor: '#fff' }, 200).animate( { backgroundColor: '#fff' }, 200);
	if(!document.getElementById(obj.name + "_span"))
	$(obj).parent().append("<div class=\"inpt_error\" id=\"" + obj.name + "_span\">" + msg + "</div>");
	obj.focus(); 
}

function remove_error(obj){
	$(obj).css("border","1px solid #CCCCCC");
	$("div#" + obj.name + "_span").remove('');
}

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){
		
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		  
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		   
		    return false
		 }

 		 return true					
	}