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 deleteNews(id)
{
	// alert(id);
	
	if ( confirm('Are you sure you wish to delete this news article?\nThis can NOT be undone.') ) {
		$("#data")  
			.load(JI.base_url + "admin/delete_news/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}

function deleteProperty(id)
{
	// alert(id);
	
	if ( confirm('Are you sure you wish to delete this property?\nThis can NOT be undone.') ) {
		$("#data")  
			.load(JI.base_url + "admin/delete_property/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	}
}

function makePOW(id)
{
	// alert(id);
	
	if ( confirm('Are you sure you wish to make this property the property of the week?\nThis can NOT be undone.') ) {
// 		$("#data").load(JI.base_url + "admin/make_pow/" + id + "/", {limit: 25}, function(){
// 			window.location.reload();
// 		 });
		
		$("#data")  
			.load(JI.base_url + "admin/make_pow/" + id + "/", null, function(responseText){  
			 	window.location.reload();  
		});
	} 
	
	// window.location.reload();
}


function deleteBrochure(id)
{
	// alert( id); 
	
	if ( confirm('Are you sure you wish to delete this brochure?\nThis can NOT be undone.') ) {
		
		$("#data").load(JI.base_url + "admin/delete_brochure/" + id + "/");

		var el = document.getElementById('brochure_'+id);
		if (el) {
			el.style.display='none';
		}
		
		return false;
	} else {
		return false;
	}
}

function deleteEPC(id)
{
	// alert( id); 
	
	if ( confirm('Are you sure you wish to delete this EPC?\nthis can NOT be undone.') ) {
		
		$("#data").load(JI.base_url + "admin/delete_photo/" + id + "/");

		var el = document.getElementById('epc_'+id);
		if (el) {
			el.style.display='none';
		}
		
		return false;
	} else {
		return false;
	}
}

function deletePhoto(id)
{
	// alert( id); 
	
	if ( confirm('Are you sure you wish to delete this photo?\nthis can NOT be undone.') ) {
		
		$("#data").load(JI.base_url + "admin/delete_photo/" + id + "/");

		var el = document.getElementById('photo_'+id);
		if (el) {
			el.style.display='none';
		}
		
		return false;
	} else {
		return false;
	}
}


function getreq() { // returns false if exists
	if(window.ActiveXObject) { // if IE
		try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
		return new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
		return;
			}
		}
	} else if(window.XMLHttpRequest) { // if Mozilla, Safari, etc.
		return new XMLHttpRequest();
		}
}

function testExists(imagepath) {
   	// alert( imagepath );
       
    req = getreq();
    req.onreadystatechange = imagexists;
	req.open("GET", imagepath, false);
    req.send(null);  
    
	if(req.status == 200) {	// image exists
		nB = true;
	}
	else if(req.status==404) {	// image doesn't exist
		nB = false;
	}
	else {
		// all other error codes will set this
		 nB = null;
	}
	
	// alert('test here ' + nB);
	
	return nB ;
    
    // return req.onreadystatechange;   
}

function imagexists(){
	
	// alert('new test here ' + req.readyState );
	
	if(req.readyState == 4) {

		// alert('test here ' + req.status);
		
		if(req.status == 200) {	// image exists
			nB = true;
		}
		else if(req.status==404) {	// image doesn't exist
			nB = false;
		}
		else {
			// all other error codes will set this
			 nB = null;
		}
		
		return nB ;
		
	}
}

function openURL( form ) { 

	// alert(form);
	
	var newIndex = form.our_services.selectedIndex; 

	if ( newIndex == 0 ) { 

		alert( "Please select a menu item!" ); 

	} else { 

		cururl = form.our_services.options[ newIndex ].value; 

		window.location.assign( cururl ); 

	} 

}

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

