// JavaScript Document

function init() {
	//alert(document.body.clientHeight);
	preload();
}

function randtestimonial() {
	
	var testimonials = new Array;
	testimonials[1] = '&quot;Since moving to smaller premises we can now store any goods we wish off site whilst keeping the costs of our premises to a minimum&quot;'; 
	
	testimonials[2] = '&quot;I used U Can Store It to store my household belongings because they offer excellent storage units with great security at reasonable prices&quot;';
	
	testimonials[3] = '&quot;Our company use U Can Store It to safely store our entire stock inventory eliminating costly overheads&quot;';
	
	testimonials[4] = '&quot;Before we rented our unit from U Can Store It any surplus materials at the end of a job would be thrown away&quot;';
	
	testimonials[5] = '&quot;Varied rental terms allow us to have greater control over storage&quot;';
	
	document.getElementById("testimonial").innerHTML = testimonials[(Math.round((Math.random()*4)+1))];
	
}

function swapThisImage(oElement){
	imageSource = oElement.src;
	arrayParts = imageSource.split('.');
	var extension = arrayParts.pop();
	var path = arrayParts.join('.');
	if(imageSource.lastIndexOf('2.') > 1) {
		path = path.substring(0,path.length-1)
		oElement.src = path + '.' + extension;
	} else {
		oElement.src = path + '2.' + extension;
	}
}

function verifyContactForm() {

	if (document.contactForm.name.value == '') {
		alert('Please enter your name');
		document.contactForm.name.focus();
		return false;
	}

	if (document.contactForm.email.value == '') {
		alert('Please enter your email address');
		document.contactForm.email.focus();
		return false;
	}

	/*if (document.contactForm.address.value == '') {
		alert('Please enter your address');
		document.contactForm.address.focus();
		return false;
	}

	if (document.contactForm.postCode.value == '') {
		alert('Please enter your postcode');
		document.contactForm.postCode.focus();
		return false;
	}*/

	if (document.contactForm.phone.value == '') {
		alert('Please enter your phone number');
		document.contactForm.phone.focus();
		return false;
	}

	if (typeof(document.contactForm.preferredLocation) != 'undefined') {
		if (document.contactForm.preferredLocation.value == '') {
			alert('Please enter a preferred storage location');
			document.contactForm.preferredLocation.focus();
			return false;
		} else {
			if (document.contactForm.preferredLocation.value == 'West Bromwich') {
				document.contactForm.h_id.value = "2603B";
			} else {
				document.contactForm.h_id.value = "2603A";
			}
		}
	}

	return true;
}

function verifyQuoteForm() {

	if (document.quoteForm.name.value == '') {
		alert('Please enter your name');
		document.quoteForm.name.focus();
		return false;
	}

	if (document.quoteForm.email.value == '') {
		alert('Please enter your email address');
		document.quoteForm.email.focus();
		return false;
	}

	/*if (document.quoteForm.address.value == '') {
		alert('Please enter your address');
		document.quoteForm.address.focus();
		return false;
	}

	if (document.quoteForm.postCode.value == '') {
		alert('Please enter your postcode');
		document.quoteForm.postCode.focus();
		return false;
	}*/

	if (document.quoteForm.phone.value == '') {
		alert('Please enter your phone number');
		document.quoteForm.phone.focus();
		return false;
	}
	
	if (document.quoteForm.preferredLocation.value == '') {
		alert('Please enter a preferred storage location');
		document.quoteForm.preferredLocation.focus();
		return false;
	} else {
		if (document.quoteForm.preferredLocation.value == 'West Bromwich') {
			document.quoteForm.h_id.value = "2603B";
		} else {
			document.quoteForm.h_id.value = "2603A";
		}
	}

	if (document.quoteForm.storageWhat.value == '') {
		alert('Please enter what you would like to store');
		document.quoteForm.storageWhat.focus();
		return false;
	}

	return true;
}

function verifyHuman(formName) {
	document[formName].h_formValidated.value = 'true'
}

function verifyCallbackForm() {

	if (document.callbackForm.phone.value == '') {
		alert('Please enter your phone number');
		document.callbackForm.phone.focus();
		return false;
	}

	if (document.callbackForm.h_formValidated.value != 'true') {
		alert('To prevent automated SPAM, we require you to enter your phone number manually.');
		document.callbackForm.phone.focus();
		return false;
	}

	return true;
}

function verifyReserveForm() {
	oForm = document.reserveForm;

	if (oForm.Name.value == '') {
		alert('Please enter your name');
		oForm.Name.focus();
		return false;
	}

	if (oForm.Address.value == '') {
		alert('Please enter your address');
		oForm.Address.focus();
		return false;
	}

	if (oForm.Telephone.value == '') {
		alert('Please enter your telephone number');
		oForm.Telephone.focus();
		return false;
	}

	if (!validateEmail(oForm.Email.value)) {
		alert('Please enter a valid email address');
		oForm.Email.focus();
		return false;
	}

	if (oForm["Estimated Start Date"].value == '') {
		alert('Please select your estimated start date');
		oForm["Estimated Start Date"].focus();
		return false;
	}

	var radioChecked = false;
	for (i = 0; i <oForm.Container.length; i++) {
		if (oForm.Container[i].checked) {
			radioChecked = true;
		}
	}
	if (!radioChecked) {
		alert('Please select the type of container you wish to reserve');
		return false;
	}

	if (oForm.h_formValidated.value != 'true') {
		alert('To prevent automated SPAM, we require you to enter your name manually.');
		oForm.Name.focus();
		return false;
	}

	return true;
}


var hover = new Array();
hover[0] = "images/nnav_home2.jpg";
hover[1] = "images/nnav_household2.jpg";
hover[2] = "images/nnav_business2.jpg";
hover[3] = "images/nnav_document2.jpg";
hover[4] = "images/nnav_about2.jpg";
hover[5] = "images/nnav_prices2.jpg";

var normal = new Array();
normal[0] = "images/nnav_home.jpg";
normal[1] = "images/nnav_household.jpg";
normal[2] = "images/nnav_business.jpg";
normal[3] = "images/nnav_document.jpg";
normal[4] = "images/nnav_about.jpg";
normal[5] = "images/nnav_prices.jpg";

function imageSwap(oEle, index) {
	oEle.src = relpath + hover[index];
}

function imageRestore(oEle, index) {
	oEle.src = relpath + normal[index];
}

function preload() {
	for(var i=0; i<hover.length; i++){
		if (document.images){
			preload_image = new Image(); 
			preload_image.src = relpath + hover[i];
		}
	}
}



function openImage(str_URL, str_title, int_width, int_height, str_resize, str_scroll, str_autoSize) {
	if (int_width == 0) {
		int_width = 600
	} if (int_height == 0) {
		int_height = 400
	} if (str_resize != 'yes') {
		str_resize = 'no'
	} if (str_scroll != 'yes') {
		str_scroll = 'no'
	}
	
	newWindow = window.open('', '_blank', 'width='+int_width+',height='+int_height+',menubar=off,directories=off,toolbar=off,resizable='+str_resize+',scrollbars='+str_scroll);
	newWindow.document.write("<html>")
	newWindow.document.write("<title>" + str_title + "</title>")
	
	if (str_autoSize = 'yes') {
		newWindow.document.write("<body onload=\"window.resizeTo(document.getElementById('myImage').width+30, document.getElementById('myImage').height+70)\">")
	} else {
		newWindow.document.write("<body>")
	}
	
	newWindow.document.write("<img src='" + str_URL + "' alt='" + str_title + "' id='myImage' />")
	newWindow.document.write("</body>")
	newWindow.document.write("</html>")
	newWindow.document.close()
	if (window.focus) {newWindow.focus()};
}


function popImage(imageUrl, pOrL){
	if(pOrL == "l"){
		winWidth = "590";
		winHeight = "473";
	} else {
		winWidth = "453";
		winHeight = "610";
	}
	window.open('../info/imagepop.asp?imageURL='+imageUrl,'register','width='+winWidth+',height='+winHeight+',menubar=0,directories=0,toolbar=0,location=0,status=0,resizable=no,scrollbars=no');
}

function validateEmail(email_address) {
	if (/\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email_address)){
		return true;
	}
	return false;
}