function ValidateQuantity(){
	var ok = true;
	var frm = document.getElementById('form2');
	var filter  = /^[1-9]+[0-9]*$/; // only positive numbers greater than zero
	for (var i = 0; i < frm.elements.length; i++){
		if(frm.elements[i].type == "text"){
			if (!filter.test(frm.elements[i].value)) {
				frm.elements[i].style.borderColor = "#CC0000";				
				ok = false;
			}	
			else frm.elements[i].style.borderColor = "#000000";				
		}
	}
	if (!ok) alert ("Quantity has to be number greater then zero!");
	return ok;
}

function CheckAgreeTerms(){
	var check = document.getElementById('terms');
	if (!check.checked) {
		alert("You must agree with terms & policy!");
		return false;
	}
	else return true;
}


function ValidatePayment(){
	
}


function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function BodyCheck(){
 var body = document.getElementById('message').value;
 var arrBody = body.split(' ');
 var arrBodyCount = arrBody.length; var strReturn='';
 for (i=0; i < arrBodyCount; i++){ if (trim(arrBody[i])!='') {
 var arrCRBody = (trim(arrBody[i])).split('\n'); if (arrCRBody.length > 1){
 for (j=0; j < arrCRBody.length; j++){
 if (trim(arrCRBody[j])!='') {
 strReturn += trim(arrCRBody[j]); if (j < ((arrCRBody.length)-1))strReturn += ' '; } }
 } else strReturn += trim(arrBody[i]); if (i < arrBodyCount-1) strReturn += ' '
 }
 }
 arrBody = strReturn.split(' ');
 arrBodyCount = arrBody.length;
 //for (i=0; i < arrBodyCount; i++) alert("++"+arrBody[i]+"++"); 
if (arrBodyCount < 10) {
 if (trim(arrBody[0])=='' || trim(arrBody[arrBodyCount-1])=='') arrBodyCount--;
 if (arrBodyCount == 1) var words = 'word';
 else var words = 'words';
 alert("Your submission has "+arrBodyCount+" "+words+" - it must be a least 10 words.");
 return false;
 }
 else return true; 

}


function ValidateContact(){
	var name = document.getElementById('name').value;
	name = name.replace(/^\s*|\s*$/g,"");
	if (name==""){
		alert ("Please fill the name field.");
		return false;
	}
	

  var x = document.getElementById('email').value
  var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  if (!filter.test(x))
  {
    alert ("Please enter correct email address.");
    return false;           
  }	
  
	var subject = document.getElementById('subject').value;
	subject = subject.replace(/^\s*|\s*$/g,"");
	if (subject==""){
		alert ("Please fill the subject field.");
		return false;
	}	  
  
  if (!BodyCheck()) return false;
  
  return true;
}
