function closeBookNowForm()
{
	document.getElementById('book_box').style.display = 'none';
	var overlay = document.getElementById("book_box_overlay");
	overlay.style.display = 'none';
}

function showBookNowForm(destination)
{
	
	var overlay = document.getElementById("book_box_overlay");
	var h = document.body.scrollHeight;
	var BodyHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
	if(h<BodyHeight) {
			h = BodyHeight;
	}
	overlay.style.height = h+'px';
	overlay.style.display = 'block';
	var destControl = document.getElementById('Destination');
	for(var i=0;i<destControl.options.length;i++)
	{
	 if(destControl.options[i].value.indexOf(destination)>=0)
	 {
	 	destControl.selectedIndex = i;
	 	break;
	 }
	  
	}
	document.getElementById('book_box').style.display = 'block';
	document.getElementById('book_box_form').style.display = 'block';
	document.getElementById('book_box_result_form').style.display = 'none';
	document.getElementById('book_box_result_loader').style.display = 'none';
	 
}

function submitBookNowForm()
{
	var errorControl = document.getElementById('bookNowFormMessage');
	
	var FirstName = document.getElementById('FirstName').value;
	var LastName = document.getElementById('LastName').value;
	var Email = document.getElementById('Email').value;
	var Phone1 = document.getElementById('ContactPhone1').value;
	var Phone2 = document.getElementById('ContactPhone2').value;
	var Phone3 = document.getElementById('ContactPhone3').value;
	var Destination = document.getElementById('Destination').value;
	
	var errorMessage = '';
	//validation
	var emailTest = "^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z_-]+\\.)+[a-z]{2,4}$"; 
	var regex = new RegExp(emailTest); 
	
	if(!FirstName.length)
		errorMessage = 'Please enter First Name';
	else if(!LastName.length)
	  errorMessage = 'Please enter Last Name';  
	else if(!Email.length)
	  errorMessage = 'Please enter Email Address'; 
	else if(!regex.test(Email))  
	  errorMessage = 'Please enter valid Email Address'; 
	else if(Phone1.length<3 || Phone2.length<3 || Phone3.length<4)
	  errorMessage = 'Please enter correct Phone Number';    
	 
	if(errorMessage.length)
	{
		errorControl.innerHTML  = errorMessage;
	  CMPS_blink(errorControl);
	}
	else
	{
	  document.getElementById('book_box_form').style.display = 'none';
	  document.getElementById('book_box_result_loader').style.display = 'block';
	  //send data
	  var unique = Math.round(Math.random()*1000);
	  var urlReq = 'http://www.campushwy.com/ajaxapi.php?book_process=1&FirstName='+escape(FirstName)+'&LastName='+escape(LastName)+
	               '&Email='+escape(Email)+'&Phone='+escape(Phone1+Phone2+Phone3)+'&Destination='+escape(Destination)+'&unique='+unique;
	 // alert(urlReq);
	  dhtmlCampusLoadScript(urlReq);
	}
	 
	
}


function submitBookNowFormCallback()
{
	document.getElementById('book_box_result_loader').style.display = 'none';
	document.getElementById('book_box_result_form').style.display = 'block';
}
 

function submitBookNowFormNumberMask(e, val) {
  var keynum;
  var keychar;
  var numcheck;

  if (window.event) {
    keynum = e.keyCode;
  }
  else if (e.which && e.which!=8 && e.which!=9) {
    keynum = e.which;
  }
  else
    return true;

  if((keynum == 8 || keynum ==9|| keynum ==37|| keynum ==39))
  {
    return true;
  }
  
  if(navigator.userAgent.toLowerCase().indexOf('safari') >= 0 && (keynum == 8 || keynum ==9))
	{
	  return true;
	}
  keychar = String.fromCharCode(keynum);
  numcheck = /\d/;
  if(val.indexOf(".") >= 0 && keychar=='.')
    return false;

  if (val.indexOf(".") >= 0 && (val.indexOf(".")+3 <= val.length))
    return false;

  return (keychar=='.' || numcheck.test(keychar));
}

CMPS_blink = function(elm, count)
{
	var count  = count | 3;
	var blinks = 0;
	function blink_f()
	{
		blinks++;
		elm.style.visibility = blinks%2==0 && blinks!=count*2?'visible':'hidden';
		if (blinks < count*2)
		{
			setTimeout(blink_f, 100);
		}
		else
		elm.style.visibility = 'visible';
	};
	blink_f();
}
