var email = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/
var plainText = /[a-zA-Z]+$/
var alphaNum = /[a-zA-Z0-9]+$/

function checkEmail(valEmail)
{
	if (!isEmpty(valEmail)){
		if (valEmail.search(email)==-1){
			return false;
		}else{
		return true;
		}
	}else{
		return false;
	}
}

function checkNonNumeric(valStr)
{
	if (!isEmpty(valStr)){
		if (valStr.search(plainText)==-1){
			return false;
		}else{
		return true;
		}
	}else{
		return false;
	}
}

function getInsruction(me)
{
	if (me.indexOf("DOB")!=-1){
		me = "DOB";
	}
	var currInput = document.getElementById(me);
	var msgBox = document.getElementById('msg'+me);
	var strInstruction;
	
	displayMsg(getInstructionMsg(me), me);
}
function getInstructionMsg(me)
{
	switch (me) {
     case "FirstName" :
        strInstruction = "Enter your First Name.";
        break;
     case "LastName" :
        strInstruction = "Enter your Last Name.";
        break;
	case "Name" :
        strInstruction = "Enter your Name.";
        break;
	case "DOBMode": case "BirthMode":
        strInstruction = "You can choose to either only show your Age or to show both your Age and your full Date of Birth.";
        break;
	case "DOB":
        strInstruction = "Enter your Birthdate. ( Month - Day - Year)";
        break;
	 case "Gender" :
        strInstruction = "What is your Gender?";
        break;
	 case "Country" :
        strInstruction = "What Country do you come from? Select from the list.";
        break;
	case "MarStatus":
        strInstruction = "Select from the list what currently best describes your marital status.";
        break;
	case "Height":
        strInstruction = "Enter your height. Leave it empty to not show any height details.";
        break;
	case "Weight":
        strInstruction = "Enter your weight. Leave it empty to not show any weight details.";
        break;
	case "Occupation":
        strInstruction = "Enter your Occupation.";
        break;
	case "Address":
        strInstruction = "What is your full Postal Address?";
        break;
	case "PostCode":
        strInstruction = "What is your Postal Code?";
        break;
	case "City":
        strInstruction = "What City do you come from?";
        break;
	 case "Email" : case "ContactEmail" :
        strInstruction = "Enter your email address.";
        break;
	case "EmailMode":
        strInstruction = "Select how you want your email address to be used by our website. Private means that no one except MaxLifestyle staff will have access to your email address. Private Emailing means that we will not display your email address anywhere on our website but other members will be able to send you an email through our website. Public means that your email address will be displayed in your public profile meaning that anyone can contact you.";
        break;
	case "Telephone":
        strInstruction = "Enter your full Telephone Number including country and region codes. You can use the Public Check box to indicate if you want this information to stay private or if you want to add it to your public profile. To keep it private leave the checkbox unchecked. To add it to your public profile you can checkmark it.";
        break;
	case "Mobile":
        strInstruction = "Enter your full Mobile Number including country and region codes. You can use the Public Check box to indicate if you want this information to stay private or if you want to add it to your public profile. To keep it private leave the checkbox unchecked. To add it to your public profile you can checkmark it.";
        break;
	 case "Username" :
        strInstruction = "Enter your Username. Your username must be between 4-12 characters.";
        break;
	 case "Password" :
        strInstruction = "Enter your Password. Your password must be between 4-12 characters.";
        break;
	 case "Password2" :
        strInstruction = "Retype your chosen password to confirm it.";
        break;
	 case "Newsletter" :
        strInstruction = "Indicate if you would like to receive our Newsletter.";
        break;
	 case "Refer" :
        strInstruction = "Please select which way you found our website from the drop down list.";
        break;
	 case "HumanBeing" :
        strInstruction = "To make sure that you are an actual human member and not a bot we have to ask you to read the image on your left and write down the text in this box. The image is generated randomly and at times, some of the image colors will make the text unreadable. In such cases, you can refresh the page or use the refresh link to create or find a new readable image.";
        break;	
	 case "TimeDif" :
        strInstruction = "Use the given Server Time to determine the Time Difference between the server time and the time in your present location. By setting the time difference we will be able to display synchronized time. ";
        break;	
	case "Type" :
        strInstruction = "Select the type of Link Partnership that you are interested in. The four types are described above.";
        break;	
	case "Title" :
        strInstruction = "Enter the Full Official Name of your Website.";
        break;
	case "URL" :
        strInstruction = "Enter the full URL of the homepage of your website.";
        break;	
	case "LinkPageURL" :
        strInstruction = "Where are you linking to our Website? For our Standard, Premier and Homepage Link Programs you will need to setup a link to our website first. Upon submitting this form, one of our administrators will review your link and you will receive feedback within 48 hours. For the one-way, three-way, or custom link program you can leave this field blank.";
        break;	
	case "ContactName" :
        strInstruction = "Enter the First and Last Name of the Contact Person of your Website.";
        break;		
	case "Description" :
        strInstruction = "Give a short description of your website.";
        break;		
	case "Comment" :
        strInstruction = "Use this box to give comments or suggestions to the administrator that will review your link request. For Custom Link deals you will have to use this field to explain the type of link deal that you would like to setup.";
        break;	
	case "Inquiry" :
		strInstruction = "Select an Inquiry Type. We will forward your message to our staff members based on your chosen inquiry type so please choose carefully.";
		break;
	case "Subject" :
		strInstruction = "Enter the Subject line of your message. Use this to provide us with a short summary of your inquiry so we know which staff member to forward it to.";
		break;
	case "Message" :
		strInstruction = "Enter your message. Please make it as short and as to the point as possible.";
		break;
	case "AboutMe" :
		strInstruction = "Give a short story about who you are. You are free to fill in this space in any way you want.";
		break;
	case "Hobbies" :
		strInstruction = "Give a short story about your hobbies. You are free to fill in this space in any way you want.";
		break;
	case "Quote" :
		strInstruction = "Give your favourite Quote or One Liner.";
		break;
	case "Company" :
		strInstruction = "If you work somewhere then you can give the name of the company you work for here. If you do not want to give the exact Company Name then feel free to provide a description or sector you work in.";
		break;
	case "School" :
		strInstruction = "You can use this field to indicate to which school or college you went to.";
		break;
	case "Books" :
		strInstruction = "Give the titles of your favourite books or magazines.";
		break;
	case "Movies" :
		strInstruction = "Give the titles of your favourite Movies.";
		break;
	case "Music" :
		strInstruction = "Give the titles of your favourite Music.";
		break;
	case "TVShows" :
		strInstruction = "Give the titles of your favourite TV Shows.";
		break;
	case "ExtContactInfo" :
		strInstruction = "You can use the 5 slots given to the left to give more contact methods. Be warned: all details you give here will be publically viewable in your profile. To enter an ID, simply choose from the list of types and select the type of ID you want to add. Next insert your ID for that service. If the service you use is not listed then choose the other option and then specify the service name in the ID field.";
		break;
	case "ProfilesBlogs" :
		strInstruction = "You can use the 5 slots given to the left to give website links. You can link to your Blogs or Profiles at the most popular social networking websites. You can also opt to link to any other website.";
		break;
	case "ARTitle" :
		strInstruction = "Give your Article a short but descriptive title. The title is allowed to be up to 100 characters in length but shorter is better. ";
		break;
	case "ARDescription" :
		strInstruction = "Give a short summary of your article which explains what the content is basically about. This short summary can be up to 200 characters in length and we recommend you use this space. ";
		break;
	case "ARContent" :
		strInstruction = "This is where you should submit your actual article. ";
		break;
	case "ARComment" :
		strInstruction = "Use this textbox to provide us with any comments you might have about your Article. You could give us suggestions on how to use the article, where to place it on our website or any other information you want to pass along to us. If you have images that you would like to add to the article then you can indicate that here too. We will contact you and ask you to email us the pictures. ";
		break;	
	case "NEDate1": case "NEDate3": case "NEDate2":
		strInstruction = "Select the Date that the News Item should be published under. The date you select here will determine when and under what date your news item will be published. ";
		break;	
	case "NERegion" :
		strInstruction = "Select a Region that this News Item pertains to. If your news item does not really pertain to any specific Region then simply select The World. ";
		break;	
	case "NECountry" :
		strInstruction = "If you selected The World in the Region field, you can just leave this as is. Otherwise, select a Country that your News Item pertains to. ";
		break;	
	case "NECategory" :
		strInstruction = "Choose a Category that best fits your News Item. ";
		break;	
	case "NETitle" :
		strInstruction = "Give a short but descriptive title for your news item. This title will be shown as the main title above the news item and in the snippets on our homepage. ";
		break;	
	case "NEDescription" :
		strInstruction = "Give a short summary of your News Item where you explain what the news item is basically about. This short summary can be up to 500 characters in length and we recommend you use this space. ";
		break;	
	case "NEContent" :
		strInstruction = "This is where you should submit your actual News Item. ";
		break;	
	case "Word" :
		strInstruction = "Give the Word or Term that you want to add to the Dictionary. ";
		break;	
	case "WordDescription" :
		strInstruction = "Give the Definition or Meaning of your suggested word. ";
		break;
	case "ALType" :
		strInstruction = "Choose what type of Photo Album you want to insert. Personal Albums are just for storing your images and sharing them through our website. Professional Albums can be started by Professional Photographers who want to showcase and sell their pictures through our website. Professional Albums are more complex since you will be able to add pricing and order information for each picture that you store in your album. Unless you are a Professional Photographer you should add a Personal Photo Album";
		break;	
	case "ALTitle" :
		strInstruction = "Give a Name or Title of your Photo Album. To make it clear to our visitors what they can expect from your photo album it is a good idea to make the title describe what kind of pictures are going to be placed in the album";
		break;
	case "ALDescription" :
		strInstruction = "Give a short description of your Photo Album. It would be best to describe what type of pictures you are going to feature in the photo album";
		break;
	case "ALActive" :
		strInstruction = "You can select here whether you want this photo album to be displayed on our website or not. You can use this option to temporarily remove your album from public viewing. This does not delete your album.";
		break;
	case "UploadFile" :
		strInstruction = "To upload a picture to our webserver, simply press the Browse button to locate the picture file on your own computer and select it. The picture address will appear in this form field. When you submit the form, our webserver will start the upload of your selected picture. Note: Pictures must either be .gif or .jpg, maxium size of 4MB, and the width should not be more than 640 pixels.";
		break;
	case "AL_ID" :
		strInstruction = "Choose which Photo Album you want to store your Picture in";
		break;
	case "PITitle" :
		strInstruction = "Give a short but descriptive title for your picture";
		break;
	case "PIDescription" :
		strInstruction = "Give a Description of your Picture. It would be best to describe what the picture is about since that will help our visitors finding your picture. Feel free however to give any description you like";
		break;
	case "PICategory" :
		strInstruction = "Choose a Category for this Picture. People using our Picture Archive can use this categorisation to find the type of pictures they are looking for";
		break;
	case "PIDate1" :case "PIDate2" :case "PIDate3" :
		strInstruction = "Enter the Date that the Picture was taken";
		break;
	case "PIRegion" :
		strInstruction = "Select the Region where the Picture was taken. Upon selecting a Region, a list of Countries within that Region will become available in this selection box. Upon selecting a Country, a list of States within that Country will become available in the State section box";
		break;
	case "PICountry" :
		strInstruction = "Select the Country where the Picture was taken. Upon selecting a Region, a list of Countries within that Region will become available in this selection box. Upon selecting a Country, a list of States within that Country will become available in the State section box";
		break;
	case "PIState" :
		strInstruction = "Select the State where the Picture was taken. Upon selecting a Region, a list of Countries within that Region will become available in this selection box. Upon selecting a Country, a list of States within that Country will become available in the State section box";
		break;
	case "PICity" :
		strInstruction = "Enter the City or Location where the Picture was taken";
		break;
	case "PIActive" :
		strInstruction = "You can select here whether you want this picture to be displayed on our website or not. You can use this option to temporarily remove your picture from public viewing. This does not delete your picture.";
		break;
	case "PILowPrice" :
		strInstruction = "Enter the lowest available price for the picture. You can give more information on the pricing of the picture in the text box below. This field is just to give our visitors an idea of what they will have to pay for this picture.";
		break;
	case "PIBuyInfo" :
		strInstruction = "Use this text box to give all the necessary pricing information for this picture. You should include the formats that the picture is available in and the prices for the different formats and options. Be as precise as possible so that clients can easily decide if they want to purchase the picture.";
		break;
	case "PIBuyURL" :
		strInstruction = "If you have your own website where you sell this picture through then you can add a URL here that directly leads to this picture on your website or to any other page of your choosing.";
		break;
	case "ReferTitle" :
		strInstruction = "Give the Name of your Photography Service. You can use your name for instance: John Doe Professional Photographer or EasyPics Hiking Photographers. This is the title that will be displayed at the top of the contact page";
		break;
	case "ReferDescription" :
		strInstruction = "Give a short description of your company or of yourself and your photography. You can include information about the subjects you photograph, where you take your pictures, the equipment you use or any other information you would want to pass on to potential clients";
		break;
	case "ReferAddress" :
		strInstruction = "Give your Address where clients can visit your shop or galery. This is an optional field.";
		break;
	case "ReferPhone" :
		strInstruction = "Give your Telephone Number where clients can call you with Questions and possible Orders.";
		break;
	case "ReferEmail" :
		strInstruction = "Give your Email Address where clients can email you with Questions and possible Orders.";
		break;
	case "ReferWebsite" :
		strInstruction = "If you have a website then give the address here. This could possible be another way that clients can reach you and possibly order your pictures.";
		break;
	case "TopicSubject" :
		strInstruction = "Give a short subject name for your new topic. Keep it as descriptive as possible so people will know what type of discussions to expect within your topic";
		break;
	case "signature" :
		strInstruction = "Choose whether you want to show your signature at the bottom of your message or not. You can use the view link to view your current signature. You can edit your signature using the edit link";
		break;
	case "email" :
		strInstruction = "You can check this option if you want to receive an email notification everytime someone posts a comment in this topic. In this way you can keep track of how other members are reacting to your post.";
		break;
	case "ReceiverName" :
		strInstruction = "Enter the Name of the person you are sending this Article to.";
		break;
	case "ReceiverEmail" :
		strInstruction = "Enter the Email Address that you want to send this article to.";
		break;
	case "FriendComment" :
		strInstruction = "Enter an optional Message or Greeting that you want to add to the email you will send. You can use this to explain to the Recipient why you are sending him or her the article, or you can just use it to add a little greeting to the email.";
		break;
	case "FriendCommentForum" :
		strInstruction = "Enter an optional Message or Greeting that you want to add to the email you will send. You can use this to explain to the Recipient why you are sending him or her this topic or post, or you can just use it to add a little greeting to the email.";
		break;
	case "Select" :
		strInstruction = "You can choose to either email the entire topic to someone or just the post you selected. With the post you selected we mean the post on which you clicked the Email button."
		break;
	case "reply" :
		strInstruction= "You can check this option if you want to reply to an email notification everytime someone posts a comment in this topic. In this way you can keep track of how other members are reacting to your post.";
		break;
	case "postcomment" :
		strInstruction= "You can use this option if you want to receive an email notification every time someone posts a comment for this article. In this way, you can keep track of how other members are reacting to your comment.";
		break;
	case "emailnoti" :	
		strInstruction= "You can use this option if you want to receive an email notification every time someone posts a comment for this article. In this way, you can keep track of how other members are reacting to your comment."
		break;
	case "srate" :	
		strInstruction= "If you want you can give this Service a Rating from 1-10. This rating will be a good measure for all our website visitors and fellow hiking enthusiasts to see if the service is recommended. If you have no strong feelings about this service then you can just select -none- in which case you will simply not give a rating."
		break;
	case "co" :	
		strInstruction= "You want you can give this Product a Rating from 1-10. This rating will be a good measure for all our website visitors and fellow shoppers to see if the product is a recommended buy. If you have no strong feelings about this product then you can just select -none- in which case you will simply not give a rating to this shop item."
		break;	
    case "uname" :	
		strInstruction= "Enter User name";
		break;
	case "passwd" :	
		strInstruction= "Enter your Password.";
		break;
		default :
        strInstruction = "Required field.";
		
	}
	return strInstruction;
}

function displayMsg(msg, me)
{
	var msgBox = document.getElementById('msg'+me);
	msgBox.style.backgroundColor="#FEFFAF";
	msgBox.style.padding="2px 5px 2px 5px";
	msgBox.style.color="#000000";
	msgBox.style.zIndex="2000";
	msgBox.style.display="block";
	msgBox.style.border="solid 1px #FEFFAF";
	msgBox.innerHTML=msg;
	return;
}

function clearInstruction(me)
{
	if (me.indexOf("DOB")!=-1){
		me = "DOB";
	}
	var msgBox = document.getElementById('msg'+me);
	msgBox.style.display="none";
}

function isEmpty(myValue)
{
	if (myValue.length==0){
		return true;
	}else{
		return false;
	}
}



function validateCharInput(me)
{
	var currInput = document.getElementById(me);
	var msgBox = document.getElementById('msg'+me);

	if (isEmpty(currInput.value)){
		displayMsg("Required Field.", me);
	}
	else{
		if (me=='Email'){
			if (currInput.value.search(email)==-1){
				displayMsg("Enter a valid email address", me);
			}else{
				msgBox.innerHTML="";
			}
		}else if (me=='Password' || me=='Password2'){
			clearInstruction(me);
		}
		else if (me=='TimeDif' || me=='Newsletter'){
			clearInstruction(me);
		}else if (me=='ReferPhone' || me=='ReferTitle'){
			clearInstruction(me);
		}
		//else{
			//if (currInput.value.search(plainText)==-1){
			//	displayMsg("Numeric or special characters are not allowed.", me);
			//}else{
				clearInstruction(me);
			//}
		//}
	}
}

function CheckForm() {
	var errorMsg = "";

	if (isEmpty(document.formRegister.FirstName.value))
	{	displayMsg("Required Field.", "FirstName"); 
		errorMsg+="1";
	}else{
		if (document.formRegister.FirstName.value.search(plainText)==-1){
		displayMsg("Numeric or special characters are not allowed.", "FirstName");
		}
	}
	if (isEmpty(document.formRegister.LastName.value))
	{
		displayMsg("Required Field.", "LastName"); 
		errorMsg+="1";
	}else{
		if (document.formRegister.LastName.value.search(plainText)==-1){
		displayMsg("Numeric or special characters are not allowed.", "LastName");
		}
	}
	if (isEmpty(document.formRegister.Email.value))
	{
		displayMsg("Required Field.", "Email"); errorMsg+="1";
		errorMsg+="1";
	}else{
		if (document.formRegister.Email.value.search(email)==-1){
		displayMsg("Enter a valid email address", "Email");
		errorMsg+="1";
		}
	}
	if (isEmpty(document.formRegister.Username.value))
	{displayMsg("Required Field.", "Username"); errorMsg+="1";}
	if (isEmpty(document.formRegister.Password.value))
	{displayMsg("Required Field.", "Password"); errorMsg+="1";}
	if (isEmpty(document.formRegister.Password2.value))
	{displayMsg("Required Field.", "Password2"); errorMsg+="1";}
	if (isEmpty(document.formRegister.HumanBeing.value))
	{displayMsg("Required Field.", "HumanBeing"); errorMsg+="1";}
	if (isEmpty(document.formRegister.HumanBeing.value))
	{displayMsg("Required Field.", "HumanBeing"); errorMsg+="1";}
	
	
	if ((document.formRegister.Password.value) != (document.formRegister.Password2.value)) {
		displayMsg("Both the Password and the Verifying Password must be the same.", "Password2");
		errorMsg+= "1";
	}
	
	if (((document.formRegister.Username.value) == (document.formRegister.Password.value)) && (document.formRegister.Username.value!="" || document.formRegister.Password.value)) {
		displayMsg("Do not use the same Username and Password.", "Password");
		errorMsg+= "1";
	}
	
	if ((errorMsg.length>0)){
		alert("There are problems with the data you submitted.");
		return false;
	}
	document.formRegister.submit(true);
}


function resetForm(form)
{
	alert(form);
	document.getElementById(form).reset();
	document.getElementById(form).submit(false);
}
