var proc = false;
try {
  proc = new XMLHttpRequest();
} catch (trymicrosoft) {
  try {
    proc = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (othermicrosoft) {
    try {
      proc = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (failed) {
      proc = false;
	  alert('Your browser does not support the technology used for your administrator. Please upgrade to a newer browser.');
    }
  }
}

function controlDialog(name, action) {
   $(name).dialog(action);
   $("*").removeClass("ui-corner-all ui-dialog-buttonpane ui-widget-content ui-widget ui-widget-header");
}

$(document).ready(function(){
  $('.dialogClose').click(function() {
	controlDialog($(this).parents('.userDialog').first(), 'close');
  });

  $('#signupnow_form').submit(function() {
	
	signup();

	return false;
  });
});


function signup(){
	fname = document.getElementById('first_name').value;
	if (fname == ''){
		alert('Please provide your first name.');
		return false;
	}
	lname = document.getElementById('last_name').value;
	if (lname == ''){
		alert('Please provide your last name.');
		return false;
	}
	email = document.getElementById('email').value;
	if (email == ''){
		alert('Please provide your email.');
		return false;
	}
	mobile = document.getElementById('mobile').value;
	key = document.getElementById('ke').value;
	
	proc.open('POST', 'z_includes/zsignup.php', true);
		data = 'fname='+fname+'&lname='+lname+"&email="+email+"&mobile="+mobile+"&key="+key;
		proc.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		proc.send(data);
		proc.onreadystatechange = function(){ 
		if(proc.readyState  == 4){
			if(proc.status  == 200){ 
				if (proc.responseText && proc.responseText != 'passed'){				
					alert ('SOMETHINGS WRONG insert--\n\n' + proc.responseText);
					return false;
				}else{
					controlDialog('#thankyou-modal', 'open');	
				}//end response text
			}//end status
		}//end readState
	}//end function
}
