//All Craftsmen Profile Scripts.

/*  Form Verification   */

function verifyForm() {
	var formIsGood = true;
	var alertString = '';
	if (!$F('login-form-name')) {
		alertString += "You didn't enter a Name\n"
		new Effect.Highlight($('login-form-name'))		
	}
	if (!verifyTel()) {
		formIsGood = false;
		alertString += "Not a real Telephone Number\n"
		new Effect.Highlight($('login-form-tel'))
	}
	if (!verifyEmail()) {
		formIsGood = false;
		alertString += "Not a real Email Address\n"
		new Effect.Highlight($('login-form-email'))
	}
	if (!$F('login-form-houseno')) {
		alertString += "Not a real House Number\n"
		new Effect.Highlight($('login-form-houseno'))
		
	}
	if (!verifyPostcode()) {
		formIsGood = false;
		alertString += "Not a real Postcode\n"
		new Effect.Highlight($('login-form-postcode'))
	}
	if (!formIsGood) alert(alertString);
	return formIsGood;
	
}

function verifyTel() {
	var tel = $F('login-form-tel');
	var telNoSpaces = tel.split(' ').join('');
	
	var re = /^0[1278][0-9]{8,9}$/;
	if (re.test(telNoSpaces)) {
		return true;		
	}
	return false
	
}

function verifyEmail() {
	var email1 = $F('login-form-email');	
	
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (re.test(email1)) {
		return true;
	} 		
	else {
		return false;
	}
}

function verifyPostcode() {

	var re = /^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/
	var postcode = $F('login-form-postcode').split(' ').join('');
	if (re.test(postcode)) {
		return true;		
	}
	else {
		return false;
	}
}

/** Sliding Boxes **/
function toggleView (div_id) {
	theDiv = $(div_id)
	if (!theDiv) return false;
	if (theDiv.hasClassName('open')) {
		new Effect.SlideUp(theDiv,{duration:0.2})
		theDiv.removeClassName('open')
	}
	else {
		new Effect.SlideDown(theDiv,{duration:0.2})
		theDiv.addClassName('open')
	}
}

