﻿    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 OK(name)
    {
        __doPostBack(name,'');
    }
   
    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 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");
    var ddl = document.getElementById(PageName);
    window.open(ddl.value,'_Blank',"status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes");
}
function CheckDelete(grid,checkboxname)
{
    var inputs = document.getElementsByTagName('input');
    var state;
    var numberOfSelectedItem = 0;
    for (i=0; i<inputs.length; ++i) 
    {
		if (inputs[i].type.toLowerCase()=='checkbox' &&
		    checkboxname == Right(inputs[i].id,checkboxname.length)   &&  
		    inputs[i].checked == true) 
		{
	        numberOfSelectedItem++;
	    }
    } 
    if(numberOfSelectedItem > 0)
    {
        return confirm('Bạn có muốn xóa các dòng được chọn?');
    }
    else
    {
        alert('Vui lòng chọn 1 dòng cần xóa!');
        return false;
    }
}
function CheckRadioList()
{
    var inputs = document.getElementsByTagName('input');
    var state;
    var numberOfSelectedItem = 0;
    for (i=0; i<inputs.length; ++i) 
    {
		if (inputs[i].type.toLowerCase()=='radio' &&
		    inputs[i].checked == 'checked') 
		{
	        numberOfSelectedItem++;
	    }
    } 
    if(numberOfSelectedItem == 0)
    {
        alert('Bạn chưa chọn câu trả lời!');
        return false;
    }
    else
        return true;
}

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 định dạng!');
        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 SetValueHidden(hdf, button, GiaTri)
{
    alert('da vao can cu');
   alert('Ten cua hidden field là: ' + hdf) ;
   var hidden = document.getElementById(hdf);
   alert('Gia tri hien tai: ' + hidden.value);
   hidden.value = GiaTri; 
   alert('Gia tri sau kh gan : ' + hidden.value);
   __doPostBack(button,'');
   
}

function showFlowLayer(value)
{
    var divcontent = document.getElementById('divContent');
    var width = 450;
    var height = 450;
	var HTML = '';

    HTML +=  ('<a href="' + value + '" style="display:block;width:520px;height:330px" id="player"></a>');
    HTML +=  ('<script> flowplayer("player", "../flowplayer-3.2.7.swf",{clip: {autoPlay: false, autoBuffering: true }});</script>');
    divcontent.innerHTML = HTML;	
}

function showPLayer(placeholderid, link,start)
{
    var divcontent = document.getElementById(placeholderid);
    var width = 450;
    var height = 450;
	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>');
	divcontent.innerHTML = HTML;	
}

function showPLayer1(link,start)
{
    var width = 450;
    var height = 450;
	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 SetImagePath(imgPath, value)
{
   var img = document.getElementById(imgPath);
   img.src = value; 
}

function updateHtml(currentid)
{
    var linkApplication = document.getElementById('linkApplication');
    var linkStore = document.getElementById('linkStore');
    var linkPolicy = document.getElementById('linkPolicy');
    var imgApplication = document.getElementById('imgApplication');
    var imgStore = document.getElementById('imgStore');
    var imgPolicy = document.getElementById('imgPolicy');
    var divApplication = document.getElementById('divApplication');
    var divStore = document.getElementById('divStore');
    var divPolicy = document.getElementById('divPolicy');
    if(currentid == 1)
    {
        linkApplication.setAttribute('class','tab active');
        imgApplication.setAttribute('style','display:block');
        divApplication.setAttribute('style','display:block');
        linkStore.setAttribute('class','tab');
        imgStore.setAttribute('style','display:none');
        divStore.setAttribute('style','display:none');
        linkPolicy.setAttribute('class','tab');
        imgPolicy.setAttribute('style','display:none');
        divPolicy.setAttribute('style','display:none');
    }
    else if(currentid == 2)
    {
        linkApplication.setAttribute('class','tab');
        imgApplication.setAttribute('style','display:none');
        divApplication.setAttribute('style','display:none');
        linkStore.setAttribute('class','tab active');
        imgStore.setAttribute('style','display:block');
        divStore.setAttribute('style','display:block');
        linkPolicy.setAttribute('class','tab');
        imgPolicy.setAttribute('style','display:none');
        divPolicy.setAttribute('style','display:none');
    }
    else if(currentid == 3)
    {
        linkApplication.setAttribute('class','tab');
        imgApplication.setAttribute('style','display:none');
        divApplication.setAttribute('style','display:none');
        linkStore.setAttribute('class','tab');
        imgStore.setAttribute('style','display:none');
        divStore.setAttribute('style','display:none');
        linkPolicy.setAttribute('class','tab active');
        imgPolicy.setAttribute('style','display:block');
        divPolicy.setAttribute('style','display:block');
    }
    
}
