/*
#   P&G	- Display, Handling and Validation for the ContactUs Form 
#   Brand:             Ariel
#   Country:           UK   
#   Language:          English
#   Live Address:      DEFAULT
#   Staging Address:   DEFAULT
#   Mon May 31 10:41:57 2004  Eugen Fleseriu@berg COMPUTERS
#	Changes 02.10.2006 Daniel Haiduc @ berg COMPUTERS
*/

/*
  Functions For Handling Selected Items From Forms

function FeedBackTypeChanged(lselectedfeedbacktype)
{
		document.contact_us.product_form.selectedIndex=0;
	//set global variables
	bFeedbackTypeSelected = true;
	lselectedfeedback_type = lselectedfeedbacktype;
	//Check if complaint or question contition meet
	ComplaintOrQuestion4ProductForm();
	
	//Check if conditions meet and load Feedback Topics
	LoadFeedbackTopics();
}

function FeedBackAboutChanged(aboutSelectedIndex)
{
		document.contact_us.product_form.selectedIndex=0;
	bProductSelected = true;
	if (aboutSelectedIndex == 0)
	{
		bProductSelected = false;
		document.getElementById("product_form_all").style.display = "none"
	}
	if (aboutSelectedIndex == 1)
	{
		document.getElementById("product_form_all").style.display = "none"
	}
	if (aboutSelectedIndex == 2)
	{
		document.getElementById("product_form_all").style.display = "none"
	}	
	if (aboutSelectedIndex == 3)
	{
		document.contact_us.product_form.selectedIndex=0;
		document.getElementById("product_form_all").style.display = ""
	}

	if (aboutSelectedIndex == 4)
	{
		document.contact_us.product_form.selectedIndex=0;
		document.getElementById("product_form_all").style.display = ""
	}

	if (aboutSelectedIndex == 5)
	{
		document.contact_us.product_form.selectedIndex=0;
		document.getElementById("product_form_all").style.display = ""
	}
	if (aboutSelectedIndex == 6)
	{
		document.contact_us.product_form.selectedIndex=0;
		document.getElementById("product_form_all").style.display = ""
	}
	//Check if complaint or question contition meet
	ComplaintOrQuestion4ProductForm();
	
	//Check if conditions meet and load Feedback Topics
	LoadFeedbackTopics();
}

function ComplaintOrQuestion4ProductForm()
{
	if (bProductSelected && bFeedbackTypeSelected)
	{
		if (((document.contact_us.feedback_about.selectedIndex == 3) || 
			(document.contact_us.feedback_about.selectedIndex == 4) || 
			(document.contact_us.feedback_about.selectedIndex == 5) || 
			(document.contact_us.feedback_about.selectedIndex == 6)) && 
			((lselectedfeedback_type == 2) || 
			(lselectedfeedback_type == 3)) &&
			(document.contact_us.product_form.selectedIndex != 0))
		{
			document.contact_us.product_wash_size.selectedIndex = 0;
			ShowComplaintOrQuestion4ProductFormLayer();
		} else {
			document.contact_us.product_wash_size.selectedIndex = 0;
			HideComplaintOrQuestion4ProductFormLayer();
		}
	} else {
			document.contact_us.product_wash_size.selectedIndex = 0;
			HideComplaintOrQuestion4ProductFormLayer();
	}
}


function LoadFeedbackTopics()
{

	if(bProductSelected && bFeedbackTypeSelected)
	{
		if (document.contact_us.feedback_about.selectedIndex == 0)
		{
			document.contact_us.feedback_topic.selectedIndex=0;
			document.contact_us.feedback_topic.options[0]=new Option('Select a feeback type and product', '');
			document.contact_us.feedback_topic.length=1;
		}
		if (document.contact_us.feedback_about.selectedIndex == 1)
		{
			document.contact_us.feedback_topic.selectedIndex=0;
			document.contact_us.feedback_topic.options[0]=new Option('select one', '');
			document.contact_us.feedback_topic.options[1]=new Option('Advertising/Commercials', '1');
			document.contact_us.feedback_topic.options[2]=new Option('Availability/Finding products', '2');
			document.contact_us.feedback_topic.options[3]=new Option('Cleaning Ability/Stains', '3');
			document.contact_us.feedback_topic.options[4]=new Option('Coupons/Samples/Promotions/Sponsorship', '4');
			document.contact_us.feedback_topic.options[5]=new Option('Customer Service', '5');
			document.contact_us.feedback_topic.options[6]=new Option('Effect on Fabrics', '6');
			document.contact_us.feedback_topic.options[7]=new Option('Health/Safety', '7');
			document.contact_us.feedback_topic.options[8]=new Option('How to use/Information request', '8');
			document.contact_us.feedback_topic.options[9]=new Option('Label appearance/Instructions', '9');
			document.contact_us.feedback_topic.options[10]=new Option('Package quality/Design', '10');
			document.contact_us.feedback_topic.options[11]=new Option('Other', '16');
			document.contact_us.feedback_topic.length=12;
		}
		if (document.contact_us.feedback_about.selectedIndex == 2)
		{
			document.contact_us.feedback_topic.selectedIndex=0;
			document.contact_us.feedback_topic.options[0]=new Option('select one', '');
			document.contact_us.feedback_topic.options[1]=new Option('Content/Articles/Tips', '11');
			document.contact_us.feedback_topic.options[2]=new Option('Navigation/Usability', '12');
			document.contact_us.feedback_topic.options[3]=new Option('Personal information/Privacy statement', '13');
			document.contact_us.feedback_topic.options[4]=new Option('Special offers', '14');
			document.contact_us.feedback_topic.options[5]=new Option('Stain Detective', '15');
			document.contact_us.feedback_topic.options[6]=new Option('Other', '16');
			document.contact_us.feedback_topic.length=7;
		}
		if ((document.contact_us.feedback_about.selectedIndex == 3) || 
			(document.contact_us.feedback_about.selectedIndex == 4) || 
			(document.contact_us.feedback_about.selectedIndex == 5) || 
			(document.contact_us.feedback_about.selectedIndex == 6))
		{
			document.contact_us.feedback_topic.selectedIndex=0;
			document.contact_us.feedback_topic.options[0]=new Option('select one', '');
			document.contact_us.feedback_topic.options[1]=new Option('Advertising/Commercials', '17');
			document.contact_us.feedback_topic.options[2]=new Option('Availability/Finding products', '18');
			document.contact_us.feedback_topic.options[3]=new Option('Cleaning Ability/Stains', '19');
			document.contact_us.feedback_topic.options[4]=new Option('Coupons/Samples/Promotions/Sponsorship', '20');
			document.contact_us.feedback_topic.options[5]=new Option('Customer Service', '21');
			document.contact_us.feedback_topic.options[6]=new Option('Effect on Fabrics', '22');
			document.contact_us.feedback_topic.options[7]=new Option('Health/Safety', '23');
			document.contact_us.feedback_topic.options[8]=new Option('How to use/Information request', '24');
			document.contact_us.feedback_topic.options[9]=new Option('Label appearance/Instructions', '25');
			document.contact_us.feedback_topic.options[10]=new Option('Package quality/Design', '26');
			document.contact_us.feedback_topic.options[11]=new Option('Dispensing/Pouring', '27');
			document.contact_us.feedback_topic.options[12]=new Option('Foaming/Sudsing', '28');
			document.contact_us.feedback_topic.options[13]=new Option('General likes/Dislikes', '29');
			document.contact_us.feedback_topic.options[14]=new Option('Other', '16');
			document.contact_us.feedback_topic.length=15;

		}		
	} else {
		document.contact_us.feedback_topic.selectedIndex=0;
		document.contact_us.feedback_topic.options[0]=new Option('Select a feeback type and product', '');
		document.contact_us.feedback_topic.length=1;
	}
}
*/

/*
Helper functions for validations
*/

function trim(str){
	// trim removes all leading and trailing spaces of string str
	// remove all leading spaces of str
	var i = 0;
	while ((i < str.length) && (str.charAt(i) == ' ')){
		i++;
	}
	str = str.substring(i);
	// remove all trailing spaces of str
	i = str.length;
	while ((i > 0) && (str.charAt(i-1) == ' ')){
		i--;
	}
	str = str.substring(0,i);
	return str;
}

function isInt(strNumber){
	// isInt checks if the string strNumber is an integer.
	return ( !(isNaN(parseInt(strNumber))) );
}

function isListboxSelected(objForm, fieldname){
  /* isListboxSelected checks if an item in the listbox "fieldname" in form "formname"
    is selected. It assumes that when an item with value '' is selected, none of the
    options are selected. This is the case in all required listbox fields on the Contact Us page. 
  */
	iSelIndex = objForm.elements[fieldname].options.selectedIndex;
	return ( !((iSelIndex == -1) || (objForm.elements[fieldname].options[iSelIndex].value == '')) );
}

function isTextFieldEmpty(objForm, fieldname){
	/* isTextFieldEmpty checks if field "fieldname" in form "form" is empty or only
    contains white space characters */
	if(trim(objForm.elements[fieldname].value)=='' || objForm.elements[fieldname].value=="Enter value"){
		return true;
	}
}

function isValidEmailAddress(pstrEmailAddress){
	// isValidEmailAddress checks if the string pstrEmailAddress contains an @ symbol
	return (pstrEmailAddress.indexOf('@') != -1)
}

function checkAge(refAge, birthMonth, birthYear){
	/* checkAge checks if a person with birth month birthMonth and birth year birthYear is of age 
	refAge or older than refAge. Birth day will be the first of the month in the check.*/
	var birthDay = '1';
	var dtBirth = new Date(birthYear, birthMonth, birthDay);
	var dtCurrent = new Date();
	var dtRef = new Date(dtCurrent.getYear()-refAge, dtCurrent.getMonth(), dtCurrent.getDate());
	return (dtBirth <= dtRef);
}

function isValidYear(pstrYear){
	/* isValidYear checks if pstrYear contains a valid birth year. If so, isValidYear returns true,
	otherwise isValidYear returns false */
  
	if (isInt(pstrYear)){
		var iYear = parseInt(pstrYear);
		var bYear = ((iYear.toString()).length == 4) && (iYear>=1900);
		return bYear;
	}else{
		return false;
	}
}
/*
Function for form validation
*/
function CheckContactUsFormAndSubmitIfValid(objForm)
{
	var bCheckForm = true;
	if(isTextFieldEmpty(objForm, 'feedback_message')){
		document.getElementById("errormsg").innerHTML = "Please specify a comment or message."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.feedback_message.focus();
		bCheckForm = false;
	} else if(isTextFieldEmpty(objForm, 'email_address')){
		document.getElementById("errormsg").innerHTML = "Please specify your e-mail address."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.email_address.focus();
		bCheckForm = false;
	} else if(!isValidEmailAddress(objForm.email_address.value)){
		document.getElementById("errormsg").innerHTML = "The e-mail address you have specified is invalid."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.email_address.focus();
		bCheckForm = false;
	} else if(!isListboxSelected(objForm, 'title')) {
		document.getElementById("errormsg").innerHTML = "Please select a Title."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		bCheckForm = false;
	} else if(isTextFieldEmpty(objForm, 'first_name')){
		document.getElementById("errormsg").innerHTML = "Please specify your First Name."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.first_name.focus();
		bCheckForm = false;
	} else if(isTextFieldEmpty(objForm, 'surname')){
		document.getElementById("errormsg").innerHTML = "Please specify your Surname."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.surname.focus();
		bCheckForm = false;
	}  /*else if (!isListboxSelected(objForm, 'birth_month')){
		document.getElementById("errormsg").innerHTML = "Please select Birth Month."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		bCheckForm = false;
	} else if (isTextFieldEmpty(objForm, 'birth_year')){
		document.getElementById("errormsg").innerHTML = "Please select a Title."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.birth_year.focus();
		bCheckForm = false;
	} else if (!isValidYear(objForm.birth_year.value)){
		document.getElementById("errormsg").innerHTML = "Please select a Title."
		document.getElementById("error").style.display = "";
		location.href="#errorbox";
		objForm.birth_year.focus();
		bCheckForm = false;
	} else if (!checkAge (18, objForm.birth_month.value, objForm.birth_year.value)){
		document.getElementById("birth_underage_error").style.display = ""
		location.href="#errorbox";
		objForm.birth_year.focus();
		bCheckForm = false;
	}*/
	
	return bCheckForm;
}

function HideErrors()
{
	document.getElementById("error").style.display = "none"
}

/*
Function for display/hide for items

function HideAllErrors()
{
	document.getElementById("feedback_type_error").style.display = "none";
	document.getElementById("feedback_about_error").style.display = "none";
	document.getElementById("feedback_topic_error").style.display = "none";
	document.getElementById("feedback_message_error").style.display = "none";
	document.getElementById("email_address_empty_error").style.display = "none";
	document.getElementById("email_address_invalid_error").style.display = "none";
	document.getElementById("title_error").style.display = "none";
	document.getElementById("first_name_error").style.display = "none";	
	document.getElementById("surname_error").style.display = "none";
	document.getElementById("birth_month_error").style.display = "none";
	document.getElementById("birth_year_error").style.display = "none";
	document.getElementById("birth_year_value_error").style.display = "none";
	document.getElementById("birth_underage_error").style.display = "none";
	document.getElementById("valuable_offers_bold_error").style.display = "none";
	document.getElementById("valuable_offers_other_error").style.display = "none";
	
	ComplaintOrQuestion4ProductForm();
}

function SetFormForFirstTimeDisplay()
{
	HideAllErrors();
	document.getElementById("product_form_all").style.display = "none";
}

function ShowComplaintOrQuestion4ProductFormLayer()
{
	document.getElementById("ComplaintOrQuestion4ProductFormLayer1").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer2").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer3").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer4").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer5").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer6").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer7").style.display = ""
	document.getElementById("ComplaintOrQuestion4ProductFormLayer8").style.display = ""
}

function HideComplaintOrQuestion4ProductFormLayer()
{
	document.getElementById("ComplaintOrQuestion4ProductFormLayer1").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer2").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer3").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer4").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer5").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer6").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer7").style.display = "none"
	document.getElementById("ComplaintOrQuestion4ProductFormLayer8").style.display = "none"
}
*/