var sChar1 ="'";
var sChar2 ="\"";

function isLowerAlphabet(ch){
if( ch >= 'a' && ch <= 'z')
	return true;
return false;
}

function isUpperAlphabet(ch){
if( ch >= 'A' && ch <= 'Z')
	return true;
return false;
}

function isAlphabet(ch){
if( isUpperAlphabet(ch) || isLowerAlphabet(ch) )
	return true;
return false;
}

function isNumeric(ch){
if( ch >= '0' && ch <= '9')
	return true;
return false;
}

function isAlphaNumeric(ch){
if( isAlphabet(ch) || isNumeric(ch) )
	return true;
return false;
}

function isLowerAlphaNumeric(ch){
if( isLowerAlphabet(ch) || isNumeric(ch) )
	return true;
return false;
}

function isUpperAlphaNumeric(ch){
if( isUpperAlphabet(ch) || isNumeric(ch) )
	return true;
return false;
}


function formatChars(charList){
var formatStr=" ";
var i=0;
while( i < charList.length){
	if(charList.charAt(i)!=' '){
		formatStr= formatStr+charList.charAt(i)+" ";
	}
	else{
		formatStr= formatStr+"space ";
	}
i++;
}
return formatStr;
}


function checkSelect(obj, req, label){
if(req !=1){
	return true;
}
else{
	if(! obj.options[0].selected)
	return true;
	else{
        	tMessage = label+" is a required field. Please select";
	        eMessage = eMessage + "-"+tMessage +"\n";
		return false;
        }  
}
}

function checkCheckBox(obj, req, label){
if(req !=1){
	return true;
}
else{
	if(obj.checked == true)
		return true;
	else{
                tMessage = label+" is a required field. Please check the box";
	        eMessage = eMessage + "-"+tMessage +"\n";
		return false;
        } 
}
}

//charType= 1 a-z
//charType= 2 A-Z
//charType= 3 0-9
//charType= 4 a-z A-Z
//charType= 5 0-9 a-z
//charType= 6 0-9 A-Z
//charType= 7 0-9 a-z A-Z


function checkText(obj, req, label, min, charType, specialChars, msg){
if(req == 1){
	if(obj == "" || obj == null){
                tMessage = label+" is a required field. Please enter a value";
                if(msg == 1)
		alert(tMessage);
                else
                eMessage = eMessage + "-"+tMessage +"\n";
		return false;
	}
	if( obj.length < min ){
		tMessage = label+" field required minimum " + min + " characters. Please enter again";			
                if(msg == 1)
		alert(tMessage);
		else
	        eMessage = eMessage + "-"+tMessage +"\n";
		return false;
	}
}
else{
	
if(( obj.length != 0 ) && ( obj.length < min )) {
		tMessage = label+" field required minimum " + min + " characters. Please enter again";			
                if(msg == 1)
		alert(tMessage);
		else
	        eMessage = eMessage + "-"+tMessage +"\n";
		return false;
}


}

if( charType == 1){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isLowerAlphabet(ch)){
			tMessage = "The characters allowed for "+label+" are a-z";				
			if(msg == 1 )
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+tMessage +"\n";
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isLowerAlphabet(ch) && specialChars.indexOf(ch) < 0){
			tMessage = "The characters allowed for "+label+" are a-z " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+tMessage +"\n"; 	
	                return false;
		}
	}
}
return true;
}

if( charType == 2){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isUpperAlphabet(ch)){
			tMessage = "The characters allowed for "+label+" are A-Z";				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+tMessage +"\n"; 	
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isUpperAlphabet(ch) && specialChars.indexOf(ch) < 0){
                        tMessage = "The characters allowed for "+label+" are A-Z " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+tMessage +"\n";
	                return false;
		}
	}
}
return true;
}

if( charType == 3){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isNumeric(ch)){
			tMessage= "The characters allowed for "+label+" are 0-9";				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isNumeric(ch) && specialChars.indexOf(ch) < 0){
			tMessage = "The characters allowed for "+label+" are 0-9 " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+tMessage +"\n";
	                return false;
		}
	}
}
return true;
}

if( charType == 4){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isAlphabet(ch)){
			tMessage = "The characters allowed for "+label+" are a-z A-Z";				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isAlphabet(ch) && specialChars.indexOf(ch) < 0){
			tMessage = "The characters allowed for "+label+" are a-z A-Z " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
	                return false;
		}
	}
}
return true;
}

if( charType == 5){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isLowerAlphaNumeric(ch)){
			tMessage = "The characters allowed for "+label+" are a-z 0-9";				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isLowerAlphaNumeric(ch) && specialChars.indexOf(ch) < 0){
			tMessage = "The characters allowed for "+label+" are a-z 0-9 " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
	                return false;
		}
	}
}
return true;
}

if( charType == 6){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isUpperAlphaNumeric(ch)){
			tMessage = "The characters allowed for "+label+" are A-Z 0-9";				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isUpperAlphaNumeric(ch) && specialChars.indexOf(ch) < 0){
			tMessage = "The characters allowed for "+label+" are A-Z 0-9 " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
	                return false;
		}
	}
}
return true;
}

if( charType == 7){
if(specialChars == "" || specialChars == null){
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
		if(!isAlphaNumeric(ch)){
			tMessage = "The characters allowed for "+label+" are a-z A-Z 0-9";				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
			return false;
		}
	}
}
else{
	for(i=0; i< obj.length; i++){
		ch = obj.substring(i,i+1);
                if(!isAlphaNumeric(ch) && specialChars.indexOf(ch) < 0){
			tMessage = "The characters allowed for "+label+" are a-z A-Z 0-9 " +formatChars(specialChars);				
			if(msg == 1)
                        alert(tMessage);
                        else
	                eMessage = eMessage + "-"+ tMessage +"\n";
	                return false;
		}
	}
}
return true;
}

}

function checkDescription(obj, req, label, msg){
var min = 30; var max = 3200;
if(req == 1){
	if(obj == "" || obj == null){
                tMessage = label+" is a required field. Please enter a value";
                if(msg == 1) {
			alert(tMessage);
		} else {
                	eMessage = eMessage + "-"+tMessage +"\n";
		}
		return false;
	} else if( obj.length < min  || obj.length > max ){
		if(obj.length < min) {
			tMessage = label+" field required minimum " + min + " characters. Please enter again";			
		} else {
			tMessage = label+" field needs to be less than " + max + " characters. Please enter again";			
		}
                if(msg == 1) { 
			alert(tMessage); 
		} else { 
			eMessage = eMessage + "-"+tMessage +"\n"; 
		}
		return false;
	}
} else if(( obj.length != 0 ) && ( obj.length < min || obj.length > max)) {
		if(obj.length < min) {
			tMessage = label+" field required minimum " + min + " characters. Please enter again";			
		} else {
			tMessage = label+" field needs to be less than " + max + " characters. Please enter again";			
		}
                if(msg == 1) {
			alert(tMessage);
		} else {
	        	eMessage = eMessage + "-"+tMessage +"\n";
		}
		return false;
}

return true;

}

function checkEmail(obj, req, label, msg)
 { 
   if (( obj == "" || obj == null ) && (req == 1)){
       tMessage = label+" is required field. Please enter a value";
       if(msg == 1)
 	alert(tMessage);
       else
       eMessage = eMessage + "-"+tMessage +"\n";
       return false;
   }
   if (obj.indexOf('@') < 0 || obj.indexOf('.') < 0   ) {
      tMessage = label + " field is in wrong format.  At least one period (.) and \"@\" sign is required.";
      if(msg == 1)
	alert(tMessage);
      else
	  eMessage = eMessage + "-"+tMessage +"\n";
      return false;
   }
   return checkText(obj, req, label, 8, 7, '@._-', msg);
}

function checkMultiEmail(obj, req, label, msg)
 { 
   if (( obj == "" || obj == null ) && (req == 1)){
       tMessage = label+" is a required field. Please enter a value";
       if(msg == 1)
 	alert(tMessage);
       else
       eMessage = eMessage + "-"+tMessage +"\n";
       return false;
   }
   if (obj.indexOf('@') < 0 || obj.indexOf('.') < 0   ) {
      tMessage = label + " field is in wrong format.  At least one period (.) and \"@\" sign is required.";
      if(msg == 1)
	alert(tMessage);
      else
	  eMessage = eMessage + "-"+tMessage +"\n";
      return false;
   }
   return checkText(obj, req, label, 8, 7, '@._-, ', msg);
}


function isEqual(obj1, obj2){ 
 if (obj1.length != obj2.length || obj1 != obj2 ) 
 return false;  
 return true;
}  

function confirmValues(obj1, obj2, label, msg){
if(!isEqual(obj1, obj2)){
	tMessage = label + " and Confirm " + label + " field do not match.";
        if(msg == 1)
 		alert(tMessage);
      	else
	eMessage = eMessage + "-"+tMessage +"\n";
	return false;
}
return true;
}

function checkAccount(obj1, obj2, label, msg){
if(checkText(obj1, 1, label, 15, 3, '', msg)){
if((obj2 != 4) && (obj1.length != 16)){
	tMessage = label + " is Invalid, Please Enter Vaild " + label + " and Type.";
        if(msg == 1)
 		alert(tMessage);
      	else
	eMessage = eMessage + "-"+tMessage +"\n";
	return false;
}
if((obj2 == 4) && (obj1.length !=15)){
	tMessage = label + " is Invalid, Please Enter Vaild " + label + " and Type.";
        if(msg == 1)
 		alert(tMessage);
      	else
	eMessage = eMessage + "-"+tMessage +"\n";
	return false;
}
return true;
}
}

function checkDate(obj, req, year_min, year_max, label, msg)
{
 if(checkText(obj, req, label, 10, 3, '-', msg)){
 var month=0, day=0; year=0, value=0;

 for(i=0; i < obj.length; i++){
 ch = obj.substring(i,i+1);
 if (ch == '-')
 value++;
 }
 ch1 = obj.substring(4,5);
 ch2 = obj.substring(7,8);
 if((ch1 != '-') || ( ch2 != '-') || ( value != 2 )){
 tMessage = label + " format is invalid. " + label + " must be in the YYYY-MM-DD format.";
 if(msg == 1)
   alert(tMessage);
 else
   eMessage = eMessage + "-"+tMessage +"\n";
 return false;
 }
 else{
 month = obj.substring(5,7);
 day= obj.substring(8,10); 
 year= obj.substring(0,4);
 if( year < year_min || year > year_max){
 tMessage = "Invalid year entered in " + label + ".  Please enter a year between " + year_min +"-" + year_max +"."
 if(msg == 1)
   alert(tMessage);
 else
   eMessage = eMessage + "-"+tMessage +"\n";
 return false;
 }
 if (isNaN(month) || month < 1 || month > 12){
   tMessage = label+ " includes an invalid month. "+ label + " Month must be between 01 and 12.";
   if(msg == 1)
    alert(tMessage);
   else
    eMessage = eMessage + "-"+tMessage +"\n";
   return false;
  }
  if (isNaN(day) || day < 1 || day > 31){ 
      tMessage = label + " includes an invalid day of the month.";
     if(msg == 1)
      alert(tMessage);
     else
      eMessage = eMessage + "-"+tMessage +"\n";
     return false;
  }
  if (month == 4 || month == 6 || month == 9 || month == 11){ 
    if (day > 30){ 
       tMessage = label + " includes an invalid day of the month.";
       if(msg == 1)
         alert(tMessage);
       else
         eMessage = eMessage + "-"+tMessage +"\n";
       return false;
       }
    }
    else if (month == 2 && (year%4 == 0)){ 
    if ( day > 29){ 
       tMessage = label + " includes an invalid day of the month.";
       if(msg == 1)
         alert(tMessage);
       else
         eMessage = eMessage + "-"+tMessage +"\n";
       return false;
       }
   }
   else if (month == 2 && (year%4 != 0)){ 
   if ( day > 28){ 
       tMessage = label + " includes an invalid day of the month.";
       if(msg == 1)
         alert(tMessage);
       else
         eMessage = eMessage + "-"+tMessage +"\n";
       return false;
      }
   }
 return true;
 }
 }
}

function checkExpDate(obj, req, year_min, year_max, label, msg)
{
 if(checkText(obj, req, label, 7, 3, '-', msg)){
 var month=0, year=0, value=0;

 for(i=0; i < obj.length; i++){
 ch = obj.substring(i,i+1);
 if (ch == '-')
 value++;
 }

 ch1 = obj.substring(4,5);

 if((ch1 != '-') || ( value != 1 )){
 tMessage = label + " format is invalid. " + label + " must be in the YYYY-MM format.";
 if(msg == 1)
   alert(tMessage);
 else
   eMessage = eMessage + "-"+tMessage +"\n";
 return false;
 }
 else{
 month = obj.substring(5,7);
 year= obj.substring(0,4);
 if( year < year_min || year > year_max){
 tMessage = "Invalid year entered in " + label + ".  Please enter a year between " + year_min +"-" + year_max +"."
 if(msg == 1)
   alert(tMessage);
 else
   eMessage = eMessage + "-"+tMessage +"\n";
 return false;
 }

 if (isNaN(month) || month < 1 || month > 12){
   tMessage = label+ " includes an invalid month. "+ label + " Month must be between 01 and 12.";
   if(msg == 1)
    alert(tMessage);
   else
    eMessage = eMessage + "-"+tMessage +"\n";
   return false;
 }
 return true;
 }

 }

}

function checkDateFormat(obj, req, label, msg){
 if(checkText(obj, req, label, 10, 3, '-', msg)){
	 var month=0, day=0; year=0, value=0;

 	for(i=0; i < obj.length; i++){
 		ch = obj.substring(i,i+1);
 		if (ch == '-')
 		value++;
 	}
 	ch1 = obj.substring(4,5);
 	ch2 = obj.substring(7,8);
 	if((ch1 != '-') || ( ch2 != '-') || ( value != 2 )){
 		tMessage = label + " format is invalid. " + label + " must be in the YYYY-MM-DD format.";
 		if(msg == 1)
   			alert(tMessage);
 		else
   			eMessage = eMessage + "-"+tMessage +"\n";
 		return false;
 	}
 	return true;
 }
}
