var message2="was not defined!";

/*

NOTE: Please do not copy this comment into HTML-Pages due to the version control. 

Syntax:

( (loopCheck(formname, fieldname, index, message)) && (loopCheck(formname, fieldname, index, message)) && ... && (loopCheck(formname, fieldname, index, message)) ) ? null : message2="";

where
 * formname - name or index of the active form 
 * fieldname - name or index of the form element to be checked
 * index - stands for the type of validation to be performed
 * message - input the type of the field here. For example, if input field corresponds to   
   the Last Name, input "Last Name"


//Index Parameter Description: 

//1 - if empty or alphabetic, returns true, otherwise, returns false
//2 - if empty or numeric, returns true, otherwise, returns false
//3 - if empty or alphanumurec+hyphens, returns true, otherwise, returns false
//4 - if non-empty and alphabetic, returns true, otherwise, returns false
//5 - if non-empty and numeric, returns true, otherwise, returns false
//6 - if non-empty and alphanumeric, returns true, otherwise, returns false
//7 - returns true, if select box value has been changed, otherwise returns false

function doCheck(){

( 
(loopCheck(0, "day", 7, "Day ")) && (loopCheck(0,"mon", 7, "Month")) && (loopCheck(0,"year", 5, "Year") && (loopCheck(0,"description", 6, "Description")) ? window.document.forms[0].submit() : message2=""
)

}

*/


function loopCheck(formname, fieldname, index, message){

var is=true;

(index==1) ? is=check1((window.document.forms[formname].elements[fieldname])) : null;
(index==2) ? is=check2((window.document.forms[formname].elements[fieldname])) : null;
(index==3) ? is=check3((window.document.forms[formname].elements[fieldname])) : null;
(index==4) ? is=check4((window.document.forms[formname].elements[fieldname])) : null;
(index==5) ? is=check5((window.document.forms[formname].elements[fieldname])) : null;
(index==6) ? is=check6((window.document.forms[formname].elements[fieldname])) : null;
(index==7) ? is=check7((window.document.forms[formname].elements[fieldname])) : null;

(!is) ? window.document.forms[formname].elements[fieldname].focus() : null;
(!is) ? alert(message+" "+message2) : null
return is;



}


function doCheck1(){
(loopCheck(0, "day", 0, "Day ")) && (loopCheck(0,"mon", 0, "Month")) && (loopCheck(0,"year", 5, "Year")) && (loopCheck(0,"description", 6, "Description")) ? window.document.forms[0].submit : message="";
}


function isType(numStr, data){
var thisChar="";
var counter=0;

for(var i=0; i<data.length; i++) {
 thisChar=data.substring(i,i+1);
 (numStr.indexOf(thisChar)!=-1) ? counter++ : null;
 }
 
 (counter==data.length) ?  counter=true : counter=false;
 return counter;
}

function isNum(data){
//returns true, if data contains only numbers

return isType("0123456789", data);

}

function isAlpha(data){
//returns true, if data contains only alpha

return isType("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ", data);
}

function isAlphaNum(data){
//returns true, if data contains only alpha, numbers and hyphens

return isType("0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ", data);
}


function isHyphen(data){
//returns true, if data contains only alpha, numbers and hyphens

return isType("0123456789-qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM ", data);
}

function isListSelected(fieldname){
//returns true, if selection has been changed in List Box

 var is;
 (fieldname.selectedIndex==0) ? is=false: is=true;
 
 return is;
}

function isEmpty(data){
//returns true if string is Empty

var is;
(data.length>0) ? is=false : is=true;
return is;
}


function check1(text_field){
//if non-empty and alpha or empty, returns true, otherwise, returns false

var is=true;

if (!isEmpty(text_field.value)) 
 {
  (isAlpha(text_field.value)) ? is=true : is=false;
 }
 if (!is)
  message2 = message2 + "failed check1";
 return is;
}


function check2(text_field){
//if non-empty and numeric or empty, returns true, otherwise, returns false

var is=true;

if (!isEmpty(text_field.value)) 
 {
  (isNum(text_field.value)) ? is=true : is=false;
 }

 return is;
}


function check3(text_field)
{
//if non-empty and alphanumurec+hyphens or empty, returns true, otherwise, returns false

var is=true;

if (!isEmpty(text_field.value)) 
 {
  (isHyphen(text_field.value)) ? is=true : is=false;
 }

 return is;

}


function check4(text_field)
{
//if non-empty and alpha, returns true, otherwise, returns false

var is=true;

((!isEmpty(text_field.value)) && (isAlpha(text_field.value))) ? is=true : is=false;

 return is;

}


function check5(text_field)
{
//if non-empty and numeric, returns true, otherwise, returns false

var is=true;

((!isEmpty(text_field.value)) && (isNum(text_field.value))) ? is=true : is=false;

 return is;

}


function check6(text_field)
{
//if non-empty and alphanumeric, returns true, otherwise, returns false

var is=true;

((!isEmpty(text_field.value)) && (isAlphaNum(text_field.value))) ? is=true : is=false;

 return is;

}


function check7(select_field)
{
//returns true, if selection has been changed in List Box

var is=true;

(isListSelected(select_field)) ? is=true : is=false;

 return is;

}
function check8(select_field)
{
//returns true, if selection has been changed in List Box

var is=true;

(isListSelected(select_field)) ? is=true : is=false;

 return is;

}



