﻿// JScript File
/***********************************
            Directly Play
************************************/
function PlayDirectly()
{
    var playInfo = Querystring("Playing", "none");
    var id = Querystring("ID", "-1");

    if(playInfo != "none")
    {
		if(playInfo == "Direct")
		{
			changeSource(id);	
		}    
		else if(playInfo == "VC")
		{
			changeSource('PlayList.aspx?Media=' + id); 
		}
        else if((playInfo == "TVO") || (playInfo == "Radio") || (playInfo == "THTN"))
        {
            changeSource('PlayList.aspx?' + playInfo + '=-1'); 
        }
        else if(id != "-1")
        {
            changeSource('PlayList.aspx?' + playInfo + '=' + id); 
        }
        else
        {
            changeSource('PlayList.aspx?' + playInfo); 
        }
    }
}


/***********************************
            Datalist Paging
************************************/
function ShowPreviousPage(pageSize, currentPageIndex)
{
    currentPageIndex -= pageSize;
    if (currentPageIndex < 0)
    {
        currentPageIndex = 0;
    }
    return currentPageIndex;
}

function ShowNextPage(pageSize, recordCount, currentPageIndex)
{
    if ((currentPageIndex + pageSize) < recordCount)
    {
        currentPageIndex += pageSize;
    }
    return currentPageIndex;
}

function ShowLastPage(pageSize, recordCount, currentPageIndex)
{
    if (recordCount > 0)
    {
        var intMod = recordCount % pageSize;
        if (intMod > 0)
        {
            currentPageIndex = recordCount - intMod;
        }
        else
        {
            currentPageIndex = recordCount - pageSize;
        }
    }
    return currentPageIndex;    
}


/***********************************
            String Cut
************************************/
function cutStrExper( head, length )
{
    if(head == "?")
    {
        document.write("");
		return;
    }
        
   	var strLen = head.length;
	if (strLen > length)
	{
		head = head.substr(0, length+5) ;
		
		var lastIndexOfSpace = head.lastIndexOf(' ');
		
		if (lastIndexOfSpace > 0)
        {
            head = head.substr(0, lastIndexOfSpace) ;
        }
        else 
        {
            head = head.substr(0, length) ;
        }
		
		document.write(head + " ...");
		return;
	}
	else
	{
		document.write(head);		
	}		
}

function cutStrExperJs( head, length )
{
    if(head == "?")
    {
        return "";	
    }
    
   	var strLen = head.length;
	if (strLen > length)
	{
		head = head.substr(0, length+5) ;
		
		var lastIndexOfSpace = head.lastIndexOf(' ');
		
		if (lastIndexOfSpace > 0)
        {
            head = head.substr(0, lastIndexOfSpace) ;
        }
        else 
        {
            head = head.substr(0, length) ;
        }
		
		return head + " ...";
	}
	else
	{
		return head;		
	}		
}

function standardizeNumber( number, length )
{
   	var strLen = number.length;
	if (strLen < length)
	{
		for(i=length-strLen; i>0; i--)
		{
		    number = "0" + number;
		}				
	}
	document.write(number);	
	return;				
}


function cutStrExperForObject( obj, length )
{
    var head = (obj.value);
    
	var strLen = head.length;
	if (strLen > length)
	{
		head = head.substr(0, length+5) ;
		head = head.substr(0, head.lastIndexOf(' '))
		//document.write(head + " ...");
		
		obj.value = head + " ...";
		
		return;
	}
	else
	{
		//document.write(head);				
	}		
}


/*------------------------------------------------------
				Display Vega Mail																								 
------------------------------------------------------*/
function AboutVega()
{
	alert("mailto:" + "Sales" + "@" + "vega.com.vn");
}

/*------------------------------------------------------
				CallBack Error Load Info																								
------------------------------------------------------*/
function onCallbackError(message)
{
    if(confirm('Tạm thời không kết nối được tới Internet\n Bạn hãy thử nạp lại trang?'))
    {
       location.reload();
    }
}


/*------------------------------------------------------
				Listening the song																								
------------------------------------------------------*/
function changeSource( strSource )
{
    var s;
    s="<OBJECT id=winMediaPlayerID ";
            s+="codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715 ";
            s+="type=application/x-oleobject height=340 ";
            s+="standby=\"Loading Microsoft Windows Media Player components...\" "; 
            s+="width=304 classid=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ";
            s+="name=winMediaPlayer>";
        s+="<PARAM NAME=\"URL\" VALUE=\""+strSource+"\"> ";
        s+="<PARAM NAME=\"rate\" VALUE=\"1\">";
        s+="<PARAM NAME=\"balance\" VALUE=\"0\">";
        s+="<PARAM NAME=\"currentPosition\" VALUE=\"0\">";
        s+="<PARAM NAME=\"defaultFrame\" VALUE=\"0\">";
        s+="<PARAM NAME=\"playCount\" VALUE=\"999\">";
        s+="<PARAM NAME=\"CursorType\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"autoStart\" VALUE=\"1\">";
        s+="<PARAM NAME=\"currentMarker\" VALUE=\"0\">";
        s+="<PARAM NAME=\"invokeURLs\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"volume\" VALUE=\"50\">";
        s+="<PARAM NAME=\"mute\" VALUE=\"0\">";
        s+="<PARAM NAME=\"stretchToFit\" VALUE=\"-1\">";
        s+="<PARAM NAME=\"windowlessVideo\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enabled\" VALUE=\"1\">";
        s+="<PARAM NAME=\"fullScreen\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enableContextMenu\" VALUE=\"0\">";
        s+="<PARAM NAME=\"enableErrorDialogs\" VALUE=\"0\"> \n";
        
        s+="<Embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/' filename='"+strSource+"' src='"+strSource+"' Name='MediaPlayerTV' "; 
            s+="width='304' ";
            s+="height='340' ";
            s+="AutoSize='1' ";
            s+="AutoStart='1' ";
            s+="ClickToPlay='1' ";
            s+="DisplaySize='1' ";
            s+="EnableContextMenu='0' ";
            s+="EnableFullScreenControls='1' "; 
            s+="EnableTracker='1' ";
            s+="Mute='0' ";
            s+="PlayCount='999' "; 
            s+="ShowControls='1' "; 
            s+="ShowAudioControls='1' "; 
            s+="ShowDisplay='0' ";
            s+="ShowGotoBar='0' ";
            s+="ShowPositionControls='1' "; 
            s+="ShowStatusBar='1' ";
            s+="ShowTracker='1'> ";
            s+="</embed> ";
    s+="</OBJECT>";
	
    document.getElementById("MediaPlayer").innerHTML=s;
}

/*------------------------------------------------------
				Parse Search KeyWord																								
------------------------------------------------------*/
function onCmdSearchClick( txtBox )
{
    var q = (txtBox.value);
    
    if ((q.indexOf('AND') == -1) && (q.indexOf('OR') == -1) && (q.indexOf('"') == -1) && (q != ''))
	{
		q = '\'' + q + '\'';
	    txtBox.value = q;
	}
}

/*------------------------------------------------------
				Write Short DateTime																								
------------------------------------------------------*/
function writeDayTime(s)
{
	var mydate=new Date(s)
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900
	var month = mydate.getMonth() + 1
	if (month < 10)
		month = "0" + month
	var day = mydate.getDate()
	if (day < 10)
		day = "0" + day

	var dayw = mydate.getDay()
	
	document.write( day+"/"+month+"/"+year )
}


/*------------------------------------------------------
				Get Query String																							
------------------------------------------------------*/
function Querystring(strKey,strDefault)
{
    // get the query string, ignore the ? at the front.
	var querystring=location.search.substring(1,location.search.length);

    // parse out name/value pairs separated via &
	var args = querystring.split('&');

    // split out each name = value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=');

		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		name = temp.join(' ');

		temp = unescape(pair[1]).split('+');
		value = temp.join(' ');
        
        if(name == strKey)
        {
            return value;
        }		
	}
    
    return strDefault;
}