function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = 'Red'; 
        error = fld.name + " \n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function validateNumericOnly(fld) {
	var error = "";
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < fld.value.length && IsNumber == true; i++) { 
		Char = fld.value.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber=false;
		}
	}
	if(!IsNumber) {
		fld.style.background = 'Red'; 
		error += fld.name + " can only hold a number \n" ;	
	}
	
	return error;	
}
function validate_contact_form()
{
   	var error="";
  	var field_name="";
 	
  	error += validateEmpty(document.contactus.name);
   	if(!document.contactus.name.value)
   	field_name += "Your name \n";
   	  	
 	error += validateEmpty(document.contactus.from_email);
 	if(!document.contactus.from_email.value)
 	field_name += "Your Email Address \n";
 	
 	error += validateEmpty(document.contactus.subject);
 	if(!document.contactus.subject.value)
 	field_name += "Subject \n";
 	
 	error += validateEmpty(document.contactus.query);	
 	if(!document.contactus.query.value)
 	field_name += "Comment/Question \n";
	
	if (error != "") {
			alert("Some fields has not been filled:\n" + field_name);
			return false;
	}
}

function validate_join_form()
{
	var error="";
  	var field_name="";
  	var error2="";
  	var field_name2="";

	   	error += validateEmpty(document.join.company_name);
	   	if(!document.join.company_name.value)
	   	field_name += "Company Name \n";

	  	error += validateEmpty(document.join.company_desc);	
	 	if(!document.join.company_desc.value)
	 	field_name += "Company Profile \n";	   	  	  	
	   	
 	if (document.join.city.value == "null")
   	{
	   	error += document.join.city.name + "\n";
	   	field_name += "City \n";
	   	document.join.city.style.background = 'Red';
   	}
   	
   	else {
        document.join.city.style.background = 'White';
    }

  	if (document.join.category_type.value == "null")
   	{
	   	error += document.join.category_type.name + "\n";
	   	field_name += "Category Type \n";
	   	document.join.category_type.style.background = 'Red';
   	}
   	
   	else {
        document.join.category_type.style.background = 'White';
    }
   	  	
	 	error += validateEmpty(document.join.company_address1);
	 	if(!document.join.company_address1.value)
	 	field_name += "Company Address 1\n";	
	 	
	 	error += validateEmpty(document.join.company_address2);
	 	if(!document.join.company_address2.value)
	 	field_name += "Company Address 2\n";
	 	
	  	error += validateEmpty(document.join.postcode);	
	 	if(!document.join.postcode.value)
	 	field_name += "Post Code \n";	
	 	
	 	error += validateEmpty(document.join.contact_number);
	 	//error2 += validateNumericOnly(document.join.contact_number);
	 	//if (error2)
	 	//field_name2 += "Contact Number \n"; 	
	 	if(!document.join.contact_number.value)
	 	field_name += "Contact Number \n";
	
	  	//error += validateEmpty(document.join.contact_email);	
	 	//if(!document.join.contact_email.value)
	 	//field_name += "Email Address \n";

  	if (document.join.join_type.value == "null")
   	{
	   	error += document.join.join_type.name + "\n";
	   	field_name += "Registration Type \n";
	   	document.join.join_type.style.background = 'Red';
   	}
   	
   	else {
        document.join.join_type.style.background = 'White';
    } 
    
    if (document.join.join_type.value == "advance")
    {
	  	error += validateEmpty(document.join.logo);	
	 	if(!document.join.logo.value)
	 	field_name += "Company Logo \n";
	    
	  	error += validateEmpty(document.join.image);	
	 	if(!document.join.image.value)
	 	field_name += "Image \n";
	 	
	    if (document.join.payment.value == "null")
	   	{
		   	error += document.join.payment.name + "\n";
		   	field_name += "Payment \n";
		   	document.join.payment.style.background = 'Red';
	   	}
	   	
	   	else {
	        document.join.payment.style.background = 'White';
	    }	 	   
    }

	  	error += validateEmpty(document.join.security_code);	
	 	if(!document.join.security_code.value)
	 	field_name += "Security Code \n";    
      	
	if (error != "") {
			alert("Some fields has not been filled:\n" + field_name);
			return false;
	}
	
	if (error2 != ""){
			alert("These fields should only be numbers \n" + field_name2);
			return false;
	}			
	
}

function show_fields()
{
 	var registration_type=document.join.join_type.value;
	if (registration_type == 'advance')
	{
		document.getElementById('company_logo').style.display = "inline";		
		document.join.logo.style.display = "inline";		
				
		document.getElementById('company_image').style.display = "inline";		
		document.join.image.style.display = "inline";
		
		document.getElementById('payment_label').style.display = "inline";		
		document.join.payment.style.display = "inline";			

		document.getElementById('company_logo_note').style.display = "inline";
                //document.join.payment.style.display = "inline";

		document.getElementById('image_note').style.display = "inline";
                //document.join.payment.style.display = "inline";

					
	}
	
	else
	{
		document.getElementById('company_logo').style.display = "none";		
		document.join.logo.style.display = "none";		
		
		document.getElementById('company_image').style.display = "none";		
		document.join.image.style.display = "none";		
		
		document.getElementById('payment_label').style.display = "none";		
		document.join.payment.style.display = "none";			

		document.getElementById('company_logo_note').style.display = "none";
                document.join.image.style.display = "none";

                document.getElementById('image_note').style.display = "none";
                document.join.payment.style.display = "none";
	}		

}



