function checkBusiness(value)
{
	document.getElementById("other").style.display = (value == "Other") ? "inline" : "none";
}

function validateForm()
{
	var firstName = document.getElementById("vFirstName");
	
	if (firstName.value == "")
	{
		return invalidField("First name", firstName);
	}
	
	var lastName = document.getElementById("vLastName");
	
	if (lastName.value == "")
	{
		return invalidField("Last name", lastName);
	}
	
	var title = document.getElementById("vTitle");
	
	if (title.value == "")
	{
		return invalidField("Title", title);
	}
	
	var company= document.getElementById("vCompany");
	
	if (company.value == "")
	{
		return invalidField("Company", company);
	}

	var email = document.getElementById("vEmail");
	
	if (email.value == "")
	{
		return invalidField("Email address", email);
	}
	
	var atPos = email.value.indexOf("@");
	var dotPos = email.value.lastIndexOf(".");
	
	if (atPos < 2 || atPos == email.value.length - 1 || dotPos < 5 || dotPos > email.value.length - 3 || dotPos < atPos || email.value.indexOf("@", atPos + 1) != -1 || dotPos < atPos + 3 || email.value.indexOf(" ") != -1)
	{
		alert("Email address in not in a valid format.");
		
		return invalidField("", email);
	}
	
	/*
	var phone = document.getElementById("vPhone");
	
	if (phone.value == "")
	{
		return invalidField("Phone number", phone);
	}
	
	var business = document.getElementById("vCompBusiness");
	
	if (business.options[business.selectedIndex].value == "")
	{
		return invalidField("Company business", business);
	}
	
	var businessOther = document.getElementById("vCompBusinessother");
	
	if (business.options[business.selectedIndex].value == "Other" && businessOther.value == "")
	{
		alert("Please tell use your company business.");
		
		return invalidField("", businessOther);
	}
	*/
	if(document.getElementById("capt")){
	var capt = document.getElementById("capt");
	
	if (capt.value == "")
	{
		return invalidField("Image verification  code", capt);
	}

    if(capt.value != ""){
        var xmlhttp;
        if (window.XMLHttpRequest)
        {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
            alert("Your browser does not support XMLHTTP!");
        }
        
        xmlhttp.onreadystatechange=function()
        {
            if(xmlhttp.readyState==4)
            {
                if(xmlhttp.responseText == "1"){
                    document.more_info.submit();
                }else{
                    alert("The code you have entered is not matching image code.Please try again.");
                    return false;
                }
            }
        }
        pagename=document.getElementById("pagename").value;
        if(pagename == "resources" ||  pagename == "processor"){
            captachpath="checkcpatcha.php";
        }else{
            captachpath="../checkcpatcha.php";
        }
        xmlhttp.open("GET",captachpath+"?capt="+capt.value,true);
        xmlhttp.send(null);
        return false;
    }
    }
}

function invalidField(text, field)
{
	if (text != "")
	{
		alert(text + " is a required field.");
	}
	
	field.focus();
	
	return false;
}
