function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}


function limitTextName(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}


function showHide(type) {
	switch(type){
		case "business":
			document.getElementById("business").className = "show";
			document.getElementById("event_img_img").src = "images/events/2.1.jpg";
			document.getElementById("private").className = "hide";
			break;
		case "private":
			document.getElementById("business").className = "hide";
			document.getElementById("event_img_img").src = "images/events/1.1.jpg";
			document.getElementById("private").className = "show";
			break;
		}
}


function selected(type) {
	switch(type){
		case "reunions":
			document.getElementById("event_img_img").src = "images/events/1.1.jpg";
			break;
		case "birthdays":
			document.getElementById("event_img_img").src = "images/events/1.2.jpg";
			break;
		case "engagement":
			document.getElementById("event_img_img").src = "images/events/1.3.jpg";		
			break;
		case "non_pro":
			document.getElementById("event_img_img").src = "images/events/2.1.jpg";
			break;
		case "costumer":
			document.getElementById("event_img_img").src = "images/events/2.2.jpg";		
			break;
		case "product":
			document.getElementById("event_img_img").src = "images/events/2.3.jpg";
			break;
     }
    }
   

function catering_others(type) {
	if(type=="delivery"){
	   document.getElementById("delivery").value="Write the address (Office Name, building number, street, Town, zip-code)"; 
		document.getElementById("delivery").className = "show";
     } else {
     document.getElementById("delivery").value="";
     document.getElementById("delivery").className = "hide";
     }
    }
    
function others(type) {
	if(type=="other"){
		document.getElementById("other_describe").className = "show";
     } else {document.getElementById("other_describe").className = "hide";}
    }



function showHideShop(idVar) {
	idVar= "form_" + idVar; 
	classValue = document.getElementById(idVar).className;
	switch (classValue){
		case "hide":
			classValue = document.getElementById(idVar).className = "show";
			break;
		case "show":
			classValue = document.getElementById(idVar).className = "hide";
			break;		
			}
	}
	

function mouseOver(idVar) {
		document.getElementById(idVar).className = "regular2";
			}
			

function mouseOut(idVar) {
		document.getElementById(idVar).className = "regular1";
			}


function mouseOverProfile(idVar) {
		document.getElementById(idVar).className = "regular2profile";
			}

			
function mouseOutProfile(idVar) {
		document.getElementById(idVar).className = "regular1Profile";
			}


function mouseOverMenu(idVar) {
		document.getElementById(idVar).className = "menubover";
			if ((idVar=="index.php")||(idVar=="mission.php")||
			(idVar=="shop.php")||(idVar=="directions.php")||
			(idVar=="reviews.php")||(idVar=="contact_us.php"))
			{
						mouseOutMenuMenu();}
			}


function mouseOverMenu2(idVar) {
		document.getElementById("menutxt1menu").className = "menutxt1hidden";
			}			


function mouseOutMenu(idVar) {
		document.getElementById(idVar).className = "menub";
			}


function mouseClickMenu(idVar) {
		urlVar = "./" + idVar;
		window.location = urlVar;
			}


/*Those are the script for the menu button to make appear and dissapear
the menu navigation table */ 

function mouseOverMenuMenu(idVar) {
		document.getElementById(idVar).className = "menuvisible";
		document.getElementById("foodlist.php").className = "menuvisible";
			}


function mouseOverMenuMenu2(idVar) {
		document.getElementById(idVar).className = "profileover";
			}			


function mouseOutMenuMenu2(idVar) {
		document.getElementById(idVar).className = "profile";
			}
																									


function mouseClickMenuMenu(idVar) {
classValue = document.getElementById(idVar).className;
	switch (classValue){
		case "menuvisible":
			classValue = document.getElementById(idVar).className = "menuhidden";
			break;
		case "menuhidden":
			classValue = document.getElementById(idVar).className = "menuvisible";
			break;		
			}
	}


function mouseClickMenuMenu2(idVar) {
classValue = document.getElementById(idVar).className;
	switch (classValue){
		case "menutxt1visible":
			classValue = document.getElementById(idVar).className = "menutxt1hidden";
			break;
		case "menutxt1hidden":
			classValue = document.getElementById(idVar).className = "menutxt1visible";
			break;		
			}
	}


function showHideProfile(idVar) { 
	classValue = document.getElementById(idVar).className;
	switch (classValue){
		case "hide":
			classValue = document.getElementById(idVar).className = "lable_show";
			break;
		case "lable_show":
			classValue = document.getElementById(idVar).className = "hide";
			break;		
			}
	}
	

function searchOnfocus(idVar) {
	if (document.getElementById(idVar).value=="Search the site"){
	document.getElementById(idVar).value="";	
			};
	}


function searchOnblur(idVar) {
	if (document.getElementById(idVar).value==""){
	document.getElementById(idVar).value="Search the site";	
			}
	}


function numCheck(idValue) {
	idValue='form_'+ idValue;
	numValue=document.getElementById(idValue).value;
	while (numValue > 1 && numValue < 999)
		{
		break;
	}
	document.getElementById(idValue).value = document.getElementById(idValue).value.substring(0, 0);
	}


function checkEmail(email,email2,pass,pass2){
 var1=document.getElementById(email).value;
 var2=document.getElementById(email2).value; 
 pas1=document.getElementById(pass).value;
 pas2=document.getElementById(pass2).value; 

 if( var1==var2 )  			
 	{
				if(pas1==pas2)  			
 	{
 			if(
 				(document.getElementById('user').value !="")&&
 			 	(document.getElementById('user').value!=" ")&&	
 			 	(document.getElementById('pass').value!="")&&
 			 	(document.getElementById('pass').value!=" ")&&
 			 	(document.getElementById('email').value!="")&&
 			 	(document.getElementById('email').value!=" ")&&
 			 	(document.getElementById('first').value!="")&&
 			 	(document.getElementById('first').value!=" ")&&
 			 	(document.getElementById('last').value!="")&&
 			 	(document.getElementById('last').value!=" ")
 			 			 			 			)
 			 			 			 	{
						emailVar=document.getElementById('email').value;
				if(validEmail(emailVar)==true){ 
						document.contact_us_form.submit();
						}else{
						document.getElementById('email').className="loginform_wrong";
						document.getElementById('email2').className="loginform_wrong";	
					alert("The email is not a valid!");
						};
										}
										else
										{
									alert("You have to fill all the forms!");										
										};		
				}
			else{ 
			alert("The passwords do not match!");
			document.getElementById('pass').className="loginform_wrong";
			document.getElementById('pass2').className="loginform_wrong";
			document.getElementById('passw').className="loginform_wrongw";
			document.getElementById('passw2').className="loginform_wrongw";
			};
			}
		else{ 
			alert("Check the e-mail adress!");
			document.getElementById('email').className="loginform_wrong";
			document.getElementById('email2').className="loginform_wrong";
			document.getElementById('emailw').className="loginform_wrongw";
			document.getElementById('emailw2').className="loginform_wrongw";
			};
		}					 			

														
function contactUsCheck(){
//check if there are empty forms or " " (spaced) forms
			if(
	(emptyCheck('First_Name')==true)&&
 	(emptyCheck('Last_Name')==true)&& 
	(emptyCheck('email')==true)&&
	(emptyCheck('email2')==true)&&
	(emptyCheck('phone')==true)&&
	(emptyCheck('category')==true)&&
	(emptyCheck('message')==true)
			){ 
	//check if the emails are the same
	if(document.getElementById('email').value==
	document.getElementById('email2').value) 
			{
				emailVar=document.getElementById('email').value;
				if(validEmail(emailVar)==true){ 
						document.getElementById('contact_us_form').submit();
						}else{document.getElementById('email').className="contactusform_wrong";
						document.getElementById('email2').className="contactusform_wrong";
						document.getElementById('emailw').className="contactustxt_wrong";	
						document.getElementById('email2w').className="contactustxt_wrong";
					alert("The email is not a valid!");
						};
			}else{
			//the emails aren't the same
			document.getElementById('email').className="contactusform_wrong";
			document.getElementById('email2').className="contactusform_wrong";
			document.getElementById('emailw').className="contactustxt_wrong";	
			document.getElementById('email2w').className="contactustxt_wrong";
			alert("The e-mail addresses do not match! Please try again.");
			};
		}else{
		//the forms aren't complete or are speced
		alert("Please make sure you fill all the forms correctly.");
		};
}
	

function emptyCheck(idVar){
idValue=document.getElementById(idVar).value; 
idVarTxt=idVar + "w";
if( (idValue=="") || (idValue==" ") || (idValue==null) ){
	// the form is emty or spaced 
	document.getElementById(idVarTxt).className="contactustxt_wrong";
	document.getElementById(idVar).className="contactusform_wrong";
	return false;
}else{
	document.getElementById(idVarTxt).className="contactustxt";
	document.getElementById(idVar).className="contactusform";
	return true;
				};
			}	


function validEmail(email){
  apos=email.indexOf("@");
  dotpos=email.lastIndexOf(".");
  if (apos<1||dotpos-apos<2)
    {return false;}
  else {return true;};
}	


// those are the functions for the "ADD" or "Remove" button of catering.php

function add_over(idVar){
if(document.getElementById(idVar).className=="hide"){}else{
document.getElementById(idVar).className="add_over";
};
}


function add_out(idVar){
if(document.getElementById(idVar).className=="hide"){}else{
document.getElementById(idVar).className="add";
};
}


// add an item (or "table row") to the receipt 

function add_click(name,idvar,idvarNum,addid,itemid,category,price){

// hide the "add" button and change added itmes's background
	 document.getElementById(addid).className="hide";
	 document.getElementById(itemid).style.backgroundColor='#f97f4f';
// add new row element	
    var tbody = document.getElementById("receipt_table");
    var row = document.createElement("div");
    var idRow="row_" + idvar;
    row.id=idRow;
    row.className="receipt_table_row";

    var td1 = document.createElement("div");
    td1.appendChild(document.createTextNode(name));
    td1.className="receipt_table";
    td1.id="name"+idvar;

    var td2 = document.createElement("div");
    td2.appendChild (document.createTextNode(price));    
    td2.className="receipt_table";	 
    var price_form = document.createElement("input");     
    price_form.className="hide";
    price_form.id="catering_" + category + "_price" + idvar;    
    td2.appendChild (price_form);
    price_form.value = price;
    
    
    var td3 = document.createElement("div");
    td3.className="receipt_table";
    var quantity_form = document.createElement("input");     
    quantity_form.className="catering_breakfst";
    quantity_form.size="3";
    quantity_form.id="catering_" + category + idvar;   
    quantity_form.name=quantity_form.id;
    idformVar = quantity_form.id;
    quantity_form.value=idvarNum; 
    
    //min quantity and id layer
    var quantity_form_min = document.createElement("input");     
    quantity_form_min.className="hide";
    quantity_form_min.size="3";
    quantity_form_min.id="catering_min" + category + idvar;
	 quantity_form_min.value=idvarNum; 
	 td3.appendChild(quantity_form_min);	    
    			 
    td3.appendChild(quantity_form);
					    
			    
    var remove = document.createElement("div");
    remove.appendChild (document.createTextNode("Remove Item"));
    remove.className="remove_add";
    remove.id=idvar;
    
    var edit = document.createElement("div");
    edit.appendChild (document.createTextNode("Add NOTES"));
    edit.className="edit_add";
    edit.id=idvar + "editnote";
    idvarEdit=edit.id;
    var td4 = document.createElement("div");    
    td4.className="receipt_table_remove";
    td4.appendChild(edit);
    td4.appendChild(remove); 
    row.appendChild(td1);
    row.appendChild(td2);
    row.appendChild(td3);
    row.appendChild(td4);
    tbody.appendChild(row);
    document.getElementById(idvarEdit).onclick = calcolate('calcolate', 'calcolation');
        
    document.getElementById(idvar).className="remove_add";
    
    document.getElementById(idvar).onmouseover=function() {
			    document.getElementById(idvar).className="remove_add_over";
    					};
	 document.getElementById(idvar).onmouseout = function() {
			    document.getElementById(idvar).className="remove_add";
    					};
	 document.getElementById(idvar).onclick = function() {
	 
	 row.parentNode.removeChild(row);
		document.getElementById(addid).className="add";
		document.getElementById(itemid).style.backgroundColor='#ffffff';    
		calcolate('calcolate', 'calcolation');
        					};
    
	
	 document.getElementById(edit.id).onmouseover=function() {
			    document.getElementById(edit.id).className="edit_add_over";
    					};
	 document.getElementById(edit.id).onmouseout = function() {
			    document.getElementById(edit.id).className="edit_add";
    					};
	 document.getElementById(edit.id).onclick = function() {
	 idtest="div_note" + idvar;
	 				if(
	 			(document.getElementById(edit.id).innerHTML=='Add NOTES')
							&& 
				(document.getElementById(idtest)== null)	 		
	 								){
	 		var note_input = document.createElement("textarea");
	 		note_input.className="catering_form2";
	 		note_input.rows=3;
	 		note_input.cols=30;
	 		var note = document.createElement("div");
	 		note.id="div_note" + idvar;
	 		note.className="note_div";
	 		row.appendChild(note);
    		note.appendChild(note_input);
    		note_input.id="note_input" + idvar;
    		note_input.name =note_input.id; 
    		var note_div2=document.createElement("div");
    		note_div2.id="note_div2" + idvar;
    		var add_note = document.createElement("div");
    		add_note.id="add_note"+idvar;
	 		add_note.appendChild (document.createTextNode("ADD"));
	 		add_note.className="edit_add2";
	 		var cancel_note = document.createElement("div");
    		cancel_note.id="cancel_note"+idvar;
	 		cancel_note.appendChild (document.createTextNode("DISCARD"));
	 		cancel_note.className="edit_add2";
	 		note_div2.appendChild(add_note);
	 		note_div2.appendChild(cancel_note);
	 		 //document.getElementById(note_div2.id).style.borderWidth="1px";
	 		//document.getElementById(note_div2.id).style.borderStyle="solid";
	 		note.appendChild(note_div2);
    	// Functionality of the "ADD" comment button
    			document.getElementById(add_note.id).onmouseover=function() {
			    document.getElementById(add_note.id).className="edit_add_over2";
    					};
	 			document.getElementById(add_note.id).onmouseout = function() {
			    document.getElementById(add_note.id).className="edit_add2";
    					};		
    			document.getElementById(add_note.id).onclick = function() {
    			document.getElementById(note.id).style.visibility='hidden';
    			document.getElementById(note.id).style.display='none';
    			document.getElementById(edit.id).innerHTML='Edit NOTES';
    			text_note=note_input.value.substring(0,5);
    			document.getElementById(td1.id).innerHTML =name + '<br> ('+ text_note + '...)';
    			     	};
    			     	
    	// Functionality of the "CANCEL" comment button
    			document.getElementById(cancel_note.id).onmouseover=function() {
			    document.getElementById(cancel_note.id).className="edit_add_over2";
    					};
	 			document.getElementById(cancel_note.id).onmouseout = function() {
			    document.getElementById(cancel_note.id).className="edit_add2";
    					};		
    			document.getElementById(cancel_note.id).onclick = function() {
    			document.getElementById(td1.id).innerHTML =name;
    			document.getElementById(edit.id).innerHTML='Add NOTES';
    			document.getElementById(note.id).parentNode.removeChild(note);
    			     	};
   	
	 	} else {
	 	noteId="div_note" + idvar;
	 		document.getElementById(noteId).style.visibility='visible'; 
	 		document.getElementById(noteId).style.display='block';  					    					    						
    			};
  
    	};

} 


// those are the functions for the "Drop" button of catering.php

function drop_over(idVar){
class_var =document.getElementById(idVar).className; 
switch(class_var){
case "drop":
document.getElementById(idVar).className="drop_over";
break;
case "drop_open":
document.getElementById(idVar).className="drop_open_over";		
		}
}


function drop_out(idVar){
class_var=document.getElementById(idVar).className; 
switch(class_var){
case "drop_over":
document.getElementById(idVar).className="drop";
break;
case "drop_open_over":
document.getElementById(idVar).className="drop_open";		
		}
}


function drop_click(idVar,container){
class_var =document.getElementById(idVar).className; 
switch(class_var){
case "drop_over":
document.getElementById(idVar).className="drop_open_over";
document.getElementById(container).className="hide";
break; 
case "drop":
document.getElementById(idVar).className="drop_open";
break;
case "drop_open_over":
document.getElementById(idVar).className="drop_over";
document.getElementById(container).className="category_Item_container";
break; 
case "drop_open": 
document.getElementById(idVar).className="drop";
			} 
}


function calcolate(idbutton,idtotal){
total=0;
//breakfast category
var category=["breakfast", "coffee", "salad", "plater", "cake", "pizza"];
for (element in category ) {
	for (i=1; i<=10; i ++){
	   id_id= category[element] + "_" + i;
		idvar = "catering_" + category[element] + category[element] + "_" + i;
		idvar_price = "catering_" + category[element] + "_price" + category[element] + "_" + i;
		number = 0;		
//    quantity_form.id="catering_" + category + idvar;
//    price_form.id="catering_" + category + "_price" + idvar;   			
		
		if(
		(document.getElementById(idvar) !== null)
		){
			number = document.getElementById(idvar).value;
			idMin="catering_min" +  category[element] + category[element] + "_" + i ;
			minNumber=document.getElementById(idMin).value;
			minNumber = parseInt(minNumber); 
				if ((number < minNumber )||(number >  999)){
				   row_id="row_" + id_id;
				   document.getElementById(row_id).className= "row_wrong";
					alert (row_id + " Enter a valid number between a minimum of " + minNumber + " and a maximum of 999");
					number= minNumber ;
					document.getElementById(idvar).value=minNumber ;
					}
											
								
		//Integer number only
				if (number != parseInt(number)){
					alert("Integer Numbers only!");
					number= minNumber ;
					document.getElementById(idvar).value=minNumber ;
					}
					
					priceTxt= document.getElementById(idvar_price).value;
							
	price = (priceTxt) ;
	total = total + (price * number);

					
}

	}
}
//document.getElementById(idtotal).innerHTML= document.getElementById(idvar_price).value ;
document.getElementById(idtotal).innerHTML="$ " +  total   ;
}

