var link_nohandler= window.clientInformation ? null : window.undefined;

function link_down() {
    this.onfocus= this.blur;
}

function link_up() {
    this.onfocus= link_nohandler;
}

function link_bind() {
    for (var i= document.links.length; i-->0;) {
        document.links[i].onmousedown= link_down;
        document.links[i].onmouseup= link_up;
    }
}

function changeContent(id, content) {
	// alert(id + ' ' + content);
	if ( content ) {
		document.getElementById(id).innerHTML = content;
	}
}

function calculate(type)
{
	switch(type)
	{
		case 1:
			var deposit = document.getElementById('deposit').value;
			var estimatedprice = document.getElementById('estimatedprice').value;

			var loanamount = (estimatedprice - deposit);
			
			document.getElementById('loanamount').value = loanamount;
			
			// alert('buy ' + deposit  + ' ' + estimatedprice + ' ' + loanamount);
			break;
		case 2:
			var rental = document.getElementById('rental').value;
			alert(rental);
			break;
		case 3:
			var propertyprice = document.getElementById('propertyprice').value;
			
			if( propertyprice < 125000 )
			{
				var stampduty = 'Zero';
			}
			else if ( propertyprice > 125000 && propertyprice <= 250000 )
			{
				var stampduty = ( propertyprice / 100 );
			}
			else if ( propertyprice > 250000 && propertyprice <= 500000 )
			{
				var stampduty = ( propertyprice / 100 ) * 3;
			}
			else if ( propertyprice > 500000 )
			{
				var stampduty = ( propertyprice / 100 ) * 4;
			}
			
			document.getElementById('stampduty').value = stampduty;
			break;
	}
}

function togglestatus(table, id, status)
{
	// alert('table: ' + table + ' id: ' + id + ' status: ' + status);
	
	switch(table)
	{
		case 'links':
			var theNameStr = 'link';
			break;
		case 'news':
			var theNameStr = 'news article';
			break;
		case 'users':
			var theNameStr = 'user';
			break;
		case 'functions':
			var theNameStr = 'function';
			break;
		case 'locations':
			var theNameStr = 'location';
			break;
		case 'jobs':
			var theNameStr = 'job';
			break;
		case 'offers':
			var theNameStr = 'offer';
			break;
	}
	
	switch(status)
	{
		case 0:
			var theStr = 'activate';
			break;
		case 1:
			var theStr = 'de-activate';
			break;
	}
	
	if ( confirm('Are you sure you wish to ' + theStr + ' this ' + theNameStr + '?') )
	{
		$("#feedback")  
			.load(CI.base_url + "admin/" + table + "/toggleStatus/" + id + "/" + status + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}

}

function removefromshortlist(id, div)
{
	// if ( confirm('Are you sure you wish to remove this property from your shortlist?') )
	// {
		$("#shortlist")  
			.load(CI.base_url + "property/removefromshortlist/" + id + "/", null, function(responseText){  
				//window.location.reload();  
		});
	// }
}

function addtoshortlist(id)
{
	// alert('addtoshortlist: ' + id);
	
	$("#shortlist")  
		.load(CI.base_url + "property/addtoshortlist/" + id + "/", null, function(responseText){  
			// window.location.reload();  
	});
}

function deleteRole(id)
{
	if ( confirm('Are you sure you wish to delete this role?\nThis can NOT be undone.') ) {
		$("#feedback")  
			.load(CI.base_url + "admin/roles/deleteRole/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}

function deleteTestimonial(id)
{
	
	if ( confirm('Are you sure you wish to delete this testimonial?\nThis can NOT be undone.') ) {
		$("#feedback")  
			.load(CI.base_url + "admin/testimonials/delete/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}

function deleteLocation(id)
{
	
	if ( confirm('Are you sure you wish to delete this location?\nThis can NOT be undone.') ) {
		$("#feedback")  
			.load(CI.base_url + "admin/locations/delete/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}

function deleteFunction(id)
{
	
	if ( confirm('Are you sure you wish to delete this function?\nThis can NOT be undone.') ) {
		$("#feedback")  
			.load(CI.base_url + "admin/functions/delete/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}


function deleteitem(table, id)
{
	if ( confirm('Are you sure you wish to delete this item?\nThis can NOT be undone.') )
	{
		$("#feedback")  
			.load(CI.base_url + "admin/" + table + "/delete/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}

function changeImgSrc(id,src) {
	var el = document.getElementById(id);
	if (el) el.setAttribute('src',src);
}


