// JavaScript Document Spaceanywhere


//DIV Show Error
function show_div(id)
{
	
	el = document.getElementById(id);
	
	if (el.style.display == 'none')
	{
		el.style.display = '';
	} 
	
}

function hide_div(id)
{
	
	el = document.getElementById(id);
	
	if (el.style.display == '')
	{
		el.style.display = 'none';
	} 
	
}
//-------------------------












function createObject()
{
	
var requestType;
var browser = 	navigator.appName;

	if(browser=="Microsoft Internet Explorer")
	{
		requestType = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		requestType = new XMLHttpRequest();	
	}
	
return requestType;
	
}


var http = createObject();

/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;

//-----------------------------------------------------------------------------------------------------
function getRate() {
var name = encodeURI(document.getElementById('py_rates').value);
var typ;
if(frm_py_rate.chk_rate[0].checked) //buy
{
	typ=1;
}
else if(frm_py_rate.chk_rate[1].checked)
{
	
	typ=2;
}

document.getElementById('div_chk_rate').innerHTML = "<br><br>checking...";


// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'includes/get_rate.php?id='+name+'&type='+typ+'&nocache = '+nocache);
http.onreadystatechange = rateReply;
http.send(null);
}


function rateReply() {

	if(http.readyState == 4)
	{
	
		var response = http.responseText;

		if(response != 0){
		// if entered
		
		document.getElementById('div_chk_rate').innerHTML = response;
	
		}
	
	}

}//funct rate reply
//-----------------------------------------------------------------------------------------------------

//-----------------------------------------------------------------------------------------------------
//-------CHECK LOGIN NAME AVAILABILITY
function check_login_avail()
{


var login = encodeURI(document.getElementById('txtLoginID').value);


	if(login.length>=6)
	{
		document.getElementById('checkavailable').innerHTML = '<span class="normaltextRED">Checking...</span>';
			// Set te random number to add to URL request
			nocache = Math.random();
			// Pass the login variables like URL variable
			http.open('get', 'includes/check_loginAvail.php?id='+login+'&nocache = '+nocache);
			http.onreadystatechange = checkLoginAvail_reply;
			http.send(null);
	}
	else if(login.length<6)
	{
		
		alert('Please enter a valid user id. Minimum of 6 characters.');	
		
	}
}


function checkLoginAvail_reply() {

	if(http.readyState==4)
	{

		var response = http.responseText;

		if(response==0){
		// if entered
		
			document.getElementById('checkavailable').innerHTML = '<span class="normaltextGREEN">Available</span>&nbsp;:&nbsp;<a href="" onclick="check_login_avail(); return false;"><span class="bolddarkbluetext">Check Again</span></a>';

			
		}
		else if(response==1)
		{
			
			document.getElementById('checkavailable').innerHTML = ' <span class="normaltextRED">Not Available</span>&nbsp;:&nbsp;<a href="" onclick="check_login_avail(); return false;"><span class="bolddarkbluetext">Check Again</span></a>';
		}
	
	}

}//funct rate reply











//-----------------------------------------------------------------------------------------------------


var prop_id=0;

function shortlist(pid)
{

		prop_id = pid;
		document.getElementById(pid).innerHTML = "<span class=\"normaltextRED\">Shortlisting...</span>";
			// Set te random number to add to URL request
			nocache = Math.random();
			// Pass the login variables like URL variable
			http.open('get', 'includes/shortlist.php?id='+pid+'&nocache = '+nocache);
			
			http.onreadystatechange = shortlist_reply;
			http.send(null);
	
}


function shortlist_reply(pid) {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
		hide_div(prop_id);
	
		if(response==1){
		// if entered
			
			document.getElementById(prop_id).innerHTML = '<span class="normaltextGREEN">Shortlisted</span>';
			show_div(prop_id);
	
		}
		else if(response==0)
		{
			
			document.getElementById(prop_id).innerHTML = '<span class="normaltextRED">ERROR</span>';
			show_div(prop_id);
		}
	
	}

}//funct rate reply

//-----------------------------------------------------------------------------------------------------



function search_by_id()
{

		var text = encodeURI(document.getElementById('txt_pid').value);
		
		if(text.length>3)
		{
		
			hide_div('advance_search');
			
			document.getElementById('advance_search_result').innerHTML = "<span class=\"normaltextRED\">Searching...</span>";
			show_div('advance_search_result');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get', 'includes/search_by_id.php?pid='+text+'&nocache = '+nocache);
			
			http.onreadystatechange = search_reply;
			http.send(null);
			
		}else {
			
			alert('Invalid Property ID');
		}
	
}


function search_reply() {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
			
		
			document.getElementById('advance_search_result').innerHTML = response;
			
	}

}//funct search reply ends




//------------FUNCTION GETTING USER ALERTS-------------------------------------------------------------------------------

function get_alerts(uid)
{

hide_div('alert_div');
			show_div('load');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get','includes/get_alerts.php?uid='+uid+'&nocache = '+nocache);
			
			http.onreadystatechange = alert_reply;
			http.send(null);
}


function alert_reply() {

	if(http.readyState == 4)
	{
		var response = http.responseText;
		
		
		hide_div('load');
		show_div('alert_div');
		document.getElementById('alert_div').innerHTML = response;
	}

}//funct ends



//------------FUNCTION GETTING SHORTLISTED BUY-------------------------------------------------------------------------------

function get_shortlist(buy_rent)
{


	if(buy_rent==1)						//shortlist buy
	{

			hide_div('shortlisted_buy');
			show_div('load_shortlist_buy');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get','includes/get_shortlisted_buy.php?nocache = '+nocache);
			
			http.onreadystatechange = shortlist_buy_reply;
			http.send(null);
			
	}
	else if(buy_rent==3)					//shortlisted buy when removeid. will not call rent shortlisted function
	{
			hide_div('shortlisted_buy');
			show_div('load_shortlist_buy');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get','includes/get_shortlisted_buy.php?nocache = '+nocache);
			
			http.onreadystatechange = shortlist_buy_only_reply;
			http.send(null);
			
	}
	else if(buy_rent==2)					//shortlist rent
	{
			hide_div('shortlisted_rent');
			show_div('load_shortlist_rent');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get','includes/get_shortlisted_rent.php?nocache = '+nocache);
			
			http.onreadystatechange = shortlist_rent_reply;
			http.send(null);
		
	}
	
}


function shortlist_buy_reply() {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
		hide_div('load_shortlist_buy');
		show_div('shortlisted_buy');
		document.getElementById('shortlisted_buy').innerHTML = response;
		get_shortlist(2);
	}

}//funct ends

//shortlist buy function widout calling rent function in the end
function shortlist_buy_only_reply() {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
		hide_div('load_shortlist_buy');
		show_div('shortlisted_buy');
		document.getElementById('shortlisted_buy').innerHTML = response;
	}

}//funct ends

function shortlist_rent_reply() {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
		hide_div('load_shortlist_rent');
		show_div('shortlisted_rent');
		document.getElementById('shortlisted_rent').innerHTML = response;
	}

}//funct ends

//-----------------------------------------------------------------------------------------------

//------------FUNCTION UNSELECTING-------------------------------------------------------------------------------

function ulist(pyid)
{
	
			nocache = Math.random();
			http.open('get','includes/unshortlisted.php?pyid='+pyid+'&nocache = '+nocache);
			http.onreadystatechange = ulist_reply;
			http.send(null);
}

function ulist_reply() {

	if(http.readyState == 4)
	{
		var response = http.responseText;
		if(response==1)			//refersh shortlisted buy
		{	get_shortlist(3);	} else { get_shortlist(2);	}
	}

}//funct ends


//------------FUNCTION Delete / Mark read unread messages-------------------------------------------------------------------------------

function message(msgid,uid,action)			//action = 1 means delete , action = 2 = mark unread
{
	
	nocache = Math.random();
	if(action==1)
	{
			http.open('get','includes/process_msgs.php?mid='+msgid+'&act='+action+'&nocache = '+nocache);
			http.onreadystatechange = delete_msg_reply;
			http.send(null);
	}
	else if(action==2)			//mark read
	{
			http.open('get','includes/process_msgs.php?mid='+msgid+'&act='+action+'&nocache = '+nocache);
			http.onreadystatechange = markread_msg_reply;
			http.send(null);
	}
	else if(action==3)			//mark unread
	{
			http.open('get','includes/process_msgs.php?mid='+msgid+'&act='+action+'&nocache = '+nocache);
			http.onreadystatechange = markunread_msg_reply;
			http.send(null);	
	}	

}

function delete_msg_reply() {				//delete reply

	if(http.readyState == 4)
	{
		var response = http.responseText;
		document.getElementById('MESSAGE'+response).style.display = 'none';
	}
}//funct ends
	
function markread_msg_reply() {				//mark read reply

	if(http.readyState == 4)
	{
		var response = http.responseText;
		document.getElementById('MESSAGE'+response).style.background = '#F7F7F7';
		document.getElementById('readunread'+response).innerHTML = "<a href=\"\" onClick=\"message('"+response+"','1','3'); return false;\" class=\"Heading_trecFont_BIG_red\">mark as unread</a>";

	}
}//funct ends
function markunread_msg_reply() {					//mark unread reply

	if(http.readyState == 4)
	{
		var response = http.responseText;
		document.getElementById('MESSAGE'+response).style.background = '#F3FFCE';
		document.getElementById('readunread'+response).innerHTML = "<a href=\"\" onClick=\"message('"+response+"','1','2'); return false;\" class=\"Heading_trecFont_BIG_red\">mark as read</a>";
	}
}//funct ends



//------------FUNCTION LISTING ALERTS N UPDATES-------------------------------------------------------------------------------

function list_update_alert(alert_updates)
{


	if(alert_updates==1)						//update
	{

			hide_div('list_update');
			show_div('load_update');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get','includes/get_update_alert.php?flag='+alert_updates+'nocache = '+nocache);
			
			http.onreadystatechange = list_update_reply;
			http.send(null);
	}
	else if(alert_updates==2)					//alerts
	{
			hide_div('list_alert');
			show_div('load_alert');
			// Set te random number to add to URL request
			nocache = Math.random();
			
			http.open('get','includes/get_update_alert.php?flag='+alert_updates+'nocache = '+nocache);
			
			http.onreadystatechange = list_alert_reply;
			http.send(null);
		
	}
	
}

function list_update_reply() {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
		hide_div('load_update');
		show_div('list_update');
		document.getElementById('list_update').innerHTML = response;
		
		list_update_alert(2);				//calling for alerts
	}

}//get updates reply funct ends

function list_alert_reply() {

	if(http.readyState == 4)
	{
		
		var response = http.responseText;
		hide_div('load_alert');
		show_div('list_alert');
		document.getElementById('list_alert').innerHTML = response;
	}

}//get alert reply funct ends



//--------------------------------------------POLLS

//GETTING active POLL ------------------------------------

function get_active_poll() {


document.getElementById('today_poll').innerHTML ="<br /><br /><img src=\"images/ld.gif\" alt=\"Loading\" /><br /><br />";
document.getElementById('today_poll').align = "center";

nocache = Math.random();
// Pass the login variables like URL variable
http.open('post', 'includes/get_poll_result.php?nocache = '+nocache);
http.onreadystatechange = activepoll_fetch;
http.send(null);
}
function activepoll_fetch() {

	if(http.readyState == 4)
	{
		var response = http.responseText;
	document.getElementById('today_poll').align = "left";		
		document.getElementById('today_poll').innerHTML = response;

	}

}//fetch pools


//posting polls from poll page

function post_vote() {
	
var value1 = encodeURI(document.getElementById('radV1').checked);
var value2 = encodeURI(document.getElementById('radV2').checked);
var value3 = encodeURI(document.getElementById('radV3').checked);
var opt;

if(value1=='true')
{
	opt=1;
}
else if(value2=='true')
{
	opt=2;
}
else if(value3=='true')
{
	opt=3;
}

document.getElementById('vote_now').innerHTML ="<table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\" bgcolor=\"#FFFFFF\"><span class=\"past_poll_bottom_txt_res\">Processing....</td></tr></table>";
			  
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('post', 'includes/process_vote.php?val='+opt+'&nocache = '+nocache);
http.onreadystatechange = process_vote;
http.send(null);
}

function process_vote() {

	if(http.readyState == 4)
	{
		var response = http.responseText;
		
		if(response==1)
		{

			document.getElementById('vote_now').innerHTML ="<table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td align=\"center\" bgcolor=\"#FFFFFF\"><span class=\"past_poll_bottom_txt_res\">Vote Counted Successfully. &nbsp;&nbsp;<a href=\"\" onclick=\"hide_div('vote_now'); return false;\" class=\"Blue_11_noUnder\">[ X Close ]</a></td></tr></table>";
			//calling to display updated poll
			get_active_poll();
		}
	}

}//fetch pools




//GETTING PREVIOUS POLLS only 10  recent past polls ------------------------------------

function get_pastpolls(recent_flag) {
show_div('load');
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('post', 'includes/get_rec_polls.php?val='+recent_flag+'&nocache = '+nocache);
http.onreadystatechange = pastpolls_fetch;
http.send(null);
}
function pastpolls_fetch() {

	if(http.readyState == 4)
	{
		hide_div('load');
		var response = http.responseText;
		document.getElementById('pastpolls').innerHTML = response;

	}

}//fetch pools


//---------------------------- ARTICLE SOURCES HIDE SHOW

//DIV Show hide
function show_source(id)
{
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		hide_div('show_src');
		show_div('hide_src');
	} 
}

function close_source(id)
{
	el = document.getElementById(id);
	if (el.style.display == '')
	{
		el.style.display = 'none';
		show_div('show_src');
		hide_div('hide_src');
	} 
	
}
//-------------------------

//-----------------------------------------------------------------------------------------------------

function showSMS(sms,mail) {

	//document.getElementById(sms).style.display='';
	//document.getElementById(mail).style.display='none';
	show_div(sms);
	hide_div(mail);
}

function showEMAIL(sms,mail) {

	//document.getElementById(sms).style.display='none';
	//document.getElementById(mail).style.display='';
	show_div(mail);
	hide_div(sms);
}

function exit(id) {

	hide_div(id);
}

