	function checkEmailAvailable() {
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("register.php",{ email: $('[id=email]').val(), firstname: $('[id=fname]').val(), lastname: $('[id=lname]').val(), password: $('[id=password]').val(), type: $('[name=registration]:checked').val(), stid: jQuery('[name=stid]').val() } ,function(data)
	
		{
		  if(data=='error') //if username not avaiable
		  {
			$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email Already exists <a href="http://login.timedoctor.com/v2/" >Click here to log in</a><br /> \
				or <a href="https://login.timedoctor.com/v2/forgot_password.php" id="resetPass">click here to get a new password</a> \
				<form id="resetPassForm" action="https://login.timedoctor.com/v2/forgot_password.php" method="post"> \
				  <input type="hidden" name="signinform" value="" /> \
				  <input type="hidden" name="email" value="'+jQuery('[id=email]').val()+'" /> \
				  <input type="hidden" name="reset_pass" value="RESET_PASSWORD" /> \
				</form>'
				).addClass('messageboxerror').fadeTo(900,1);
			  jQuery('#resetPass').click(function(){
				jQuery('#resetPassForm').submit();
				return false;
			  });
			});		
		  }
		  else
		  {
			/*$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Registration successful!').addClass('messageboxok').fadeTo(900,1);	
			});*/
			
			if($('[name=registration]:checked').val() == 1) {
				//window.location = "http://admin.timedoctor.com/v2/setup/company/?key="+ data +"";
				window.location = "http://www.timedoctor.com/success.php?regMail="+ data +"";
			}
			else if($('[name=registration]:checked').val() == 0) {
				window.location = "http://www.timedoctor.com/success.php?regMail="+ data +"";
			}
		  }
				
		});
	}
	
	function secondCheckEmailAvailable() {
		
		//remove all the class add the messagebox classes and start fading
		$("#s_msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("register.php",{ email: $('[id=s_email]').val(), firstname: $('[id=s_fname]').val(), lastname: $('[id=s_lname]').val(), password: $('[id=s_password]').val(), type: $('[name=s_registration]:checked').val() } ,function(data)

		{
		  if(data=='error') //if username not avaiable
		  {
			$("#s_msgbox").fadeTo(200,0.1,function() //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Email Already exists <a href="#login" onclick="accountExist();" name="modal_existings_account">Click here to log in</a>').addClass('messageboxerror').fadeTo(900,1);
			});		
		  }
		  else
		  {
			/*$("#s_msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Registration successful!').addClass('messageboxok').fadeTo(900,1);	
			});*/
			
			if($('[name=s_registration]:checked').val() == 1) {
				//window.location = "http://admin.timedoctor.com/v2/setup/company/?key="+ data +"";
				window.location = "http://www.timedoctor.com/success.php?regMail="+ data +"";
			}
			else if($('[name=s_registration]:checked').val() == 0) {
				//window.location = "http://admin.timedoctor.com/v2/setup/individual/?key="+ data +"";
				window.location = "http://www.timedoctor.com/success.php?regMail="+ data +"";
			}
			
		  }
				
		});
	}
	
	function checkLogin() {
		//remove all the class add the messagebox classes and start fading
		$("#l_msgbox").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
		//check the username exists or not from ajax
		$.post("login.php",{ username: $('[id=l_username]').val(), password: $('[id=l_password]').val()} ,function(data)

		{
		  if(data=='error') {
			$("#l_msgbox").fadeTo(200,0.1,function(){ 
			  //add message and change the class of the box and start fading
			  $(this).html('Username or password wrong').addClass('messageboxerror').fadeTo(900,1);
			});		
		  }
		  else if(data == 'notConfirmed') {
			notConfirmed($('[id=l_username]').val());
		  }
		  else {
			window.location = data;
		  }
				
		});
	}
	
	function notConfirmed(username) {
		//Cancel the link behavior

		$('#loginFormID').fadeOut(function() {$('#notConfirmedEmail').html(username); $('#notConfirmed').fadeIn(400);});
		
		//send confirmation link again
		$.post("sendConfirmation.php",{ username: username} ,function(data){});
		
	}	
	
	//resend confirmation link
	function resendConfirmation() {
		var username = $('#notConfirmedEmail').html();
		
		$.post("sendConfirmation.php",{ username: username} ,function(data){
		
			if(data=='success') {
				$("#confirmationSend").fadeTo(200,0.1,function(){ 
				  //add message and change the class of the box and start fading
				  $(this).html('Confirmation email has been re-sent').addClass('messageboxok').fadeTo(900,1);
				});
			  }
			  else {
				$("#confirmationSend").fadeTo(200,0.1,function(){ 
				  //add message and change the class of the box and start fading
				  $(this).html('There was problem resending your email address').addClass('messageboxerror').fadeTo(900,1);
				});		
			  }
				
		});
	}

	function accountExist() {
		//Cancel the link behavior


		$('#mask').hide();

		$('.window').hide();
		
		//Cancel the link behavior


		//Get the A tag

		var id = '#login';

	

		//Get the screen height and width

		var maskHeight = $(document).height();

		var maskWidth = $(window).width();

	

		//Set heigth and width to mask to fill up the whole screen


		$('#mask').css({'width':maskWidth,'height':maskHeight});

		

		//transition effect		

		$('#mask').fadeIn(10);	

		$('#mask').fadeTo(10,0.8);	

	

		//Get the window height and width

		var winH = $(window).height();

		var winW = $(window).width();

			  

		//Set the popup window to center

		//$(id).css('top',  winH/2-$(id).height()/2);

		$(id).css('top', parseInt(winH/2-200) + $(document).scrollTop() );		

		$(id).css('left', winW/2-$(id).width()/2);

	

		//transition effect

		$(id).fadeIn(800); 
	

	}	

	
	$(document).ready(function() {
		$.validator.setDefaults({
			debug: false
		});
		$("#signupformsubmission").validate({
			event: "keyup",
			rules: {
				email: {
					required: true,
					email: true
				},
				repeatEmail: {
					required: true,
					email: true,
					equalTo: "#email"
				},
				password: {
					required: true,
					minlength: 5
				},
				confirm_password: {
					required: true,
					minlength: 5,
					equalTo: "#password"
				}
			},
		});
	});
	

	//Login form
	$(document).ready(function() {
	$.validator.setDefaults({
		debug: false
	});

		$("#loginForm").validate({
			event: "keyup",
			rules: {
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				email: "Please enter a valid email address"
			},
			submitHandler: function(form) {
				checkLogin();
		  }
	
		});
	
	});
	
function showModal(id) {
	//Get the screen height and width
	var maskHeight = Math.max(1200, $(document).height());
	var maskWidth = Math.max(1920, $(document).width());

	//Set heigth and width to mask to fill up the whole screen
	$('#mask').css({'width':maskWidth,'height':maskHeight});

	//transition effect		
	$('#mask').fadeIn(10);	
	$('#mask').fadeTo(10,0.983);	

	//Get the window height and width
	var winH = $(window).height();
	var winW = $(window).width();

	//Set the popup window to center
	$(id).css('top',  Math.max(winH/2-$(id).height()/2-100, 0));
	//$(id).css('top', parseInt(winH/2-285) + $(document).scrollTop() );		
	$(id).css('left', winW/2-$(id).width()/2);

	//transition effect
	$(id).fadeIn(800); 
}
function closeModal(id) {
	$('#mask').hide();
	$(id).hide();
}
		
  $(document).ready(function(){

    //$.preloadCssImages();

    $('.alpha').alpha();

	$(window).resize(function(){
		if ($('#mask').css('display') != 'none'){
			$('#mask').css('width',$(this).width());
		}
	});

	//select all the a tag with name equal to modal

	$('a[name=modal]').click(function(e) {
		//Cancel the link behavior

		e.preventDefault();

		

		//Get the A tag

		var id = $(this).attr('href');

	

		//Get the screen height and width

		var maskHeight = $(document).height();

		var maskWidth = $(document).width();
	

		//Set heigth and width to mask to fill up the whole screen


		$('#mask').css({'width':maskWidth,'height':maskHeight});

		

		//transition effect		

		$('#mask').fadeIn(10);	
		var opacity = parseFloat(jQuery(id).attr('maskOpacity'));
		if (isNaN(opacity)) opacity = 0.95;
		$('#mask').fadeTo(10,opacity);	

	

		//Get the window height and width

		var winH = $(window).height();

		var winW = $(window).width();

              

		//Set the popup window to center

		//$(id).css('top',  winH/2-$(id).height()/2);

		$(id).css('top', parseInt(winH/2-285) + $(document).scrollTop() );		

		$(id).css('left', winW/2-$(id).width()/2);

	

		//transition effect

		$(id).fadeIn(800); 

		$(id + ' input:enabled').eq(0).focus();

	});

	

	//if close button is clicked

	$('.close').click(function (e) {

		//Cancel the link behavior

		e.preventDefault();

		

		$('#mask').hide();

		$('.window').hide();

	});		
	$('.close1').click(function (e) {

		//Cancel the link behavior

		e.preventDefault();

		

		$('#mask').hide();

		$('.window').hide();

	});		
	$('.producttour').click(function (e) {

		//Cancel the link behavior

		e.preventDefault();

		

		$('#mask').hide();

		$('.window').hide();
		window.location = 'product_tour.html';

	});		
	
	
	
	$('.create_new_account').click(function (e) {
		//Cancel the link behavior

		e.preventDefault();


		$('#mask').hide();

		$('.window').hide();
		
		//Cancel the link behavior

		e.preventDefault();

		

		//Get the A tag

		var id = $(this).attr('href');

	

		//Get the screen height and width

		var maskHeight = $(document).height();

		var maskWidth = $(window).width();

	

		//Set heigth and width to mask to fill up the whole screen


		$('#mask').css({'width':maskWidth,'height':maskHeight});

		

		//transition effect		

		$('#mask').fadeIn(10);	

		$('#mask').fadeTo(10,0.8);	

	

		//Get the window height and width

		var winH = $(window).height();

		var winW = $(window).width();

			  

		//Set the popup window to center

		//$(id).css('top',  winH/2-$(id).height()/2);

		$(id).css('top', parseInt(winH/2-200) + $(document).scrollTop() );		

		$(id).css('left', winW/2-$(id).width()/2);

	

		//transition effect

		$(id).fadeIn(800); 
	
		
	
	

	});		

	

	//if mask is clicked

	//$('#mask').click(function () {
	//
	//		$(this).hide();
	//
	//		$('.window').hide();
	//
	//});	
	
	
	//if mask is clicked
	
  });
  
  	//contact form
	$().ready(function() {
		// validate the comment form when it is submitted
		$("#contactForm").validate({
			rules: {
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				email: "Invalid email address"
			}
		});
	});
	
	//support form
	$().ready(function() {
		// validate the comment form when it is submitted
		$("#supportForm").validate({
			rules: {
				email: {
					required: true,
					email: true
				}
			},
			messages: {
				email: "Invalid email address"
			}
		});
	});
	$().ready(function() {
		// validate the comment form when it is submitted
		$('#create').click(function () {
			
			$('#popup').hide();
			$('#dialog').show(800); 
		});	

	});
	
	//-------------------------GET PARAMS FROM THE URL----------------------//
	function getUrlVars()
	{
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}
	

	//-------------------------GET PARAMS FROM THE URL----------------------//
