// JavaScript Document
function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}


function validateContactForm() {
	var str;
	var err;
	theform = document.EmailForm;
	name = trim(theform.fname.value);
	email = trim(theform.email.value);
	message = trim(theform.message.value);
	vericode = trim(theform.vericode.value);
	
	err = '';
	if(name == '') {
		err	+= 'Full Name';
	}
	if(email == '') {
		err	+= '\nEmail Address.';
	}
	if(message.length == 0) {
		err	+= '\nComments.';
	}
	if(vericode.length == 0) {
		err	+= '\nSecurity Code.';
	}
	if(err!='') {
		str = 'Please correct the following required fields before you proceed\n';
		str+='----------------------------------------------------------------------------\n';
		str +=err;
		alert(str);
		return false;	
	}
	
	theform.submit();
}

function validateQuoteForm() {
	var str;
	var err;
	 theform = document.QuoteForm;
	 name = trim(theform.name.value);
	 company = trim(theform.company.value);
	 email = trim(theform.email.value);
	 phone = trim(theform.phone.value);
	 city = trim(theform.city.value);
	 state = trim(theform.state.value);
	 country = trim(theform.country.value);
	 projecttype = trim(theform.project_type.value) ;
	 budget =trim(theform.budget.value) ; 
	 timeframe = trim(theform.timeframe.value);
	 url = trim(theform.url.value);
	 desc = trim(theform.description.value);
	 vericode = trim(theform.vericode.value);
	 	err = '';
	if(name == '') {
		err	+= 'Full Name';
	}
		if(company == '') {
		err	+= '\nCompany';
	}
		if(email == '') {
		err	+= '\nEmail';
	}
	/*	if(phone == '') {
		err	+= '\nPhone';
	}
		if(city == '') {
		err	+= '\nCity';
	}
		if(state== '') {
		err	+= '\nState';
	}
		if(country == '') {
		err	+= '\nCountry';
	}*/
		if(projecttype == '') {
		err	+= '\nProject Type';
	}
		if(budget == '') {
		err	+= '\nBudget';
	}
		if(timeframe == '') {
		err	+= '\nTimeframe';
	}
	/*	if(url == '') {
		err	+= '\nUrl';
	}*/
		if(desc == '') {
		err	+= '\nDescription';
	}
		if(vericode.length == 0) {
		err	+= '\nSecurity Code.';
	}
	checkedservices = '';
	for(j = 0 ;j < theform.elements.length; j++) {
		elm = theform.elements[j];
		//alert(elm.type);
		if(elm.type == 'checkbox' ) {
			//alert(j);
			if(elm.checked) {
				checkedservices += elm.value+',';
			}
		}
	}
	checkedservices = trim(checkedservices);
	if(checkedservices == '') {
		err += '\nServices required';
	}
	if(err!='') {
		str = 'Please correct the following required fields before you proceed\n';
		str+='----------------------------------------------------------------------------\n';
		str +=err;
		alert(str);
		return false;	
	} 
	
	theform.servicerequired.value = checkedservices;
	theform.submit();
}

 