
function checkWebinar()
{
	var c_first_name, c_last_name, c_company, c_title, c_phone, c_email, c_application, c_webinar_date;

	with(window.document.webinar)
	{
		c_first_name = first_name; c_first_name.value = trim(c_first_name.value);
		c_last_name = last_name; c_last_name.value = trim(c_last_name.value);
		c_company = company; c_company.value = trim(c_company.value);
		c_title = title; c_title.value = trim(c_title.value);
		c_phone = phone; c_phone.value = trim(c_phone.value);
		c_email = email; c_email.value = trim(c_email.value);
		c_application = application; c_application.value = trim(c_application.value);
		c_webinar_date = webinar_date; c_webinar_date.value = trim(c_webinar_date.value);
	}
	
	if(c_first_name.value == '')
	{
		alert('Please enter your first name');
		c_first_name.focus();
		return false;
	}
	if(c_last_name.value == '')
	{
		alert('Please enter your last name');
		c_last_name.focus();
		return false;
	}
	else if(c_company.value == '')
	{
		alert('Please enter your company name');
		c_company.focus();
		return false;
	}
	else if(c_title.value == '')
	{
		alert('Please enter your title');
		c_title.focus();
		return false;
	}
	else if(c_phone.value == '')
	{
		alert('Please enter your phone nubmer');
		c_phone.focus();
		return false;
	}
	else if(!checkInternationalPhone(c_phone.value))
	{
		alert('Please enter a valid phone number');
		c_phone.focus();
		return false;
	}
	
	else if(c_email.value == '')
	{
		alert('Please enter your email address');
		c_email.focus();
		return false;
	}
	else if(!isEmail(c_email.value))
	{
		alert('Please enter a valid email address');
		c_email.focus();
		return false;
	}
	else if(c_application.value == 'none')
	{
		alert('Please select your application');
		c_application.focus();
		return false;
	}
	else if(c_webinar_date.value == 'none')
	{
		alert('Please select a webinar date/time');
		c_webinar_date.focus();
		return false;
	}
	else if(c_webinar_date.value == 'Holiday')
	{
		alert('The webinar date you have chosen is a holiday.  Please select a valid webinar date.');
		c_webinar_date.focus();
		return false;
	}
	else
	{
		
		document.getElementById('pinwheel').style.display='inline';
		
		return true;
	}
}

/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	// return str.replace(/^\s+|\s+$/g,'');
	return String(str).replace(/^\s+|\s+$/g,'');
	// return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	// return String(str || '').replace(/^\s+|\s+$/g,'');
}

/*
Check if a string is in valid email format. 
Returns true if valid, false otherwise.
*/
function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ac|ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|asia|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cat|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|info|int|io|iq|ir|is|it|je|jm|jo|jobs|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mil|mk|ml|mm|mn|mo|mobi|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tel|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|travel|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|xn|ye|yt|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}


/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// 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 = 10;

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);
}
