function loadCells() {
  for (var i=0; i<66; i++) {
   startCell("cell"+i, $("d"+i).className);
  }
}
function startCell(cell, stime) {
  var params = 'c=' + cell + '&d=' + stime;
  new Ajax.Updater(cell, 'actions/update_front.php', { method: 'post', parameters: params, evalScripts: true, onComplete: setObservers(cell) });
}
function setObservers(cell) {
  Event.observe(cell, 'mouseover', function() { 
    try {$(this).getElementsByTagName('div')[2].style.display = 'block';} 
	catch(err){}
    try {$(this).getElementsByTagName('div')[3].style.display = 'block';} 
	catch(err){}
  } );
  Event.observe(cell, 'mouseout', function() {  
    try { $(this).getElementsByTagName('div')[2].style.display = 'none';} 
	catch(err){}
    try { $(this).getElementsByTagName('div')[3].style.display = 'none';} 
	catch(err){}	
  } ); 
}


function addApp(id, cell, stime, sid) {  
  w = new Window({className: "mac_os_x", title: "Book Appointment", width:600, height:380, destroyOnClose: true, recenterAuto:false}); 
  var params = 'id=' + id + '&c=' + cell + '&d=' + stime + '&sid=' + sid;
  w.setAjaxContent('actions/request-form.php', { method: 'post', parameters: params }, true, true);  
  w.showCenter();
}

function doRequest(id, cell, stime) {
		var err = false;
		
	if ($F('phone') == '') {
		err = true;
	}
	
		if ($F('street') == '') {
		err = true;
	}
	
		if ($F('state') == '') {
		err = true;
	}
	
		if ($F('zip') == '') {
		err = true;
	}
	
		if ($F('city') == '') {
		err = true;
	}
	
	if (err == false) {
	
	
	$(cell).innerHTML = '<span class=\'btext\'>Updating...</span>';
	var params = $('frmRequest').serialize();
	params += '&action=request&id=' + id + '&c=' + cell + '&d=' + stime;
	new Ajax.Updater(cell, 'actions/update_front.php', { method: 'post', parameters: params, onComplete: setObservers(cell) });alert("Thank you for using our mobile booking calendar, please check your email for confirmation.");
	  w.destroy();
    $('overlay_modal').hide();
	
	
	} else {
	alert("Plese fill out the required fields.");	
	}
}

