/*****************************************************************************************************
* Easy Javascript Validation by Daniel Boorn
* Copyright 2006, All Rights reserved by Daniel Boorn
* Contact: daniel.boorn@gmail.com - wwww.dboorn.com
* In any form element add the following form attributes to validate
* required ="yes"
* validate = { "int", "float", "text", "email" }
* message = "Error Message for Element"
* Example: <input type="text" validate="int" message="Please enter valid zip code" name="zip">
*
* It is required that you add the following to any submit button
*     onClick="validate(this.form); return document.formSubmit;"
******************************************************************************************************/

	function validate(form){
		
		var error = "";
		//for each form element
		
		for(var i=0; i<form.length; i++){
			var element = form[i];

			//if required
			if(element.getAttribute("required") == "yes"){
				//if form element if empty
				if(!valid(element.value,element.getAttribute("validate"),element))
					error += element.getAttribute("message") + "\r\n";	
			}
		}
		if(error != ""){
			alert(error);
			document.formSubmit = false;
		}
		else {
				if (document.mindspring.splinfo != undefined) {
					//Spam check	
					if (document.mindspring.splinfo.value != "") {
						document.formSubmit = false;
					}
					else {
						document.formSubmit = true;
					}
				}
				else {
					document.formSubmit = true;
				}
		}
	}	
	
	function valid(value,type,element){		
		if(value == "")
			return false;
			
		switch(type){
			case "int":
				if(isNaN(parseInt(value)))
					return false;
				break;
			case "float":
				if(isNaN(parseFloat(value)))
					return false;
				break;
			case "email":
				var p = value.indexOf('@');
				if(p<1 || p==(value.length-1))
					return false;
				break;
			case "checked":
				if(!element.checked)
					return false;
				break;
			default://string
				break;
		}
		return true;
	}	
	
	function chkcontactfrm()
	{
		if (document.mindspring.first.value == "") {
			alert("Please enter your First Name.")
			document.mindspring.first.focus()
			return false
		}
		/*if (document.mindspring.title.value == "") {
			alert("Please enter Title.")
			document.mindspring.title.focus()
			return false
		}*/
		if (document.mindspring.company.value == "") {
			alert("Please enter the name of your Company.")
			document.mindspring.company.focus()
			return false
		}
		
		if (document.mindspring.email.value == "") {
			alert("Please enter a valid email address.")
			document.mindspring.email.focus()
			return false
		}
		
	
		var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
		if(!emailfmt.test(document.mindspring.email.value))
		{ 
			alert("Please enter a valid email address.")
			document.mindspring.email.focus()
			return false
		}
	
		
		if (document.mindspring.phone.value == "") {
			alert("Please enter your Phone Number.")
			document.mindspring.phone.focus()
			return false
		}
		/*
		if (document.mindspring.phone.value != "") {
		if( isNaN(document.mindspring.phone.value) || (document.mindspring.phone.value.length)!=10 ){
		alert("Please enter valid Phone Number");
		alert(document.mindspring.phone.value.length);
		return false;
		}
		
		
		}
		
		*/
		
		
		
		if (document.mindspring.splinfo.value != "") {
			return false
		}				
	}
	
	function chkpartnerfrm()
	{

		if (document.partnerfrm.txtorganization.value == "") {
			alert("Please enter the name of your Organization.")
			document.partnerfrm.txtorganization.focus()
			return false
		}

		if (document.partnerfrm.dwlOrgtype.value == "") {
			alert("Please select Organization type.")
			document.partnerfrm.dwlOrgtype.focus()
			return false
		}
		
		if (document.partnerfrm.dwlOrgtype.value == "Other") {
			if (document.partnerfrm.txtorgother.value == "") {
				alert("Please enter Organization type.")
				document.partnerfrm.txtorgother.focus()
				return false
			}
		}
		
		if (document.partnerfrm.dwlCountry.value == "") {
			alert("Please select location.")
			document.partnerfrm.dwlCountry.focus()
			return false
		}
		
		if (document.partnerfrm.dwlCountry.value == "Other") {
			if (document.partnerfrm.txtother.value == "") {
				alert("Please enter location.")
				document.partnerfrm.txtother.focus()
				return false
			}
		}		

		if (document.partnerfrm.txtname.value == "") {
			alert("Please enter your Name.")
			document.partnerfrm.txtname.focus()
			return false
		}
		
		var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
		if(!emailfmt.test(document.partnerfrm.email.value))
		{ 
			alert("Please enter a valid email address.")
			document.partnerfrm.email.focus()
			return false
		}
		
	}
	
	function showOthers(dwl) {
			if (dwl == "dwlCountry") {
				if (document.partnerfrm.dwlCountry.value == "Other") {
					document.getElementById("othercountry").style.display = "";
				}
				else {
					document.getElementById("othercountry").style.display = "none";
				}
			}
			if (dwl == "dwlOrgtype") {
				if (document.partnerfrm.dwlOrgtype.value == "Other") {
					document.getElementById("otherorg").style.display = "";
				}
				else {
					document.getElementById("otherorg").style.display = "none";
				}
			}

	}
