﻿function CheckAll(chk_Header,chk_Delete)
{
    var chkAll = document.getElementById(chk_Header);
	var inputs = document.getElementsByTagName('input');
	var state = chkAll.checked;
	for (i = 0; i < inputs.length; i++) 
	{
		if (inputs[i].type.toLowerCase()=='checkbox' && chk_Delete == Right(inputs[i].id,chk_Delete.length)) 
		{
			inputs[i].checked=state;
		}
	} 
}
function UnCheckAll(chk_Header,chk_Delete)
{
	var inputs = document.getElementsByTagName('input');
	var state = true;
	for (i = 0; i < inputs.length; i++) 
	{
		if (inputs[i].type.toLowerCase()=='checkbox' && chk_Header != Right(inputs[i].id,chk_Header.length))
		{
			if (inputs[i].checked==false)
			{
			    state = false;
				break;
		    }
		}
	}
	for (j = 0; j < inputs.length; j++) 
	{
		if (inputs[j].type.toLowerCase()=='checkbox' && chk_Header == Right(inputs[j].id,chk_Header.length))
		{
			inputs[j].checked = state;
			break;
		}
	}
}
    
   
function Right(str, n)
{
    if (n <= 0)
        return "";
    else 
        if (n > String(str).length)
                return str;
            else
            {
                var iLen = String(str).length;
                return String(str).substring(iLen, iLen - n);
            }
}
function OpenChild(PageName) 
{
    //var WinSettings = "center:yes;resizable:no;dialogWidth:1000px;dialogHeight:700px"
    // ALTER BELOW LINE - supply correct URL for Child Form
    window.open(PageName,'_Parent',"height=650,width=850,status=yes,toolbar=no,menubar=no,location=no");
}

function OpenResult(PageName) 
{
    //var WinSettings = "center:yes;resizable:no;dialogWidth:1000px;dialogHeight:700px"
    // ALTER BELOW LINE - supply correct URL for Child Form
    window.open(PageName,'_Parent',"height=300,width=700,status=yes,toolbar=no,menubar=no,location=no");
}
function OpenWindow(PageName) 
{
    var ddl = document.getElementById(PageName);
    //var WinSettings = "center:yes;resizable:no;dialogWidth:1000px;dialogHeight:700px"
    // ALTER BELOW LINE - supply correct URL for Child Form
    //window.open(PageName,'_Parent',"height=500,width=500,status=yes,toolbar=no,menubar=no,location=no");
    window.open(PageName,'_Blank',"status=no,toolbar=no,menubar=no,location=no,resizable=no");
}


function CheckImageExtension(FileUpload)
{
    var input = document.getElementById(FileUpload);
    var filetype = input.value;
    var splitName = filetype.split('.');
    
    filetype = splitName[splitName.length-1];
    filetype = filetype.toLowerCase();
    if (filetype == 'gif' || filetype == 'jpg' || filetype == 'jpeg' || filetype == 'bmp'
        || filetype == 'png')
    {
        return true;
    }
    else if(filetype != '')
    {
        alert('Ảnh bạn chọn không đúng các định dạng (.gif, .jpg, .jpeg, .bmp, .png)');
        return false;
    }
}

function CheckExtension(FileUpload, arrExtension)
{
    var input = document.getElementById(FileUpload);
    var filetype = input.value;
    var splitName = filetype.split('.');
    filetype = splitName[splitName.length-1];
    filetype = filetype.toLowerCase();
    if (arrExtension.indexOf(filetype) != -1)
    {
        return true;
    }
    else if(filetype != '')
    {
        alert('Tập tin bạn chọn không đúng định dạng ' + arrExtension + '!');
        return false;
    }
}

function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
    return false;

 return true;
}

function SetActive(name)
{
    document.getElementById(name).className='active';
}

function SetDeactive(name, currentpage, code)
{
    var curpage = document.getElementById(currentpage).value;
    if(curpage == code)
    {
        document.getElementById(name).className='active';
    }
    else
    {
        document.getElementById(name).className='';
    }
}

function showPLayer(link,start)
{
    var width = 250;
    var height = 105;
	var HTML = '';

    HTML +=  ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+width+'" height="'+height+'" id="player1" name="player1">');
    HTML +=  ('<param name="movie" value="resources/flash/jwplayer.swf">');
    HTML +=  ('<param name="allowfullscreen" value="true">');
    HTML +=  ('<param name="allowscriptaccess" value="always">');
    HTML +=  ('<param name="wmode" value="transparent">');
    HTML +=  ('<param name="flashvars" value="file='+link+'&image=resources/images/bgplayer.jpg&frontcolor=000000&autostart=true&skin=resources/flash/skins/fs35.xml&logo=resources/images/logoplayer.png">');
    HTML +=  ('<embed type="application/x-shockwave-flash" id="player2" name="player2" src="resources/flash/jwplayer.swf" width="'+width+'" height="'+height+'" bgcolor="undefined" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" flashvars="file='+link+'&image=resources/images/bgplayer.jpg&frontcolor=000000&autostart=true&skin=resources/flash/skins/fs35.xml&logo=resources/images/logoplayer.png"/>');
    HTML +=  ('</object>');
	return HTML;	
}

function nghenhac(musicid, supplier) 
{
    var param = "ID=" + musicid + "&Sup=" + supplier;
    var url = "nghenhac.aspx?" + param;

    var newwin = OpenWindow(url);
    if (window.focus) { newwin.focus() }
}

function listenmusic(musicid, supplier) 
{
    var param = "ID=" + musicid + "&Sup=" + supplier;
    var url = "listentomusic.aspx?" + param;

    var newwin = OpenWindow(url);
    if (window.focus) { newwin.focus() }
}

function showdiv(divid)
{
    var divcontent = document.getElementById(divid);
    divcontent.style.display = "block";
}
