// usage: btnGenerate.Attributes.Add("onclick", "javascript:return ValidateItems(document.all['TaskActions1:tbTotal'].value, true, true, 1, 10, document.all['TaskActions1_lblCountExisting']);")
// "-1" are optional, if greater than -1, then opt to validate

function ValidateItems(ValueToCheck, CheckNumeric, CheckRequired, MinValue, MaxValue, objDiv) {

	// initialize as valid
	var valid = true;
	var HTMLMessage = "<ul>";
	
	// check value is numeric
	if (CheckNumeric == true) {
		if (IsNumeric(ValueToCheck) == false) {
			valid = false;
			HTMLMessage += "<li type='square'>Input must be numeric.</li>";
		}
	}
	
	// check field is not empty
	if (CheckRequired == true) {
		if (ValueToCheck == "" || ValueToCheck == null) {
			valid = false;
			HTMLMessage += "<li type='square'>A value must be entered.</li>";
		}
	}

	// check value is not greater than max value
	if (MaxValue > -1) {
		if (ValueToCheck > MaxValue) {
			valid = false;
			HTMLMessage += "<li type='square'>The value entered must not exceed " + MaxValue + ".</li>";
		}
	}

	// check value is not less than min value
	if (MinValue > -1) {
		if (ValueToCheck < MinValue) {
			valid = false;
			HTMLMessage += "<li type=square>The value entered must not be less than " + MinValue + ".</li>";
		}
	}

	// if valid, continue; otherwise return message and return false
	if (valid != true) {
		HTMLMessage +=  "</ul>";
		objDiv.innerHTML = HTMLMessage
		return false
	}
}

// check numeric function
function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

function CheckExplanation(src, args) {
	var ddl;
	ddl = document.all[ChangeToDdl(src.id)];
	var ddlval = ddl.options[ddl.selectedIndex].text;
	var tblen = document.all[ChangeToCtr(src.id)].value.length;
	
	if((ddlval.indexOf("Disagree") > -1) && (tblen < 1)) {
		args.IsValid = false;
	} else {
		args.IsValid = true;
	}
}

function ChangeToCtr(str) {
	var tb = str.substring(0, str.indexOf("rptAnswers")) + "tbComments";
	return tb
}

function ChangeToDdl(str) {
	var ddl = str.substring(0, str.indexOf("cvExplain")) + "ddl";
	return ddl
}

function CheckAll(src, args) {
	var boolchk = true;
	if (typeof(Page_ClientValidate) == 'function') {
		boolchk = Ctm_ClientValidate(src);
	}
	if(! boolchk) { 
		alert('Please enter a response for all required fields (marked with an asterisk*)\nand verify email addresses and dates are in the correct format.'); 
	} 
	args.IsValid = true;
}
function Ctm_ClientValidate(src) {
	var i;
	for (i = 0; i < Page_Validators.length; i++) {
		if (Page_Validators[i] != src) {
			ValidatorValidate(Page_Validators[i]);
		}
	}
	ValidatorUpdateIsValid();    
	ValidationSummaryOnSubmit();
	Page_BlockSubmit = !Page_IsValid;
	return Page_IsValid;
}
function DdlValidity(ddl) {
	if(ddl.selectedIndex == 0) {
		ddl.selectedIndex = document.Form1.initValue.value;
		return false
	} else {
		doPostBack('ddlSurveys','');
	}
}

function doPostBack(eventTarget, eventArgument) {
	var theform;
	if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
		theform = document.forms["Form1"];
	}
	else {
		theform = document.Form1;
	}
	theform.__CSTMTARGET.value = eventTarget.split("$").join(":");
	theform.__CSTMARGUMENT.value = eventArgument;
	theform.submit();
}

// the following is sample javascript called from a drop down list
function NeverSelectNeutral(id, val) {
	if(val.value=='16') {
		for(i=0; i < document.Form1.elements.length; i++) {
		// compare with this control
			compareId = document.Form1.elements[i].name;
			if(compareId != undefined) {
				if ((compareId.indexOf('rptSections:_ctl0:UcSectionQuestions1') > -1) && (compareId.indexOf('ddl') > -1) && (compareId != id)) {
					var breakout = false;
					for (x=0; x < document.Form1.elements[compareId].options.length; x++) {
						if ((breakout == false) && (document.Form1.elements[compareId].options[x].value == '10')) {
							document.Form1.elements[compareId].selectedIndex = x;
							f_breakout = true;
						}
					}
				}
			}
		}
	}
}