function isan(string){
    if (string.length == 0)
        return false;
    for (var i=0;i < string.length;i++){
        if ((string.substring(i,i+1) < '0') || (string.substring(i,i+1) > '9'))
            return false;
    }
    return true;
}


function selInterest(objSel, objOther)

{
	if (objSel.selectedIndex == objSel.options.length-2) {
		objOther.disabled = false

	} else {
		objOther.value = ""
		objOther.disabled = true;
	}
}


function validate()
{
	//define error messages
	var msg = document.getElementById("strMessage");
	msg.innerHTML = "The following errors have occurred (Click on each error to rectify the respective field):";
	var strInterest = "<li><a href='#Interest' onclick='javascript: document.form1.Interest1.focus();'>Please select your Interest.</a></li>";
	var strname = "<li><a href='#' onclick='javascript: document.form1.name.focus();'>Please enter a name.</a></li>";
	var strjob_title = "<li><a href='#' onclick='javascript: document.form1.job_title.focus();'>Please enter a job title</a></li>";
	var strcompany = "<li><a href='#' onclick='javascript: document.form1.company.focus();'>Please provide a company name.</a></li>";
	var strcountry = "<li><a href='#Country' onclick='javascript: document.form1.country.focus();'>Please select a country</a></li>";
	var stremail = "<li><a href='#' onclick='javascript: document.form1.email.focus();'>Please provide an email address.</a></li>";
	var stremail2 = "<li><a href='#' onclick='javascript: document.form1.email.focus();'>Please provide a valid email address.</a></li>";
	var straddress = "<li><a href='#' onclick='javascript: document.form1.address.focus();'>Please provide your address</a></li>";
	var strtelephone = "<li><a href='#' onclick='javascript: document.form1.telephone.focus();'>Please provide your telephone number.</a></li>";
	var strfax = "<li><a href='#' onclick='javascript: document.form1.fax.focus();'>Please provide your fax number.</a></li>";
	var strCategories = "<li><a href='#' onclick='javascript: document.form1.Categories.focus();'>Please fill in your categories of products.</a></li>";
	var strSpace = "<li><a href='#' onclick='javascript: document.form1.Space.focus();'>Please enter the space required.</a></li>";
	var strSpace2 = "<li><a href='#' onclick='javascript: document.form1.Space.focus();'>Please enter a valid space value!</a></li>";
	var strSpace3 = "<li><a href='#' onclick='javascript: document.form1.Space.focus();'>Space minimum 9 sqm!</a></li>";

	var blnFlagError = false;
	//end of define error messages


	intselect=false;
	
	for (i=1;i<=7;i++)
	{
		value1=eval('document.form1.Interest'+i)
			if(value1.checked)
			{
				intselect=true;
			}
	}

	if (!intselect)
	{
		msg.innerHTML += strInterest;
		blnFlagError = true;
	}


	if (document.form1.SelectInterest.value=='Exhibiting individually')
		{
			if (document.form1.Space.value == "")
			{
				msg.innerHTML += strSpace;
				changeStyle("Space", "input_style2");
				blnFlagError = true;
			} else if (document.form1.Space.value != "") {
				if (!isan(document.form1.Space.value))
				{
					msg.innerHTML += strSpace2;
					changeStyle("Space", "input_style2");
					blnFlagError = true;
				}else if (isan(document.form1.Space.value)) {
					changeStyle("Space", "input_style");
				}
				if (document.form1.Space.value<9)
				{
					msg.innerHTML += strSpace3;
					changeStyle("Space", "input_style2");
					blnFlagError = true;
				}else if (document.form1.Space.value>=9) {
					changeStyle("Space", "input_style");
				}
			}
		}else{
		
		changeStyle("Space", "input_style");
		
	}



	if (document.form1.name.value == "")
	{
		msg.innerHTML += strname;
		changeStyle("name", "input_style2");
		blnFlagError = true;
	} else if (document.form1.name.value != "") {
		changeStyle("name", "input_style");
	}
	

	if (document.form1.job_title.value == "")
	{
		msg.innerHTML += strjob_title;
		changeStyle("job_title", "input_style2");
		blnFlagError = true;
	} else if (document.form1.job_title.value != "") {
		changeStyle("job_title", "input_style");
	}


	if (document.form1.company.value == "")
	{
		msg.innerHTML += strcompany;
		changeStyle("company", "input_style2");
		blnFlagError = true;
	} else if (document.form1.company.value != "") {
		changeStyle("company", "input_style");
	}


	if (document.form1.address.value == "")
	{
		msg.innerHTML += straddress;
		changeStyle("address", "input_style2");
		blnFlagError = true;
	} else if (document.form1.address.value != "") {
		changeStyle("address", "input_style");
	}


	if (document.form1.country.selectedIndex<=0)
	{
		msg.innerHTML += strcountry;
		blnFlagError = true;
	} 

	if (document.form1.telephone.value == "")
	{
		msg.innerHTML += strtelephone;
		changeStyle("telephone", "input_style2");
		blnFlagError = true;
	} else if (document.form1.telephone.value != "") {
		changeStyle("telephone", "input_style");
	}


	if (document.form1.fax.value == "")
	{
		msg.innerHTML += strfax;
		changeStyle("fax", "input_style2");
		blnFlagError = true;
	} else if (document.form1.fax.value != "") {
		changeStyle("fax", "input_style");
	}

	if (document.form1.Categories.value == "")
	{
		msg.innerHTML += strCategories;
		changeStyle("Categories", "input_style2");
		blnFlagError = true;
	} else if (document.form1.Categories.value != "") {
		changeStyle("Categories", "input_style");
	}

	if (document.form1.email.value == "")
	{
		msg.innerHTML += stremail;
		changeStyle("email", "input_style2");
		blnFlagError = true;
	} else if (document.form1.email.value != "") {
		if ((document.form1.email.value.indexOf("@") == -1) || (document.form1.email.value.indexOf(".")==-1) || (document.form1.email.value.indexOf(" ")>1) || (document.form1.email.value.indexOf(",")>0))
		{
			msg.innerHTML += stremail2;
			changeStyle("email", "input_style2");
			blnFlagError = true;
		} else if (document.form1.email.value != "") {
			changeStyle("email", "input_style");
		}

	}








	if (blnFlagError == true)
	{
		ErrorMsg.style.display = "block";
		blnFlagError = false;
		return false;
	}
	
}

function changeStyle(element, style)
{
	var id = document.getElementById(element);
	
	id.className = style;
}

function validateInvalidChars(element)
{
	var input = document.getElementById(element).value;
	
	var strInvalidChars = /[^a-zA-Z0-9_-]/i;	//check for characters not withstanding a to z, A to Z, 0 to 9, underscore and hyphen;
												//i = case insensitive
	var objRegExp = new RegExp(strInvalidChars);
	
	return objRegExp.test(input);	//true = input string is invalid (contains invalid chars);
									//false = input string is valid
}