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

function echeck(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	   return false;

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   return false;

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		return false;

	 if (str.indexOf(at,(lat+1))!=-1)
		return false;

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		return false;

	 if (str.indexOf(dot,(lat+2))==-1)
		return false;
	
	 if (str.indexOf(" ")!=-1)
		return false;

	 return true;
}

function validateContactForm (formType) {
	var validation = '';
	if (formType == 'contact') {
		if ((document.getElementById('ws_full_name').value == '') || (document.getElementById('ws_full_name').value == 'FULL NAME'))
			validation+= '* You must specify your name\n';
		if ((document.getElementById('ws_email').value == '') || (document.getElementById('ws_email').value == 'EMAIL'))
			validation+= '* You must specify your email address\n';
		else if (!echeck(document.getElementById('ws_email').value))
			validation+= '* You must specify a valid email address\n';
		if ((document.getElementById('ws_phone').value == '') || (document.getElementById('ws_phone').value == 'PHONE'))
			validation+= '* You must specify your phone number\n';
	}
	
	if (formType == 'xmas') {
		if ((document.getElementById('ws_full_name').value == '') || (document.getElementById('ws_full_name').value == 'FULL NAME'))
			validation+= '* You must specify your name\n';
		if ((document.getElementById('ws_business_name').value == '') || (document.getElementById('ws_business_name').value == 'BUSINESS NAME'))
			validation+= '* You must specify your businesses name\n';
		if ((document.getElementById('ws_email').value == '') || (document.getElementById('ws_email').value == 'EMAIL'))
			validation+= '* You must specify your email address\n';
		else if (!echeck(document.getElementById('ws_email').value))
			validation+= '* You must specify a valid email address\n';
		if ((document.getElementById('ws_postal_address').value == '') || (document.getElementById('ws_postal_address').value == 'POSTAL ADDRESS'))
			validation+= '* You must specify your postal address\n';
		if ((document.getElementById('ws_phone').value == '') || (document.getElementById('ws_phone').value == 'PHONE'))
			validation+= '* You must specify your phone number\n';
		if (document.getElementById('ws_contact_list').value == '')
			validation+= '* You must upload a contact list\n';
		if (document.getElementById('ws_company_logo').value == '')
			validation+= '* You must upload your company logo\n';
	}
	
	if (validation == '') {
		return true;
	}
	else {
		alert (validation)
		return false;
	}
}