// JavaScript Document
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}function isNumeric (s)
{   
s = trim(s);
var i;

   if (!isEmpty(s)) {

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);
		
        if (! ( isDigit(c) ) )
          return false;
    }

    // All characters are numbers or letters.
    return true;
	}else return true;
}

function trim ( s ) {
fixedTrim = "";
lastCh = " ";
for (x=0; x < s.length; x++) {
ch = s.charAt(x);
if ((ch != " ") || (lastCh != " ")) { fixedTrim += ch; }
lastCh = ch;
}
if (fixedTrim.charAt(fixedTrim.length - 1) == " ") {
fixedTrim = fixedTrim.substring(0, fixedTrim.length - 1); }
s = fixedTrim
return s
}
function isAlphanumeric (s)

{   
s = trim(s);
var i;

   if (!isEmpty(s)) {

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
	}
}
function Currency(anynum) {
        //returns number as string in $xxx,xxx.xx format.
        anynum = "" + eval(anynum)  //evaluate (in case an expression sent)
        intnum = parseInt(anynum)  //isolate integer portion
        intnum = Math.abs(intnum)
        intstr = ""+intnum
        //add comma in thousands place.
        if (intnum >= 1000) {
                intlen = intstr.length
                temp1=parseInt(""+(intnum/1000))
                temp2=intstr.substring(intlen-3,intlen)
                intstr = temp1+","+temp2

        }
        if (intnum >= 1000000) {
                intlen = intstr.length
                temp1=parseInt(""+(intnum/1000000))
                temp2=intstr.substring(intlen-7,intlen)
                intstr = temp1+","+temp2
        }
        return "$"+intstr
}
function viewmls()
	{
			document.searchmls.action = "listings.asp?mls="+mlsname.value;
			document.searchmls.submit();
	}
	
	
window.onerror=null

bState = true

oReq = new Collection("AMOUNT","RATE","","","","")

oVal = new Collection("AMOUNT","RATE","","","","")

oTst = new Collection("N","N","","","","")


function controller(oForm, oBtn) {

   while (bState) {

      if (!Required(oForm))

         break

      if (!Validate(oForm))

         break

      if (!SetValue(oForm))

         break

     if (!NewPage(oForm, oBtn))

         break

      if (bState) {

          bState = false

      }

   }

   bState = true

}

function Required(oView) {

   for (i in oView) {

      for (j in oReq) {

        if (i==oReq[j]) {      

           if (isMissing(oView[i])) {

               return(false)

           }

        }

     }

  }

  return(true)

}

function Validate(oView) {

   for (i in oView) {

      for (j in oVal) {

        if (i==oVal[j] && oTst[j]=="N") {      

           if (isTest(oView[i], oTst[j])) {

               return(false)

           }

        }

     }

  }

  return(true)

}

function SetValue(oView) {

   Mortgage = new Loan(oView.AMOUNT.value, oView.RATE.value, get_selection(oView.YEARS), 0, 0, get_selection(oView.FREQUENCY), 0 )

   Mortgage.calcPeriods()

   Mortgage.calcPayment()

   Mortgage.calcInterest()

   oView.PAYMENT.value = calcRound(Mortgage.Payment)

   oView.INTEREST.value = calcRound(Mortgage.Interest)

   setCookie("_Prin", Mortgage.Amount)

   setCookie("_Int", Mortgage.Rate)

   setCookie("_Year", Mortgage.Term)

   setCookie("_Tot", Mortgage.Interest)

   return(true)

}



function isMissing(oCtrl) {

   if (oCtrl.value == "") {  

      alert("You have left a required value blank. Please type a number") 

      oCtrl.focus()

      oCtrl.select()

      return(true)

      }

   else

      { 

      return(false)

   }

}

function isTest(oCtrl, oTest) {

   if (oTest=="N" && !isNumber(oCtrl.value) ) {

      alert(oCtrl.value+" contains an invalid character. Please type a number") 

      oCtrl.focus()

      oCtrl.select()

      return(true)

      }

      else

      { 

      return(false)

   }

}

function isNumber(input) {

   for (var i=0;i<input.length;i++) {

       var oneChar = input.substring(i, i+1)

       if (oneChar < "0" || oneChar > "9") {

          if (oneChar != "." ) { 

             return(false)

          }

       }

   }

   return(true)

}



function Collection(item1, item2, item3, item4, item5, item6) {

   this.item1 = item1

   this.item2 = item2

   this.item3 = item3

   this.item4 = item4

   this.item5 = item5

   this.item6 = item6

}

function Loan(Amount, Rate, Term, Payment, Interest, Frequency, Periods ) {

   this.Amount = Amount

   this.Rate = Rate

   this.Term = Term

   this.Payment = Payment

   this.Interest = Interest

   this.Frequency = Frequency

   this.Periods = Periods

   this.calcPeriods = calcPeriods

   this.calcPayment = calcPayment

   this.calcInterest = calcInterest

}

function calcPayment() {

   this.Payment = (this.Amount*((this.Rate/(this.Periods*100))/(1-(Math.pow(1+(this.Rate/(this.Periods*100)),((this.Term*this.Periods)*-1))))))

}

function calcInterest() {

   this.Interest = ((this.Payment*(this.Term*this.Periods))-this.Amount)

}

function calcPeriods() {

   if (this.Frequency=="Monthly") { this.Periods=12 } else { this.Periods=26 }

}

function calcRound(num) {

   result="$"+Math.floor(num)+"." 

   n = result.length

   if (num>1000 && num<999999) {  

     result="$"+result.substring(1,n-4)+","+result.substring(n-4,n)

   }

   if (num>1000000) {  

     result = "$"+result.substring(1,n-7)+","+result.substring(n-7,n-4)+","+result.substring(n-4,n)

   }

   var cents=100*(num-Math.floor(num))+0.5

   result += Math.floor(cents/10)

   result += Math.floor(cents%10)

   return(result)

}



function select_item(name, value) {  

   this.name = name  

   this.value = value

}

function get_selection(select_object) {   

   contents = new select_item()

   for(var i=0;i<select_object.options.length;i++)

      if(select_object.options[i].selected == true) {

        contents.name = select_object.options[i].text

        contents.value = select_object.options[i].value

      }      

   return(contents.name)

}

function setCookie (name, value ) {

  document.cookie = name + "=" + escape (value) + "; path=/"; 

}   

function NewPage(oForm, oBtn) {

   if (oBtn.name == "cmdCalc") {

      return(false)

    }

   if (confirm("An Amortization Table calculates the periodic payment breakdown for each specific category listed.")) {

      text = ("<HEAD><TITLE>Amortization Table</TITLE></HEAD>");

      text = (text +"<BODY BGCOLOR =  '#FFFFFF'><BR><BR>");

      text = (text +"<H2 ALIGN=CENTER><FONT COLOR=PURPLE>Amortization Table</FONT></H2>");

      text = (text +"<UL><FONT SIZE=-1>The following table is based on the information entered in the calculator form.</FONT></UL>");

      text = (text +"<UL><FONT SIZE=+1 COLOR=PURPLE>Mortgage Amount: </FONT>" +calcRound(Mortgage.Amount));

      text = (text +"<BR><FONT SIZE=+1 COLOR=PURPLE>  Interest Rate: </FONT>" + Mortgage.Rate + " %");

      text = (text +"<BR><FONT SIZE=+1 COLOR=PURPLE>Mortgage Length: </FONT>" +get_selection(oForm.YEARS) + " Years </UL>");

      text = (text +"<BR><CENTER><table border='1' width='100%'>");

      text = (text +"<TR><TD ALIGN=CENTER BGCOLOR=PURPLE><FONT COLOR=WHITE><B>Year</B></FONT></TD><TD ALIGN=RIGHT BGCOLOR=PURPLE><FONT COLOR=WHITE><B>Interest&nbsp;</B></FONT></TD><TD ALIGN=RIGHT BGCOLOR=PURPLE><FONT COLOR=WHITE><B>Principal&nbsp;</B></FONT></TD><TD ALIGN=RIGHT BGCOLOR=PURPLE><FONT COLOR=WHITE><B>Balance&nbsp;</B></FONT></TD></TR>\n");

      makeTable(oForm)

      text = (text +"</TABLE></CENTER>");

      msgWindow=window.open("","displayWindow","toolbar=no,width=500,height=300,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")

      msgWindow.document.write(text)

      msgWindow.document.close()

      return(true)

    }

  return(false)

}



function makeTable(oView) {

   var currInt = 0

   var currPrin = 0

   prevBalance = Mortgage.Amount

   InterestRate = ( Mortgage.Rate /100) / Mortgage.Periods

   MonthlyPayment = Mortgage.Payment

   currStart = get_selection(oView.START)

   for(i=1;i<=30;i++) {

      for(j=1;j<=Mortgage.Periods;j++) {

         periodInt = prevBalance * InterestRate

         periodPrin = MonthlyPayment - periodInt

         currBal = prevBalance - periodPrin

         currInt += periodInt

         currPrin += periodPrin

         prevBalance = currBal

      }

      if( currBal <= 0 ){ 

         currBal = 0

      }


      text = (text +"<TR><TD ALIGN=CENTER>"+ currStart +"</TD><TD ALIGN=RIGHT>"+ calcRound(currInt) +"&nbsp;</TD><TD ALIGN=RIGHT>"+ calcRound(currPrin) +"&nbsp;</TD><TD ALIGN=RIGHT>"+ calcRound(currBal)+"&nbsp;</TD></TR>");

      currInt = 0

      currPrin = 0

      currStart = parseInt(currStart)

      currStart += 1

      if(currBal<=0) {

         return(true)

      }       

   }

   return (true)

}



function setfocus() {   

   document.MORTGAGE.AMOUNT.focus()

   document.MORTGAGE.AMOUNT.select()

}

// unhide 

// -->

	var stickynote = 0;
	function changeImage(imageURL,title)
		{
		document.big_image.src = imageURL;
		document.image_form.image_title.value = title;
		}
	function doPopUpImage(imageURL,idc,notes)
		{
			var new_url = 'showimage.asp?';
			var imageURL ='imageURL='+imageURL;
			var idc ='&idc='+idc;
			var notes ='&notes='+notes;
			var new_name = 'imageLg';
			var fullurl = new_url+imageURL+idc+notes;
			var new_width = 320;
			var new_height = 320;
			var new_top = 50;
			var new_left = (screen.width / 2) - (new_width / 2);
			var win_look = ', resizable=yes, menubar=no, directories=no, status=no, location=no, toolbar=no, scrollbars=no';
			var win_size = 'left=' + new_left + ', top=' + new_top + ', width=' + new_width + ', height=' + new_height;
			var features = win_size + win_look;
			window.open(fullurl, new_name , features);
		}
	//-->
function validateannounce(obj)
	{
		if(obj.title.value == "")
		{
			alert("Title cannot be null");
			obj.title.focus();
			return false;
		}
		if(obj.summery.value == "" && obj.announcebody.value == "")
		{
			alert("Please enter summery or body in announcements");
			obj.summery.focus();
			return false;
		}
		return true;
	}
function validatereal(obj)
	{
		if(obj.linktitle.value == "")
		{
			alert("Title cannot be null");
			obj.linktitle.focus();
			return false;	
		}
		if(obj.shortdesc.value == "")
		{
			alert("Short description cannot be null");
			obj.shortdesc.focus();
			return false;
		}
	}
//Add Image Function
function addImage(s,lid)
{
	var newName = 'addImage';
	var newUrl = 'addImage.asp?';
	var secret='s='+s;
	var lid = '&lid='+lid;
	//var mls = '&mls=' + mls;
	//var idc = '&idc=' + idc;
	var fullUrl = newUrl + secret + lid;
	var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
	window.open(fullUrl, newName, features );
}
//Update Image Function
function updImage(s,lid){
var newName = 'updImage';
var newUrl = 'updImage.asp?';
var secret='s='+s;
var lid ='&lid='+lid;
//var cur_image ='&curimage='+curimage;
//var mlsstr ='&mls='+ mls; 
//var idc = '&idc='+ idc;
var fullUrl = newUrl + secret + lid;
var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
window.open(fullUrl, newName, features );
}
//Delete Image Function
function deleteImage(s,lid){
	var conf = confirm("Are you sure do you want to delete this main image?");
	if(conf)
	{
		var newName = 'deleteImage';
		var newUrl = 'deleteImage.asp?';
		var secret='s='+s;
		var listingid ='&lid='+lid;
		//var cur_image ='&curimage='+curimage;
		//var mlsstr ='&mls='+ mls; 
		//var idc = '&idc='+ idc;
		var fullUrl = newUrl + secret + listingid ;
		var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
		window.open(fullUrl, newName, features );
	}
}
//Update Thumb Function
function updThumb(s,lid,photonum,alttagnum){
var newName = 'updThumb';
var newUrl='updThumb.asp?';
var secret='s='+s;
var listingid ='&lid='+lid;
var photo_num='&photonum='+photonum;
var alttagnum='&alttagnum='+alttagnum;
//var cur_image='&curimage='+curimage;
//var mlsstr ='&mls='+ mls; 
//var idc = '&idc='+ idc; 
var fullUrl = newUrl + secret + listingid + photo_num + alttagnum;
var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
window.open(fullUrl, newName, features );
}
//Delete Thumb Function
function deleteThumb(s,lid,photonum,alttagnum){
	var conf = confirm("Are you sure do you want to delete this thumb image?");
	if(conf)
	{
		var newName = 'deleteThumb';
		var newUrl = 'deleteThumb.asp?';
		var secret='s='+s;
		var lid ='&lid='+lid;
		var photonum = '&photonum='+photonum;
		var alttagnum='&alttagnum='+alttagnum;
		//var cur_image ='&curimage='+curimage;
		//var mlsstr ='&mls='+ mls; 
		//var idc = '&idc='+ idc;
		var fullUrl = newUrl + secret + lid + photonum + alttagnum;
		var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
		window.open(fullUrl, newName, features );
		window.reload()
	}
}
//Add Thumb Function
function addThumb(s,lid,photonum,alttagnum){
	var newName = 'updThumb';
	var newUrl='addThumb.asp?';
	var secret='s='+s;
	var listingid ='&lid='+lid;
	var photo_num='&photonum='+photonum;
	var alttagnum='&alttagnum='+alttagnum;
	//var cur_image='&curimage='+curimage;
	//var mls ='&mls='+ mls; 
	//var idc = '&idc='+ idc ;
	var fullUrl = newUrl+secret+listingid+photo_num+alttagnum;
	var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
	window.open(fullUrl, newName, features );
}

//function submitForm(){
	//document.forms.updateListing.submit();
//}
//View Image In New Window 
function openImage(listingImg,idc){
	 var new_url = 'listingImg.asp?';
	 var listingImg ='listingImg='+listingImg;
	 var idc ='&idc='+idc;
	 var fullurl = new_url+listingImg+idc;
	 var new_name = 'ListingLg';
	// var wHeight = (NS)?window.innerHeight:document.body.clientHeight; 	 
	 //var iHeight = listingImg.height + 40;
	 //var wWidth = (NS)?window.innerWidth:document.body.clientWidth;
	 var new_width = 320;
	 var new_height = 75;
	 var new_top = 50;
	 var new_left = (screen.width / 2) - (new_width / 2);
	 var win_look = ', resizable=yes, menubar=no, directories=no, status=no, location=no, toolbar=no, scrollbars=no';
	 var win_size = 'left=' + new_left + ', top=' + new_top + ', width=' + new_width + ', height=' + new_height;
	 var features = win_size + win_look;
	 window.open(fullurl, new_name, features );
}
//View Agent Image In New Window
function openagentImage(agentImg,idc){
	 var new_url = 'agentImg.asp?';
	 var agentImg ='agentImg='+agentImg;
	 var idc ='&idc='+idc;
	 var fullurl = new_url+agentImg+idc;
	 var new_name = 'AgentLg';
	// var wHeight = (NS)?window.innerHeight:document.body.clientHeight; 	 
	 //var iHeight = listingImg.height + 40;
	 //var wWidth = (NS)?window.innerWidth:document.body.clientWidth;
	 var new_width = 120;
	 var new_height = 50;
	 var new_top = 50;
	 var new_left = (screen.width / 2) - (new_width / 2);
	 var win_look = ', resizable=yes, menubar=no, directories=no, status=no, location=no, toolbar=no, scrollbars=no';
	 var win_size = 'left=' + new_left + ', top=' + new_top + ', width=' + new_width + ', height=' + new_height;
	 var features = win_size + win_look;
	 window.open(fullurl, new_name, features );
}
//Add Agent Image Function
function addagentImage(s,aid,idc){
	var newName = 'addagentImage';
	var newUrl = 'addagentImage.asp?';
	var secret='s='+s;
	var aid = '&aid=' + aid;
	var idc = '&idc=' + idc;
	var fullUrl = newUrl + secret + aid + idc ;
	var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
		window.open(fullUrl, newName, features );
}
//Update Agent Image Function
function updagentImage(s,aid,curimage,idc){
var newName = 'updagentImage';
var newUrl = 'updagentImage.asp?';
var secret = 's='+s;
var aid='&aid='+aid;
var cur_image ='&curimage='+curimage;
var idc = '&idc='+ idc;
var fullUrl = newUrl + secret + aid + cur_image + idc;
var features = 'left=150, top=150, width=400, height=200, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
window.open(fullUrl, newName, features );
}
//Delete Agent Image Function
function deleteagentImage(s,aid,curimage,idc){
	var conf = confirm("Are you sure do You want to delete this main image?");
	if(conf)
	{
		var newName = 'deleteagentImage';
		var newUrl = 'deleteagentImage.asp?';
		var secret='s='+s;
		var aid = '&aid='+aid;
		var cur_image ='&curimage='+curimage;
		var idc = '&idc='+ idc;
		var fullUrl = newUrl + secret + aid + cur_image  + idc;
		var features = 'left=150, top=150, width=400, height=240, resizable=no, menubar=no, directories=no, status=no, location=no, toolbar=no'
		window.open(fullUrl, newName, features );
	}
}
var NS = (navigator.appName=="Netscape") ? true:false; 
	
function fitPic() 
	{ 
		
		wHeight = (NS)?window.innerHeight:document.body.clientHeight; 
		iHeight = document.images[0].height + 40;
		wWidth = (NS)?window.innerWidth:document.body.clientWidth; 

		window.resizeTo(wWidth, iHeight); 

		self.focus(); 
	}; 
//Validation For Agency Information 
function validateagency(obj)
	{
		if(obj.agencyName.value == "")
		{
			alert("Please Enter Agency Name");
			obj.agencyName.focus();
			return false;
		}
		if(obj.agencyAddress.value == "" && obj.agencyAddress2.value == "" )	
		{
			alert("Please enter your address");
			obj.agencyAddress.focus();
			return false;
		}
		if(obj.city.value == "")	
		{
			alert("Please enter your city");
			obj.city.focus();
			return false;
		}
		if(obj.zip.value == "")	
		{
			alert("Please enter your zipcode");
			obj.zip.focus();
			return false;
		}
		else if(/(^-?\d\d*$)/.test(obj.zip.value))
		{
			return true;
		}
		else
		{
			alert("Please enter numeric value");
			obj.zip.focus();
			return false;
		}
		if(obj.mainEmail.value == "")
		{	
			alert("Please enter your email address");
			obj.mainEmail.focus();
			return false;
		}
		else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.mainEmail.value))
		{
			return true;
		}
		else
		{
			alert("Invalid e-mail address! Please re-enter.");
			obj.mainEmail.focus();
			return false;
		}
		return true;
	}
//Validation For property Listing Information 
function validatelist(obj)
	{
		if(obj.propertyName.value == "")
		{
			alert("Please enter a Property Name");
			obj.propertyName.focus();
			return false;
		}
		if(obj.city.value == "")
		{
			alert("Please enter city name");
			obj.city.focus();
			return false;
		}
		if(obj.price.value == "")
		{
			alert("Please enter a price");
			obj.price.focus();
			return false;
		}
		return true;
	}
//Validation For property Listing Information 
function validatefeatured()
{
	// set var checkbox_choices to zero
	var checkbox_choices = 0;
	
	// Loop from zero to the one minus the number of checkbox button selections
	for (counter = 0; counter < updateFeatured.indexdisplay.length; counter++)
	{
	
		// If a checkbox has been selected it will return true
		// (If not it will return false)
		if (updateFeatured.indexdisplay[counter].checked)
		{ 
			checkbox_choices = checkbox_choices + 1; 
		}
	
	}
	
	if (checkbox_choices > 5 )
	{
		// If there were more than three selections made display an alert box
		msg="You're limited to only three selections.\n"
		msg=msg + "You have made " + checkbox_choices + " selections.\n"
		msg=msg + "Please remove " + (checkbox_choices-5) + " selection(s)."
		alert(msg)
		return (false);
	}
	
	return (true);
}
// Validation For Agent Information 
function validateagent(obj)
 	{
		if(obj.firstName.value == "")
		{	
			alert("Please enter your first name");
			obj.firstName.focus();
			return false;			
		}
		if(obj.lastName.value == "")
		{
			alert("Please enter your last Name");
			obj.lastName.focus();
			return false;
		}	
		if(obj.userName.value == "")
		{
			alert("Please enter your username");
			obj.userName.focus();
			return false;
		}	
		if(obj.notes.value == "")
		{
			alert("Please enter your notes");
			obj.notes.focus();
			return false;
		}
		if(obj.emailAddress.value == "")
		{	
			alert("Please enter your email address");
			obj.emailAddress.focus();
			return false;
		}
		else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value))
		{
			return true;
		}
		else
		{
			alert("Invalid e-mail address! please re-enter.");
			obj.emailAddress.focus();
			return false;
		}
	return true;
	}
//Validate ThumbNail Image
/*function uploadthumb(obj)
	{
		if(obj.mainphoto.value == "" ) 
		{	
			alert("Please select thumb image");
			obj.mainphoto.focus();
			return false;
		}
		return true;
	}*/
//Delete Listing Function	
function deletelisting()
	{
		var msg = 'Are you sure you want to delete this listing?';
		if(confirm(msg))
		{
			document.form_deletelisting.submit();
		}
	}
function searchform(pageid)
	{
		if(!pageid == "") 
		{
			document.searchform.action = "Editlistings.asp?pageID="+pageid;
			document.searchform.submit();
		}			
	}
function deletelisting(s,mls,idc,agencyType)
	{
		var msg = 'Are you sure you want to delete this listing?';
		if (confirm(msg))
		{
			var newurl = 'deletelisting.asp?';
			var secret ='s='+s;
			var mls ='&mls='+mls;
			var idc ='&idc='+idc;
			var fullurl = newurl + secret + mls + idc;
			window.open(fullurl,"_self");
			//window.location = '<%= deleteAgent %>';
		}
	}
// JavaScript Document
function viewaccount()
{
	window.open("myAccount.asp?action=newuser","_self");
}
function searchform(pageid)
	{
		if(!pageid == "") 
		{
			location.href= "listings.asp?pageID="+pageid;
		}			
	}
function viewlisting(sid)
	{
			window.open("listings.asp?lid=" +sid.value, "_self");
	}
function viewlisting1(sid)
	{
		if(sid != "")
		{
			window.open("listings.asp?aid=" +sid, "_self");
		}
	}

//Validation for mls number	
function validatemls(obj)
	{
			if(obj.mlsname.value == "")
			{
				alert("Please enter MLS number");
				obj.mlsname.focus();
				return false;
			}
	}	
//Validation for listing number	
function validatelis(obj)
	{
			if(obj.lisnumber.value == "")
			{
				alert("Please enter listing number");
				obj.lisnumber.focus();
				return false;
			}
	}	
	
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;

	function isInteger(s)
	{
		var i;
		for (i = 0; i < s.length; i++)
		{   
        	// Check that current character is number.
	        var c = s.charAt(i);
    	    if (((c < "0") || (c > "9"))) return false;
	    }
    	// All characters are numbers.
	    return true;
	}

	function stripCharsInBag(s, bag)
	{
		var i;
	    var returnString = "";
    	// Search through string's characters one by one.
	    // If character is not in bag, append to returnString.
    	for (i = 0; i < s.length; i++)
		{   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year)
	{
		// February has 29 days in any year evenly divisible by four,
	    // EXCEPT for centurial years which are not also divisible by 400.
    	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}
function DaysArray(n) 
	{
		for (var i = 1; i <= n; i++) 
		{
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
			if (i==2) {this[i] = 29}
	   } 
	   return this
	}

function isDate(dtStr)
	{
		var thedate = new Date( );
		var theyear = thedate.getFullYear( );
		var themonth = thedate.getMonth( ) + 1;
		var theday = thedate.getDate( );
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) 
		{
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
			month=parseInt(strMonth)
			day=parseInt(strDay)
			year=parseInt(strYr)
		//return false;
		if (pos1==-1 || pos2==-1)
		{
			alert("The date format should be : mm/dd/yyyy")
			return false
		}
	if (strMonth.length<1 || month<1 || month>12)
	{
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
	{
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		alert("Please enter a valid date")
		return false
	}
	if(day < theday && month < themonth && year < theyear)
	{
		alert("Please enter a valid date");
		return false;
	}
	if(day < theday && month >= themonth && year >= theyear)
	{
		alert("Please enter a valid date");
		return false;
	}
	if(day >= theday && month < themonth &&  year >= theyear)
	{
		alert("Please enter a valid date");
		return false;
	}
	if(day >= theday && month >= themonth && year < theyear)
	{
		alert("Please enter a valid date");
		return false;
	}
return true
}

 function validateopen(obj)
		{
			var dt=obj.openhousedate.value
			if (isDate(dt)==false)
			{
				obj.openhousedate.focus();
				return false;
			}

		if(obj.openhousetime.value == "")
		{
			alert("Please enter open house time");
			obj.openhousetime.focus();
			return false;			
		}
		if(obj.openhousecomment.value == "")
		{
			alert("Please enter open house comment");
			obj.openhousecomment.focus();
			return false;			
		}
		return true;
	}
function validatecommunity(obj)
	{
		if(obj.commtitle.value == "")
		{
			alert("Title cannot be null");
			obj.commtitle.focus();
			return false;
		}
		
		/*re = /^(file|http):\/\/\S+\.(com|net|org|info|biz|ws|us|tv|cc)$/i
		 if (re.test(obj.commurl.value)) 
		 {
			 return true
		 }
		 else 
		 {
			 alert ("The URL you entered is not valid")
			 return false
		 }*/
		if(obj.commdesc.value == "")
		{
			alert("Description cannot be null");
			obj.commdesc.focus();
			return false;
		}
	return true;			
	}
function validateservice(obj)
	{
		if(obj.serviceid.value == "")
		{
			alert("Service name cannot be null");
			obj.serviceid.focus();
			return false;
		}
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailAddress.value))
		{
			return true;
		}
		else
		{
			alert("Invalid e-mail address! Please re-enter.");
			obj.emailAddress.focus();
			return false;
		}
		return true;
	}	
function validateterm(obj)
	{
		//var term = obj.searchterm.value;
		if(!obj.termname.value == "") 
		{
			//window.open("alpha.asp?termname="+obj.term.value,"_self");
			document.glossaryform.action = "searchglossary.asp?termname="+obj.termname.value;
			//document.glossaryform.submit();
		}			
	}
function validateaboutus(obj)
	{
		if(obj.aboutusdesc.value == "")
		{
			alert("About us description cannot be null");
			obj.aboutusdesc.focus();
			return false;
		}
		return true;
	}
function validateaboutus(obj)	
	{
		if(obj.membername.value == "")
		{
			alert("Please enter your team member name");
			obj.membername.value;
			return false;
		}
		if(obj.memberposition.value == "")
		{
			alert("Please enter your team member position");
			obj.memberposition.value;
			return false;
		}
		if(obj.memberphone.value == "")
		{
			alert("Please enter your team member phone number");
			obj.memberphone.value;
			return false;
		}
		if(obj.memberemail.value == "")
		{	
			alert("Please enter your email address");
			obj.memberemail.focus();
			return false;
		}
		else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.memberemail.value))
		{
			return true;
		}
		else
		{
			alert("Invalid e-mail address! Please re-enter.");
			obj.memberemail.focus();
			return false;
		}
		if(obj.memberdesc.value == "")
		{
			alert("Please enter your team member description");
			obj.memberdesc.value;
			return false;
		}
	}
function validatetestimonial(obj)
	{
		if(obj.testimonialname.value == "")
		{
			alert("Please enter the name of testimonial");
			obj.testimonialname.focus();
			return false;
		}
		if(obj.testimonialcity.value == "")
		{
			alert("Please enter city name");
			obj.testimonialcity.focus();
			return false;
		}
		if(obj.testimonialnamedesc.value == "")
		{
			alert("Please enter the a description");
			obj.testimonialdesc.focus();
			return false;
		}
		return true;
	}
function validatecontactinfo(obj)	
	{
		if(obj.confirstname.value == "" )
		{
			alert("Please enter your first name");
			obj.confirstname.focus();
			return false;
		}
		if(obj.conlastname.value == "" )
		{
			alert("Please enter your last name");
			obj.conlastname.focus();
			return false;
		}
		if(obj.condayphone.value == "" && obj.conevephone.value == "" && obj.conemail.value == "")
		{
			alert("Please enter your phone number or email address");
			return false;
		}
		if(obj.conemail.value == "")
		{	
			alert("Please enter your email address");
			obj.conemail.focus();
			return false;
		}
		else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.conemail.value))
		{
			return true;
		}
		else
		{
			alert("Invalid e-mail address! Please re-enter.");
			obj.conemail.focus();
			return false;
		}
		return true;
	}
function validateaddress(obj)
	{
		if(obj.companyname.value == "")
		{
			alert("Company name cannot be null");
			obj.companyname.focus();
			return false;		
		}
		if(obj.companyadd.value == "")
		{
			alert("Company address cannot be null");
			obj.companyadd.focus();
			return false;		
		}
		if(obj.companyzipcode.value == "")
		{
			alert("Company zipcode cannot be null");
			obj.companyzipcode.focus();
			return false;		
		}
		if(obj.emailaddress.value == "")
		{	
			alert("Please enter your email address");
			obj.emailaddress.focus();
			return false;
		}
		else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(obj.emailaddress.value))
		{
			return true;
		}
		else
		{
			alert("Invalid e-mail address! Please re-enter.");
			obj.emailaddress.focus();
			return false;
		}
		return true;
	}
	function searchform(pageid)
		{
			if(!pageid == "") 
			{
				document.searchform.action = "listings.asp?pageID="+pageid;
				document.searchform.submit();
			}			
		}
	function showMe(ctrlObj) {
		if (document.getElementById(ctrlObj).style.display == "none") {
			document.getElementById(ctrlObj).style.display = "block";
		}else{
			document.getElementById(ctrlObj).style.display = "none";
		}
	}	
