function Require(obForm,vFields)
{ 
		            var fields = vFields.split(",");
		            var vMissing= new Array();
					for(x=0;x<fields.length;x++)
		               {	
						if( fields[x]=="age" || fields[x]=="country")
						{
							if (obForm.elements[fields[x]].value == "" || obForm.elements[fields[x]].value == -1)
							{
								vMissing[vMissing.length] = x;
							}	
						}
						else						
						if(obForm.elements[fields[x]].value.length==0)
		                    {
								//alert("The field "+fields[x]+" must be completed");	
							
								vMissing[vMissing.length] = x ;
							}
							/*
							if (obForm.elements[fields[x]].value == "-1" )
							{
								vMissing[vMissing.length] = x;
							}*/	
						
		               }
					if(vMissing.length>0)
		              {
		            //  alert("The field"+((vMissing.length>1)?"s ":" ")+vMissing.join(",")+" must be filled in first");
							ErrorMsg = "";
	
							for( var i=0; i<vMissing.length; i++ ){
								if( error_array[ vMissing[i] ] )
									ErrorMsg += error_array[vMissing[i] ] + "\n";
							}
														
							if(ErrorMsg!="") 
							{
								alert(ErrorMsg );
								return false;
							}
		              }
		            return true;
}

function changePic()
{
	if (document.getElementById('mid').style.display == 'none')
					{										 	
						document.getElementById('mid').style.display='block';	  					 
						document.getElementById('bottom').style.display='block';
						document.getElementById('order').style.display='block';
						document.subscribe.show_all.value='all';
						document.getElementById('order_pic').src = 'images/order_free_sample_up.gif';
					}
					else
					{
						document.getElementById('mid').style.display='none';
						document.getElementById('bottom').style.display='none';
						document.getElementById('order').style.display='none';
						document.subscribe.show_all.value='';
						document.getElementById('order_pic').src = 'images/order_free_sample_down.gif';
					}
}


function changeShippPic()
{
	if (document.getElementById('mid').style.display == 'none')
					{										 	
						document.getElementById('mid').style.display='block';	
						document.getElementById('order').style.display='block';	
						document.subscribe.show_all.value='no_camp';
						document.getElementById('ship_pic').src = 'images/shipping_info_free_samples_up.gif';
					}
					else
					{
						document.getElementById('mid').style.display='none';	
						document.getElementById('order').style.display='none';							
						document.subscribe.show_all.value='';
						document.getElementById('ship_pic').src = 'images/shipping_info_free_Samples_down.gif';
					}	
}

function Require1(obForm,vFields)
{ 
	var fields = vFields.split(",");
	var vMissing= new Array();
	
	for(x=0;x<fields.length;x++)
    {	
        if(obForm.elements[fields[x]].value.length==0)
        {
			alert("The field "+fields[x]+" must be completed");
			vMissing[vMissing.length]=new String(fields[x]);
		}
    }

    if(vMissing.length)
    {
		             // alert("The field"+((vMissing.length>1)?"s ":" ")+vMissing.join(",")+" must be filled in first");
         return false
    }

	return true;
}
function submitTheSmallForm(form)
{
	if ( document.subscribe.show_all.value == 'no_camp' )
	{	
		var radioLength = document.subscribe.opt_online.length;
		var off = 0;
		var on = 0;
		var on_off = 0;
		
		for(var i = 0; i < radioLength; i++) 
		{
			if(document.subscribe.opt_offline[i].checked) 
			{
				off += 1;
			}
			if(document.subscribe.opt_online[i].checked) 
			{
				on += 1;
			}
			if(document.subscribe.opt_onoff[i].checked) 
			{
				on_off += 1;
			}
			
		}
		
		if (off == 0)
		{
			alert("Please indicate if you would like to receive free product samples from Envive and other  Procter & Gamble Feminine Care brands.");
		}
		else
			if (on == 0)
			{
				alert("Please indicate if you would like to receive news about Envive and other  Procter & Gamble Feminine Care brands");
			}
			else
				if (on_off == 0)
				{
					alert("Please indicate if you would like to receive the latest on-line information and samples from other Procter & Gamble brands.");
				}
				else
					if ( Require(form, 'email,email2,username,password,password2,fname,lname,address,city,postcode,country') )
						document.subscribe.submit();
	}
	else
	{
		if ( document.subscribe.show_all.value == 'all' )
		{
			submitTheForm(form);
		}
		else
		{	
			var radioLength = document.subscribe.opt_online.length;
			var off = 0;
			var on = 0;
			var on_off = 0;
			
			for(var i = 0; i < radioLength; i++) 
			{
				if(document.subscribe.opt_offline[i].checked) 
				{
					off += 1;
				}
				if(document.subscribe.opt_online[i].checked) 
				{
					on += 1;
				}
				if(document.subscribe.opt_onoff[i].checked) 
				{
					on_off += 1;
				}
				
			}
		
		
			if (on == 0)
			{
				alert("Please indicate if you would like to receive news about Envive and other  Procter & Gamble Feminine Care brands");
			}
			else
				if (on_off == 0)
				{
					alert("Please indicate if you would like to receive the latest on-line information and samples from other Procter & Gamble brands.");
				}
				else
					if ( Require(form, 'email,email2,username,password,password2') )
					document.subscribe.submit();	
		}
	}
}

function submitTheForm(form)
{ 
	var radioLength = document.subscribe.prod.length;
	var v = 0;
	
	for(var i = 0; i < radioLength; i++) 
	{
		if(document.subscribe.prod[i].checked) 
		{
			v += 1;
		}
	}
	
	if ( v==0)
	{
		alert("Sie haben kein Gratismuster ausgewählt. Bitte wählen Sie ein Gratismuster oder wählen Sie 'keines'");
	}
	else
	{
		var radioLength = document.subscribe.opt_online.length;
		var off = 0;
		var on = 0;
		var on_off = 0;
		
		for(var i = 0; i < radioLength; i++) 
		{
			if(document.subscribe.opt_offline[i].checked) 
			{
				off += 1;
			}
			if(document.subscribe.opt_online[i].checked) 
			{
				on += 1;
			}
			if(document.subscribe.opt_onoff[i].checked) 
			{
				on_off += 1;
			}
			
		}
		
		if (off == 0)
		{
			alert("Please indicate if you would like to receive free product samples from Envive and other  Procter & Gamble Feminine Care brands.");
		}
		else
			if (on == 0)
			{
				alert("Please indicate if you would like to receive news about Envive and other  Procter & Gamble Feminine Care brands");
			}
			else
				if (on_off == 0)
				{
					alert("Please indicate if you would like to receive the latest on-line information and samples from other Procter & Gamble brands.");
				}
				else
					if ( Require(form, 'email,email2,username,password,password2,fname,lname,address,city,postcode,country') )
						document.subscribe.submit();
	}		
}


function EmptyString(s) 
{ 
				var Count; 
				var Nblank = 0; 
				if (s.length == 0) return (true); // empty string 
				// count the number of blank chars 
				for (Count = 0; Count < s.length; Count++) { 
				if (s.charAt(Count) == " ") Nblank++; 
				} 
				if (Nblank == s.length) 
				return (true); 
				else 
				return (false); 
} // end EmptyString

function ValidEmail(s) 
{ 
				var Count; 
				var s2; 
				// empty or blank email 
				if (EmptyString(s) == false) {
					// email without @ 
					if (s.indexOf('@') == -1) return (false); 
					// email with @ as the 1st char 
					if (s.indexOf('@') == 0) return (false); 
					// email with @ as the last char 
					if ((s.indexOf('@')+1) == s.length) return (false); 
					// email without . 
					if (s.indexOf('.') == -1) return (false); 
					// email with . as the 1st char 
					if (s.indexOf('.') == 0) return (false); 
					// email with . as the last char 
					if ((s.indexOf('.')+1) == s.length) return (false); 
					// Now look for the first . after the first @ 
					// s2 = string after the first @ 
					s2=s.substring(s.indexOf('@')+1,s.length); 
					// email without a dot after the first @ 
					if (s2.indexOf('.') == -1) return (false); 
					// email dot right after the first @ 
					if (s2.indexOf('.') == 0) return (false); 
				}
				else
					return false;
				return (true); 
} // end ValidEmail


function submitTheFormFreesample(form)
{ 
	var radioLength = document.subscribe.prod.length;
	var v = 0;
	
	for(var i = 0; i < radioLength; i++) 
	{
		if(document.subscribe.prod[i].checked) 
		{
			v += 1;
		}
	}
	
	if ( v==0)
	{
		alert("Sie haben kein Gratismuster ausgewählt. Bitte wählen Sie ein Gratismuster.");
	}
	else
	{
		var radioLength = document.subscribe.opt_online.length;
		var zeit = 0;
		var on = 0;
		var on_off = 0;
		
		for(var i = 0; i < radioLength; i++) 
		{ 
			if(document.subscribe.opt_zeit[i].checked) 
			{
				zeit += 1;
			} 
			if(document.subscribe.opt_online[i].checked) 
			{
				on += 1;
			}
			if(document.subscribe.opt_onoff[i].checked) 
			{
				on_off += 1;
			}
			
		}
		/*
		if (off == 0)
		{
			alert("Please indicate if you would like to receive free product samples from Envive and other  Procter & Gamble Feminine Care brands.");
		}
		else */
			if ( (on == 0) || (on_off == 0) || (zeit == 0) )
			{
				alert("Bitte geben Sie an, ob Sie Online Informationen und Muster von Procter&Gamble Marken erhalten wollen!");
			}			
				else
				{
					
					if ( (document.subscribe.email.value!='') && !ValidEmail(document.subscribe.email.value) )
					{
						alert('Bitte geben Sie eine gültige E-Mail Adresse ein!');
					}
					else
					{					
						
							if ( checkDateDiv() &&  Require(form, 'email,fname,lname,address,city,country,postcode') )
							document.subscribe.submit();
						
					}
				}
					
	}		
}

function checkDateDiv()
{	
	var myDayStr = document.getElementById("daySelect").value;
	var myMonthStr = document.getElementById("monthSelect").value;
	var myYearStr = document.getElementById("yearSelect").value;
	var myMonth = new Array('January','February','March','April','May','June','July','August','September','October','November','December'); 
	var myDateStr = myDayStr + ' ' + myMonth[myMonthStr-1] + ' ' + myYearStr;

	var myDate = new Date();
	myDate.setFullYear( myYearStr, myMonthStr-1, myDayStr );

	if ( myDayStr!= -1 && myMonthStr!=-1 && myYearStr!=-1 )
	{
	
		if  (myDate.getMonth() != (myMonthStr-1) ) 
		{
			alert( 'Bitte prüfen Sie Ihre Angaben beim Datum!' );
			return false;
		} 
		else
		{
			return true;
		}
	}
	else
	{
		alert( 'Bitte wähle ein gültiges Datum aus!' );
		return false;
	}
}

function submitTheLogin(form)
{ 
	if ( Require(form, 'username,password') )
		document.loginform.submit();
}

function check_edit_subscribe()
{
	var radioLength = document.edit_subscribe.prod.length;
	var v = 0;
	
	for(var i = 0; i < radioLength; i++) 
	{
		if(document.edit_subscribe.prod[i].checked) 
		{
			v += 1;
		}
	}
	if ( v==0)
	{
		alert("Sie haben kein Gratismuster ausgewählt. Bitte wählen Sie ein Gratismuster oder wählen Sie 'keines'");
	}
	else
	{	
		var radioLength = document.edit_subscribe.opt_online.length;
		var off = 0;
		var on = 0;
		var on_off = 0;
		
		for(var i = 0; i < radioLength; i++) 
		{
			if(document.edit_subscribe.opt_offline[i].checked) 
			{
				off += 1;
			}
			if(document.edit_subscribe.opt_online[i].checked) 
			{
				on += 1;
			}
			if(document.edit_subscribe.opt_onoff[i].checked) 
			{
				on_off += 1;
			}
			
		}
			
			if (on == 0)
			{
				alert("Please indicate if you would like to receive news about Envive and other  Procter & Gamble Feminine Care brands");
			}
			else
				if (on_off == 0)
				{
					alert("Please indicate if you would like to receive the latest on-line information and samples from other Procter & Gamble brands.");
				}
				else
					if ( Require(document.edit_subscribe, 'email,email2,username,fname,lname,address,city,postcode,country') )
						document.edit_subscribe.submit();
	}		
}

function check_unsubscribe(r)
{

	if ( document.manage.unsubscribe.checked == true)
		{
			if ( confirm('You have selected to UNREGISTER from this website.  This action cannot be undone.  Are you sure you want to have your profile entirely removed from this website?') ) 
				document.manage.submit();
		}
	else
	{
		var radioLength = document.manage.prod.length;
		var v = 0;
		
		for(var i = 0; i < radioLength; i++) 
		{
			if(document.manage.prod[i].checked) 
			{
				v += 1;
			}
		}
		
		if ( v==0 && r=='n')
		{
			alert("Sie haben kein Gratismuster ausgewählt. Bitte wählen Sie ein Gratismuster oder wählen Sie 'keines'.");
		}
		else
		{
			var radioLength = document.manage.opt_online.length;
			var off = 0;
			var on = 0;
			var on_off = 0;
		
			for(var i = 0; i < radioLength; i++) 
			{
				if(document.manage.opt_offline[i].checked) 
				{
					off += 1;
				}
				if(document.manage.opt_online[i].checked) 
				{
					on += 1;
				}
				if(document.manage.opt_onoff[i].checked) 
				{
					on_off += 1;
				}
				
			}
			
			if (off == 0)
			{
				alert("Please indicate if you would like to receive free product samples from Envive and other  Procter & Gamble Feminine Care brands.");
			}
			else
				if (on == 0)
				{
					alert("Please indicate if you would like to receive news about Envive and other  Procter & Gamble Feminine Care brands");
				}
				else
					if (on_off == 0)
					{
						alert("Please indicate if you would like to receive the latest on-line information and samples from other Procter & Gamble brands.");
					}
					else
						if ( Require(document.manage, 'email,email2,username,fname,lname,address,city,postcode,country') )
							{ 
								document.manage.submit();
							}
		}		
	}
}
function checkMail(form_name,email_field)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test( eval("document."+form_name+"."+email_field+".value" )))
		return true;
	else 
		return false;

}
function check_registration(r)
{
	if(!checkMail('subscribe','email') || !checkMail('subscribe','email2'))
	{
		alert('Please enter a valid e-mail address.');
		return false;
	}
	else if(document.subscribe.email.value!=document.subscribe.email2.value)
	{
		alert('The e-mail addresses entered do not match. Please enter the same e-mail address in both e-mail fields.');
		return false;
	}
	else
		if ( !Require(document.subscribe, 'username,password,password2') )
			return false;
				
	return true;
}
function check_contact(LoggedIn)
{	
	if(LoggedIn==1)
	{
		if ( Require(document.contactusform, 'message') )
			document.contactusform.submit();				
	}
	else
		if ( Require(document.contactusform, 'message,email,firstname,age') )
			document.contactusform.submit();
					
}

function make_editable(form)
{
	form.email.readOnly = false;
	form.email2.readOnly = false;
	form.old_password.readOnly = false;	
	form.password.readOnly = false;
	form.password2.readOnly = false;
	form.username.readOnly = false;
	form.fname.readOnly = false;
	form.lname.readOnly = false;
	form.address.readOnly = false;
	form.address2.readOnly = false;
	form.city.readOnly = false;
	form.postcode.readOnly = false;
	form.country.disabled = false;
	
	form.opt_offline[0].disabled = false;	
	form.opt_offline[1].disabled = false;
	
	form.opt_online[0].disabled = false;
	form.opt_online[1].disabled = false;
	
	form.opt_onoff[0].disabled = false;
	form.opt_onoff[1].disabled = false;
	form.phone.readOnly = false;
	
}

function checkProductSelectorForm()
{
	var found_checked = false;
	for(var i=0; i<4; i++){
		if(document.selectorform.product[i].checked==true)
			found_checked = true;
	}
	if(!found_checked){
		alert('Bitte wählen Sie eine Option aus');
		return false;
	}
	return true;
}