// JavaScript Document

function viewTime(a){
	if(a>=300000){// five min 
		var b = 300000;
	}else{
		var b = a*2;
	}
	pagetimer();
window.setTimeout("viewTime('"+b+"')",b);
}

function viewTimeNonSearch(a){
	if(a>=300000){// five min 
		var b = 300000;
	}else{
		var b = a*2;
	}
	pagetimerNonSearch();
window.setTimeout("viewTimeNonSearch('"+b+"')",b);
}

function pagetimerNonSearch(){
	//checkedItems();
//var url = "/gwinnetthomes/pagetimer.php";

//alert('before_pagetimer');
var url = "pagetimer.php";
//alert('after_pagetimer');


	var http; //declare the variable to hold the object.
	//var browser = navigator.appName; //find the browser name
	//if(browser == "Microsoft Internet Explorer")
	
	if (window.ActiveXObject){
		/* Create the object using MSIE's method */
		//alert('option1');
		http = new ActiveXObject("Microsoft.XMLHTTP");
		
	//}else{
	}else if (window.XMLHttpRequest) {
		//alert('option2');
		/* Create the object using other browser's method */
		http = new XMLHttpRequest();
	}else{
	//alert('option3');	
	}


if(document.pagetimer.giveSearchType.value == 'viewPage'){
	var params = "ad="+document.pagetimer.ad.value+"&userLinkID="+document.pagetimer.userLinkID.value+"&searchID="+document.pagetimer.searchID.value+"&passdomain="+document.pagetimer.passdomain.value+"&giveSearchType=ViewPage&pageName="+document.pagetimer.pageName.value;
	//alert('viewPAge');
}

http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		//alert(http.responseText);
	}
}
http.send(params);	
	
	//alert("request was sent");
}//end of non search pagetimer




function pagetimer(){
	//checkedItems();
//var url = "/gwinnetthomes/pagetimer.php";

//alert('before_pagetimer');
var url = "pagetimer.php";
//alert('after_pagetimer');


	var http; //declare the variable to hold the object.
	//var browser = navigator.appName; //find the browser name
	//if(browser == "Microsoft Internet Explorer")
	
	if (window.ActiveXObject){
		/* Create the object using MSIE's method */
		//alert('option1');
		http = new ActiveXObject("Microsoft.XMLHTTP");
		
	//}else{
	}else if (window.XMLHttpRequest) {
		//alert('option2');
		/* Create the object using other browser's method */
		http = new XMLHttpRequest();
	}else{
	//alert('option3');	
	}

if(document.TopSearch.clientlogin.value == '1234'){
	//changes searchtype if client logs in
	var params = "ad="+document.TopSearch.ad.value+"&userLinkID="+document.TopSearch.userLinkID.value+"&searchID="+document.TopSearch.searchID.value+"&passdomain="+document.TopSearch.passdomain.value+"&giveSearchType=Client Login";
	
}else{
var action = document.TopSearch.giveSearchType.value;

var params = "ad="+document.TopSearch.ad.value+"&userLinkID="+document.TopSearch.userLinkID.value+"&searchID="+document.TopSearch.searchID.value+"&passdomain="+document.TopSearch.passdomain.value+"&giveSearchType="+document.TopSearch.giveSearchType.value+"&Criteria/MinPrice="+document.TopSearch.MinPrice.value+"&Criteria/MaxPrice="+document.TopSearch.MaxPrice.value+"&Criteria/MinBedrooms="+document.TopSearch.MinBedrooms.value+"&Criteria/MinBathrooms="+document.TopSearch.MinBathrooms.value+"&Criteria/MinYearBuilt="+document.TopSearch.MinYearBuilt.value+"&Criteria/MaxYearBuilt="+document.TopSearch.MaxYearBuilt.value+"&checkedItems="+document.TopSearch.checkeditems.value;
if(action == 'city'){
params =params+"&Criteria/City="+document.TopSearch.City.value;	
}
if(action == 'geographic'){
	var action_type = TopSearch.action_type.value;
	if(action_type == 'County'){
params =params+"&Criteria/RECoSearchLevel2="+document.TopSearch.County.value;
	}
	if(action_type == 'Zip'){
params =params+"&Criteria/ZipCode="+document.TopSearch.zipcode.value;
	}
	if(action_type == 'Subdivision'){
params =params+"&Criteria/Subdivision="+document.TopSearch.subdivision.value;
	}
}
if(action == 'schooldistrict'){
params =params+"&Criteria/ElementarySchool="+document.TopSearch.elem.value+"&Criteria/MiddleSchool="+document.TopSearch.mid.value+"&Criteria/HighSchool="+document.TopSearch.high.value;
}
if(action == 'mls'){
params =params+"&Criteria/ListingNumber="+document.TopSearch.mlsnum.value;
}
if(action == 'radius'){
params =params+"&Criteria/City="+document.TopSearch.radCity.value+"&Criteria/RadiusSearch/FullAddress="+document.TopSearch.address.value+"&Criteria/RadiusSearch/RadiusDistance="+document.TopSearch.radius.value;
}
}
//var params = "searchID=1234667&passdomain=testpassdomain&giveSearchType=city";

http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		//alert(http.responseText);
	}
}
http.send(params);	
	
	//alert("request was sent");
}


function fillSearchID(){
var randnum = Math.floor(Math.random()*9999999);
document.pagetimer.searchID.value = randnum;
//document.pagetimer.searchID.value = '2134567';
document.pagetimer.clientlogin.value = '0';	

}

function clickLog(title,mode){
	var url = "emailData.php";
	var http;
	//alert('chatclick');
	if (window.ActiveXObject){
		/* Create the object using MSIE's method */
	http = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		/* Create the object using other browser's method */
		http = new XMLHttpRequest();
	}
	var params = "clickLog="+title+"&clickLogMode="+mode;
	
	http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		//alert(http.responseText);
	}
}
http.send(params);
}

function Flashover(){
theObjects = document.getElementsByTagName("object");
for (var i = 0; i < theObjects.length; i++) {
theObjects[i].outerHTML = theObjects[i].outerHTML;
}
}


function chatclick(){
	var url = "emailData.php";
	var http;
	//alert('chatclick');
	if (window.ActiveXObject){
		/* Create the object using MSIE's method */
	http = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest) {
		/* Create the object using other browser's method */
		http = new XMLHttpRequest();
	}
	var params = "chatclick=yes&domain="+document.hvform.domain.value;
	
	http.open("POST", url, true);

//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");

http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		//alert(http.responseText);
	}
}
http.send(params);
}

function echeck(str) {
//alert('echeck'+str);
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}


		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
