// tim control
function $$(id)
{
	return document.getElementById(id);
}
// lay noi dung FCK Editor
function getTextFCK(FCKname)
{
	// Get the editor instance that we want to interact with.
	var oEditor = FCKeditorAPI.GetInstance(FCKname) ;
		// Get the editor contents in XHTML.
	return oEditor.GetXHTML(true);// "true" means you want it formatted.
}
function showHidden(id)
    {
        id =$$(id);
        if(id.style.display=="")
            id.style.display="none";
        else    
            id.style.display="";
    }
function isMaxLength(title,maxLength,ctrl)
{
	s = trimSpace($$(ctrl).value);
	if(s!=null && s!="" && s.length>maxLength)
	{
		alert("Chiá»?u dÃ i tá»‘i Ä‘a cá»§a " + title + " lÃ  " + maxLength + " kÃ½ tá»±!");
		$$(ctrl).focus();
		return false;
	}	
	return true;
}
function trimSpace(s)
{
	for(i=0;i<s.length;i++)
		s = s.replace("&nbsp;"," ");
	while(s.charCodeAt(0)==32 && s.length>1)
	{
		s=s.substr(1,s.length)
	}
	
	//-------------------------
	if(s.charCodeAt(0)==32 && s.length==1)
		return "";
	else
		return s;	
}
function form()
{
	return document.forms[0];
}

function isEmail(email)
{
	
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(email))	
		return false;
	else
		return true;
	
}
function getEditorFCK(nameControl,type)
{
	var content = findNameControl(nameControl,type);
		content = content.replace(":","_");
		if($$(content).value=="")
			return false;
		else
			return true;
}
function showdate()
		{
			d = new Date();
			var a = new Array("Chá»§ nháº­t","Thá»© hai","Thá»© ba","Thá»© tÆ°","Thá»© nÄƒm","Thá»© sÃ¡u","Thá»© báº£y");
			s = "<b>" + a[d.getDay()] + 
				", " +	(d.getDate()<10?"0" + d.getDate():d.getDate()) +
				"/" +	(d.getMonth()+1 <10?"0" + (d.getMonth() + 1):(d.getMonth()+1)) +
				"/" +	d.getFullYear() + "</b>";
			document.write(s);			
}
// kiem tra dung theo dang file can tim khong
// fileName: ten file
// extType: loai file nhu Video, Doc...
function isFile(fileName,extType){
		var dotpos, vReturn=false;
		fileName = fileName.substring(FileName.lastIndexOf("\\")+1,FileName.length);
		dotpos = fileName.lastIndexOf('.');
		ext = fileName.substr(dotpos+1,FileName.length-dotpos);
		ext = ext.toLowerCase();	
		switch(extType.toLowerCase()){
			case "video":				
				if (ext != "" && ext != "flv" && ext != "mp3" && ext != "avi" && ext != "asf" && ext != "mpg" && ext != "wma" && ext != "wmv" && ext != "wav"){
					vReturn = false;					
				}else{
					vReturn = true;
				}				
				break;
			case "doc":				
				if (ext != "" && ext != "doc" && ext != "txt" && ext != "pdf" && ext != "xsl"){
					vReturn = false;					
				}else{
					vReturn = true;
				}				
				break;
			case "images":				
				if (ext != "" && ext != "jpg" && ext != "gif" && ext != "png" && ext != "bmp"){
					vReturn = false;					
				}else{
					vReturn = true;
				}				
				break;
			case "flash":				
				if (ext != "" && ext != "swf" && ext != "flv"){
					vReturn = false;					
				}else{
					vReturn = true;
				}				
				break;
		}		
	return vReturn;
}
function isNumber(textNum)
{
	var re = /^[0-9]{1,4}$/;	
	if (!re.test($$(textNum).value)){
		alert("Vui long dien so!");
		$$(textNum).value="1";
		$$(textNum).focus();
		return false;
	}
}
function funTextArea(names, classname, width, values, rows){		
		var sBasePath = 'fckeditor/';
		var oFCKeditor = new FCKeditor( names ) ;
		oFCKeditor.BasePath	= sBasePath ;
		oFCKeditor.Height	= 250 ;
		oFCKeditor.Value	=  values ;
		oFCKeditor.Create() ;		
}
function ConvertDate(_date)	
{
	var aDate = new Array();
	aDate = _date.split("/");
	return (aDate[2] + (aDate[1].length<2?"0"+aDate[1]:aDate[1]) + (aDate[0].length<2?"0"+aDate[0]:aDate[0]));
}	
function keyWords(s0)
{
	s=$$(s0).value;		
	for(i=0;i<s.length;i++)
	{				
		a=s.charCodeAt(i);		
		if(a<48 || (a>57 && a<65) || a>122 || a==92 || a==94 || a==95 || a==96 ) //`^_\
		{			
			s = s.substr(0,i) + s.substr(i+1,s.length);
			$$(s0).value=s;
		}
	}
}
function showImage(url)
{
	var img = new Image();
	img.src = url;	
	w = img.width;
	h = img.height;
	t=(screen.availHeight - h)/2;
	l=(screen.availWidth - w)/2;
	window.open(url,"","width=" + (w + 20)+ "px,height=" + (h + 20)+ ",top=" + t +"px,left=" + l + "px,resizable=0,status=0,scrollbars=yes");
}
function delKeyWords(c1,c2){
	$$(c1).value="";	
	$$(c2).value="";
}
function showPrint(root,id,tbl){
	url = root+"modules/news/print.php?newid="+id+"&tb="+tbl;
	t=(screen.availHeight - h)/2;
	l=(screen.availWidth - w)/2;
	window.open(url,"","width=" + (w + 20)+ "px,height=" + (h + 20)+ ",top=" + t +"px,left=" + l + "px,resizable=0,status=0,scrollbars=yes");		
}
// id=showInfoThisHere 
function showEmail(root,id,tbl){
	url = root+"modules/news/print.php?newid="+id+"&tb="+tbl;
	t=(screen.availHeight - h)/2;
	l=(screen.availWidth - w)/2;
	window.open(url,"","width=" + (w + 20)+ "px,height=" + (h + 20)+ ",top=" + t +"px,left=" + l + "px,resizable=0,status=0,scrollbars=yes");		
}
function showReplay(root,id,tbl){
	url = root+"modules/news/print.php?newid="+id+"&tb="+tbl;
	t=(screen.availHeight - h)/2;
	l=(screen.availWidth - w)/2;
	window.open(url,"","width=" + (w + 20)+ "px,height=" + (h + 20)+ ",top=" + t +"px,left=" + l + "px,resizable=0,status=0,scrollbars=yes");		
}
function showInfoReplay(url,id,tbl){
	$('#'+id).html('<img src="skins/default/loading.gif">');
	$('#'+id).load(url,{'id':id,'tbl':tbl});
}
