// Java Document
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function theValidator(theForm,theControl,theMessage,theNumeric,theEMail)
{
	// This function is used to validate that all text
	// fields in a given form contain some value
	//Split the controls + Messages + Numerics by comma ,
//alert();	
	var theControls = new Array();
	var theMessages = new Array();
	var theNumerics = new Array();
	var theEMails = new Array();

	theControls=theControl.split("|");
	theMessages=theMessage.split("|");
	theNumerics=theNumeric.split("|");
	theEMails=theEMail.split("|");

for (var i=0; i < theForm.elements.length; i++){
 for(var counter=0;counter < theControls.length; counter++){
  if (theForm.elements[i].name == theControls[counter]){
   //type File field
   if (theForm.elements[i].type=='file') {
    //Blank value check
    if (trim(theForm.elements[i].value)=='') {
     alert("Please enter the "+ theMessages[counter] + ".");
	 theForm.elements[i].focus();
	 return false;	
	 } }
   //type File field
   //type Text field
   if (theForm.elements[i].type=='text') {
    //Blank value check
    if (trim(theForm.elements[i].value)=='') {
     alert("Please enter the "+ theMessages[counter] + ".");
	 theForm.elements[i].focus();
	 return false; }
    //Blank value check
	// Numeric value check
    if (trim(theForm.elements[i].value) != '' && theNumerics[counter] == "Y") {
     if(isNaN(trim(theForm.elements[i].value))){
	  alert("Please enter numeric value for "+theMessages[counter]+".");
	  theForm.elements[i].focus();
	  return false;	}
	if(trim(theForm.elements[i].value)<= 0 ) {
      abc=theMessages[counter].replace(theMessages[counter],theMessages[counter].charAt(0).toUpperCase());
	  alert(abc+theMessages[counter].substring(1,theMessages[counter].length)+ " should be greater than 0.");
	  theForm.elements[i].focus();
	  return false;	} }
	// Numeric value check
	// EMail check
    if (trim(theForm.elements[i].value)!= '' && theEMails[counter] == "Y") {
	 var regex=/^[a-zA-Z0-9]+[\._]?[a-zA-Z0-9]+[\._]?[a-zA-Z0-9]+@[a-zA-Z]{2,16}.[a-z]{1,3}[\.]{1}[a-z]{1,3}$/;
 	 if (!regex.test(theForm.elements[i].value)){
	  alert("Enter a valid e-mail.");
	  theForm.elements[i].focus();
	  return false; } }	// EMail check
	 }
   //type Text field
	//type Password field
	if(theForm.elements[i].type=='password'){
     if (trim(theForm.elements[i].value)=='') {
      alert("Please enter the "+ theMessages[counter] + ".");
	  theForm.elements[i].focus();
	  return false; } }
	//type Password field
	// Text Area Validation
	if (theForm.elements[i].type == "textarea") {
	 if(trim(theForm.elements[i].value)=="") {
	  alert("Please enter the "+theMessages[counter] + ".");
	  theForm.elements[i].focus();
	  return false;	} }
	// Text Area Validation
	//Select box validation
	if (theForm.elements[i].type == "select-one") {
	 var selIndex,selValue;
	 var theObject=theForm.elements[i];
	 selIndex=theForm.elements[i].selectedIndex;
	 selValue = theObject[selIndex].value;
	 if( trim(selValue)=="" || trim(selValue)=="0") {
      alert("Please select the " + theMessages[counter] + ".");
	  theForm.elements[i].focus();
	  return false;	} }
  	//Select box validation

	} } }
}

function mkEnable(theForm,chkControl,theControl){
 var theControls = new Array();
 theControls=theControl.split("|");
 if (document.getElementById(chkControl).checked==1){
  for(var counter=0;counter<theControls.length; counter++){
 	document.getElementById(theControls[counter]).disabled = false;  }
 } else {
  for(var counter=0;counter<theControls.length; counter++){
 	document.getElementById(theControls[counter]).disabled = true;  }
  }
}

function sameValue(theForm,srcControls,finControls){
	var sourcControls = new Array();
	var finalControls = new Array();
	sourcControls=srcControls.split("|");
	finalControls=finControls.split("|");
	
	for(var counter=0; counter<sourcControls.length; counter++){
		document.getElementById(finalControls[counter]).value=document.getElementById(sourcControls[counter]).value;
	}
	
}
///////////////////////////////////////////////////////////////////////
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}
function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;
 	selectbox.options.add(optn);
}

