var short;
var phoneNumberDelimiters = "()- .ext:*,";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 8;
function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

/*
howmight_str:Check How might you use WebEx? question enable if question is on form
*/
function checkFields(howmight_str)
{
	var els = document.getElementsByTagName('*');
	for (var i=0; i<els.length; i++){
	    if (els[i].className != ''){
		els[i].className = els[i].className.replace('error', '');
	    }
	}
	document.getElementById('incorrect').innerHTML = '';
	document.getElementById('incorrect').style.display = 'none';
	var errors = "";
	if(document.getElementById('fname'))
	{
		if(document.getElementById("fname").value.length == 0)
		{
			errors += "<p>Your <strong>First Name</strong> was entered incorrectly</p>\n";
			document.getElementById("fname").parentNode.className += ' error';
		}
	}
	if(document.getElementById('lname'))
	{
		if(document.getElementById("lname").value.length == 0)
		{
			errors += "<p>Your <strong>Last Name</strong> was entered incorrectly</p>\n";
			document.getElementById("lname").parentNode.className += ' error';
		}
	}
	if(document.getElementById('email'))
	{
		if(document.getElementById('email').value.length == 0)
		{
			errors += "<p>Your <strong>Email address</strong> was entered incorrectly</p>\n";
			document.getElementById("email").parentNode.className += ' error';
		}
		else if(!document.getElementById('email').value.match(new RegExp('^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$')))
		{
			errors += "<p>Your <strong>Email address</strong> was entered incorrectly</p>\n";
			document.getElementById("email").parentNode.className += ' error';
		}
	}
	
	if(errors.length > 0)
	{	//alert("error");
		document.getElementById('incorrect').innerHTML = errors;
		document.getElementById('incorrect').style.display = 'block';
		return false;
	}
	else
	{
		
		//alert(document._mktf.Lead_score.value);
		return true;	
	}
	
}