function contact_form_show(){  
container_off();
var contact_form = document.getElementById('contact_form');
contact_form.style.display="block";
contact_form.style.left = (screen.width/2 - 490/2)+"px";
contact_form.style.top = (screen.height/2 - 340/2 - 80)+"px";
}
function contact_form_hide(){
var contact_form = document.getElementById('contact_form');
contact_form.style.display="none";
container_on();
}
function container_off(){
document.getElementById('container_dark').style.width=document.body.clientWidth+'px';
document.getElementById('container_dark').style.height='100%';
document.getElementById('container_dark').style.display="block";

document.getElementById('container_dark').style.backgroundColor="black";
alpha_set('container_dark',0);
setTimeout('alpha_set(\''+'container_dark'+'\','+1+')',200);
setTimeout('alpha_set(\''+'container_dark'+'\','+2+')',300);
setTimeout('alpha_set(\''+'container_dark'+'\','+3+')',400);
setTimeout('alpha_set(\''+'container_dark'+'\','+4+')',500);
setTimeout('alpha_set(\''+'container_dark'+'\','+5+')',600);

}
function container_on(){
//alpha_set('container_dark',0);
document.getElementById('container_dark').style.display="none";
document.getElementById('container_dark').style.backgroundColor="transparent";
}
function alpha_set(element_id, value)
{	 	
	   document.getElementById(element_id).style.opacity = value/10;
       document.getElementById(element_id).style.filter  = 'alpha(opacity=' + value*10 + ')';
       //document.getElementById(element_id).opacitystring = 'filter:progid:DXImageTransform.Microsoft.alpha(opacity='+value+'); -moz-opacity: '+value/10;
       if(navigator.appName=='Microsoft Internet Explorer')     {
          document.getElementById(element_id).style.filter = 'progid:DXImageTransform.Microsoft.alpha(opacity='+(value*10)+'); -moz-opacity: '+(value/10)+'; opacity: '+(value*10)+'';
       }
}
function contact_form_verify(){
if(document.getElementById('id_contact_form_name').value=="")
     document.getElementById('contact_form_name_star').style.display = "inline";
else document.getElementById('contact_form_name_star').style.display ="none";
if(document.getElementById('id_contact_form_content').value==""){
     document.getElementById('contact_form_content_star').style.display = "inline";
	 contact_form_off();
	 }else{ 
     document.getElementById('contact_form_content_star').style.display ="none";     
}

if(
document.getElementById('id_contact_form_phone').value=="" &&
document.getElementById('id_contact_form_email').value==""
){
document.getElementById('contact_form_phone_star').style.display = "inline";
document.getElementById('contact_form_email_star').style.display = "inline";
contact_form_off();
}else{
document.getElementById('contact_form_phone_star').style.display = "none";
document.getElementById('contact_form_email_star').style.display = "none";
}

//email
if(!(document.getElementById('id_contact_form_email').value=="")){
if(!isValidEmail(document.getElementById('id_contact_form_email').value)){
document.getElementById('contact_form_email_star').style.display = "inline";
contact_form_off();
}else{document.getElementById('contact_form_email_star').style.display = "none";
}}

if(!(  
    (document.getElementById('id_contact_form_phone').value=="" && document.getElementById('id_contact_form_email').value=="" )
    || document.getElementById('id_contact_form_content').value==""
	|| (!(document.getElementById('id_contact_form_email').value=="") && !isValidEmail(document.getElementById('id_contact_form_email').value))  //email
)){
	 
contact_form_on();
}

}
function contact_form_off(){
document.getElementById('contact_form_submit').disabled = true;}
function contact_form_on(){
document.getElementById('contact_form_submit').disabled = false;}



$(document).ready(function(){
	$('#contact_form_form').submit(function() {
	
	$('#contact_form_form').hide();
	
		$('#contact_form_waiting').show(500);
		//$('#demoForm').hide(0);
		//$('#message').hide(0);

		
		
		$.ajax({
			type : 'POST',
			url : 'mail.php',
			data: {
			    name  : $('#id_contact_form_name').val(),
				email : $('#id_contact_form_email').val(),
				phone : $('#id_contact_form_phone').val(),
				content : $('#id_contact_form_content').val()
				
			},
			success : function(data){
				$('#contact_form_waiting').hide(500);				
				document.getElementById('contact_form_message').innerHTML = data+'<br><a href="javascript://" onclick="contact_form_hide();">Ok</a>';
				$('#contact_form_message').show(500);				
				
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$('#contact_form_waiting').hide(500);
				alert('fail');
			}
		});

		return false;
	});
});

function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  strEmail = document.forms[0].email.value;   
  if (strEmail.search(validRegExp) == -1){return false;} 
  return true; 
}
