// Copy the text between this line and the ***** line exactly
function isBlank(text) {
	for(var i = 0; i < text.length; ++i) {
		var c = text.charAt(i);
	}
}

function verifyText(text) {
	if(text == null || text == " " || text == "")
	   return false;
  else
	   return true;
}

function isSetRadioButton(buttons) {
    var checked = false;
    for(var i=0; i < buttons.length; ++i) {        
        if(buttons[i].checked)
            checked = buttons[i].value;
    }       
    return checked;
}

function isSet(element) {

	if(element.value == "- Veuillez sˇlectionner -" )
	{
		alert("yay");
	}

    switch(element.type.toLowerCase()) {    
        case "text" :
            return verifyText(element.value);
            break;
        case "textarea" :            
            return verifyText(element.value);
            break;
        case "select-one" :
            if(element.value == "----------" || 
               element.value == "- Please Select -"         || 
               element.value.indexOf("elect") != -1)
                return false;
            else
                return true;
            break;
        case "radio" :
            var checked = false;
            for(var m=0; m<element.length; m++) {
                if(element[m].checked)
                    checked = true;
            }
            if(!checked) // add error
                return false;
            break;
    }
}

function isEmail(value) {
    p=value.indexOf('@');
    if (p<1 || p==(value.length-1)) 
        return false;
    return true;
}

function isSetEmail(element) {
    if(verifyText(element.value) && isEmail(element.value))
        return true;
    return false;   
}

/************************************************************************/


// Modify the code in this function to check each form name element that is required.
// Any Radio button fields must use isSetRadioButton, text and textarea elements should
// use isSet.
function bidVerify(form) {
	var elementErrorString = new Array();
	var errorNumber = 0;
	
	
	// Check each element that you want to verify
	
	if(!isSet(form["messageSubject"]))
	   elementErrorString.push("Please select a product you are interested in.");	   
	
	if(!isSet(form["firstname"]))
	   elementErrorString.push("Please enter your first name.");
	if(!isSet(form["lastname"]))
	   elementErrorString.push("Please enter your last name.");	   
	if(!isSet(form["job"]))
	   elementErrorString.push("Please select your job function.");	   
	if(!isSet(form["company"]))
	   elementErrorString.push("Please enter the company name.");
	if(!isSet(form["phone"]))
	   elementErrorString.push("Please enter a phone number.");
	if(!isSetEmail(form["submittedBy"]))
	   elementErrorString.push("Please enter a valid email address.");	   
	   
	if(!isSet(form["address"]))
	   elementErrorString.push("Please enter an address.");	   
	if(!isSet(form["city"]))
	   elementErrorString.push("Please enter a city.");	      
	if(!isSet(form["zip"]))
	   elementErrorString.push("Please enter a postal code.");	   	   
	if(!isSet(form["country"]))
	   elementErrorString.push("Please select a country.");
	if(!isSet(form["hearabout"]))
	   elementErrorString.push("Please tell us how you heard about MTC.");	   
	   
	   
	if(!isSet(form["security_code"]))
	   elementErrorString.push("Please enter Security Code.");
	   
	   



	
	/** Do NOT MODIFY THE CODE BELOW **/
    if(elementErrorString.length > 0) {
	   	var alertString = "The following required ";
		if(elementErrorString.length > 1)
			alertString += "fields are incomplete :\n ";
		else {
			alertString += "field is incomplete :\n ";
  			alertString += "\n";
  		}
		for(var j = 0; j < elementErrorString.length; ++j) {
            alertString += elementErrorString[j] + "\n";
		}
		alertString += "\n";
		alert(alertString);
		return false;
  	}
  	else
		return true;
	   
}
