﻿function initCheckbox( chks ,callback){
	for(var i=0;i<chks.length;i++){
		if( chks[i].addEventListener){
			chks[i].parentNode.addEventListener("click", checkevent(chks , chks[i] , callback,true )  ,false);
		}else{
			chks[i].attachEvent("onclick",  checkevent(chks,chks[i] , callback,true) );

		}
		chks[i].checked = false;

	}
}
function setCheck(id,bchk){
	var el ;
	if(  typeof id=="string" || id instanceof String ){
		 el = document.getElementById( id );
	}else{ 
		el = id;
	}
	if( typeof bchk != "undefined" )
		el.checked = bchk;
	else
		bchk = el.checked ;
	if(bchk ){
		addCssClass( el.parentNode,"checkboxlabel-checked");
	}else{
		removeCssClass( el.parentNode ,"checkboxlabel-checked");
	}
}
function checkevent(chks,el,callback,isSingle){
	return function(){
		setCheck(el);
		if(callback)
			callback(el);
		
	}
}

function EL(id){
	return document.getElementById(id );
}
function addCssClass(el, clsName){

	if(el.className){
		var arr = el.className.split(/\s+/g); 
		for(var i=arr.length-1;i>-1;i--){
			if( arr[i]==clsName)//已经有了
				return;
		} 
		arr.push( clsName );
		el.className = arr.join(" ");
		
	}else{ 
		el.className= clsName;
	}
}
function removeCssClass( el , clsName ){
	if(el.className){
		var arr = el.className.split(/\s+/g);
		for(var i=arr.length-1;i>-1;i--){
			if( arr[i]== clsName)
				arr.splice(i,1);
		}
		el.className = arr.join(" ");
	}else{
		el.className= clsName;
	}
	
}


function  showHtmlMsg(html,callBack){
	var el = EL("popup");
	if( el == null ){
		el = initPopup();
	}
	EL("popup-msgtext").innerHTML = html;
	el.style.display="block";
	initPopup.callBack = callBack;
}
function initPopup(){
	var html='<div id="popup" style="position:absolute;width:100%;height:100%;">\
		<div class="content">\
			<div id="popup-msgtext"></div>\
			<div class="btns" style="text-align:center">\
				<button class="btnOk" id="popup-btnOk"></button>\
			</div>\
		</div>\
	</div>';
	var div = document.createElement("div");
	div.innerHTML = html;
	div = EL("sjtd").appendChild( div.firstChild );
	EL("popup-btnOk").onclick=function(){
		EL("popup").style.display= "none";
		if( initPopup.callBack){
			initPopup.callBack();
		}
		return false;
	}
	try{
		return div;
	}finally{
		div = null;
	}

}