window.onresize = do_resize;

// Script Enables Background Image Logo to be set as a hyperlink
window.onload = function() 
{
	if (document.getElementById) 
	{
		do_resize();
			
		/* Associate logo's onclick event with home page */
		var logo = document.getElementById("logo");
 		if (logo != null) {
			logo.onclick = function() {
				window.location = 'index.php';
				return false;
			}
		}
		
		aLinks = document.getElementsByTagName("a");
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if (aLinks[aIndex].href.indexOf('http://www.katebloom.co.uk') == -1) 
			{
				aLinks[aIndex].target = '_blank';
			}
		}		

		var aCommentsForm = document.getElementById('commentsform');
		if (aCommentsForm != null) aCommentsForm.onsubmit = JSFnValidateCommentForm;
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;

		var aBookingForm = document.getElementById('bookingform');
		if (aBookingForm != null) aBookingForm.onsubmit = JSFnValidateBookingForm;

		var aSendCVForm = document.getElementById('sendcvform');
		if (aSendCVForm != null) aSendCVForm.onsubmit = JSFnValidateSendCVForm;

//		var aMailOffer1Form = document.getElementById('mailoffer1');
//		if (aMailOffer1Form != null) aMailOffer1Form.onsubmit = JSFnValidateMailOffer1Form;

		var aMailOffer2Form = document.getElementById('mailoffer2');
		if (aMailOffer2Form != null) aMailOffer2Form.onsubmit = JSFnValidateMailOffer2Form;
		
		var aPrint = document.getElementById("printbutton");
		if (aPrint != null)
		{
			aPrint.innerHTML = '<input type="button" value="Print" onclick="window.print();" class="button printbutton"></input>';
		}
    }
}

var aContactRequiredFields = new Array ("Name","Please enter your name to continue");
function JSFnValidateContactForm()
{
	var aEmail = document.getElementById('Email');
	var aTelephone = document.getElementById('Telephone');
	var aFax = document.getElementById('Fax');
	if ((aEmail != null) && (aTelephone != null) && (aFax != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == '') && (aFax.value == ''))
		{
			alert('You must provide either your telephone/fax number or email address to continue.');
			return false;
		}
	}
	
	return JSFnValidateForm(aContactRequiredFields);
}

var aCommentsRequiredFields = new Array ("Email","Please enter your email address to continue");
function JSFnValidateCommentForm()
{
	return JSFnValidateForm(aCommentsRequiredFields);
}

var aBookingRequiredFields = new Array ("Name","Please enter your name to continue",
										"Address","Please enter your address to continue",
										"Postcode","Please enter your postcode to continue",
										"TelephoneHome","Please enter your telephone no to continue",
										"EmailAddress","Please enter your email address to continue",
										"Date","Please enter a date to continue",
										"Time","Please enter a time to continue",
										"Stylist","Please select a stylist to continue",
										"Service","Please enter service required to continue");
function JSFnValidateBookingForm()
{
	return JSFnValidateForm(aBookingRequiredFields);
}

var aSendCVRequiredFields = new Array ("Name","Please enter your name to continue",
										"Address","Please enter your address to continue",
										"Postcode","Please enter your postcode to continue",
										"TelephoneHome","Please enter your telephone no to continue",
										"EmailAddress","Please enter your email address to continue",
										"Interest","Please enter the position you are interested in to continue",
										"attachment1","Please attach your CV to continue");
function JSFnValidateSendCVForm()
{
	return JSFnValidateForm(aSendCVRequiredFields);
}

var aMailOffer1RequiredFields = new Array ("Email","Please enter your email address to continue");

function JSFnValidateMailOffer1Form()
{
	return JSFnValidateForm(aMailOffer1RequiredFields);
}

var aMailOffer2RequiredFields = new Array ("Name","Please enter your name to continue",
										   "Address","Please enter your address to continue",
										   "Postcode","Please enter your postcode to continue",
										   "TelHome","Please enter your telephone no to continue",
										   "HearBy","Please select 'Where did you hear about us?' to continue");

function JSFnValidateMailOffer2Form()
{
	return JSFnValidateForm(aMailOffer2RequiredFields);
}


function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if  (   (   (currElement.type == 'text')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'password')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'checkbox')
				     && (currElement.checked == false))
				 || (   (currElement.type == 'file')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'textarea')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'select-one')
				     && (currElement.value == '')))
			{
				alert(aRequiredFields[aIndex + 1]);
				return false;
			}
			else if (currElement.type == 'radio')
			{
				aIndex = aIndex + 2;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}

function do_resize()
{
	if (document.getElementById) 
	{
		var aRightImg = document.getElementById("rightimg");
		var aLeftImg = document.getElementById("leftimg");
 		if ((aRightImg != null) && (aLeftImg != null))
		{
			if (document.documentElement.clientWidth < 1000) 
			{
				aRightImg.style.display = 'none';
				aLeftImg.style.display = 'none';
			}
			else
			{
				aRightImg.style.display = 'block';
				aLeftImg.style.display = 'block';
			}
		}
	}
}