function isEmpty(s){
    for (var i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }	
return true;
}

function isDigit(c){
    return (( c >= "0" ) && (c <= "9"))
}

function isInteger(s){
var i, c;
   if(isEmpty(s)) 
      return false;
   for(i = 0; i < s.length; i++){
      c = s.charAt(i);
      if(isDigit(c)) 
	  return true;
  }
return false;
}

// E-mail
function isEmail(field){    
    var positionOfAt;
    var positionOfDot;
    var s = field.value;
	
    if ( s.charAt(0) == '@' || s.charAt(s.length -1) == '@'){    
        return false;
    }  
	
    positionOfAt = s.indexOf('@',1); 
    if ((positionOfAt == -1) || ( positionOfAt == (s.length-1))){    
        return false;
    }
      
    if ( s.charAt(0) == '.' || s.charAt(s.length -1) == '.'){    
        return false;
    }
	
    positionOfDot = s.indexOf('.',1); 
    if ((positionOfDot == -1) || ( positionOfDot == (s.length-1))){    
        return false;
    }
      
return true;
}

function validate_luxor(f){
   form = document.orderForm; 
   var msg;
   var empty_fields = " ";
      
   for(var i = 0; i < f.length; i++){
   var e = f.elements[i];   
  if(((e.type == "text") || (e.type == "textarea")) && (!e.optional)) {
        if((e.value == null) || (e.value == " ") || isEmpty(e.value)) {
  	       empty_fields += "\n\t" + e.name;
  		   continue;
  	  }
   }
}

if( (!empty_fields) && (isEmail(form.email)) && (!isInteger(form.first_name.value)) && (!isInteger(form.last_name.value)))
    return true;

msg = "________________________________________________\n\n";
msg += "Please correct the following errors and re-submit.\n";
msg += "________________________________________________\n\n";

if(empty_fields != " "){
    msg += "- The following required field(s) are empty:" + empty_fields + "\n";  
    alert(msg);
	return false;
}

if(!isEmail(form.email))
    msg += "\n- E-mail in invalid form.";

if(isInteger(form.first_name.value))
    msg += "\n- First name contains a number.";
	
if(isInteger(form.last_name.value))
    msg += "\n- Last name contains a number.";
	
if(isInteger(form.first_name.value) || isInteger(form.last_name.value) || !isEmail(form.email)){	
    alert(msg);
	return false;
}
return true;
}
