// JavaScript Document
function clearings(formN){
	if (formN.defaultValue == formN.value || formN.value == "email is not valid"){
		formN.value = "";
		formN.style.color = "black";
	}
	
}
function valForm(cPage){
	
	var error = "";
	var whereIs = "";
	var emailFilter = /^.+@.+\..{2,3}$/;
	
	if(document.inputForm.cEmail.value == "" || document.inputForm.cEmail.value == "email"){
			error = error + "email,";
			whereIs = whereIs + "cEmail,";
	}else{
		if (!(emailFilter.test(document.inputForm.cEmail.value))) { 
					error = error + "email is not valid,";
					whereIs = whereIs + "cEmail,";
				}
	}
	if(document.inputForm.cName.value == "" || document.inputForm.cName.value == "name"){
					error = error + "name,";
					whereIs = whereIs + "cName,";
			}
	//-------------------for booking page
	if(cPage == "booking"){
			var spaceRemove1 = " ";
			var spaceRemove2 = "";
			var newStringings = document.inputForm.cHomeTel.value.replace(spaceRemove1, spaceRemove2);
			if(isNaN(newStringings) || newStringings.length < 6){
					error = error + "phone,";
					whereIs = whereIs + "cHomeTel,";
			}
			if(document.inputForm.cMake.value == "" || document.inputForm.cMake.value == "make"){
					error = error + "make,";
					whereIs = whereIs + "cMake,";
			}
			if(document.inputForm.cModel.value == "" || document.inputForm.cModel.value == "model"){
					error = error + "model,";
					whereIs = whereIs + "cModel,";
			}
			if(document.inputForm.cReg.value == "" || document.inputForm.cReg.value == "Year of registration"){
					error = error + "Year of registration,";
					whereIs = whereIs + "cReg,";
			}
			if(document.inputForm.cDateS.value == "" || document.inputForm.cDateS.value == "Preferred date for service"){
					error = error + "Preferred date for service,";
					whereIs = whereIs + "cDateS,";
			}
			if(document.inputForm.cHomeAd.value == "" || document.inputForm.cHomeAd.value == "address"){
					error = error + "address,";
					whereIs = whereIs + "cHomeAd,";
			}
			if(document.inputForm.cHomework[1].checked){
				if(document.inputForm.cWorkTel.value == "" || document.inputForm.cWorkTel.value == "work phone"){
					error = error + "work phone,";
					whereIs = whereIs + "cWorkTel,";
				}
				if(document.inputForm.cWorkAd.value == "" || document.inputForm.cWorkAd.value == "work address"){
						error = error + "work address,";
						whereIs = whereIs + "cWorkAd,";
				}
			}
			
	}
	
	if(error){
		var whereIsErr = whereIs.split(",");
		var errors = error.split(",");
		for(i=0; i < (errors.length - 1); i++){
			document.getElementById(whereIsErr[i]).value = errors[i];
			document.getElementById(whereIsErr[i]).style.color = "red";
			//document.getElementById("errYear").style.fontSize = "60%";
		}
			document.getElementById("errReport").innerHTML = "Some errors were found, they are highlighted in red";
			document.getElementById("errReport").style.color = "red";
			document.getElementById("errReport").style.fontSize = "80%";
		
		return (false);
	}
}

function showEx(postId, cWhich){

	var whichpost = document.getElementById(postId); 
	if (cWhich=="home") { 
		whichpost.className="collapseblock";
	}else{ 
		whichpost.className="expandblock";
	} 
}	
