function getIndex(arrayName, value) {
	for (var i=0; i < arrayName.length; i++) if(value == arrayName[i]) return i;
	return -1;
}

function getValue(Field) {
	fieldType = Field.type;

	if (fieldType == "text") {
		return getTextValue(Field);
	} else if (fieldType == "hidden") {
		return getTextValue(Field);
	} else if (fieldType == "select-one") {
		return getListValue(Field);
	} else if (fieldType == "textarea") {
		return getTextValue(Field);
	} else if (fieldType == "file") {
		return getTextValue(Field);
	} else if (fieldType == "password") {
		return getTextValue(Field);
	} else if (fieldType == "checkbox") {
		return getCheckboxValue(Field);
	} else if (isNaN(fieldType)) {
		return getRadioValue(Field);
	} else {
		return getTextValue(Field);
	}
}

function isEmptyField(Field) {
	fieldType = Field.type;

	if (fieldType == "text") {
		return isEmptyText(Field);
	} else if (fieldType == "hidden") {
		return isEmptyText(Field);
	} else if (fieldType == "file") {
		return isEmptyText(Field);
	} else if (fieldType == "select-one") {
		return isEmptyList(Field);
	} else if (fieldType == "textarea") {
		return isEmptyText(Field);
	} else if (fieldType == "password") {
		return isEmptyText(Field);
	} else if (fieldType == "checkbox") {
		return isEmptyCheckbox(Field)
	} else if (isNaN(fieldType)) {
		return isEmptyRadio(Field)
	} else {
		return isEmptyText(Field);
	}
}

function isCurrency(Field) {
	strValue = Field.value;

	regexp = /^(([0-9]{1,3}(\,[0-9]{3})*)|([0-9]{0,3}))(\.[0-9]{2})?$/

	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}


function isFloat(Field) {
	strValue = Field.value;

	regexp = /^(\+|\-)?([0-9]+)(((\.|\,)?([0-9]+))?)$/

	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isInteger(Field) {
	strValue = getValue(Field);

	regexp = /^(\+|\-)?([0-9]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isMemberUserName(Field) {
	strValue = getValue(Field);

	regexp = /^[^*]([^$@\\ ]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isUserName(Field) {
	strValue = getValue(Field);

	regexp = /^([^$@\\ ]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isCreditCardNumber(Field) {
	strValue = getValue(Field);

	if (isEmpty(strValue)) {
		return false;
	}

	if (strValue.indexOf('-') >=0 ) {
		regexp = /^\d{4}-\d{4}-\d{4}-\d{4}$/
	} else {
		regexp = /^\d{16}$/
	}
	return regexp.test(strValue);
}	


function isEmail(strValue) {
	regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

function isURL(Field) {
	strValue = getValue(Field);

	regexp = /^http(s?):\/\/([^$@\\ ]+)$/i
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}	

function isEmailList(Field) {
	strValue = getValue(Field);

	// delete all spaces near comma
	rexp = /, /gi;
	strValue = strValue.replace(rexp, ',');
	rexp = / ,/gi;
	strValue = strValue.replace(rexp, ',');
	strArray = strValue.split(",");

	regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/

	for (i=0; i < strArray.length; i++) {
		if (isEmpty(strArray[i])) return false;
		if (!regexp.test(strArray[i])) return false;
	}
	// set new field value (with removed spaces between comma and addresses)
	Field.value = strValue;
	return true;
}	

function isEmptyCheckbox(Field) {
	return !Field.checked;
}

function isEmptyRadio(Field) {
	found = false;
	for(i=0; i< Field.length; i++) {
		if ( Field[i].checked ) {
			found = true;
			break;
		}
	}	
	return !found;
}

function getListValue(Field) {
	return Field[Field.selectedIndex].value;
}

function getTextValue(Field) {
	return Field.value;
}

function getCheckboxValue(Field) {

	if (Field.checked) return Field.value;
	return '';
}

function getRadioValue(Field) {
        alert("inside getradiovalue");
	found = false;
	for(i=0; i< Field.length; i++) {
		if ( Field[i].checked ) {
			return Field[i].value;
			break;
		}
	}	
	return !found;
}

function isZip(Field) {
	strValue = getValue(Field);

	if (isEmpty(strValue)) {
		return false;
	}

	if (strValue.indexOf('-') >=0 ) {
		regexp = /^\d{5}-\d{4}$/
	} else {
		regexp = /^\d{5}$/
	}

	return regexp.test(strValue);
}

function isPhone(Field) {
	strValue = getValue(Field);

	regexp = /^\d{3}-\d{3}-\d{4}$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

function isFax(Field) {
	strValue = getValue(Field);

	regexp = /^\d{3}-\d{3}-\d{4}$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

function isEmptyList(Field) {
	return isEmpty(Field[Field.selectedIndex].value);
}

function isEmptyText(Field) {
	return isEmpty(Field.value)
}

function isEmpty(s) {
	if (s == null || s == '') {
		return true;
	}else{
		return false;
	}
}

function convertYear(y) {
	var borderYEAR = 40;

	yearvalue = parseInt(y,10);
	if (isNaN(yearvalue)) return y;

	if (yearvalue - borderYEAR <= 0) {
		yearvalue = yearvalue + 2000
	} else if (yearvalue - 100 < 0) {
		yearvalue = yearvalue + 1900
	}

	return yearvalue;
}

function CheckTime(hh,mm,ampm) {
	if (isNaN(parseInt(hh,10))) return false;
	if (isNaN(parseInt(mm,10))) return false;
	if (isEmpty(ampm)) return false;

	hh = parseInt(hh,10);
	mm = parseInt(mm,10);
	
	if (ampm == 'PM' && hh > 12) return false;
	return true;
}

function isLeapYear(Year)
{
	if(Math.round(Year/4) == Year/4){
		if(Math.round(Year/100) == Year/100){
			if(Math.round(Year/400) == Year/400)
				return true;
			else return false;
		}else return true;
	}
	return false;
}

function trim(str) {
	while (str.substring(0,1) == " ") {
		str = str.substring(1,str.length);
	}
	while (str.substring(str.length-1,str.length) == " ") {
		str = str.substring(0,str.length-1);
	}
	return str;
}

function CheckMonthYear(m,y){
  if (isNaN(parseInt(m,10))) return false;
  if (isNaN(parseInt(y,10))) return false;

  y = parseInt(y,10);
  m = parseInt(m,10);
  y = convertYear(y);

  if (y <= 1900 ){
    return false;

  }else{ 
    if (m < 1 || m > 12 ){
      return false;
    }else{
      return true;
    }

  }

}

function CheckDate(m,d,y) {
	Months = "31/!/28/!/31/!/30/!/31/!/30/!/31/!/31/!/30/!/31/!/30/!/31";
	MonthArray  = Months.split("/!/");

	if (isNaN(parseInt(m,10))) return false;
	if (isNaN(parseInt(d,10))) return false;
	if (isNaN(parseInt(y,10))) return false;

	d = parseInt(d,10);
	y = parseInt(y,10);
	m = parseInt(m,10);

	y = convertYear(y);

	if (y <= 1900 ) return false;
	if (m < 1 || m > 12 ) return false;
	if ( isLeapYear(y)) MonthArray[1] = eval(eval(MonthArray[1]) + 1);

	if (d<1 || MonthArray[m-1] < d ) return false;
	return true;
}

function isShort(elm){
	var elmstr = elm.value+"";
	if (elmstr.length <=4) return true;
	else return false;
}

function checkType(elm){
	var elmstr = elm;
	if (elm.options[0].selected==true){
	return true;}
	else return false;
} 

function checkType1(elm){
	var elmstr = elm;
	if (elm.options[1].selected==true){
	return true;}
	else return false;
} 
function checkType2(elm){
	var elmstr = elm;
	if (elm.options[2].selected==true){
	return true;}
	else return false;
}
function checkType3(elm){
	var elmstr = elm;
	if (elm.options[3].selected==true){
	return true;}
	else return false;
} 
function checkType4(elm){
	var elmstr = elm;
	if (elm.options[4].selected==true){
	return true;}
	else return false;
} 