﻿function changeLangInput(ctlInput)
{
	if (ctlInput.src.indexOf('Vietnam.gif') == -1)	
	{
	    setMethod(0);
	    ctlInput.src ='/Web/Images/Vietnam.gif';
	    ctlInput.alt = 'Chọn bộ gõ Tiếng Việt. Tình trạng: bật.'
    } 
    else 
    {	    
	    setMethod(-1);
	    ctlInput.src ='/Web/Images/English.gif';
	    ctlInput.alt = 'Chọn bộ gõ Tiếng Việt. Tình trạng: tắt.'
    }
    return true;
}
function FireDefaultButton(event, target) {
        if (event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea"))) {
        var defaultButton;
        if (__nonMSDOMBrowser) {
            defaultButton = document.getElementById(target);
        }
        else {
            defaultButton = document.all[target];
        }
        if (defaultButton && typeof(defaultButton.click) != "undefined") {
            defaultButton.click();
            event.cancelBubble = true;
            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}
function popupWin(url)
{
	window.open(url, 'PopUp', 'resizable=yes,width=500,height=450,top=75,left=220,scrollbars=yes');
}
function popupReport(url)
{
	window.open(url, 'PopupReport', 'resizable=yes,width=800,height=600,top=75,left=220,scrollbars=yes');
}

function SelectAllCheckboxes(theBox)
{
	xState = theBox.checked;
	elm = theBox.form.elements;

	for (i = 0; i < elm.length; i++)
		if (elm[i].type == "checkbox" && elm[i].id != theBox.id)
			{
			if (elm[i].checked != xState)
					elm[i].click();
			}
}

function installSearchEngine() 
{
 if (window.external && ("AddSearchProvider" in window.external)) {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.5sub.com/opensearch.xml");
 }
}

function CopyToClipBoard(iElementId,imgMessID)
{
        if (typeof iElementId == "string" && iElementId.length > 0) 
        {
            var element = document.getElementById(iElementId);
            if (element)
            {
                element.select();
                if (window.clipboardData) 
                {
                    window.clipboardData.setData("Text", element.value);
                    displayImgCopy2Clipboard(10, imgMessID);    
                }                
            }    
        }
}

var count=0;
function ShowMedia(controlID) 
{
    if(count==0)
    {
        var obj = null;
        obj = document.getElementById(controlID);
        if( obj != null   )
        {
            obj.style.visibility = "visible";
            count=1;
        }
    }
    else
    {
        HideMedia();
        count=0;
    }
    
}

function HideMedia(controlID) 
{
    var obj = null;
    obj = document.getElementById(controlID);
    if( obj != null   )
    {
        obj.style.visibility = "hidden";
    }
}

function displayImgCopy2Clipboard(k, imgID) 
{
    var objImage = null;
    objImage = document.getElementById(imgID);
    if( objImage != null   )
    {
        objImage.style.visibility = "visible";
    }
}

function SetFitSizeImage(imageId, maxWidth, maxHeight)
{
    try
    {
        var img = document.getElementById(imageId);
        var width = img.clientWidth;
        var height = img.clientHeight;
        var ratio = width / height;
        //alert(img.width);
        if (width <= maxWidth && height <= maxHeight)
        {
            return;
        }
        if (ratio >= 1)
        {
            img.width = maxWidth - 2;
        }
        else
        {
            img.width = Math.floor(maxHeight * ratio) - 2;
        }
    }
    catch(e)
    {
        //alert('Error: ' + e.message);
    }
}

function ValidateSearchKey(txtControl )
	{	 
	    var ctlTxt = document.getElementById(txtControl);
	    if( objImage != null   )
        {
            var str = ctlTxt.value;
		    if (str.length <= 1) 
		    {
		    alert('asdasd');
			    return false;
		    }
        }		
	}


function ReloadPage()
{
	window.location.reload();
}

function BuildYouTubeEmbed(code) {
    document.write('<object width=\"480\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/"'+ code +'"&hl=en_US&fs=1&\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/{0}&hl=en_US&fs=1&\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"480\" height=\"385\"></embed></object>');
}

