function createRequestObject() {

	var req;

	if(window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		alert('There was a problem creating the XMLHttpRequest object');
	}

	return req;

}
var mailsend = createRequestObject();
 function formval()
 {
			var cname=document.getElementById("name").value;
			var cemail=document.getElementById("e-mail").value;
			var cphone=document.getElementById("phone").value;
			var cmessage=document.getElementById("message").value;
			if(cname=="" && cemail==""&& cphone=="" && cmessage=="")
			{
			alert("Please Enter The Empty Field ");
			return false;
			}else {
				mailsend.open('post','mail.php');
				mailsend.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				mailsend.onreadystatechange=resemail;
				mailsend.send('mailchk=1&cname='+cname+'&cemail='+cemail+'&cphone='+cphone+'&cmessage='+cmessage);
				
		}
	 
 }
function resemail()

{	
		$('.resmsge').show();
		if(mailsend.readyState==1)
		{
			document.getElementById("resmsge").innerHTML='Sending...';
		}
		else (mailsend.readyState==4 &&mailsend.status==200)
		{
		var ress=mailsend.responseText;
			if(ress=="sent"){					
				document.getElementById("resmsge").innerHTML=' Thanks!.Email has been Sent';
				$("#contactForm").slideUp("slow");
				$("#backgroundPopup").fadeOut("slow");
			}
		}

 }
function nameval(){
	var cname=document.getElementById("name").value;
	if(cname ==""){ $('.name-missing').show(); }
	else{ $('.name-missing').hide(); }
	
}
function phonenum(){
	var cphone=document.getElementById("phone").value;
	if(cphone==""){ $('.phone-missing').show(); }
	else{ $('.phone-missing').hide(); }
	
}
function emailval(){
	var cemail=document.getElementById("e-mail").value;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(cemail) == false) {
		$('.email-missing').show();}
	else if( cemail=="" ){ $('.email-missing').show(); }
	else{ $('.email-missing').hide(); }
}
function msgval(){
	var cmessage=document.getElementById("message").value;
	if( cmessage=="" ){ $('.message-missing').show(); }
	else{ $('.message-missing').hide(); }
	
}
$(document).ready(function(){
	//function for contact form dropdown
	/*$("#contactForm").hide('fast');*/
	function contact() {
		if ($("#contactForm").is(":hidden")){
			$("#contactForm").slideDown("slow");
			$("#backgroundPopup").css({"opacity": "0.7"});
			$("#backgroundPopup").fadeIn("slow"); 
		}
		else{
			$("#contactForm").slideUp("slow");
			$("#backgroundPopup").fadeOut("slow");  
		}
	}
	 
	//run contact form when any contact link is clicked
	$("#grt_frm").click(function(){contact()});
	$(".close").click(function(){contactclos()});
	function contactclos() {
			$("#contactForm").slideUp("slow");
			$("#backgroundPopup").fadeOut("slow");  
			}
	
	//animation for same page links #
	$('a[href*=#]').each(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		&& location.hostname == this.hostname
		&& this.hash.replace(/#/,'') ) {
		  var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']');
		  var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
			if ($(this.hash).length) {
				$(this).click(function(event) {
					var targetOffset = $(this.hash).offset().top;
					var target = this.hash;
					event.preventDefault();			   
					$('html, body').animate({scrollTop: targetOffset}, 500);
					return false;
				});
			}
		}
	});
  

	//only need force for IE6  
	/*$("#backgroundPopup").css({  
		"height": document.documentElement.clientHeight 
	});  */
});
