/**
 * @author Administrator
 */
var objNews = null;
var objLoading = null;
Object.extend(Element, {
	getWidth: function(element) {
	   	element = $(element);
	   	return element.offsetWidth; 
	},
	setWidth: function(element,w) {
	   	element = $(element);
    	element.style.width = w +"px";
	},
	setHeight: function(element,h) {
   		element = $(element);
    	element.style.height = h +"px";
	},
	setTop: function(element,t) {
	   	element = $(element);
    	element.style.top = t +"px";
	},
	setSrc: function(element,src) {
    	element = $(element);
    	element.src = src; 
	},
	setHref: function(element,href) {
    	element = $(element);
    	element.href = href; 
	},
	setInnerHTML: function(element,content) {
		element = $(element);
		element.innerHTML = content;
	}
});
function prepage(){
	objCategory = document.getElementById('CategoryID')
	getNews(objCategory.value);		

}
function getNews(CategoryID){
	objBody = document.getElementsByTagName('body').item(0);
	objContainer = document.getElementById('divContainer');
	objNews = document.getElementById('divNews');
	objLoading = document.createElement('div');
	objLoading.innerHTML = '<img src=images/loading.gif>'
	objLoading.style.paddingTop = 30;
	objLoading.style.width= '100%';
	objLoading.style.textAlign='center';
	objLoading.style.zIndex='90';
	objLoading.style.height = '91px';
	objLoading.style.display = 'none'
	objContainer.appendChild(objLoading);
	_StartLoading(function(){
		getAjax(CategoryID,function(){
			alert('abc');
		})
	});
	
	
}
function chgType(){

	objPwd = document.getElementById('password');
	objRpc = document.createElement('input');
	
	
	//objPwd.parentNode.replaceChild(objRpc,objPwd);
	objRpc.setAttribute('id','password');
	objRpc.setAttribute('name','password');
	objRpc.setAttribute('type','password');
	objRpc.className = 'main_input1';
	
	objPwd.parentNode.replaceChild(objRpc,objPwd);
	objRpc.focus();
	
	


}

function getAjax(CategoryID,afterFunction){
		var myOption = {
		method: 'GET',
		onSuccess: function(t) {
			objNews.innerHTML = t.responseText; //HTMLTemp.getElementById('divList').innerHTML;
			//Element.hide(objLoading);
			//Element.show(objNews);
			
			_EndLoading(
				function(){
					new Effect.Appear(objNews,{duration:0.2});
				}
			);

		},
		// Handle 404
		on404: function(t) {
			alert('Error 404: location "' + t.statusText + '" was not found.');
		},
		// Handle other errors
		onFailure: function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
		}
	}
	new Ajax.Request('shpra_news.php?Method=getNews&CategoryID='+CategoryID, myOption);
}
function _EndLoading(afterFunction){
	new Effect.Fade(objLoading,{
		duration:0.2,
		start:1,
		to:0,
		afterFinish:function(){afterFunction();}
	})
}
function _StartLoading(afterFunction){
	new Effect.Fade(objNews,{	
			duration:0.2,
			start:1,
			to:0,
			afterFinish:function(){
				new Effect.Appear(objLoading,{duration:0.2,afterFinish:function(){afterFunction();}})				
			}
		});

}

function _createDiv(){
		objOverlay = document.createElement("div");
		objLoading = document.createElement("div");
		objOverlay.setAttribute('id','tbOverlay');
		objOverlay.style.position= 'absolute';
		objOverlay.style.zIndex = 50;
		objOverlay.style.left = 0;
		objOverlay.style.top = 0;
		Element.setHeight(objOverlay,objNews.offsetHeight);
		Element.setWidth(objOverlay,objNews.offsetWidth);
		objOverlay.style.backgroundColor = '#000';
		//objOverlay.style.display = 'none';
		objNews.appendChild(objOverlay);
		alert('abc');		
		objLoading.setAttribute('id','tbLoad');
		objLoading.innerHTML = "<img src=images/loading.gif><p>Loading";
		objLoading.style.display = 'none';
		objBody.appendChild(objLoading);
		isCreate = true;
}
