// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function getCheckedId(formObj,nameRadio) {
 for (i=0;i<formObj.length; i++) {
	if ((formObj[i].type=='radio')&&(formObj[i].name==nameRadio)) {
        if ((formObj[i].checked)){
            return i;
        }
 }
}
}

function checkForm(formObj) {
isChecked = false;

for (i=0;i<formObj.length; i++) {
	if ((formObj[i].type=='radio')&&(formObj[i].name=="_role")) {
        if ((formObj[i].checked)){
            isChecked = true;
        }
 }
}


message = "";
whatLang = "RU_RU_TRADITIONAL_WIN" ? rusinterface = true : rusinterface = false;

	Name = formObj._Name.value
	Title = formObj._Title.value
//	Institution_Type = formObj._InstitutionType[formObj._InstitutionType.selectedIndex].value
	Institution_Name = formObj._InstitutionName.value
	Address = formObj._Address.value
	City = formObj._City.value
	if ( whatLang == "EN_US_TRADITIONAL_WIN" ) {
		State =  formObj._State.value
	}
	Zip = formObj._ZIP.value
	Country = formObj._Country[formObj._Country.selectedIndex].value
	Phone = formObj._Phone.value
	Email = formObj.submit_by.value

/*    Name_of_Library = formObj._lib_name.value
    Library_Contact = formObj._lib_contact_name.value
    Contact_Title = formObj._lib_contact_title[formObj._lib_contact_title.selectedIndex].value
    Contact_Email = formObj._lib_contact_email.value*/


    Role = isChecked ? formObj[getCheckedId(formObj, "_role")].value : "";
    OtherRole = formObj._other.value;


    if (isWhitespace(Name)) {	message += rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u0412\u0410\u0428\u0418 \u0418\u041c\u042f \u0418 \u0424\u0410\u041c\u0418\u041b\u0418\u042f*  \r\n" : "Please, fill *YOUR NAME* field \r\n" ; }
	if (isWhitespace(Title)) {	message += rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u0412\u0410\u0428\u0410 \u0414\u041e\u041b\u0416\u041d\u041e\u0421\u0422\u042c*  \r\n" : "Please, fill *YOUR TITLE* field \r\n"; }
	if (isWhitespace(Institution_Name)) {	message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u041d\u0410\u0417\u0412\u0410\u041d\u0418\u0415 \u0418\u041d\u0421\u0422\u0418\u0422\u0423\u0422\u0410*  \r\n" : "Please, fill *INSTITUTION NAME* field \r\n"; }
	//if (isWhitespace(Address)) {	message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u0410\u0414\u0420\u0415\u0421*  \r\n" : "Please, fill *ADDRESS* field \r\n"; }
	if (isWhitespace(City)) {	message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435  *\u0413\u041e\u0420\u041e\u0414* \r\n" : "Please, fill *CITY* field \r\n"; }

/*
    if (isWhitespace(Name_of_Library)) {	message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435  *Name of Library* \r\n" : "Please, fill *Name of Library* field \r\n"; }
    if (isWhitespace(Library_Contact)) {	message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435  *Library Contact* \r\n" : "Please, fill *Library Contact* field \r\n"; }
*/

    if ( whatLang == "EN_US_TRADITIONAL_WIN" ) {
		if (isWhitespace(State)) {	message +=  "Please, fill *STATE/PROVINCE* field \r\n"; }
	}
	if (isWhitespace(Zip)) {	message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u041f\u041e\u0427\u0422\u041e\u0412\u042b\u0419 \u0418\u041d\u0414\u0415\u041a\u0421*  \r\n" : "Please, fill *ZIP* field \r\n"; }
		//	else if ( !ForceNumber(formObj._ZIP, "*ZIP*")) { message += rusinterface ? ">>> \u043f\u043e\u043b\u0435 *\u041f\u041e\u0427\u0422\u041e\u0412\u042b\u0419 \u0418\u041d\u0414\u0415\u041a\u0421* \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b" : ">>> *ZIP*" + " must be a valid numeric entry. \r\n"; }
	if (Country == "n/a") { message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u0421\u0422\u0420\u0410\u041d\u0410*  \r\n" : "Please, fill *COUNTRY* field \r\n"; }

/*
    if (Contact_Title == "n/a") { message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *Contact Title*  \r\n" : "Please, fill *Contact Title* field \r\n"; }

*/
    if (isWhitespace(Phone)) { message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *\u0422\u0415\u041b\u0415\u0424\u041e\u041d*  \r\n" : "Please, fill *Phone* field \r\n"; }
		else if ( !ForceNumber(formObj._Phone, "*PHONE*")) { message += rusinterface ? ">>> \u043f\u043e\u043b\u0435 *\u0422\u0415\u041b\u0415\u0424\u041e\u041d* \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0446\u0438\u0444\u0440\u044b" : ">>> *Phone*" + " must be a valid numeric entry. \r\n"; }
	if (isWhitespace(Email)) { message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *E-MAIL*  \r\n" : "Please, fill *E-MAIL* field \r\n"; }
      		else if (!isEmail(Email)) { message += "Please, fill email correctly \r\n"; }

/*
    if (isWhitespace(Contact_Email)) { message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *LIBRARIAN CONTACT E-MAIL*  \r\n" : "Please, fill *LIBRARIAN CONTACT E-MAIL* field \r\n"; }
      		else if (!isEmail(Contact_Email)) { message += "Please, fill librarian contact email correctly \r\n"; }
*/

    if (isWhitespace(Role)) { message +=  rusinterface ? "\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u043f\u043e\u043b\u0435 *ROLE*  \r\n" : "Please, ndicate your Role \r\n"; }
         else if (Role == "_role_other") {
             if (isWhitespace(OtherRole)) {message += "Please fill in your other role"}
         }


    if (message.length > 0)	{
	alert (message);
	return false;
	} else {
	return true;
	}

}

