// JavaScript Document
function getXMLHTTP1() { //fuction to return the xml http object

	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}
	return xmlhttp;
}



	function get_state(id,state_id) {	

			var strURL="ajax_get_state.php?id=" + id + "&state_id=" + state_id;
			var req = getXMLHTTP1();
			if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) { 
							document.getElementById('states').innerHTML = req.responseText;		
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}
	
	
	
	
		function get_bus_state(id,state_id) {	

			var strURL="ajax_get_busstate.php?id=" + id + "&state_id=" + state_id;
			
			var req = getXMLHTTP1();
			if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) { 
							document.getElementById('bus_state').innerHTML = req.responseText;		
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}

		function get_bus_selstate(id,state_id) {	
alert(state_id);
			var strURL="ajax_sel_busstate.php?id=" + id + "&state_id=" + state_id;
			
			var req = getXMLHTTP1();
			if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) { 
							document.getElementById('bus_state').innerHTML = req.responseText;		
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}

// Property type

function get_property(id,pid) {	
		var strURL="ajax_get_property.php?id=" + id + "&pid=" + pid;
			
			var req = getXMLHTTP1();
			if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) { 
							document.getElementById('ptype').innerHTML = req.responseText;		
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}


			function check_username(name) {	
			//alert(name);
			var strURL="ajax_chk_username.php?uname=" + name;
			var req = getXMLHTTP1();
			
			if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
				
						if (req.responseText == 1)
						{	
							document.getElementById('err_username').innerHTML = 'Choose another user name.';
							document.getElementById('valid_user').value = 1;		
						}
						else 
						{	
							document.getElementById('err_username').innerHTML = '';
							document.getElementById('valid_user').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}

	function addtoFavourites(rid,bm_for) {		
			
//alert(rid);
		var strURL="addtofavourites.php?aid="+rid+ "&for=" + bm_for;
	//alert(strURL);
		var req = getXMLHTTP1();
		if (req) {
			 
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) { //alert(req.responseText);
						if (req.responseText == 1 )
						{ 
						document.getElementById('success_disp'+rid).innerHTML = 'Successfully Added into Bookmarks';	
						document.getElementById('addremovelink'+rid).innerHTML  = '&nbsp;<a  href="javascript:removeFavourites(\''+rid+'\',\''+bm_for+'\');">Remove  Book Mark</a>';
							document.getElementById('addf'+rid).style.display='none';
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	
	function removeFavourites(rid,bm_for) {		
	//alert(rid);
		var strURL="removefavourites.php?aid="+rid+ "&for=" + bm_for;
		

		var req = getXMLHTTP1();
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
						if (req.responseText == 0)
						{
							document.getElementById('success_disp'+rid).innerHTML='Successfully Removed from Bookmarks';	
							document.getElementById('addremovelink'+rid).innerHTML        =  '&nbsp;<a  href="javascript:addtoFavourites(\''+rid+'\',\''+bm_for+'\');">Add to Book Mark</a>';
							document.getElementById('removef'+rid).style.display='none';
						}
					
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
		function check_mailedit(mail,rid) {	
		var strURL="ajax_chk_mailedit.php?mailid=" + mail + "&id=" + rid;
		var req = getXMLHTTP1();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
			
						if (req.responseText == 1)
						{	
							document.getElementById('err_mailid').innerHTML = 'Choose another Mail id.';
							document.getElementById('validmail').value = 1;		
						}
						else 
						{	
							document.getElementById('err_mailid').innerHTML = '';
							document.getElementById('validmail').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}

// Password - Validation

		function check_password(pwd,rid) {	
		//alert('fdgdfg');
		var strURL="ajax_chk_password.php?pwd=" + pwd + "&id=" + rid;
		var req = getXMLHTTP1();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
			
						if (req.responseText == 1)
						{	
							document.getElementById('err_pwd').innerHTML = 'Type correct Password.';
							document.getElementById('valid_pwd').value = 1;		
						}
						else 
						{	
							document.getElementById('err_pwd').innerHTML = '';
							document.getElementById('valid_pwd').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}

// Bid Value - Validation

		function check_bidvalue(bvalue,aid) {	 
		var strURL="ajax_chk_bidvalue.php?bvalue=" + bvalue + "&aid=" + aid;
		var req = getXMLHTTP1();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
			
						if (req.responseText == 1)
						{	
							document.getElementById('err_bid').innerHTML = 'Kindly enter the bid value greater than the Reserve Price/Last Bid value plus Minimum Incremental Bid Amount(MIBA).';
							document.getElementById('valid_bid').value = 1;		
						}
						else 
						{	
							document.getElementById('err_bid').innerHTML = '';
							document.getElementById('valid_bid').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}


	// Bid - Bid Key Code - Validation

		function check_keycode(key,aid) {	
		//alert('fdgdfg');
		var strURL="ajax_chk_keyvalue.php?key=" + key + "&aid=" + aid;
		var req = getXMLHTTP1();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
		

						if (req.responseText == 1)
						{	
							document.getElementById('err_key').innerHTML = 'Wrong Bid Code.';
							document.getElementById('valid_key').value = 1;		
						}
						else 
						{	
							document.getElementById('err_key').innerHTML = '';
							document.getElementById('valid_key').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}

	
	function check_mailvalue(mail) {	
	//alert('gfhg');
		var strURL="ajax_chk_mailid.php?mailid=" + mail;
		var req = getXMLHTTP1();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
				
						if (req.responseText == 1)
						{	
							document.getElementById('err_mailid').innerHTML = 'Choose another Mail id.';
							document.getElementById('valid_mail').value = 1;		
						}
						else 
						{	
							document.getElementById('err_mailid').innerHTML = '';
							document.getElementById('valid_mail').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}
	
	
	
	
	// key generation
	
			function keygeneration(id) {	
			var strURL="ajax_keygeneration.php?id=" + id;
			var req = getXMLHTTP1();
			
			if (req) {
			

			req.onreadystatechange = function() {
		
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
							document.getElementById('keycode').innerHTML = 'Bid Activation Key : '+req.responseText;		
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	

		
		
	}

// EMD - Check

		function check_emd(mid,aid) {	
		var strURL="ajax_chk_emd.php?mid=" + mid+ "&aid=" + aid;
		var req = getXMLHTTP1();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {
		

						if (req.responseText == 1)
						{	
							document.getElementById('err_key').innerHTML = 'This Member does not Deposit the EMD.';
							document.getElementById('valid_key').value = 1;		
						}
						else 
						{	
							document.getElementById('err_key').innerHTML = '';
							document.getElementById('valid_key').value = 0;
						}
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}	
				}	
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}	
		
	}



