//(c) 2006-2007 XMLSEO.com, DREW RILEY

//ajax
function sendhitto(strURL,hitdata) {
//
   var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
               document.getElementById("response").innerHTML = self.xmlHttpReq.responseText;
				        }
    }
    self.xmlHttpReq.send(hitdata);
}



function ajaxlocate(strURL) {
	var s1 = document.getElementById("textstreet").value;
	var s2 = document.getElementById("textcity").value;
	var s3 = document.getElementById("textstate").value;

	var qs;
	qs = "street=" + s1 + "&city=" + s2 + "&state=" + s3;
	
sendhitto(strURL,qs);	

}





function smartpop() {
}

function getX() {

var oElement = document.getElementById("searchtext");
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
alert(iReturnValue);
}

function getY() {

var oElement = document.getElementById("searchtext");
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
alert(iReturnValue);
} 

function dosmartsearch() {
var res =  searchcode(document.getElementById("searchtext").value);
if (res != "") {
document.location.href="/search/" + res;
}
}

function dosmartsearchb() {
var res = searchcode(document.getElementById("searchtextb").value);
document.location.href="/search/" + res;

}
function entsub(event) {
 if (window.event && window.event.keyCode == 13)
    hitenter();
  else

	if (event && event.which == 13){

   	 hitenter();

	}

	//alert(event.which);
    return true;

}

function hitenter() {
var s2 = "";
var s1 = document.getElementById("searchtext").value;
	try {
		 s2 = document.getElementById("searchtextb").value;

	} catch(e) {
		s2 = "";
	} 

	if (s2 != "") {
	document.getElementById("searchtext").value = s2
	} 
	dosmartsearch()
	




}


function searchcode(str) {
     var result = "";
     for (var i = 0; i < str.length; i++) {
          
	if (str.charAt(i) == " "){
	 result += "+";
	} else  {
		if (str.charAt(i) == "+") {

		} else {		
		 result += str.charAt(i);
     		}
	}

	}
     return result;
}




var textarea_maxlength = "5000"


function geolookup() {
var v1 = document.form1.listingstreetaddress.value;
var v2 = document.form1.listingcity.value;
var v3 = document.form1.listingcountry.value;
var res = '';
var addy = v1 + ' ' + v2 + ' ' + v3 ;
res = confirm('I\'m about to search the geocode database for the adddress:\n\n'+addy + '\n\nPress OK if this is your address.');
if (res) {

	geoajax(addy);

}
//  listingstreetaddress listingcity listingcountry
}


function geoajax(ad) {

var URL = "";
var QS = "";

//URL = 'http://api.local.yahoo.com/MapsService/V1/geocode?output=php&appid=YahooDemo&location='  + ad ;
URL = '/getpage/|api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location='  + ad ;
QS = 'appid=YahooDemo&location='  + ad ;




    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', URL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(QS);





//alert('The search for ' + ad + ' is complete.');
}

function updatepage(t) {
//loadXML(t);





// code for IE
if (window.ActiveXObject)
  {
  var doc=new ActiveXObject("Microsoft.XMLDOM");
  doc.async="false";
  doc.loadXML(t);
  }
// code for Mozilla, Firefox, Opera, etc.
else
  {
  var parser=new DOMParser();
  var doc=parser.parseFromString(t,"text/xml");
  }// documentElement always represents the root node
var x=doc.documentElement;

var v1 = "";
var v3 = "";
var v2 = "";
var v4= "";
var v5 = "";
var v6 = "";
var res = false;

try {
v1 = (x.getElementsByTagName("Latitude")[0].childNodes[0].nodeValue);
v2 = (x.getElementsByTagName("Longitude")[0].childNodes[0].nodeValue);
}
catch(e) { alert('Sorry Your Location Was Not Found .\n\n\n\n' +  t + '\n'); }


try {
v5 = (x.getElementsByTagName("Country")[0].childNodes[0].nodeValue);
v4 = (x.getElementsByTagName("City")[0].childNodes[0].nodeValue);
v3 = (x.getElementsByTagName("Address")[0].childNodes[0].nodeValue);
//v6 = (x.getElementsByTagName("Zip")[0].childNodes[0].nodeValue);
}
catch(e) {} //alert('Your exact address was not found, but we found a substitute.\n\n\n\n' +  t + '\n');



var msg = '';
msg = msg + 'Please review the results.\n\nAddress  :' + v3 + '\n' ;
msg = msg + 'City  :' + v4 + '\n' ;
msg = msg + 'County  :' + v5 + '\n' ;
msg = msg + 'Latitude  :' + v1 + '\n' ;
msg = msg + 'Longitude :' + v2 + '\n' ;
res = confirm(msg + '\nIf this information is correct press OK, otherwise press cancel.');
if (res) {

document.form1.latitude.value = v1;
document.form1.longitude.value = v2;


}





//<Latitude>37.416384</Latitude> //
//  <Longitude>-122.024853</Longitude> 
//  <Address>701 FIRST AVE</Address> 
//  <City>SUNNYVALE</City> 
//  <State>CA</State> 
 // <Zip>94089-1019</Zip> 
//  <Country>US</Country> 



//document.write("Text of first child element: ");
//document.write(x.childNodes[0].childNodes[0].nodeValue);
//document.write("<br />");
//document.write("Text of second child element: ");
//document.write(x.childNodes[1].childNodes[0].nodeValue);

}



function textCounter(field, countfield, maxlimit) 
	{
		if (field.value.length > maxlimit) 
			field.value = field.value.substring(0, maxlimit); 
		else
			countfield.value = maxlimit - field.value.length;
	}
function setloc()  {

var n = "SVR|" + document.form1.txtlocation.value + "|SVR";

//alert(n);
var s = n.split("|");
var s0 = s.slice(0,1);
var s = n.split("|");
var s1 = s.slice(1,2);
var s = n.split("|");
var s2 = s.slice(2,3);

//alert(s1);
//alert(s2);

document.form1.listingregion.value = s1;
document.form1.listingaltregion.value = s2;

	if (s2 == "Canada") {
	
		document.form1.listingcountry.value = s2;
		document.form1.listingstate.value = s1;
		
	}else {


		if (s2 == "Mexico") {
	
			document.form1.listingcountry.value = s2;
			document.form1.listingstate.value = s1;
			
		}else {


			if (s2 == "United States") {
	
				document.form1.listingcountry.value = s2;
				document.form1.listingstate.value = s1;
				
			}else {
				document.form1.listingcountry.value = s1;
				document.form1.listingstate.value = s1;
	
				
			}

		}

	}

}




function showload() {

new Effect.Grow("insidebox",{duration: .30});
new Effect.DropOut("loading",{duration: .30});

}
function loaded() {
$('loading').morph('color:#bf0000').morph('color:#2027B7',{delay:0.5});
//new Effect.Grow("tbanner",{duration: 1.00});
Effect.BlindDown('tbanner', {duration:3});
setTimeout("showload()",400);

}
//showload();

