/* ***********************************************************************
* File:			validate.js
* Author:		peter@iimg.com
* Commenced:	02.18.2003
* Overview:		all validation stuff will go here
***********************************************************************
FUNCTIONS:
	jsValidateRadio()
	jsValidateAfDoc()
	jsFinalAss()
	jsValidateUserDetails()
	jsValidatePaymentConfirm()
	
	jsConfirmUserDetails()

*********************************************************************** */

/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateWorkshop()
{

	var ret = ''; 

	if ( '' == document.navform.ftitle.value ) {
		ret += ' \n\t *  Workshop title';
	}	
	if ( '' == document.navform.txtabstract.value ) {
		ret += ' \n\t *  Abstract Text';
	}	
	if ( '' == document.navform.description.value ) {
		ret += ' \n\t *  Description';
	}	
	if ( '' == document.navform.objectives.value ) {
		ret += ' \n\t *  Objectives';
	}	
	if ( '' == document.navform.audience.value ) {
		ret += ' \n\t *  Audience';
	}	
	if ( '' == document.navform.programme.value ) {
		ret += ' \n\t *  Programme';
	}	

	if ( false == jsValidateRadio( document.navform.duration ) ) {
		ret += ' \n\t *  Duration';
	}	
	
	
	if ( '' == ret ) {
		return true;
	}
	else {
		// wrap up the message
		ret = 'The following field(s) are incomplete: ' + ret
			+ '\nPlease complete and submit the form again.';
		alert ( ret );
		return false;
	}
	return false;
}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateEReg(alevel)
{

	var ret = ''; 
	var str = ''
	
	if ( false == jsValidateRadio( document.navform.postertype ) ) {
		ret += ' \n\t *  Poster Type';
	}	
	
	if ( '' == document.navform.title.value ) {
		ret += ' \n\t *  Poster title';
	}	
	str = document.navform.title.value; 
	if (str.length > 1000 ) {
		ret += ' \n\t Poster title field should be no more than 1000 chars.';
	}
			
	if ( '' == document.navform.description.value ) {
		ret += ' \n\t *  Description';
	}	
	str = document.navform.description.value; 
	if (str.length > 1000 ) {
		ret += ' \n\t Description field should be no more than 1000 chars.';
	}


	if ( '' == document.navform.benefit.value ) {
		ret += ' \n\t *  Benefit';
	}	
	str = document.navform.benefit.value; 
	if (str.length > 1000 ) {
		ret += ' \n\t Benefit field should be no more than 1000 chars.';
	}

	if ( '' == document.navform.achieve.value ) {
		ret += ' \n\t *  Achieve';
	}	
	str = document.navform.achieve.value; 
	if (str.length > 1000 ) {
		ret += ' \n\t Achieve field should be no more than 1000 chars.';
	}

	// extraitems
	str = document.navform.extraitems.value; 
	if (str.length > 1000 ) {
		ret += ' \n\t Extra Items field should be no more than 1000 chars.';
	}
	str = document.navform.remarks.value; 
	if (str.length > 1000 ) {
		ret += ' \n\t Additional remarks field should be no more than 1000 chars.';
	}

	if ( alevel != '1' ) {
		if ( true != document.navform.toc.checked ) {
			ret += '\n\t * Terms And Condition'
		} 
	}
	
	if ( '' == ret ) {
		return true;
	}
	else {
		// wrap up the message
		ret = 'The following field(s) are incomplete: ' + ret
			+ '\nPlease complete and submit the form again.';
		alert ( ret );
		return false;
	}
	return false;

}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsConfirmUserDetails()
{
	var ret = ''; 
	
	if ( true != document.navForm.toc.checked ) {
		ret = '\n\t * Terms And Condition'
	} 
	if ( false == jsValidateRadio( document.navForm.display ) ) {
		ret += ' \n\t *  Acceptance';
	}

	if ( '' == ret ) {
		return true;
	}
	else {
		// wrap up the message
		ret = 'The following field(s) are incomplete: ' + ret
			+ '\nPlease complete and submit the form again.';
		alert ( ret );
		return false;
	}
	return false;
}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidatePaymentConfirm()
{
	var ret = jsValidateRadio( document.navForm.payment ); 
	if ( false == ret ) {
		alert("Please select payment type."); 
		return false; 
	}
	else {
		return true; 
	}
}

/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateDFAssessment(aMode)
{
	var ret = '';
	var str = '';

/*
Objectives  abscattxtdfasstopic07

Technical/Business case Quality				abscattxtdfasstopic15

Industrial Significance and Eventual Benefits				abscattxtdfasstopic23

Balance, Structure and Clarity				abscattxtdfasstopic33

Conclusion and Recommendations				abscattxtdfasstopic42

rejection : abscattxtdfasstopic44
radio : acceptance if less than 3
*/

	with( document.navForm) {
		if ( '' == abscattxtdfasstopic07.value ) {
			ret = ' \n\t *  Objectives';
		}

		if ( '' == abscattxtdfasstopic15.value ) {
			ret += ' \n\t *  Technical/Business case Quality';
		}

		if ( '' == abscattxtdfasstopic23.value ) {
			ret += ' \n\t *  Industrial Significance and Eventual Benefits';
		}

		if ( '' == abscattxtdfasstopic33.value ) {
			ret += ' \n\t *  Balance, Structure and Clarity';
		}

		if ( '' == abscattxtdfasstopic42.value ) {
			ret += ' \n\t *  Conclusion and Recommendations';
		}

		if ( false == jsValidateRadio( document.navForm.acceptance ) ) {
			ret += ' \n\t *  Acceptance';
		}
		else {
			var acc = jsGetRadioValue(document.navForm.acceptance);
			if ( acc < 3 ) {
				if ( '' == abscattxtdfasstopic44.value ) {
					ret += ' \n\t *  Reasons For Rejection';
				}
			}
		}
	}

	// final check
	if ( '' == ret ) {
		return true;
	}
	else {
		// wrap up the message
		ret = 'The following field(s) are incomplete: ' + ret
			+ '\nPlease complete and submit the form again.';
		alert ( ret );
		return false;
	}
	return false;
}

/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateUpload(aMode)
{
	var ext;
	var i;
	var str;
	var fileName = new String(document.navForm.file.value);
	var ipos = fileName.lastIndexOf(".");
	str = fileName.substr(fileName.lastIndexOf(".") + 1);
	var fileExt = str.toLowerCase();
	var rightExt = false;

	if (aMode == 'picture') {
		ext = new Array( 'jpeg', 'jpg', 'jpe');
		// check if file extension is *.jpeg, *.jpg, *.jpe
		for (i = 0; i<ext.length; i++) {
			rightExt = rightExt || ( ext[i] == fileExt );
		}
	}
	else if ( ( aMode == 'dfpaper') || (aMode == 'fpaper') || (aMode =='wsfinal') )   {
		ext = new Array( 'doc' );
		for (i = 0; i<ext.length; i++) {
			rightExt = rightExt || ( ext[i] == fileExt );
		}
	}
	else if ( ( aMode == 'ppt') )   {
		ext = new Array( 'ppt' );
		for (i = 0; i<ext.length; i++) {
			rightExt = rightExt || ( ext[i] == fileExt );
		}
	}

	// form up error message
	if (false == rightExt) {
		str = 'You can only upload the following types of files\n';
		for (i = 0; i<ext.length; i++) {
			str +='\t *.' + ext[i] + '\n'
		}
		str += 'Please choose the different file and try again.'
		alert(str);
		return false;
	}
	else {
		return true;
	}
}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateUserDetails(aMode, aLevel)
{
	var ret = '';
	var str = '';

	with( document.userDefails) {
		if ( '' == firstname.value ) {
			ret = ' \n\t * FirstName ';
		}
		if ( '' == lastname.value ) {
			ret += ' \n\t * LastName ';
		}
		if ( '' == email.value ) {
			ret += ' \n\t * EMail ';
		}
		if ( '' == address.value ) {
			ret += ' \n\t * Address ';
		}
		if ( '' == city.value ) {
			ret += ' \n\t * City ';
		}
		if ( '' == phone.value ) {
			ret += ' \n\t * Phone ';
		}
		if ( '' == organisation.value ) {
			ret += ' \n\t * Organisation ';
		}

		//alert( country.options[country.selectedIndex].value);

		if ( '-1' == country.options[country.selectedIndex].value ) {
			ret += ' \n\t * Country ';
		}


		if ( aMode != 'short' ) {
			// biography
			str = bio.value;
			if ( 2000 <  str.length ) {
				ret += ' \n\t * Biography field is more than 2000 chars. ';
			}

			// research 200
			str = research.value;
			if ( 200 <  str.length ) {
				ret += ' \n\t * Research interest field is more than 200 chars. ';
			}
		}


	}
	
	if ( aLevel > 2) {
		if (false == jsValidateRadio( document.userDefails.display ) ){
			ret += ' \n\t * Results displaying ';
		}

		if (false == jsValidateRadio( document.userDefails.orgtype ) ){
			ret += ' \n\t * Organisational Type ';
		}
	}
	
	// final check
	if ( '' == ret ) {
		return true;
	}
	else {
		// wrap up the message
		ret = 'The following field(s) are incomplete: ' + ret
			+ '\nPlease complete and submit the form again.';
		alert ( ret );
		return false;
	}
	return false;

}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * arguments:		a_sType : type of the finalizing
 * returns:
 ********************************************************* */
function jsFinalAss(a_sType)
{

	if ( false == jsValidateRadio(document.formFinalAss.finalass) ) {
		alert('You have to choose YES or NO!');
		return;
	}
	else {
		var score = jsGetRadioValue(document.formFinalAss.finalass);
		var factid = document.formFinalAss.factid.value;
		var url = 'site/code/finalizeAbstractAssessment.asp?factid=' + factid 
				+ '&fscore=' + score + '&type=' + a_sType;
		//alert(url);
		jsOpenWindowEx(url, 'width=300,height=200,scrollbars=1')
	}
}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateRadio( aRadio )
{	

	for (var i = 0; i < aRadio.length; i++) {
		if (true == aRadio[i].checked) {
			return true;
		}
	}
	return false;
}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
function jsValidateAfDoc()
{
	var ret = '';
/*
technicalquality
businessquality
innovation
relevance
presentation
acceptance
*/


	if ( (false == jsValidateRadio(document.navForm.technicalquality)) &&
			( false == jsValidateRadio(document.navForm.businessquality) ) ) {
		ret = ' \n\t * Either Technical or Business Quality ';
	}

	if (false == jsValidateRadio(document.navForm.innovation) ) {
		ret += ' \n\t * Innovation ';
	}

	if (false == jsValidateRadio(document.navForm.relevance) ) {
		ret += ' \n\t * Relevance ';
	}

	if (false == jsValidateRadio(document.navForm.presentation) ) {
		ret += ' \n\t * Presentation ';
	}

	if (false == jsValidateRadio(document.navForm.acceptance) ) {
		ret += ' \n\t * Acceptance ';
	}


	// comments
	if ( '' == document.navForm.comments.value ) {
		ret += ' \n\t * Comments to the Author';
	}

	// final check
	if ( '' == ret ) {
		return true;
	}
	else {
		// wrap up the message
		ret = 'The following field(s) are incomplete: ' + ret
			+ '\nPlease complete and submit the form again.';
		alert ( ret );
		return false
	}
	return false;
}


/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */
/** *******************************************************
 * function:
 * author:			peter@iimg.com
 * description:
 * returns:
 ********************************************************* */

