// Confirm Password.
function confirmpass(obj1, obj2, str){
	if(obj1.value != obj2.value){
		obj2.value=""
		selfocobj(obj1, str)
		return false;	
	}
	return true
}

// checks whether string is numeric or not.
function isNumeric(obj,s){
	if(isEmpty(obj.value) | isNaN(obj.value)){
			selfocobj(obj, s)
			return false;
		}
	return true;
}

// checks whether string is positive integer or not.
function isNumericPosInt(obj,s){
	if(obj.value.match(/^\d+$/)==null){
			selfocobj(obj, s)
			if (!isNaN(obj.value)) obj.value=Math.abs(parseInt(obj.value));
			  else obj.value=0;
			return false;
		}
	return true;		
}

// checks whether string starts with phone or not.
function isPhone(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_phone = /^\d\d\d-\d\d\d-\d\d\d\d/
	if (!re_phone.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string starts with http:// or not.
function isWebURL(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_url = /^http:\/\/\w/
	if (!re_url.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is Currency or not.
//^(\d+)\-(\d+)\-(\d+)$/;
function isCurrency(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_money = /^\d*(\.\d{2})?$/
	if (!re_money.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is Currency/Percent or not.
//^(\d+)\-(\d+)\-(\d+)$/; or /^\d+$/
function isCurrencyORPercent(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_money = /^\d*(\.\d{2})?$/
	var re_percent = /^\d+$/
	if (!re_money.exec(obj.value) && !re_percent.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is Date or not.
//^(\d+)\-(\d+)\-(\d+)$/;
function isDate(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_date = /^([0-9]){2}(\/|-){1}([0-9]){2}(\/|-){1}([0-9]){2}$/
	if (!re_date.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is a Year between year 1/year 2 or not.
//^(\d+)\-(\d+)\-(\d+)$/;
function isYear(obj,y1,y2,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_year = /^([0-9]){4}$/
	if (!re_year.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	if (Math.abs(parseInt(obj.value)) < y1 || Math.abs(parseInt(obj.value)) > y2 ){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is Date or not.
function isDateTime(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	var re_date = /^(\d+)\-(\d+)\-(\d+)\s+(\d+)\:(\d+)\:(\d+)$/;
	if (!re_date.exec(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// isDocument (STRING s [, BOOLEAN emptyOK])
//function isDocument (obj, s) {   
	//if((obj.value.lastIndexOf(".doc")==-1) && (obj.value.lastIndexOf(".pdf")==-1))
	 //{
	   // selfocobj(obj, s)
//		return false;
	 // }
	//return true;
//}

// checks whether string is DOC or PDF document with alphanumeric spaces or underscores
function isDocument(obj,s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	} 
	what=obj.value;
    if (what.indexOf('/') > -1)
        answer = what.substring(what.lastIndexOf('/')+1,what.length);
    else
        answer = what.substring(what.lastIndexOf('\\')+1,what.length);
	var re_doc = /^[a-zA-Z0-9\-_ ]+\.(pdf|PDF|doc|DOC)$/;
	if (!re_doc.exec(answer)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is empty or not
function isRequired(obj, s){
	if(isEmpty(obj.value)){
		selfocobj(obj, s)
		return false;
	}
	return true;
}

// checks whether string is empty or not
function isRequiredFT(obj, s){
	if(isEmpty(obj.value)){
		alert(s);
		return false;
	}
	return true;
}

// checks whether select string is empty or not
function isReqSel(obj, s){
	if(isEmpty(obj[obj.selectedIndex].value)){
		alert(s);
        obj.focus();
		return false;
	}
	return true;
}

// checks whether multi-select string is empty or not
function isReqSelMulti(obj, s){
    valsel=0;
	for (x = 0; x < obj.options.length; x++) {
		if (obj.options[x].selected == true) {
          valsel=1;
		}
	}
	if(valsel == 0){
		alert(s);
        obj.focus();
		return false;
	}
	return true;
}


// checks whether text area exceeds max length
function isTooLong(obj, n, s){
	if(obj.value.length > n){
		alert(s);
		return false;
	}
	return true;
}

// checks whether file name, excluding path, exceeds max length
function isTooLongFile(obj, n, s){
var lastSlashLocation = obj.value.split(/\\|\//);
var fileName=lastSlashLocation[lastSlashLocation.length-1];
	if(fileName.length > n){
		alert(s);
		return false;
	}
	return true;
}

// checks whether text area exceeds max length
function isTooLongFormatted(obj, n, s){
contents = obj.value.replace(/<(.+?)>/g, '');//Don't count HTML tags 
contents = contents.replace(/&nbsp;/g, '');//Count nbsp; as one keystroke
contents = contents.replace(/\n/g, '');
contents = contents.replace(/\r/g, '');
contents = (contents.replace(/^\W+/,'')).replace(/\W+$/,'');

//alert(contents.length);
//alert(contents);
//alert(contents.charAt(119));
//alert(contents.charAt(120));
//alert(contents.charAt(121));
	if(contents.length-1 > n){
		alert(s);
		return false;
	}
	return true;
}

// checks whether item is checked
function isReqChecked(obj, s){
   var bolSelected = false;
    for (i=0;i<obj.length;i++){
          if(obj[i].checked){
                    bolSelected = true;
                    break;
          }
     }     
	if(!bolSelected){
		alert(s);
        obj[0].focus();
		return false;
	}
	return true;
}


//Select and focus on object.
function selfocobj(obj, str){
		alert(str);
		obj.select();
		obj.focus();
}


// Check whether string s is empty.
function isEmpty(s)
{  
	return ((s == null) || (s.length == 0)||s.charAt(0) == ' ')
}

// isEmail (STRING s [, BOOLEAN emptyOK])
function isEmail (obj, s) {   
	var reEmail = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

	if (isEmpty(obj.value) || !reEmail.test(obj.value)) {
	    selfocobj(obj, s)
		return false;
	  }
	return true;
}


// isImage (STRING s [, BOOLEAN emptyOK])
function isImage (obj, s) {   
	var reImage = /^\S+\.(gif|jpg)$/
	if (!isEmpty(obj.value) && !reImage.test(obj.value)) {
	    selfocobj(obj, s)
		return false;
	  }
	return true;
}


function checkMaxLength (textarea, evt, maxLength) {
  if (textarea.selected && evt.shiftKey) 
    // ignore shift click for select
    return true;
  var allowKey = false;
  if (textarea.selected && textarea.selectedLength > 0)
    allowKey = true;
  else {
    var keyCode = document.layers ? evt.which : evt.keyCode;
    if (keyCode < 47 && keyCode != 13)
      allowKey = true;
    else           
      allowKey = textarea.value.length < maxLength;
  }
  textarea.selected = false;
  return allowKey;
}
function updatecnt (textarea, evt, tracker, maxLength) {
  var keyCode = document.layers ? evt.which : evt.keyCode;
  tracker.value=textarea.value.length;
  if (tracker.value > maxLength)
  {
    if (keyCode < 47 && keyCode != 13)
{}
else {
  alert("Maximum character limit exceeded.  You will not be able to submit the form until the problem is corrected.");
}
  }
}
function storeSelection (field) {
  if (document.all) {
    field.selected = true;
    field.selectedLength = 
      field.createTextRange ?
        document.selection.createRange().text.length : 1;
  }
}


function unselect (field) {
	for (x = 0; x < field.options.length; x++) {
		if (field.options[x].value == "") {
			field.options[x].selected = false;
		}
	}
}

function checkDate(dayobj,monthobj,yearobj) {

	var myDayStr = dayobj.value;
	var myMonthStr = monthobj.value;
	var myYearStr = yearobj.value;
	var myDateStr = myDayStr + ' ' + myMonthStr + ' ' + myYearStr;

var myDateStr  = myMonthStr + '/' + myDayStr + '/' + myYearStr;

/* Using form values, create a new date object
which looks like "Wed Jan 1 00:00:00 EST 1975". */
var myDate = new Date( myDateStr );

var monthnum = myDate.getMonth()+1;

if ( monthnum != myMonthStr ) {
  alert( myDateStr + ' is NOT a valid date.' );
  dayobj.selectedIndex=0;
} 
 
}

function checkOrderDate(day1obj,month1obj,year1obj,day2obj,month2obj,year2obj,s) {

var startday = parseFloat(day1obj.value);
var startmonth = parseFloat(month1obj.value);
var startyear = parseFloat(year1obj.value);

var endday = parseFloat(day2obj.value);
var endmonth = parseFloat(month2obj.value);
var endyear = parseFloat(year2obj.value);

if (endyear < startyear) { alert(s); return false;}
else {
  if (endyear == startyear) { 
	  if (endmonth < startmonth){ alert(s); return false;}
	  else {
        if (endmonth == startmonth) { 
	  	  if (endday < startday){ alert(s); return false;}
		  else {return true;}
		}
		else {return true;}  
	  }
  }	  
  else {return true;}  
}
} 

function checkOrderTime(hour1obj,min1obj,ampm1obj,hour2obj,min2obj,ampm2obj,s) {

var starthour = parseFloat(hour1obj.value);
var startmin = parseFloat(min1obj.value);
var startampm = ampm1obj.value;

var endhour = parseFloat(hour2obj.value);
var endmin = parseFloat(min2obj.value);
var endampm = ampm2obj.value;

if (endampm=='AM' && startampm=='PM') { 
  if (endhour != 12)
  {alert(s); return false;}
  else {return true;}
  }
else {
   if (endampm == startampm) {
	  if (endhour < starthour){ if(starthour != 12) {alert(s); return false;} else {return true;}}
	  else {
        if (endhour == starthour) { 
	  	  if (endmin < startmin){ alert(s); return false;}
		  else {return true;}
		}
		else {return true;}  
	  }
	  }
   else {return true;}  
}
} 
 

