function isEmpty(s) {
	if (s == null || s == '') {
		return true;
	}else{
		return false;
	}
}

function isEmail(strValue) {
	regexp = /^([^$@\\ ]+)@((([^$@\\ \.]+)\.)+)([A-Za-z0-9]+)$/
	if (isEmpty(strValue)) {
		return false;
	}
	return regexp.test(strValue);
}

	var defaultEmptyOK = false;
	var daysInMonth = makeArray(12);
	daysInMonth[1] = 31;
	daysInMonth[2] = 29;
	daysInMonth[3] = 31;
	daysInMonth[4] = 30;
	daysInMonth[5] = 31;
	daysInMonth[6] = 30;
	daysInMonth[7] = 31;
	daysInMonth[8] = 31;
	daysInMonth[9] = 30;
	daysInMonth[10] = 31;
	daysInMonth[11] = 30;
	daysInMonth[12] = 31;

function makeArray(n){
   for (var i = 1; i <= n; i++) {
	  this[i] = 0
   }
   return this
}

function isEmpty(s){
	return ((s == null) || (s.length == 0))
}

function isNonnegativeInteger (s){   
	var secondArg = defaultEmptyOK;
	if (isNonnegativeInteger.arguments.length > 1)
		secondArg = isNonnegativeInteger.arguments[1];
	return (isSignedInteger(s, secondArg)
		 && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isIntegerInRange (s, a, b){
	if (isEmpty(s))
	   if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
	   else return (isIntegerInRange.arguments[1] == true);
	if (!isInteger(s, false)) return false;
	var num = parseInt (s);
	return ((num >= a) && (num <= b));
}

function isSignedInteger (s){
	if (isEmpty(s))
	   if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
	   else return (isSignedInteger.arguments[1] == true);
	else {
		var startPos = 0;
		var secondArg = defaultEmptyOK;
		if (isSignedInteger.arguments.length > 1)
			secondArg = isSignedInteger.arguments[1];
		if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
		   startPos = 1;
		return (isInteger(s.substring(startPos, s.length), secondArg))
	}
}

function isDigit (c){
	return ((c >= "0") && (c <= "9"))
}

function daysInFebruary (year){
	return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isDate (year, month, day){
	if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
	var intYear = parseInt(year);
	var intMonth = parseInt(month);
	var intDay = parseInt(day);
	if (intDay > daysInMonth[intMonth]) return false;
	if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
	return true;
}

function isYear (s){
	if (isEmpty(s))
	   if (isYear.arguments.length == 1) return defaultEmptyOK;
	   else return (isYear.arguments[1] == true);
	if (!isNonnegativeInteger(s)) return false;
	return ((s.length == 2) || (s.length == 4));
}

function isMonth (s){
	if (isEmpty(s))
	   if (isMonth.arguments.length == 1) return defaultEmptyOK;
	   else return (isMonth.arguments[1] == true);
	return isIntegerInRange (s, 1, 12);
}

function isDay (s){
	if (isEmpty(s))
	   if (isDay.arguments.length == 1) return defaultEmptyOK;
	   else return (isDay.arguments[1] == true);
	return isIntegerInRange (s, 1, 31);
}

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(Field) {
	strValue = getValue(Field);

	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) {
	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 isZipValue(strValue){
	if (strValue.indexOf('-') >=0 ) {
		regexp = /^\d{5}-\d{4}$/
	} else {
		regexp = /^\d{5}$/
	}
	return regexp.test(strValue);
}


function isPhoneValue(strValue){
	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 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 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 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 isBlank(s) {
	if (s == null || s == '') {
		return true;
	}else{
		return false;
	}
}

function isBlankField(Field) {
	fieldType = Field.type;
	
	if (fieldType == "text") {
		return isBlankText(Field);
	} else if (fieldType == "hidden") {
		return isBlankText(Field);
	} else if (fieldType == "file") {
		return isBlankText(Field);
	} else if (fieldType == "select-one") {
		return isBlankList(Field);
	} else if (fieldType == "textarea") {
		return isBlankText(Field);
	} else if (fieldType == "password") {
		return isBlankText(Field);
	} else if (fieldType == "checkbox") {
		return isBlankCheckbox(Field)
	} else if (fieldType == "radio") {
		return isBlankRadio(Field)
	} else if (isNaN(fieldType)) {
		return isBlankRadio(Field)
	} else {
		return isBlankText(Field);
	}
}

function isBlankCheckbox(Field) {
	return !Field.checked;
}

function isBlankRadio(Field) {
	found = false;

	if(isNaN(Field.length)) {
		return !Field.checked;
	}
	for(i=0; i< Field.length; i++) {
		if ( Field[i].checked ) {
			found = true;
			break;
		}
	}	
	return !found;
}

function isBlankList(Field) {
	return isBlank(Field[Field.selectedIndex].value);
}

function isBlankText(Field) {
	return isBlank(Field.value)
}

function switchPic(placeholder,imageObject){
	document.images[placeholder].src = eval(imageObject + ".src" );
}

var showLogin = 0;
var slideDelay = 20;
var objStyle = null;

function findObj(menuObj){
	if (document.getElementById){
		return (document.getElementById(menuObj).style);
	}else if(document.all){
		return (document.all[menuObj].style);
	}
}

function loginOpen(menuObj){
	objStyle = findObj(menuObj);
	if (showLogin){
		fX = -220; cX = 0; showLogin = 0;
	}else{
		fX = 0; cX = -220; showLogin = 1;
	}
	slideMenu(cX,fX);
}

function slideMenu(cX,fX){
	if (cX != fX){
		(cX > fX)? cX -= 10 : cX += 10;
		objStyle.top = cX;
		setTimeout('slideMenu(' + cX + ',' + fX + ')', slideDelay);  
	}
	return;
}

var seedDiv = "el1";
	
function switchMe(obj){
	switchDisplay(obj,seedDiv);
	seedDiv = obj;
}

function switchDisplay(obj,seedObj){
	visObj = findObj(obj);
	hidObj = findObj(seedObj);
	imgOnObj = document.getElementById(obj + 'I');
	imgOffObj = document.getElementById(seedObj + 'I');
	if(hidObj != null){
		hidObj.display = "none";
	}
	if(visObj != null){
		visObj.display = "block";
	}
	if(imgOnObj != null && imgOffObj != null){
		imgOffObj.src = eval(seedObj+"I_o.src");
		imgOnObj.src = eval(obj+"I.src");
	}
}

function getIndex(selectedValue, lookupArray){
	var outval=0
		for (ct=0; ct<lookupArray.length; ct++)
			if (lookupArray[ct]==selectedValue) 
				outval=ct
			return outval
}

function fillNeighborhoodCode(cmbBox,metroCd,lastValue){
	if(cmbBox.options){
		var metIdx = getIndex(metroCd,metroCodes)
		var nIdx = getIndex(lastValue,neighborhoodCodeValue[metIdx])
		cmbBox.length = 0
			for (i=0; i<neighborhoodCodeText[metIdx].length; i++)
				cmbBox.options[i] = new Option(neighborhoodCodeText[metIdx][i],neighborhoodCodeValue[metIdx][i])
				cmbBox.selectedIndex = nIdx
			}
}

function fillNeighborhoodCodeLoad(cmbBox,metroCd,lastValue){
	if(cmbBox.options){
		var isProfileNeighborhood = false
		var lastNeighborhood = document.lastValueForm.lastvalue.value
		var metIdx = getIndex(lastValue.options[lastValue.options.selectedIndex].value,metroCodes)
		cmbBox.length = 0
		for (i=0; i<neighborhoodCodeText[metIdx].length; i++)
			cmbBox.options[i] = new Option(neighborhoodCodeText[metIdx][i],neighborhoodCodeValue[metIdx][i])
			for (i=0;i<cmbBox.length;i++){
				if(lastNeighborhood==cmbBox.options[i].value){ 
					var nIdx = getIndex(lastNeighborhood,neighborhoodCodeValue[metIdx])
					isProfileNeighborhood = true
				}
		}
		if(!isProfileNeighborhood)
			var nIdx = getIndex(cmbBox.options[0].value,neighborhoodCodeValue[metIdx])
			cmbBox.selectedIndex = nIdx
		}
}

function getMetroIndex(selectedValue, lookupArray){
	var outval=0
	for (ct=0; ct<lookupArray.length; ct++){
		for (cl=0; cl<lookupArray[ct].length; cl++){
			if (lookupArray[ct][cl]==selectedValue)
				outval=ct
			}
	}
	return outval
}

function selectMetroCode(cmbBox,metroCd,lastValue){
	if(cmbBox.options){
		var lastNeighborhood = cmbBox.options[cmbBox.options.selectedIndex].value
		var metIdx = getMetroIndex(lastNeighborhood,neighborhoodCodeValue)
		if(!(lastValue.options[lastValue.options.selectedIndex].value==metroCodes[metIdx])){
			for(i=0;i<lastValue.length;i++){
				if(lastValue.options[i].value==metroCodes[metIdx])
					lastValue.selectedIndex=i
			}
		}
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkName() {
	document.frm.FILENAME.value = document.frm.UPLOAD_PHOTO.value
	len = document.frm.FILENAME.value.length;
	ext = document.frm.FILENAME.value.substring (len-3,len);
	ext.toLowerCase();
	if (isEmptyField(document.frm.FILENAME)) {
		alert("Please browse for uploading a .jpg or .gif file");
		return false;
	}
	return true;
}

function checkForm(theForm){
	if (isEmptyField(theForm.TITLE)) {
		alert ("Please enter the Title");
		theForm.TITLE.focus ();
		return false;
	}
	return true;
}

function NewWindow2(mypage,myname,w,h,scroll,resize,pos){
	if(pos=="random"){
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null){
		LeftPosition=0;TopPosition=20
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=yes,directories=no,status=yes,menubar=yes,toolbar=yes,resizable='+resize+'';
	win=window.open(mypage,myname,settings);
	if(win.focus){
		win.focus();
	}
}
function downloadAds(value){
	if(value.length > 0){
		NewWindow2(value,'ads','488','249','yes','yes','')
	}

}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}